build-package: add new arg -c for "continue build"

As replacement for TERMUX_PKG_QUICK_REBUILD. Running
./build-package.sh -c <package> starts a build for <package>, but does
not extract and patch the source from scratch. Instead it sets up the
build variables and starts from termux_step_make.

When working on a big package that can take hours to build it is
convenient to be able to build until there is an error, then apply
some new patch (manually) to the source, and then continue from where
the build failed.
This commit is contained in:
Henrik Grimler 2021-08-21 18:08:57 +02:00
parent a636bfa2da
commit ecd214881a
9 changed files with 161 additions and 137 deletions

View File

@ -276,7 +276,7 @@ _show_usage() {
exit 1 exit 1
} }
while getopts :a:hdDfiIqso: option; do while getopts :a:hdDfiIqso:c option; do
case "$option" in case "$option" in
a) a)
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
@ -300,6 +300,7 @@ while getopts :a:hdDfiIqso: option; do
q) export TERMUX_QUIET_BUILD=true;; q) export TERMUX_QUIET_BUILD=true;;
s) export TERMUX_SKIP_DEPCHECK=true;; s) export TERMUX_SKIP_DEPCHECK=true;;
o) TERMUX_DEBDIR=$(realpath -m "$OPTARG");; o) TERMUX_DEBDIR=$(realpath -m "$OPTARG");;
c) TERMUX_CONTINUE_BUILD="true";;
?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";; ?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";;
esac esac
done done
@ -373,22 +374,38 @@ while (($# > 0)); do
termux_step_setup_variables termux_step_setup_variables
termux_step_handle_buildarch termux_step_handle_buildarch
termux_step_start_build termux_step_start_build
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
termux_step_get_dependencies termux_step_get_dependencies
fi
termux_step_create_timestamp_file termux_step_create_timestamp_file
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
cd "$TERMUX_PKG_CACHEDIR" cd "$TERMUX_PKG_CACHEDIR"
termux_step_get_source termux_step_get_source
cd "$TERMUX_PKG_SRCDIR" cd "$TERMUX_PKG_SRCDIR"
termux_step_post_get_source termux_step_post_get_source
termux_step_handle_hostbuild termux_step_handle_hostbuild
fi
termux_step_setup_toolchain termux_step_setup_toolchain
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
termux_step_patch_package termux_step_patch_package
termux_step_replace_guess_scripts termux_step_replace_guess_scripts
cd "$TERMUX_PKG_SRCDIR" cd "$TERMUX_PKG_SRCDIR"
termux_step_pre_configure termux_step_pre_configure
fi
# Even on continued build we might need to setup paths
# to tools so need to run part of configure step
cd "$TERMUX_PKG_BUILDDIR" cd "$TERMUX_PKG_BUILDDIR"
termux_step_configure termux_step_configure
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
cd "$TERMUX_PKG_BUILDDIR" cd "$TERMUX_PKG_BUILDDIR"
termux_step_post_configure termux_step_post_configure
fi
cd "$TERMUX_PKG_BUILDDIR" cd "$TERMUX_PKG_BUILDDIR"
termux_step_make termux_step_make
cd "$TERMUX_PKG_BUILDDIR" cd "$TERMUX_PKG_BUILDDIR"

View File

@ -64,11 +64,9 @@ termux_step_host_build() {
} }
termux_step_pre_configure() { termux_step_pre_configure() {
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
mkdir openmp/runtime/src/android mkdir openmp/runtime/src/android
cp $TERMUX_PKG_BUILDER_DIR/nl_types.h openmp/runtime/src/android cp $TERMUX_PKG_BUILDER_DIR/nl_types.h openmp/runtime/src/android
cp $TERMUX_PKG_BUILDER_DIR/nltypes_stubs.cpp openmp/runtime/src/android cp $TERMUX_PKG_BUILDER_DIR/nltypes_stubs.cpp openmp/runtime/src/android
fi
# Add unknown vendor, otherwise it screws with the default LLVM triple # Add unknown vendor, otherwise it screws with the default LLVM triple
# detection. # detection.

View File

@ -24,7 +24,6 @@ SWIFT_BINDIR="$TERMUX_PKG_HOSTBUILD_DIR/$SWIFT_BIN/usr/bin"
fi fi
termux_step_post_get_source() { termux_step_post_get_source() {
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
# The Swift build-script requires a particular organization of source # The Swift build-script requires a particular organization of source
# directories, which the following sets up. # directories, which the following sets up.
mkdir .temp mkdir .temp
@ -78,7 +77,7 @@ termux_step_post_get_source() {
$TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz \ $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz \
86b849d9f6ba2eda4e12ea5eafaa0748bffcd6272466b514c2b0fd4a829c63a4 86b849d9f6ba2eda4e12ea5eafaa0748bffcd6272466b514c2b0fd4a829c63a4
fi fi
fi
# The Swift compiler searches for the clang headers so symlink against them. # The Swift compiler searches for the clang headers so symlink against them.
export TERMUX_CLANG_VERSION=$(grep ^TERMUX_PKG_VERSION= $TERMUX_PKG_BUILDER_DIR/../libllvm/build.sh | cut -f2 -d=) export TERMUX_CLANG_VERSION=$(grep ^TERMUX_PKG_VERSION= $TERMUX_PKG_BUILDER_DIR/../libllvm/build.sh | cut -f2 -d=)
} }
@ -103,7 +102,6 @@ termux_step_host_build() {
termux_step_pre_configure() { termux_step_pre_configure() {
export SWIFT_ARCH=$TERMUX_ARCH export SWIFT_ARCH=$TERMUX_ARCH
test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7' test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7'
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
cd llbuild cd llbuild
# A single patch needed from the existing llbuild package # A single patch needed from the existing llbuild package
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../llbuild/lib-llvm-Support-CmakeLists.txt.patch patch -p1 < $TERMUX_PKG_BUILDER_DIR/../llbuild/lib-llvm-Support-CmakeLists.txt.patch
@ -125,7 +123,6 @@ termux_step_pre_configure() {
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" | \ sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" | \
sed "s%\@SWIFT_ARCH\@%${SWIFT_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json sed "s%\@SWIFT_ARCH\@%${SWIFT_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json
fi fi
fi
} }
termux_step_make() { termux_step_make() {

View File

@ -2,10 +2,23 @@ termux_step_configure() {
[ "$TERMUX_PKG_METAPACKAGE" = "true" ] && return [ "$TERMUX_PKG_METAPACKAGE" = "true" ] && return
if [ "$TERMUX_PKG_FORCE_CMAKE" = "false" ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then if [ "$TERMUX_PKG_FORCE_CMAKE" = "false" ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then
if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then
return;
fi
termux_step_configure_autotools termux_step_configure_autotools
elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then elif [ "$TERMUX_PKG_FORCE_CMAKE" = "true" ] || [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then
if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then
termux_setup_cmake
if [ "$TERMUX_CMAKE_BUILD" = Ninja ]; then
termux_setup_ninja
fi
return;
fi
termux_step_configure_cmake termux_step_configure_cmake
elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then
if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then
return;
fi
termux_step_configure_meson termux_step_configure_meson
fi fi
} }

View File

@ -14,6 +14,9 @@ termux_step_configure_cmake() {
MAKE_PROGRAM_PATH=$(command -v make) MAKE_PROGRAM_PATH=$(command -v make)
fi fi
if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then
return
fi
local CMAKE_ADDITIONAL_ARGS=() local CMAKE_ADDITIONAL_ARGS=()
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
CXXFLAGS+=" --target=$CCTERMUX_HOST_PLATFORM" CXXFLAGS+=" --target=$CCTERMUX_HOST_PLATFORM"

View File

@ -3,19 +3,15 @@ termux_step_handle_hostbuild() {
[ "$TERMUX_PKG_HOSTBUILD" = "false" ] && return [ "$TERMUX_PKG_HOSTBUILD" = "false" ] && return
cd "$TERMUX_PKG_SRCDIR" cd "$TERMUX_PKG_SRCDIR"
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do
echo "Applying patch: $(basename $patch)" echo "Applying patch: $(basename $patch)"
test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1 test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1
done done
fi
local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION" local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION"
if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR" rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR"
mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR" mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR"
fi
cd "$TERMUX_PKG_HOSTBUILD_DIR" cd "$TERMUX_PKG_HOSTBUILD_DIR"
termux_step_host_build termux_step_host_build
touch "$TERMUX_HOSTBUILD_MARKER" touch "$TERMUX_HOSTBUILD_MARKER"

View File

@ -6,7 +6,6 @@ termux_step_patch_package() {
if [ "$TERMUX_DEBUG_BUILD" = "true" ]; then if [ "$TERMUX_DEBUG_BUILD" = "true" ]; then
DEBUG_PATCHES=$(find $TERMUX_PKG_BUILDER_DIR -mindepth 1 -maxdepth 1 -name \*.patch.debug) DEBUG_PATCHES=$(find $TERMUX_PKG_BUILDER_DIR -mindepth 1 -maxdepth 1 -name \*.patch.debug)
fi fi
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
# Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses:
shopt -s nullglob shopt -s nullglob
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,} $DEBUG_PATCHES; do for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,} $DEBUG_PATCHES; do
@ -20,5 +19,4 @@ termux_step_patch_package() {
"$patch" | patch --silent -p1 "$patch" | patch --silent -p1
done done
shopt -u nullglob shopt -u nullglob
fi
} }

View File

@ -8,6 +8,7 @@ termux_step_setup_variables() {
: "${TERMUX_NO_CLEAN:="false"}" : "${TERMUX_NO_CLEAN:="false"}"
: "${TERMUX_PACKAGES_DIRECTORIES:="packages"}" : "${TERMUX_PACKAGES_DIRECTORIES:="packages"}"
: "${TERMUX_PKG_API_LEVEL:="24"}" : "${TERMUX_PKG_API_LEVEL:="24"}"
: "${TERMUX_CONTINUE_BUILD:="false"}"
: "${TERMUX_QUIET_BUILD:="false"}" : "${TERMUX_QUIET_BUILD:="false"}"
: "${TERMUX_SKIP_DEPCHECK:="false"}" : "${TERMUX_SKIP_DEPCHECK:="false"}"
: "${TERMUX_TOPDIR:="$HOME/.termux-build"}" : "${TERMUX_TOPDIR:="$HOME/.termux-build"}"
@ -122,7 +123,6 @@ termux_step_setup_variables() {
TERMUX_PKG_PLATFORM_INDEPENDENT=false TERMUX_PKG_PLATFORM_INDEPENDENT=false
TERMUX_PKG_PRE_DEPENDS="" TERMUX_PKG_PRE_DEPENDS=""
TERMUX_PKG_PROVIDES="" #https://www.debian.org/doc/debian-policy/#virtual-packages-provides TERMUX_PKG_PROVIDES="" #https://www.debian.org/doc/debian-policy/#virtual-packages-provides
TERMUX_PKG_QUICK_REBUILD=false # set this temporarily when iterating on a large package and you don't want the source and build directories wiped every time you make a mistake
TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
TERMUX_PKG_REPLACES="" TERMUX_PKG_REPLACES=""
TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

View File

@ -47,6 +47,23 @@ termux_step_start_build() {
fi fi
fi fi
echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..."
test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME"
# Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build.
export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig
if [ "$TERMUX_PKG_BUILD_IN_SRC" = "true" ]; then
echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set to true" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt"
TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR
fi
if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then
# Do not remove source dir on continued builds, the
# rest in this function can be skipped in this case
return
fi
if [ "$TERMUX_INSTALL_DEPS" == true ] && [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libllvm/}" ]; then if [ "$TERMUX_INSTALL_DEPS" == true ] && [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libllvm/}" ]; then
LLVM_DEFAULT_TARGET_TRIPLE=$TERMUX_HOST_PLATFORM LLVM_DEFAULT_TARGET_TRIPLE=$TERMUX_HOST_PLATFORM
if [ $TERMUX_ARCH = "arm" ]; then if [ $TERMUX_ARCH = "arm" ]; then
@ -68,7 +85,6 @@ termux_step_start_build() {
-e "s|@TERMUX_ARCH@|$TERMUX_ARCH|g" > $TERMUX_PREFIX/bin/llvm-config -e "s|@TERMUX_ARCH@|$TERMUX_ARCH|g" > $TERMUX_PREFIX/bin/llvm-config
chmod 755 $TERMUX_PREFIX/bin/llvm-config chmod 755 $TERMUX_PREFIX/bin/llvm-config
fi fi
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
# Following directories may contain files with read-only permissions which # Following directories may contain files with read-only permissions which
# makes them undeletable. We need to fix that. # makes them undeletable. We need to fix that.
[ -d "$TERMUX_PKG_BUILDDIR" ] && chmod +w -R "$TERMUX_PKG_BUILDDIR" [ -d "$TERMUX_PKG_BUILDDIR" ] && chmod +w -R "$TERMUX_PKG_BUILDDIR"
@ -77,9 +93,6 @@ termux_step_start_build() {
# Cleanup old build state: # Cleanup old build state:
rm -Rf "$TERMUX_PKG_BUILDDIR" \ rm -Rf "$TERMUX_PKG_BUILDDIR" \
"$TERMUX_PKG_SRCDIR" "$TERMUX_PKG_SRCDIR"
else
TERMUX_PKG_SKIP_SRC_EXTRACT=true
fi
# Cleanup old packaging state: # Cleanup old packaging state:
rm -Rf "$TERMUX_PKG_PACKAGEDIR" \ rm -Rf "$TERMUX_PKG_PACKAGEDIR" \
@ -111,15 +124,4 @@ termux_step_start_build() {
g++ -std=c++11 -Wall -Wextra -pedantic -Os -D__ANDROID_API__=$TERMUX_PKG_API_LEVEL \ g++ -std=c++11 -Wall -Wextra -pedantic -Os -D__ANDROID_API__=$TERMUX_PKG_API_LEVEL \
"$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER" "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER"
fi fi
if [ "$TERMUX_PKG_BUILD_IN_SRC" = "true" ]; then
echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set to true" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt"
TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR
fi
echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..."
test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME"
# Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build.
export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig
} }