Browse Source

Enable dependency checks for out-of-tree packages

When building an out-of-tree package, as in
	./build-package.sh path/to/my-package.sh
dependency checks now works.
android-5
Fredrik Fornwall 7 years ago
parent
commit
02764a913f
  1. 3
      build-all.sh
  2. 6
      build-package.sh
  3. 70
      scripts/buildorder.py

3
build-all.sh

@ -47,7 +47,8 @@ exec > >(tee -a $BUILDALL_DIR/ALL.out)
exec 2> >(tee -a $BUILDALL_DIR/ALL.err >&2)
trap "echo ERROR: See $BUILDALL_DIR/\${package}.err" ERR
for package in `cat $BUILDORDER_FILE`; do
for package_path in `cat $BUILDORDER_FILE`; do
package=`basename $package_path`
# Check build status (grepping is a bit crude, but it works)
if [ -e $BUILDSTATUS_FILE ] && grep "^$package\$" $BUILDSTATUS_FILE >/dev/null; then
echo "Skipping $package"

6
build-package.sh

@ -229,8 +229,6 @@ termux_step_handle_arguments() {
if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi
export TERMUX_PKG_BUILDER_DIR
TERMUX_PKG_BUILDER_DIR=$(realpath "$1")
# Skip depcheck for external package:
TERMUX_SKIP_DEPCHECK=true
else
# Package name:
if [ -n "${TERMUX_IS_DISABLED=""}" ]; then
@ -375,12 +373,10 @@ termux_step_start_build() {
if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then
local p TERMUX_ALL_DEPS
TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_NAME")
TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR")
for p in $TERMUX_ALL_DEPS; do
if [ "$p" != "$TERMUX_PKG_NAME" ]; then
echo "Building dependency $p if necessary..."
./build-package.sh -a $TERMUX_ARCH -s "$p"
fi
done
fi

70
scripts/buildorder.py

@ -73,16 +73,14 @@ class TermuxBuildFile(object):
class TermuxPackage(object):
PACKAGES_DIR = 'packages'
def __init__(self, name):
self.name = name
self.dir = os.path.join(self.PACKAGES_DIR, name)
def __init__(self, dir_path):
self.dir = dir_path
self.name = os.path.basename(self.dir)
# search package build.sh
build_sh_path = os.path.join(self.dir, 'build.sh')
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.deps = self.buildfile._get_dependencies()
@ -94,11 +92,8 @@ class TermuxPackage(object):
self.subpkgs = []
for filename in os.listdir(self.dir):
if not filename.endswith('.subpackage.sh'):
continue
subpkg_name = filename.split('.subpackage.sh')[0]
subpkg = TermuxSubPackage(subpkg_name, parent=self)
if not filename.endswith('.subpackage.sh'): continue
subpkg = TermuxSubPackage(self.dir + '/' + filename, self)
self.subpkgs.append(subpkg)
self.deps |= subpkg.deps
@ -115,14 +110,13 @@ class TermuxPackage(object):
class TermuxSubPackage(TermuxPackage):
def __init__(self, name, parent=None):
def __init__(self, subpackage_file_path, parent):
if parent is None:
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.buildfile = TermuxBuildFile(os.path.join(self.parent.dir, name + '.subpackage.sh'))
self.deps = self.buildfile._get_dependencies()
def __repr__(self):
@ -139,16 +133,20 @@ pkgs_map = {}
# Reverse dependencies
pkg_depends_on = {}
PACKAGES_DIR = 'packages'
PACKAGES_DIRS = ['packages']
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)):
pkg = TermuxPackage(pkgdir_name)
pkgs_map[pkg.name] = pkg
for pkg in all_packages:
if pkg.name in pkgs_map: die('Duplicated package: ' + pkg.name)
else: pkgs_map[pkg.name] = pkg
for subpkg in pkg.subpkgs:
pkgs_map[subpkg.name] = pkg
@ -214,34 +212,50 @@ def generate_full_buildorder():
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):
l = []
for dep in sorted(pkg.deps):
l += deps_then_me(pkgs_map[dep])
l += [pkg]
return l
def generate_targets_buildorder(targetnames):
def generate_targets_buildorder(target_paths):
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:
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)
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()
if len(sys.argv) == 1:
if full_buildorder:
bo = generate_full_buildorder()
else:
bo = generate_targets_buildorder(sys.argv[1:])
for pkg in bo:
print(pkg.name)
print(pkg.dir)

Loading…
Cancel
Save