| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Code that runs inside Alpine chroot.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # regtest/aports-guest.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 |
|
| 12 | log() {
|
| 13 | echo "$@" >& 2
|
| 14 | }
|
| 15 |
|
| 16 | # copied from build/deps.sh
|
| 17 | my-time-tsv() {
|
| 18 | python3 benchmarks/time_.py \
|
| 19 | --tsv \
|
| 20 | --time-span --rusage \
|
| 21 | "$@"
|
| 22 | # TODO: could add --rusage-2 to measure page faults / context switches
|
| 23 | # for tuning the xargs -P value - for thrashing and so forth
|
| 24 | }
|
| 25 |
|
| 26 | my-time-tsv-test() {
|
| 27 | # Doesn't output to stdout
|
| 28 | # my-time-tsv sleep 0.5
|
| 29 |
|
| 30 | my-time-tsv -o /tmp/my-time sleep 0.5
|
| 31 | cat /tmp/my-time
|
| 32 | }
|
| 33 |
|
| 34 | readonly LOG_DIR=_tmp/aports-guest
|
| 35 |
|
| 36 | timestamp() {
|
| 37 | date '+%H:%M:%S'
|
| 38 | }
|
| 39 |
|
| 40 | build-one-package() {
|
| 41 | # Copied from build/deps.sh maybe-install-wedge
|
| 42 | #
|
| 43 | # Difference vs. build-package: do not need $config here
|
| 44 |
|
| 45 | local pkg=${1:-lua5.4}
|
| 46 | local a_repo=${2:-main}
|
| 47 | local xargs_slot=${3:-99} # recorded in tasks.tsv
|
| 48 | # -k: keep built packages
|
| 49 | # -K: keep build time temp files
|
| 50 | local more_abuild_flags=${4:-'-k -K'}
|
| 51 | local timeout_secs=${5:-$(( 15 * 60 ))} # 15 minutes by default
|
| 52 |
|
| 53 | printf -v xargs_str '%2s' $xargs_slot
|
| 54 | echo " TASK $xargs_str $(timestamp) $pkg"
|
| 55 |
|
| 56 | local task_file=$LOG_DIR/$pkg.task.tsv
|
| 57 | local log_file=$LOG_DIR/$pkg.log.txt
|
| 58 |
|
| 59 | mkdir -p $(dirname $task_file)
|
| 60 |
|
| 61 | my-time-tsv --print-header \
|
| 62 | --field xargs_slot \
|
| 63 | --field pkg \
|
| 64 | --field pkg_HREF \
|
| 65 | --output $task_file
|
| 66 |
|
| 67 | # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
|
| 68 | # namespaces don't compose with chroots
|
| 69 | local -a cmd=( abuild -f -r -C ~/aports/$a_repo/$pkg $more_abuild_flags )
|
| 70 |
|
| 71 | # Give it 1 second to respond to SIGTERM, then SIGKILL
|
| 72 | local -a timeout_cmd=( timeout -k 1 $timeout_secs "${cmd[@]}" )
|
| 73 |
|
| 74 | #set -x
|
| 75 | # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
|
| 76 | set +o errexit
|
| 77 | my-time-tsv \
|
| 78 | --field "$xargs_slot" \
|
| 79 | --field "$pkg" \
|
| 80 | --field "log/$pkg.log.txt" \
|
| 81 | --append \
|
| 82 | --output $task_file \
|
| 83 | -- \
|
| 84 | "${timeout_cmd[@]}" >$log_file 2>&1
|
| 85 | local status=$?
|
| 86 | set -o errexit
|
| 87 |
|
| 88 | if test "$status" -eq 0; then
|
| 89 | echo " OK $(timestamp) $pkg"
|
| 90 | else
|
| 91 | echo " FAIL $(timestamp) $pkg"
|
| 92 | fi
|
| 93 |
|
| 94 | # Note: should we try not to fetch here? I think the caching of "abuilt
|
| 95 | # fetch" might make this OK
|
| 96 |
|
| 97 | # TODO: avoid running tests and building the APK itself/
|
| 98 | # Only "abuild builddeps,build" is enough to start?
|
| 99 | }
|
| 100 |
|
| 101 | "$@"
|