Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 1 | # coding=utf8 |
| 2 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015, Google Inc. |
| 4 | # |
| 5 | # Permission to use, copy, modify, and/or distribute this software for any |
| 6 | # purpose with or without fee is hereby granted, provided that the above |
| 7 | # copyright notice and this permission notice appear in all copies. |
| 8 | # |
| 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 12 | # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 14 | # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 15 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 17 | """Enumerates source files for consumption by various build systems.""" |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 18 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 19 | import optparse |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 20 | import os |
| 21 | import subprocess |
| 22 | import sys |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 23 | import json |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 24 | |
| 25 | |
| 26 | # OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for |
| 27 | # that platform and the extension used by asm files. |
| 28 | OS_ARCH_COMBOS = [ |
David Benjamin | f6584e7 | 2017-06-08 16:27:16 -0400 | [diff] [blame] | 29 | ('ios', 'arm', 'ios32', [], 'S'), |
| 30 | ('ios', 'aarch64', 'ios64', [], 'S'), |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 31 | ('linux', 'arm', 'linux32', [], 'S'), |
| 32 | ('linux', 'aarch64', 'linux64', [], 'S'), |
Adam Langley | 7c075b9 | 2017-05-22 15:31:13 -0700 | [diff] [blame] | 33 | ('linux', 'ppc64le', 'linux64le', [], 'S'), |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 34 | ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'), |
| 35 | ('linux', 'x86_64', 'elf', [], 'S'), |
| 36 | ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'), |
| 37 | ('mac', 'x86_64', 'macosx', [], 'S'), |
| 38 | ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'), |
| 39 | ('win', 'x86_64', 'nasm', [], 'asm'), |
| 40 | ] |
| 41 | |
| 42 | # NON_PERL_FILES enumerates assembly files that are not processed by the |
| 43 | # perlasm system. |
| 44 | NON_PERL_FILES = { |
| 45 | ('linux', 'arm'): [ |
Adam Langley | 7b8b9c1 | 2016-01-04 07:13:00 -0800 | [diff] [blame] | 46 | 'src/crypto/curve25519/asm/x25519-asm-arm.S', |
David Benjamin | 3c4a5cb | 2016-03-29 17:43:31 -0400 | [diff] [blame] | 47 | 'src/crypto/poly1305/poly1305_arm_asm.S', |
Adam Langley | 7b93593 | 2018-11-12 13:53:42 -0800 | [diff] [blame] | 48 | ], |
| 49 | ('linux', 'x86_64'): [ |
| 50 | 'src/crypto/hrss/asm/poly_rq_mul.S', |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 51 | ], |
| 52 | } |
| 53 | |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 54 | PREFIX = None |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 55 | EMBED_TEST_DATA = True |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def PathOf(x): |
| 59 | return x if not PREFIX else os.path.join(PREFIX, x) |
| 60 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 61 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 62 | class Android(object): |
| 63 | |
| 64 | def __init__(self): |
| 65 | self.header = \ |
| 66 | """# Copyright (C) 2015 The Android Open Source Project |
| 67 | # |
| 68 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 69 | # you may not use this file except in compliance with the License. |
| 70 | # You may obtain a copy of the License at |
| 71 | # |
| 72 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 73 | # |
| 74 | # Unless required by applicable law or agreed to in writing, software |
| 75 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 76 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 77 | # See the License for the specific language governing permissions and |
| 78 | # limitations under the License. |
| 79 | |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 80 | # This file is created by generate_build_files.py. Do not edit manually. |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 81 | """ |
| 82 | |
| 83 | def PrintVariableSection(self, out, name, files): |
| 84 | out.write('%s := \\\n' % name) |
| 85 | for f in sorted(files): |
| 86 | out.write(' %s\\\n' % f) |
| 87 | out.write('\n') |
| 88 | |
| 89 | def WriteFiles(self, files, asm_outputs): |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 90 | # New Android.bp format |
| 91 | with open('sources.bp', 'w+') as blueprint: |
| 92 | blueprint.write(self.header.replace('#', '//')) |
| 93 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 94 | # Separate out BCM files to allow different compilation rules (specific to Android FIPS) |
| 95 | bcm_c_files = files['bcm_crypto'] |
| 96 | non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files] |
| 97 | non_bcm_asm = self.FilterBcmAsm(asm_outputs, False) |
| 98 | bcm_asm = self.FilterBcmAsm(asm_outputs, True) |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 99 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 100 | self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, non_bcm_asm) |
| 101 | self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, bcm_asm) |
| 102 | self.PrintDefaults(blueprint, 'libssl_sources', files['ssl']) |
| 103 | self.PrintDefaults(blueprint, 'bssl_sources', files['tool']) |
| 104 | self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support']) |
| 105 | self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test']) |
| 106 | self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test']) |
| 107 | |
| 108 | # Legacy Android.mk format, only used by Trusty in new branches |
| 109 | with open('sources.mk', 'w+') as makefile: |
| 110 | makefile.write(self.header) |
| 111 | makefile.write('\n') |
| 112 | self.PrintVariableSection(makefile, 'crypto_sources', files['crypto']) |
| 113 | |
| 114 | for ((osname, arch), asm_files) in asm_outputs: |
| 115 | if osname != 'linux': |
| 116 | continue |
| 117 | self.PrintVariableSection( |
| 118 | makefile, '%s_%s_sources' % (osname, arch), asm_files) |
| 119 | |
| 120 | def PrintDefaults(self, blueprint, name, files, asm_outputs={}): |
| 121 | """Print a cc_defaults section from a list of C files and optionally assembly outputs""" |
| 122 | blueprint.write('\n') |
| 123 | blueprint.write('cc_defaults {\n') |
| 124 | blueprint.write(' name: "%s",\n' % name) |
| 125 | blueprint.write(' srcs: [\n') |
| 126 | for f in sorted(files): |
| 127 | blueprint.write(' "%s",\n' % f) |
| 128 | blueprint.write(' ],\n') |
| 129 | |
| 130 | if asm_outputs: |
| 131 | blueprint.write(' target: {\n') |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 132 | for ((osname, arch), asm_files) in asm_outputs: |
Steven Valdez | 93d242b | 2016-10-06 13:49:01 -0400 | [diff] [blame] | 133 | if osname != 'linux' or arch == 'ppc64le': |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 134 | continue |
| 135 | if arch == 'aarch64': |
| 136 | arch = 'arm64' |
| 137 | |
Dan Willemsen | 2eb4bc5 | 2017-10-16 14:37:00 -0700 | [diff] [blame] | 138 | blueprint.write(' linux_%s: {\n' % arch) |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 139 | blueprint.write(' srcs: [\n') |
| 140 | for f in sorted(asm_files): |
| 141 | blueprint.write(' "%s",\n' % f) |
| 142 | blueprint.write(' ],\n') |
| 143 | blueprint.write(' },\n') |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [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 | blueprint.write('}\n') |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 147 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 148 | def FilterBcmAsm(self, asm, want_bcm): |
| 149 | """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] | 150 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 151 | Args: |
| 152 | asm: Assembly file lists to filter |
| 153 | want_bcm: If true then include BCM files, otherwise do not |
Dan Willemsen | b57e4fc | 2016-07-21 11:08:44 -0700 | [diff] [blame] | 154 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 155 | Returns: |
| 156 | A copy of |asm| with files filtered according to |want_bcm| |
| 157 | """ |
| 158 | return [(archinfo, filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, files)) |
| 159 | for (archinfo, files) in asm] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 160 | |
| 161 | |
David Benjamin | eca48e5 | 2019-08-13 11:51:53 -0400 | [diff] [blame] | 162 | class AndroidCMake(object): |
| 163 | |
| 164 | def __init__(self): |
| 165 | self.header = \ |
| 166 | """# Copyright (C) 2019 The Android Open Source Project |
| 167 | # |
| 168 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 169 | # you may not use this file except in compliance with the License. |
| 170 | # You may obtain a copy of the License at |
| 171 | # |
| 172 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 173 | # |
| 174 | # Unless required by applicable law or agreed to in writing, software |
| 175 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 176 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 177 | # See the License for the specific language governing permissions and |
| 178 | # limitations under the License. |
| 179 | |
| 180 | # This file is created by generate_build_files.py. Do not edit manually. |
| 181 | # To specify a custom path prefix, set BORINGSSL_ROOT before including this |
| 182 | # file, or use list(TRANSFORM ... PREPEND) from CMake 3.12. |
| 183 | |
| 184 | """ |
| 185 | |
| 186 | def PrintVariableSection(self, out, name, files): |
| 187 | out.write('set(%s\n' % name) |
| 188 | for f in sorted(files): |
| 189 | # Ideally adding the prefix would be the caller's job, but |
| 190 | # list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When |
| 191 | # sources.cmake is the source of truth, we can ask Android to either write |
| 192 | # a CMake function or update to 3.12. |
| 193 | out.write(' ${BORINGSSL_ROOT}%s\n' % f) |
| 194 | out.write(')\n') |
| 195 | |
| 196 | def WriteFiles(self, files, asm_outputs): |
| 197 | # The Android emulator uses a custom CMake buildsystem. |
| 198 | # |
| 199 | # TODO(davidben): Move our various source lists into sources.cmake and have |
| 200 | # Android consume that directly. |
| 201 | with open('android-sources.cmake', 'w+') as out: |
| 202 | out.write(self.header) |
| 203 | |
| 204 | self.PrintVariableSection(out, 'crypto_sources', files['crypto']) |
| 205 | self.PrintVariableSection(out, 'ssl_sources', files['ssl']) |
| 206 | self.PrintVariableSection(out, 'tool_sources', files['tool']) |
| 207 | self.PrintVariableSection(out, 'test_support_sources', |
| 208 | files['test_support']) |
| 209 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 210 | files['crypto_test']) |
| 211 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
| 212 | |
| 213 | for ((osname, arch), asm_files) in asm_outputs: |
| 214 | self.PrintVariableSection( |
| 215 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
| 216 | |
| 217 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 218 | class Bazel(object): |
| 219 | """Bazel outputs files suitable for including in Bazel files.""" |
| 220 | |
| 221 | def __init__(self): |
| 222 | self.firstSection = True |
| 223 | self.header = \ |
| 224 | """# This file is created by generate_build_files.py. Do not edit manually. |
| 225 | |
| 226 | """ |
| 227 | |
| 228 | def PrintVariableSection(self, out, name, files): |
| 229 | if not self.firstSection: |
| 230 | out.write('\n') |
| 231 | self.firstSection = False |
| 232 | |
| 233 | out.write('%s = [\n' % name) |
| 234 | for f in sorted(files): |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 235 | out.write(' "%s",\n' % PathOf(f)) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 236 | out.write(']\n') |
| 237 | |
| 238 | def WriteFiles(self, files, asm_outputs): |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 239 | with open('BUILD.generated.bzl', 'w+') as out: |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 240 | out.write(self.header) |
| 241 | |
| 242 | self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers']) |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 243 | self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments']) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 244 | self.PrintVariableSection( |
| 245 | out, 'ssl_internal_headers', files['ssl_internal_headers']) |
| 246 | self.PrintVariableSection(out, 'ssl_sources', files['ssl']) |
| 247 | self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers']) |
| 248 | self.PrintVariableSection( |
| 249 | out, 'crypto_internal_headers', files['crypto_internal_headers']) |
| 250 | self.PrintVariableSection(out, 'crypto_sources', files['crypto']) |
| 251 | self.PrintVariableSection(out, 'tool_sources', files['tool']) |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 252 | self.PrintVariableSection(out, 'tool_headers', files['tool_headers']) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 253 | |
| 254 | for ((osname, arch), asm_files) in asm_outputs: |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 255 | self.PrintVariableSection( |
Piotr Sikora | 3f5fe60 | 2015-10-28 12:24:35 -0700 | [diff] [blame] | 256 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 257 | |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 258 | with open('BUILD.generated_tests.bzl', 'w+') as out: |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 259 | out.write(self.header) |
| 260 | |
| 261 | out.write('test_support_sources = [\n') |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 262 | for filename in sorted(files['test_support'] + |
| 263 | files['test_support_headers'] + |
| 264 | files['crypto_internal_headers'] + |
| 265 | files['ssl_internal_headers']): |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 266 | if os.path.basename(filename) == 'malloc.cc': |
| 267 | continue |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 268 | out.write(' "%s",\n' % PathOf(filename)) |
Adam Langley | 9c164b2 | 2015-06-10 18:54:47 -0700 | [diff] [blame] | 269 | |
Adam Langley | 7b6acc5 | 2017-07-27 16:33:27 -0700 | [diff] [blame] | 270 | out.write(']\n') |
Chuck Hays | c608d6b | 2015-10-06 17:54:16 -0700 | [diff] [blame] | 271 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 272 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 273 | files['crypto_test']) |
| 274 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 275 | self.PrintVariableSection(out, 'crypto_test_data', |
| 276 | files['crypto_test_data']) |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame] | 277 | self.PrintVariableSection(out, 'urandom_test_sources', |
| 278 | files['urandom_test']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 279 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 280 | |
Robert Sloan | e091af4 | 2017-10-09 12:47:17 -0700 | [diff] [blame] | 281 | class Eureka(object): |
| 282 | |
| 283 | def __init__(self): |
| 284 | self.header = \ |
| 285 | """# Copyright (C) 2017 The Android Open Source Project |
| 286 | # |
| 287 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 288 | # you may not use this file except in compliance with the License. |
| 289 | # You may obtain a copy of the License at |
| 290 | # |
| 291 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 292 | # |
| 293 | # Unless required by applicable law or agreed to in writing, software |
| 294 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 295 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 296 | # See the License for the specific language governing permissions and |
| 297 | # limitations under the License. |
| 298 | |
| 299 | # This file is created by generate_build_files.py. Do not edit manually. |
| 300 | |
| 301 | """ |
| 302 | |
| 303 | def PrintVariableSection(self, out, name, files): |
| 304 | out.write('%s := \\\n' % name) |
| 305 | for f in sorted(files): |
| 306 | out.write(' %s\\\n' % f) |
| 307 | out.write('\n') |
| 308 | |
| 309 | def WriteFiles(self, files, asm_outputs): |
| 310 | # Legacy Android.mk format |
| 311 | with open('eureka.mk', 'w+') as makefile: |
| 312 | makefile.write(self.header) |
| 313 | |
| 314 | self.PrintVariableSection(makefile, 'crypto_sources', files['crypto']) |
| 315 | self.PrintVariableSection(makefile, 'ssl_sources', files['ssl']) |
| 316 | self.PrintVariableSection(makefile, 'tool_sources', files['tool']) |
| 317 | |
| 318 | for ((osname, arch), asm_files) in asm_outputs: |
| 319 | if osname != 'linux': |
| 320 | continue |
| 321 | self.PrintVariableSection( |
| 322 | makefile, '%s_%s_sources' % (osname, arch), asm_files) |
| 323 | |
| 324 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 325 | class GN(object): |
| 326 | |
| 327 | def __init__(self): |
| 328 | self.firstSection = True |
| 329 | self.header = \ |
| 330 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 331 | # Use of this source code is governed by a BSD-style license that can be |
| 332 | # found in the LICENSE file. |
| 333 | |
| 334 | # This file is created by generate_build_files.py. Do not edit manually. |
| 335 | |
| 336 | """ |
| 337 | |
| 338 | def PrintVariableSection(self, out, name, files): |
| 339 | if not self.firstSection: |
| 340 | out.write('\n') |
| 341 | self.firstSection = False |
| 342 | |
| 343 | out.write('%s = [\n' % name) |
| 344 | for f in sorted(files): |
| 345 | out.write(' "%s",\n' % f) |
| 346 | out.write(']\n') |
| 347 | |
| 348 | def WriteFiles(self, files, asm_outputs): |
| 349 | with open('BUILD.generated.gni', 'w+') as out: |
| 350 | out.write(self.header) |
| 351 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 352 | self.PrintVariableSection(out, 'crypto_sources', |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 353 | files['crypto'] + |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 354 | files['crypto_internal_headers']) |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 355 | self.PrintVariableSection(out, 'crypto_headers', |
| 356 | files['crypto_headers']) |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 357 | self.PrintVariableSection(out, 'ssl_sources', |
James Robinson | 98dd68f | 2018-04-11 14:47:34 -0700 | [diff] [blame] | 358 | files['ssl'] + files['ssl_internal_headers']) |
| 359 | self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 360 | |
| 361 | for ((osname, arch), asm_files) in asm_outputs: |
| 362 | self.PrintVariableSection( |
| 363 | out, 'crypto_sources_%s_%s' % (osname, arch), asm_files) |
| 364 | |
| 365 | fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0] |
| 366 | for fuzzer in files['fuzz']] |
| 367 | self.PrintVariableSection(out, 'fuzzers', fuzzers) |
| 368 | |
| 369 | with open('BUILD.generated_tests.gni', 'w+') as out: |
| 370 | self.firstSection = True |
| 371 | out.write(self.header) |
| 372 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 373 | self.PrintVariableSection(out, 'test_support_sources', |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 374 | files['test_support'] + |
| 375 | files['test_support_headers']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 376 | self.PrintVariableSection(out, 'crypto_test_sources', |
| 377 | files['crypto_test']) |
David Benjamin | f014d60 | 2019-05-07 18:58:06 -0500 | [diff] [blame] | 378 | self.PrintVariableSection(out, 'crypto_test_data', |
| 379 | files['crypto_test_data']) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 380 | self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 381 | |
| 382 | |
| 383 | class GYP(object): |
| 384 | |
| 385 | def __init__(self): |
| 386 | self.header = \ |
| 387 | """# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 388 | # Use of this source code is governed by a BSD-style license that can be |
| 389 | # found in the LICENSE file. |
| 390 | |
| 391 | # This file is created by generate_build_files.py. Do not edit manually. |
| 392 | |
| 393 | """ |
| 394 | |
| 395 | def PrintVariableSection(self, out, name, files): |
| 396 | out.write(' \'%s\': [\n' % name) |
| 397 | for f in sorted(files): |
| 398 | out.write(' \'%s\',\n' % f) |
| 399 | out.write(' ],\n') |
| 400 | |
| 401 | def WriteFiles(self, files, asm_outputs): |
| 402 | with open('boringssl.gypi', 'w+') as gypi: |
| 403 | gypi.write(self.header + '{\n \'variables\': {\n') |
| 404 | |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 405 | self.PrintVariableSection(gypi, 'boringssl_ssl_sources', |
| 406 | files['ssl'] + files['ssl_headers'] + |
| 407 | files['ssl_internal_headers']) |
| 408 | self.PrintVariableSection(gypi, 'boringssl_crypto_sources', |
| 409 | files['crypto'] + files['crypto_headers'] + |
| 410 | files['crypto_internal_headers']) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 411 | |
| 412 | for ((osname, arch), asm_files) in asm_outputs: |
| 413 | self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' % |
| 414 | (osname, arch), asm_files) |
| 415 | |
| 416 | gypi.write(' }\n}\n') |
| 417 | |
Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 418 | class CMake(object): |
| 419 | |
| 420 | def __init__(self): |
| 421 | self.header = \ |
| 422 | R'''# Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 423 | # Use of this source code is governed by a BSD-style license that can be |
| 424 | # found in the LICENSE file. |
| 425 | |
| 426 | # This file is created by generate_build_files.py. Do not edit manually. |
| 427 | |
| 428 | cmake_minimum_required(VERSION 3.0) |
| 429 | |
| 430 | project(BoringSSL LANGUAGES C CXX) |
| 431 | |
| 432 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 433 | set(CLANG 1) |
| 434 | endif() |
| 435 | |
| 436 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 437 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti") |
| 438 | if(APPLE) |
| 439 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 440 | endif() |
| 441 | |
| 442 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common") |
| 443 | if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG) |
| 444 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") |
| 445 | else() |
| 446 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") |
| 447 | endif() |
| 448 | endif() |
| 449 | |
| 450 | # pthread_rwlock_t requires a feature flag. |
| 451 | if(NOT WIN32) |
| 452 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
| 453 | endif() |
| 454 | |
| 455 | if(WIN32) |
| 456 | add_definitions(-D_HAS_EXCEPTIONS=0) |
| 457 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
| 458 | add_definitions(-DNOMINMAX) |
| 459 | # Allow use of fopen. |
| 460 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 461 | # VS 2017 and higher supports STL-only warning suppressions. |
| 462 | # A bug in CMake < 3.13.0 may cause the space in this value to |
| 463 | # cause issues when building with NASM. In that case, update CMake. |
| 464 | add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987") |
| 465 | endif() |
| 466 | |
| 467 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 468 | |
Adam Langley | 8973007 | 2020-01-17 08:18:07 -0800 | [diff] [blame] | 469 | # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an |
| 470 | # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR |
| 471 | # alone, and expects all architecture-specific logic to be conditioned within |
| 472 | # the source files rather than the build. This does not work for our assembly |
| 473 | # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture |
| 474 | # builds. |
| 475 | if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) |
| 476 | list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) |
| 477 | if(NOT ${NUM_ARCHES} EQUAL 1) |
| 478 | message(FATAL_ERROR "Universal binaries not supported.") |
| 479 | endif() |
| 480 | list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) |
| 481 | endif() |
| 482 | |
Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 483 | if(OPENSSL_NO_ASM) |
| 484 | add_definitions(-DOPENSSL_NO_ASM) |
| 485 | set(ARCH "generic") |
| 486 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
| 487 | set(ARCH "x86_64") |
| 488 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") |
| 489 | set(ARCH "x86_64") |
| 490 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") |
| 491 | # cmake reports AMD64 on Windows, but we might be building for 32-bit. |
David Benjamin | 884614c | 2020-06-16 10:59:58 -0400 | [diff] [blame] | 492 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 493 | set(ARCH "x86_64") |
| 494 | else() |
| 495 | set(ARCH "x86") |
| 496 | endif() |
| 497 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") |
| 498 | set(ARCH "x86") |
| 499 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") |
| 500 | set(ARCH "x86") |
| 501 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") |
| 502 | set(ARCH "x86") |
| 503 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") |
| 504 | set(ARCH "aarch64") |
| 505 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") |
| 506 | set(ARCH "aarch64") |
| 507 | # Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture. |
| 508 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64e") |
| 509 | set(ARCH "aarch64") |
| 510 | elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*") |
| 511 | set(ARCH "arm") |
| 512 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips") |
| 513 | # Just to avoid the “unknown processor” error. |
| 514 | set(ARCH "generic") |
| 515 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le") |
| 516 | set(ARCH "ppc64le") |
| 517 | else() |
| 518 | message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) |
| 519 | endif() |
| 520 | |
| 521 | if(NOT OPENSSL_NO_ASM) |
| 522 | if(UNIX) |
| 523 | enable_language(ASM) |
| 524 | |
| 525 | # Clang's integerated assembler does not support debug symbols. |
| 526 | if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang") |
| 527 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g") |
| 528 | endif() |
| 529 | |
| 530 | # CMake does not add -isysroot and -arch flags to assembly. |
| 531 | if(APPLE) |
| 532 | if(CMAKE_OSX_SYSROOT) |
| 533 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"") |
| 534 | endif() |
| 535 | foreach(arch ${CMAKE_OSX_ARCHITECTURES}) |
| 536 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}") |
| 537 | endforeach() |
| 538 | endif() |
| 539 | else() |
| 540 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8") |
| 541 | enable_language(ASM_NASM) |
| 542 | endif() |
| 543 | endif() |
| 544 | |
Adam Langley | a0cdbf9 | 2020-01-21 09:07:46 -0800 | [diff] [blame] | 545 | if(BUILD_SHARED_LIBS) |
| 546 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 547 | # Enable position-independent code globally. This is needed because |
| 548 | # some library targets are OBJECT libraries. |
| 549 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 550 | endif() |
| 551 | |
Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 552 | include_directories(src/include) |
| 553 | |
| 554 | ''' |
| 555 | |
| 556 | def PrintLibrary(self, out, name, files): |
| 557 | out.write('add_library(\n') |
| 558 | out.write(' %s\n\n' % name) |
| 559 | |
| 560 | for f in sorted(files): |
| 561 | out.write(' %s\n' % PathOf(f)) |
| 562 | |
| 563 | out.write(')\n\n') |
| 564 | |
| 565 | def PrintExe(self, out, name, files, libs): |
| 566 | out.write('add_executable(\n') |
| 567 | out.write(' %s\n\n' % name) |
| 568 | |
| 569 | for f in sorted(files): |
| 570 | out.write(' %s\n' % PathOf(f)) |
| 571 | |
| 572 | out.write(')\n\n') |
| 573 | out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs))) |
| 574 | |
| 575 | def PrintSection(self, out, name, files): |
| 576 | out.write('set(\n') |
| 577 | out.write(' %s\n\n' % name) |
| 578 | for f in sorted(files): |
| 579 | out.write(' %s\n' % PathOf(f)) |
| 580 | out.write(')\n\n') |
| 581 | |
| 582 | def WriteFiles(self, files, asm_outputs): |
| 583 | with open('CMakeLists.txt', 'w+') as cmake: |
| 584 | cmake.write(self.header) |
| 585 | |
| 586 | for ((osname, arch), asm_files) in asm_outputs: |
| 587 | self.PrintSection(cmake, 'CRYPTO_%s_%s_SOURCES' % (osname, arch), |
| 588 | asm_files) |
| 589 | |
| 590 | cmake.write( |
| 591 | R'''if(APPLE AND ${ARCH} STREQUAL "aarch64") |
| 592 | set(CRYPTO_ARCH_SOURCES ${CRYPTO_ios_aarch64_SOURCES}) |
| 593 | elseif(APPLE AND ${ARCH} STREQUAL "arm") |
| 594 | set(CRYPTO_ARCH_SOURCES ${CRYPTO_ios_arm_SOURCES}) |
| 595 | elseif(APPLE) |
| 596 | set(CRYPTO_ARCH_SOURCES ${CRYPTO_mac_${ARCH}_SOURCES}) |
| 597 | elseif(UNIX) |
| 598 | set(CRYPTO_ARCH_SOURCES ${CRYPTO_linux_${ARCH}_SOURCES}) |
| 599 | elseif(WIN32) |
| 600 | set(CRYPTO_ARCH_SOURCES ${CRYPTO_win_${ARCH}_SOURCES}) |
| 601 | endif() |
| 602 | |
| 603 | ''') |
| 604 | |
| 605 | self.PrintLibrary(cmake, 'crypto', |
| 606 | files['crypto'] + ['${CRYPTO_ARCH_SOURCES}']) |
| 607 | self.PrintLibrary(cmake, 'ssl', files['ssl']) |
Adam Langley | ff63113 | 2020-01-13 15:24:22 -0800 | [diff] [blame] | 608 | self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto']) |
| 609 | |
| 610 | cmake.write( |
| 611 | R'''if(NOT MSVC AND NOT ANDROID) |
| 612 | target_link_libraries(crypto pthread) |
| 613 | endif() |
| 614 | |
| 615 | ''') |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 616 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 617 | def FindCMakeFiles(directory): |
| 618 | """Returns list of all CMakeLists.txt files recursively in directory.""" |
| 619 | cmakefiles = [] |
| 620 | |
| 621 | for (path, _, filenames) in os.walk(directory): |
| 622 | for filename in filenames: |
| 623 | if filename == 'CMakeLists.txt': |
| 624 | cmakefiles.append(os.path.join(path, filename)) |
| 625 | |
| 626 | return cmakefiles |
| 627 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 628 | def OnlyFIPSFragments(path, dent, is_dir): |
Matthew Braithwaite | 95511e9 | 2017-05-08 16:38:03 -0700 | [diff] [blame] | 629 | return is_dir or (path.startswith( |
| 630 | os.path.join('src', 'crypto', 'fipsmodule', '')) and |
| 631 | NoTests(path, dent, is_dir)) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 632 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 633 | def NoTestsNorFIPSFragments(path, dent, is_dir): |
Adam Langley | 323f1eb | 2017-04-06 17:29:10 -0700 | [diff] [blame] | 634 | return (NoTests(path, dent, is_dir) and |
| 635 | (is_dir or not OnlyFIPSFragments(path, dent, is_dir))) |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 636 | |
| 637 | def NoTests(path, dent, is_dir): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 638 | """Filter function that can be passed to FindCFiles in order to remove test |
| 639 | sources.""" |
| 640 | if is_dir: |
| 641 | return dent != 'test' |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 642 | return 'test.' not in dent |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 643 | |
| 644 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 645 | def OnlyTests(path, dent, is_dir): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 646 | """Filter function that can be passed to FindCFiles in order to remove |
| 647 | non-test sources.""" |
| 648 | if is_dir: |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 649 | return dent != 'test' |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 650 | return '_test.' in dent |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 651 | |
| 652 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 653 | def AllFiles(path, dent, is_dir): |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 654 | """Filter function that can be passed to FindCFiles in order to include all |
| 655 | sources.""" |
| 656 | return True |
| 657 | |
| 658 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 659 | def NoTestRunnerFiles(path, dent, is_dir): |
Martin Kreichgauer | 8b487b7 | 2017-04-03 16:07:27 -0700 | [diff] [blame] | 660 | """Filter function that can be passed to FindCFiles or FindHeaderFiles in |
| 661 | order to exclude test runner files.""" |
| 662 | # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which |
| 663 | # are in their own subpackage, from being included in boringssl/BUILD files. |
| 664 | return not is_dir or dent != 'runner' |
| 665 | |
| 666 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 667 | def NotGTestSupport(path, dent, is_dir): |
David Benjamin | c388963 | 2019-03-01 15:03:05 -0500 | [diff] [blame] | 668 | return 'gtest' not in dent and 'abi_test' not in dent |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 669 | |
| 670 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 671 | def SSLHeaderFiles(path, dent, is_dir): |
Aaron Green | 0e15002 | 2018-10-16 12:05:29 -0700 | [diff] [blame] | 672 | 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] | 673 | |
| 674 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 675 | def FindCFiles(directory, filter_func): |
| 676 | """Recurses through directory and returns a list of paths to all the C source |
| 677 | files that pass filter_func.""" |
| 678 | cfiles = [] |
| 679 | |
| 680 | for (path, dirnames, filenames) in os.walk(directory): |
| 681 | for filename in filenames: |
| 682 | if not filename.endswith('.c') and not filename.endswith('.cc'): |
| 683 | continue |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 684 | if not filter_func(path, filename, False): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 685 | continue |
| 686 | cfiles.append(os.path.join(path, filename)) |
| 687 | |
| 688 | for (i, dirname) in enumerate(dirnames): |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 689 | if not filter_func(path, dirname, True): |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 690 | del dirnames[i] |
| 691 | |
| 692 | return cfiles |
| 693 | |
| 694 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 695 | def FindHeaderFiles(directory, filter_func): |
| 696 | """Recurses through directory and returns a list of paths to all the header files that pass filter_func.""" |
| 697 | hfiles = [] |
| 698 | |
| 699 | for (path, dirnames, filenames) in os.walk(directory): |
| 700 | for filename in filenames: |
| 701 | if not filename.endswith('.h'): |
| 702 | continue |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 703 | if not filter_func(path, filename, False): |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 704 | continue |
| 705 | hfiles.append(os.path.join(path, filename)) |
| 706 | |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 707 | for (i, dirname) in enumerate(dirnames): |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 708 | if not filter_func(path, dirname, True): |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 709 | del dirnames[i] |
| 710 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 711 | return hfiles |
| 712 | |
| 713 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 714 | def ExtractPerlAsmFromCMakeFile(cmakefile): |
| 715 | """Parses the contents of the CMakeLists.txt file passed as an argument and |
| 716 | returns a list of all the perlasm() directives found in the file.""" |
| 717 | perlasms = [] |
| 718 | with open(cmakefile) as f: |
| 719 | for line in f: |
| 720 | line = line.strip() |
| 721 | if not line.startswith('perlasm('): |
| 722 | continue |
| 723 | if not line.endswith(')'): |
| 724 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 725 | # Remove "perlasm(" from start and ")" from end |
| 726 | params = line[8:-1].split() |
| 727 | if len(params) < 2: |
| 728 | raise ValueError('Bad perlasm line in %s' % cmakefile) |
| 729 | perlasms.append({ |
| 730 | 'extra_args': params[2:], |
| 731 | 'input': os.path.join(os.path.dirname(cmakefile), params[1]), |
| 732 | 'output': os.path.join(os.path.dirname(cmakefile), params[0]), |
| 733 | }) |
| 734 | |
| 735 | return perlasms |
| 736 | |
| 737 | |
| 738 | def ReadPerlAsmOperations(): |
| 739 | """Returns a list of all perlasm() directives found in CMake config files in |
| 740 | src/.""" |
| 741 | perlasms = [] |
| 742 | cmakefiles = FindCMakeFiles('src') |
| 743 | |
| 744 | for cmakefile in cmakefiles: |
| 745 | perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile)) |
| 746 | |
| 747 | return perlasms |
| 748 | |
| 749 | |
| 750 | def PerlAsm(output_filename, input_filename, perlasm_style, extra_args): |
| 751 | """Runs the a perlasm script and puts the output into output_filename.""" |
| 752 | base_dir = os.path.dirname(output_filename) |
| 753 | if not os.path.isdir(base_dir): |
| 754 | os.makedirs(base_dir) |
David Benjamin | fdd8e9c | 2016-06-26 13:18:50 -0400 | [diff] [blame] | 755 | subprocess.check_call( |
| 756 | ['perl', input_filename, perlasm_style] + extra_args + [output_filename]) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 757 | |
| 758 | |
| 759 | def ArchForAsmFilename(filename): |
| 760 | """Returns the architectures that a given asm file should be compiled for |
| 761 | based on substrings in the filename.""" |
| 762 | |
| 763 | if 'x86_64' in filename or 'avx2' in filename: |
| 764 | return ['x86_64'] |
| 765 | elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename: |
| 766 | return ['x86'] |
| 767 | elif 'armx' in filename: |
| 768 | return ['arm', 'aarch64'] |
| 769 | elif 'armv8' in filename: |
| 770 | return ['aarch64'] |
| 771 | elif 'arm' in filename: |
| 772 | return ['arm'] |
David Benjamin | 9f16ce1 | 2016-09-27 16:30:22 -0400 | [diff] [blame] | 773 | elif 'ppc' in filename: |
| 774 | return ['ppc64le'] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 775 | else: |
| 776 | raise ValueError('Unknown arch for asm filename: ' + filename) |
| 777 | |
| 778 | |
| 779 | def WriteAsmFiles(perlasms): |
| 780 | """Generates asm files from perlasm directives for each supported OS x |
| 781 | platform combination.""" |
| 782 | asmfiles = {} |
| 783 | |
| 784 | for osarch in OS_ARCH_COMBOS: |
| 785 | (osname, arch, perlasm_style, extra_args, asm_ext) = osarch |
| 786 | key = (osname, arch) |
| 787 | outDir = '%s-%s' % key |
| 788 | |
| 789 | for perlasm in perlasms: |
| 790 | filename = os.path.basename(perlasm['input']) |
| 791 | output = perlasm['output'] |
| 792 | if not output.startswith('src'): |
| 793 | raise ValueError('output missing src: %s' % output) |
| 794 | output = os.path.join(outDir, output[4:]) |
William Hesse | c618c40 | 2015-06-22 16:34:02 +0200 | [diff] [blame] | 795 | if output.endswith('-armx.${ASM_EXT}'): |
| 796 | output = output.replace('-armx', |
| 797 | '-armx64' if arch == 'aarch64' else '-armx32') |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 798 | output = output.replace('${ASM_EXT}', asm_ext) |
| 799 | |
| 800 | if arch in ArchForAsmFilename(filename): |
| 801 | PerlAsm(output, perlasm['input'], perlasm_style, |
| 802 | perlasm['extra_args'] + extra_args) |
| 803 | asmfiles.setdefault(key, []).append(output) |
| 804 | |
| 805 | for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems(): |
| 806 | asmfiles.setdefault(key, []).extend(non_perl_asm_files) |
| 807 | |
| 808 | return asmfiles |
| 809 | |
| 810 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 811 | def ExtractVariablesFromCMakeFile(cmakefile): |
| 812 | """Parses the contents of the CMakeLists.txt file passed as an argument and |
| 813 | returns a dictionary of exported source lists.""" |
| 814 | variables = {} |
| 815 | in_set_command = False |
| 816 | set_command = [] |
| 817 | with open(cmakefile) as f: |
| 818 | for line in f: |
| 819 | if '#' in line: |
| 820 | line = line[:line.index('#')] |
| 821 | line = line.strip() |
| 822 | |
| 823 | if not in_set_command: |
| 824 | if line.startswith('set('): |
| 825 | in_set_command = True |
| 826 | set_command = [] |
| 827 | elif line == ')': |
| 828 | in_set_command = False |
| 829 | if not set_command: |
| 830 | raise ValueError('Empty set command') |
| 831 | variables[set_command[0]] = set_command[1:] |
| 832 | else: |
| 833 | set_command.extend([c for c in line.split(' ') if c]) |
| 834 | |
| 835 | if in_set_command: |
| 836 | raise ValueError('Unfinished set command') |
| 837 | return variables |
| 838 | |
| 839 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 840 | def main(platforms): |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 841 | cmake = ExtractVariablesFromCMakeFile(os.path.join('src', 'sources.cmake')) |
Andres Erbsen | 5b280a8 | 2017-10-30 15:58:33 +0000 | [diff] [blame] | 842 | crypto_c_files = (FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments) + |
Adam Langley | 7f02881 | 2019-10-18 14:48:11 -0700 | [diff] [blame] | 843 | FindCFiles(os.path.join('src', 'third_party', 'fiat'), NoTestsNorFIPSFragments)) |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 844 | fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments) |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 845 | ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 846 | tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests) |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 847 | tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 848 | |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 849 | # BCM shared library C files |
| 850 | bcm_crypto_c_files = [ |
| 851 | os.path.join('src', 'crypto', 'fipsmodule', 'bcm.c') |
| 852 | ] |
| 853 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 854 | # Generate err_data.c |
| 855 | with open('err_data.c', 'w+') as err_data: |
| 856 | subprocess.check_call(['go', 'run', 'err_data_generate.go'], |
| 857 | cwd=os.path.join('src', 'crypto', 'err'), |
| 858 | stdout=err_data) |
| 859 | crypto_c_files.append('err_data.c') |
| 860 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 861 | test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'), |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 862 | NotGTestSupport) |
Matt Braithwaite | dfdd49c | 2016-06-13 17:06:48 -0700 | [diff] [blame] | 863 | test_support_h_files = ( |
| 864 | FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) + |
Martin Kreichgauer | 8b487b7 | 2017-04-03 16:07:27 -0700 | [diff] [blame] | 865 | FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles)) |
David Benjamin | 2607383 | 2015-05-11 20:52:48 -0400 | [diff] [blame] | 866 | |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 867 | crypto_test_files = [] |
| 868 | if EMBED_TEST_DATA: |
| 869 | # Generate crypto_test_data.cc |
| 870 | with open('crypto_test_data.cc', 'w+') as out: |
| 871 | subprocess.check_call( |
| 872 | ['go', 'run', 'util/embed_test_data.go'] + cmake['CRYPTO_TEST_DATA'], |
| 873 | cwd='src', |
| 874 | stdout=out) |
| 875 | crypto_test_files += ['crypto_test_data.cc'] |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 876 | |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 877 | crypto_test_files += FindCFiles(os.path.join('src', 'crypto'), OnlyTests) |
David Benjamin | 96ee4a8 | 2017-07-09 23:46:47 -0400 | [diff] [blame] | 878 | crypto_test_files += [ |
David Benjamin | c388963 | 2019-03-01 15:03:05 -0500 | [diff] [blame] | 879 | 'src/crypto/test/abi_test.cc', |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 880 | 'src/crypto/test/file_test_gtest.cc', |
| 881 | 'src/crypto/test/gtest_main.cc', |
| 882 | ] |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame] | 883 | # urandom_test.cc is in a separate binary so that it can be test PRNG |
| 884 | # initialisation. |
| 885 | crypto_test_files = [ |
| 886 | file for file in crypto_test_files |
| 887 | if not file.endswith('/urandom_test.cc') |
| 888 | ] |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 889 | |
| 890 | ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests) |
Robert Sloan | ae1e087 | 2019-03-01 16:01:30 -0800 | [diff] [blame] | 891 | ssl_test_files += [ |
| 892 | 'src/crypto/test/abi_test.cc', |
| 893 | 'src/crypto/test/gtest_main.cc', |
| 894 | ] |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 895 | |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame] | 896 | urandom_test_files = [ |
| 897 | 'src/crypto/fipsmodule/rand/urandom_test.cc', |
| 898 | ] |
| 899 | |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 900 | fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests) |
| 901 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 902 | ssl_h_files = ( |
| 903 | FindHeaderFiles( |
| 904 | os.path.join('src', 'include', 'openssl'), |
| 905 | SSLHeaderFiles)) |
| 906 | |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 907 | def NotSSLHeaderFiles(path, filename, is_dir): |
| 908 | return not SSLHeaderFiles(path, filename, is_dir) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 909 | crypto_h_files = ( |
| 910 | FindHeaderFiles( |
| 911 | os.path.join('src', 'include', 'openssl'), |
| 912 | NotSSLHeaderFiles)) |
| 913 | |
| 914 | ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests) |
Andres Erbsen | 5b280a8 | 2017-10-30 15:58:33 +0000 | [diff] [blame] | 915 | crypto_internal_h_files = ( |
| 916 | FindHeaderFiles(os.path.join('src', 'crypto'), NoTests) + |
Adam Langley | 7f02881 | 2019-10-18 14:48:11 -0700 | [diff] [blame] | 917 | FindHeaderFiles(os.path.join('src', 'third_party', 'fiat'), NoTests)) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 918 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 919 | files = { |
Pete Bentley | 44544d9 | 2019-08-15 15:01:26 +0100 | [diff] [blame] | 920 | 'bcm_crypto': bcm_crypto_c_files, |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 921 | 'crypto': crypto_c_files, |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 922 | 'crypto_headers': crypto_h_files, |
| 923 | 'crypto_internal_headers': crypto_internal_h_files, |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 924 | 'crypto_test': sorted(crypto_test_files), |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 925 | '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] | 926 | 'fips_fragments': fips_fragments, |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 927 | 'fuzz': fuzz_c_files, |
Adam Langley | feca9e5 | 2017-01-23 13:07:50 -0800 | [diff] [blame] | 928 | 'ssl': ssl_source_files, |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 929 | 'ssl_headers': ssl_h_files, |
| 930 | 'ssl_internal_headers': ssl_internal_h_files, |
David Benjamin | 1d5a570 | 2017-02-13 22:11:49 -0500 | [diff] [blame] | 931 | 'ssl_test': sorted(ssl_test_files), |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 932 | 'tool': tool_c_files, |
Adam Langley | f11f233 | 2016-06-30 11:56:19 -0700 | [diff] [blame] | 933 | 'tool_headers': tool_h_files, |
David Benjamin | c5aa841 | 2016-07-29 17:41:58 -0400 | [diff] [blame] | 934 | 'test_support': test_support_c_files, |
| 935 | 'test_support_headers': test_support_h_files, |
Adam Langley | 3e502c8 | 2019-10-16 09:56:38 -0700 | [diff] [blame] | 936 | 'urandom_test': sorted(urandom_test_files), |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems()) |
| 940 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 941 | for platform in platforms: |
| 942 | platform.WriteFiles(files, asm_outputs) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 943 | |
| 944 | return 0 |
| 945 | |
| 946 | |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 947 | if __name__ == '__main__': |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 948 | parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]' |
David Benjamin | eca48e5 | 2019-08-13 11:51:53 -0400 | [diff] [blame] | 949 | ' [android|android-cmake|bazel|eureka|gn|gyp]') |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 950 | parser.add_option('--prefix', dest='prefix', |
| 951 | help='For Bazel, prepend argument to all source files') |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 952 | parser.add_option( |
| 953 | '--embed_test_data', type='choice', dest='embed_test_data', |
| 954 | action='store', default="true", choices=["true", "false"], |
David Benjamin | f014d60 | 2019-05-07 18:58:06 -0500 | [diff] [blame] | 955 | 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] | 956 | options, args = parser.parse_args(sys.argv[1:]) |
| 957 | PREFIX = options.prefix |
Adam Langley | 990a323 | 2018-05-22 10:02:59 -0700 | [diff] [blame] | 958 | EMBED_TEST_DATA = (options.embed_test_data == "true") |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 959 | |
| 960 | if not args: |
| 961 | parser.print_help() |
| 962 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 963 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 964 | platforms = [] |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 965 | for s in args: |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 966 | if s == 'android': |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 967 | platforms.append(Android()) |
David Benjamin | eca48e5 | 2019-08-13 11:51:53 -0400 | [diff] [blame] | 968 | elif s == 'android-cmake': |
| 969 | platforms.append(AndroidCMake()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 970 | elif s == 'bazel': |
| 971 | platforms.append(Bazel()) |
Robert Sloan | e091af4 | 2017-10-09 12:47:17 -0700 | [diff] [blame] | 972 | elif s == 'eureka': |
| 973 | platforms.append(Eureka()) |
David Benjamin | 38d01c6 | 2016-04-21 18:47:57 -0400 | [diff] [blame] | 974 | elif s == 'gn': |
| 975 | platforms.append(GN()) |
| 976 | elif s == 'gyp': |
| 977 | platforms.append(GYP()) |
Adam Langley | cfd80a9 | 2019-11-08 14:40:08 -0800 | [diff] [blame] | 978 | elif s == 'cmake': |
| 979 | platforms.append(CMake()) |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 980 | else: |
Matt Braithwaite | 1669589 | 2016-06-09 09:34:11 -0700 | [diff] [blame] | 981 | parser.print_help() |
| 982 | sys.exit(1) |
Adam Langley | 9e1a660 | 2015-05-05 17:47:53 -0700 | [diff] [blame] | 983 | |
Adam Langley | 049ef41 | 2015-06-09 18:20:57 -0700 | [diff] [blame] | 984 | sys.exit(main(platforms)) |