Browse Source

buildorder.py: wrap main()

android-5
Francisco Demartino 9 years ago
parent
commit
15ea0fef9e
  1. 35
      buildorder.py

35
buildorder.py

@ -30,7 +30,8 @@ packages_map = {}
packages_dir = 'packages' packages_dir = 'packages'
for subdir_name in sorted(os.listdir(packages_dir)): def main():
for subdir_name in sorted(os.listdir(packages_dir)):
subdir_path = packages_dir + '/' + subdir_name subdir_path = packages_dir + '/' + subdir_name
if os.path.exists(subdir_path + '/BROKEN.txt'): if os.path.exists(subdir_path + '/BROKEN.txt'):
@ -53,6 +54,7 @@ for subdir_name in sorted(os.listdir(packages_dir)):
dep = dep.strip() dep = dep.strip()
if not dep.endswith('libandroid-support-dev'): if not dep.endswith('libandroid-support-dev'):
this_package.remaining_dependencies.add(dep) this_package.remaining_dependencies.add(dep)
for file_in_subdir_name in sorted(os.listdir(subdir_path)): for file_in_subdir_name in sorted(os.listdir(subdir_path)):
if file_in_subdir_name.endswith('.subpackage.sh'): if file_in_subdir_name.endswith('.subpackage.sh'):
subpackage_name = file_in_subdir_name[0:-len(".subpackage.sh"):] subpackage_name = file_in_subdir_name[0:-len(".subpackage.sh"):]
@ -70,27 +72,29 @@ for subdir_name in sorted(os.listdir(packages_dir)):
# Do not depend on any sub package # Do not depend on any sub package
this_package.remaining_dependencies.difference_update(this_package.sub_packages) this_package.remaining_dependencies.difference_update(this_package.sub_packages)
for package in all_packages: for package in all_packages:
for remaining in package.remaining_dependencies: for remaining in package.remaining_dependencies:
if remaining not in packages_map: if remaining not in packages_map:
die('Package ' + package.name + ' depends on non-existing package "' + remaining + '"') die('Package %s depends on non-existing package "%s"' % (
package.name, remaining
))
packages_map[remaining].prerequisite_for.add(package) packages_map[remaining].prerequisite_for.add(package)
# List of all DebianPackage:s without dependencies # List of all DebianPackage:s without dependencies
packages_without_deps = [p for p in all_packages if not p.remaining_dependencies] packages_without_deps = [p for p in all_packages if not p.remaining_dependencies]
if not packages_without_deps: if not packages_without_deps:
die('No package without dependency - where to start?') die('No package without dependency - where to start?')
# Sort alphabetically, but with libandroid-support first (since dependency on libandroid-support # Sort alphabetically, but with libandroid-support first (since dependency on libandroid-support
# does not need to be declared explicitly, so anything might in theory depend on it to build): # does not need to be declared explicitly, so anything might in theory depend on it to build):
packages_without_deps.sort( packages_without_deps.sort(
key=lambda p: '' if p.name == 'libandroid-support' else p.name, key=lambda p: '' if p.name == 'libandroid-support' else p.name,
reverse=True) reverse=True)
# Topological sorting # Topological sorting
build_order = [] build_order = []
while packages_without_deps: while packages_without_deps:
pkg = packages_without_deps.pop() pkg = packages_without_deps.pop()
build_order.append(pkg) build_order.append(pkg)
for other_package in pkg.prerequisite_for: for other_package in pkg.prerequisite_for:
@ -102,12 +106,15 @@ while packages_without_deps:
# Check if the other package is ready to build now # Check if the other package is ready to build now
packages_without_deps.append(other_package) packages_without_deps.append(other_package)
if len(all_packages) != len(build_order): if len(all_packages) != len(build_order):
print("ERROR: Cycle exists. Remaining: ") print("ERROR: Cycle exists. Remaining: ")
for pkg in all_packages: for pkg in all_packages:
if pkg not in build_order: if pkg not in build_order:
print(pkg.name) print(pkg.name)
sys.exit(1) sys.exit(1)
for pkg in build_order: for pkg in build_order:
print(pkg.name) print(pkg.name)
if __name__ == '__main__':
main()

Loading…
Cancel
Save