building packages: create termux_step_get_source function
Calls termux_git_clone_src if TERMUX_PKG_SRCURL ends with .git, and termux_download_src_archive and termux_extract_src_archive otherwise. termux_step_extract_package has been split up into the latter two functions. termux_step_post_extract_package has been renamed to termux_step_post_get_source to reflect these changes.
This commit is contained in:
parent
955a7b7c5c
commit
4e902a41a5
@ -89,17 +89,29 @@ source "$TERMUX_SCRIPTDIR/scripts/build/termux_download_deb.sh"
|
||||
# shellcheck source=scripts/build/termux_get_repo_files.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/termux_get_repo_files.sh"
|
||||
|
||||
# Source the package build script and start building. No to be overridden by packages.
|
||||
# Source the package build script and start building. Not to be overridden by packages.
|
||||
# shellcheck source=scripts/build/termux_step_start_build.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_start_build.sh"
|
||||
|
||||
# Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages.
|
||||
# shellcheck source=scripts/build/termux_step_extract_package.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_extract_package.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"
|
||||
|
||||
# Hook for packages to act just after the package has been extracted.
|
||||
# Invoked in $TERMUX_PKG_SRCDIR.
|
||||
termux_step_post_extract_package() {
|
||||
# Run from termux_step_get_source if TERMUX_PKG_SRCURL ends with .git.
|
||||
# shellcheck source=scripts/build/get_source/termux_step_get_source.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_git_clone_src.sh"
|
||||
|
||||
# Run from termux_step_get_source if TERMUX_PKG_SRCURL does not ends with .git.
|
||||
# shellcheck source=scripts/build/get_source/termux_download_src_archive.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_download_src_archive.sh"
|
||||
|
||||
# Run from termux_step_get_source after termux_download_src_archive.
|
||||
# shellcheck source=scripts/build/get_source/termux_extract_src_archive.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_extract_src_archive.sh"
|
||||
|
||||
# Hook for packages to act just after the package sources have been obtained.
|
||||
# Invoked from $TERMUX_PKG_SRCDIR.
|
||||
termux_step_post_get_source() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -108,7 +120,7 @@ termux_step_post_extract_package() {
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_handle_hostbuild.sh"
|
||||
|
||||
# Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR.
|
||||
# After termux_step_post_extract_package() and before termux_step_patch_package()
|
||||
# After termux_step_post_get_source() and before termux_step_patch_package()
|
||||
# shellcheck source=scripts/build/termux_step_host_build.sh
|
||||
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_host_build.sh"
|
||||
|
||||
@ -337,9 +349,10 @@ while (($# > 0)); do
|
||||
termux_step_setup_variables
|
||||
termux_step_handle_buildarch
|
||||
termux_step_start_build
|
||||
termux_step_extract_package
|
||||
cd "$TERMUX_PKG_CACHEDIR"
|
||||
termux_step_get_source
|
||||
cd "$TERMUX_PKG_SRCDIR"
|
||||
termux_step_post_extract_package
|
||||
termux_step_post_get_source
|
||||
termux_step_handle_hostbuild
|
||||
termux_step_setup_toolchain
|
||||
termux_step_patch_package
|
||||
|
19
scripts/build/get_source/termux_download_src_archive.sh
Normal file
19
scripts/build/get_source/termux_download_src_archive.sh
Normal file
@ -0,0 +1,19 @@
|
||||
termux_download_src_archive() {
|
||||
if [ -z "${TERMUX_PKG_SRCURL:=""}" ] || [ "${TERMUX_PKG_SKIP_SRC_EXTRACT-false}" = "true" ] || [ "$TERMUX_PKG_METAPACKAGE" = "true" ]; then
|
||||
return
|
||||
fi
|
||||
local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]})
|
||||
local PKG_SHA256=(${TERMUX_PKG_SHA256[@]})
|
||||
if [ ! ${#PKG_SRCURL[@]} == ${#PKG_SHA256[@]} ] && [ ! ${#PKG_SHA256[@]} == 0 ]; then
|
||||
termux_error_exit "Error: length of TERMUX_PKG_SRCURL isn't equal to length of TERMUX_PKG_SHA256."
|
||||
fi
|
||||
|
||||
for i in $(seq 0 $(( ${#PKG_SRCURL[@]}-1 ))); do
|
||||
local file="$TERMUX_PKG_CACHEDIR/$(basename "${PKG_SRCURL[$i]}")"
|
||||
if [ "${PKG_SHA256[$i]}" == "" ]; then
|
||||
termux_download "${PKG_SRCURL[$i]}" "$file"
|
||||
else
|
||||
termux_download "${PKG_SRCURL[$i]}" "$file" "${PKG_SHA256[$i]}"
|
||||
fi
|
||||
done
|
||||
}
|
22
scripts/build/get_source/termux_extract_src_archive.sh
Normal file
22
scripts/build/get_source/termux_extract_src_archive.sh
Normal file
@ -0,0 +1,22 @@
|
||||
termux_extract_src_archive() {
|
||||
# STRIP=1 extracts archives straight into TERMUX_PKG_SRCDIR while STRIP=0 puts them in subfolders. zip has same behaviour per default
|
||||
# If this isn't desired then this can be fixed in termux_step_post_get_source.
|
||||
local STRIP=1
|
||||
local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]})
|
||||
local PKG_SHA256=(${TERMUX_PKG_SHA256[@]})
|
||||
for i in $(seq 0 $(( ${#PKG_SRCURL[@]}-1 ))); do
|
||||
local file="$TERMUX_PKG_CACHEDIR/$(basename "${PKG_SRCURL[$i]}")"
|
||||
local folder
|
||||
set +o pipefail
|
||||
if [ "${file##*.}" = zip ]; then
|
||||
folder=$(unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-)
|
||||
rm -Rf $folder
|
||||
unzip -q "$file"
|
||||
mv $folder "$TERMUX_PKG_SRCDIR"
|
||||
else
|
||||
test "$i" -gt 0 && STRIP=0
|
||||
tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=$STRIP
|
||||
fi
|
||||
set -o pipefail
|
||||
done
|
||||
}
|
27
scripts/build/get_source/termux_git_clone_src.sh
Normal file
27
scripts/build/get_source/termux_git_clone_src.sh
Normal file
@ -0,0 +1,27 @@
|
||||
termux_git_clone_src() {
|
||||
local CHECKED_OUT_FOLDER=$TERMUX_PKG_TMPDIR/checkout-$TERMUX_PKG_VERSION
|
||||
local TMP_CHECKOUT=$TERMUX_PKG_CACHEDIR/tmp-checkout
|
||||
|
||||
# If user aborts git clone step here the folder needs to be removed
|
||||
# manually. IMO this is better than git cloning the src everytime
|
||||
if [ ! -d $CHECKED_OUT_FOLDER ] && [ ! -d $TMP_CHECKOUT ]; then
|
||||
if [ "$TERMUX_PKG_GIT_BRANCH" == "" ]; then
|
||||
TERMUX_PKG_GIT_BRANCH=v$TERMUX_PKG_VERSION
|
||||
fi
|
||||
git clone --depth 1 \
|
||||
--branch $TERMUX_PKG_GIT_BRANCH \
|
||||
$TERMUX_PKG_SRCURL \
|
||||
$TMP_CHECKOUT
|
||||
cd $TMP_CHECKOUT
|
||||
|
||||
git submodule update --init --recursive
|
||||
cd ..
|
||||
fi
|
||||
|
||||
if [ ! -d $CHECKED_OUT_FOLDER ]; then
|
||||
cp -Rf $TMP_CHECKOUT $CHECKED_OUT_FOLDER
|
||||
fi
|
||||
|
||||
rm -rf $TERMUX_PKG_SRCDIR
|
||||
cp -Rf $CHECKED_OUT_FOLDER $TERMUX_PKG_SRCDIR
|
||||
}
|
10
scripts/build/get_source/termux_step_get_source.sh
Normal file
10
scripts/build/get_source/termux_step_get_source.sh
Normal file
@ -0,0 +1,10 @@
|
||||
termux_step_get_source() {
|
||||
if [ "${TERMUX_PKG_SRCURL: -4}" == ".git" ]; then
|
||||
termux_git_clone_src
|
||||
else
|
||||
mkdir -p $TERMUX_PKG_SRCDIR
|
||||
termux_download_src_archive
|
||||
cd $TERMUX_PKG_TMPDIR
|
||||
termux_extract_src_archive
|
||||
fi
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
termux_step_extract_package() {
|
||||
if [ -z "${TERMUX_PKG_SRCURL:=""}" ] || [ "${TERMUX_PKG_SKIP_SRC_EXTRACT-false}" = "true" ] || [ "$TERMUX_PKG_METAPACKAGE" = "true" ]; then
|
||||
mkdir -p "$TERMUX_PKG_SRCDIR"
|
||||
return
|
||||
fi
|
||||
cd "$TERMUX_PKG_TMPDIR"
|
||||
local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]})
|
||||
local PKG_SHA256=(${TERMUX_PKG_SHA256[@]})
|
||||
if [ ! ${#PKG_SRCURL[@]} == ${#PKG_SHA256[@]} ] && [ ! ${#PKG_SHA256[@]} == 0 ]; then
|
||||
termux_error_exit "Error: length of TERMUX_PKG_SRCURL isn't equal to length of TERMUX_PKG_SHA256."
|
||||
fi
|
||||
# STRIP=1 extracts archives straight into TERMUX_PKG_SRCDIR while STRIP=0 puts them in subfolders. zip has same behaviour per default
|
||||
# If this isn't desired then this can be fixed in termux_step_post_extract_package.
|
||||
local STRIP=1
|
||||
for i in $(seq 0 $(( ${#PKG_SRCURL[@]}-1 ))); do
|
||||
test "$i" -gt 0 && STRIP=0
|
||||
local filename
|
||||
filename=$(basename "${PKG_SRCURL[$i]}")
|
||||
local file="$TERMUX_PKG_CACHEDIR/$filename"
|
||||
# Allow TERMUX_PKG_SHA256 to be empty:
|
||||
set +u
|
||||
termux_download "${PKG_SRCURL[$i]}" "$file" "${PKG_SHA256[$i]}"
|
||||
set -u
|
||||
|
||||
local folder
|
||||
set +o pipefail
|
||||
if [ "${file##*.}" = zip ]; then
|
||||
folder=$(unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-)
|
||||
rm -Rf $folder
|
||||
unzip -q "$file"
|
||||
mv $folder "$TERMUX_PKG_SRCDIR"
|
||||
else
|
||||
mkdir -p "$TERMUX_PKG_SRCDIR"
|
||||
tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=$STRIP
|
||||
fi
|
||||
set -o pipefail
|
||||
done
|
||||
}
|
@ -102,6 +102,7 @@ termux_step_setup_variables() {
|
||||
TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package
|
||||
TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src
|
||||
TERMUX_PKG_SHA256=""
|
||||
TERMUX_PKG_GIT_BRANCH="" # branch defaults to 'v$TERMUX_PKG_VERSION' unless this variable is defined
|
||||
TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp
|
||||
TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build
|
||||
TERMUX_PKG_PLATFORM_INDEPENDENT=false
|
||||
|
Loading…
Reference in New Issue
Block a user