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

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