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

175 lines, 112 significant
1"""
2frontend/NINJA_subgraph.py
3"""
4
5from __future__ import print_function
6
7from build import ninja_lib
8from build.ninja_lib import log
9
10_ = log
11
12
13def NinjaGraph(ru):
14 n = ru.n
15
16 ru.comment('Generated by %s' % __name__)
17
18 n.rule('consts-gen',
19 command='_bin/shwrap/consts_gen $action $out_prefix',
20 description='consts_gen $action $out_prefix')
21
22 n.rule('flag-gen',
23 command='_bin/shwrap/flag_gen $action $out_prefix',
24 description='flag_gen $action $out_prefix')
25
26 n.rule('option-gen',
27 command='_bin/shwrap/option_gen $action $out_prefix',
28 description='consts_gen $action $out_prefix')
29
30 n.rule('signal-gen',
31 command='_bin/shwrap/signal_gen $action $out_prefix',
32 description='signal_gen $action $out_prefix')
33
34 ru.py_binary('frontend/consts_gen.py')
35
36 ru.py_binary('frontend/flag_gen.py')
37
38 # TODO: hook this up
39 #ru.py_binary('frontend/lexer_gen.py')
40
41 ru.py_binary('frontend/option_gen.py')
42
43 ru.py_binary('frontend/signal_gen.py')
44
45 prefix = '_gen/frontend/id_kind.asdl'
46 n.build([prefix + '.h', prefix + '.cc'],
47 'consts-gen', [],
48 implicit=['_bin/shwrap/consts_gen'],
49 variables=[
50 ('out_prefix', prefix),
51 ('action', 'cpp'),
52 ])
53 n.newline()
54
55 ru.cc_library(
56 '//frontend/help_meta',
57 srcs=['_gen/frontend/help_meta.cc'],
58 # generated by build/py.all -> build/doc.sh all-help -> doctools/help_gen.py
59 generated_headers=['_gen/frontend/help_meta.h'])
60
61 ru.cc_library('//frontend/id_kind.asdl',
62 srcs=['_gen/frontend/id_kind.asdl.cc'],
63 generated_headers=['_gen/frontend/id_kind.asdl.h'])
64
65 # Similar to above
66 prefix = '_gen/frontend/consts'
67 n.build([prefix + '.h', prefix + '.cc'],
68 'consts-gen', [],
69 implicit=['_bin/shwrap/consts_gen'],
70 variables=[
71 ('out_prefix', prefix),
72 ('action', 'cpp-consts'),
73 ])
74 n.newline()
75
76 ru.cc_library(
77 '//frontend/consts',
78 srcs=['_gen/frontend/consts.cc'],
79 generated_headers=['_gen/frontend/consts.h'],
80 # See header
81 deps=[
82 '//core/runtime.asdl',
83 '//frontend/id_kind.asdl',
84 '//frontend/option.asdl',
85 '//frontend/types.asdl',
86 ])
87
88 prefix = '_gen/frontend/arg_types'
89 n.build([prefix + '.h', prefix + '.cc'],
90 'flag-gen', [],
91 implicit=['_bin/shwrap/flag_gen'],
92 variables=[
93 ('out_prefix', prefix),
94 ('action', 'cpp'),
95 ])
96 n.newline()
97
98 ru.cc_library(
99 '//frontend/arg_types',
100 generated_headers=['_gen/frontend/arg_types.h'],
101 srcs=['_gen/frontend/arg_types.cc'],
102 deps=['//cpp/frontend_flag_spec'],
103 )
104
105 ru.cc_binary(
106 'frontend/arg_types_test.cc',
107 deps=['//frontend/arg_types', '//mycpp/runtime'],
108 matrix=ninja_lib.COMPILERS_VARIANTS,
109 )
110
111 prefix = '_gen/frontend/option.asdl'
112 # no .cc file
113 n.build([prefix + '.h'],
114 'option-gen', [],
115 implicit=['_bin/shwrap/option_gen'],
116 variables=[
117 ('out_prefix', prefix),
118 ('action', 'cpp'),
119 ])
120 n.newline()
121
122 ru.cc_library('//frontend/option.asdl',
123 srcs=[],
124 generated_headers=['_gen/frontend/option.asdl.h'])
125
126 prefix = '_gen/frontend/signal'
127 n.build([prefix + '.h', prefix + '.cc'],
128 'signal-gen', [],
129 implicit=['_bin/shwrap/signal_gen'],
130 variables=[
131 ('out_prefix', prefix),
132 ('action', 'cpp'),
133 ])
134 n.newline()
135
136 ru.cc_library('//frontend/signal',
137 srcs=['_gen/frontend/signal.cc'],
138 generated_headers=['_gen/frontend/signal.h'])
139
140 ru.asdl_library('frontend/types.asdl', pretty_print_methods=False)
141
142 # Uses core/value.asdl, but value.asdl also depeneds on frontend/syntax.asdl
143 #
144 # In Python, that an import line:
145 # if TYPE_CHECKING:
146 # from _devbuild.gen.value_asdl import value_t
147 #
148 # In C++, it creates a forward declaration in the header namespace value_asdl { class value_t }
149 # But an #include in the .cc file, I guess for pretty printing? Yes
150 #
151 # Questions:
152 # - Do we need the deps at all? We have different deps
153 # - #include "hnode.asdl.h" - if pretty_print_methods
154 # - #include "id_kind_asdl.h" - if app_types - TODO: should refactor this
155 # - this is using by VALUE, not just by POINTER
156 # - Should we create a single asdl_library() target?
157 # - What will we do when we switch to tagged pointers? Then we can't
158 # forward declare?
159
160 ru.asdl_library(
161 'frontend/syntax.asdl',
162 deps=[
163 # #include in header file
164 # Problem: asdl_main.py hard-codes this dependency
165 '//frontend/id_kind.asdl',
166
167 # This is a circular dep.
168 # Hm it did not create a problem? I guess only cc_library() deps
169 # can't be circular?
170 '//core/value.asdl',
171 ])
172
173 ru.cc_binary('frontend/syntax_asdl_test.cc',
174 deps=['//frontend/syntax.asdl'],
175 matrix=ninja_lib.COMPILERS_VARIANTS)