OILS / build / native.sh View on Github | oilshell.org

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