OILS / yaks / NINJA_subgraph.py View on Github | oilshell.org

94 lines, 64 significant
1"""
2yaks/NINJA_subgraph.py
3"""
4from __future__ import print_function
5
6from build import ninja_lib
7from build.ninja_lib import log, COMPILERS_VARIANTS
8
9_ = log
10
11# TODO: should have dependencies with sh_binary
12RULES_PY = 'build/ninja-rules-py.sh'
13
14
15def NinjaGraph(ru):
16 n = ru.n
17
18 ru.comment('Generated by %s' % __name__)
19
20 ru.asdl_library('yaks/yaks.asdl')
21
22 ru.cc_binary('yaks/yaks_runtime_test.cc',
23 deps=['//mycpp/runtime'],
24 matrix=COMPILERS_VARIANTS)
25
26 # yaks compiler
27 main_name = 'yaks_main'
28 with open('_build/NINJA/yaks.%s/translate.txt' % main_name) as f:
29 deps = [line.strip() for line in f]
30
31 prefix = '_gen/yaks/%s.mycpp' % main_name
32 outputs = [prefix + '.cc', prefix + '.h']
33 n.build(outputs,
34 'gen-oils-for-unix',
35 deps,
36 implicit=['_bin/shwrap/mycpp_main', RULES_PY],
37 variables=[('out_prefix', prefix), ('main_name', main_name),
38 ('translator', 'yaks'),
39 ('preamble', 'yaks/preamble.h')])
40
41 ru.cc_binary(
42 '_gen/yaks/%s.mycpp.cc' % main_name,
43 # Note: yaks/yaks.py is bad for Python imports, so it's called
44 # yaks_main.py
45 # yaks overlaps with the directory _bin/cxx-opt/yaks/examples
46 #bin_path='yaks_main',
47 preprocessed=True,
48 matrix=ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS,
49 deps=[
50 '//core/optview', # TODO: remove this dep
51 '//core/runtime.asdl',
52 '//core/value.asdl',
53 '//cpp/data_lang',
54 '//cpp/frontend_match',
55 '//data_lang/nil8.asdl',
56 '//frontend/consts',
57 '//mycpp/runtime',
58 '//yaks/yaks.asdl',
59 ])
60
61 ### Custom yaks translation
62 n.newline()
63
64 n.rule('yaks',
65 command='_bin/cxx-opt/yaks/yaks_main.mycpp cpp $in > $out',
66 description='yaks cpp $in > $out')
67 n.newline()
68
69 raw_cc = '_gen/yaks/examples/hello_raw.yaks.cc'
70 example_cc = '_gen/yaks/examples/hello.yaks.cc'
71
72 n.build(
73 [raw_cc],
74 'yaks',
75 ['yaks/examples/hello.yaks'],
76 implicit=['_bin/cxx-opt/yaks/yaks_main.mycpp'],
77 )
78 n.newline()
79
80 n.build([example_cc],
81 'wrap-cc', [raw_cc],
82 implicit=[RULES_PY],
83 variables=[('name', 'hello'), ('preamble_path', '""'),
84 ('translator', 'yaks')])
85 n.newline()
86
87 ru.cc_binary(
88 example_cc,
89 matrix=ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS,
90 deps=['//mycpp/runtime'],
91 )
92
93
94# vim: sw=4