Browse Source

buildorder.py: wrap main()

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

167
buildorder.py

@ -30,84 +30,91 @@ packages_map = {}
packages_dir = 'packages' packages_dir = 'packages'
for subdir_name in sorted(os.listdir(packages_dir)): def main():
subdir_path = packages_dir + '/' + subdir_name for subdir_name in sorted(os.listdir(packages_dir)):
subdir_path = packages_dir + '/' + subdir_name
if os.path.exists(subdir_path + '/BROKEN.txt'):
continue if os.path.exists(subdir_path + '/BROKEN.txt'):
continue
build_sh_path = subdir_path + '/build.sh'
build_sh_path = subdir_path + '/build.sh'
this_package = DebianPackage(subdir_name)
all_packages.append(this_package) this_package = DebianPackage(subdir_name)
packages_map[this_package.name] = this_package all_packages.append(this_package)
packages_map[this_package.name] = this_package
if not os.path.isfile(build_sh_path):
die('The directory ' + subdir_name + ' does not contain build.sh') if not os.path.isfile(build_sh_path):
die('The directory ' + subdir_name + ' does not contain build.sh')
with open(build_sh_path) as build_sh_file:
for line in build_sh_file: with open(build_sh_path) as build_sh_file:
if line.startswith('TERMUX_PKG_DEPENDS='): for line in build_sh_file:
deps_comma_separated = line[(line.index('=')+2):(len(line)-2)] if line.startswith('TERMUX_PKG_DEPENDS='):
for dep in deps_comma_separated.split(','): deps_comma_separated = line[(line.index('=')+2):(len(line)-2)]
dep = dep.strip() for dep in deps_comma_separated.split(','):
if not dep.endswith('libandroid-support-dev'): dep = dep.strip()
this_package.remaining_dependencies.add(dep) if not dep.endswith('libandroid-support-dev'):
for file_in_subdir_name in sorted(os.listdir(subdir_path)):
if file_in_subdir_name.endswith('.subpackage.sh'):
subpackage_name = file_in_subdir_name[0:-len(".subpackage.sh"):]
this_package.sub_packages.add(subpackage_name)
packages_map[subpackage_name] = this_package
with open(subdir_path + '/' + file_in_subdir_name) as subpackage_sh_file:
for line in subpackage_sh_file:
if line.startswith('TERMUX_SUBPKG_DEPENDS='):
deps_comma_separated = line[(line.index('=')+2):(len(line)-2)]
for dep in deps_comma_separated.split(','):
dep = dep.strip()
this_package.remaining_dependencies.add(dep) this_package.remaining_dependencies.add(dep)
# Do not depend on itself
this_package.remaining_dependencies.discard(this_package.name) for file_in_subdir_name in sorted(os.listdir(subdir_path)):
# Do not depend on any sub package if file_in_subdir_name.endswith('.subpackage.sh'):
this_package.remaining_dependencies.difference_update(this_package.sub_packages) subpackage_name = file_in_subdir_name[0:-len(".subpackage.sh"):]
this_package.sub_packages.add(subpackage_name)
for package in all_packages: packages_map[subpackage_name] = this_package
for remaining in package.remaining_dependencies: with open(subdir_path + '/' + file_in_subdir_name) as subpackage_sh_file:
if remaining not in packages_map: for line in subpackage_sh_file:
die('Package ' + package.name + ' depends on non-existing package "' + remaining + '"') if line.startswith('TERMUX_SUBPKG_DEPENDS='):
packages_map[remaining].prerequisite_for.add(package) deps_comma_separated = line[(line.index('=')+2):(len(line)-2)]
for dep in deps_comma_separated.split(','):
# List of all DebianPackage:s without dependencies dep = dep.strip()
packages_without_deps = [p for p in all_packages if not p.remaining_dependencies] this_package.remaining_dependencies.add(dep)
if not packages_without_deps: # Do not depend on itself
die('No package without dependency - where to start?') this_package.remaining_dependencies.discard(this_package.name)
# Do not depend on any sub package
# Sort alphabetically, but with libandroid-support first (since dependency on libandroid-support this_package.remaining_dependencies.difference_update(this_package.sub_packages)
# does not need to be declared explicitly, so anything might in theory depend on it to build):
for package in all_packages:
packages_without_deps.sort( for remaining in package.remaining_dependencies:
key=lambda p: '' if p.name == 'libandroid-support' else p.name, if remaining not in packages_map:
reverse=True) die('Package %s depends on non-existing package "%s"' % (
package.name, remaining
# Topological sorting ))
build_order = [] packages_map[remaining].prerequisite_for.add(package)
while packages_without_deps:
pkg = packages_without_deps.pop() # List of all DebianPackage:s without dependencies
build_order.append(pkg) packages_without_deps = [p for p in all_packages if not p.remaining_dependencies]
for other_package in pkg.prerequisite_for: if not packages_without_deps:
# Remove this package die('No package without dependency - where to start?')
other_package.remaining_dependencies.discard(pkg.name)
# .. and all its subpackages # Sort alphabetically, but with libandroid-support first (since dependency on libandroid-support
other_package.remaining_dependencies.difference_update(pkg.sub_packages) # does not need to be declared explicitly, so anything might in theory depend on it to build):
if not other_package.remaining_dependencies:
# Check if the other package is ready to build now packages_without_deps.sort(
packages_without_deps.append(other_package) key=lambda p: '' if p.name == 'libandroid-support' else p.name,
reverse=True)
if len(all_packages) != len(build_order):
print("ERROR: Cycle exists. Remaining: ") # Topological sorting
for pkg in all_packages: build_order = []
if pkg not in build_order: while packages_without_deps:
print(pkg.name) pkg = packages_without_deps.pop()
sys.exit(1) build_order.append(pkg)
for other_package in pkg.prerequisite_for:
for pkg in build_order: # Remove this package
print(pkg.name) other_package.remaining_dependencies.discard(pkg.name)
# .. and all its subpackages
other_package.remaining_dependencies.difference_update(pkg.sub_packages)
if not other_package.remaining_dependencies:
# Check if the other package is ready to build now
packages_without_deps.append(other_package)
if len(all_packages) != len(build_order):
print("ERROR: Cycle exists. Remaining: ")
for pkg in all_packages:
if pkg not in build_order:
print(pkg.name)
sys.exit(1)
for pkg in build_order:
print(pkg.name)
if __name__ == '__main__':
main()

Loading…
Cancel
Save