1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Translate parts of Oil with mycpp, to work around circular deps issue.
|
4 | #
|
5 | # Usage:
|
6 | # prebuilt/translate.sh <function name>
|
7 |
|
8 | : ${LIB_OSH=stdlib/osh}
|
9 | source $LIB_OSH/bash-strict.sh
|
10 | source $LIB_OSH/task-five.sh
|
11 |
|
12 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
13 |
|
14 | source mycpp/common.sh # MYPY_REPO
|
15 | source build/ninja-rules-cpp.sh
|
16 |
|
17 | readonly TEMP_DIR=_build/tmp
|
18 |
|
19 | oils-part() {
|
20 | ### Translate ASDL deps for unit tests
|
21 |
|
22 | local out_prefix=$1
|
23 | local raw_header=$2
|
24 | local guard=$3
|
25 | local more_include=$4
|
26 | shift 4
|
27 |
|
28 | local name=asdl_runtime
|
29 | local raw=$TEMP_DIR/${name}_raw.cc
|
30 |
|
31 | mkdir -p $TEMP_DIR
|
32 |
|
33 | # j8_lite depends on pyext/fastfunc.pyi
|
34 | local mypypath=$REPO_ROOT:$REPO_ROOT/pyext
|
35 |
|
36 | local mycpp=_bin/shwrap/mycpp_main
|
37 |
|
38 | ninja $mycpp
|
39 | $mycpp \
|
40 | $mypypath $raw \
|
41 | --header-out $raw_header \
|
42 | "$@"
|
43 |
|
44 | {
|
45 | echo "// $out_prefix.h: GENERATED by mycpp"
|
46 | echo
|
47 | echo "#ifndef $guard"
|
48 | echo "#define $guard"
|
49 | echo
|
50 | echo '#include "_gen/asdl/hnode.asdl.h"'
|
51 | echo '#include "_gen/display/pretty.asdl.h"'
|
52 | echo '#include "cpp/data_lang.h"'
|
53 | echo '#include "mycpp/runtime.h"'
|
54 | echo "$more_include"
|
55 |
|
56 | cat $raw_header
|
57 |
|
58 | echo "#endif // $guard"
|
59 |
|
60 | } > $out_prefix.h
|
61 |
|
62 | { cat <<EOF
|
63 | // $out_prefix.cc: GENERATED by mycpp
|
64 |
|
65 | #include "$out_prefix.h"
|
66 | EOF
|
67 | cat $raw
|
68 |
|
69 | } > $out_prefix.cc
|
70 | }
|
71 |
|
72 | readonly -a ASDL_FILES=(
|
73 | $REPO_ROOT/{asdl/runtime,asdl/format,display/ansi,display/pretty,pylib/cgi,data_lang/j8_lite}.py \
|
74 | )
|
75 |
|
76 | asdl-runtime() {
|
77 | mkdir -p prebuilt/asdl $TEMP_DIR/asdl
|
78 | oils-part \
|
79 | prebuilt/asdl/runtime.mycpp \
|
80 | $TEMP_DIR/asdl/runtime_raw.mycpp.h \
|
81 | ASDL_RUNTIME_MYCPP_H \
|
82 | '
|
83 | #include "_gen/display/pretty.asdl.h"
|
84 |
|
85 | using pretty_asdl::doc; // ad hoc
|
86 | ' \
|
87 | --to-header asdl.runtime \
|
88 | --to-header asdl.format \
|
89 | "${ASDL_FILES[@]}"
|
90 | }
|
91 |
|
92 | core-error() {
|
93 | ### For cpp/osh_test.cc
|
94 |
|
95 | # Depends on frontend/syntax_asdl
|
96 |
|
97 | mkdir -p prebuilt/core $TEMP_DIR/core
|
98 | oils-part \
|
99 | prebuilt/core/error.mycpp \
|
100 | $TEMP_DIR/core/error.mycpp.h \
|
101 | CORE_ERROR_MYCPP_H \
|
102 | '
|
103 | #include "_gen/core/runtime.asdl.h"
|
104 | #include "_gen/core/value.asdl.h"
|
105 | #include "_gen/frontend/syntax.asdl.h"
|
106 |
|
107 | using value_asdl::value; // This is a bit ad hoc
|
108 | ' \
|
109 | --to-header core.error \
|
110 | core/error.py \
|
111 | core/num.py
|
112 | }
|
113 |
|
114 | frontend-args() {
|
115 | ### For cpp/frontend_args_test.cc
|
116 |
|
117 | # Depends on core/runtime_asdl
|
118 |
|
119 | mkdir -p prebuilt/frontend $TEMP_DIR/frontend
|
120 | oils-part \
|
121 | prebuilt/frontend/args.mycpp \
|
122 | $TEMP_DIR/frontend/args_raw.mycpp.h \
|
123 | FRONTEND_ARGS_MYCPP_H \
|
124 | '
|
125 | #include "_gen/core/runtime.asdl.h"
|
126 | #include "_gen/core/value.asdl.h"
|
127 | #include "_gen/display/pretty.asdl.h"
|
128 | #include "_gen/frontend/syntax.asdl.h"
|
129 | #include "cpp/frontend_flag_spec.h"
|
130 |
|
131 | using value_asdl::value; // This is a bit ad hoc
|
132 | using pretty_asdl::doc;
|
133 | ' \
|
134 | --to-header asdl.runtime \
|
135 | --to-header asdl.format \
|
136 | --to-header frontend.args \
|
137 | "${ASDL_FILES[@]}" \
|
138 | core/error.py \
|
139 | core/num.py \
|
140 | frontend/args.py
|
141 | }
|
142 |
|
143 | all() {
|
144 | asdl-runtime
|
145 | core-error
|
146 | frontend-args
|
147 | }
|
148 |
|
149 | deps() {
|
150 | PYTHONPATH='.:vendor' \
|
151 | python2 -c 'import sys; from frontend import args; print(sys.modules.keys())'
|
152 |
|
153 | PYTHONPATH='.:vendor' \
|
154 | python2 -c 'import sys; from core import error; print(sys.modules.keys())'
|
155 | }
|
156 |
|
157 | task-five "$@"
|