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

141 lines, 96 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 variables = [
78 ('out_prefix', prefix),
79 ('main_name', main_name),
80 ('translator', translator),
81 ('preamble', 'cpp/preamble.h'),
82 ]
83 if translator == 'mycpp-souffle':
84 variables.append(('extra_mycpp_opts', '--minimize-stack-roots'))
85
86 n.build(outputs,
87 'gen-oils-for-unix',
88 deps,
89 implicit=['_bin/shwrap/mycpp_main', RULES_PY],
90 variables=variables)
91
92 if main_name == 'oils_for_unix':
93 # The main program!
94 if translator == 'mycpp-souffle':
95 bin_path = '%s/oils-for-unix' % translator
96 else:
97 # Keep the default mycpp build at the original location to
98 # avoid breaking benchmarks and tests.
99 bin_path = 'oils-for-unix'
100 symlinks = ['osh', 'ysh']
101 else:
102 symlinks = []
103 bin_path = None # use default
104
105 ru.cc_binary(
106 '_gen/bin/%s.%s.cc' % (main_name, translator),
107 bin_path=bin_path,
108 symlinks=symlinks,
109 preprocessed=True,
110 matrix=(ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS +
111 ninja_lib.OTHER_VARIANTS),
112 deps=[
113 '//bin/text_files',
114 '//cpp/core',
115 '//cpp/data_lang',
116 '//cpp/fanos',
117 '//cpp/libc',
118 '//cpp/osh',
119 '//cpp/pgen2',
120 '//cpp/pylib',
121 '//cpp/stdlib',
122 '//cpp/frontend_flag_spec',
123 '//cpp/frontend_match',
124 '//cpp/frontend_pyreadline',
125 '//data_lang/nil8.asdl',
126 '//display/pretty.asdl',
127 '//frontend/arg_types',
128 '//frontend/consts',
129 '//frontend/help_meta',
130 '//frontend/id_kind.asdl',
131 '//frontend/option.asdl',
132 '//frontend/signal',
133 '//frontend/syntax.asdl',
134 '//frontend/types.asdl',
135 '//core/optview',
136 '//core/runtime.asdl',
137 '//core/value.asdl',
138 '//osh/arith_parse',
139 '//ysh/grammar',
140 '//mycpp/runtime',
141 ])