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