1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./regtest.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | readonly THIS_DIR=$(cd $(dirname $0) && pwd)
|
11 | source $THIS_DIR/common.sh
|
12 |
|
13 | readonly REPO_ROOT=$(cd $THIS_DIR/.. && pwd)
|
14 |
|
15 | # Everything we care about compiling:
|
16 | _all-py-files() {
|
17 | local fmt=$1
|
18 |
|
19 | # Python files (including build scripts and unit tests, which aren't in the
|
20 | # binary).
|
21 | oil-python-sources $REPO_ROOT "$fmt"
|
22 |
|
23 | # - stdlib deps of bin.oil and bin.opy_
|
24 | # NOTE: These end with .pyc
|
25 | cat \
|
26 | $REPO_ROOT/_build/py-to-compile.txt \
|
27 | $REPO_ROOT/_build/{oil,opy}/py-to-compile.txt
|
28 | }
|
29 |
|
30 | # Only compile unique
|
31 | all-py-files() {
|
32 | _all-py-files "$@" | sort | uniq
|
33 | }
|
34 |
|
35 | _copy() {
|
36 | local dest_dir=$1
|
37 | local src_path=$2
|
38 | local dest_rel_path=$3
|
39 |
|
40 | local dest=$dest_dir/$dest_rel_path
|
41 |
|
42 | dest=${dest%c} # .pyc -> py
|
43 |
|
44 | mkdir -p $(dirname $dest)
|
45 | cp -v --no-target-directory $src_path $dest
|
46 | }
|
47 |
|
48 | import() {
|
49 | local dest=_regtest/src
|
50 | mkdir -p $dest
|
51 |
|
52 | all-py-files '%p %P\n' | xargs -n 2 -- $0 _copy $dest
|
53 | }
|
54 |
|
55 | #
|
56 | # Now compiled the files imported
|
57 | #
|
58 |
|
59 | manifest() {
|
60 | # add .pyc at the end
|
61 | find _regtest/src -type f -a -printf '%p %Pc\n'
|
62 | }
|
63 |
|
64 | # 19 seconds on lisa. This should be a benchmark.
|
65 |
|
66 | # TODO: Parallelize with xargs. compile-manifest in build.sh is serial. Just
|
67 | # needs a mkdir.
|
68 |
|
69 | # NOTE: This is like './build.sh compile-manifest', except we don't exclude
|
70 | # docstrings, etc.
|
71 | _compile-manifest() {
|
72 | local dest_dir=$1
|
73 | while read full_src_path rel_dest_path; do
|
74 | local dest=$dest_dir/$rel_dest_path
|
75 | mkdir -p $(dirname $dest)
|
76 |
|
77 | # stdout is saved and linked on /release/$VERSION/index.html
|
78 | echo "$full_src_path"
|
79 |
|
80 | $THIS_DIR/../bin/opyc compile $full_src_path $dest
|
81 | done
|
82 | }
|
83 |
|
84 | compile-all() {
|
85 | local pat=${1:-}
|
86 | local dest_dir=_tmp/regtest
|
87 | mkdir -p $dest_dir
|
88 | time manifest | egrep "$pat" | _compile-manifest $dest_dir
|
89 | }
|
90 |
|
91 | checksum() {
|
92 | find _tmp/regtest -type f | xargs $THIS_DIR/../bin/opyc dis-md5 | sort -n
|
93 | }
|
94 |
|
95 | lines() {
|
96 | find _regtest/src -type f | xargs wc -l | sort -n
|
97 | }
|
98 |
|
99 | # For debugging golden differences. We want it to be the same on multiple
|
100 | # machines.
|
101 | compare-other-machine() {
|
102 | local rel_path=${1:-'opy/compiler2/transformer.pyc'}
|
103 | # TODO: Copy zip from flanders?
|
104 | local zip=_tmp/flanders/bytecode-opy.zip
|
105 |
|
106 | ls -l _tmp/regtest/$rel_path
|
107 |
|
108 | unzip -p $rel_path $zip | od -c
|
109 | }
|
110 |
|
111 | # One-off debugging
|
112 | compare-flanders() {
|
113 | #local rel_path=${1:-'core/word_test.pyc'}
|
114 | #local rel_path=${1:-'core/word_compile.pyc'}
|
115 | local rel_path=${1:-'_devbuild/gen/osh_asdl.pyc'}
|
116 |
|
117 | local mine=_tmp/regtest/$rel_path
|
118 | local flanders=_tmp/flanders-regtest/$rel_path
|
119 |
|
120 | # Not accurate because of timestamps
|
121 | #md5sum $mine $flanders
|
122 |
|
123 | # Hm somehow these checksums are different, but the 'dis' dumps are the same.
|
124 | # I guess an ordering issue that goes awa when you print?
|
125 | ../bin/opyc dis-md5 $mine $flanders
|
126 |
|
127 | ../bin/opyc dis $mine > _tmp/mine.txt
|
128 | ../bin/opyc dis $flanders > _tmp/flanders.txt
|
129 |
|
130 | diff -u _tmp/{mine,flanders}.txt
|
131 | }
|
132 |
|
133 | smoke-three-modes() {
|
134 | compile oil
|
135 | $THIS_DIR/../bin/opyc eval '1+2*3'
|
136 | echo '4+5*6' | $THIS_DIR/../bin/opyc repl
|
137 | }
|
138 |
|
139 | "$@"
|