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