mirror of
https://github.com/termux/termux-packages.git
synced 2025-05-10 10:25:50 +00:00
66 lines
2.4 KiB
Bash
Executable File
66 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
cd "$(realpath "$(dirname "$0")")/../.." || { echo "cd failed"; exit 1; }
|
|
readarray -t TERMUX_PACKAGE_DIRECTORIES < <(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json)
|
|
readarray -t PACKAGES < <(grep -rl termux_setup_golang --include=build.sh "${TERMUX_PACKAGE_DIRECTORIES[@]}" | cut -d/ -f2 | sort -u || :) || :
|
|
ARCH="${1?"Usage: $0 [aarch64|arm|x86_64|i686]"}"
|
|
REPORT_PATH="${TMPDIR:-/tmp}/golang-validation-report.txt"
|
|
|
|
# Converts milliseconds to human-readable format.
|
|
# Example: `ms_to_human_readable 123456789` => 34h 17m 36s 789ms
|
|
ms_to_human_readable() {
|
|
echo "$(($1/3600000))h $(($1%3600000/60000))m $(($1%60000/1000))s $(($1%1000))ms" | sed 's/0h //;s/0m //;s/0s //'
|
|
}
|
|
|
|
maybe_cleanup() {
|
|
[[ -z "$CI" ]] && return
|
|
local PACKAGE="$1" CLEANUP_THRESHOLD=10 # GiB
|
|
|
|
if grep -Fxq "$PACKAGE" scripts/big-pkgs.list; then
|
|
echo "INFO: performing cleanup before building big package."
|
|
elif df "$HOME" | awk -v t="$CLEANUP_THRESHOLD" 'NR == 2 { exit ($4 / 1024^2 < t ? 0 : 1) }'; then
|
|
echo "INFO: Cleaning up, free disk space is below the threshold (${CLEANUP_THRESHOLD} GiB)."
|
|
else
|
|
return
|
|
fi
|
|
|
|
./clean.sh
|
|
rm -rf ./output/*
|
|
}
|
|
|
|
# Target of this script is pretty much simple:
|
|
# 1. Obtain list of all go packages.
|
|
# 2. Build them.
|
|
# 3. Create logfile containing only build logs of failed build attempts.
|
|
|
|
[[ -z "$CI" ]] && echo "INFO: Skipping all cleanup steps: not running in CI environment."
|
|
echo "INFO: Report file path: ${REPORT_PATH}"
|
|
echo "INFO: Rebuild list: ${PACKAGES[*]}" | tee "${REPORT_PATH}"
|
|
|
|
output=
|
|
declare -A failed=()
|
|
start_building_arch="$(date +%10s%3N)"
|
|
for package in "${PACKAGES[@]}"; do
|
|
output="$(
|
|
start="$(date +%10s%3N)"
|
|
exec > >(tee /dev/fd/2) 2>&1 # output everything to both variable and stdout.
|
|
|
|
# Header
|
|
echo "INFO: Building ${package} for ${ARCH}"
|
|
maybe_cleanup "${package}"
|
|
./build-package.sh -I -f -a "${ARCH}" "${package}"
|
|
status="${PIPESTATUS[0]}"
|
|
echo # newline
|
|
echo "INFO: Building ${package} for ${ARCH} took $(ms_to_human_readable $(( $(date +%10s%3N) - start )))"
|
|
echo # newline
|
|
exit "$status"
|
|
)" || failed["${package} ${ARCH}"]="${output}"
|
|
done
|
|
echo "INFO: Building all packages for ${ARCH} took $(ms_to_human_readable $(( $(date +%10s%3N) - start_building_arch )))" | tee -a "${REPORT_PATH}"
|
|
echo # newline
|
|
|
|
for entry in "${!failed[@]}"; do
|
|
echo "${failed["${entry}"]}" >> "${REPORT_PATH}"
|
|
done
|
|
|
|
exit $(( ${#failed[@]} > 0 ))
|