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