OILS / prebuilt / translate.sh View on Github | oilshell.org

147 lines, 91 significant
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
8set -o nounset
9set -o pipefail
10set -o errexit
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
13
14source mycpp/common.sh # MYPY_REPO
15source devtools/run-task.sh # run-task
16source build/ninja-rules-cpp.sh
17
18readonly TEMP_DIR=_build/tmp
19
20oils-part() {
21 ### Translate ASDL deps for unit tests
22
23 local out_prefix=$1
24 local raw_header=$2
25 local guard=$3
26 local more_include=$4
27 shift 4
28
29 local name=asdl_runtime
30 local raw=$TEMP_DIR/${name}_raw.cc
31
32 mkdir -p $TEMP_DIR
33
34 # j8_lite depends on pyext/fastfunc.pyi
35 local mypypath=$REPO_ROOT:$REPO_ROOT/pyext
36
37 local mycpp=_bin/shwrap/mycpp_main
38
39 ninja $mycpp
40 $mycpp \
41 $mypypath $raw \
42 --header-out $raw_header \
43 "$@"
44
45 {
46 echo "// $out_prefix.h: GENERATED by mycpp"
47 echo
48 echo "#ifndef $guard"
49 echo "#define $guard"
50 echo
51 echo '#include "_gen/asdl/hnode.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"
66EOF
67 cat $raw
68
69 } > $out_prefix.cc
70}
71
72readonly -a ASDL_FILES=(
73 $REPO_ROOT/{asdl/runtime,asdl/format,core/ansi,pylib/cgi,data_lang/j8_lite}.py \
74)
75
76asdl-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 --to-header asdl.runtime \
84 --to-header asdl.format \
85 "${ASDL_FILES[@]}"
86}
87
88core-error() {
89 # Depends on frontend/syntax_asdl
90
91 mkdir -p prebuilt/core $TEMP_DIR/core
92 oils-part \
93 prebuilt/core/error.mycpp \
94 $TEMP_DIR/core/error.mycpp.h \
95 CORE_ERROR_MYCPP_H \
96 '
97#include "_gen/core/runtime.asdl.h"
98#include "_gen/core/value.asdl.h"
99#include "_gen/frontend/syntax.asdl.h"
100
101using value_asdl::value; // This is a bit ad hoc
102' \
103 --to-header core.error \
104 core/error.py \
105 core/num.py
106}
107
108frontend-args() {
109 # Depends on core/runtime_asdl
110
111 mkdir -p prebuilt/frontend $TEMP_DIR/frontend
112 oils-part \
113 prebuilt/frontend/args.mycpp \
114 $TEMP_DIR/frontend/args_raw.mycpp.h \
115 FRONTEND_ARGS_MYCPP_H \
116 '
117#include "_gen/core/runtime.asdl.h"
118#include "_gen/core/value.asdl.h"
119#include "_gen/frontend/syntax.asdl.h"
120#include "cpp/frontend_flag_spec.h"
121
122using value_asdl::value; // This is a bit ad hoc
123' \
124 --to-header asdl.runtime \
125 --to-header asdl.format \
126 --to-header frontend.args \
127 "${ASDL_FILES[@]}" \
128 core/error.py \
129 core/num.py \
130 frontend/args.py
131}
132
133all() {
134 asdl-runtime
135 core-error
136 frontend-args
137}
138
139deps() {
140 PYTHONPATH='.:vendor' \
141 python2 -c 'import sys; from frontend import args; print(sys.modules.keys())'
142
143 PYTHONPATH='.:vendor' \
144 python2 -c 'import sys; from core import error; print(sys.modules.keys())'
145}
146
147run-task "$@"