diff --git a/bin/NINJA_subgraph.py b/bin/NINJA_subgraph.py index d9edb31743..ea0a9e806d 100644 --- a/bin/NINJA_subgraph.py +++ b/bin/NINJA_subgraph.py @@ -80,14 +80,15 @@ def NinjaGraph(ru): ('translator', translator), ('preamble', 'cpp/preamble.h'), ] - if translator == 'mycpp-souffle': - variables.append( - ('extra_mycpp_opts', '--minimize-stack-roots')) + if translator == 'mycpp': + shwrap_path = '_bin/shwrap/mycpp_main' + else: + shwrap_path = '_bin/shwrap/mycpp_main_souffle' n.build(outputs, 'gen-oils-for-unix', deps, - implicit=['_bin/shwrap/mycpp_main', RULES_PY], + implicit=[shwrap_path, RULES_PY], variables=variables) if main_name == 'oils_for_unix': diff --git a/build/dynamic-deps.sh b/build/dynamic-deps.sh index 91e527e610..9d8754a464 100755 --- a/build/dynamic-deps.sh +++ b/build/dynamic-deps.sh @@ -196,9 +196,6 @@ write-mycpp() { | mysort \ | tee $deps - # EXTRA FILE - echo '_bin/datalog/dataflow' >> $deps - echo echo $dir/* } diff --git a/build/ninja-rules-py.sh b/build/ninja-rules-py.sh index e8ce5e7a8c..27aceb03ad 100755 --- a/build/ninja-rules-py.sh +++ b/build/ninja-rules-py.sh @@ -18,6 +18,11 @@ source build/dev-shell.sh # python2 in $PATH #source devtools/types.sh # typecheck-files source $REPO_ROOT/test/tsv-lib.sh # time-tsv +die() { + echo "$@" >& 2 + exit 1 +} + example-main-wrapper() { ### Used by mycpp/examples @@ -133,13 +138,13 @@ print-wrap-cc() { # main() function case $translator in - mycpp) + mycpp_main|mycpp_main_souffle) example-main-wrapper $main_module ;; - yaks) + yaks_main) main-wrapper $main_module ;; - pea) + pea_main) main-wrapper $main_module #echo '#include ' #echo 'int main() { printf("stub\n"); return 1; }' @@ -303,6 +308,17 @@ exit $status EOF } +shwrap-mycpp-souffle() { + cat <<'EOF' +MYPYPATH=$1 # e.g. $REPO_ROOT/mycpp +out=$2 +shift 2 + +# Add an extra flag, and also depends on _bin/datalog +exec _bin/shwrap/mycpp_main $MYPYPATH $out --minimize-stack-roots "$@" +EOF +} + shwrap-pea() { ### Part of shell template for pea executable @@ -353,6 +369,9 @@ EOF mycpp) shwrap-mycpp ;; + mycpp-souffle) + shwrap-mycpp-souffle + ;; pea) shwrap-pea ;; diff --git a/build/ninja_lib.py b/build/ninja_lib.py index a73093de84..65a74e1d50 100644 --- a/build/ninja_lib.py +++ b/build/ninja_lib.py @@ -518,12 +518,19 @@ def asdl_library(self, ) def py_binary(self, main_py, deps_base_dir='_build/NINJA', template='py'): - """ - Wrapper for Python script with dynamically discovered deps + """Wrapper for Python script with dynamically discovered deps + + Args: + template: py, mycpp, or pea + + Example: + _bin/shwrap/mycpp_main wraps mycpp/mycpp_main.py + - using dependencies from prebuilt/ninja/mycpp.mycpp_main/deps.txt + - with the 'shwrap-mycpp' template defined in build/ninja-lib.sh """ rel_path, _ = os.path.splitext(main_py) - py_module = rel_path.replace( - '/', '.') # asdl/asdl_main.py -> asdl.asdl_main + # asdl/asdl_main.py -> asdl.asdl_main + py_module = rel_path.replace('/', '.') deps_path = os.path.join(deps_base_dir, py_module, 'deps.txt') with open(deps_path) as f: @@ -531,8 +538,8 @@ def py_binary(self, main_py, deps_base_dir='_build/NINJA', template='py'): deps.remove(main_py) # raises ValueError if it's not there - basename = os.path.basename(rel_path) - self.n.build('_bin/shwrap/%s' % basename, + shwrap_name = os.path.basename(rel_path) + self.n.build('_bin/shwrap/%s' % shwrap_name, 'write-shwrap', [main_py] + deps, variables=[('template', template)]) self.n.newline() diff --git a/mycpp/NINJA_subgraph.py b/mycpp/NINJA_subgraph.py index 5653009b5b..282961b968 100644 --- a/mycpp/NINJA_subgraph.py +++ b/mycpp/NINJA_subgraph.py @@ -14,10 +14,20 @@ def DefineTargets(ru): + # Creates _bin/shwrap/mycpp_main ru.py_binary('mycpp/mycpp_main.py', deps_base_dir='prebuilt/ninja', template='mycpp') + # mycpp wrapper that depends on _bin/datalog/dataflow, a binary created + # from Souffle datalog! + ru.n.build( + '_bin/shwrap/mycpp_main_souffle', + 'write-shwrap', + implicit=['_bin/shwrap/mycpp_main', '_bin/datalog/dataflow'], + variables=[('template', 'mycpp-souffle')], + ) + ru.cc_library( '//mycpp/runtime', # Could separate into //mycpp/runtime_{marksweep,bumpleak} @@ -170,18 +180,21 @@ def TranslatorSubgraph(ru, translator, ex): # Note: build/ninja-rules-py.sh writes this 'shwrap' # It depends on MYPY_WEDGE and PY3_LIBS_WEDGE translator_wrapper = '_bin/shwrap/pea_main' - base_translator = 'pea' translate_rule = 'translate-pea' - else: + elif translator == 'mycpp': translate_rule = 'translate-mycpp' - base_translator = 'mycpp' translator_wrapper = '_bin/shwrap/mycpp_main' + elif translator == 'mycpp-souffle': + translate_rule = 'translate-mycpp-souffle' + translator_wrapper = '_bin/shwrap/mycpp_main_souffle' + else: + raise AssertionError('translator = %r' % translator) translator_vars = [ ('mypypath', '$NINJA_REPO_ROOT/mycpp:$NINJA_REPO_ROOT/pyext'), ] - if translator == 'mycpp-souffle': - translator_vars.append(('extra_mycpp_opts', '--minimize-stack-roots')) + #if translator == 'mycpp-souffle': + # translator_vars.append(('extra_mycpp_opts', '--minimize-stack-roots')) n.build( raw, @@ -198,12 +211,17 @@ def TranslatorSubgraph(ru, translator, ex): main_cc_src = '_gen/mycpp/examples/%s.%s.cc' % (ex, translator) # Make a translation unit - n.build(main_cc_src, - 'wrap-cc', - raw, - implicit=[RULES_PY], - variables=[('name', ex), ('preamble_path', preamble_path), - ('translator', base_translator)]) + n.build( + main_cc_src, + 'wrap-cc', + raw, + implicit=[RULES_PY], + variables=[ + ('name', ex), + ('preamble_path', preamble_path), + # translator is used to determine wrap-cc + ('translator', os.path.basename(translator_wrapper)) + ]) n.newline() @@ -260,10 +278,14 @@ def NinjaGraph(ru): n.newline() # mycpp and pea have the same interface - n.rule( - 'translate-mycpp', - command='_bin/shwrap/mycpp_main $mypypath $out $in $extra_mycpp_opts', - description='mycpp $mypypath $out $in') + n.rule('translate-mycpp', + command='_bin/shwrap/mycpp_main $mypypath $out $in', + description='mycpp $mypypath $out $in') + n.newline() + + n.rule('translate-mycpp-souffle', + command='_bin/shwrap/mycpp_main_souffle $mypypath $out $in', + description='mycpp-souffle $mypypath $out $in') n.newline() n.rule('translate-pea', diff --git a/prebuilt/ninja/mycpp.mycpp_main/deps.txt b/prebuilt/ninja/mycpp.mycpp_main/deps.txt index 40d9764337..7ebc00358e 100644 --- a/prebuilt/ninja/mycpp.mycpp_main/deps.txt +++ b/prebuilt/ninja/mycpp.mycpp_main/deps.txt @@ -10,4 +10,3 @@ mycpp/translate.py mycpp/util.py mycpp/virtual_pass.py mycpp/visitor.py -_bin/datalog/dataflow diff --git a/yaks/NINJA_subgraph.py b/yaks/NINJA_subgraph.py index 2c448eaf83..16be6a1e32 100644 --- a/yaks/NINJA_subgraph.py +++ b/yaks/NINJA_subgraph.py @@ -35,7 +35,7 @@ def NinjaGraph(ru): deps, implicit=['_bin/shwrap/mycpp_main', RULES_PY], variables=[('out_prefix', prefix), ('main_name', main_name), - ('translator', 'yaks'), + ('translator', 'yaks_main'), ('preamble', 'yaks/preamble.h')]) ru.cc_binary( @@ -82,7 +82,7 @@ def NinjaGraph(ru): 'wrap-cc', [raw_cc], implicit=[RULES_PY], variables=[('name', 'hello'), ('preamble_path', '""'), - ('translator', 'yaks')]) + ('translator', 'yaks_main')]) n.newline() ru.cc_binary(