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