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