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']) |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame^] | 275 | self.PrintVariableSection(out, 'urandom_test_sources', |
| 276 | files['urandom_test']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 277 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 278 | |
Robert Sloan | e091af4 | 2017-10-09 12:47:17 -0700 | [diff] [blame] | 279 | class Eureka(object): |
| 280 | |
| 281 | def __init__(self): |
| 282 | self.header = \ |
| 283 | """# Copyright (C) 2017 The Android Open Source Project |
| 284 | # |
| 285 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 286 | # you may not use this file except in compliance with the License. |
| 287 | # You may obtain a copy of the License at |
| 288 | # |
| 289 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 290 | # |
| 291 | # Unless required by applicable law or agreed to in writing, software |
| 292 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 293 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 294 | # See the License for the specific language governing permissions and |
| 295 | # limitations under the License. |
| 296 | |
| 297 | # This file is created by generate_build_files.py. Do not edit manually. |
| 298 | |
| 299 | """ |
| 300 | |
| 301 | def PrintVariableSection(self, out, name, files): |
| 302 | out.write('%s := \\\n' % name) |
| 303 | for f in sorted(files): |
| 304 | out.write(' %s\\\n' % f) |
| 305 | out.write('\n') |
| 306 | |
| 307 | def WriteFiles(self, files, asm_outputs): |
| 308 | # Legacy Android.mk format |
| 309 | with open('eureka.mk', 'w+') as makefile: |
| 310 | makefile.write(self.header) |
| 311 | |
| 312 | self.PrintVariableSection(makefile, 'crypto_sources', files['crypto']) |
| 313 | self.PrintVariableSection(makefile, 'ssl_sources', files['ssl']) |
| 314 | self.PrintVariableSection(makefile, 'tool_sources', files['tool']) |
| 315 | |
| 316 | for ((osname, arch), asm_files) in asm_outputs: |
| 317 | if osname != 'linux': |
| 318 | continue |
| 319 | self.PrintVariableSection( |
| 320 | makefile, '%s_%s_sources' % (osname, arch), asm_files) |
| 321 | |
| 322 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 323 | class GN(object): |
| 324 | |
| 325 | def __init__(self): |
| 326 | self.firstSection = True |
| 327 | self.header = \ |
| 328 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 329 | # Use of this source code is governed by a BSD-style license that can be |
| 330 | # found in the LICENSE file. |
| 331 | |
| 332 | # This file is created by generate_build_files.py. Do not edit manually. |
| 333 | |
| 334 | """ |
| 335 | |
| 336 | def PrintVariableSection(self, out, name, files): |
| 337 | if not self.firstSection: |
| 338 | out.write('\n') |
| 339 | self.firstSection = False |
| 340 | |
| 341 | out.write('%s = [\n' % name) |
| 342 | for f in sorted(files): |
| 343 | out.write(' "%s",\n' % f) |
| 344 | out.write(']\n') |
| 345 | |
| 346 | def WriteFiles(self, files, asm_outputs): |
| 347 | with open('BUILD.generated.gni', 'w+') as out: |
| 348 | out.write(self.header) |
| 349 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 350 | self.PrintVariableSection(out, 'crypto_sources', |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 351 | files['crypto'] + |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 352 | files['crypto_internal_headers']) |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 353 | self.PrintVariableSection(out, 'crypto_headers', |
| 354 | files['crypto_headers']) |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 355 | self.PrintVariableSection(out, 'ssl_sources', |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 356 | files['ssl'] + files['ssl_internal_headers']) |
| 357 | self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 358 | |
| 359 | for ((osname, arch), asm_files) in asm_outputs: |
| 360 | self.PrintVariableSection( |
| 361 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
| 362 | |
| 363 | fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0] |
| 364 | for fuzzer in files['fuzz']] |
| 365 | self.PrintVariableSection(out, 'fuzzers', fuzzers) |
| 366 | |
| 367 | with open('BUILD.generated_tests.gni', 'w+') as out: |
| 368 | self.firstSection = True |
| 369 | out.write(self.header) |
| 370 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 371 | self.PrintVariableSection(out, 'test_support_sources', |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 372 | files['test_support'] + |
| 373 | files['test_support_headers']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 374 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 375 | files['crypto_test']) |
David Benjamin | f014d60 | 2019-05-07 18:58:06 -0500 | [diff] [blame] | 376 | self.PrintVariableSection(out, 'crypto_test_data', |
| 377 | files['crypto_test_data']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 378 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 379 | |
| 380 | |
| 381 | class GYP(object): |
| 382 | |
| 383 | def __init__(self): |
| 384 | self.header = \ |
| 385 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 386 | # Use of this source code is governed by a BSD-style license that can be |
| 387 | # found in the LICENSE file. |
| 388 | |
| 389 | # This file is created by generate_build_files.py. Do not edit manually. |
| 390 | |
| 391 | """ |
| 392 | |
| 393 | def PrintVariableSection(self, out, name, files): |
| 394 | out.write(' \'%s\': [\n' % name) |
| 395 | for f in sorted(files): |
| 396 | out.write(' \'%s\',\n' % f) |
| 397 | out.write(' ],\n') |
| 398 | |
| 399 | def WriteFiles(self, files, asm_outputs): |
| 400 | with open('boringssl.gypi', 'w+') as gypi: |
| 401 | gypi.write(self.header + '{\n \'variables\': {\n') |
| 402 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 403 | self.PrintVariableSection(gypi, 'boringssl_ssl_sources', |
| 404 | files['ssl'] + files['ssl_headers'] + |
| 405 | files['ssl_internal_headers']) |
| 406 | self.PrintVariableSection(gypi, 'boringssl_crypto_sources', |
| 407 | files['crypto'] + files['crypto_headers'] + |
| 408 | files['crypto_internal_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 409 | |
| 410 | for ((osname, arch), asm_files) in asm_outputs: |
| 411 | self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' % |
| 412 | (osname, arch), asm_files) |
| 413 | |
| 414 | gypi.write(' }\n}\n') |
| 415 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 416 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 417 | def FindCMakeFiles(directory): |
| 418 | """Returns list of all CMakeLists.txt files recursively in directory.""" |
| 419 | cmakefiles = [] |
| 420 | |
| 421 | for (path, _, filenames) in os.walk(directory): |
| 422 | for filename in filenames: |
| 423 | if filename == 'CMakeLists.txt': |
| 424 | cmakefiles.append(os.path.join(path, filename)) |
| 425 | |
| 426 | return cmakefiles |
| 427 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 428 | def OnlyFIPSFragments(path, dent, is_dir): |
Matthew Braithwaite | 95511e9 | 2017-05-08 16:38:03 -0700 | [diff] [blame] | 429 | return is_dir or (path.startswith( |
| 430 | os.path.join('src', 'crypto', 'fipsmodule', '')) and |
| 431 | NoTests(path, dent, is_dir)) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 432 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 433 | def NoTestsNorFIPSFragments(path, dent, is_dir): |
Adam Langley | 323f1eb | 2017-04-06 17:29:10 -0700 | [diff] [blame] | 434 | return (NoTests(path, dent, is_dir) and |
| 435 | (is_dir or not OnlyFIPSFragments(path, dent, is_dir))) |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 436 | |
| 437 | def NoTests(path, dent, is_dir): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 438 | """Filter function that can be passed to FindCFiles in order to remove test |
| 439 | sources.""" |
| 440 | if is_dir: |
| 441 | return dent != 'test' |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 442 | return 'test.' not in dent |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 443 | |
| 444 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 445 | def OnlyTests(path, dent, is_dir): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 446 | """Filter function that can be passed to FindCFiles in order to remove |
| 447 | non-test sources.""" |
| 448 | if is_dir: |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 449 | return dent != 'test' |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 450 | return '_test.' in dent |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 451 | |
| 452 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 453 | def AllFiles(path, dent, is_dir): |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 454 | """Filter function that can be passed to FindCFiles in order to include all |
| 455 | sources.""" |
| 456 | return True |
| 457 | |
| 458 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 459 | def NoTestRunnerFiles(path, dent, is_dir): |
Martin Kreichgauer | 8b487b7 | 2017-04-03 16:07:27 -0700 | [diff] [blame] | 460 | """Filter function that can be passed to FindCFiles or FindHeaderFiles in |
| 461 | order to exclude test runner files.""" |
| 462 | # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which |
| 463 | # are in their own subpackage, from being included in boringssl/BUILD files. |
| 464 | return not is_dir or dent != 'runner' |
| 465 | |
| 466 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 467 | def NotGTestSupport(path, dent, is_dir): |
David Benjamin | c388963 | 2019-03-01 15:03:05 -0500 | [diff] [blame] | 468 | return 'gtest' not in dent and 'abi_test' not in dent |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 469 | |
| 470 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 471 | def SSLHeaderFiles(path, dent, is_dir): |
Aaron Green | 0e15002 | 2018-10-16 12:05:29 -0700 | [diff] [blame] | 472 | 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] | 473 | |
| 474 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 475 | def FindCFiles(directory, filter_func): |
| 476 | """Recurses through directory and returns a list of paths to all the C source |
| 477 | files that pass filter_func.""" |
| 478 | cfiles = [] |
| 479 | |
| 480 | for (path, dirnames, filenames) in os.walk(directory): |
| 481 | for filename in filenames: |
| 482 | if not filename.endswith('.c') and not filename.endswith('.cc'): |
| 483 | continue |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 484 | if not filter_func(path, filename, False): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 485 | continue |
| 486 | cfiles.append(os.path.join(path, filename)) |
| 487 | |
| 488 | for (i, dirname) in enumerate(dirnames): |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 489 | if not filter_func(path, dirname, True): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 490 | del dirnames[i] |
| 491 | |
| 492 | return cfiles |
| 493 | |
| 494 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 495 | def FindHeaderFiles(directory, filter_func): |
| 496 | """Recurses through directory and returns a list of paths to all the header files that pass filter_func.""" |
| 497 | hfiles = [] |
| 498 | |
| 499 | for (path, dirnames, filenames) in os.walk(directory): |
| 500 | for filename in filenames: |
| 501 | if not filename.endswith('.h'): |
| 502 | continue |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 503 | if not filter_func(path, filename, False): |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 504 | continue |
| 505 | hfiles.append(os.path.join(path, filename)) |
| 506 | |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 507 | for (i, dirname) in enumerate(dirnames): |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 508 | if not filter_func(path, dirname, True): |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 509 | del dirnames[i] |
| 510 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 511 | return hfiles |
| 512 | |
| 513 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 514 | def ExtractPerlAsmFromCMakeFile(cmakefile): |
| 515 | """Parses the contents of the CMakeLists.txt file passed as an argument and |
| 516 | returns a list of all the perlasm() directives found in the file.""" |
| 517 | perlasms = [] |
| 518 | with open(cmakefile) as f: |
| 519 | for line in f: |
| 520 | line = line.strip() |
| 521 | if not line.startswith('perlasm('): |
| 522 | continue |
| 523 | if not line.endswith(')'): |
| 524 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 525 | # Remove "perlasm(" from start and ")" from end |
| 526 | params = line[8:-1].split() |
| 527 | if len(params) < 2: |
| 528 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 529 | perlasms.append({ |
| 530 | 'extra_args': params[2:], |
| 531 | 'input': os.path.join(os.path.dirname(cmakefile), params[1]), |
| 532 | 'output': os.path.join(os.path.dirname(cmakefile), params[0]), |
| 533 | }) |
| 534 | |
| 535 | return perlasms |
| 536 | |
| 537 | |
| 538 | def ReadPerlAsmOperations(): |
| 539 | """Returns a list of all perlasm() directives found in CMake config files in |
| 540 | src/.""" |
| 541 | perlasms = [] |
| 542 | cmakefiles = FindCMakeFiles('src') |
| 543 | |
| 544 | for cmakefile in cmakefiles: |
| 545 | perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile)) |
| 546 | |
| 547 | return perlasms |
| 548 | |
| 549 | |
| 550 | def PerlAsm(output_filename, input_filename, perlasm_style, extra_args): |
| 551 | """Runs the a perlasm script and puts the output into output_filename.""" |
| 552 | base_dir = os.path.dirname(output_filename) |
| 553 | if not os.path.isdir(base_dir): |
| 554 | os.makedirs(base_dir) |
David Benjamin | fdd8e9c | 2016-06-26 13:18:50 -0400 | [diff] [blame] | 555 | subprocess.check_call( |
| 556 | ['perl', input_filename, perlasm_style] + extra_args + [output_filename]) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 557 | |
| 558 | |
| 559 | def ArchForAsmFilename(filename): |
| 560 | """Returns the architectures that a given asm file should be compiled for |
| 561 | based on substrings in the filename.""" |
| 562 | |
| 563 | if 'x86_64' in filename or 'avx2' in filename: |
| 564 | return ['x86_64'] |
| 565 | elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename: |
| 566 | return ['x86'] |
| 567 | elif 'armx' in filename: |
| 568 | return ['arm', 'aarch64'] |
| 569 | elif 'armv8' in filename: |
| 570 | return ['aarch64'] |
| 571 | elif 'arm' in filename: |
| 572 | return ['arm'] |
David Benjamin | 9f16ce1 | 2016-09-27 16:30:22 -0400 | [diff] [blame] | 573 | elif 'ppc' in filename: |
| 574 | return ['ppc64le'] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 575 | else: |
| 576 | raise ValueError('Unknown arch for asm filename: ' + filename) |
| 577 | |
| 578 | |
| 579 | def WriteAsmFiles(perlasms): |
| 580 | """Generates asm files from perlasm directives for each supported OS x |
| 581 | platform combination.""" |
| 582 | asmfiles = {} |
| 583 | |
| 584 | for osarch in OS_ARCH_COMBOS: |
| 585 | (osname, arch, perlasm_style, extra_args, asm_ext) = osarch |
| 586 | key = (osname, arch) |
| 587 | outDir = '%s-%s' % key |
| 588 | |
| 589 | for perlasm in perlasms: |
| 590 | filename = os.path.basename(perlasm['input']) |
| 591 | output = perlasm['output'] |
| 592 | if not output.startswith('src'): |
| 593 | raise ValueError('output missing src: %s' % output) |
| 594 | output = os.path.join(outDir, output[4:]) |
William Hesse | c618c40 | 2015-06-22 16:34:02 +0200 | [diff] [blame] | 595 | if output.endswith('-armx.${ASM_EXT}'): |
| 596 | output = output.replace('-armx', |
| 597 | '-armx64' if arch == 'aarch64' else '-armx32') |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 598 | output = output.replace('${ASM_EXT}', asm_ext) |
| 599 | |
| 600 | if arch in ArchForAsmFilename(filename): |
| 601 | PerlAsm(output, perlasm['input'], perlasm_style, |
| 602 | perlasm['extra_args'] + extra_args) |
| 603 | asmfiles.setdefault(key, []).append(output) |
| 604 | |
| 605 | for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems(): |
| 606 | asmfiles.setdefault(key, []).extend(non_perl_asm_files) |
| 607 | |
| 608 | return asmfiles |
| 609 | |
| 610 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 611 | def ExtractVariablesFromCMakeFile(cmakefile): |
| 612 | """Parses the contents of the CMakeLists.txt file passed as an argument and |
| 613 | returns a dictionary of exported source lists.""" |
| 614 | variables = {} |
| 615 | in_set_command = False |
| 616 | set_command = [] |
| 617 | with open(cmakefile) as f: |
| 618 | for line in f: |
| 619 | if '#' in line: |
| 620 | line = line[:line.index('#')] |
| 621 | line = line.strip() |
| 622 | |
| 623 | if not in_set_command: |
| 624 | if line.startswith('set('): |
| 625 | in_set_command = True |
| 626 | set_command = [] |
| 627 | elif line == ')': |
| 628 | in_set_command = False |
| 629 | if not set_command: |
| 630 | raise ValueError('Empty set command') |
| 631 | variables[set_command[0]] = set_command[1:] |
| 632 | else: |
| 633 | set_command.extend([c for c in line.split(' ') if c]) |
| 634 | |
| 635 | if in_set_command: |
| 636 | raise ValueError('Unfinished set command') |
| 637 | return variables |
| 638 | |
| 639 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 640 | def main(platforms): |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 641 | cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake')) |
Andres Erbsen | 5b280a8 | 2017-10-30 15:58:33 +0000 | [diff] [blame] | 642 | crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) + |
Adam Langley | e0c533a | 2019-05-20 09:50:07 -0700 | [diff] [blame] | 643 | FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments) + |
| 644 | FindCFiles(os.path.join('src', 'third_party', 'sike'), NoTestsNorFIPSFragments)) |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 645 | fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments) |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 646 | ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 647 | tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests) |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 648 | tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 649 | |
David Benjamin | 0c9c1aa | 2017-12-12 15:19:20 -0500 | [diff] [blame] | 650 | # third_party/fiat/p256.c lives in third_party/fiat, but it is a FIPS |
| 651 | # fragment, not a normal source file. |
| 652 | p256 = os.path.join('src', 'third_party', 'fiat', 'p256.c') |
| 653 | fips_fragments.append(p256) |
| 654 | crypto_c_files.remove(p256) |
| 655 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 656 | # BCM shared library C files |
| 657 | bcm_crypto_c_files = [ |
| 658 | os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c') |
| 659 | ] |
| 660 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 661 | # Generate err_data.c |
| 662 | with open('err_data.c', 'w+') as err_data: |
| 663 | subprocess.check_call(['go', 'run', 'err_data_generate.go'], |
| 664 | cwd=os.path.join('src', 'crypto', 'err'), |
| 665 | stdout=err_data) |
| 666 | crypto_c_files.append('err_data.c') |
| 667 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 668 | test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'), |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 669 | NotGTestSupport) |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 670 | test_support_h_files = ( |
| 671 | FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) + |
Martin Kreichgauer | 8b487b7 | 2017-04-03 16:07:27 -0700 | [diff] [blame] | 672 | FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles)) |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 673 | |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 674 | crypto_test_files = [] |
| 675 | if EMBED_TEST_DATA: |
| 676 | # Generate crypto_test_data.cc |
| 677 | with open('crypto_test_data.cc', 'w+') as out: |
| 678 | subprocess.check_call( |
| 679 | ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'], |
| 680 | cwd='src', |
| 681 | stdout=out) |
| 682 | crypto_test_files += ['crypto_test_data.cc'] |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 683 | |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 684 | crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests) |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 685 | crypto_test_files += [ |
David Benjamin | c388963 | 2019-03-01 15:03:05 -0500 | [diff] [blame] | 686 | 'src/crypto/test/abi_test.cc', |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 687 | 'src/crypto/test/file_test_gtest.cc', |
| 688 | 'src/crypto/test/gtest_main.cc', |
| 689 | ] |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame^] | 690 | # urandom_test.cc is in a separate binary so that it can be test PRNG |
| 691 | # initialisation. |
| 692 | crypto_test_files = [ |
| 693 | file for file in crypto_test_files |
| 694 | if not file.endswith('/urandom_test.cc') |
| 695 | ] |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 696 | |
| 697 | ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests) |
Robert Sloan | ae1e087 | 2019-03-01 16:01:30 -0800 | [diff] [blame] | 698 | ssl_test_files += [ |
| 699 | 'src/crypto/test/abi_test.cc', |
| 700 | 'src/crypto/test/gtest_main.cc', |
| 701 | ] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 702 | |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame^] | 703 | urandom_test_files = [ |
| 704 | 'src/crypto/fipsmodule/rand/urandom_test.cc', |
| 705 | ] |
| 706 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 707 | fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests) |
| 708 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 709 | ssl_h_files = ( |
| 710 | FindHeaderFiles( |
| 711 | os.path.join('src', 'include', 'openssl'), |
| 712 | SSLHeaderFiles)) |
| 713 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 714 | def NotSSLHeaderFiles(path, filename, is_dir): |
| 715 | return not SSLHeaderFiles(path, filename, is_dir) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 716 | crypto_h_files = ( |
| 717 | FindHeaderFiles( |
| 718 | os.path.join('src', 'include', 'openssl'), |
| 719 | NotSSLHeaderFiles)) |
| 720 | |
| 721 | ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests) |
Andres Erbsen | 5b280a8 | 2017-10-30 15:58:33 +0000 | [diff] [blame] | 722 | crypto_internal_h_files = ( |
| 723 | FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) + |
Adam Langley | e0c533a | 2019-05-20 09:50:07 -0700 | [diff] [blame] | 724 | FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests) + |
| 725 | FindHeaderFiles(os.path.join('src', 'third_party', 'sike'), NoTests)) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 726 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 727 | files = { |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 728 | 'bcm_crypto': bcm_crypto_c_files, |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 729 | 'crypto': crypto_c_files, |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 730 | 'crypto_headers': crypto_h_files, |
| 731 | 'crypto_internal_headers': crypto_internal_h_files, |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 732 | 'crypto_test': sorted(crypto_test_files), |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 733 | '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] | 734 | 'fips_fragments': fips_fragments, |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 735 | 'fuzz': fuzz_c_files, |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 736 | 'ssl': ssl_source_files, |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 737 | 'ssl_headers': ssl_h_files, |
| 738 | 'ssl_internal_headers': ssl_internal_h_files, |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 739 | 'ssl_test': sorted(ssl_test_files), |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 740 | 'tool': tool_c_files, |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 741 | 'tool_headers': tool_h_files, |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 742 | 'test_support': test_support_c_files, |
| 743 | 'test_support_headers': test_support_h_files, |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame^] | 744 | 'urandom_test': sorted(urandom_test_files), |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems()) |
| 748 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 749 | for platform in platforms: |
| 750 | platform.WriteFiles(files, asm_outputs) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 751 | |
| 752 | return 0 |
| 753 | |
| 754 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 755 | if __name__ == '__main__': |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 756 | parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]' |
David Benjamin | eca48e5 | 2019-08-13 11:51:53 -0400 | [diff] [blame] | 757 | ' [android|android-cmake|bazel|eureka|gn|gyp]') |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 758 | parser.add_option('--prefix', dest='prefix', |
| 759 | help='For Bazel, prepend argument to all source files') |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 760 | parser.add_option( |
| 761 | '--embed_test_data', type='choice', dest='embed_test_data', |
| 762 | action='store', default="true", choices=["true", "false"], |
David Benjamin | f014d60 | 2019-05-07 18:58:06 -0500 | [diff] [blame] | 763 | 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] | 764 | options, args = parser.parse_args(sys.argv[1:]) |
| 765 | PREFIX = options.prefix |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 766 | EMBED_TEST_DATA = (options.embed_test_data == "true") |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 767 | |
| 768 | if not args: |
| 769 | parser.print_help() |
| 770 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 771 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 772 | platforms = [] |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 773 | for s in args: |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 774 | if s == 'android': |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 775 | platforms.append(Android()) |
David Benjamin | eca48e5 | 2019-08-13 11:51:53 -0400 | [diff] [blame] | 776 | elif s == 'android-cmake': |
| 777 | platforms.append(AndroidCMake()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 778 | elif s == 'bazel': |
| 779 | platforms.append(Bazel()) |
Robert Sloan | e091af4 | 2017-10-09 12:47:17 -0700 | [diff] [blame] | 780 | elif s == 'eureka': |
| 781 | platforms.append(Eureka()) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 782 | elif s == 'gn': |
| 783 | platforms.append(GN()) |
| 784 | elif s == 'gyp': |
| 785 | platforms.append(GYP()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 786 | else: |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 787 | parser.print_help() |
| 788 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 789 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 790 | sys.exit(main(platforms)) |