| 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 | }
|
| 23 |
|
| 24 | my-time-tsv-test() {
|
| 25 | # Doesn't output to stdout
|
| 26 | # my-time-tsv sleep 0.5
|
| 27 |
|
| 28 | my-time-tsv -o /tmp/my-time sleep 0.5
|
| 29 | cat /tmp/my-time
|
| 30 | }
|
| 31 |
|
| 32 | readonly LOG_DIR=_tmp/aports-guest
|
| 33 |
|
| 34 | timestamp() {
|
| 35 | date '+%H:%M:%S'
|
| 36 | }
|
| 37 |
|
| 38 | build-package() {
|
| 39 | # Copied from build/deps.sh maybe-install-wedge
|
| 40 |
|
| 41 | local config=${1:-baseline}
|
| 42 | local pkg=${2:-lua5.4}
|
| 43 |
|
| 44 | local task_file=$LOG_DIR/$config/$pkg.task.tsv
|
| 45 | local log_file=$LOG_DIR/$config/$pkg.log.txt
|
| 46 |
|
| 47 | mkdir -p $(dirname $task_file)
|
| 48 |
|
| 49 | my-time-tsv --print-header \
|
| 50 | --field xargs_slot \
|
| 51 | --field pkg \
|
| 52 | --field pkg_HREF \
|
| 53 | --output $task_file
|
| 54 |
|
| 55 | # Packages live in /home/udu/aports/main
|
| 56 | # -f forces rebuild: needed for different configs
|
| 57 | # -r: install missing deps from system repository?
|
| 58 | #local -a cmd=( abuild -f -r -C ~/aports/main/$pkg rootbld )
|
| 59 |
|
| 60 | # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
|
| 61 | # namespaces don't compose with chroots
|
| 62 | local -a cmd=( abuild -f -r -C ~/aports/main/$pkg )
|
| 63 |
|
| 64 | # Give it 1 second to respond to SIGTERM, then SIGKILL
|
| 65 | local seconds=$(( 5 * 60 )) # 5 minutes max for now, save time!
|
| 66 | local -a timeout_cmd=( timeout -k 1 $seconds "${cmd[@]}" )
|
| 67 |
|
| 68 | #set -x
|
| 69 | # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
|
| 70 | set +o errexit
|
| 71 | my-time-tsv \
|
| 72 | --field "${XARGS_SLOT:-99}" \
|
| 73 | --field "$pkg" \
|
| 74 | --field "log/$pkg.log.txt" \
|
| 75 | --append \
|
| 76 | --output $task_file \
|
| 77 | -- \
|
| 78 | "${timeout_cmd[@]}" >$log_file 2>&1
|
| 79 | local status=$?
|
| 80 | set -o errexit
|
| 81 |
|
| 82 | if test "$status" -eq 0; then
|
| 83 | echo " OK $(timestamp) $pkg"
|
| 84 | else
|
| 85 | echo " FAIL $(timestamp) $pkg"
|
| 86 | fi
|
| 87 |
|
| 88 | # Note: should we try not to fetch here? I think the caching of "abuilt
|
| 89 | # fetch" might make this OK
|
| 90 |
|
| 91 | # TODO: avoid running tests and building the APK itself/
|
| 92 | # Only "abuild builddeps,build" is enough to start?
|
| 93 | }
|
| 94 |
|
| 95 | build-one-package() {
|
| 96 | # Copied from build/deps.sh maybe-install-wedge
|
| 97 | #
|
| 98 | # Difference vs. build-package: do not need $config here
|
| 99 |
|
| 100 | local pkg=${1:-lua5.4}
|
| 101 | local a_repo=${2:-main}
|
| 102 |
|
| 103 | local task_file=$LOG_DIR/$pkg.task.tsv
|
| 104 | local log_file=$LOG_DIR/$pkg.log.txt
|
| 105 |
|
| 106 | mkdir -p $(dirname $task_file)
|
| 107 |
|
| 108 | my-time-tsv --print-header \
|
| 109 | --field xargs_slot \
|
| 110 | --field pkg \
|
| 111 | --field pkg_HREF \
|
| 112 | --output $task_file
|
| 113 |
|
| 114 | # Packages live in /home/udu/aports/main
|
| 115 | # -f forces rebuild: needed for different configs
|
| 116 | # -r: install missing deps from system repository?
|
| 117 | #local -a cmd=( abuild -f -r -C ~/aports/main/$pkg rootbld )
|
| 118 |
|
| 119 | # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
|
| 120 | # namespaces don't compose with chroots
|
| 121 | local -a cmd=( abuild -f -r -C ~/aports/$a_repo/$pkg )
|
| 122 |
|
| 123 | # Give it 1 second to respond to SIGTERM, then SIGKILL
|
| 124 | local seconds=$(( 5 * 60 )) # 5 minutes max for now, save time!
|
| 125 | local -a timeout_cmd=( timeout -k 1 $seconds "${cmd[@]}" )
|
| 126 |
|
| 127 | #set -x
|
| 128 | # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
|
| 129 | set +o errexit
|
| 130 | my-time-tsv \
|
| 131 | --field "${XARGS_SLOT:-99}" \
|
| 132 | --field "$pkg" \
|
| 133 | --field "log/$pkg.log.txt" \
|
| 134 | --append \
|
| 135 | --output $task_file \
|
| 136 | -- \
|
| 137 | "${timeout_cmd[@]}" >$log_file 2>&1
|
| 138 | local status=$?
|
| 139 | set -o errexit
|
| 140 |
|
| 141 | if test "$status" -eq 0; then
|
| 142 | echo " OK $(timestamp) $pkg"
|
| 143 | else
|
| 144 | echo " FAIL $(timestamp) $pkg"
|
| 145 | fi
|
| 146 |
|
| 147 | # Note: should we try not to fetch here? I think the caching of "abuilt
|
| 148 | # fetch" might make this OK
|
| 149 |
|
| 150 | # TODO: avoid running tests and building the APK itself/
|
| 151 | # Only "abuild builddeps,build" is enough to start?
|
| 152 | }
|
| 153 |
|
| 154 |
|
| 155 | # leave 1 CPU for other stuff
|
| 156 | # Note:
|
| 157 | # - Some packages builds use multiple CPUs though ... this is where the GNU
|
| 158 | # make job server protocol would come in handy.
|
| 159 | # - We can also compute parallelism LATER from tasks.tsv, with the heuristic
|
| 160 | # USER TIME / ELAPSED TIME
|
| 161 | readonly NPROC=$(( $(nproc) - 1 ))
|
| 162 |
|
| 163 | build-package-list() {
|
| 164 | ### Reads task rows from stdin
|
| 165 | local config=${1:-baseline}
|
| 166 | local parallel=${2:-}
|
| 167 |
|
| 168 | mkdir -p $LOG_DIR
|
| 169 |
|
| 170 | local -a flags
|
| 171 | if test -n "$parallel"; then
|
| 172 | log ""
|
| 173 | log "=== Building packages with $NPROC jobs in parallel"
|
| 174 | log ""
|
| 175 | flags=( -P $NPROC )
|
| 176 | else
|
| 177 | log ""
|
| 178 | log "=== Building packages serially"
|
| 179 | log ""
|
| 180 | fi
|
| 181 |
|
| 182 | # Reads from stdin
|
| 183 | # Note: --process-slot-var requires GNU xargs! busybox args doesn't have it.
|
| 184 | #
|
| 185 | # $name $version $wedge_dir
|
| 186 | xargs "${flags[@]}" -n 1 --process-slot-var=XARGS_SLOT -- $0 build-package "$config"
|
| 187 | }
|
| 188 |
|
| 189 | build-packages() {
|
| 190 | local config=$1 # e.g. baseline
|
| 191 | shift
|
| 192 |
|
| 193 | for pkg in "$@"; do
|
| 194 | echo "$pkg"
|
| 195 | done | build-package-list "$config"
|
| 196 | }
|
| 197 |
|
| 198 | "$@"
|