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

146 lines, 90 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
8: ${LIB_OSH=stdlib/osh}
9source $LIB_OSH/bash-strict.sh
10source $LIB_OSH/task-five.sh
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
13
14source mycpp/common.sh # MYPY_REPO
15source build/ninja-rules-cpp.sh
16
17readonly TEMP_DIR=_build/tmp
18
19oils-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 "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"
65EOF
66 cat $raw
67
68 } > $out_prefix.cc
69}
70
71readonly -a ASDL_FILES=(
72 $REPO_ROOT/{asdl/runtime,asdl/format,core/ansi,pylib/cgi,data_lang/j8_lite}.py \
73)
74
75asdl-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 --to-header asdl.runtime \
83 --to-header asdl.format \
84 "${ASDL_FILES[@]}"
85}
86
87core-error() {
88 # Depends on frontend/syntax_asdl
89
90 mkdir -p prebuilt/core $TEMP_DIR/core
91 oils-part \
92 prebuilt/core/error.mycpp \
93 $TEMP_DIR/core/error.mycpp.h \
94 CORE_ERROR_MYCPP_H \
95 '
96#include "_gen/core/runtime.asdl.h"
97#include "_gen/core/value.asdl.h"
98#include "_gen/frontend/syntax.asdl.h"
99
100using value_asdl::value; // This is a bit ad hoc
101' \
102 --to-header core.error \
103 core/error.py \
104 core/num.py
105}
106
107frontend-args() {
108 # Depends on core/runtime_asdl
109
110 mkdir -p prebuilt/frontend $TEMP_DIR/frontend
111 oils-part \
112 prebuilt/frontend/args.mycpp \
113 $TEMP_DIR/frontend/args_raw.mycpp.h \
114 FRONTEND_ARGS_MYCPP_H \
115 '
116#include "_gen/core/runtime.asdl.h"
117#include "_gen/core/value.asdl.h"
118#include "_gen/frontend/syntax.asdl.h"
119#include "cpp/frontend_flag_spec.h"
120
121using value_asdl::value; // This is a bit ad hoc
122' \
123 --to-header asdl.runtime \
124 --to-header asdl.format \
125 --to-header frontend.args \
126 "${ASDL_FILES[@]}" \
127 core/error.py \
128 core/num.py \
129 frontend/args.py
130}
131
132all() {
133 asdl-runtime
134 core-error
135 frontend-args
136}
137
138deps() {
139 PYTHONPATH='.:vendor' \
140 python2 -c 'import sys; from frontend import args; print(sys.modules.keys())'
141
142 PYTHONPATH='.:vendor' \
143 python2 -c 'import sys; from core import error; print(sys.modules.keys())'
144}
145
146task-five "$@"