OILS / devtools / xshar.sh View on Github | oilshell.org

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