1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Common functions.
|
4 | # NOTE: The module that sources this must initialize THIS_DIR.
|
5 | #
|
6 | # Usage:
|
7 | # ./common.sh <function name>
|
8 |
|
9 | set -o nounset
|
10 | set -o pipefail
|
11 | set -o errexit
|
12 |
|
13 | # Used by scripts/release.sh too.
|
14 | readonly OSH_BYTERUN=opy/_tmp/repo-with-opy/bin/osh-byterun
|
15 |
|
16 | log() {
|
17 | echo "$@" >&2
|
18 | }
|
19 |
|
20 | die() {
|
21 | log "FATAL: $@"
|
22 | exit 1
|
23 | }
|
24 |
|
25 | opy_() {
|
26 | PYTHONPATH=$THIS_DIR $THIS_DIR/../bin/opy_.py "$@"
|
27 | }
|
28 |
|
29 | # NOTES:
|
30 | # - Exclude _devbuild/cpython-full, but include _devbuild/gen.
|
31 | # - must exclude opy/testdata/, because some of it can't be compiled
|
32 | # - exclude spec/ for spec/stateful tests, which are in Python 3
|
33 | # Has some similarity to test/lint.sh, but not the same.
|
34 | oil-python-sources() {
|
35 | local repo_root=$1
|
36 | local fmt=${2:-'%P\n'}
|
37 |
|
38 | # mycpp: exclude Python 3 sources
|
39 | find $repo_root \
|
40 | -name _tmp -a -prune -o \
|
41 | -name _cache -a -prune -o \
|
42 | -name _chroot -a -prune -o \
|
43 | -name _clone -a -prune -o \
|
44 | -name _deps -a -prune -o \
|
45 | -name _regtest -a -prune -o \
|
46 | -name mycpp -a -prune -o \
|
47 | -name pea -a -prune -o \
|
48 | -name yaks -a -prune -o \
|
49 | -name testdata -a -prune -o \
|
50 | -name Python-2.7.13 -a -prune -o \
|
51 | -name py-yajl -a -prune -o \
|
52 | -name spec -a -prune -o \
|
53 | -name '*.py' -a -printf "$fmt"
|
54 |
|
55 | # TODO: move type-annotated files to pea/, and get rid of py3_parse.py hack
|
56 | }
|
57 |
|
58 | opyc-run() {
|
59 | ../bin/opyc run "$@"
|
60 | }
|
61 |
|
62 | opyc-compile() {
|
63 | ../bin/opyc compile "$@"
|
64 | }
|
65 |
|