Skip to content

Commit

Permalink
YAML module doesn't guarantee order
Browse files Browse the repository at this point in the history
We must use a different way to ensure that all the dependencies
are correct, because the python YAML module doesn't guarantee
that the order is preserved, so, since the parts could be
returned in a different order, we can't stop when we find "debs".
  • Loading branch information
sergio-costas committed Sep 19, 2024
1 parent f847d19 commit 33c3510
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions tools/check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,41 @@

data = yaml.safe_load(open(config_file, "r"))

parts = {}
exceptions = ['buildenv']

for part in data['parts']:
if part == "debs":
break
if part in exceptions:
continue
parts[part] = False

def filldeps(part):
""" Fill recursively the dependencies of each part """
global data
global parts
if 'after' not in data['parts'][part]:
return

deps = data['parts'][part]['after']
for dep in deps:
parts[dep] = True
filldeps(dep)
output = []
if 'after' in data['parts'][part]:
for dep in data['parts'][part]['after']:
# it's not a problem to have duplicated dependencies
output += filldeps(dep)
output.append(dep)
return output

dependencies = {}

# get the dependencies for each part
for part in data["parts"]:
dependencies[part] = filldeps(part)

deb_dependencies = []
for part in data["parts"]:
if "debs" == part:
continue
if "debs" in dependencies[part]:
# if it depends on debs, it must be after, so don't take it into account
continue
if part in exceptions:
continue
deb_dependencies.append(part)

filldeps("debs")
failed = False
for part in parts:
if parts[part]:
continue
print(f"DEBS must depend on {part}")
failed = True
for dependency in deb_dependencies:
if dependency not in dependencies["debs"]:
print(f"DEBS part must be after {dependency}")
failed = True

if failed:
sys.exit(1)
Expand Down

0 comments on commit 33c3510

Please sign in to comment.