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

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