Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ TERMUX_SCRIPTDIR=$(cd "$(realpath "$(dirname "$0")")"; pwd)
# Store pid of current process in a file for docker__run_docker_exec_trap
source "$TERMUX_SCRIPTDIR/scripts/utils/docker/docker.sh"; docker__create_docker_exec_pid_file


if [ "$(uname -o)" = "Android" ] || [ -e "/system/bin/app_process" ]; then
echo "On-device execution of this script is not supported."
exit 1
Expand All @@ -18,26 +17,29 @@ fi
test -f "$HOME"/.termuxrc && . "$HOME"/.termuxrc
: ${TERMUX_TOPDIR:="$HOME/.termux-build"}
: ${TERMUX_ARCH:="aarch64"}
: ${TERMUX_FORMAT:="debian"}
: ${TERMUX_DEBUG_BUILD:=""}
: ${TERMUX_INSTALL_DEPS:="-s"}
# Set TERMUX_INSTALL_DEPS to -s unless set to -i

_show_usage() {
echo "Usage: ./build-all.sh [-a ARCH] [-d] [-i] [-o DIR]"
echo "Usage: ./build-all.sh [-a ARCH] [-d] [-i] [-o DIR] [-f FORMAT]"
echo "Build all packages."
echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all."
echo " -d Build with debug symbols."
echo " -i Build dependencies."
echo " -o Specify deb directory. Default: debs/."
echo " -f Specify format pkg: debian(default) or pacman."
exit 1
}

while getopts :a:hdio: option; do
while getopts :a:hdio:f: option; do
case "$option" in
a) TERMUX_ARCH="$OPTARG";;
d) TERMUX_DEBUG_BUILD='-d';;
i) TERMUX_INSTALL_DEPS='-i';;
o) TERMUX_OUTPUT_DIR="$(realpath -m "$OPTARG")";;
f) TERMUX_FORMAT="$OPTARG";;
h) _show_usage;;
*) _show_usage >&2 ;;
esac
Expand All @@ -50,6 +52,11 @@ if [[ ! "$TERMUX_ARCH" =~ ^(all|aarch64|arm|i686|x86_64)$ ]]; then
exit 1
fi

if [[ ! "$TERMUX_FORMAT" =~ ^(debian|pacman)$ ]]; then
echo "ERROR: Invalid format '$TERMUX_FORMAT'" 1>&2
exit 1
fi
Comment on lines +55 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a case for this instead of regex.

Suggested change
if [[ ! "$TERMUX_FORMAT" =~ ^(debian|pacman)$ ]]; then
echo "ERROR: Invalid format '$TERMUX_FORMAT'" 1>&2
exit 1
fi
case "$TERMUX_FORMAT" in
debian|pacman);;
*) echo "ERROR: Invalid format '$TERMUX_FORMAT'" 1>&2; exit 1;;
esac


BUILDSCRIPT=$(dirname "$0")/build-package.sh
BUILDALL_DIR=$TERMUX_TOPDIR/_buildall-$TERMUX_ARCH
BUILDORDER_FILE=$BUILDALL_DIR/buildorder.txt
Expand All @@ -65,25 +72,30 @@ if [ -e "$BUILDSTATUS_FILE" ]; then
echo "Continuing build-all from: $BUILDSTATUS_FILE"
fi

exec > >(tee -a "$BUILDALL_DIR"/ALL.out)
exec 2> >(tee -a "$BUILDALL_DIR"/ALL.err >&2)
trap 'echo ERROR: See $BUILDALL_DIR/${PKG}.err' ERR
exec &> >(tee -a "$BUILDALL_DIR"/ALL.out)
trap 'echo ERROR: See $BUILDALL_DIR/${PKG}.out' ERR

while read -r PKG PKG_DIR; do
# Check build status (grepping is a bit crude, but it works)
if [ -e "$BUILDSTATUS_FILE" ] && grep "^$PKG\$" "$BUILDSTATUS_FILE" >/dev/null; then
if [ -e "$BUILDSTATUS_FILE" ] && grep -q "^$PKG\$" "$BUILDSTATUS_FILE"; then
echo "Skipping $PKG"
continue
fi

# Start building
if [ -n "${TERMUX_DEBUG_BUILD}" ]; then
echo "\"$BUILDSCRIPT\" -a \"$TERMUX_ARCH\" $TERMUX_DEBUG_BUILD --format \"$TERMUX_FORMAT\" --library $(test "${PKG_DIR%/*}" = "gpkg" && echo "glibc" || echo "bionic") ${TERMUX_OUTPUT_DIR+-o $TERMUX_OUTPUT_DIR} $TERMUX_INSTALL_DEPS \"$PKG_DIR\""
fi

echo -n "Building $PKG... "
BUILD_START=$(date "+%s")
bash -x "$BUILDSCRIPT" -a "$TERMUX_ARCH" $TERMUX_DEBUG_BUILD \
"$BUILDSCRIPT" -a "$TERMUX_ARCH" $TERMUX_DEBUG_BUILD --format "$TERMUX_FORMAT" \
--library $(test "${PKG_DIR%/*}" = "gpkg" && echo "glibc" || echo "bionic") \
${TERMUX_OUTPUT_DIR+-o $TERMUX_OUTPUT_DIR} $TERMUX_INSTALL_DEPS "$PKG_DIR" \
> "$BUILDALL_DIR"/"${PKG}".out 2> "$BUILDALL_DIR"/"${PKG}".err
&> "$BUILDALL_DIR"/"${PKG}".out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also prefer stdout and stderr in a single log as well, however, I remember that Grimler didn't like this:

Image

#20513 (comment)

and this is subjective. For some other people who are not you and me, stdout and stderr in separate logs might be easier to handle and understand, and that might be the reason why they were written to save in separate logs to begin with.

@Grimler91 what do you think about it now that it is in a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally fine with this change, but it should probably be a separate commit.

BUILD_END=$(date "+%s")
BUILD_SECONDS=$(( BUILD_END - BUILD_START ))
echo "done in $BUILD_SECONDS"
echo "done in $BUILD_SECONDS sec"

# Update build status
echo "$PKG" >> "$BUILDSTATUS_FILE"
Expand Down