Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit d519bff

Browse files
William Douglasbryteise
authored andcommitted
Update detection of loops
This code will detect content loops and also modifies how the content sets are updated. In addition also-add content is skipped as it is intentionally not required content of a bundle.
1 parent 4ec459e commit d519bff

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

unbundle

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,47 @@ import argparse
33
import os
44
import sys
55

6-
def resolve_includes(bundle_name, bundle_path, bundles=False):
6+
def resolve_includes(bundle_name, bundle_path, content, bundles=False, path=set()):
77
"""
88
resolve_incudes returns a full package list of include-resolved packages in
99
the bundle definition file or pundle declaration under bundle_path. Sources
1010
for included bundles are other bundle definition files at
1111
bundle_path/bundles/* and bundle_path/packages.
1212
"""
1313
bundle_def = os.path.join(bundle_path, "bundles", bundle_name)
14+
path.add(bundle_name)
1415
try:
1516
with open(bundle_def, "r", encoding="latin-1") as bundlef:
1617
lines = bundlef.readlines()
1718
except FileNotFoundError:
1819
print(f"ERROR: could not find {bundle_name} bundle")
19-
return set(), False
20+
return False
2021

21-
packages = set()
2222
if bundles:
23-
packages.add(bundle_name)
23+
content.add(bundle_name)
2424

2525
for line in lines:
2626
line = line.split("#", 1)[0].strip()
2727
if not line:
2828
continue
29-
30-
if line.startswith("include("):
29+
elif line.startswith("also-add("):
30+
continue
31+
elif line.startswith("include("):
3132
inc_bundle = line[line.find("(")+1:line.find(")")]
32-
try:
33-
n_packages, success = resolve_includes(inc_bundle, bundle_path, bundles)
34-
if not success:
35-
return set(), False
36-
packages = packages.union(n_packages)
37-
except RecursionError:
38-
print("ERROR: include loop found")
39-
return set(), False
33+
if inc_bundle in path:
34+
print(f"Error cycle detected: {inc_bundle} is part of a loop in bundles {path}.")
35+
return False
36+
success = resolve_includes(inc_bundle, bundle_path, content, bundles, path)
37+
if not success:
38+
return False
4039
if bundles:
41-
packages.add(inc_bundle)
42-
40+
content.add(inc_bundle)
4341
continue
42+
elif not bundles:
43+
content.add(line)
4444

45-
if not bundles:
46-
packages.add(line)
47-
48-
return packages, True
45+
path.remove(bundle_name)
46+
return True
4947

5048
if __name__ == "__main__":
5149
parser = argparse.ArgumentParser(description='Process bundle packages following includes')
@@ -55,16 +53,17 @@ if __name__ == "__main__":
5553
help='Report only included bundle names')
5654
args = parser.parse_args()
5755
success = True
56+
content = set()
5857
if args.bundles:
5958
os_core_set = set(["os-core"])
6059
else:
61-
os_core_set, success = resolve_includes("os-core", args.bundle_path)
62-
60+
os_core_set = set()
61+
success = resolve_includes("os-core", args.bundle_path, os_core_set)
6362
if not success:
6463
sys.exit(1)
6564

66-
bundle_set, success = resolve_includes(args.bundle_name, args.bundle_path, bundles=args.bundles)
65+
success = resolve_includes(args.bundle_name, args.bundle_path, content, bundles=args.bundles)
6766
if not success:
6867
sys.exit(1)
6968

70-
print('\n'.join(sorted(os_core_set.union(bundle_set))))
69+
print('\n'.join(sorted(os_core_set.union(content))))

0 commit comments

Comments
 (0)