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

116 lines, 57 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 mkdir -p _bin
23
24 ./configure
25
26 time _build/oils.sh '' '' SKIP_REBUILD
27
28 local bin=_bin/cxx-opt-sh/oils-for-unix.stripped
29
30 ls -l $bin
31
32 echo
33 echo "You can now run $bin. Example:"
34 echo
35
36 set -o xtrace
37
38 # TODO: Use symlink
39 $bin osh -n -c 'echo "hello $name"'
40}
41
42measure-build-times() {
43 local variant=${1:-opt}
44
45 mkdir -p _bin
46
47 ./configure
48
49 local out_tsv=_tmp/time-tarball-$variant.tsv
50
51 # Header for functions in build/ninja-rules-cpp.sh
52 benchmarks/time_.py --tsv --out $out_tsv --rusage --print-header --field verb --field out
53
54 time TIME_TSV_OUT=$out_tsv _build/oils.sh '' $variant
55
56 echo
57 cat $out_tsv
58}
59
60#
61# Ninja Wrappers
62#
63
64oil-slice-demo() {
65 export PYTHONPATH='.:vendor/'
66
67 echo 'echo hi' | bin/osh_parse.py
68 bin/osh_parse.py -c 'ls -l'
69
70 local osh=${1:-bin/osh}
71
72 # Same functionality in bin/oils-for-unix
73 echo 'echo hi' | $osh
74 $osh -n -c 'ls -l'
75 echo ---
76 # ast format is none
77 $osh --ast-format none -n -c 'ls -l'
78
79 echo '-----'
80
81 # Now test some more exotic stuff
82 $osh -c '(( a = 1 + 2 * 3 )); echo $a'
83
84 $osh -c \
85 'echo "hello"x $$ ${$} $((1 + 2 * 3)) {foo,bar}@example.com'
86
87 $osh -c 'for x in 1 2 3; do echo $x; done'
88}
89
90soil-run() {
91 if test "${container:-}" = podman; then
92
93 # Work around for ASAN not working in podman
94
95 local bin=_bin/cxx-dbg/osh
96
97 log "Using $bin for podman"
98 log ''
99
100 else
101 local bin=_bin/cxx-asan/osh
102 fi
103
104 ninja $bin
105 echo
106
107 echo "Built $bin"
108 echo
109
110 $bin --version
111 echo
112
113 oil-slice-demo $bin
114}
115
116"$@"