forked from termux/termux-packages
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-all.sh
executable file
·104 lines (87 loc) · 3.04 KB
/
build-all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# build-all.sh - script to build all packages with a build order specified by buildorder.py
set -e -u -o pipefail
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
fi
# Read settings from .termuxrc if existing
test -f "$HOME"/.termuxrc && . "$HOME"/.termuxrc
: "${TERMUX_TOPDIR:="$HOME/.termux-build"}"
: "${TERMUX_ARCH:="aarch64"}"
: "${TERMUX_INSTALL_DEPS:=""}"
_show_usage() {
echo "Usage: ./build-all.sh [-a ARCH] [-i] [-o DIR]"
echo "Build all packages."
echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all."
echo " -i Install dependencies."
echo " -o Specify deb directory. Default: debs/."
exit 1
}
while getopts :a:hdio: option; do
case "$option" in
a) TERMUX_ARCH="$OPTARG";;
i) TERMUX_INSTALL_DEPS='-i';;
o) TERMUX_OUTPUT_DIR="$(realpath -m "$OPTARG")";;
h) _show_usage;;
*) _show_usage >&2 ;;
esac
done
shift $((OPTIND-1))
if [ "$#" -ne 0 ]; then _show_usage; fi
if [[ ! "$TERMUX_ARCH" =~ ^(all|aarch64|arm|i686|x86_64)$ ]]; then
echo "ERROR: Invalid arch '$TERMUX_ARCH'" 1>&2
exit 1
fi
BUILDSCRIPT=$(dirname "$0")/build-package.sh
BUILDALL_DIR=$TERMUX_TOPDIR/_buildall-$TERMUX_ARCH
BUILDORDER_FILE=$BUILDALL_DIR/buildorder.txt
BUILDSTATUS_FILE=$BUILDALL_DIR/buildstatus.txt
if [ -e "$BUILDORDER_FILE" ]; then
echo "Using existing buildorder file: $BUILDORDER_FILE"
else
mkdir -p "$BUILDALL_DIR"
"$TERMUX_SCRIPTDIR/scripts/buildorder.py" > "$BUILDORDER_FILE"
fi
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
# Read lines from build order file first before building,
# so builds reading from stdin cannot interfere.
PKG_DIRS=()
while read -r PKG PKG_DIR; do
PKG_DIRS+=( "$PKG_DIR" )
done < "${BUILDORDER_FILE}"
for PKG_DIR in "${PKG_DIRS[@]}"; do
PKG=$(basename $PKG_DIR)
# Check build status (grepping is a bit crude, but it works)
if [ -e "$BUILDSTATUS_FILE" ] && grep "^$PKG\$" "$BUILDSTATUS_FILE" >/dev/null; then
echo "Skipping $PKG"
continue
fi
echo -n "Building $PKG... "
BUILD_START=$(date "+%s")
STDOUT_TO="$BUILDALL_DIR"/"${PKG}".out
STDERR_TO="$BUILDALL_DIR"/"${PKG}".err
if [ "$PKG" = "lit" ] || [ "$PKG" = "luvit" ]; then
# Work around https://github.com/luvit/lit/issues/292
STDERR_TO=/dev/tty
fi
bash -x "$BUILDSCRIPT" -a "$TERMUX_ARCH" \
${TERMUX_OUTPUT_DIR+-o $TERMUX_OUTPUT_DIR} $TERMUX_INSTALL_DEPS "$PKG_DIR" \
> "$STDOUT_TO" 2> "$STDERR_TO"
BUILD_END=$(date "+%s")
BUILD_SECONDS=$(( BUILD_END - BUILD_START ))
echo "done in $BUILD_SECONDS"
# Update build status
echo "$PKG" >> "$BUILDSTATUS_FILE"
done
# Update build status
# rm -f "$BUILDSTATUS_FILE"
echo "Finished"