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

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