| 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 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 | shopt -s strict:all 2>/dev/null || true # dogfood for OSH
|
| 12 |
|
| 13 | # adapted from build/ovm-compile.sh
|
| 14 | # and devtools/release.sh
|
| 15 |
|
| 16 | OILS_VERSION=$(head -n 1 oils-version.txt)
|
| 17 | readonly 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 |
|
| 31 | gen-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 |
|
| 43 | tarball-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 |
|
| 52 | make-tar() {
|
| 53 | local app_name=${1:-'oils-for-unix'}
|
| 54 | local sh_name=${2:-'_build/oils.sh'}
|
| 55 | local do_souffle=${3:-T}
|
| 56 |
|
| 57 | local tar=_release/${app_name}.tar
|
| 58 |
|
| 59 | # NOTE: Could move this to the Makefile, which will make it
|
| 60 | mkdir -p _release
|
| 61 |
|
| 62 | local source_name=${app_name//'-'/'_'} # oils_for_unix
|
| 63 | gen-shell-build $source_name $sh_name
|
| 64 |
|
| 65 | # Build source code
|
| 66 | ninja _gen/bin/$source_name.mycpp.cc
|
| 67 |
|
| 68 | if test -n "$do_souffle"; then
|
| 69 | ninja _gen/bin/$source_name.mycpp-souffle.cc
|
| 70 | fi
|
| 71 |
|
| 72 | local sed_expr="s,^,${app_name}-${OILS_VERSION}/,"
|
| 73 | tarball-manifest $source_name \
|
| 74 | | xargs -- tar --create --transform "$sed_expr" --file $tar
|
| 75 |
|
| 76 | local tar_gz=_release/${app_name}-${OILS_VERSION}.tar.gz
|
| 77 | gzip -c $tar > $tar_gz
|
| 78 |
|
| 79 | ls -l _release
|
| 80 | }
|
| 81 |
|
| 82 | test-tar() {
|
| 83 | local install=${1:-}
|
| 84 | local translator=${2:-mycpp}
|
| 85 |
|
| 86 | local tmp=_tmp/native-tar-test # like oil-tar-test
|
| 87 | rm -r -f $tmp
|
| 88 | mkdir -p $tmp
|
| 89 | cd $tmp
|
| 90 | tar -x < ../../_release/oils-for-unix.tar
|
| 91 |
|
| 92 | pushd oils-for-unix-$OILS_VERSION
|
| 93 | build/native.sh tarball-demo $translator
|
| 94 |
|
| 95 | if test -n "$install"; then
|
| 96 | sudo ./install
|
| 97 | fi
|
| 98 |
|
| 99 | popd
|
| 100 | }
|
| 101 |
|
| 102 | test-install-tar() {
|
| 103 | ### test that sudo ./install works
|
| 104 |
|
| 105 | # This is run in the raw-vm soil task
|
| 106 | test-tar T
|
| 107 | }
|
| 108 |
|
| 109 | #
|
| 110 | # hello app
|
| 111 | #
|
| 112 |
|
| 113 | make-hello-tar() {
|
| 114 | make-tar hello _build/oils.sh
|
| 115 |
|
| 116 | # TODO:
|
| 117 | # - turn tar into zip file
|
| 118 | # - bin/hello should #includee mycpp/gc_list.h only?
|
| 119 | # - test it on Windows
|
| 120 | }
|
| 121 |
|
| 122 | test-hello-tar() {
|
| 123 | #local zip="$PWD/_release/hello-$OILS_VERSION.zip"
|
| 124 |
|
| 125 | local tmp=_tmp/hello-tar-test # like oil-tar-test
|
| 126 | rm -r -f $tmp
|
| 127 | mkdir -p $tmp
|
| 128 | cd $tmp
|
| 129 |
|
| 130 | tar -x < ../../_release/hello.tar
|
| 131 |
|
| 132 | #zip -r $zip .
|
| 133 |
|
| 134 | pushd hello-$OILS_VERSION
|
| 135 |
|
| 136 | ./configure
|
| 137 | _build/oils.sh
|
| 138 |
|
| 139 | set +o errexit
|
| 140 | _bin/cxx-opt-sh/hello a b c
|
| 141 | echo "hello status=$?"
|
| 142 | set -o errexit
|
| 143 |
|
| 144 | popd
|
| 145 | }
|
| 146 |
|
| 147 | #
|
| 148 | # More
|
| 149 | #
|
| 150 |
|
| 151 | extract-for-benchmarks() {
|
| 152 | local install=${1:-}
|
| 153 |
|
| 154 | local tar=$PWD/_release/oils-for-unix.tar
|
| 155 | local dest='../benchmark-data/src'
|
| 156 | mkdir -p $dest
|
| 157 |
|
| 158 | pushd $dest
|
| 159 | git pull
|
| 160 | tar -x < $tar
|
| 161 |
|
| 162 | # For benchmarks
|
| 163 | pushd oils-for-unix-$OILS_VERSION
|
| 164 |
|
| 165 | # Remove binaries left over from old attempts
|
| 166 | rm -v _bin/cxx-{dbg,opt}-sh/* || true
|
| 167 |
|
| 168 | ./configure
|
| 169 |
|
| 170 | # devtools/release.sh also has this DWARF 4 hack, for bloaty
|
| 171 | for variant in dbg opt; do
|
| 172 | CXXFLAGS=-gdwarf-4 _build/oils.sh --variant "$variant"
|
| 173 | done
|
| 174 |
|
| 175 | build/native.sh tarball-demo
|
| 176 |
|
| 177 | if test -n "$install"; then
|
| 178 | sudo ./install
|
| 179 | fi
|
| 180 | popd
|
| 181 |
|
| 182 | git add oils-for-unix-$OILS_VERSION
|
| 183 |
|
| 184 | git status
|
| 185 | echo "Now run git commit"
|
| 186 |
|
| 187 | popd
|
| 188 | }
|
| 189 |
|
| 190 | #
|
| 191 | # Repro bug #1731 -- passing duplicate files to tar results in weird hard
|
| 192 | # links!
|
| 193 | #
|
| 194 |
|
| 195 | install-bsdtar() {
|
| 196 | sudo apt-get install libarchive-tools
|
| 197 | }
|
| 198 |
|
| 199 | test-with-bsdtar() {
|
| 200 | pushd _release
|
| 201 | bsdtar -x < oils-for-unix.tar
|
| 202 | popd
|
| 203 | }
|
| 204 |
|
| 205 | "$@"
|