OILS / test / spec-bin.sh View on Github | oilshell.org

273 lines, 136 significant
1#!/usr/bin/env bash
2#
3# Build binaries for the spec tests. This is necessary because they tickle
4# behavior in minor versions of each shell.
5#
6# Usage:
7# test/spec-bin.sh <function name>
8#
9# Instructions:
10# test/spec-bin.sh download # Get the right version of every tarball
11# test/spec-bin.sh extract-all # Extract source
12# test/spec-bin.sh build-all # Compile
13# test/spec-bin.sh copy-all # Put them in ../oil_DEPS/spec-bin
14# test/spec-bin.sh test-all # Run a small smoke test
15#
16# Once you've run all steps manually and understand how they work, run them
17# all at once with:
18#
19# test/spec-bin.sh all-steps
20
21set -o nounset
22set -o pipefail
23set -o errexit
24
25REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
26
27source devtools/run-task.sh
28source test/spec-common.sh
29
30# This dir is a sibling to the repo to make it easier to use containers
31readonly TAR_DIR=$REPO_ROOT/_cache/spec-bin
32readonly DEPS_DIR=$REPO_ROOT/../oil_DEPS/spec-bin
33
34#
35# "Non-hermetic"
36#
37
38link-busybox-ash() {
39 ### Non-hermetic ash only used for benchmarks / Soil dev-minimal
40
41 # Could delete this at some point
42 mkdir -p _tmp/shells
43 ln -s -f --verbose "$(which busybox)" _tmp/shells/ash
44}
45
46# dash and bash should be there by default on Ubuntu.
47install-shells-with-apt() {
48 ### Non-hermetic shells; test/spec-bin.sh replaces this for most purposes
49
50 set -x # show what needs sudo
51
52 # pass -y to install in an automated way
53 sudo apt "$@" install busybox-static mksh zsh
54 set +x
55 link-busybox-ash
56}
57
58#
59# Our own hermetic copies
60#
61
62# The authoritative versions!
63download() {
64 mkdir -p $TAR_DIR
65
66 # TODO: upgrade zsh and mksh
67
68 wget --no-clobber --directory $TAR_DIR \
69 https://www.oilshell.org/blob/spec-bin/$BASH_NAME.tar.gz \
70 https://www.oilshell.org/blob/spec-bin/$BUSYBOX_NAME.tar.bz2 \
71 https://www.oilshell.org/blob/spec-bin/$DASH_NAME.tar.gz \
72 https://www.oilshell.org/blob/spec-bin/mksh-R52c.tgz \
73 https://www.oilshell.org/blob/spec-bin/zsh-5.1.1.tar.xz \
74 https://www.oilshell.org/blob/spec-bin/$YASH_NAME.tar.xz
75}
76
77extract-all() {
78 pushd $TAR_DIR
79
80 # Remove name collision: spec-bin/mksh could be a FILE and a DIRECTORY.
81 # This is unfortunately how their tarball is laid out.
82 rm --verbose -r -f mksh mksh-R52c
83
84 for archive in *.tar.* *.tgz; do
85 echo $archive
86 tar --extract --file $archive
87 done
88 mv --verbose --no-target-directory mksh mksh-R52c # so it doesn't collide
89 popd
90}
91
92build-zsh() {
93 mkdir -p $DEPS_DIR/_zsh
94 pushd $DEPS_DIR/_zsh
95
96 # FIX for Github Actions, there's "no controlling tty", so add --with-tcsetpgrp
97 # https://www.linuxfromscratch.org/blfs/view/7.5/postlfs/zsh.html
98
99 # This builds config.modules
100 $TAR_DIR/zsh-5.1.1/configure --disable-dynamic --with-tcsetpgrp
101
102 # Build a static version of ZSH
103
104 # For some reason the regex module isn't included if we --disable-dynamic?
105 # name=zsh/regex modfile=Src/Modules/regex.mdd link=no
106 # ->
107 # name=zsh/regex modfile=Src/Modules/regex.mdd link=static
108
109 # INSTALL says I need this after editing config.modules.
110 sed -i 's/regex.mdd link=no/regex.mdd link=static/' config.modules
111 make prep
112
113 make
114
115 # This way works on a given machine, but the binaries can't be relocated!
116 #./configure --prefix $prefix
117 #make
118 #make install
119 popd
120}
121
122# bash/dash: ./configure; make
123# mksh: sh Build.sh
124# busybox: make defconfig (default config); make
125
126build-bash() {
127 mkdir -p $DEPS_DIR/_bash
128 pushd $DEPS_DIR/_bash
129 $TAR_DIR/$BASH_NAME/configure
130 make
131 popd
132}
133
134build-dash() {
135 mkdir -p $DEPS_DIR/_dash
136 pushd $DEPS_DIR/_dash
137
138 $TAR_DIR/$DASH_NAME/configure
139 make
140 popd
141}
142
143build-mksh() {
144 mkdir -p $DEPS_DIR/_mksh
145 pushd $DEPS_DIR/_mksh
146
147 sh $TAR_DIR/mksh-R52c/Build.sh
148
149 popd
150}
151
152build-busybox() {
153 mkdir -p $DEPS_DIR/_busybox
154 pushd $DEPS_DIR/_busybox
155
156 # Out of tree instructions from INSTALL
157 make KBUILD_SRC=$TAR_DIR/$BUSYBOX_NAME -f $TAR_DIR/$BUSYBOX_NAME/Makefile defconfig
158 make
159
160 popd
161}
162
163build-yash() {
164 # yash isn't written with autotools or cmake
165 # It seems like it has to be configured and built in the same dir.
166
167 pushd $TAR_DIR/$YASH_NAME
168
169 # 9/2021: Somehow hit this on my VirtualBox VM
170 # The terminfo (curses) library is unavailable!
171 # Add the "--disable-lineedit" option and try again.
172 ./configure --disable-lineedit --prefix=$DEPS_DIR/_yash
173 make
174 make install
175
176 popd
177}
178
179build-all() {
180 build-bash
181 build-dash
182 build-mksh
183 build-busybox
184 build-yash
185
186 # ZSH is a bit special
187 build-zsh
188}
189
190copy-all() {
191 pushd $DEPS_DIR
192 cp -f -v _bash/bash .
193 cp -f -v _dash/src/dash .
194 cp -f -v _mksh/mksh .
195 cp -f -v _busybox/busybox .
196 cp -f -v _yash/bin/yash .
197
198 ln -s -f -v busybox ash
199
200 # In its own tree
201 #ln -s -f -v zsh-out/bin/zsh .
202
203 # Static binary
204 cp -f -v _zsh/Src/zsh .
205 popd
206}
207
208test-all() {
209 for sh in bash dash zsh mksh ash yash; do
210 $DEPS_DIR/$sh -c 'echo "Hello from $0"'
211
212 # bash and zsh depend on libtinfo, but others don't
213 # ash and zsh depend on libm, but others don't
214 # bash and zsh depend on libdl, but others don't
215 ldd $DEPS_DIR/$sh
216 done
217}
218
219#
220# NOTE: This is older stuff I saved. We may want to use newer shell versions?
221#
222
223_wget() {
224 wget --no-clobber --directory $TAR_DIR "$@"
225}
226
227download-original-source() {
228 # Note: downloading from oilshell.org/blob/spec-bin also uses this dir
229 mkdir -p $TAR_DIR
230
231 # https://tiswww.case.edu/php/chet/bash/bashtop.html - 9/2016 release
232 # https://ftp.gnu.org/gnu/bash/
233 _wget https://ftp.gnu.org/gnu/bash/bash-5.2.tar.gz
234
235 # https://www.mirbsd.org/mksh.htm
236 _wget https://www.mirbsd.org/MirOS/dist/mir/mksh/mksh-R59.tgz
237
238 # https://tracker.debian.org/pkg/dash -- old versions
239 # http://www.linuxfromscratch.org/blfs/view/svn/postlfs/dash.html
240 _wget http://gondor.apana.org.au/~herbert/dash/files/dash-0.5.10.2.tar.gz
241
242 # http://zsh.sourceforge.net/News/
243 #_wget https://downloads.sourceforge.net/project/zsh/zsh/5.8.1/zsh-5.8.1.tar.xz
244 _wget https://downloads.sourceforge.net/project/zsh/zsh/5.9/zsh-5.9.tar.xz
245
246 _wget https://osdn.net/dl/yash/yash-2.49.tar.xz
247
248 _wget https://www.busybox.net/downloads/busybox-1.35.0.tar.bz2
249}
250
251publish-mirror() {
252 ### Mirror the source tarballs at oilshell.org/blob/spec-bin
253 local user=$1
254 local file=$2
255
256 local dest=$user@oilshell.org:oilshell.org/blob/spec-bin
257
258 scp $file $dest
259}
260
261all-steps() {
262 if test -d $DEPS_DIR; then
263 echo "$DEPS_DIR exists: skipping build of shells"
264 else
265 download # Get the right version of every tarball
266 extract-all # Extract source
267 build-all # Compile
268 copy-all # Put them in ../oil_DEPS/spec-bin
269 test-all # Run a small smoke test
270 fi
271}
272
273run-task "$@"