OILS / build / deps.sh View on Github | oilshell.org

1213 lines, 615 significant
1#!/usr/bin/env bash
2#
3# Script for contributors to build dev dependencies -- packaged as cross-distro
4# "wedges". Tested in the Soil CI.
5#
6# Usage:
7# build/deps.sh <function name>
8#
9# Examples:
10# build/deps.sh fetch
11# build/deps.sh install-wedges-fast # for both Python and C++
12#
13# build/deps.sh rm-oils-crap # rm -r -f /wedge ~/wedge to start over
14#
15# TODO: Do we need something faster, just python2, re2c, and cmark?
16#
17# - build/deps.sh fetch-py
18# - build/deps.sh install-wedges-py
19#
20# TODO: Can we make most of them non-root deps? This requires rebuilding
21# containers, which requires podman.
22#
23# rm -r -f ~/wedge # would be better
24
25
26# Check if we're in the right directory
27if [[ ! -d "stdlib/osh" ]]; then
28 echo "Error: This script must be run from the root of the Oil project directory"
29 echo "Please cd to the root directory and try again"
30 exit 1
31fi
32
33: ${LIB_OSH=stdlib/osh}
34if [[ ! -f "$LIB_OSH/bash-strict.sh" ]] || [[ ! -f "$LIB_OSH/task-five.sh" ]]; then
35 echo "Error: Required source files not found in $LIB_OSH/"
36 echo "Expected files:"
37 echo " - $LIB_OSH/bash-strict.sh"
38 echo " - $LIB_OSH/task-five.sh"
39 exit 1
40fi
41
42source $LIB_OSH/bash-strict.sh
43source $LIB_OSH/task-five.sh
44
45REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
46
47source build/dev-shell.sh # python3 in PATH, PY3_LIBS_VERSION
48source deps/from-apt.sh # PY3_BUILD_DEPS
49#source deps/podman.sh
50source test/tsv-lib.sh # tsv-concat
51source web/table/html.sh # table-sort-{begin,end}
52
53# Also in build/dev-shell.sh
54USER_WEDGE_DIR=~/wedge/oils-for-unix.org
55ROOT_WEDGE_DIR=/wedge/oils-for-unix.org
56
57readonly DEPS_SOURCE_DIR=_build/deps-source
58
59readonly RE2C_VERSION=3.0
60readonly RE2C_URL="https://github.com/skvadrik/re2c/releases/download/$RE2C_VERSION/re2c-$RE2C_VERSION.tar.xz"
61
62readonly CMARK_VERSION=0.29.0
63readonly CMARK_URL="https://github.com/commonmark/cmark/archive/$CMARK_VERSION.tar.gz"
64
65readonly PY_FTP_MIRROR="${PY_FTP_MIRROR:-https://www.python.org/ftp}"
66
67readonly PY2_VERSION=2.7.18
68readonly PY2_URL="$PY_FTP_MIRROR/python/$PY2_VERSION/Python-$PY2_VERSION.tar.xz"
69
70readonly PY3_VERSION=3.10.4
71readonly PY3_URL="$PY_FTP_MIRROR/python/$PY3_VERSION/Python-$PY3_VERSION.tar.xz"
72
73readonly BASH_VER=4.4 # don't clobber BASH_VERSION
74readonly BASH_URL="https://www.oilshell.org/blob/spec-bin/bash-$BASH_VER.tar.gz"
75
76# Another version of bash to test
77readonly BASH5_VER=5.2.21
78readonly BASH5_URL="https://www.oilshell.org/blob/spec-bin/bash-$BASH5_VER.tar.gz"
79
80readonly DASH_VERSION=0.5.10.2
81readonly DASH_URL="https://www.oilshell.org/blob/spec-bin/dash-$DASH_VERSION.tar.gz"
82
83readonly ZSH_VERSION=5.1.1
84readonly ZSH_URL="https://www.oilshell.org/blob/spec-bin/zsh-$ZSH_VERSION.tar.xz"
85
86readonly MKSH_VERSION=R52c
87readonly MKSH_URL="https://www.oilshell.org/blob/spec-bin/mksh-$MKSH_VERSION.tgz"
88
89readonly BUSYBOX_VERSION='1.35.0'
90readonly BUSYBOX_URL="https://www.oilshell.org/blob/spec-bin/busybox-$BUSYBOX_VERSION.tar.bz2"
91
92readonly YASH_VERSION=2.49
93readonly YASH_URL="https://www.oilshell.org/blob/spec-bin/yash-$YASH_VERSION.tar.xz"
94
95readonly MYPY_GIT_URL=https://github.com/python/mypy
96readonly MYPY_VERSION=0.780
97
98readonly PY3_LIBS=~/wedge/oils-for-unix.org/pkg/py3-libs/$MYPY_VERSION
99
100# Version 2.4.0 from 2021-10-06 was the last version that supported Python 2
101# https://github.com/PyCQA/pyflakes/blob/main/NEWS.rst
102readonly PYFLAKES_VERSION=2.4.0
103#readonly PYFLAKES_URL='https://files.pythonhosted.org/packages/15/60/c577e54518086e98470e9088278247f4af1d39cb43bcbd731e2c307acd6a/pyflakes-2.4.0.tar.gz'
104# 2023-07: Mirrored to avoid network problem on broome during release
105readonly PYFLAKES_URL='https://www.oilshell.org/blob/pyflakes-2.4.0.tar.gz'
106
107readonly BLOATY_VERSION=1.1
108readonly BLOATY_URL='https://github.com/google/bloaty/releases/download/v1.1/bloaty-1.1.tar.bz2'
109
110readonly UFTRACE_VERSION=0.13
111readonly UFTRACE_URL='https://github.com/namhyung/uftrace/archive/refs/tags/v0.13.tar.gz'
112
113readonly SOUFFLE_VERSION=2.4.1
114readonly SOUFFLE_URL=https://github.com/souffle-lang/souffle/archive/refs/tags/2.4.1.tar.gz
115
116log() {
117 echo "$@" >& 2
118}
119
120die() {
121 log "$0: fatal: $@"
122 exit 1
123}
124
125rm-oils-crap() {
126 ### When you want to start over
127
128 rm -r -f -v ~/wedge
129 sudo rm -r -f -v /wedge
130}
131
132# Note: git is an implicit dependency -- that's how we got the repo in the
133# first place!
134
135# python2-dev is no longer available on Debian 12
136# python-dev also seems gone
137#
138# wget: for fetching wedges (not on Debian by default!)
139# tree: tiny package that's useful for showing what we installed
140# g++: essential
141# libreadline-dev: needed for the build/prepare.sh Python build.
142# gawk: used by spec-runner.sh for the special match() function.
143# cmake: for cmark
144# PY3_BUILD_DEPS - I think these will be used for building the Python 2 wedge
145# as well
146readonly -a WEDGE_DEPS_DEBIAN=(
147 bzip2
148 wget
149 tree
150 gawk
151 g++
152 ninja-build
153 cmake
154 libreadline-dev
155 systemtap-sdt-dev
156
157 # for Souffle, flex and bison
158 #flex bison
159
160 "${PY3_BUILD_DEPS[@]}"
161)
162
163readonly -a WEDGE_DEPS_ALPINE=(
164 bzip2
165 xz
166
167 wget tree gawk
168
169 gcc g++
170 ninja-build
171 # https://pkgs.alpinelinux.org/packages?name=ninja-is-really-ninja&branch=v3.19&repo=&arch=&maintainer=
172 ninja-is-really-ninja
173 cmake
174
175 readline-dev
176 zlib-dev
177 libffi-dev
178 openssl-dev
179
180 ncurses-dev
181
182 # for Souffle, flex and bison
183 #flex bison
184)
185
186readonly -a WEDGE_DEPS_FEDORA=(
187
188 # Weird, Fedora doesn't have these by default!
189 hostname
190 tar
191 bzip2
192
193 # https://packages.fedoraproject.org/pkgs/wget/wget/
194 wget
195 # https://packages.fedoraproject.org/pkgs/tree-pkg/tree/
196 tree
197 gawk
198
199 # https://packages.fedoraproject.org/pkgs/gcc/gcc/
200 gcc gcc-c++
201
202 ninja-build
203 cmake
204
205 readline-devel
206
207 # Like PY3_BUILD_DEPS
208 # https://packages.fedoraproject.org/pkgs/zlib/zlib-devel/
209 zlib-devel
210 # https://packages.fedoraproject.org/pkgs/libffi/libffi-devel/
211 libffi-devel
212 # https://packages.fedoraproject.org/pkgs/openssl/openssl-devel/
213 openssl-devel
214
215 # For building zsh from source?
216 # https://koji.fedoraproject.org/koji/rpminfo?rpmID=36987813
217 ncurses-devel
218 #libcap-devel
219
220 # still have a job control error compiling bash
221 # https://packages.fedoraproject.org/pkgs/glibc/glibc-devel/
222 # glibc-devel
223)
224
225readonly -a WEDGE_DEPS_ARCH=(
226 # https://archlinux.org/packages/core/x86_64/bzip2/
227 bzip2
228
229 # https://archlinux.org/packages/extra/x86_64/wget/
230 wget
231
232 # https://archlinux.org/packages/extra/x86_64/tree/
233 tree
234
235 # https://archlinux.org/packages/core/x86_64/gawk/
236 gawk
237
238 # https://archlinux.org/packages/core/x86_64/gcc/
239 gcc
240
241 # https://archlinux.org/packages/community/x86_64/ninja/
242 ninja
243
244 # https://archlinux.org/packages/extra/x86_64/cmake/
245 cmake
246
247 # https://archlinux.org/packages/core/x86_64/readline/
248 readline
249
250 # https://archlinux.org/packages/core/x86_64/zlib/
251 zlib
252
253 # https://archlinux.org/packages/core/x86_64/libffi/
254 libffi
255
256 # https://archlinux.org/packages/core/x86_64/openssl/
257 openssl
258
259 # https://archlinux.org/packages/core/x86_64/ncurses/
260 ncurses
261
262 # Development headers are included in the main packages on Arch,
263 # unlike other distros that separate them into -dev/-devel packages
264
265 # Python 2 from the AUR
266 # https://aur.archlinux.org/packages/python2
267 base-devel # needed for building packages from the AUR
268
269)
270
271
272install-debian-packages() {
273 ### Packages for build/py.sh all, building wedges, etc.
274
275 set -x # show what needs sudo
276
277 # pass -y for say gitpod
278 sudo apt "$@" install "${WEDGE_DEPS_DEBIAN[@]}"
279 set +x
280
281 # maybe pass -y through
282 test/spec-bin.sh install-shells-with-apt "$@"
283}
284
285install-ubuntu-packages() {
286 ### Debian and Ubuntu packages are the same; this function is suggested on the wiki
287 install-debian-packages "$@"
288}
289
290wedge-deps-debian() {
291 # Install packages without prompt
292
293 # 2024-02 - there was an Ubuntu update, and we started needing this
294 sudo apt-get -y update
295
296 install-debian-packages -y
297}
298
299wedge-deps-fedora() {
300 # https://linuxconfig.org/install-development-tools-on-redhat-8
301 # Trying to get past compile errors
302 # sudo dnf group install --assumeyes 'Development Tools'
303
304 sudo dnf install --assumeyes "${WEDGE_DEPS_FEDORA[@]}"
305}
306
307wedge-deps-alpine() {
308 # https://linuxconfig.org/install-development-tools-on-redhat-8
309 # Trying to get past compile errors
310 # sudo dnf group install --assumeyes 'Development Tools'
311
312 sudo apk add "${WEDGE_DEPS_ALPINE[@]}"
313}
314
315wedge-deps-arch() {
316 # Install packages without prompt
317
318 # First sync the package database
319 sudo pacman -Sy
320
321 # Then install packages
322 for pkg in "${WEDGE_DEPS_ARCH[@]}"; do
323 # Only install if not already installed
324 if ! pacman -Qi "$pkg" >/dev/null 2>&1; then
325 sudo pacman --noconfirm -S "$pkg"
326 fi
327 done
328}
329
330#
331# Unused patch, was experiment for Fedora
332#
333
334get-typed-ast-patch() {
335 curl -o deps/typed_ast.patch https://github.com/python/typed_ast/commit/123286721923ae8f3885dbfbad94d6ca940d5c96.patch
336}
337
338# Work around typed_ast bug:
339# https://github.com/python/typed_ast/issues/169
340#
341# Apply this patch
342# https://github.com/python/typed_ast/commit/123286721923ae8f3885dbfbad94d6ca940d5c96
343#
344# typed_ast is tarred up though
345patch-typed-ast() {
346 local package_dir=_cache/py3-libs
347 local patch=$PWD/deps/typed_ast.patch
348
349 pushd $package_dir
350 cat $patch
351 echo
352
353 local dir=typed_ast-1.4.3
354 local tar=typed_ast-1.4.3.tar.gz
355
356 echo OLD
357 ls -l $tar
358 echo
359
360 rm -r -f -v $dir
361 tar -x -z < $tar
362
363 pushd $dir
364 patch -p1 < $patch
365 popd
366 #find $dir
367
368 # Create a new one
369 tar --create --gzip --file $tar typed_ast-1.4.3
370
371 echo NEW
372 ls -l $tar
373 echo
374
375 popd
376}
377
378#
379# Fetch
380#
381
382download-to() {
383 local dir=$1
384 local url=$2
385 wget --no-clobber --directory-prefix "$dir" "$url"
386}
387
388maybe-extract() {
389 local wedge_dir=$1
390 local tar_name=$2
391 local out_dir=$3
392
393 if test -d "$wedge_dir/$out_dir"; then
394 log "Not extracting because $wedge_dir/$out_dir exists"
395 return
396 fi
397
398 local tar=$wedge_dir/$tar_name
399 case $tar_name in
400 *.gz|*.tgz) # mksh ends with .tgz
401 flag='--gzip'
402 ;;
403 *.bz2)
404 flag='--bzip2'
405 ;;
406 *.xz)
407 flag='--xz'
408 ;;
409 *)
410 die "tar with unknown extension: $tar_name"
411 ;;
412 esac
413
414 tar --extract $flag --file $tar --directory $wedge_dir
415}
416
417clone-mypy() {
418 ### replaces deps/from-git
419 local dest_dir=$1
420 local version=${2:-$MYPY_VERSION}
421
422 local dest=$dest_dir/mypy-$version
423 if test -d $dest; then
424 log "Not cloning because $dest exists"
425 return
426 fi
427
428 # v$VERSION is a tag, not a branch
429
430 # size optimization: --depth=1 --shallow-submodules
431 # https://git-scm.com/docs/git-clone
432
433 git clone --recursive --branch v$version \
434 --depth=1 --shallow-submodules \
435 $MYPY_GIT_URL $dest
436
437 # TODO: verify commit checksum
438}
439
440copy-source-medo() {
441 mkdir -p $DEPS_SOURCE_DIR
442
443 # Copy the whole tree, including the .treeptr files
444 cp --verbose --recursive --no-target-directory \
445 deps/source.medo/ $DEPS_SOURCE_DIR/
446}
447
448fetch-spec-bin() {
449 download-to $DEPS_SOURCE_DIR/bash "$BASH_URL"
450 maybe-extract $DEPS_SOURCE_DIR/bash "$(basename $BASH_URL)" bash-$BASH_VER
451
452 download-to $DEPS_SOURCE_DIR/bash "$BASH5_URL"
453 maybe-extract $DEPS_SOURCE_DIR/bash "$(basename $BASH5_URL)" bash-$BASH5_VER
454
455 download-to $DEPS_SOURCE_DIR/dash "$DASH_URL"
456 maybe-extract $DEPS_SOURCE_DIR/dash "$(basename $DASH_URL)" dash-$DASH_VERSION
457
458 download-to $DEPS_SOURCE_DIR/zsh "$ZSH_URL"
459 maybe-extract $DEPS_SOURCE_DIR/zsh "$(basename $ZSH_URL)" zsh-$ZSH_VERSION
460
461 download-to $DEPS_SOURCE_DIR/mksh "$MKSH_URL"
462 maybe-extract $DEPS_SOURCE_DIR/mksh "$(basename $MKSH_URL)" mksh-$MKSH_VERSION
463
464 download-to $DEPS_SOURCE_DIR/busybox "$BUSYBOX_URL"
465 maybe-extract $DEPS_SOURCE_DIR/busybox "$(basename $BUSYBOX_URL)" busybox-$BUSYBOX_VERSION
466
467 download-to $DEPS_SOURCE_DIR/yash "$YASH_URL"
468 maybe-extract $DEPS_SOURCE_DIR/yash "$(basename $YASH_URL)" yash-$YASH_VERSION
469
470 # Patch: this tarball doesn't follow the convention $name-$version
471 if test -d $DEPS_SOURCE_DIR/mksh/mksh; then
472 pushd $DEPS_SOURCE_DIR/mksh
473 mv -v mksh mksh-$MKSH_VERSION
474 popd
475 fi
476}
477
478fetch() {
479 local py_only=${1:-}
480
481 # For now, simulate what 'medo expand deps/source.medo _build/deps-source'
482 # would do: fetch compressed tarballs designated by .treeptr files, and
483 # expand them.
484
485 # _build/deps-source/
486 # re2c/
487 # WEDGE
488 # re2c-3.0/ # expanded .tar.xz file
489
490 copy-source-medo
491
492 download-to $DEPS_SOURCE_DIR/re2c "$RE2C_URL"
493 download-to $DEPS_SOURCE_DIR/cmark "$CMARK_URL"
494 maybe-extract $DEPS_SOURCE_DIR/re2c "$(basename $RE2C_URL)" re2c-$RE2C_VERSION
495 maybe-extract $DEPS_SOURCE_DIR/cmark "$(basename $CMARK_URL)" cmark-$CMARK_VERSION
496
497 if test -n "$py_only"; then
498 log "Fetched dependencies for 'build/py.sh'"
499 return
500 fi
501
502 download-to $DEPS_SOURCE_DIR/pyflakes "$PYFLAKES_URL"
503 maybe-extract $DEPS_SOURCE_DIR/pyflakes "$(basename $PYFLAKES_URL)" \
504 pyflakes-$PYFLAKES_VERSION
505
506 download-to $DEPS_SOURCE_DIR/python2 "$PY2_URL"
507 download-to $DEPS_SOURCE_DIR/python3 "$PY3_URL"
508 maybe-extract $DEPS_SOURCE_DIR/python2 "$(basename $PY2_URL)" Python-$PY2_VERSION
509 maybe-extract $DEPS_SOURCE_DIR/python3 "$(basename $PY3_URL)" Python-$PY3_VERSION
510
511 fetch-spec-bin
512
513 # bloaty and uftrace are for benchmarks, in containers
514 download-to $DEPS_SOURCE_DIR/bloaty "$BLOATY_URL"
515 download-to $DEPS_SOURCE_DIR/uftrace "$UFTRACE_URL"
516 maybe-extract $DEPS_SOURCE_DIR/bloaty "$(basename $BLOATY_URL)" bloaty-$BLOATY_VERSION
517 maybe-extract $DEPS_SOURCE_DIR/uftrace "$(basename $UFTRACE_URL)" uftrace-$UFTRACE_VERSION
518
519 # This is in $DEPS_SOURCE_DIR to COPY into containers, which mycpp will directly import.
520
521 # It's also copied into a wedge in install-wedges.
522 clone-mypy $DEPS_SOURCE_DIR/mypy
523
524 if false; then
525 download-to $DEPS_SOURCE_DIR/souffle "$SOUFFLE_URL"
526 maybe-extract $DEPS_SOURCE_DIR/souffle "$(basename $SOUFFLE_URL)" souffle-$SOUFFLE_VERSION
527 fi
528
529 if command -v tree > /dev/null; then
530 tree -L 2 $DEPS_SOURCE_DIR
531 fi
532}
533
534fetch-py() {
535 fetch py_only
536}
537
538mirror-pyflakes() {
539 ### Workaround for network error during release
540 scp \
541 $DEPS_SOURCE_DIR/pyflakes/"$(basename $PYFLAKES_URL)" \
542 oilshell.org:oilshell.org/blob/
543}
544
545mirror-python() {
546 ### Can't reach python.org from some machines
547 scp \
548 $DEPS_SOURCE_DIR/python2/"$(basename $PY2_URL)" \
549 oilshell.org:oilshell.org/blob/
550
551 scp \
552 $DEPS_SOURCE_DIR/python3/"$(basename $PY3_URL)" \
553 oilshell.org:oilshell.org/blob/
554}
555
556wedge-exists() {
557 ### Does an installed wedge already exist?
558
559 local name=$1
560 local version=$2
561 local wedge_dir=${3:-/wedge/oils-for-unix.org}
562
563 local installed=$wedge_dir/pkg/$name/$version
564
565 if test -d $installed; then
566 log "$installed already exists"
567 return 0
568 else
569 return 1
570 fi
571}
572
573#
574# Install
575#
576
577# TODO: py3-libs needs to be a WEDGE, so that that you can run
578# 'wedge build deps/source.medo/py3-libs/' and then get it in
579#
580# _build/wedge/{absolute,relative} # which one?
581#
582# It needs a BUILD DEPENDENCY on:
583# - the python3 wedge, so you can do python3 -m pip install.
584# - the mypy repo, which has test-requirements.txt
585
586download-py3-libs() {
587 ### Download source/binary packages, AFTER python3 is installed
588
589 # Note that this is NOT source code; there is binary code, e.g. in
590 # lxml-*.whl
591
592 local mypy_dir=${1:-$DEPS_SOURCE_DIR/mypy/mypy-$MYPY_VERSION}
593 local py_package_dir=_cache/py3-libs
594 mkdir -p $py_package_dir
595
596 # Avoids a warning, but doesn't fix typed_ast
597 #python3 -m pip download -d $py_package_dir wheel
598
599 python3 -m pip download -d $py_package_dir -r $mypy_dir/test-requirements.txt
600 python3 -m pip download -d $py_package_dir pexpect
601}
602
603install-py3-libs-in-venv() {
604 local venv_dir=$1
605 local mypy_dir=$2 # This is a param for host build vs. container build
606 local package_dir=_cache/py3-libs
607
608 source $venv_dir/bin/activate # enter virtualenv
609
610 # 2023-07 note: we're installing yapf in a DIFFERENT venv, because it
611 # conflicts with MyPy deps!
612 # "ERROR: pip's dependency resolver does not currently take into account all
613 # the packages that are installed."
614
615 # --find-links uses a "cache dir" for packages (weird flag name!)
616
617 # Avoids a warning, but doesn't fix typed_ast
618 #time python3 -m pip install --find-links $package_dir wheel
619
620 upgrade-typed-ast $mypy_dir/mypy-requirements.txt
621
622 # for mycpp/
623 time python3 -m pip install --find-links $package_dir -r $mypy_dir/test-requirements.txt
624
625 # pexpect: for spec/stateful/*.py
626 time python3 -m pip install --find-links $package_dir pexpect
627}
628
629upgrade-typed-ast() {
630 local file=$1
631 sed -i 's/typed_ast.*/typed_ast==1.5.0/' $file
632}
633
634test-typed-ast() {
635 local dir=~/wedge/oils-for-unix.org/pkg/mypy/0.780
636
637 cp -v $dir/mypy-requirements.txt _tmp
638
639 local file=_tmp/mypy-requirements.txt
640 cat $file
641 #echo
642
643 # 1.5.0 fixed this bug
644 # https://github.com/python/typed_ast/issues/169
645
646 upgrade-typed-ast $file
647 echo
648 cat $file
649}
650
651install-py3-libs-from-cache() {
652
653 # As well as end users
654
655 local mypy_dir=${1:-$DEPS_SOURCE_DIR/mypy/mypy-$MYPY_VERSION}
656
657 local py3
658 py3=$(command -v python3)
659 case $py3 in
660 *wedge/oils-for-unix.org/*)
661 ;;
662 *)
663 die "python3 is '$py3', but expected it to be in a wedge"
664 ;;
665 esac
666
667 log "Ensuring pip is installed (interpreter $(command -v python3)"
668 python3 -m ensurepip
669
670 local venv_dir=$USER_WEDGE_DIR/pkg/py3-libs/$PY3_LIBS_VERSION
671 log "Creating venv in $venv_dir"
672
673 # Note: the bin/python3 in this venv is a symlink to python3 in $PATH, i.e.
674 # the /wedge we just built
675 python3 -m venv $venv_dir
676
677 log "Installing MyPy deps in venv"
678
679 # Run in a subshell because it mutates shell state
680 $0 install-py3-libs-in-venv $venv_dir $mypy_dir
681}
682
683install-py3-libs() {
684 ### Invoked by Dockerfile.cpp-small, etc.
685
686 download-py3-libs
687 install-py3-libs-from-cache
688}
689
690
691# zsh notes
692 # Fedora compiler error
693 # zsh ./configure is NOT detecting 'boolcodes', and then it has a broken
694 # fallback in Src/Modules/termcap.c that causes a compile error! It seems
695 # like ncurses-devel should fix this, but it doesn't
696 #
697 # https://koji.fedoraproject.org/koji/rpminfo?rpmID=36987813
698 #
699 # from /home/build/oil/_build/deps-source/zsh/zsh-5.1.1/Src/Modules/termcap.c:38:
700 # /usr/include/term.h:783:56: note: previous declaration of ‘boolcodes’ with type ‘const char * const[]’
701 # 783 | extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[];
702 #
703 # I think the ./configure is out of sync with the actual build?
704
705
706# TODO:
707# - $ROOT_WEDGE_DIR vs. $USER_WEDGE_DIR is duplicating information that's
708# already in each WEDGE file
709
710py-wedges() {
711 ### for build/py.sh all
712
713 echo cmark $CMARK_VERSION $ROOT_WEDGE_DIR
714 echo re2c $RE2C_VERSION $ROOT_WEDGE_DIR
715 echo python2 $PY2_VERSION $ROOT_WEDGE_DIR
716 echo pyflakes $PYFLAKES_VERSION $USER_WEDGE_DIR
717}
718
719cpp-wedges() {
720 ### for ninja / mycpp translation
721
722 echo python3 $PY3_VERSION $ROOT_WEDGE_DIR
723 echo mypy $MYPY_VERSION $USER_WEDGE_DIR
724
725 # py3-libs has a built time dep on both python3 and MyPy, so we're doing it
726 # separately for now
727 #echo py3-libs $PY3_LIBS_VERSION $USER_WEDGE_DIR
728}
729
730spec-bin-wedges() {
731 ### for test/spec-py.sh osh-all
732
733 echo dash $DASH_VERSION $USER_WEDGE_DIR
734 echo bash $BASH_VER $USER_WEDGE_DIR
735 echo bash $BASH5_VER $USER_WEDGE_DIR
736 echo mksh $MKSH_VERSION $USER_WEDGE_DIR
737 echo zsh $ZSH_VERSION $USER_WEDGE_DIR
738 echo busybox $BUSYBOX_VERSION $USER_WEDGE_DIR
739 echo yash $YASH_VERSION $USER_WEDGE_DIR
740}
741
742contributor-wedges() {
743 py-wedges
744 cpp-wedges
745 spec-bin-wedges
746}
747
748extra-wedges() {
749 # Contributors don't need uftrace, bloaty, and probably R-libs
750 # Although R-libs could be useful for benchmarks
751
752 # Test both outside the contianer, as well as inside?
753 echo uftrace $UFTRACE_VERSION $ROOT_WEDGE_DIR
754 echo bloaty $BLOATY_VERSION $ROOT_WEDGE_DIR
755
756 #echo souffle $SOUFFLE_VERSION $USER_WEDGE_DIR
757}
758
759timestamp() {
760 date '+%H:%M:%S'
761}
762
763my-time-tsv() {
764 python3 benchmarks/time_.py \
765 --tsv \
766 --time-span --rusage \
767 "$@"
768}
769
770maybe-install-wedge() {
771 local name=$1
772 local version=$2
773 local wedge_dir=$3 # e.g. $USER_WEDGE_DIR or empty
774
775 local task_file=$WEDGE_LOG_DIR/$name-$version.task.tsv
776 local log_file=$WEDGE_LOG_DIR/$name-$version.log.txt
777
778 echo " TASK $(timestamp) $name $version > $log_file"
779
780 # python3 because it's OUTSIDE the container
781 # Separate columns that could be joined: number of files, total size
782 my-time-tsv --print-header \
783 --field xargs_slot \
784 --field wedge \
785 --field wedge_HREF \
786 --field version \
787 --output $task_file
788
789 if wedge-exists "$name" "$version" "$wedge_dir"; then
790 echo "CACHED $(timestamp) $name $version"
791 return
792 fi
793
794 local -a cmd=( deps/wedge.sh unboxed _build/deps-source/$name/ $version)
795
796 set +o errexit
797 my-time-tsv \
798 --field "$XARGS_SLOT" \
799 --field "$name" \
800 --field "$name-$version.log.txt" \
801 --field "$version" \
802 --append \
803 --output $task_file \
804 "${cmd[@]}" "$@" >$log_file 2>&1
805 local status=$?
806 set -o errexit
807
808 if test "$status" -eq 0; then
809 echo " OK $(timestamp) $name $version"
810 else
811 echo " FAIL $(timestamp) $name $version"
812 fi
813}
814
815dummy-task() {
816 ### For testing log capture
817 local name=$1
818 local version=$2
819
820 echo "Building $name $version"
821
822 # random float between 0 and 3
823 # weirdly we need a seed from bash
824 # https://stackoverflow.com/questions/4048378/random-numbers-generation-with-awk-in-bash-shell
825 local secs
826 secs=$(awk -v seed=$RANDOM 'END { srand(seed); print rand() * 3 }' < /dev/null)
827
828 echo "sleep $secs"
829 sleep $secs
830
831 echo 'stdout'
832 log 'stderr'
833
834 if test $name = 'mksh'; then
835 echo "simulate failure for $name"
836 exit 2
837 fi
838}
839
840readonly WEDGE_LOG_DIR=_build/wedge/logs
841
842dummy-task-wrapper() {
843 # Similar to test/common.sh run-task-with-status, used by
844 # test/{spec,wild}-runner.sh
845 local name=$1
846 local version=$2
847
848 local task_file=$WEDGE_LOG_DIR/$name.task.tsv
849 local log_file=$WEDGE_LOG_DIR/$name.log.txt
850
851 echo " TASK $(timestamp) $name $version > $log_file"
852
853 # python3 because it's OUTSIDE the container
854 # Separate columns that could be joined: number of files, total size
855 my-time-tsv --print-header \
856 --field xargs_slot \
857 --field wedge \
858 --field wedge_HREF \
859 --field version \
860 --output $task_file
861
862 my-time-tsv \
863 --field "$XARGS_SLOT" \
864 --field "$name" \
865 --field "$name.log.txt" \
866 --field "$version" \
867 --append \
868 --output $task_file \
869 $0 dummy-task "$@" >$log_file 2>&1 || true
870
871 echo " DONE $(timestamp) $name $version"
872}
873
874html-head() {
875 # python3 because we're outside containers
876 PYTHONPATH=. python3 doctools/html_head.py "$@"
877}
878
879index-html() {
880 local tasks_tsv=$1
881
882 local base_url='../../../web'
883 html-head --title 'Wedge Builds' \
884 "$base_url/ajax.js" \
885 "$base_url/table/table-sort.js" \
886 "$base_url/table/table-sort.css" \
887 "$base_url/base.css"\
888
889 table-sort-begin 'width60'
890
891 cat <<EOF
892 <p id="home-link">
893 <a href="/">oilshell.org</a>
894 </p>
895
896 <h1>Wedge Builds</h1>
897EOF
898
899 tsv2html3 $tasks_tsv
900
901 cat <<EOF
902 <p>
903 <a href="tasks.tsv">tasks.tsv</a>
904 </p>
905EOF
906
907 table-sort-end 'tasks' # ID for sorting
908}
909
910NPROC=$(nproc)
911#NPROC=1
912
913install-wedge-list() {
914 ### Reads task rows from stdin
915 local parallel=${1:-}
916
917 mkdir -p _build/wedge/logs
918
919 local -a flags
920 if test -n "$parallel"; then
921 log ""
922 log "=== Installing wedges with $NPROC jobs in parallel"
923 log ""
924 flags=( -P $NPROC )
925 else
926 log ""
927 log "=== Installing wedges serially"
928 log ""
929 fi
930
931 # Reads from stdin
932 # Note: --process-slot-var requires GNU xargs! busybox args doesn't have it.
933 #
934 # $name $version $wedge_dir
935 xargs "${flags[@]}" -n 3 --process-slot-var=XARGS_SLOT -- $0 maybe-install-wedge
936
937 #xargs "${flags[@]}" -n 3 --process-slot-var=XARGS_SLOT -- $0 dummy-task-wrapper
938}
939
940write-task-report() {
941 local tasks_tsv=_build/wedge/logs/tasks.tsv
942
943 python3 devtools/tsv_concat.py $WEDGE_LOG_DIR/*.task.tsv > $tasks_tsv
944 log "Wrote $tasks_tsv"
945
946 # TODO: version can be right-justified?
947 here-schema-tsv-4col >_build/wedge/logs/tasks.schema.tsv <<EOF
948column_name type precision strftime
949status integer 0 -
950elapsed_secs float 1 -
951user_secs float 1 -
952start_time float 1 %H:%M:%S
953end_time float 1 %H:%M:%S
954sys_secs float 1 -
955max_rss_KiB integer 0 -
956xargs_slot integer 0 -
957wedge string 0 -
958wedge_HREF string 0 -
959version string 0 -
960EOF
961
962 index-html $tasks_tsv > $WEDGE_LOG_DIR/index.html
963 log "Wrote $WEDGE_LOG_DIR/index.html"
964}
965
966install-spec-bin-fast() {
967 spec-bin-wedges | install-wedge-list T
968 write-task-report
969}
970
971fake-py3-libs-wedge() {
972 local name=py3-libs
973 local version=$PY3_LIBS_VERSION
974
975 local task_file=$WEDGE_LOG_DIR/$name.task.tsv
976 local log_file=$WEDGE_LOG_DIR/$name.log.txt
977
978 my-time-tsv --print-header \
979 --field xargs_slot \
980 --field wedge \
981 --field wedge_HREF \
982 --field version \
983 --output $task_file
984
985 # There is no xargs slot!
986 my-time-tsv \
987 --field "-1" \
988 --field "$name" \
989 --field "$name.log.txt" \
990 --field "$version" \
991 --append \
992 --output $task_file \
993 $0 install-py3-libs >$log_file 2>&1 || true
994
995 echo " FAKE $(timestamp) $name $version"
996}
997
998install-wedges-fast() {
999 local extra=${1:-}
1000
1001 # For contributor setup: we need to use this BEFORE running build/py.sh all
1002 build/py.sh time-helper
1003
1004 echo " START $(timestamp)"
1005
1006 # Do all of them in parallel
1007 if test -n "$extra"; then
1008 { contributor-wedges; extra-wedges; } | install-wedge-list T
1009 else
1010 contributor-wedges | install-wedge-list T
1011 fi
1012
1013 fake-py3-libs-wedge
1014 echo " END $(timestamp)"
1015
1016 write-task-report
1017}
1018
1019install-wedges-soil() {
1020 install-wedges-fast extra
1021}
1022
1023#
1024# Unboxed wedge builds
1025#
1026
1027uftrace-host() {
1028 ### built on demand; run $0 first
1029
1030 # BUG: doesn't detect python3
1031 # WEDGE tells me that it depends on pkg-config
1032 # 'apt-get install pkgconf' gets it
1033 # TODO: Should use python3 WEDGE instead of SYSTEM python3?
1034 deps/wedge.sh unboxed _build/deps-source/uftrace
1035}
1036
1037bloaty-host() {
1038 deps/wedge.sh unboxed _build/deps-source/bloaty
1039}
1040
1041R-libs-host() {
1042 deps/wedge.sh unboxed _build/deps-source/R-libs
1043}
1044
1045#
1046# Wedges built inside a container, for copying into a container
1047#
1048
1049boxed-wedges() {
1050 #### host _build/wedge/binary -> guest container /wedge or ~/wedge
1051
1052 #export-podman
1053
1054 # TODO:
1055 #
1056 # - Add equivalents of spec-bin
1057 # - Use the same manifest as install-wedges-fast
1058 # - so then you can delete the _build/wedge dir to re-run it
1059 # - use xargs -n 1 so it's done serially
1060
1061 # - Do these lazily like we do in install-wedges-fast?
1062
1063 # We can test if the dir _build/wedge/binary/oils-for-unix.org/pkg/FOO exists
1064 # if wedge-exists "$name" "$version" "$wedge_dir"; then
1065 # echo "CACHED $(timestamp) $name $version"
1066 # return
1067 # fi
1068
1069 if false; then
1070 deps/wedge.sh boxed deps/source.medo/time-helper
1071 deps/wedge.sh boxed deps/source.medo/cmark/
1072 deps/wedge.sh boxed deps/source.medo/re2c/
1073 deps/wedge.sh boxed deps/source.medo/python3/
1074 fi
1075
1076 if false; then
1077 deps/wedge.sh boxed deps/source.medo/bloaty/
1078 fi
1079
1080 if true; then
1081 # build with debian-12, because soil-benchmarks2 is, because it has R
1082 deps/wedge.sh boxed deps/source.medo/uftrace/ '' debian-12
1083 # python2 needed everywhere
1084 #deps/wedge.sh boxed deps/source.medo/python2/ '' debian-12
1085
1086 # TODO: build with debian-12
1087 # Used in {benchmarks,benchmarks2,other-tests}
1088 #deps/wedge.sh boxed deps/source.medo/R-libs/ '' debian-12
1089 fi
1090}
1091
1092boxed-spec-bin() {
1093 if true; then
1094 #deps/wedge.sh boxed deps/source.medo/bash '4.4'
1095 deps/wedge.sh boxed deps/source.medo/bash '5.2.21'
1096 fi
1097
1098 if false; then
1099 deps/wedge.sh boxed deps/source.medo/dash
1100 deps/wedge.sh boxed deps/source.medo/mksh
1101 fi
1102
1103 if false; then
1104 # Note: zsh requires libncursesw5-dev
1105 #deps/wedge.sh boxed deps/source.medo/zsh
1106
1107 #deps/wedge.sh boxed deps/source.medo/busybox
1108
1109 # Problem with out of tree build, as above. Skipping for now
1110 deps/wedge.sh boxed deps/source.medo/yash
1111 echo
1112 fi
1113}
1114
1115#
1116# Report
1117#
1118
1119commas() {
1120 # Wow I didn't know this :a trick
1121 #
1122 # OK this is a label and a loop, which makes sense. You can't do it with
1123 # pure regex.
1124 #
1125 # https://shallowsky.com/blog/linux/cmdline/sed-improve-comma-insertion.html
1126 # https://shallowsky.com/blog/linux/cmdline/sed-improve-comma-insertion.html
1127 sed ':a;s/\b\([0-9]\+\)\([0-9]\{3\}\)\b/\1,\2/;ta'
1128}
1129
1130wedge-sizes() {
1131 local tmp=_tmp/wedge-sizes.txt
1132
1133 # -b is --bytes, but use short flag for busybox compat
1134 du -s -b /wedge/*/*/* ~/wedge/*/*/* | awk '
1135 { print $0 # print the line
1136 total_bytes += $1 # accumulate
1137 }
1138END { print total_bytes " TOTAL" }
1139' > $tmp
1140
1141 # printf justifies du output
1142 cat $tmp | commas | xargs -n 2 printf '%15s %s\n'
1143 echo
1144
1145 #du -s --si /wedge/*/*/* ~/wedge/*/*/*
1146 #echo
1147}
1148
1149wedge-report() {
1150 # 4 levels deep shows the package
1151 if command -v tree > /dev/null; then
1152 tree -L 4 /wedge ~/wedge
1153 echo
1154 fi
1155
1156 wedge-sizes
1157
1158 local tmp=_tmp/wedge-manifest.txt
1159
1160 echo 'Biggest files'
1161 if ! find /wedge ~/wedge -type f -a -printf '%10s %P\n' > $tmp; then
1162 # busybox find doesn't have -printf
1163 echo 'find -printf failed'
1164 return
1165 fi
1166
1167 set +o errexit # ignore SIGPIPE
1168 sort -n --reverse $tmp | head -n 20 | commas
1169 set -o errexit
1170
1171 echo
1172
1173 # Show the most common file extensions
1174 #
1175 # I feel like we should be able to get rid of .a files? That's 92 MB, second
1176 # most common
1177 #
1178 # There are also duplicate .a files for Python -- should look at how distros
1179 # get rid of those
1180
1181 cat $tmp | python3 -c '
1182import os, sys, collections
1183
1184bytes = collections.Counter()
1185files = collections.Counter()
1186
1187for line in sys.stdin:
1188 size, path = line.split(None, 1)
1189 path = path.strip() # remove newline
1190 _, ext = os.path.splitext(path)
1191 size = int(size)
1192
1193 bytes[ext] += size
1194 files[ext] += 1
1195
1196#print(bytes)
1197#print(files)
1198
1199n = 20
1200
1201print("Most common file types")
1202for ext, count in files.most_common()[:n]:
1203 print("%10d %s" % (count, ext))
1204
1205print()
1206
1207print("Total bytes by file type")
1208for ext, total_bytes in bytes.most_common()[:n]:
1209 print("%10d %s" % (total_bytes, ext))
1210' | commas
1211}
1212
1213task-five "$@"