Skip to content

Commit c35a2bc

Browse files
dependency_cross_matcher.py: Compatibilize parsec and parsec-tool
parsec and parsec-tool share some dependencies. In those shared dependencies, the used versions should be the same. * Modify utils/dependency_cross_matcher.py to cover the case of comparing parsec and parsec-tool dependencies as well as the previous case of checking mismatches in parsec-tool dependencies. Signed-off-by: Tomás González <[email protected]>
1 parent 239d141 commit c35a2bc

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

tests/ci.sh

+2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ done
3434
# Dependency mismatcher #
3535
#########################
3636
if [ "$MISMATCHER" = "True" ]; then
37+
3738
python3 $(pwd)/utils/dependency_cross_matcher.py --deps_dir $(pwd)
39+
3840
exit 0
3941
fi
4042

utils/dependency_cross_matcher.py

+44-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import sys
66

77

8-
def run_cargo_tree(path):
9-
cmd = 'cargo tree --all-features -d'
8+
def run_cargo_tree(path, flags=None):
9+
cmd = 'cargo tree'
10+
if flags is not None:
11+
cmd += ' ' + flags
1012
prev_dir = os.getcwd()
1113
os.chdir(os.path.join(path))
1214
return subprocess.check_output(cmd, shell=True).decode()
@@ -43,14 +45,46 @@ def main(argv=[], prog_name=''):
4345
parser = argparse.ArgumentParser(prog='DependencyCrossmatcher',
4446
description='Checks the version mismatches for dependencies '
4547
'in Cargo based repositories')
48+
parser.add_argument("-c", "--compare", action='store_true',
49+
help='Check for mismatches between 2 repositories')
4650
parser.add_argument('--deps_dir',
4751
required=True,
48-
help='Existing directory that contains the Cargo.toml for analyzing'
52+
nargs='+',
53+
help='Existing directories that contain Cargo.toml for analyzing '
4954
'dependencies')
5055
args = parser.parse_args()
5156

52-
mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir))
53-
print_deps(mismatches)
57+
mismatches = dict()
58+
parsec_tool_flags = '--all-features -d'
59+
60+
if args.compare:
61+
exceptions = {
62+
'bindgen': ['v0.66.1', 'v0.57.0'],
63+
}
64+
parsec_repo, parsec_tool_repo = args.deps_dir
65+
parsec_flags = '--all-features' + ' '
66+
parsec_flags = '--features tss-esapi/generate-bindings,cryptoki/generate-bindings -d'
67+
mismatches_parsec = run_deps_mismatcher(run_cargo_tree(parsec_repo, parsec_flags))
68+
mismatches_parsec_tool = run_deps_mismatcher(run_cargo_tree(parsec_tool_repo,
69+
parsec_tool_flags)
70+
)
71+
72+
# Dependencies that are common to both parsec_repo and parsec_tool_repo repos
73+
common_deps = list(set(mismatches_parsec.keys()) & set(mismatches_parsec_tool.keys()))
74+
for dep in common_deps:
75+
# Symmetric difference of repos parsec_repo and parsec_tool_repo
76+
mistmatch = list(set(mismatches_parsec[dep]) ^ set(mismatches_parsec_tool[dep]))
77+
if len(mistmatch) > 0:
78+
mismatches[dep] = mistmatch
79+
else:
80+
exceptions = {
81+
'base64': ['v0.13.1', 'v0.21.4'],
82+
'bitflags': ['v1.3.2', 'v2.4.1'],
83+
'nom': ['v5.1.3', 'v7.1.3'],
84+
'syn': ['v1.0.109', 'v2.0.38'],
85+
'yasna': ['v0.4.0', 'v0.5.2'],
86+
}
87+
mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir[0], parsec_tool_flags))
5488

5589
mismatches = get_deps_with_more_than_1v(mismatches)
5690

@@ -60,15 +94,12 @@ def main(argv=[], prog_name=''):
6094
print('---------------------mistmatches----------------------\n\n')
6195
print_deps(mismatches)
6296

63-
exceptions = {
64-
'base64': ['v0.13.1', 'v0.21.4'],
65-
'bitflags': ['v1.3.2', 'v2.4.1'],
66-
'nom': ['v5.1.3', 'v7.1.3'],
67-
'syn': ['v1.0.109', 'v2.0.38'],
68-
'yasna': ['v0.4.0', 'v0.5.2'],
69-
}
97+
if not args.compare:
98+
errormsg = "Found dependencies version mismatches in parsec-tool"
99+
else:
100+
errormsg = "Found dependencies version mismatches between parsec and parsec-tool"
70101

71-
assert exceptions == mismatches, "Found dependencies version mismatches in parsec-tool"
102+
assert exceptions == mismatches, errormsg
72103

73104
return 0
74105

0 commit comments

Comments
 (0)