From e34ae5da030d990f1d5b2b2af65d0a8cd9cecb51 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sat, 21 Aug 2021 18:02:31 +0200 Subject: [PATCH] build-package: mv code for getting deps out of step_start_build Into new function termux_step_get_dependencies. --- build-package.sh | 5 ++ scripts/build/termux_step_get_dependencies.sh | 69 +++++++++++++++++++ scripts/build/termux_step_start_build.sh | 67 ------------------ 3 files changed, 74 insertions(+), 67 deletions(-) create mode 100644 scripts/build/termux_step_get_dependencies.sh diff --git a/build-package.sh b/build-package.sh index ae4ff85d4..a81b3a449 100755 --- a/build-package.sh +++ b/build-package.sh @@ -103,6 +103,10 @@ source "$TERMUX_SCRIPTDIR/scripts/build/termux_get_repo_files.sh" # shellcheck source=scripts/build/termux_step_start_build.sh source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_start_build.sh" +# Download or build dependencies. Not to be overridden by packages. +# shellcheck source=scripts/build/termux_step_get_dependencies.sh +source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_get_dependencies.sh" + # Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. Can be overridden by packages. # shellcheck source=scripts/build/get_source/termux_step_get_source.sh source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_step_get_source.sh" @@ -365,6 +369,7 @@ while (($# > 0)); do termux_step_setup_variables termux_step_handle_buildarch termux_step_start_build + termux_step_get_dependencies cd "$TERMUX_PKG_CACHEDIR" termux_step_get_source cd "$TERMUX_PKG_SRCDIR" diff --git a/scripts/build/termux_step_get_dependencies.sh b/scripts/build/termux_step_get_dependencies.sh new file mode 100644 index 000000000..51e5d5326 --- /dev/null +++ b/scripts/build/termux_step_get_dependencies.sh @@ -0,0 +1,69 @@ +termux_step_get_dependencies() { + if [ "$TERMUX_SKIP_DEPCHECK" = false ] && [ "$TERMUX_INSTALL_DEPS" = true ] && [ "$TERMUX_PKG_METAPACKAGE" = "false" ]; then + # Download repo files + termux_get_repo_files + + # When doing build on device, ensure that apt lists are up-to-date. + [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] && apt update + + # Download dependencies + while read PKG PKG_DIR; do + if [ -z $PKG ]; then + continue + elif [ "$PKG" = "ERROR" ]; then + termux_error_exit "Obtaining buildorder failed" + fi + # llvm doesn't build if ndk-sysroot is installed: + if [ "$PKG" = "ndk-sysroot" ]; then continue; fi + read DEP_ARCH DEP_VERSION <<< $(termux_extract_dep_info $PKG "${PKG_DIR}") + + if [ ! "$TERMUX_QUIET_BUILD" = true ]; then + echo "Downloading dependency $PKG@$DEP_VERSION if necessary..." + fi + + if [ -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG" ]; then + if [ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG")" = "$DEP_VERSION" ]; then + continue + fi + fi + + if ! termux_download_deb $PKG $DEP_ARCH $DEP_VERSION; then + echo "Download of $PKG@$DEP_VERSION from $TERMUX_REPO_URL failed, building instead" + TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh -I "${PKG_DIR}" + continue + fi + if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then + if [ ! "$TERMUX_QUIET_BUILD" = true ]; then + echo "extracting $PKG..." + fi + ( + cd $TERMUX_COMMON_CACHEDIR-$DEP_ARCH + ar x ${PKG}_${DEP_VERSION}_${DEP_ARCH}.deb data.tar.xz + if tar -tf data.tar.xz|grep "^./$">/dev/null; then + # Strip prefixed ./, to avoid possible + # permission errors from tar + tar -xf data.tar.xz --strip-components=1 \ + --no-overwrite-dir -C / + else + tar -xf data.tar.xz --no-overwrite-dir -C / + fi + ) + fi + + mkdir -p $TERMUX_BUILT_PACKAGES_DIRECTORY + echo "$DEP_VERSION" > "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG" + done<<<$(./scripts/buildorder.py -i "$TERMUX_PKG_BUILDER_DIR" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR") + elif [ "$TERMUX_SKIP_DEPCHECK" = false ] && [ "$TERMUX_INSTALL_DEPS" = false ] && [ "$TERMUX_PKG_METAPACKAGE" = "false" ]; then + # Build dependencies + while read PKG PKG_DIR; do + if [ -z $PKG ]; then + continue + elif [ "$PKG" = "ERROR" ]; then + termux_error_exit "Obtaining buildorder failed" + fi + echo "Building dependency $PKG if necessary..." + # Built dependencies are put in the default TERMUX_DEBDIR instead of the specified one + TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh -s "${PKG_DIR}" + done<<<$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR") + fi +} diff --git a/scripts/build/termux_step_start_build.sh b/scripts/build/termux_step_start_build.sh index d2f6c32d9..f235988ff 100644 --- a/scripts/build/termux_step_start_build.sh +++ b/scripts/build/termux_step_start_build.sh @@ -47,73 +47,6 @@ termux_step_start_build() { fi fi - if [ "$TERMUX_SKIP_DEPCHECK" = false ] && [ "$TERMUX_INSTALL_DEPS" = true ] && [ "$TERMUX_PKG_METAPACKAGE" = "false" ]; then - # Download repo files - termux_get_repo_files - - # When doing build on device, ensure that apt lists are up-to-date. - [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] && apt update - - # Download dependencies - while read PKG PKG_DIR; do - if [ -z $PKG ]; then - continue - elif [ "$PKG" = "ERROR" ]; then - termux_error_exit "Obtaining buildorder failed" - fi - # llvm doesn't build if ndk-sysroot is installed: - if [ "$PKG" = "ndk-sysroot" ]; then continue; fi - read DEP_ARCH DEP_VERSION <<< $(termux_extract_dep_info $PKG "${PKG_DIR}") - - if [ ! "$TERMUX_QUIET_BUILD" = true ]; then - echo "Downloading dependency $PKG@$DEP_VERSION if necessary..." - fi - - if [ -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG" ]; then - if [ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG")" = "$DEP_VERSION" ]; then - continue - fi - fi - - if ! termux_download_deb $PKG $DEP_ARCH $DEP_VERSION; then - echo "Download of $PKG@$DEP_VERSION from $TERMUX_REPO_URL failed, building instead" - TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh -I "${PKG_DIR}" - continue - fi - if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then - if [ ! "$TERMUX_QUIET_BUILD" = true ]; then - echo "extracting $PKG..." - fi - ( - cd $TERMUX_COMMON_CACHEDIR-$DEP_ARCH - ar x ${PKG}_${DEP_VERSION}_${DEP_ARCH}.deb data.tar.xz - if tar -tf data.tar.xz|grep "^./$">/dev/null; then - # Strip prefixed ./, to avoid possible - # permission errors from tar - tar -xf data.tar.xz --strip-components=1 \ - --no-overwrite-dir -C / - else - tar -xf data.tar.xz --no-overwrite-dir -C / - fi - ) - fi - - mkdir -p $TERMUX_BUILT_PACKAGES_DIRECTORY - echo "$DEP_VERSION" > "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG" - done<<<$(./scripts/buildorder.py -i "$TERMUX_PKG_BUILDER_DIR" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR") - elif [ "$TERMUX_SKIP_DEPCHECK" = false ] && [ "$TERMUX_INSTALL_DEPS" = false ] && [ "$TERMUX_PKG_METAPACKAGE" = "false" ]; then - # Build dependencies - while read PKG PKG_DIR; do - if [ -z $PKG ]; then - continue - elif [ "$PKG" = "ERROR" ]; then - termux_error_exit "Obtaining buildorder failed" - fi - echo "Building dependency $PKG if necessary..." - # Built dependencies are put in the default TERMUX_DEBDIR instead of the specified one - TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh -s "${PKG_DIR}" - done<<<$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR") - fi if [ "$TERMUX_INSTALL_DEPS" == true ] && [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libllvm/}" ]; then LLVM_DEFAULT_TARGET_TRIPLE=$TERMUX_HOST_PLATFORM if [ $TERMUX_ARCH = "arm" ]; then