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

146 lines, 100 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 log
11
12_ = log
13
14# TODO: should have dependencies with sh_binary
15RULES_PY = 'build/ninja-rules-py.sh'
16
17
18def NinjaGraph(ru):
19 n = ru.n
20
21 ru.comment('Generated by %s' % __name__)
22
23 #
24 # Files embedded in binary
25 #
26
27 n.rule('embedded-file-gen',
28 command='_bin/shwrap/embedded_file_gen $in > $out',
29 description='embedded_file_gen $in $out')
30
31 # Generated by build/py.sh all -> build/doc.sh all-help
32 # I wish Ninja had DIRECTORY-level dependencies? Because this should
33 # ultimately depend on doc/ref/*.md
34 # We could probably create a _build/ninja-stamp/HELP file and so forth
35 files = glob('_devbuild/help/*')
36
37 # OSH and YSH stdlib
38 tmp = glob('stdlib/ysh/*.ysh') + glob('stdlib/osh/*.sh')
39
40 # Remove this?
41 tmp.extend(glob('stdlib/*.ysh'))
42
43 # exclude test files
44 for path in tmp:
45 if fnmatch(path, '*-test.ysh'):
46 continue
47 if fnmatch(path, '*-test.sh'):
48 continue
49 if fnmatch(path, '*/draft-*'):
50 continue
51
52 files.append(path)
53
54 # Make sure it's DETERMINISTIC
55 files.sort()
56
57 n.build(['_gen/bin/text_files.cc'],
58 'embedded-file-gen',
59 files,
60 implicit=['_bin/shwrap/embedded_file_gen'])
61 n.newline()
62
63 ru.cc_library('//bin/text_files', srcs=['_gen/bin/text_files.cc'])
64
65 #
66 # Main Programs
67 #
68
69 for main_name in ('osh_eval', 'oils_for_unix'):
70 for translator in ('mycpp', 'mycpp-souffle'):
71 with open('_build/NINJA/bin.%s/translate.txt' % main_name) as f:
72 deps = [line.strip() for line in f]
73
74 prefix = '_gen/bin/%s.%s' % (main_name, translator)
75 outputs = [prefix + '.cc', prefix + '.h']
76
77 if translator == 'mycpp':
78 shwrap_path = '_bin/shwrap/mycpp_main'
79 elif translator == 'mycpp-souffle':
80 shwrap_path = '_bin/shwrap/mycpp_main_souffle'
81 else:
82 raise AssertionError()
83
84 variables = [
85 ('main_name', main_name),
86 ('shwrap_path', shwrap_path),
87 ('out_prefix', prefix),
88 ('preamble', 'cpp/preamble.h'),
89 ]
90
91 n.build(outputs,
92 'gen-oils-for-unix',
93 deps,
94 implicit=[shwrap_path, RULES_PY],
95 variables=variables)
96
97 if main_name == 'oils_for_unix':
98 # The main program!
99 if translator == 'mycpp-souffle':
100 bin_path = '%s/oils-for-unix' % translator
101 else:
102 # Keep the default mycpp build at the original location to
103 # avoid breaking benchmarks and tests.
104 bin_path = 'oils-for-unix'
105 symlinks = ['osh', 'ysh']
106 else:
107 symlinks = []
108 bin_path = None # use default
109
110 ru.cc_binary(
111 '_gen/bin/%s.%s.cc' % (main_name, translator),
112 bin_path=bin_path,
113 symlinks=symlinks,
114 preprocessed=True,
115 matrix=(ninja_lib.COMPILERS_VARIANTS +
116 ninja_lib.GC_PERF_VARIANTS + ninja_lib.OTHER_VARIANTS),
117 deps=[
118 '//bin/text_files',
119 '//cpp/core',
120 '//cpp/data_lang',
121 '//cpp/fanos',
122 '//cpp/libc',
123 '//cpp/osh',
124 '//cpp/pgen2',
125 '//cpp/pylib',
126 '//cpp/stdlib',
127 '//cpp/frontend_flag_spec',
128 '//cpp/frontend_match',
129 '//cpp/frontend_pyreadline',
130 '//data_lang/nil8.asdl',
131 '//display/pretty.asdl',
132 '//frontend/arg_types',
133 '//frontend/consts',
134 '//frontend/help_meta',
135 '//frontend/id_kind.asdl',
136 '//frontend/option.asdl',
137 '//frontend/signal',
138 '//frontend/syntax.asdl',
139 '//frontend/types.asdl',
140 '//core/optview',
141 '//core/runtime.asdl',
142 '//core/value.asdl',
143 '//osh/arith_parse',
144 '//ysh/grammar',
145 '//mycpp/runtime',
146 ])