OILS / devtools / release-native.sh View on Github | oils.pub

245 lines, 137 significant
1#!/usr/bin/env bash
2#
3# Make a tarball containing native (C++) code.
4#
5# Usage:
6# devtools/release-native.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11shopt -s strict:all 2>/dev/null || true # dogfood for OSH
12
13# adapted from build/ovm-compile.sh
14# and devtools/release.sh
15
16OILS_VERSION=$(head -n 1 oils-version.txt)
17readonly OILS_VERSION
18
19ninja-main() {
20 PYTHONPATH=. build/ninja_main.py "$@"
21}
22
23_gen-win32-build() {
24 ### Print shell build script to stdout
25
26 local source_name=${1:-'oils_for_unix'}
27 local bat_name=${2:-_build/$source_name.bat}
28
29 local comment="$bat_name: Generated by build/ninja_main.py"
30
31 ninja-main batch $source_name
32}
33
34gen-win32-build() {
35 ### Write shell build script
36 local source_name=${1:-'oils_for_unix'}
37
38 # .cmd uses "delayed variable expansion"?
39 local bat_name=${2:-_build/$source_name.bat}
40
41 _gen-win32-build $source_name $bat_name > $bat_name
42 echo " (build/ninja_main.py) -> $bat_name" >&2
43}
44
45_gen-shell-build() {
46 ### Print shell build script to stdout
47
48 local source_name=${1:-'oils_for_unix'}
49 local sh_name=${2:-}
50
51 local comment="$sh_name: Generated by build/ninja_main.py"
52 sed "s;__FILE_COMMENT__;$comment;" build/oils-preamble.sh
53
54 ninja-main shell $source_name
55}
56
57gen-shell-build() {
58 ### Write shell build script
59
60 local source_name=${1:-'oils_for_unix'}
61
62 local sh_name
63 case $source_name in
64 oils_for_unix) sh_name='_build/oils.sh' ;;
65 *) sh_name="_build/$source_name.sh" ;;
66 esac
67
68 _gen-shell-build $source_name $sh_name > $sh_name
69 chmod +x $sh_name
70 echo " (build/ninja_main.py) -> $sh_name" >&2
71}
72
73tarball-manifest() {
74 ### Which files should be in the release tarball?
75
76 local source_name=${1:-'oils_for_unix'}
77
78 # 100 files
79 ninja-main tarball-manifest $source_name
80}
81
82app-deps() {
83 ### Which files should be in the release tarball?
84
85 local source_name=${1:-'oils_for_unix'}
86
87 ninja-main app-deps $source_name
88}
89
90make-tar() {
91 local app_name=${1:-'oils-for-unix'}
92
93 local tar=_release/${app_name}.tar
94
95 # NOTE: Could move this to the Makefile, which will make it
96 mkdir -p _release
97
98 local source_name=${app_name//'-'/'_'} # oils_for_unix
99 gen-shell-build $source_name
100
101 case $app_name in
102 oils-for-unix)
103 ninja _bin/cxx-dbg/oils-for-unix _bin/cxx-dbg/mycpp-{souffle,nosouffle}/oils-for-unix
104 ;;
105 *)
106 # Also generate windows
107 gen-win32-build $source_name
108 ninja _bin/cxx-asan/bin/$app_name.{mycpp,mycpp-souffle}
109 ;;
110 esac
111
112 local sed_expr="s,^,${app_name}-${OILS_VERSION}/,"
113 tarball-manifest $source_name \
114 | xargs -- tar --create --transform "$sed_expr" --file $tar
115
116 local tar_gz=_release/${app_name}-${OILS_VERSION}.tar.gz
117 gzip -c $tar > $tar_gz
118
119 ls -l _release
120}
121
122test-tar() {
123 local install=${1:-}
124 local translator=${2:-mycpp}
125
126 local tmp=_tmp/native-tar-test # like oil-tar-test
127 rm -r -f $tmp
128 mkdir -p $tmp
129 cd $tmp
130 tar -x < ../../_release/oils-for-unix.tar
131
132 pushd oils-for-unix-$OILS_VERSION
133 build/native.sh tarball-demo $translator
134
135 if test -n "$install"; then
136 sudo ./install
137 fi
138
139 popd
140}
141
142test-install-tar() {
143 ### test that sudo ./install works
144
145 # This is run in the raw-vm soil task
146 test-tar T
147}
148
149#
150# hello app
151#
152
153make-hello-tar() {
154 make-tar hello
155
156 # TODO:
157 # - turn tar into zip file
158 # - bin/hello should #includee mycpp/gc_list.h only?
159 # - test it on Windows
160}
161
162test-hello-tar() {
163 #local zip="$PWD/_release/hello-$OILS_VERSION.zip"
164
165 local tmp=_tmp/hello-tar-test # like oil-tar-test
166 rm -r -f $tmp
167 mkdir -p $tmp
168 cd $tmp
169
170 tar -x < ../../_release/hello.tar
171
172 #zip -r $zip .
173
174 pushd hello-$OILS_VERSION
175
176 ./configure
177 _build/hello.sh
178
179 set +o errexit
180 _bin/cxx-opt-sh/hello a b c
181 echo "hello status=$?"
182 set -o errexit
183
184 popd
185}
186
187#
188# More
189#
190
191extract-for-benchmarks() {
192 local install=${1:-}
193
194 local tar=$PWD/_release/oils-for-unix.tar
195 local dest='../benchmark-data/src'
196 mkdir -p $dest
197
198 pushd $dest
199 git pull
200 tar -x < $tar
201
202 # For benchmarks
203 pushd oils-for-unix-$OILS_VERSION
204
205 # Remove binaries left over from old attempts
206 rm -v _bin/cxx-{dbg,opt}-sh/* || true
207
208 ./configure
209
210 # devtools/release.sh also has this DWARF 4 hack, for bloaty
211 for variant in dbg opt; do
212 CXXFLAGS=-gdwarf-4 _build/oils.sh --variant "$variant"
213 done
214
215 build/native.sh tarball-demo
216
217 if test -n "$install"; then
218 sudo ./install
219 fi
220 popd
221
222 git add oils-for-unix-$OILS_VERSION
223
224 git status
225 echo "Now run git commit"
226
227 popd
228}
229
230#
231# Repro bug #1731 -- passing duplicate files to tar results in weird hard
232# links!
233#
234
235install-bsdtar() {
236 sudo apt-get install libarchive-tools
237}
238
239test-with-bsdtar() {
240 pushd _release
241 bsdtar -x < oils-for-unix.tar
242 popd
243}
244
245"$@"