| 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,display/pp_hnode,pylib/cgi,data_lang/j8_lite}.py
|
| 73 | )
|
| 74 |
|
| 75 | syntax-abbrev() {
|
| 76 | # Experiment: try to generate something that can be included in
|
| 77 | # _gen/frontend/syntax.asdl.h. It kinda works, but it would need a preamble.
|
| 78 |
|
| 79 | mkdir -p prebuilt/frontend $TEMP_DIR/frontend
|
| 80 | oils-part \
|
| 81 | prebuilt/frontend/syntax_abbrev.mycpp \
|
| 82 | $TEMP_DIR/frontend/syntax_abbrev_raw.mycpp.h \
|
| 83 | FRONTEND_SYNTAX_ABBREV_H \
|
| 84 | '
|
| 85 | namespace syntax_asdl {
|
| 86 | class Token;
|
| 87 | class CompoundWord;
|
| 88 | class DoubleQuoted;
|
| 89 | class SingleQuoted;
|
| 90 | class SimpleVarSub;
|
| 91 | class BracedVarSub;
|
| 92 |
|
| 93 | class command__Simple;
|
| 94 | class expr__Const;
|
| 95 | class expr__Var;
|
| 96 | }
|
| 97 | ' \
|
| 98 | --to-header frontend.syntax_abbrev \
|
| 99 | frontend/syntax_abbrev.py
|
| 100 |
|
| 101 | # Gross hack! Massage mycpp output into something we can use.
|
| 102 | sed -i \
|
| 103 | -e 's/command::/syntax_asdl::command__/g' \
|
| 104 | -e 's/expr::/syntax_asdl::expr__/g' \
|
| 105 | prebuilt/frontend/syntax_abbrev.mycpp.h
|
| 106 | }
|
| 107 |
|
| 108 | asdl-runtime() {
|
| 109 | mkdir -p prebuilt/asdl $TEMP_DIR/asdl
|
| 110 | oils-part \
|
| 111 | prebuilt/asdl/runtime.mycpp \
|
| 112 | $TEMP_DIR/asdl/runtime_raw.mycpp.h \
|
| 113 | ASDL_RUNTIME_MYCPP_H \
|
| 114 | '
|
| 115 | #include "_gen/display/pretty.asdl.h"
|
| 116 |
|
| 117 | using pretty_asdl::doc; // ad hoc
|
| 118 | ' \
|
| 119 | --to-header asdl.runtime \
|
| 120 | --to-header asdl.format \
|
| 121 | "${ASDL_FILES[@]}"
|
| 122 | #--to-header display.pp_hnode \
|
| 123 | }
|
| 124 |
|
| 125 | core-error() {
|
| 126 | ### For cpp/osh_test.cc
|
| 127 |
|
| 128 | # Depends on frontend/syntax_asdl
|
| 129 |
|
| 130 | mkdir -p prebuilt/core $TEMP_DIR/core
|
| 131 | oils-part \
|
| 132 | prebuilt/core/error.mycpp \
|
| 133 | $TEMP_DIR/core/error.mycpp.h \
|
| 134 | CORE_ERROR_MYCPP_H \
|
| 135 | '
|
| 136 | #include "_gen/core/runtime.asdl.h"
|
| 137 | #include "_gen/core/value.asdl.h"
|
| 138 | #include "_gen/frontend/syntax.asdl.h"
|
| 139 |
|
| 140 | using value_asdl::value; // This is a bit ad hoc
|
| 141 | ' \
|
| 142 | --to-header core.error \
|
| 143 | core/error.py \
|
| 144 | core/num.py
|
| 145 | }
|
| 146 |
|
| 147 | frontend-args() {
|
| 148 | ### For cpp/frontend_args_test.cc
|
| 149 |
|
| 150 | # Depends on core/runtime_asdl
|
| 151 |
|
| 152 | mkdir -p prebuilt/frontend $TEMP_DIR/frontend
|
| 153 | oils-part \
|
| 154 | prebuilt/frontend/args.mycpp \
|
| 155 | $TEMP_DIR/frontend/args_raw.mycpp.h \
|
| 156 | FRONTEND_ARGS_MYCPP_H \
|
| 157 | '
|
| 158 | #include "_gen/core/runtime.asdl.h"
|
| 159 | #include "_gen/core/value.asdl.h"
|
| 160 | #include "_gen/display/pretty.asdl.h"
|
| 161 | #include "_gen/frontend/syntax.asdl.h"
|
| 162 | #include "cpp/frontend_flag_spec.h"
|
| 163 |
|
| 164 | using value_asdl::value; // This is a bit ad hoc
|
| 165 | using pretty_asdl::doc;
|
| 166 | ' \
|
| 167 | --to-header asdl.runtime \
|
| 168 | --to-header asdl.format \
|
| 169 | --to-header frontend.args \
|
| 170 | "${ASDL_FILES[@]}" \
|
| 171 | core/error.py \
|
| 172 | core/num.py \
|
| 173 | frontend/args.py
|
| 174 | #--to-header display.pp_hnode \
|
| 175 | }
|
| 176 |
|
| 177 | all() {
|
| 178 | syntax-abbrev
|
| 179 | asdl-runtime
|
| 180 | core-error
|
| 181 | frontend-args
|
| 182 | }
|
| 183 |
|
| 184 | deps() {
|
| 185 | PYTHONPATH='.:vendor' \
|
| 186 | python2 -c 'import sys; from frontend import args; print(sys.modules.keys())'
|
| 187 |
|
| 188 | PYTHONPATH='.:vendor' \
|
| 189 | python2 -c 'import sys; from core import error; print(sys.modules.keys())'
|
| 190 | }
|
| 191 |
|
| 192 | task-five "$@"
|