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

206 lines, 115 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
19_gen-shell-build() {
20 ### Print shell build script to stdout
21
22 local source_name=${1:-'oils_for_unix'}
23 local sh_name=${2:-'_build/oils.sh'}
24
25 local comment="$sh_name: Generated by build/ninja_main.py"
26 sed "s;__FILE_COMMENT__;$comment;" build/oils-preamble.sh
27
28 PYTHONPATH=. build/ninja_main.py shell $source_name
29}
30
31gen-shell-build() {
32 ### Write shell build script
33
34 local source_name=${1:-'oils_for_unix'}
35 local sh_name=${2:-'_build/oils.sh'}
36
37 local out=_build/oils.sh
38 _gen-shell-build $source_name $sh_name > $sh_name
39 chmod +x $sh_name
40 echo " (build/ninja_main.py) -> $sh_name" >&2
41}
42
43tarball-manifest() {
44 ### Which files should be in the release tarball?
45
46 local source_name=${1:-'oils_for_unix'}
47
48 # 100 files
49 PYTHONPATH=. build/ninja_main.py tarball-manifest $source_name
50}
51
52make-tar() {
53 local app_name=${1:-'oils-for-unix'}
54 local sh_name=${2:-'_build/oils.sh'}
55
56 local tar=_release/${app_name}.tar
57
58 # NOTE: Could move this to the Makefile, which will make it
59 mkdir -p _release
60
61 local source_name=${app_name//'-'/'_'} # oils_for_unix
62 gen-shell-build $source_name $sh_name
63
64 case $app_name in
65 oils-for-unix)
66 ninja _bin/cxx-asan/oils-for-unix _bin/cxx-asan/mycpp-souffle/oils-for-unix
67 ;;
68 *)
69 ninja _bin/cxx-asan/bin/$app_name.{mycpp,mycpp-souffle}
70 ;;
71 esac
72
73 local sed_expr="s,^,${app_name}-${OILS_VERSION}/,"
74 tarball-manifest $source_name \
75 | xargs -- tar --create --transform "$sed_expr" --file $tar
76
77 local tar_gz=_release/${app_name}-${OILS_VERSION}.tar.gz
78 gzip -c $tar > $tar_gz
79
80 ls -l _release
81}
82
83test-tar() {
84 local install=${1:-}
85 local translator=${2:-mycpp}
86
87 local tmp=_tmp/native-tar-test # like oil-tar-test
88 rm -r -f $tmp
89 mkdir -p $tmp
90 cd $tmp
91 tar -x < ../../_release/oils-for-unix.tar
92
93 pushd oils-for-unix-$OILS_VERSION
94 build/native.sh tarball-demo $translator
95
96 if test -n "$install"; then
97 sudo ./install
98 fi
99
100 popd
101}
102
103test-install-tar() {
104 ### test that sudo ./install works
105
106 # This is run in the raw-vm soil task
107 test-tar T
108}
109
110#
111# hello app
112#
113
114make-hello-tar() {
115 make-tar hello _build/oils.sh
116
117 # TODO:
118 # - turn tar into zip file
119 # - bin/hello should #includee mycpp/gc_list.h only?
120 # - test it on Windows
121}
122
123test-hello-tar() {
124 #local zip="$PWD/_release/hello-$OILS_VERSION.zip"
125
126 local tmp=_tmp/hello-tar-test # like oil-tar-test
127 rm -r -f $tmp
128 mkdir -p $tmp
129 cd $tmp
130
131 tar -x < ../../_release/hello.tar
132
133 #zip -r $zip .
134
135 pushd hello-$OILS_VERSION
136
137 ./configure
138 _build/oils.sh
139
140 set +o errexit
141 _bin/cxx-opt-sh/hello a b c
142 echo "hello status=$?"
143 set -o errexit
144
145 popd
146}
147
148#
149# More
150#
151
152extract-for-benchmarks() {
153 local install=${1:-}
154
155 local tar=$PWD/_release/oils-for-unix.tar
156 local dest='../benchmark-data/src'
157 mkdir -p $dest
158
159 pushd $dest
160 git pull
161 tar -x < $tar
162
163 # For benchmarks
164 pushd oils-for-unix-$OILS_VERSION
165
166 # Remove binaries left over from old attempts
167 rm -v _bin/cxx-{dbg,opt}-sh/* || true
168
169 ./configure
170
171 # devtools/release.sh also has this DWARF 4 hack, for bloaty
172 for variant in dbg opt; do
173 CXXFLAGS=-gdwarf-4 _build/oils.sh --variant "$variant"
174 done
175
176 build/native.sh tarball-demo
177
178 if test -n "$install"; then
179 sudo ./install
180 fi
181 popd
182
183 git add oils-for-unix-$OILS_VERSION
184
185 git status
186 echo "Now run git commit"
187
188 popd
189}
190
191#
192# Repro bug #1731 -- passing duplicate files to tar results in weird hard
193# links!
194#
195
196install-bsdtar() {
197 sudo apt-get install libarchive-tools
198}
199
200test-with-bsdtar() {
201 pushd _release
202 bsdtar -x < oils-for-unix.tar
203 popd
204}
205
206"$@"