OILS / devtools / bin.sh View on Github | oils.pub

98 lines, 55 significant
1#!/usr/bin/env bash
2#
3# Manage the bin/ directory.
4#
5# Usage:
6# devtools/bin.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12# TODO:
13# - translation should be 'ysh-translate'. Later 'ysh-format'
14readonly OIL_OVM_NAMES=(ysh osh sh true false readlink)
15
16# TODO: probably delete this
17# For osh-dbg.
18ovm-snippet() {
19 local name=$1
20 echo '#!/bin/sh'
21 echo 'exec _bin/oil.ovm-dbg '$name' "$@"'
22}
23
24# For running spec tests quickly.
25make-osh-dbg() {
26 local out=_bin/osh-dbg
27 ovm-snippet osh > $out
28 chmod +x $out
29}
30
31sh-prefix() {
32 cat << 'EOF'
33#!/bin/sh
34REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
35EOF
36}
37
38make-oils-for-unix() {
39 local out=bin/oils-for-unix
40 { sh-prefix
41 echo 'PYTHONPATH=$REPO_ROOT:$REPO_ROOT/vendor exec $REPO_ROOT/bin/oils_for_unix.py "$@"'
42 } > $out
43 chmod +x $out
44 echo "Wrote $out"
45}
46
47#
48# Shell Stubs
49#
50
51sh-snippet() {
52 local wrapped=$1 # e.g. oil.py
53 local action=$2 # e.g. osh
54
55 sh-prefix
56 echo 'PYTHONPATH=$REPO_ROOT:$REPO_ROOT/vendor exec $REPO_ROOT/bin/'$wrapped' '$action' "$@"'
57}
58
59# A snippet that sets PYTHONPATH for bin/oil.py and runs it with the right
60# action.
61oil-dev-snippet() {
62 local action=$1
63 sh-snippet oils_for_unix.py $action
64}
65
66opy-dev-snippet() {
67 local action=$1
68 sh-snippet opy_.py $action
69}
70
71make-src-stubs() {
72 ### bin/ is for running with the Python interpreter.
73 mkdir -p bin
74
75 for link in "${OIL_OVM_NAMES[@]}"; do
76 # bin/ shell wrapper
77 oil-dev-snippet $link > bin/$link
78 chmod +x bin/$link
79 echo "Wrote bin/$link"
80 done
81
82 make-osh-dbg
83
84 make-oils-for-unix
85}
86
87make-ovm-links() {
88 ### _bin/ is for running with OVM app bundles.
89
90 mkdir -p _bin
91
92 for link in "${OIL_OVM_NAMES[@]}"; do
93 # _bin/ symlink
94 ln -s -f --verbose oils-ref.ovm _bin/$link
95 done
96}
97
98"$@"