|
@ -73,16 +73,14 @@ class TermuxBuildFile(object): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TermuxPackage(object): |
|
|
class TermuxPackage(object): |
|
|
PACKAGES_DIR = 'packages' |
|
|
def __init__(self, dir_path): |
|
|
|
|
|
self.dir = dir_path |
|
|
def __init__(self, name): |
|
|
self.name = os.path.basename(self.dir) |
|
|
self.name = name |
|
|
|
|
|
self.dir = os.path.join(self.PACKAGES_DIR, name) |
|
|
|
|
|
|
|
|
|
|
|
# search package build.sh |
|
|
# search package build.sh |
|
|
build_sh_path = os.path.join(self.dir, 'build.sh') |
|
|
build_sh_path = os.path.join(self.dir, 'build.sh') |
|
|
if not os.path.isfile(build_sh_path): |
|
|
if not os.path.isfile(build_sh_path): |
|
|
raise Exception("build.sh not found for package '" + name + "'") |
|
|
raise Exception("build.sh not found for package '" + self.name + "'") |
|
|
|
|
|
|
|
|
self.buildfile = TermuxBuildFile(build_sh_path) |
|
|
self.buildfile = TermuxBuildFile(build_sh_path) |
|
|
self.deps = self.buildfile._get_dependencies() |
|
|
self.deps = self.buildfile._get_dependencies() |
|
@ -94,11 +92,8 @@ class TermuxPackage(object): |
|
|
self.subpkgs = [] |
|
|
self.subpkgs = [] |
|
|
|
|
|
|
|
|
for filename in os.listdir(self.dir): |
|
|
for filename in os.listdir(self.dir): |
|
|
if not filename.endswith('.subpackage.sh'): |
|
|
if not filename.endswith('.subpackage.sh'): continue |
|
|
continue |
|
|
subpkg = TermuxSubPackage(self.dir + '/' + filename, self) |
|
|
|
|
|
|
|
|
subpkg_name = filename.split('.subpackage.sh')[0] |
|
|
|
|
|
subpkg = TermuxSubPackage(subpkg_name, parent=self) |
|
|
|
|
|
|
|
|
|
|
|
self.subpkgs.append(subpkg) |
|
|
self.subpkgs.append(subpkg) |
|
|
self.deps |= subpkg.deps |
|
|
self.deps |= subpkg.deps |
|
@ -115,14 +110,13 @@ class TermuxPackage(object): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TermuxSubPackage(TermuxPackage): |
|
|
class TermuxSubPackage(TermuxPackage): |
|
|
|
|
|
def __init__(self, subpackage_file_path, parent): |
|
|
def __init__(self, name, parent=None): |
|
|
|
|
|
if parent is None: |
|
|
if parent is None: |
|
|
raise Exception("SubPackages should have a parent") |
|
|
raise Exception("SubPackages should have a parent") |
|
|
|
|
|
|
|
|
self.name = name |
|
|
self.buildfile = TermuxBuildFile(subpackage_file_path) |
|
|
|
|
|
self.name = os.path.basename(subpackage_file_path).split('.subpackage.sh')[0] |
|
|
self.parent = parent |
|
|
self.parent = parent |
|
|
self.buildfile = TermuxBuildFile(os.path.join(self.parent.dir, name + '.subpackage.sh')) |
|
|
|
|
|
self.deps = self.buildfile._get_dependencies() |
|
|
self.deps = self.buildfile._get_dependencies() |
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
def __repr__(self): |
|
@ -139,16 +133,20 @@ pkgs_map = {} |
|
|
# Reverse dependencies |
|
|
# Reverse dependencies |
|
|
pkg_depends_on = {} |
|
|
pkg_depends_on = {} |
|
|
|
|
|
|
|
|
PACKAGES_DIR = 'packages' |
|
|
PACKAGES_DIRS = ['packages'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def populate(): |
|
|
def populate(): |
|
|
|
|
|
all_packages = [] |
|
|
|
|
|
for package_dir in PACKAGES_DIRS: |
|
|
|
|
|
for pkgdir_name in sorted(os.listdir(package_dir)): |
|
|
|
|
|
dir_path = package_dir + '/' + pkgdir_name |
|
|
|
|
|
if os.path.isfile(dir_path + '/build.sh'): |
|
|
|
|
|
all_packages.append(TermuxPackage(package_dir + '/' + pkgdir_name)) |
|
|
|
|
|
|
|
|
for pkgdir_name in sorted(os.listdir(PACKAGES_DIR)): |
|
|
for pkg in all_packages: |
|
|
|
|
|
if pkg.name in pkgs_map: die('Duplicated package: ' + pkg.name) |
|
|
pkg = TermuxPackage(pkgdir_name) |
|
|
else: pkgs_map[pkg.name] = pkg |
|
|
|
|
|
|
|
|
pkgs_map[pkg.name] = pkg |
|
|
|
|
|
|
|
|
|
|
|
for subpkg in pkg.subpkgs: |
|
|
for subpkg in pkg.subpkgs: |
|
|
pkgs_map[subpkg.name] = pkg |
|
|
pkgs_map[subpkg.name] = pkg |
|
@ -214,34 +212,50 @@ def generate_full_buildorder(): |
|
|
|
|
|
|
|
|
return build_order |
|
|
return build_order |
|
|
|
|
|
|
|
|
|
|
|
def deps(pkg): |
|
|
|
|
|
l = [] |
|
|
|
|
|
for dep in sorted(pkg.deps): |
|
|
|
|
|
l += deps_then_me(pkgs_map[dep]) |
|
|
|
|
|
return l |
|
|
|
|
|
|
|
|
def deps_then_me(pkg): |
|
|
def deps_then_me(pkg): |
|
|
l = [] |
|
|
l = [] |
|
|
|
|
|
|
|
|
for dep in sorted(pkg.deps): |
|
|
for dep in sorted(pkg.deps): |
|
|
l += deps_then_me(pkgs_map[dep]) |
|
|
l += deps_then_me(pkgs_map[dep]) |
|
|
l += [pkg] |
|
|
l += [pkg] |
|
|
|
|
|
|
|
|
return l |
|
|
return l |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_targets_buildorder(targetnames): |
|
|
def generate_targets_buildorder(target_paths): |
|
|
buildorder = [] |
|
|
buildorder = [] |
|
|
|
|
|
|
|
|
for pkgname in targetnames: |
|
|
for target_path in target_paths: |
|
|
|
|
|
if target_path.endswith('/'): target_path = target_path[:-1] |
|
|
|
|
|
pkgname = os.path.basename(target_path) |
|
|
if not pkgname in pkgs_map: |
|
|
if not pkgname in pkgs_map: |
|
|
die('Dependencies for ' + pkgname + ' could not be calculated (skip dependency check with -s)') |
|
|
die('Dependencies for ' + pkgname + ' could not be calculated (skip dependency check with -s)') |
|
|
buildorder += deps_then_me(pkgs_map[pkgname]) |
|
|
buildorder += deps(pkgs_map[pkgname]) |
|
|
|
|
|
|
|
|
return unique_everseen(buildorder) |
|
|
return unique_everseen(buildorder) |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
|
|
|
full_buildorder = len(sys.argv) == 1 |
|
|
|
|
|
if not full_buildorder: |
|
|
|
|
|
packages_real_path = os.path.realpath('packages') |
|
|
|
|
|
for path in sys.argv[1:]: |
|
|
|
|
|
if not os.path.isdir(path): |
|
|
|
|
|
die('Not a directory: ' + path) |
|
|
|
|
|
if path.endswith('/'): path = path[:-1] |
|
|
|
|
|
parent_path = os.path.dirname(path) |
|
|
|
|
|
if packages_real_path != os.path.realpath(parent_path): |
|
|
|
|
|
PACKAGES_DIRS.append(parent_path) |
|
|
|
|
|
|
|
|
populate() |
|
|
populate() |
|
|
|
|
|
|
|
|
if len(sys.argv) == 1: |
|
|
if full_buildorder: |
|
|
bo = generate_full_buildorder() |
|
|
bo = generate_full_buildorder() |
|
|
else: |
|
|
else: |
|
|
bo = generate_targets_buildorder(sys.argv[1:]) |
|
|
bo = generate_targets_buildorder(sys.argv[1:]) |
|
|
|
|
|
|
|
|
for pkg in bo: |
|
|
for pkg in bo: |
|
|
print(pkg.name) |
|
|
print(pkg.dir) |
|
|