@ -107,13 +107,26 @@ class TermuxSubPackage:
self . name = os . path . basename ( subpackage_file_path ) . split ( ' .subpackage.sh ' ) [ 0 ]
self . parent = parent
self . deps = parse_build_file_dependencies ( subpackage_file_path )
self . dir = parent . dir
self . needed_by = set ( ) # Populated outside constructor, reverse of deps.
def __repr__ ( self ) :
return " < {} ' {} ' parent= ' {} ' > " . format ( self . __class__ . __name__ , self . name , self . parent )
def read_packages_from_directories ( directories ) :
def recursive_dependencies ( self , pkgs_map ) :
""" All the dependencies of the subpackage, both direct and indirect.
Only relevant when building in fast - build mode """
result = [ ]
for dependency_name in sorted ( self . deps ) :
dependency_package = pkgs_map [ dependency_name ]
result + = dependency_package . recursive_dependencies ( pkgs_map )
result + = [ dependency_package ]
return unique_everseen ( result )
def read_packages_from_directories ( directories , fast_build_mode ) :
""" Construct a map from package name to TermuxPackage.
For subpackages this maps from the subpackage name to the parent package . """
Subpackages are mapped to the parent package if fast_build_mode is fals e. """
pkgs_map = { }
all_packages = [ ]
@ -132,6 +145,8 @@ def read_packages_from_directories(directories):
for subpkg in new_package . subpkgs :
if subpkg . name in pkgs_map :
die ( ' Duplicated package: ' + subpkg . name )
elif fast_build_mode :
pkgs_map [ subpkg . name ] = subpkg
else :
pkgs_map [ subpkg . name ] = new_package
all_packages . append ( subpkg )
@ -141,7 +156,7 @@ def read_packages_from_directories(directories):
if dependency_name not in pkgs_map :
die ( ' Package %s depends on non-existing package " %s " ' % ( pkg . name , dependency_name ) )
dep_pkg = pkgs_map [ dependency_name ]
if not isinstance ( pkg , TermuxSubPackage ) :
if fast_build_mode or not isinstance ( pkg , TermuxSubPackage ) :
dep_pkg . needed_by . add ( pkg )
return pkgs_map
@ -198,7 +213,7 @@ def generate_full_buildorder(pkgs_map):
return build_order
def generate_target_buildorder ( target_path , pkgs_map ) :
def generate_target_buildorder ( target_path , pkgs_map , fast_build_mode ) :
" Generate a build order for building the dependencies of the specified package. "
if target_path . endswith ( ' / ' ) :
target_path = target_path [ : - 1 ]
@ -209,28 +224,50 @@ def generate_target_buildorder(target_path, pkgs_map):
def main ( ) :
" Generate the build order either for all packages or a specific one. "
packages_directories = [ ' packages ' ]
full_buildorder = len ( sys . argv ) == 1
import argparse
parser = argparse . ArgumentParser ( description = ' Generate order in which to build dependencies for a package. Generates ' )
parser . add_argument ( ' -i ' , default = False , action = ' store_true ' ,
help = ' Generate dependency list for fast-build mode. This includes subpackages in output since these can be downloaded. ' )
parser . add_argument ( ' package ' , nargs = ' ? ' ,
help = ' Package to generate dependency list for. ' )
parser . add_argument ( ' package_dirs ' , nargs = ' * ' ,
help = ' Directories with packages. Can for example point to " ../x11-packages/packages/ " . " packages/ " is appended automatically. ' )
args = parser . parse_args ( )
fast_build_mode = args . i
package = args . package
packages_directories = args . package_dirs + [ ' packages ' ]
if not package :
full_buildorder = True
else :
full_buildorder = False
if fast_build_mode and full_buildorder :
die ( ' -i mode does not work when building all packages ' )
if not full_buildorder :
packages_real_path = os . path . realpath ( ' packages ' )
for path in sys . argv [ 1 : ] :
for path in packages_directories :
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_directories . append ( parent_path )
pkgs_map = read_packages_from_directories ( packages_directories )
if package :
if package [ - 1 ] == " / " :
package = package [ : - 1 ]
if not os . path . isdir ( package ) :
die ( ' Not a directory: ' + package )
if not os . path . relpath ( os . path . dirname ( package ) , ' . ' ) in packages_directories :
packages_directories . insert ( 0 , os . path . dirname ( package ) )
pkgs_map = read_packages_from_directories ( packages_directories , fast_build_mode )
if full_buildorder :
build_order = generate_full_buildorder ( pkgs_map )
else :
build_order = generate_target_buildorder ( sys . argv [ 1 ] , pkgs_map )
build_order = generate_target_buildorder ( package , pkgs_map , fast_build_mode )
for pkg in build_order :
print ( pkg . dir )
print ( " %-30s %s " % ( pkg . name , pkg . dir ) )
if __name__ == ' __main__ ' :
main ( )