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

188 lines, 132 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_bin, 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 mycpp_bin(ru,
86 '//bin/hello.mycpp',
87 template='win32',
88 matrix=ninja_lib.COMPILERS_VARIANTS)
89 mycpp_bin(ru,
90 '//bin/hello.mycpp-souffle',
91 template='win32',
92 matrix=ninja_lib.COMPILERS_VARIANTS)
93
94 # Use the stdlib
95 mycpp_binary(
96 ru,
97 'bin/hello_mylib.py',
98 deps=['//mycpp/runtime'],
99 )
100
101 oils_deps = [
102 '//bin/text_files',
103 '//cpp/core',
104 '//cpp/data_lang',
105 '//cpp/fanos',
106 '//cpp/libc',
107 '//cpp/osh',
108 '//cpp/pgen2',
109 '//cpp/pylib',
110 '//cpp/stdlib',
111 '//cpp/frontend_flag_spec',
112 '//cpp/frontend_match',
113 '//cpp/frontend_pyreadline',
114 '//data_lang/nil8.asdl',
115 '//display/pretty.asdl',
116 '//frontend/arg_types',
117 '//frontend/consts',
118 '//frontend/help_meta',
119 '//frontend/id_kind.asdl',
120 '//frontend/option.asdl',
121 '//frontend/signal',
122 '//frontend/syntax.asdl',
123 '//frontend/types.asdl',
124 '//core/optview',
125 '//core/runtime.asdl',
126 '//core/value.asdl',
127 '//osh/arith_parse',
128 '//ysh/grammar',
129 '//mycpp/runtime',
130 ]
131
132 # TODO: other files should get their own
133 oils_preamble = 'bin/oils_for_unix_preamble.h'
134
135 mycpp_library(ru,
136 'bin/osh_eval.py',
137 py_inputs=ninja_lib.TryDynamicDeps('bin/osh_eval.py'),
138 preamble=oils_preamble,
139 deps=oils_deps)
140
141 mycpp_bin(ru, '//bin/osh_eval.mycpp', matrix=ninja_lib.COMPILERS_VARIANTS)
142
143 mycpp_library(ru,
144 'bin/osh_parse.py',
145 py_inputs=ninja_lib.TryDynamicDeps('bin/osh_parse.py'),
146 preamble=oils_preamble,
147 deps=oils_deps)
148
149 mycpp_bin(ru, '//bin/osh_parse.mycpp', matrix=ninja_lib.COMPILERS_VARIANTS)
150
151 oils_symlinks = ['osh', 'ysh']
152 matrix = (ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS +
153 ninja_lib.OTHER_VARIANTS)
154
155 oils_py_inputs = ninja_lib.TryDynamicDeps('bin/oils_for_unix.py')
156
157 # Main oils-for-unix binary
158 mycpp_library(
159 ru,
160 'bin/oils_for_unix.py',
161 py_inputs=oils_py_inputs,
162 deps=oils_deps,
163 )
164 # Faster variant
165 mycpp_library(
166 ru,
167 'bin/oils_for_unix.py',
168 py_inputs=oils_py_inputs,
169 translator='mycpp-souffle',
170 deps=oils_deps,
171 )
172
173 mycpp_bin(
174 ru,
175 '//bin/oils_for_unix.mycpp',
176 matrix=matrix,
177 # _bin/cxx-opt/oils-for-unix, NOT _bin/cxx-opt/bin/oils-for-unix
178 bin_path='oils-for-unix',
179 symlinks=oils_symlinks,
180 preprocessed=True,
181 )
182 mycpp_bin(
183 ru,
184 '//bin/oils_for_unix.mycpp-souffle',
185 matrix=matrix,
186 bin_path='mycpp-souffle/oils-for-unix',
187 symlinks=oils_symlinks,
188 )