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