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

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