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

125 lines, 84 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('_gen/bin/%s.mycpp.cc' % main_name,
91 bin_path=bin_path,
92 symlinks=symlinks,
93 preprocessed=True,
94 matrix=ninja_lib.COMPILERS_VARIANTS +
95 ninja_lib.GC_PERF_VARIANTS,
96 deps=[
97 '//bin/text_files',
98 '//cpp/core',
99 '//cpp/data_lang',
100 '//cpp/fanos',
101 '//cpp/libc',
102 '//cpp/osh',
103 '//cpp/pgen2',
104 '//cpp/pylib',
105 '//cpp/stdlib',
106 '//cpp/frontend_flag_spec',
107 '//cpp/frontend_match',
108 '//cpp/frontend_pyreadline',
109 '//data_lang/nil8.asdl',
110 '//display/pretty.asdl',
111 '//frontend/arg_types',
112 '//frontend/consts',
113 '//frontend/help_meta',
114 '//frontend/id_kind.asdl',
115 '//frontend/option.asdl',
116 '//frontend/signal',
117 '//frontend/syntax.asdl',
118 '//frontend/types.asdl',
119 '//core/optview',
120 '//core/runtime.asdl',
121 '//core/value.asdl',
122 '//osh/arith_parse',
123 '//ysh/grammar',
124 '//mycpp/runtime',
125 ])