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

126 lines, 85 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 with open('_build/NINJA/bin.%s/translate.txt' % main_name) as f:
71 deps = [line.strip() for line in f]
72
73 prefix = '_gen/bin/%s.mycpp' % main_name
74 outputs = [prefix + '.cc', prefix + '.h']
75 n.build(outputs,
76 'gen-oils-for-unix',
77 deps,
78 implicit=['_bin/shwrap/mycpp_main', RULES_PY],
79 variables=[('out_prefix', prefix), ('main_name', main_name),
80 ('preamble', 'cpp/preamble.h')])
81
82 if main_name == 'oils_for_unix':
83 # The main program!
84 bin_path = 'oils-for-unix'
85 symlinks = ['osh', 'ysh']
86 else:
87 symlinks = []
88 bin_path = None # use default
89
90 ru.cc_binary(
91 '_gen/bin/%s.mycpp.cc' % main_name,
92 bin_path=bin_path,
93 symlinks=symlinks,
94 preprocessed=True,
95 matrix=(ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS +
96 ninja_lib.OTHER_VARIANTS),
97 deps=[
98 '//bin/text_files',
99 '//cpp/core',
100 '//cpp/data_lang',
101 '//cpp/fanos',
102 '//cpp/libc',
103 '//cpp/osh',
104 '//cpp/pgen2',
105 '//cpp/pylib',
106 '//cpp/stdlib',
107 '//cpp/frontend_flag_spec',
108 '//cpp/frontend_match',
109 '//cpp/frontend_pyreadline',
110 '//data_lang/nil8.asdl',
111 '//display/pretty.asdl',
112 '//frontend/arg_types',
113 '//frontend/consts',
114 '//frontend/help_meta',
115 '//frontend/id_kind.asdl',
116 '//frontend/option.asdl',
117 '//frontend/signal',
118 '//frontend/syntax.asdl',
119 '//frontend/types.asdl',
120 '//core/optview',
121 '//core/runtime.asdl',
122 '//core/value.asdl',
123 '//osh/arith_parse',
124 '//ysh/grammar',
125 '//mycpp/runtime',
126 ])