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

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