@@ -3,49 +3,47 @@ import argparse
33import os
44import 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
5048if __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