| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # xshar - Executable shell archive
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # devtools/xshar.sh <function name>
|
| 7 | #
|
| 8 | # devtools/
|
| 9 | # xshar.sh # this file
|
| 10 | # test-oils.sh # can run benchmarks
|
| 11 | #
|
| 12 | # Results in:
|
| 13 | #
|
| 14 | # _release/test-oils.xshar
|
| 15 | #
|
| 16 | # Runtime deps:
|
| 17 | #
|
| 18 | # /bin/sh
|
| 19 | # tar, gzip -d
|
| 20 | # base64
|
| 21 |
|
| 22 | : ${LIB_OSH=stdlib/osh}
|
| 23 | source $LIB_OSH/bash-strict.sh
|
| 24 | source $LIB_OSH/task-five.sh # run-task
|
| 25 |
|
| 26 | print-shell() {
|
| 27 | local tar=$1
|
| 28 | local main=$2
|
| 29 |
|
| 30 | # Same as soil/worker.sh
|
| 31 | local git_commit
|
| 32 | git_commit=$(git log -n 1 --pretty='format:%H')
|
| 33 |
|
| 34 | sed "s/__GIT_COMMIT__/$git_commit/" <<'EOF'
|
| 35 | #!/bin/sh
|
| 36 |
|
| 37 | export XSHAR_REPO=oilshell/oil
|
| 38 | export XSHAR_GIT_COMMIT=__GIT_COMMIT__
|
| 39 |
|
| 40 | name=$(basename $0) # e.g. hello-xshar.xshar
|
| 41 | default_dir=/tmp/$name.$$
|
| 42 |
|
| 43 | # User can override this, and then _build/oils.sh can use SKIP_REBUILD to make
|
| 44 | # it faster. Multiple runs without compiling.
|
| 45 |
|
| 46 | export XSHAR_DIR=${XSHAR_DIR:-$default_dir}
|
| 47 |
|
| 48 | change_dir() {
|
| 49 | mkdir -p "$XSHAR_DIR"
|
| 50 | cd "$XSHAR_DIR"
|
| 51 | }
|
| 52 |
|
| 53 | extract_data() {
|
| 54 | base64 -d <<'XSHAR_DATA' | tar -x -z
|
| 55 | EOF
|
| 56 |
|
| 57 | # Print code that extracts here doc
|
| 58 | base64 < $tar
|
| 59 |
|
| 60 | cat <<EOF
|
| 61 | XSHAR_DATA
|
| 62 | }
|
| 63 |
|
| 64 | change_dir
|
| 65 | extract_data
|
| 66 | EOF
|
| 67 | echo "$main" '"$@"'
|
| 68 |
|
| 69 | # We don't bother to clean up after, it's in /tmp
|
| 70 | }
|
| 71 |
|
| 72 | create() {
|
| 73 | local main=${1:-devtools/test-oils.sh}
|
| 74 | local manifest=$2
|
| 75 | #shift
|
| 76 |
|
| 77 | local name
|
| 78 | name=$(basename $main .sh)
|
| 79 |
|
| 80 | local tar=_tmp/$name.tar.gz
|
| 81 |
|
| 82 | # Need --files-from because we can run out of ARGV!
|
| 83 | tar --create --gzip --files-from $manifest --file $tar "$main"
|
| 84 | ls -l $tar
|
| 85 |
|
| 86 | local out=_release/$name.xshar
|
| 87 |
|
| 88 | print-shell $tar $main > $out
|
| 89 | chmod +x $out
|
| 90 | ls -l $out
|
| 91 | echo
|
| 92 | }
|
| 93 |
|
| 94 | create-hello() {
|
| 95 | local tmp=_tmp/hello-manifest.txt
|
| 96 | find yaks/ -name '*.py' > $tmp
|
| 97 | create devtools/hello-xshar.sh $tmp
|
| 98 |
|
| 99 | ls -l -h _release
|
| 100 | }
|
| 101 |
|
| 102 | test-oils-manifest() {
|
| 103 | echo '_release/oils-for-unix.tar'
|
| 104 |
|
| 105 | echo 'oil-version.txt'
|
| 106 |
|
| 107 | echo 'benchmarks/time_.py'
|
| 108 | echo 'benchmarks/time-helper.c'
|
| 109 |
|
| 110 | # TODO: implement shell-deps tool
|
| 111 | #
|
| 112 | # osh --tool shell-deps build/py.sh
|
| 113 | echo 'build/dev-shell.sh'
|
| 114 | echo 'build/py.sh'
|
| 115 | echo 'build/common.sh'
|
| 116 | echo 'stdlib/osh/task-five.sh'
|
| 117 | echo 'stdlib/osh/byo-server.sh'
|
| 118 |
|
| 119 | # osh --tool shell-deps benchmarks/osh-runtime.sh
|
| 120 | # copied from benchmarks/osh-runtime.sh
|
| 121 | cat <<'EOF'
|
| 122 | benchmarks/osh-runtime.sh
|
| 123 | benchmarks/common.sh
|
| 124 | benchmarks/id.sh
|
| 125 | soil/common.sh
|
| 126 | test/common.sh
|
| 127 | test/tsv-lib.sh
|
| 128 | EOF
|
| 129 | echo 'benchmarks/gc_stats_to_tsv.py'
|
| 130 | echo 'devtools/tsv_concat.py'
|
| 131 |
|
| 132 | find testdata/osh-runtime -type f
|
| 133 |
|
| 134 | find Python-2.7.13/ -type f
|
| 135 | }
|
| 136 |
|
| 137 | create-test-oils() {
|
| 138 | devtools/release-native.sh make-tar
|
| 139 |
|
| 140 | local tmp=_tmp/test-oils-manifest.txt
|
| 141 | test-oils-manifest > $tmp
|
| 142 | create devtools/test-oils.sh $tmp
|
| 143 | ls -l -h _release
|
| 144 | }
|
| 145 |
|
| 146 | soil-run-hello() {
|
| 147 | create-hello
|
| 148 | _release/hello-xshar.xshar main a b c
|
| 149 | }
|
| 150 |
|
| 151 | soil-run-test-oils() {
|
| 152 | create-test-oils
|
| 153 |
|
| 154 | # Demo of flag parsing
|
| 155 | XSHAR_DIR=/tmp/test-oils.xshar.REUSED _release/test-oils.xshar osh-runtime \
|
| 156 | --num-iters 1 --num-shells 1 --num-workloads 1
|
| 157 |
|
| 158 | # Run it twice to test that SKIP_REBUILD works
|
| 159 | XSHAR_DIR=/tmp/test-oils.xshar.REUSED _release/test-oils.xshar --help
|
| 160 | XSHAR_DIR=/tmp/test-oils.xshar.REUSED _release/test-oils.xshar --version
|
| 161 | }
|
| 162 |
|
| 163 | task-five "$@"
|