| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Build oils-for-unix.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # build/native.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 |
|
| 12 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd) # tsv-lib.sh uses this
|
| 13 | source build/common.sh # log
|
| 14 | source build/dev-shell.sh # python2
|
| 15 |
|
| 16 | # Demo for the oils-for-unix tarball.
|
| 17 | # Notes:
|
| 18 | # - Does not rely on Ninja, which is for the dev build
|
| 19 | # - It shouldn't require 'objcopy'
|
| 20 | # - TODO: do this in the Soil 'cpp' task
|
| 21 |
|
| 22 | tarball-demo() {
|
| 23 | translator=${1:-mycpp}
|
| 24 | mkdir -p _bin
|
| 25 |
|
| 26 | ./configure
|
| 27 |
|
| 28 | time _build/oils.sh --translator "$translator" --skip-rebuild
|
| 29 |
|
| 30 | local bin
|
| 31 | case $translator in
|
| 32 | mycpp)
|
| 33 | bin=_bin/cxx-opt-sh/oils-for-unix.stripped
|
| 34 | ;;
|
| 35 | *)
|
| 36 | bin=_bin/cxx-opt-sh/$translator/oils-for-unix.stripped
|
| 37 | ;;
|
| 38 | esac
|
| 39 |
|
| 40 | ls -l $bin
|
| 41 |
|
| 42 | echo
|
| 43 | echo "You can now run $bin. Example:"
|
| 44 | echo
|
| 45 |
|
| 46 | set -o xtrace
|
| 47 |
|
| 48 | # TODO: Use symlink
|
| 49 | $bin osh -n -c 'echo "hello $name"'
|
| 50 | }
|
| 51 |
|
| 52 | measure-build-times() {
|
| 53 | local variant=${1:-opt}
|
| 54 |
|
| 55 | mkdir -p _bin
|
| 56 |
|
| 57 | ./configure
|
| 58 |
|
| 59 | local out_tsv=_tmp/time-tarball-$variant.tsv
|
| 60 |
|
| 61 | # Header for functions in build/ninja-rules-cpp.sh
|
| 62 | benchmarks/time_.py --tsv --out $out_tsv --rusage --print-header --field verb --field out
|
| 63 |
|
| 64 | time TIME_TSV_OUT=$out_tsv _build/oils.sh --variant "$variant"
|
| 65 |
|
| 66 | echo
|
| 67 | cat $out_tsv
|
| 68 | }
|
| 69 |
|
| 70 | #
|
| 71 | # Ninja Wrappers
|
| 72 | #
|
| 73 |
|
| 74 | oils-demo() {
|
| 75 | export PYTHONPATH='.:vendor/'
|
| 76 |
|
| 77 | echo 'echo hi' | bin/osh_parse.py
|
| 78 | bin/osh_parse.py -c 'ls -l'
|
| 79 |
|
| 80 | local osh=${1:-bin/osh}
|
| 81 |
|
| 82 | # Same functionality in bin/oils-for-unix
|
| 83 | echo 'echo hi' | $osh
|
| 84 | $osh -n -c 'ls -l'
|
| 85 | echo ---
|
| 86 | # ast format is none
|
| 87 | $osh --ast-format none -n -c 'ls -l'
|
| 88 |
|
| 89 | echo '-----'
|
| 90 |
|
| 91 | # Now test some more exotic stuff
|
| 92 | $osh -c '(( a = 1 + 2 * 3 )); echo $a'
|
| 93 |
|
| 94 | $osh -c \
|
| 95 | 'echo "hello"x $$ ${$} $((1 + 2 * 3)) {foo,bar}@example.com'
|
| 96 |
|
| 97 | $osh -c 'for x in 1 2 3; do echo $x; done'
|
| 98 | }
|
| 99 |
|
| 100 | soil-run() {
|
| 101 | if test "${container:-}" = podman; then
|
| 102 |
|
| 103 | # Work around for ASAN not working in podman
|
| 104 |
|
| 105 | local bin=_bin/cxx-dbg/osh
|
| 106 |
|
| 107 | log "Using $bin for podman"
|
| 108 | log ''
|
| 109 |
|
| 110 | else
|
| 111 | local bin=_bin/cxx-asan/osh
|
| 112 | fi
|
| 113 |
|
| 114 | ninja $bin
|
| 115 | echo
|
| 116 |
|
| 117 | $bin --version
|
| 118 | echo
|
| 119 |
|
| 120 | oils-demo $bin
|
| 121 | }
|
| 122 |
|
| 123 | "$@"
|