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

121 lines, 83 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 # stdlib
38 tmp = glob('stdlib/*.ysh') + glob('stdlib/*.sh')
39 # exclude test files
40 for path in tmp:
41 if fnmatch(path, '*-test.ysh'):
42 continue
43 if fnmatch(path, '*-test.sh'):
44 continue
45 if fnmatch(path, '*/draft-*'):
46 continue
47
48 files.append(path)
49
50 # Make sure it's DETERMINISTIC
51 files.sort()
52
53 n.build(['_gen/bin/text_files.cc'],
54 'embedded-file-gen',
55 files,
56 implicit=['_bin/shwrap/embedded_file_gen'])
57 n.newline()
58
59 ru.cc_library('//bin/text_files', srcs=['_gen/bin/text_files.cc'])
60
61 #
62 # Main Programs
63 #
64
65 for main_name in ('osh_eval', 'oils_for_unix'):
66 with open('_build/NINJA/bin.%s/translate.txt' % main_name) as f:
67 deps = [line.strip() for line in f]
68
69 prefix = '_gen/bin/%s.mycpp' % main_name
70 outputs = [prefix + '.cc', prefix + '.h']
71 n.build(outputs,
72 'gen-oils-for-unix',
73 deps,
74 implicit=['_bin/shwrap/mycpp_main', RULES_PY],
75 variables=[('out_prefix', prefix), ('main_name', main_name),
76 ('preamble', 'cpp/preamble.h')])
77
78 if main_name == 'oils_for_unix':
79 # The main program!
80 bin_path = 'oils-for-unix'
81 symlinks = ['osh', 'ysh']
82 else:
83 symlinks = []
84 bin_path = None # use default
85
86 ru.cc_binary('_gen/bin/%s.mycpp.cc' % main_name,
87 bin_path=bin_path,
88 symlinks=symlinks,
89 preprocessed=True,
90 matrix=ninja_lib.COMPILERS_VARIANTS +
91 ninja_lib.GC_PERF_VARIANTS,
92 deps=[
93 '//bin/text_files',
94 '//cpp/core',
95 '//cpp/data_lang',
96 '//cpp/fanos',
97 '//cpp/libc',
98 '//cpp/osh',
99 '//cpp/pgen2',
100 '//cpp/pylib',
101 '//cpp/stdlib',
102 '//cpp/frontend_flag_spec',
103 '//cpp/frontend_match',
104 '//cpp/frontend_pyreadline',
105 '//data_lang/nil8.asdl',
106 '//data_lang/pretty.asdl',
107 '//frontend/arg_types',
108 '//frontend/consts',
109 '//frontend/help_meta',
110 '//frontend/id_kind.asdl',
111 '//frontend/option.asdl',
112 '//frontend/signal',
113 '//frontend/syntax.asdl',
114 '//frontend/types.asdl',
115 '//core/optview',
116 '//core/runtime.asdl',
117 '//core/value.asdl',
118 '//osh/arith_parse',
119 '//ysh/grammar',
120 '//mycpp/runtime',
121 ])