OILS / opy / regtest.sh View on Github | oilshell.org

139 lines, 74 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# ./regtest.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10readonly THIS_DIR=$(cd $(dirname $0) && pwd)
11source $THIS_DIR/common.sh
12
13readonly 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
31all-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
48import() {
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
59manifest() {
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
84compile-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
91checksum() {
92 find _tmp/regtest -type f | xargs $THIS_DIR/../bin/opyc dis-md5 | sort -n
93}
94
95lines() {
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.
101compare-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
112compare-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
133smoke-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"$@"