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

181 lines, 125 significant
1"""
2bin/NINJA_subgraph.py
3"""
4from __future__ import print_function
5
6from glob import glob
7from fnmatch import fnmatch
8
9from build import ninja_lib
10from build.ninja_lib import mycpp_binary, mycpp_library, main_cc, log
11
12_ = log
13
14
15def NinjaGraph(ru):
16 n = ru.n
17
18 ru.comment('Generated by %s' % __name__)
19
20 #
21 # Files embedded in binary
22 #
23
24 n.rule('embedded-file-gen',
25 command='_bin/shwrap/embedded_file_gen $in > $out',
26 description='embedded_file_gen $in $out')
27
28 # Generated by build/py.sh all -> build/doc.sh all-help
29 # I wish Ninja had DIRECTORY-level dependencies? Because this should
30 # ultimately depend on doc/ref/*.md
31 # We could probably create a _build/ninja-stamp/HELP file and so forth
32 files = glob('_devbuild/help/*')
33
34 # OSH and YSH stdlib
35 tmp = glob('stdlib/ysh/*.ysh') + glob('stdlib/osh/*.sh')
36
37 # Remove this?
38 tmp.extend(glob('stdlib/*.ysh'))
39
40 # exclude test files
41 for path in tmp:
42 if fnmatch(path, '*-test.ysh'):
43 continue
44 if fnmatch(path, '*-test.sh'):
45 continue
46 if fnmatch(path, '*/draft-*'):
47 continue
48
49 files.append(path)
50
51 # Make sure it's DETERMINISTIC
52 files.sort()
53
54 n.build(['_gen/bin/text_files.cc'],
55 'embedded-file-gen',
56 files,
57 implicit=['_bin/shwrap/embedded_file_gen'])
58 n.newline()
59
60 ru.cc_library('//bin/text_files', srcs=['_gen/bin/text_files.cc'])
61
62 #
63 # Programs
64 #
65
66 hello_py_inputs = ninja_lib.TryDynamicDeps('bin/hello.py')
67
68 # library //bin/hello.mycpp
69 mycpp_library(
70 ru,
71 'bin/hello.py',
72 py_inputs=hello_py_inputs,
73 deps=['//mycpp/runtime_pure'],
74 )
75
76 # library //bin/hello.mycpp-souffle
77 mycpp_library(
78 ru,
79 'bin/hello.py',
80 py_inputs=hello_py_inputs,
81 translator='mycpp-souffle',
82 deps=['//mycpp/runtime_pure'],
83 )
84
85 # library //bin/hello.main
86 main_cc(ru, '_gen/bin/hello.mycpp-main.cc', template='win32')
87 main_cc(ru, '_gen/bin/hello.mycpp-souffle-main.cc', template='win32')
88
89 ru.cc_binary('_gen/bin/hello.mycpp-main.cc',
90 deps=[
91 '//bin/hello.mycpp',
92 ],
93 matrix=ninja_lib.COMPILERS_VARIANTS)
94
95 ru.cc_binary('_gen/bin/hello.mycpp-souffle-main.cc',
96 deps=[
97 '//bin/hello.mycpp-souffle',
98 ],
99 matrix=ninja_lib.COMPILERS_VARIANTS)
100
101 # Use the stdlib
102 mycpp_binary(
103 ru,
104 'bin/hello_mylib.py',
105 deps=['//mycpp/runtime'],
106 )
107
108 oils_deps = [
109 '//bin/text_files',
110 '//cpp/core',
111 '//cpp/data_lang',
112 '//cpp/fanos',
113 '//cpp/libc',
114 '//cpp/osh',
115 '//cpp/pgen2',
116 '//cpp/pylib',
117 '//cpp/stdlib',
118 '//cpp/frontend_flag_spec',
119 '//cpp/frontend_match',
120 '//cpp/frontend_pyreadline',
121 '//data_lang/nil8.asdl',
122 '//display/pretty.asdl',
123 '//frontend/arg_types',
124 '//frontend/consts',
125 '//frontend/help_meta',
126 '//frontend/id_kind.asdl',
127 '//frontend/option.asdl',
128 '//frontend/signal',
129 '//frontend/syntax.asdl',
130 '//frontend/types.asdl',
131 '//core/optview',
132 '//core/runtime.asdl',
133 '//core/value.asdl',
134 '//osh/arith_parse',
135 '//ysh/grammar',
136 '//mycpp/runtime',
137 ]
138
139 # TODO: other files should get their own
140 oils_preamble = 'bin/oils_for_unix_preamble.h'
141
142 mycpp_binary(ru,
143 'bin/osh_eval.py',
144 py_inputs=ninja_lib.TryDynamicDeps('bin/osh_eval.py'),
145 preamble=oils_preamble,
146 deps=oils_deps)
147 mycpp_binary(ru,
148 'bin/osh_parse.py',
149 py_inputs=ninja_lib.TryDynamicDeps('bin/osh_parse.py'),
150 preamble=oils_preamble,
151 deps=oils_deps)
152
153 oils_symlinks = ['osh', 'ysh']
154 matrix = (ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS +
155 ninja_lib.OTHER_VARIANTS)
156
157 oils_py_inputs = ninja_lib.TryDynamicDeps('bin/oils_for_unix.py')
158
159 # Main oils-for-unix binary
160 mycpp_binary(
161 ru,
162 'bin/oils_for_unix.py',
163 py_inputs=oils_py_inputs,
164 matrix=matrix,
165 # _bin/cxx-opt/oils-for-unix, NOT _bin/cxx-opt/bin/oils-for-unix
166 bin_path='oils-for-unix',
167 symlinks=oils_symlinks,
168 deps=oils_deps,
169 preprocessed=True,
170 )
171 # Faster variant
172 # this could have been _bin/cxx-opt/oils-for-unix.mycpp-souffle?
173 mycpp_binary(
174 ru,
175 'bin/oils_for_unix.py',
176 py_inputs=oils_py_inputs,
177 translator='mycpp-souffle',
178 bin_path='mycpp-souffle/oils-for-unix',
179 symlinks=oils_symlinks,
180 deps=oils_deps,
181 )