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

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