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