OILS / yaks / NINJA_subgraph.py View on Github | oils.pub

98 lines, 66 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 shwrap_path = '_bin/shwrap/mycpp_main'
34
35 # TODO: remove gen-oils-for-unix - it shouldn't be special?
36 n.build(outputs,
37 'gen-oils-for-unix',
38 deps,
39 implicit=[shwrap_path, RULES_PY],
40 variables=[('out_prefix', prefix), ('main_name', main_name),
41 ('shwrap_path', shwrap_path),
42 ('preamble', 'yaks/preamble.h')])
43
44 ru.cc_binary(
45 '_gen/yaks/%s.mycpp.cc' % main_name,
46 # Note: yaks/yaks.py is bad for Python imports, so it's called
47 # yaks_main.py
48 # yaks overlaps with the directory _bin/cxx-opt/yaks/examples
49 #bin_path='yaks_main',
50 preprocessed=True,
51 matrix=ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS,
52 deps=[
53 '//core/optview', # TODO: remove this dep
54 '//core/runtime.asdl',
55 '//core/value.asdl',
56 '//cpp/data_lang',
57 '//cpp/frontend_match',
58 '//data_lang/nil8.asdl',
59 '//frontend/consts',
60 '//frontend/syntax.asdl', # TODO: remove this, value.asdl dep
61 '//mycpp/runtime',
62 '//yaks/yaks.asdl',
63 ])
64
65 ### Custom yaks translation
66 n.newline()
67
68 n.rule('yaks',
69 command='_bin/cxx-opt/yaks/yaks_main.mycpp cpp $in > $out',
70 description='yaks cpp $in > $out')
71 n.newline()
72
73 raw_cc = '_gen/yaks/examples/hello_raw.yaks.cc'
74 example_cc = '_gen/yaks/examples/hello.yaks.cc'
75
76 n.build(
77 [raw_cc],
78 'yaks',
79 ['yaks/examples/hello.yaks'],
80 implicit=['_bin/cxx-opt/yaks/yaks_main.mycpp'],
81 )
82 n.newline()
83
84 n.build([example_cc],
85 'wrap-cc', [raw_cc],
86 implicit=[RULES_PY],
87 variables=[('name', 'hello'), ('preamble_path', '""'),
88 ('translator', 'yaks_main')])
89 n.newline()
90
91 ru.cc_binary(
92 example_cc,
93 matrix=ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS,
94 deps=['//mycpp/runtime'],
95 )
96
97
98# vim: sw=4