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