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

100 lines, 54 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 local more_abuild_flags=${3:-} # e.g. for -k
48 local timeout_secs=${4:-$(( 5 * 60 ))} # 5 minutes by default
49
50 local xargs_slot=${TRAVIS_HACK:-99}
51
52 printf -v xargs_str '%2s' $xargs_slot
53 echo " TASK $xargs_str $(timestamp) $pkg"
54
55 local task_file=$LOG_DIR/$pkg.task.tsv
56 local log_file=$LOG_DIR/$pkg.log.txt
57
58 mkdir -p $(dirname $task_file)
59
60 my-time-tsv --print-header \
61 --field xargs_slot \
62 --field pkg \
63 --field pkg_HREF \
64 --output $task_file
65
66 # DISABLE rootbld for now - bwrap doesn't work inside chroot, because user
67 # namespaces don't compose with chroots
68 local -a cmd=( abuild -f -r -C ~/aports/$a_repo/$pkg $more_abuild_flags )
69
70 # Give it 1 second to respond to SIGTERM, then SIGKILL
71 local -a timeout_cmd=( timeout -k 1 $timeout_secs "${cmd[@]}" )
72
73 #set -x
74 # NOTE: log/foo.log.txt is the relative path after copy-results; sync-results
75 set +o errexit
76 my-time-tsv \
77 --field "$xargs_slot" \
78 --field "$pkg" \
79 --field "log/$pkg.log.txt" \
80 --append \
81 --output $task_file \
82 -- \
83 "${timeout_cmd[@]}" >$log_file 2>&1
84 local status=$?
85 set -o errexit
86
87 if test "$status" -eq 0; then
88 echo " OK $(timestamp) $pkg"
89 else
90 echo " FAIL $(timestamp) $pkg"
91 fi
92
93 # Note: should we try not to fetch here? I think the caching of "abuilt
94 # fetch" might make this OK
95
96 # TODO: avoid running tests and building the APK itself/
97 # Only "abuild builddeps,build" is enough to start?
98}
99
100"$@"