| 1 | """
|
| 2 | bin/NINJA_subgraph.py
|
| 3 | """
|
| 4 | from __future__ import print_function
|
| 5 |
|
| 6 | from glob import glob
|
| 7 | from fnmatch import fnmatch
|
| 8 |
|
| 9 | from build import ninja_lib
|
| 10 | from build.ninja_lib import log
|
| 11 |
|
| 12 | _ = log
|
| 13 |
|
| 14 | # TODO: should have dependencies with sh_binary
|
| 15 | RULES_PY = 'build/ninja-rules-py.sh'
|
| 16 |
|
| 17 |
|
| 18 | def 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 | # Programs
|
| 67 | #
|
| 68 |
|
| 69 | preamble = 'cpp/preamble.h' # TODO: change this
|
| 70 |
|
| 71 | # Demos
|
| 72 | for main_name in ('osh_eval', 'osh_parse'):
|
| 73 | MainBinary(ru, main_name, 'mycpp', preamble)
|
| 74 |
|
| 75 | oils_symlinks = ['osh', 'ysh']
|
| 76 |
|
| 77 | # Main oils-for-unix binary
|
| 78 | MainBinary(
|
| 79 | ru,
|
| 80 | 'oils_for_unix',
|
| 81 | 'mycpp',
|
| 82 | preamble,
|
| 83 | # _bin/cxx-opt/oils-for-unix, NOT _bin/cxx-opt/bin/oils-for-unix
|
| 84 | bin_path='oils-for-unix',
|
| 85 | symlinks=oils_symlinks,
|
| 86 | )
|
| 87 | # Faster variant
|
| 88 | # this could have been _bin/cxx-opt/oils-for-unix.mycpp-souffle?
|
| 89 | MainBinary(
|
| 90 | ru,
|
| 91 | 'oils_for_unix',
|
| 92 | 'mycpp-souffle',
|
| 93 | preamble,
|
| 94 | bin_path='mycpp-souffle/oils-for-unix',
|
| 95 | symlinks=oils_symlinks,
|
| 96 | )
|
| 97 |
|
| 98 |
|
| 99 | _SHWRAP = {
|
| 100 | 'mycpp': '_bin/shwrap/mycpp_main',
|
| 101 | 'mycpp-souffle': '_bin/shwrap/mycpp_main_souffle',
|
| 102 | }
|
| 103 |
|
| 104 |
|
| 105 | def MainBinary(ru,
|
| 106 | main_name,
|
| 107 | translator,
|
| 108 | preamble,
|
| 109 | bin_path=None,
|
| 110 | symlinks=None):
|
| 111 | symlinks = symlinks or []
|
| 112 |
|
| 113 | n = ru.n
|
| 114 |
|
| 115 | with open('_build/NINJA/bin.%s/translate.txt' % main_name) as f:
|
| 116 | deps = [line.strip() for line in f]
|
| 117 |
|
| 118 | prefix = '_gen/bin/%s.%s' % (main_name, translator)
|
| 119 | shwrap_path = _SHWRAP[translator]
|
| 120 |
|
| 121 | variables = [
|
| 122 | ('main_name', main_name),
|
| 123 | ('shwrap_path', shwrap_path),
|
| 124 | ('out_prefix', prefix),
|
| 125 | ('preamble', preamble),
|
| 126 | ]
|
| 127 |
|
| 128 | outputs = [prefix + '.cc', prefix + '.h']
|
| 129 | n.build(outputs,
|
| 130 | 'gen-oils-for-unix',
|
| 131 | deps,
|
| 132 | implicit=[shwrap_path, RULES_PY],
|
| 133 | variables=variables)
|
| 134 |
|
| 135 | ru.cc_binary(
|
| 136 | '_gen/bin/%s.%s.cc' % (main_name, translator),
|
| 137 | bin_path=bin_path,
|
| 138 | symlinks=symlinks,
|
| 139 | preprocessed=True,
|
| 140 | matrix=(ninja_lib.COMPILERS_VARIANTS + ninja_lib.GC_PERF_VARIANTS +
|
| 141 | ninja_lib.OTHER_VARIANTS),
|
| 142 | deps=[
|
| 143 | '//bin/text_files',
|
| 144 | '//cpp/core',
|
| 145 | '//cpp/data_lang',
|
| 146 | '//cpp/fanos',
|
| 147 | '//cpp/libc',
|
| 148 | '//cpp/osh',
|
| 149 | '//cpp/pgen2',
|
| 150 | '//cpp/pylib',
|
| 151 | '//cpp/stdlib',
|
| 152 | '//cpp/frontend_flag_spec',
|
| 153 | '//cpp/frontend_match',
|
| 154 | '//cpp/frontend_pyreadline',
|
| 155 | '//data_lang/nil8.asdl',
|
| 156 | '//display/pretty.asdl',
|
| 157 | '//frontend/arg_types',
|
| 158 | '//frontend/consts',
|
| 159 | '//frontend/help_meta',
|
| 160 | '//frontend/id_kind.asdl',
|
| 161 | '//frontend/option.asdl',
|
| 162 | '//frontend/signal',
|
| 163 | '//frontend/syntax.asdl',
|
| 164 | '//frontend/types.asdl',
|
| 165 | '//core/optview',
|
| 166 | '//core/runtime.asdl',
|
| 167 | '//core/value.asdl',
|
| 168 | '//osh/arith_parse',
|
| 169 | '//ysh/grammar',
|
| 170 | '//mycpp/runtime',
|
| 171 | ])
|