Skip to content

Commit bb62b68

Browse files
tgonzalezorlandoarmgowthamsk-arm
authored andcommitted
utils/dependency_cross_matcher.py: Add the --compare option
Add the --compare option to compare the dependency mismatches between the parsec and parsec-tool repositories. Signed-off-by: Tomás González <[email protected]>
1 parent 1434fd8 commit bb62b68

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

utils/dependency_cross_matcher.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,65 @@ def main(argv=[], prog_name=''):
5151
parser = argparse.ArgumentParser(prog='DependencyCrossmatcher',
5252
description='Checks the version mismatches for dependencies '
5353
'in Cargo based repositories')
54+
parser.add_argument("-c", "--compare", action='store_true',
55+
help='Check for mismatches between 2 repositories')
5456
parser.add_argument('--deps_dir',
5557
required=True,
56-
help='Existing directory that contains the Cargo.toml for analyzing'
58+
nargs='+',
59+
help='Existing directories that contain Cargo.toml for analyzing '
5760
'dependencies')
5861
args = parser.parse_args()
5962

63+
mismatches = dict()
6064
parsec_flags = '--all-features' + ' '
6165
parsec_flags += '--features tss-esapi/generate-bindings,cryptoki/generate-bindings -d'
62-
mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir, parsec_flags))
63-
print_deps(mismatches)
6466

65-
mismatches = get_deps_with_more_than_1v(mismatches)
67+
if args.compare:
68+
# Versions should be sorted!
69+
exceptions = {
70+
'bindgen': ['v0.66.1'],
71+
'cexpr': ['v0.6.0'],
72+
}
73+
parsec_repo, parsec_tool_repo = args.deps_dir
74+
parsec_tool_flags = '--all-features -d'
75+
mismatches_parsec = run_deps_mismatcher(run_cargo_tree(parsec_repo, parsec_flags))
76+
mismatches_parsec_tool = run_deps_mismatcher(run_cargo_tree(parsec_tool_repo,
77+
parsec_tool_flags)
78+
)
79+
80+
# Dependencies that are common to both parsec_repo and parsec_tool_repo repos
81+
common_deps = list(set(mismatches_parsec.keys()) & set(mismatches_parsec_tool.keys()))
82+
for dep in common_deps:
83+
# Symmetric difference of repos parsec_repo and parsec_tool_repo
84+
mistmatch = sorted(set(mismatches_parsec[dep]) ^ set(mismatches_parsec_tool[dep]))
85+
if len(mistmatch) > 0:
86+
mismatches[dep] = mistmatch
87+
else:
88+
# Versions should be sorted!
89+
exceptions = {
90+
'base64': ['v0.13.1', 'v0.21.4'],
91+
'bindgen': ['v0.57.0', 'v0.66.1'],
92+
'bitflags': ['v1.3.2', 'v2.4.1'],
93+
'cexpr': ['v0.4.0', 'v0.6.0'],
94+
'nom': ['v5.1.3', 'v7.1.3'],
95+
'shlex': ['v0.1.1', 'v1.2.0'],
96+
'syn': ['v1.0.109', 'v2.0.38'],
97+
}
98+
mismatches = run_deps_mismatcher(run_cargo_tree(args.deps_dir[0], parsec_flags))
99+
mismatches = get_deps_with_more_than_1v(mismatches)
66100

67101
print('---------------------exceptions-----------------------\n\n')
68-
exceptions = {
69-
'base64': ['v0.13.1', 'v0.21.4'],
70-
'bindgen': ['v0.57.0', 'v0.66.1'],
71-
'bitflags': ['v1.3.2', 'v2.4.1'],
72-
'cexpr': ['v0.4.0', 'v0.6.0'],
73-
'nom': ['v5.1.3', 'v7.1.3'],
74-
'shlex': ['v0.1.1', 'v1.2.0'],
75-
'syn': ['v1.0.109', 'v2.0.38'],
76-
}
77102
print_deps(exceptions)
78103

79104
print('---------------------mistmatches----------------------\n\n')
80105
print_deps(mismatches)
81106

82-
if exceptions != mismatches:
83-
return 1
107+
if not args.compare:
108+
errormsg = "Found dependencies version mismatches in parsec"
109+
else:
110+
errormsg = "Found dependencies version mismatches between parsec and parsec-tool"
111+
112+
assert exceptions == mismatches, errormsg
84113

85114
return 0
86115

0 commit comments

Comments
 (0)