OILS / regtest / aports-guest.sh View on Github | oils.pub

99 lines, 50 significant
1#!/usr/bin/env bash
2#
3# Code that runs inside Alpine chroot.
4#
5# Usage:
6# regtest/aports-guest.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12log() {
13 echo "$@" >& 2
14}
15
16# copied from build/deps.sh
17my-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
26my-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
34readonly LOG_DIR=_tmp/aports-guest
35
36timestamp() {
37 date '+%H:%M:%S'
38}
39
40build-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
48 local task_file=$LOG_DIR/$pkg.task.tsv
49 local log_file=$LOG_DIR/$pkg.log.txt
50
51 mkdir -p $(dirname $task_file)
52
53 my-time-tsv --print-header \
54 --field xargs_slot \
55 --field pkg \
56 --field pkg_HREF \
57 --output $task_file
58
59 # Packages live in /home/udu/aports/main
60 # -f forces rebuild: needed for different configs
61 # -r: install missing deps from system repository?
62 #local -a cmd=( abuild -f -r -C ~/aports/main/$pkg rootbld )
63
64 # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
65 # namespaces don't compose with chroots
66 local -a cmd=( abuild -f -r -C ~/aports/$a_repo/$pkg )
67
68 # Give it 1 second to respond to SIGTERM, then SIGKILL
69 local seconds=$(( 5 * 60 )) # 5 minutes max for now, save time!
70 local -a timeout_cmd=( timeout -k 1 $seconds "${cmd[@]}" )
71
72 #set -x
73 # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
74 set +o errexit
75 my-time-tsv \
76 --field "${XARGS_SLOT:-99}" \
77 --field "$pkg" \
78 --field "log/$pkg.log.txt" \
79 --append \
80 --output $task_file \
81 -- \
82 "${timeout_cmd[@]}" >$log_file 2>&1
83 local status=$?
84 set -o errexit
85
86 if test "$status" -eq 0; then
87 echo " OK $(timestamp) $pkg"
88 else
89 echo " FAIL $(timestamp) $pkg"
90 fi
91
92 # Note: should we try not to fetch here? I think the caching of "abuilt
93 # fetch" might make this OK
94
95 # TODO: avoid running tests and building the APK itself/
96 # Only "abuild builddeps,build" is enough to start?
97}
98
99"$@"