/
oil-slice.sh
executable file
·125 lines (96 loc) · 2.48 KB
/
oil-slice.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
#
# Test of the standalone parser.
#
# Usage:
# ./osh_parse.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
shopt -s strict:all 2>/dev/null || true # dogfood for OSH
source types/common.sh
demo() {
export PYTHONPATH='.:vendor/'
echo 'echo hi' | bin/osh_parse.py
bin/osh_parse.py -c 'ls -l'
local osh_eval=${1:-bin/osh_eval.py}
# Same functionality in bin/osh_eval
echo 'echo hi' | $osh_eval
$osh_eval -n -c 'ls -l'
echo ---
# ast format is none
$osh_eval --ast-format none -n -c 'ls -l'
echo '-----'
# Now test some more exotic stuff
$osh_eval -c '(( a = 1 + 2 * 3 ))'
$osh_eval -c \
'echo "hello"x $$ ${$} $((1 + 2 * 3)) {foo,bar}@example.com'
$osh_eval -c 'for x in 1 2 3; do echo $x; done'
}
osh-eval() {
PYTHONPATH=. bin/osh_eval.py "$@"
}
readonly OSH_EVAL_DEPS='_tmp/osh_eval-deps.txt'
deps() {
local prog=$1
local pythonpath='.:vendor'
local out=_build/$prog
mkdir -p $out
build/actions.sh app-deps $prog "$pythonpath" bin.$prog
ls -l $out
#head -n 30 $out/*
echo ---
# Around 16K lines, after stripping down the 'typing' module.
awk '
$1 ~ /^.*\.py$/ { print $1 }
' $out/app-deps-cpython.txt \
| grep -v __init__ | sort | tee _tmp/${prog}-deps.txt | xargs wc -l | sort -n
}
osh-parse-deps() { deps osh_parse; }
osh-eval-deps() { deps osh_eval; }
egrep-deps() {
cat $OSH_EVAL_DEPS | xargs -- egrep "$@"
}
typecheck-all() {
local manifest=$1
local strict_none=${2:-}
# 150 errors left without those flags. But it doesn't impede translating to
# C++ since you have nullptr. Although List[Optional[int]] may be an issue.
#local flags=''
local flags
if test -n "$strict_none"; then
flags='--strict'
else
flags=$MYPY_FLAGS
fi
local log_path=_tmp/err.txt
set +o errexit
cat $manifest | xargs -- $0 typecheck --follow-imports=silent $flags >$log_path
local status=$?
set -o errexit
if test $status -eq 0; then
echo 'OK'
else
echo
cat $log_path
echo
echo 'FAIL'
return 1
fi
}
# The manifest needs to be checked in because we don't have
# _deps/cpython-full on Travis to crawl dependencies.
travis-setup() {
# TODO: add stat.py back. Why does it cause errors?
local exclude='vendor|__future__|mylib.py|/stat.py'
osh-eval-deps
egrep -v "$exclude" $OSH_EVAL_DEPS | tee $OSH_EVAL_MANIFEST
}
travis() {
if test -n "${TRAVIS_SKIP:-}"; then
echo "TRAVIS_SKIP: Skipping $0"
return
fi
typecheck-all $OSH_EVAL_MANIFEST
}
"$@"