OILS / soil / worker.sh View on Github | oilshell.org

645 lines, 208 significant
1#!/usr/bin/env bash
2#
3# Run continuous build tasks.
4#
5# Usage:
6# soil/worker.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd) # tsv-lib.sh uses this
13readonly REPO_ROOT
14
15source soil/common.sh
16source test/tsv-lib.sh
17
18py-all-and-ninja() {
19 ### baseline for most tasks
20
21 build/py.sh all
22 ./NINJA-config.sh
23}
24
25ninja-config() {
26 ./NINJA-config.sh
27}
28
29dummy-tasks() {
30 ### Print tasks that execute quickly
31
32 # (task_name, script, action, result_html)
33 cat <<EOF
34os-info soil/diagnose.sh os-info -
35dump-env soil/diagnose.sh dump-env -
36EOF
37}
38
39raw-vm-tasks() {
40 # The perf tool depends on a specific version of a kernel, so run it outside
41 # a container.
42
43 # (task_name, script, action, result_html)
44 cat <<EOF
45os-info soil/diagnose.sh os-info -
46dump-env soil/diagnose.sh dump-env -
47perf-install benchmarks/perf.sh soil-install -
48wait-for-tarball soil/wait.sh for-cpp-tarball -
49test-install-tar devtools/release-native.sh test-install-tar -
50perf-profiles benchmarks/perf.sh soil-run _tmp/perf/index.html
51EOF
52}
53
54# Oh there is a large list of pre-installed software
55# https://github.com/actions/runner-images#available-images
56# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md
57# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
58#
59# 1. System deps for building wedges - ninja, cmake, libreadline-dev, etc.
60# 2. fetch wedges - re2c, cmark, python2, python3, MyPy, pyflakes
61# - Python 3.10 desired for "pea"
62# 3. build them
63# 4. build Oils with them
64
65dev-setup-for() {
66 local distro=$1
67 # (task_name, script, action, result_html)
68
69 cat <<EOF
70os-info soil/diagnose.sh os-info -
71dump-env soil/diagnose.sh dump-env -
72wedge-deps build/deps.sh wedge-deps-$distro -
73fetch build/deps.sh fetch -
74install-wedges build/deps.sh install-wedges-soil _build/wedge/logs/index.html
75py-all-and-ninja soil/worker.sh py-all-and-ninja -
76smoke-test build/dev-setup-test.sh smoke-test -
77wedge-report build/deps.sh wedge-report -
78EOF
79}
80
81spec-bin-for() {
82 local distro=$1
83 cat <<EOF
84os-info soil/diagnose.sh os-info -
85dump-env soil/diagnose.sh dump-env -
86wedge-deps build/deps.sh wedge-deps-$distro -
87fetch build/deps.sh fetch -
88spec-bin build/deps.sh install-spec-bin-fast _build/wedge/logs/index.html
89EOF
90}
91
92dev-setup-debian-tasks() {
93 # (task_name, script, action, result_html)
94
95 dev-setup-for debian
96}
97
98dev-setup-fedora-tasks() {
99 # (task_name, script, action, result_html)
100
101 dev-setup-for fedora
102}
103
104dev-setup-alpine-tasks() {
105 # (task_name, script, action, result_html)
106
107 dev-setup-for alpine
108}
109
110pea-tasks() {
111 ### Print tasks for the 'pea' build
112
113 # We need a later version of Python 3 / MyPy both to type check and
114 # to parse
115
116 # Run py-source so we can type check generated code
117 # We need to type check more than we translate
118
119 # (task_name, script, action, result_html)
120 cat <<EOF
121os-info soil/diagnose.sh os-info -
122dump-env soil/diagnose.sh dump-env -
123py-source build/py.sh py-source -
124check-types pea/TEST.sh check-types -
125run-tests pea/TEST.sh run-tests -
126parse-all pea/TEST.sh parse-all -
127EOF
128}
129
130dev-minimal-tasks() {
131 ### Print tasks for the 'dev-minimal' build
132
133 # repo overview is suggested by README.md
134
135 # (task_name, script, action, result_html)
136 cat <<EOF
137os-info soil/diagnose.sh os-info -
138dump-env soil/diagnose.sh dump-env -
139build-minimal build/py.sh minimal -
140repo-overview metrics/source-code.sh overview -
141lint test/lint.sh soil-run -
142asdl-types asdl/TEST.sh check-types -
143oil-types devtools/types.sh soil-run -
144unit test/unit.sh minimal _test/py-unit/
145lossless test/lossless.sh soil-run -
146parse-errors test/parse-errors.sh soil-run-py -
147runtime-errors test/runtime-errors.sh soil-run-py -
148ysh-parse-errors test/ysh-parse-errors.sh soil-run-py -
149ysh-runtime-errors test/ysh-runtime-errors.sh soil-run-py -
150ysh-every-string test/ysh-every-string.sh soil-run-py -
151ysh-large ysh/run.sh soil-run -
152j8-errors data_lang/j8-errors.sh soil-run-py -
153link-busybox-ash test/spec-bin.sh link-busybox-ash -
154osh-minimal test/spec-py.sh osh-minimal _tmp/spec/osh-minimal/index.html
155headless client/run.sh soil-run-py -
156stdlib-test stdlib/TEST.sh soil-run -
157EOF
158}
159
160interactive-tasks() {
161 ### Print tasks for the 'interactive' build
162
163 # TODO: also run interactive suite with osh-cpp
164
165# TODO: Why does the needs-terminal suite hang in Docker? It doesn't hang in an interactive Docker session.
166#
167# needs-terminal test/spec-py.sh needs-terminal-all _tmp/spec/needs-terminal-py/index.html
168#
169# https://oilshell.zulipchat.com/#narrow/stream/121539-oil-dev/topic/Spec.20Tests.20for.20Interactive.20Parsing
170
171 cat <<EOF
172os-info soil/diagnose.sh os-info -
173dump-env soil/diagnose.sh dump-env -
174py-all-and-ninja soil/worker.sh py-all-and-ninja -
175interactive-osh test/spec-py.sh interactive-osh _tmp/spec/interactive-osh/index.html
176nohup test/nohup.sh soil-run -
177process-table test/process-table.sh soil-run _tmp/process-table/index.html
178stateful test/stateful.sh soil-run _tmp/spec/stateful/index.html
179EOF
180
181}
182
183wild-tasks() {
184 ### Print tasks for the 'wild' build
185
186 # (task_name, script, action, result_html)
187 cat <<EOF
188os-info soil/diagnose.sh os-info -
189dump-env soil/diagnose.sh dump-env -
190wait-for-tarball soil/wait.sh for-cpp-tarball -
191test-tar devtools/release-native.sh test-tar -
192linecount metrics/tarball.sh linecount-oils-cpp -
193wild test/wild.sh soil-run _tmp/wild-www/index.html
194EOF
195}
196
197benchmarks-tasks() {
198 # (task_name, script, action, result_html)
199
200 cat <<EOF
201os-info soil/diagnose.sh os-info -
202dump-env soil/diagnose.sh dump-env -
203py-all-and-ninja soil/worker.sh py-all-and-ninja -
204dev-shell-test build/dev-shell-test.sh soil-run -
205id-test benchmarks/id-test.sh soil-run -
206osh-parser benchmarks/osh-parser.sh soil-run _tmp/osh-parser/index.html
207osh-runtime benchmarks/osh-runtime.sh soil-run _tmp/osh-runtime/index.html
208vm-baseline benchmarks/vm-baseline.sh soil-run _tmp/vm-baseline/index.html
209compute benchmarks/compute.sh soil-run _tmp/compute/index.html
210gc benchmarks/gc.sh soil-run _tmp/gc/index.html
211mycpp-benchmarks benchmarks/mycpp.sh soil-run _tmp/mycpp-examples/index.html
212EOF
213}
214
215bloaty-tasks() {
216 cat <<EOF
217os-info soil/diagnose.sh os-info -
218dump-env soil/diagnose.sh dump-env -
219wait-for-tarball soil/wait.sh for-cpp-tarball -
220test-tar devtools/release-native.sh test-tar -
221native-code metrics/native-code.sh oils-for-unix _tmp/metrics/oils-for-unix/
222EOF
223}
224
225benchmarks2-tasks() {
226 # Note: id-test doesn't run in 'other-tests' because 'gawk' isn't in that image
227 cat <<EOF
228os-info soil/diagnose.sh os-info -
229dump-env soil/diagnose.sh dump-env -
230wait-for-tarball soil/wait.sh for-cpp-tarball -
231test-tar devtools/release-native.sh test-tar -
232uftrace benchmarks/uftrace.sh soil-run _tmp/uftrace/index.html
233gc-cachegrind benchmarks/gc-cachegrind.sh soil-run _tmp/gc-cachegrind/index.html
234EOF
235}
236
237cpp-spec-tasks() {
238 # (task_name, script, action, result_html)
239
240 cat <<EOF
241os-info soil/diagnose.sh os-info -
242dump-env soil/diagnose.sh dump-env -
243py-all-and-ninja soil/worker.sh py-all-and-ninja -
244oils-cpp-smoke build/native.sh soil-run -
245osh-all test/spec-cpp.sh osh-all _tmp/spec/osh-cpp/compare.html
246ysh-all test/spec-cpp.sh ysh-all _tmp/spec/ysh-cpp/compare.html
247ysh-py test/spec-py.sh ysh-all-serial _tmp/spec/ysh-py/index.html
248EOF
249}
250
251cpp-tarball-tasks() {
252
253 # Note: build-times task requires _build/oils.sh
254 # It's a bit redundant with test-tar
255
256 cat <<EOF
257os-info soil/diagnose.sh os-info -
258dump-env soil/diagnose.sh dump-env -
259py-all-and-ninja soil/worker.sh py-all-and-ninja -
260oils-cpp-smoke build/native.sh soil-run -
261make-tar devtools/release-native.sh make-tar _release/oils-for-unix.tar
262xshar-hello devtools/xshar.sh soil-run-hello _release/hello-xshar.xshar
263xshar-test-oils devtools/xshar.sh soil-run-test-oils _release/test-oils.xshar
264build-times build/native.sh measure-build-times -
265EOF
266
267# build-times is a good enough test
268# test-tar devtools/release-native.sh test-tar -
269#
270# Note: tarball is deployed outside the container
271
272}
273
274cpp-small-tasks() {
275
276 # yaks could be moved to pea/ image once it has python2-dev
277 cat <<EOF
278os-info soil/diagnose.sh os-info -
279dump-env soil/diagnose.sh dump-env -
280py-all-and-ninja soil/worker.sh py-all-and-ninja -
281py-unit test/unit.sh all _test/py-unit/
282yaks yaks/TEST.sh soil-run -
283oils-cpp-smoke build/native.sh soil-run -
284cpp-unit test/cpp-unit.sh soil-run _test/-wwz-index
285headless client/run.sh soil-run-cpp -
286asan test/asan.sh soil-run -
287ltrace test/ltrace.sh soil-run -
288micro-syntax doctools/micro-syntax.sh soil-run -
289src-tree doctools/src-tree.sh soil-run _tmp/src-tree-www/index.html
290line-counts metrics/source-code.sh write-reports _tmp/metrics/line-counts/-wwz-index
291preprocessed metrics/source-code.sh preprocessed _tmp/metrics/preprocessed/-wwz-index
292mycpp-examples mycpp/TEST.sh soil-run _test/-wwz-index
293parse-errors test/parse-errors.sh soil-run-cpp -
294runtime-errors test/runtime-errors.sh soil-run-cpp -
295ysh-parse-errors test/ysh-parse-errors.sh soil-run-cpp -
296ysh-runtime-errors test/ysh-runtime-errors.sh soil-run-cpp -
297ysh-every-string test/ysh-every-string.sh soil-run-cpp -
298ysh-large ysh/run.sh soil-run-cpp -
299j8-errors data_lang/j8-errors.sh soil-run-cpp -
300houston-fp demo/houston-fp/run.sh soil-run -
301souffle-smoke-test test/souffle-smoke.sh soil-run -
302EOF
303}
304
305cpp-coverage-tasks() {
306 # dep notes: hnode_asdl.h required by expr_asdl.h in mycpp/examples
307
308 # TODO: make this work
309#tar-compile benchmarks/ovm-build.sh soil-run -
310 cat <<EOF
311os-info soil/diagnose.sh os-info -
312dump-env soil/diagnose.sh dump-env -
313py-all-and-ninja soil/worker.sh py-all-and-ninja -
314extract-clang deps/from-binary.sh extract-clang-in-container -
315mycpp-unit-coverage mycpp/TEST.sh unit-test-coverage _test/clang-coverage/mycpp/html/index.html
316mycpp-examples-coverage mycpp/TEST.sh examples-coverage _test/clang-coverage/mycpp/examples/html/index.html
317cpp-coverage cpp/TEST.sh coverage _test/clang-coverage/cpp/html/index.html
318unified-coverage test/coverage.sh unified-report _test/clang-coverage/unified/html/index.html
319compare-gcc-clang metrics/native-code.sh compare-gcc-clang _tmp/metrics/compare-gcc-clang.txt
320EOF
321}
322
323ovm-tarball-tasks() {
324 ### Print tasks for the 'ovm-tarball' build
325
326 # notes:
327 # - py-all needed to crawl dependencies to make tarball.
328
329 # (task_name, script, action, result_html)
330 cat <<EOF
331os-info soil/diagnose.sh os-info -
332dump-env soil/diagnose.sh dump-env -
333py-all build/py.sh all -
334syscall test/syscall.sh soil-run _tmp/syscall/-wwz-index
335osh-spec test/spec-py.sh osh-all-serial _tmp/spec/osh-py/index.html
336gold test/gold.sh soil-run -
337osh-usage test/osh-usage.sh soil-run -
338tools-deps test/tools-deps.sh soil-run -
339make-tarball devtools/release.sh py-tarball _release/oil.tar
340ysh-ovm-tarball test/spec-py.sh ysh-ovm-tarball _tmp/spec/ysh-py/index.html
341docs build/doc.sh soil-run _release/VERSION/index.html
342doc-metrics echo no-op _release/VERSION/doc/metrics.txt
343EOF
344
345# doc-metrics is a no-op, just for the link. Because soil-run just runs the
346# release, which creates metrics.
347}
348
349# Reuse ovm-tarball container
350app-tests-tasks() {
351
352 cat <<EOF
353os-info soil/diagnose.sh os-info -
354dump-env soil/diagnose.sh dump-env -
355py-all build/py.sh all -
356ble-clone test/ble.sh clone -
357ble-build test/ble.sh build -
358ble-bash-suite test/ble.sh bash-suite -
359ble-test-osh-py test/ble.sh run-tests-osh-py -
360wait-for-tarball soil/wait.sh for-cpp-tarball -
361test-tar devtools/release-native.sh test-tar -
362ble-test-osh-cpp test/ble.sh run-tests-osh-cpp -
363EOF
364
365# This doesn't work
366# ble-test-osh-bash test/ble.sh run-tests-osh-bash -
367}
368
369# TODO: Most of these should be Ninja tasks.
370# Other tests:
371# find-test, xargs-test, pgen2-test, web/table/csv2html-test.sh
372# Probably should start using a shell test framework too.
373other-tests-tasks() {
374 cat <<EOF
375os-info soil/diagnose.sh os-info -
376dump-env soil/diagnose.sh dump-env -
377build-minimal build/py.sh minimal -
378configure-test ./configure-test.sh soil_run -
379time-test benchmarks/time-test.sh soil-run -
380tsv-lib-test test/tsv-lib-test.sh soil-run -
381ysh-ify test/ysh-ify.sh soil-run -
382R-test devtools/R-test.sh soil-run -
383xargs-test test/other.sh xargs-test -
384csv2html-test test/other.sh csv2html-test -
385oil-python-symbols metrics/source-code.sh oil-python-symbols -
386opyc test/opyc.sh soil-run -
387opy-count-lines opy/soil.sh count-lines -
388test-gold opy/soil.sh test-gold -
389build-oil-repo opy/soil.sh build-oil-repo -
390regtest-compile opy/soil.sh regtest-compile -
391EOF
392
393# TODO: add this back after fixing transitive test enumeration problem
394# We shouldn't use
395
396# web-remote-test soil/web-remote-test.sh soil-run -
397}
398
399tests-todo() {
400 ### More tests to add
401 find . -name '_*' -a -prune -o -name '*-test.sh' -a -print
402
403 # pgen2/pgen2-test.sh seems mostly broken
404}
405
406# Redefinition for quicker cloud debugging
407maybe-merge-tasks() {
408 cat <<EOF
409os-info soil/diagnose.sh os-info -
410dump-env soil/diagnose.sh dump-env -
411maybe-merge soil/maybe-merge.sh soil-run -
412EOF
413}
414
415run-tasks() {
416 ### Run the tasks on stdin and write _tmp/soil/INDEX.tsv.
417 local job_name=$1
418 local out_dir=$2 # should already exist
419 local tty=$3
420
421 mkdir -p $out_dir/logs
422
423 # So we can run benchmarks/time_.py.
424 # 2023-02-28: Images like soil-wild based off the new soil-common no longer
425 # have 'cc'. Instead they use a wedge.
426 if command -v cc > /dev/null; then
427 build/py.sh time-helper
428 else
429 echo 'test time-tsv3'
430 time-tsv3 -o /tmp/echo.tsv --append -- echo hi
431
432 echo '/tmp/echo.tsv:'
433 cat /tmp/echo.tsv
434 fi
435
436 # For the later deploy step to pick up
437 date +%s > $out_dir/task-run-start-time.txt
438
439 # This data can go on the dashboard index
440 local tsv=$out_dir/INDEX.tsv
441 rm -f $tsv
442
443 local status
444 local max_status=0
445
446 while read task_name script action result_html; do
447 log "--- task: $task_name ---"
448
449 local log_path=$out_dir/logs/$task_name.txt
450
451 # 15 minutes per task
452 # One of the longest tasks is test/spec-cpp, which takes around 420 seconds
453 # TODO: should have a configurable timeout
454 local -a timeout=(timeout 900)
455 local stdin_tty=''
456
457 case $script in
458 test/process-table.sh)
459 # Workaround for weird interaction, see
460 # $ test/process-table.sh timeout-issue
461 timeout=()
462 ;;
463 test/nohup.sh)
464 # Only run test/nohup.sh with TTY. For some reason build/py.sh all hangs
465 # with $tty?
466 stdin_tty=$tty
467 ;;
468 esac
469
470 local -a argv=(
471 time-tsv3 -o $tsv --append
472 --field $task_name --field $script --field $action
473 --field $result_html --
474 "${timeout[@]}" "$script" "$action"
475 )
476
477 # Run task and save status
478 set +o errexit
479 if test -n "$stdin_tty"; then
480 # explicitly connect TTY, e.g. for soil/interactive
481 "${argv[@]}" > $log_path 2>&1 < $stdin_tty
482 else
483 # Temporary fix: build/doc.sh soil-run reads from stdin!
484 "${argv[@]}" > $log_path 2>&1 < /dev/null
485 fi
486 status=$?
487 set -o errexit
488
489 if test "$status" -gt "$max_status"; then
490 max_status=$status
491 fi
492
493 # Show the last line
494 echo
495 tsv-row status elapsed task script action result_html
496 tail -n 1 $tsv
497 echo
498 log "status=$status max_status=$max_status"
499 done
500
501 log '--- done ---'
502 ls -l $out_dir
503 wc -l $out_dir/logs/*
504
505 # This suppressed the deployment of logs, which we don't want. So all our
506 # Travis builds succeed? But then we can't use their failure notifications
507 # (which might be OK).
508 if false; then
509 # exit with the maximum exit code.
510 awk '
511 BEGIN { max = 0 }
512 { if ($1 > max) { max = $1 } }
513 END { exit(max) }
514 ' $tsv
515 fi
516
517 # To fail later. Important: this dir persists across jobs; it's NOT removed
518 # by 'host-shim.sh job-reset'.
519 mkdir -p _soil-jobs
520
521 # Hack: Assign job_id and write it to the status file. Other jobs can poll
522 # for completion of this job and access its resources.
523
524 local job_id
525 job_id="$(date +%Y-%m-%d__%H-%M-%S)"
526
527 # e.g. _soil-jobs/dummy.status.txt
528 echo "$max_status $job_id" > _soil-jobs/$job_name.status.txt
529}
530
531save-metadata() {
532 ### Write metadata files to be saved as JSON
533
534 # NOTE: host-shim.sh also writes image-pull-time.txt
535
536 local job_name=$1
537 local meta_dir=$2
538
539 echo "$job_name" > $meta_dir/job-name.txt
540
541 # command to show current branch
542 # This does NOT work in detached HEAD! Travis puts the branch in an env
543 # variable, but sr.ht doesn't.
544 # git rev-parse --abbrev-ref HEAD > $meta_dir/git-branch.txt
545
546 git log -n 1 --pretty='format:%H' > $meta_dir/commit-hash.txt
547
548 # ISO 8601 format
549 # Note: this can get confused with rebases. Two different commits can have
550 # the same date.
551 git log -n 1 --pretty='format:%aI' > $meta_dir/commit-date.txt
552
553 git log -n 1 --pretty='format:%s' > $meta_dir/commit-line.txt # "subject"
554}
555
556disable-git-errors() {
557
558 # 2023-02: The build started failing because of the permissions we set in
559 # soil/host-shim.sh mount-perms.
560 #
561 # The issue is that the guest needs to be able to write to the Docker mount
562 # of the repo. I think it may have been related to podman vs. Docker.
563 # Should check if mount-perms is necessary in both places.
564 #
565 # git fails unless we have this workaround.
566
567 # https://stackoverflow.com/questions/72978485/git-submodule-update-failed-with-fatal-detected-dubious-ownership-in-repositor
568
569 # https://github.blog/2022-04-12-git-security-vulnerability-announced/
570
571 #git config --global --add safe.directory '*'
572
573 git config --global --add safe.directory /home/uke/oil
574}
575
576job-main() {
577 local job_name=$1
578
579 local out_dir=_tmp/soil
580
581 # Report for debugging
582 export EXTRA_MYCPP_ARGS='--stack-roots-warn 16'
583
584 log-context 'job-main'
585 mkdir -v -p $out_dir
586 ls -l -d $out_dir
587
588 disable-git-errors
589
590 save-metadata $job_name $out_dir
591
592 local captured
593
594 set +o errexit
595 captured=$(tty)
596 status=$?
597 set -o errexit
598
599 if test $status -eq 0; then
600 echo "TTY = $captured"
601 local tty=$captured
602 else
603 echo "captured = $captured"
604 local tty='' # clear the output
605 fi
606 echo
607
608 ${job_name}-tasks | run-tasks $job_name $out_dir "$tty"
609}
610
611JOB-dummy() { job-main 'dummy'; }
612JOB-raw-vm() { job-main 'raw-vm'; }
613JOB-dev-setup-debian() { job-main 'dev-setup-debian'; }
614JOB-dev-setup-fedora() { job-main 'dev-setup-fedora'; }
615JOB-dev-setup-alpine() { job-main 'dev-setup-alpine'; }
616
617JOB-dev-minimal() { job-main 'dev-minimal'; }
618JOB-interactive() { job-main 'interactive'; }
619
620JOB-other-tests() { job-main 'other-tests'; }
621
622JOB-pea() { job-main 'pea'; }
623
624JOB-ovm-tarball() { job-main 'ovm-tarball'; }
625JOB-app-tests() { job-main 'app-tests'; }
626
627JOB-cpp-coverage() { job-main 'cpp-coverage'; }
628JOB-cpp-small() { job-main 'cpp-small'; }
629JOB-cpp-tarball() { job-main 'cpp-tarball'; }
630JOB-cpp-spec() { job-main 'cpp-spec'; }
631
632JOB-bloaty() { job-main 'bloaty'; }
633JOB-benchmarks() { job-main 'benchmarks'; }
634JOB-benchmarks2() { job-main 'benchmarks2'; }
635
636JOB-wild() { job-main 'wild'; }
637
638JOB-maybe-merge() { job-main 'maybe-merge'; }
639
640list-jobs() {
641 # dev-setup-fedora for Fedora, disable
642 compgen -A function | grep -- '^JOB-' | sed 's/^JOB-//g' | egrep -v 'maybe-merge|dev-setup-fedora|dev-setup-alpine'
643}
644
645"$@"