Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 1 | # Copyright (c) 2015, Google Inc. |
| 2 | # |
| 3 | # Permission to use, copy, modify, and/or distribute this software for any |
| 4 | # purpose with or without fee is hereby granted, provided that the above |
| 5 | # copyright notice and this permission notice appear in all copies. |
| 6 | # |
| 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 15 | """Enumerates source files for consumption by various build systems.""" |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 16 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 17 | import optparse |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 18 | import os |
| 19 | import subprocess |
| 20 | import sys |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 21 | import json |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 22 | |
| 23 | |
| 24 | # OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for |
| 25 | # that platform and the extension used by asm files. |
| 26 | OS_ARCH_COMBOS = [ |
| 27 | ('linux', 'arm', 'linux32', [], 'S'), |
| 28 | ('linux', 'aarch64', 'linux64', [], 'S'), |
David Benjamin | 9f16ce1 | 2016-09-27 16:30:22 -0400 | [diff] [blame] | 29 | ('linux', 'ppc64le', 'ppc64le', [], 'S'), |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 30 | ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'), |
| 31 | ('linux', 'x86_64', 'elf', [], 'S'), |
| 32 | ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'), |
| 33 | ('mac', 'x86_64', 'macosx', [], 'S'), |
| 34 | ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'), |
| 35 | ('win', 'x86_64', 'nasm', [], 'asm'), |
| 36 | ] |
| 37 | |
| 38 | # NON_PERL_FILES enumerates assembly files that are not processed by the |
| 39 | # perlasm system. |
| 40 | NON_PERL_FILES = { |
| 41 | ('linux', 'arm'): [ |
Adam Langley | 7b8b9c1 | 2016-01-04 07:13:00 -0800 | [diff] [blame] | 42 | 'src/crypto/curve25519/asm/x25519-asm-arm.S', |
David Benjamin | 3c4a5cb | 2016-03-29 17:43:31 -0400 | [diff] [blame] | 43 | 'src/crypto/poly1305/poly1305_arm_asm.S', |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 44 | ], |
Matt Braithwaite | e021a24 | 2016-01-14 13:41:46 -0800 | [diff] [blame] | 45 | ('linux', 'x86_64'): [ |
| 46 | 'src/crypto/curve25519/asm/x25519-asm-x86_64.S', |
| 47 | ], |
Piotr Sikora | 8ca0b41 | 2016-06-02 11:59:21 -0700 | [diff] [blame] | 48 | ('mac', 'x86_64'): [ |
| 49 | 'src/crypto/curve25519/asm/x25519-asm-x86_64.S', |
| 50 | ], |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 51 | } |
| 52 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 53 | # For now, GTest-based tests are specified manually. Once everything has updated |
| 54 | # to support GTest, these will be determined automatically by looking for files |
| 55 | # ending with _test.cc. |
| 56 | CRYPTO_TEST_SOURCES = [ |
David Benjamin | 358baeb | 2017-01-23 15:16:14 -0500 | [diff] [blame] | 57 | 'src/crypto/dh/dh_test.cc', |
| 58 | 'src/crypto/dsa/dsa_test.cc', |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 59 | ] |
| 60 | DECREPIT_TEST_SOURCES = [ |
David Benjamin | 358baeb | 2017-01-23 15:16:14 -0500 | [diff] [blame] | 61 | 'src/decrepit/decrepit_test.cc', |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 62 | ] |
| 63 | SSL_TEST_SOURCES = [ |
David Benjamin | 358baeb | 2017-01-23 15:16:14 -0500 | [diff] [blame] | 64 | 'src/ssl/ssl_test.cc', |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 65 | ] |
| 66 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 67 | PREFIX = None |
| 68 | |
| 69 | |
| 70 | def PathOf(x): |
| 71 | return x if not PREFIX else os.path.join(PREFIX, x) |
| 72 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 73 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 74 | class Android(object): |
| 75 | |
| 76 | def __init__(self): |
| 77 | self.header = \ |
| 78 | """# Copyright (C) 2015 The Android Open Source Project |
| 79 | # |
| 80 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 81 | # you may not use this file except in compliance with the License. |
| 82 | # You may obtain a copy of the License at |
| 83 | # |
| 84 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 85 | # |
| 86 | # Unless required by applicable law or agreed to in writing, software |
| 87 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 88 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 89 | # See the License for the specific language governing permissions and |
| 90 | # limitations under the License. |
| 91 | |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 92 | # This file is created by generate_build_files.py. Do not edit manually. |
| 93 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 94 | """ |
| 95 | |
| 96 | def PrintVariableSection(self, out, name, files): |
| 97 | out.write('%s := \\\n' % name) |
| 98 | for f in sorted(files): |
| 99 | out.write(' %s\\\n' % f) |
| 100 | out.write('\n') |
| 101 | |
| 102 | def WriteFiles(self, files, asm_outputs): |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 103 | # New Android.bp format |
| 104 | with open('sources.bp', 'w+') as blueprint: |
| 105 | blueprint.write(self.header.replace('#', '//')) |
| 106 | |
| 107 | blueprint.write('cc_defaults {\n') |
| 108 | blueprint.write(' name: "libcrypto_sources",\n') |
| 109 | blueprint.write(' srcs: [\n') |
David Benjamin | 8c29e7d | 2016-09-30 21:34:31 -0400 | [diff] [blame] | 110 | for f in sorted(files['crypto']): |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 111 | blueprint.write(' "%s",\n' % f) |
| 112 | blueprint.write(' ],\n') |
| 113 | blueprint.write(' target: {\n') |
| 114 | |
| 115 | for ((osname, arch), asm_files) in asm_outputs: |
Steven Valdez | 93d242b | 2016-10-06 13:49:01 -0400 | [diff] [blame] | 116 | if osname != 'linux' or arch == 'ppc64le': |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 117 | continue |
| 118 | if arch == 'aarch64': |
| 119 | arch = 'arm64' |
| 120 | |
| 121 | blueprint.write(' android_%s: {\n' % arch) |
| 122 | blueprint.write(' srcs: [\n') |
| 123 | for f in sorted(asm_files): |
| 124 | blueprint.write(' "%s",\n' % f) |
| 125 | blueprint.write(' ],\n') |
| 126 | blueprint.write(' },\n') |
| 127 | |
| 128 | if arch == 'x86' or arch == 'x86_64': |
| 129 | blueprint.write(' linux_%s: {\n' % arch) |
| 130 | blueprint.write(' srcs: [\n') |
| 131 | for f in sorted(asm_files): |
| 132 | blueprint.write(' "%s",\n' % f) |
| 133 | blueprint.write(' ],\n') |
| 134 | blueprint.write(' },\n') |
| 135 | |
| 136 | blueprint.write(' },\n') |
| 137 | blueprint.write('}\n\n') |
| 138 | |
| 139 | blueprint.write('cc_defaults {\n') |
| 140 | blueprint.write(' name: "libssl_sources",\n') |
| 141 | blueprint.write(' srcs: [\n') |
| 142 | for f in sorted(files['ssl']): |
| 143 | blueprint.write(' "%s",\n' % f) |
| 144 | blueprint.write(' ],\n') |
| 145 | blueprint.write('}\n\n') |
| 146 | |
| 147 | blueprint.write('cc_defaults {\n') |
| 148 | blueprint.write(' name: "bssl_sources",\n') |
| 149 | blueprint.write(' srcs: [\n') |
| 150 | for f in sorted(files['tool']): |
| 151 | blueprint.write(' "%s",\n' % f) |
| 152 | blueprint.write(' ],\n') |
| 153 | blueprint.write('}\n\n') |
| 154 | |
| 155 | blueprint.write('cc_defaults {\n') |
| 156 | blueprint.write(' name: "boringssl_test_support_sources",\n') |
| 157 | blueprint.write(' srcs: [\n') |
| 158 | for f in sorted(files['test_support']): |
| 159 | blueprint.write(' "%s",\n' % f) |
| 160 | blueprint.write(' ],\n') |
| 161 | blueprint.write('}\n\n') |
| 162 | |
| 163 | blueprint.write('cc_defaults {\n') |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 164 | blueprint.write(' name: "boringssl_crypto_test_sources",\n') |
| 165 | blueprint.write(' srcs: [\n') |
| 166 | for f in sorted(files['crypto_test']): |
| 167 | blueprint.write(' "%s",\n' % f) |
| 168 | blueprint.write(' ],\n') |
| 169 | blueprint.write('}\n\n') |
| 170 | |
| 171 | blueprint.write('cc_defaults {\n') |
| 172 | blueprint.write(' name: "boringssl_ssl_test_sources",\n') |
| 173 | blueprint.write(' srcs: [\n') |
| 174 | for f in sorted(files['ssl_test']): |
| 175 | blueprint.write(' "%s",\n' % f) |
| 176 | blueprint.write(' ],\n') |
| 177 | blueprint.write('}\n\n') |
| 178 | |
| 179 | blueprint.write('cc_defaults {\n') |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 180 | blueprint.write(' name: "boringssl_tests_sources",\n') |
| 181 | blueprint.write(' srcs: [\n') |
| 182 | for f in sorted(files['test']): |
| 183 | blueprint.write(' "%s",\n' % f) |
| 184 | blueprint.write(' ],\n') |
| 185 | blueprint.write('}\n') |
| 186 | |
| 187 | # Legacy Android.mk format, only used by Trusty in new branches |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 188 | with open('sources.mk', 'w+') as makefile: |
| 189 | makefile.write(self.header) |
| 190 | |
David Benjamin | 8c29e7d | 2016-09-30 21:34:31 -0400 | [diff] [blame] | 191 | self.PrintVariableSection(makefile, 'crypto_sources', files['crypto']) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 192 | |
| 193 | for ((osname, arch), asm_files) in asm_outputs: |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 194 | if osname != 'linux': |
| 195 | continue |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 196 | self.PrintVariableSection( |
| 197 | makefile, '%s_%s_sources' % (osname, arch), asm_files) |
| 198 | |
| 199 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 200 | class Bazel(object): |
| 201 | """Bazel outputs files suitable for including in Bazel files.""" |
| 202 | |
| 203 | def __init__(self): |
| 204 | self.firstSection = True |
| 205 | self.header = \ |
| 206 | """# This file is created by generate_build_files.py. Do not edit manually. |
| 207 | |
| 208 | """ |
| 209 | |
| 210 | def PrintVariableSection(self, out, name, files): |
| 211 | if not self.firstSection: |
| 212 | out.write('\n') |
| 213 | self.firstSection = False |
| 214 | |
| 215 | out.write('%s = [\n' % name) |
| 216 | for f in sorted(files): |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 217 | out.write(' "%s",\n' % PathOf(f)) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 218 | out.write(']\n') |
| 219 | |
| 220 | def WriteFiles(self, files, asm_outputs): |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 221 | with open('BUILD.generated.bzl', 'w+') as out: |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 222 | out.write(self.header) |
| 223 | |
| 224 | self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers']) |
| 225 | self.PrintVariableSection( |
| 226 | out, 'ssl_internal_headers', files['ssl_internal_headers']) |
| 227 | self.PrintVariableSection(out, 'ssl_sources', files['ssl']) |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 228 | self.PrintVariableSection(out, 'ssl_c_sources', files['ssl_c']) |
| 229 | self.PrintVariableSection(out, 'ssl_cc_sources', files['ssl_cc']) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 230 | self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers']) |
| 231 | self.PrintVariableSection( |
| 232 | out, 'crypto_internal_headers', files['crypto_internal_headers']) |
| 233 | self.PrintVariableSection(out, 'crypto_sources', files['crypto']) |
| 234 | self.PrintVariableSection(out, 'tool_sources', files['tool']) |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 235 | self.PrintVariableSection(out, 'tool_headers', files['tool_headers']) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 236 | |
| 237 | for ((osname, arch), asm_files) in asm_outputs: |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 238 | self.PrintVariableSection( |
Piotr Sikora | 3f5fe60 | 2015-10-28 12:24:35 -0700 | [diff] [blame] | 239 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 240 | |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 241 | with open('BUILD.generated_tests.bzl', 'w+') as out: |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 242 | out.write(self.header) |
| 243 | |
| 244 | out.write('test_support_sources = [\n') |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 245 | for filename in sorted(files['test_support'] + |
| 246 | files['test_support_headers'] + |
| 247 | files['crypto_internal_headers'] + |
| 248 | files['ssl_internal_headers']): |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 249 | if os.path.basename(filename) == 'malloc.cc': |
| 250 | continue |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 251 | out.write(' "%s",\n' % PathOf(filename)) |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 252 | |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 253 | out.write(']\n\n') |
| 254 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 255 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 256 | files['crypto_test']) |
| 257 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
| 258 | |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 259 | out.write('def create_tests(copts, crypto, ssl):\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 260 | name_counts = {} |
| 261 | for test in files['tests']: |
| 262 | name = os.path.basename(test[0]) |
| 263 | name_counts[name] = name_counts.get(name, 0) + 1 |
| 264 | |
| 265 | first = True |
| 266 | for test in files['tests']: |
| 267 | name = os.path.basename(test[0]) |
| 268 | if name_counts[name] > 1: |
| 269 | if '/' in test[1]: |
| 270 | name += '_' + os.path.splitext(os.path.basename(test[1]))[0] |
| 271 | else: |
| 272 | name += '_' + test[1].replace('-', '_') |
| 273 | |
| 274 | if not first: |
| 275 | out.write('\n') |
| 276 | first = False |
| 277 | |
| 278 | src_prefix = 'src/' + test[0] |
| 279 | for src in files['test']: |
| 280 | if src.startswith(src_prefix): |
| 281 | src = src |
| 282 | break |
| 283 | else: |
| 284 | raise ValueError("Can't find source for %s" % test[0]) |
| 285 | |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 286 | out.write(' native.cc_test(\n') |
| 287 | out.write(' name = "%s",\n' % name) |
| 288 | out.write(' size = "small",\n') |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 289 | out.write(' srcs = ["%s"] + test_support_sources,\n' % |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 290 | PathOf(src)) |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 291 | |
| 292 | data_files = [] |
| 293 | if len(test) > 1: |
| 294 | |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 295 | out.write(' args = [\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 296 | for arg in test[1:]: |
| 297 | if '/' in arg: |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 298 | out.write(' "$(location %s)",\n' % |
| 299 | PathOf(os.path.join('src', arg))) |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 300 | data_files.append('src/%s' % arg) |
| 301 | else: |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 302 | out.write(' "%s",\n' % arg) |
| 303 | out.write(' ],\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 304 | |
Adam Langley | d7b9002 | 2016-11-17 09:02:01 -0800 | [diff] [blame] | 305 | out.write(' copts = copts + ["-DBORINGSSL_SHARED_LIBRARY"],\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 306 | |
| 307 | if len(data_files) > 0: |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 308 | out.write(' data = [\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 309 | for filename in data_files: |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 310 | out.write(' "%s",\n' % PathOf(filename)) |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 311 | out.write(' ],\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 312 | |
| 313 | if 'ssl/' in test[0]: |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 314 | out.write(' deps = [\n') |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 315 | out.write(' crypto,\n') |
| 316 | out.write(' ssl,\n') |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 317 | out.write(' ],\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 318 | else: |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 319 | out.write(' deps = [crypto],\n') |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 320 | out.write(' )\n') |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 321 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 322 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 323 | class GN(object): |
| 324 | |
| 325 | def __init__(self): |
| 326 | self.firstSection = True |
| 327 | self.header = \ |
| 328 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 329 | # Use of this source code is governed by a BSD-style license that can be |
| 330 | # found in the LICENSE file. |
| 331 | |
| 332 | # This file is created by generate_build_files.py. Do not edit manually. |
| 333 | |
| 334 | """ |
| 335 | |
| 336 | def PrintVariableSection(self, out, name, files): |
| 337 | if not self.firstSection: |
| 338 | out.write('\n') |
| 339 | self.firstSection = False |
| 340 | |
| 341 | out.write('%s = [\n' % name) |
| 342 | for f in sorted(files): |
| 343 | out.write(' "%s",\n' % f) |
| 344 | out.write(']\n') |
| 345 | |
| 346 | def WriteFiles(self, files, asm_outputs): |
| 347 | with open('BUILD.generated.gni', 'w+') as out: |
| 348 | out.write(self.header) |
| 349 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 350 | self.PrintVariableSection(out, 'crypto_sources', |
| 351 | files['crypto'] + files['crypto_headers'] + |
| 352 | files['crypto_internal_headers']) |
| 353 | self.PrintVariableSection(out, 'ssl_sources', |
| 354 | files['ssl'] + files['ssl_headers'] + |
| 355 | files['ssl_internal_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 356 | |
| 357 | for ((osname, arch), asm_files) in asm_outputs: |
| 358 | self.PrintVariableSection( |
| 359 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
| 360 | |
| 361 | fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0] |
| 362 | for fuzzer in files['fuzz']] |
| 363 | self.PrintVariableSection(out, 'fuzzers', fuzzers) |
| 364 | |
| 365 | with open('BUILD.generated_tests.gni', 'w+') as out: |
| 366 | self.firstSection = True |
| 367 | out.write(self.header) |
| 368 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 369 | self.PrintVariableSection(out, 'test_support_sources', |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 370 | files['test_support'] + |
| 371 | files['test_support_headers']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 372 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 373 | files['crypto_test']) |
| 374 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 375 | out.write('\n') |
| 376 | |
| 377 | out.write('template("create_tests") {\n') |
| 378 | |
| 379 | all_tests = [] |
| 380 | for test in sorted(files['test']): |
| 381 | test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0] |
| 382 | all_tests.append(test_name) |
| 383 | |
| 384 | out.write(' executable("%s") {\n' % test_name) |
| 385 | out.write(' sources = [\n') |
| 386 | out.write(' "%s",\n' % test) |
| 387 | out.write(' ]\n') |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 388 | out.write(' sources += test_support_sources\n') |
David Benjamin | b3be1cf | 2016-04-27 19:15:06 -0400 | [diff] [blame] | 389 | out.write(' if (defined(invoker.configs_exclude)) {\n') |
| 390 | out.write(' configs -= invoker.configs_exclude\n') |
| 391 | out.write(' }\n') |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 392 | out.write(' configs += invoker.configs\n') |
| 393 | out.write(' deps = invoker.deps\n') |
| 394 | out.write(' }\n') |
| 395 | out.write('\n') |
| 396 | |
| 397 | out.write(' group(target_name) {\n') |
| 398 | out.write(' deps = [\n') |
| 399 | for test_name in sorted(all_tests): |
| 400 | out.write(' ":%s",\n' % test_name) |
| 401 | out.write(' ]\n') |
| 402 | out.write(' }\n') |
| 403 | out.write('}\n') |
| 404 | |
| 405 | |
| 406 | class GYP(object): |
| 407 | |
| 408 | def __init__(self): |
| 409 | self.header = \ |
| 410 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 411 | # Use of this source code is governed by a BSD-style license that can be |
| 412 | # found in the LICENSE file. |
| 413 | |
| 414 | # This file is created by generate_build_files.py. Do not edit manually. |
| 415 | |
| 416 | """ |
| 417 | |
| 418 | def PrintVariableSection(self, out, name, files): |
| 419 | out.write(' \'%s\': [\n' % name) |
| 420 | for f in sorted(files): |
| 421 | out.write(' \'%s\',\n' % f) |
| 422 | out.write(' ],\n') |
| 423 | |
| 424 | def WriteFiles(self, files, asm_outputs): |
| 425 | with open('boringssl.gypi', 'w+') as gypi: |
| 426 | gypi.write(self.header + '{\n \'variables\': {\n') |
| 427 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 428 | self.PrintVariableSection(gypi, 'boringssl_ssl_sources', |
| 429 | files['ssl'] + files['ssl_headers'] + |
| 430 | files['ssl_internal_headers']) |
| 431 | self.PrintVariableSection(gypi, 'boringssl_crypto_sources', |
| 432 | files['crypto'] + files['crypto_headers'] + |
| 433 | files['crypto_internal_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 434 | |
| 435 | for ((osname, arch), asm_files) in asm_outputs: |
| 436 | self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' % |
| 437 | (osname, arch), asm_files) |
| 438 | |
| 439 | gypi.write(' }\n}\n') |
| 440 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 441 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 442 | def FindCMakeFiles(directory): |
| 443 | """Returns list of all CMakeLists.txt files recursively in directory.""" |
| 444 | cmakefiles = [] |
| 445 | |
| 446 | for (path, _, filenames) in os.walk(directory): |
| 447 | for filename in filenames: |
| 448 | if filename == 'CMakeLists.txt': |
| 449 | cmakefiles.append(os.path.join(path, filename)) |
| 450 | |
| 451 | return cmakefiles |
| 452 | |
| 453 | |
| 454 | def NoTests(dent, is_dir): |
| 455 | """Filter function that can be passed to FindCFiles in order to remove test |
| 456 | sources.""" |
| 457 | if is_dir: |
| 458 | return dent != 'test' |
| 459 | return 'test.' not in dent and not dent.startswith('example_') |
| 460 | |
| 461 | |
| 462 | def OnlyTests(dent, is_dir): |
| 463 | """Filter function that can be passed to FindCFiles in order to remove |
| 464 | non-test sources.""" |
| 465 | if is_dir: |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 466 | return dent != 'test' |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 467 | # For now, GTest-based tests are specified manually. |
| 468 | if dent in [os.path.basename(p) for p in CRYPTO_TEST_SOURCES]: |
| 469 | return False |
| 470 | if dent in [os.path.basename(p) for p in DECREPIT_TEST_SOURCES]: |
| 471 | return False |
| 472 | if dent in [os.path.basename(p) for p in SSL_TEST_SOURCES]: |
| 473 | return False |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 474 | return '_test.' in dent or dent.startswith('example_') |
| 475 | |
| 476 | |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 477 | def AllFiles(dent, is_dir): |
| 478 | """Filter function that can be passed to FindCFiles in order to include all |
| 479 | sources.""" |
| 480 | return True |
| 481 | |
| 482 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 483 | def NotGTestMain(dent, is_dir): |
| 484 | return dent != 'gtest_main.cc' |
| 485 | |
| 486 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 487 | def SSLHeaderFiles(dent, is_dir): |
| 488 | return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h'] |
| 489 | |
| 490 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 491 | def FindCFiles(directory, filter_func): |
| 492 | """Recurses through directory and returns a list of paths to all the C source |
| 493 | files that pass filter_func.""" |
| 494 | cfiles = [] |
| 495 | |
| 496 | for (path, dirnames, filenames) in os.walk(directory): |
| 497 | for filename in filenames: |
| 498 | if not filename.endswith('.c') and not filename.endswith('.cc'): |
| 499 | continue |
| 500 | if not filter_func(filename, False): |
| 501 | continue |
| 502 | cfiles.append(os.path.join(path, filename)) |
| 503 | |
| 504 | for (i, dirname) in enumerate(dirnames): |
| 505 | if not filter_func(dirname, True): |
| 506 | del dirnames[i] |
| 507 | |
| 508 | return cfiles |
| 509 | |
| 510 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 511 | def FindHeaderFiles(directory, filter_func): |
| 512 | """Recurses through directory and returns a list of paths to all the header files that pass filter_func.""" |
| 513 | hfiles = [] |
| 514 | |
| 515 | for (path, dirnames, filenames) in os.walk(directory): |
| 516 | for filename in filenames: |
| 517 | if not filename.endswith('.h'): |
| 518 | continue |
| 519 | if not filter_func(filename, False): |
| 520 | continue |
| 521 | hfiles.append(os.path.join(path, filename)) |
| 522 | |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 523 | for (i, dirname) in enumerate(dirnames): |
| 524 | if not filter_func(dirname, True): |
| 525 | del dirnames[i] |
| 526 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 527 | return hfiles |
| 528 | |
| 529 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 530 | def ExtractPerlAsmFromCMakeFile(cmakefile): |
| 531 | """Parses the contents of the CMakeLists.txt file passed as an argument and |
| 532 | returns a list of all the perlasm() directives found in the file.""" |
| 533 | perlasms = [] |
| 534 | with open(cmakefile) as f: |
| 535 | for line in f: |
| 536 | line = line.strip() |
| 537 | if not line.startswith('perlasm('): |
| 538 | continue |
| 539 | if not line.endswith(')'): |
| 540 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 541 | # Remove "perlasm(" from start and ")" from end |
| 542 | params = line[8:-1].split() |
| 543 | if len(params) < 2: |
| 544 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 545 | perlasms.append({ |
| 546 | 'extra_args': params[2:], |
| 547 | 'input': os.path.join(os.path.dirname(cmakefile), params[1]), |
| 548 | 'output': os.path.join(os.path.dirname(cmakefile), params[0]), |
| 549 | }) |
| 550 | |
| 551 | return perlasms |
| 552 | |
| 553 | |
| 554 | def ReadPerlAsmOperations(): |
| 555 | """Returns a list of all perlasm() directives found in CMake config files in |
| 556 | src/.""" |
| 557 | perlasms = [] |
| 558 | cmakefiles = FindCMakeFiles('src') |
| 559 | |
| 560 | for cmakefile in cmakefiles: |
| 561 | perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile)) |
| 562 | |
| 563 | return perlasms |
| 564 | |
| 565 | |
| 566 | def PerlAsm(output_filename, input_filename, perlasm_style, extra_args): |
| 567 | """Runs the a perlasm script and puts the output into output_filename.""" |
| 568 | base_dir = os.path.dirname(output_filename) |
| 569 | if not os.path.isdir(base_dir): |
| 570 | os.makedirs(base_dir) |
David Benjamin | fdd8e9c | 2016-06-26 13:18:50 -0400 | [diff] [blame] | 571 | subprocess.check_call( |
| 572 | ['perl', input_filename, perlasm_style] + extra_args + [output_filename]) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 573 | |
| 574 | |
| 575 | def ArchForAsmFilename(filename): |
| 576 | """Returns the architectures that a given asm file should be compiled for |
| 577 | based on substrings in the filename.""" |
| 578 | |
| 579 | if 'x86_64' in filename or 'avx2' in filename: |
| 580 | return ['x86_64'] |
| 581 | elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename: |
| 582 | return ['x86'] |
| 583 | elif 'armx' in filename: |
| 584 | return ['arm', 'aarch64'] |
| 585 | elif 'armv8' in filename: |
| 586 | return ['aarch64'] |
| 587 | elif 'arm' in filename: |
| 588 | return ['arm'] |
David Benjamin | 9f16ce1 | 2016-09-27 16:30:22 -0400 | [diff] [blame] | 589 | elif 'ppc' in filename: |
| 590 | return ['ppc64le'] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 591 | else: |
| 592 | raise ValueError('Unknown arch for asm filename: ' + filename) |
| 593 | |
| 594 | |
| 595 | def WriteAsmFiles(perlasms): |
| 596 | """Generates asm files from perlasm directives for each supported OS x |
| 597 | platform combination.""" |
| 598 | asmfiles = {} |
| 599 | |
| 600 | for osarch in OS_ARCH_COMBOS: |
| 601 | (osname, arch, perlasm_style, extra_args, asm_ext) = osarch |
| 602 | key = (osname, arch) |
| 603 | outDir = '%s-%s' % key |
| 604 | |
| 605 | for perlasm in perlasms: |
| 606 | filename = os.path.basename(perlasm['input']) |
| 607 | output = perlasm['output'] |
| 608 | if not output.startswith('src'): |
| 609 | raise ValueError('output missing src: %s' % output) |
| 610 | output = os.path.join(outDir, output[4:]) |
William Hesse | c618c40 | 2015-06-22 16:34:02 +0200 | [diff] [blame] | 611 | if output.endswith('-armx.${ASM_EXT}'): |
| 612 | output = output.replace('-armx', |
| 613 | '-armx64' if arch == 'aarch64' else '-armx32') |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 614 | output = output.replace('${ASM_EXT}', asm_ext) |
| 615 | |
| 616 | if arch in ArchForAsmFilename(filename): |
| 617 | PerlAsm(output, perlasm['input'], perlasm_style, |
| 618 | perlasm['extra_args'] + extra_args) |
| 619 | asmfiles.setdefault(key, []).append(output) |
| 620 | |
| 621 | for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems(): |
| 622 | asmfiles.setdefault(key, []).extend(non_perl_asm_files) |
| 623 | |
| 624 | return asmfiles |
| 625 | |
| 626 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 627 | def main(platforms): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 628 | crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests) |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 629 | ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 630 | tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests) |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 631 | tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 632 | |
| 633 | # Generate err_data.c |
| 634 | with open('err_data.c', 'w+') as err_data: |
| 635 | subprocess.check_call(['go', 'run', 'err_data_generate.go'], |
| 636 | cwd=os.path.join('src', 'crypto', 'err'), |
| 637 | stdout=err_data) |
| 638 | crypto_c_files.append('err_data.c') |
| 639 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 640 | test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'), |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 641 | NotGTestMain) |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 642 | test_support_h_files = ( |
| 643 | FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) + |
| 644 | FindHeaderFiles(os.path.join('src', 'ssl', 'test'), AllFiles)) |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 645 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 646 | test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests) |
| 647 | test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests) |
| 648 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 649 | fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests) |
| 650 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 651 | ssl_h_files = ( |
| 652 | FindHeaderFiles( |
| 653 | os.path.join('src', 'include', 'openssl'), |
| 654 | SSLHeaderFiles)) |
| 655 | |
| 656 | def NotSSLHeaderFiles(filename, is_dir): |
| 657 | return not SSLHeaderFiles(filename, is_dir) |
| 658 | crypto_h_files = ( |
| 659 | FindHeaderFiles( |
| 660 | os.path.join('src', 'include', 'openssl'), |
| 661 | NotSSLHeaderFiles)) |
| 662 | |
| 663 | ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests) |
| 664 | crypto_internal_h_files = FindHeaderFiles( |
| 665 | os.path.join('src', 'crypto'), NoTests) |
| 666 | |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 667 | with open('src/util/all_tests.json', 'r') as f: |
| 668 | tests = json.load(f) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 669 | # For now, GTest-based tests are specified manually. |
| 670 | tests = [test for test in tests if test[0] not in ['crypto/crypto_test', |
| 671 | 'decrepit/decrepit_test', |
| 672 | 'ssl/ssl_test']] |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 673 | test_binaries = set([test[0] for test in tests]) |
| 674 | test_sources = set([ |
| 675 | test.replace('.cc', '').replace('.c', '').replace( |
| 676 | 'src/', |
| 677 | '') |
| 678 | for test in test_c_files]) |
| 679 | if test_binaries != test_sources: |
| 680 | print 'Test sources and configured tests do not match' |
| 681 | a = test_binaries.difference(test_sources) |
| 682 | if len(a) > 0: |
| 683 | print 'These tests are configured without sources: ' + str(a) |
| 684 | b = test_sources.difference(test_binaries) |
| 685 | if len(b) > 0: |
| 686 | print 'These test sources are not configured: ' + str(b) |
| 687 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 688 | files = { |
| 689 | 'crypto': crypto_c_files, |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 690 | 'crypto_headers': crypto_h_files, |
| 691 | 'crypto_internal_headers': crypto_internal_h_files, |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 692 | 'crypto_test': sorted(CRYPTO_TEST_SOURCES + |
David Benjamin | 358baeb | 2017-01-23 15:16:14 -0500 | [diff] [blame] | 693 | ['src/crypto/test/gtest_main.cc']), |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 694 | 'fuzz': fuzz_c_files, |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 695 | 'ssl': ssl_source_files, |
| 696 | 'ssl_c': [s for s in ssl_source_files if s.endswith('.c')], |
| 697 | 'ssl_cc': [s for s in ssl_source_files if s.endswith('.cc')], |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 698 | 'ssl_headers': ssl_h_files, |
| 699 | 'ssl_internal_headers': ssl_internal_h_files, |
David Benjamin | 358baeb | 2017-01-23 15:16:14 -0500 | [diff] [blame] | 700 | 'ssl_test': sorted(SSL_TEST_SOURCES + ['src/crypto/test/gtest_main.cc']), |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 701 | 'tool': tool_c_files, |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 702 | 'tool_headers': tool_h_files, |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 703 | 'test': test_c_files, |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 704 | 'test_support': test_support_c_files, |
| 705 | 'test_support_headers': test_support_h_files, |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 706 | 'tests': tests, |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems()) |
| 710 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 711 | for platform in platforms: |
| 712 | platform.WriteFiles(files, asm_outputs) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 713 | |
| 714 | return 0 |
| 715 | |
| 716 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 717 | if __name__ == '__main__': |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 718 | parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]' |
David Benjamin | 8c29e7d | 2016-09-30 21:34:31 -0400 | [diff] [blame] | 719 | ' [android|bazel|gn|gyp]') |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 720 | parser.add_option('--prefix', dest='prefix', |
| 721 | help='For Bazel, prepend argument to all source files') |
| 722 | options, args = parser.parse_args(sys.argv[1:]) |
| 723 | PREFIX = options.prefix |
| 724 | |
| 725 | if not args: |
| 726 | parser.print_help() |
| 727 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 728 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 729 | platforms = [] |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 730 | for s in args: |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 731 | if s == 'android': |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 732 | platforms.append(Android()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 733 | elif s == 'bazel': |
| 734 | platforms.append(Bazel()) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 735 | elif s == 'gn': |
| 736 | platforms.append(GN()) |
| 737 | elif s == 'gyp': |
| 738 | platforms.append(GYP()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 739 | else: |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 740 | parser.print_help() |
| 741 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 742 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 743 | sys.exit(main(platforms)) |