blob: 663d6c72b69b301a4fbd799b576585783de7c02b [file] [log] [blame]
Adam Langley9e1a6602015-05-05 17:47:53 -07001# Copyright (c) 2015, Google Inc.
2#
3# Permission to use, copy, modify, and/or distribute this software for any
4# purpose with or without fee is hereby granted, provided that the above
5# copyright notice and this permission notice appear in all copies.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15"""Enumerates the BoringSSL source in src/ and either generates two gypi files
16 (boringssl.gypi and boringssl_tests.gypi) for Chromium, or generates
17 source-list files for Android."""
18
19import os
20import subprocess
21import sys
Adam Langley9c164b22015-06-10 18:54:47 -070022import json
Adam Langley9e1a6602015-05-05 17:47:53 -070023
24
25# OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for
26# that platform and the extension used by asm files.
27OS_ARCH_COMBOS = [
28 ('linux', 'arm', 'linux32', [], 'S'),
29 ('linux', 'aarch64', 'linux64', [], 'S'),
30 ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
31 ('linux', 'x86_64', 'elf', [], 'S'),
32 ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
33 ('mac', 'x86_64', 'macosx', [], 'S'),
34 ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
35 ('win', 'x86_64', 'nasm', [], 'asm'),
36]
37
38# NON_PERL_FILES enumerates assembly files that are not processed by the
39# perlasm system.
40NON_PERL_FILES = {
41 ('linux', 'arm'): [
Adam Langley7b8b9c12016-01-04 07:13:00 -080042 'src/crypto/curve25519/asm/x25519-asm-arm.S',
David Benjamin3c4a5cb2016-03-29 17:43:31 -040043 'src/crypto/poly1305/poly1305_arm_asm.S',
Adam Langley9e1a6602015-05-05 17:47:53 -070044 ],
Matt Braithwaitee021a242016-01-14 13:41:46 -080045 ('linux', 'x86_64'): [
46 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
47 ],
Piotr Sikora8ca0b412016-06-02 11:59:21 -070048 ('mac', 'x86_64'): [
49 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
50 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070051}
52
53
Adam Langley9e1a6602015-05-05 17:47:53 -070054class Android(object):
55
56 def __init__(self):
57 self.header = \
58"""# Copyright (C) 2015 The Android Open Source Project
59#
60# Licensed under the Apache License, Version 2.0 (the "License");
61# you may not use this file except in compliance with the License.
62# You may obtain a copy of the License at
63#
64# http://www.apache.org/licenses/LICENSE-2.0
65#
66# Unless required by applicable law or agreed to in writing, software
67# distributed under the License is distributed on an "AS IS" BASIS,
68# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69# See the License for the specific language governing permissions and
70# limitations under the License.
71
72"""
73
Adam Langley049ef412015-06-09 18:20:57 -070074 def ExtraFiles(self):
75 return ['android_compat_hacks.c', 'android_compat_keywrap.c']
76
Adam Langley9e1a6602015-05-05 17:47:53 -070077 def PrintVariableSection(self, out, name, files):
78 out.write('%s := \\\n' % name)
79 for f in sorted(files):
80 out.write(' %s\\\n' % f)
81 out.write('\n')
82
83 def WriteFiles(self, files, asm_outputs):
84 with open('sources.mk', 'w+') as makefile:
85 makefile.write(self.header)
86
Piotr Sikora6ae67df2015-11-23 18:46:33 -080087 crypto_files = files['crypto'] + self.ExtraFiles()
88 self.PrintVariableSection(makefile, 'crypto_sources', crypto_files)
Adam Langley9e1a6602015-05-05 17:47:53 -070089 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
90 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
91
92 for ((osname, arch), asm_files) in asm_outputs:
93 self.PrintVariableSection(
94 makefile, '%s_%s_sources' % (osname, arch), asm_files)
95
96
Adam Langley049ef412015-06-09 18:20:57 -070097class AndroidStandalone(Android):
98 """AndroidStandalone is for Android builds outside of the Android-system, i.e.
99
100 for applications that wish wish to ship BoringSSL.
101 """
102
103 def ExtraFiles(self):
104 return []
105
106
107class Bazel(object):
108 """Bazel outputs files suitable for including in Bazel files."""
109
110 def __init__(self):
111 self.firstSection = True
112 self.header = \
113"""# This file is created by generate_build_files.py. Do not edit manually.
114
115"""
116
117 def PrintVariableSection(self, out, name, files):
118 if not self.firstSection:
119 out.write('\n')
120 self.firstSection = False
121
122 out.write('%s = [\n' % name)
123 for f in sorted(files):
124 out.write(' "%s",\n' % f)
125 out.write(']\n')
126
127 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700128 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700129 out.write(self.header)
130
131 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
132 self.PrintVariableSection(
133 out, 'ssl_internal_headers', files['ssl_internal_headers'])
134 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
135 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
136 self.PrintVariableSection(
137 out, 'crypto_internal_headers', files['crypto_internal_headers'])
138 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
139 self.PrintVariableSection(out, 'tool_sources', files['tool'])
140
141 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700142 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700143 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700144
Chuck Haysc608d6b2015-10-06 17:54:16 -0700145 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700146 out.write(self.header)
147
148 out.write('test_support_sources = [\n')
149 for filename in files['test_support']:
150 if os.path.basename(filename) == 'malloc.cc':
151 continue
152 out.write(' "%s",\n' % filename)
Adam Langley9c164b22015-06-10 18:54:47 -0700153
Chuck Haysc608d6b2015-10-06 17:54:16 -0700154 out.write(']\n\n')
155
156 out.write('def create_tests(copts):\n')
157 out.write(' test_support_sources_complete = test_support_sources + \\\n')
158 out.write(' native.glob(["src/crypto/test/*.h"])\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700159 name_counts = {}
160 for test in files['tests']:
161 name = os.path.basename(test[0])
162 name_counts[name] = name_counts.get(name, 0) + 1
163
164 first = True
165 for test in files['tests']:
166 name = os.path.basename(test[0])
167 if name_counts[name] > 1:
168 if '/' in test[1]:
169 name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
170 else:
171 name += '_' + test[1].replace('-', '_')
172
173 if not first:
174 out.write('\n')
175 first = False
176
177 src_prefix = 'src/' + test[0]
178 for src in files['test']:
179 if src.startswith(src_prefix):
180 src = src
181 break
182 else:
183 raise ValueError("Can't find source for %s" % test[0])
184
Chuck Haysc608d6b2015-10-06 17:54:16 -0700185 out.write(' native.cc_test(\n')
186 out.write(' name = "%s",\n' % name)
187 out.write(' size = "small",\n')
188 out.write(' srcs = ["%s"] + test_support_sources_complete,\n' % src)
Adam Langley9c164b22015-06-10 18:54:47 -0700189
190 data_files = []
191 if len(test) > 1:
192
Chuck Haysc608d6b2015-10-06 17:54:16 -0700193 out.write(' args = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700194 for arg in test[1:]:
195 if '/' in arg:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700196 out.write(' "$(location src/%s)",\n' % arg)
Adam Langley9c164b22015-06-10 18:54:47 -0700197 data_files.append('src/%s' % arg)
198 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700199 out.write(' "%s",\n' % arg)
200 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700201
Chuck Haysc608d6b2015-10-06 17:54:16 -0700202 out.write(' copts = copts,\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700203
204 if len(data_files) > 0:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700205 out.write(' data = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700206 for filename in data_files:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700207 out.write(' "%s",\n' % filename)
208 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700209
210 if 'ssl/' in test[0]:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700211 out.write(' deps = [\n')
212 out.write(' ":crypto",\n')
213 out.write(' ":ssl",\n')
214 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700215 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700216 out.write(' deps = [":crypto"],\n')
217 out.write(' )\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700218
Adam Langley049ef412015-06-09 18:20:57 -0700219
David Benjamin38d01c62016-04-21 18:47:57 -0400220class GN(object):
221
222 def __init__(self):
223 self.firstSection = True
224 self.header = \
225"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
226# Use of this source code is governed by a BSD-style license that can be
227# found in the LICENSE file.
228
229# This file is created by generate_build_files.py. Do not edit manually.
230
231"""
232
233 def PrintVariableSection(self, out, name, files):
234 if not self.firstSection:
235 out.write('\n')
236 self.firstSection = False
237
238 out.write('%s = [\n' % name)
239 for f in sorted(files):
240 out.write(' "%s",\n' % f)
241 out.write(']\n')
242
243 def WriteFiles(self, files, asm_outputs):
244 with open('BUILD.generated.gni', 'w+') as out:
245 out.write(self.header)
246
247 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
248 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
249
250 for ((osname, arch), asm_files) in asm_outputs:
251 self.PrintVariableSection(
252 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
253
254 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
255 for fuzzer in files['fuzz']]
256 self.PrintVariableSection(out, 'fuzzers', fuzzers)
257
258 with open('BUILD.generated_tests.gni', 'w+') as out:
259 self.firstSection = True
260 out.write(self.header)
261
262 self.PrintVariableSection(out, '_test_support_sources',
263 files['test_support'])
264 out.write('\n')
265
266 out.write('template("create_tests") {\n')
267
268 all_tests = []
269 for test in sorted(files['test']):
270 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
271 all_tests.append(test_name)
272
273 out.write(' executable("%s") {\n' % test_name)
274 out.write(' sources = [\n')
275 out.write(' "%s",\n' % test)
276 out.write(' ]\n')
277 out.write(' sources += _test_support_sources\n')
David Benjaminb3be1cf2016-04-27 19:15:06 -0400278 out.write(' if (defined(invoker.configs_exclude)) {\n')
279 out.write(' configs -= invoker.configs_exclude\n')
280 out.write(' }\n')
David Benjamin38d01c62016-04-21 18:47:57 -0400281 out.write(' configs += invoker.configs\n')
282 out.write(' deps = invoker.deps\n')
283 out.write(' }\n')
284 out.write('\n')
285
286 out.write(' group(target_name) {\n')
287 out.write(' deps = [\n')
288 for test_name in sorted(all_tests):
289 out.write(' ":%s",\n' % test_name)
290 out.write(' ]\n')
291 out.write(' }\n')
292 out.write('}\n')
293
294
295class GYP(object):
296
297 def __init__(self):
298 self.header = \
299"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
300# Use of this source code is governed by a BSD-style license that can be
301# found in the LICENSE file.
302
303# This file is created by generate_build_files.py. Do not edit manually.
304
305"""
306
307 def PrintVariableSection(self, out, name, files):
308 out.write(' \'%s\': [\n' % name)
309 for f in sorted(files):
310 out.write(' \'%s\',\n' % f)
311 out.write(' ],\n')
312
313 def WriteFiles(self, files, asm_outputs):
314 with open('boringssl.gypi', 'w+') as gypi:
315 gypi.write(self.header + '{\n \'variables\': {\n')
316
317 self.PrintVariableSection(
318 gypi, 'boringssl_ssl_sources', files['ssl'])
319 self.PrintVariableSection(
320 gypi, 'boringssl_crypto_sources', files['crypto'])
321
322 for ((osname, arch), asm_files) in asm_outputs:
323 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
324 (osname, arch), asm_files)
325
326 gypi.write(' }\n}\n')
327
328 with open('boringssl_tests.gypi', 'w+') as test_gypi:
329 test_gypi.write(self.header + '{\n \'targets\': [\n')
330
331 test_names = []
332 for test in sorted(files['test']):
333 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
334 test_gypi.write(""" {
335 'target_name': '%s',
336 'type': 'executable',
337 'dependencies': [
338 'boringssl.gyp:boringssl',
339 ],
340 'sources': [
341 '%s',
342 '<@(boringssl_test_support_sources)',
343 ],
344 # TODO(davidben): Fix size_t truncations in BoringSSL.
345 # https://crbug.com/429039
346 'msvs_disabled_warnings': [ 4267, ],
347 },\n""" % (test_name, test))
348 test_names.append(test_name)
349
350 test_names.sort()
351
352 test_gypi.write(' ],\n \'variables\': {\n')
353
354 self.PrintVariableSection(
355 test_gypi, 'boringssl_test_support_sources', files['test_support'])
356
357 test_gypi.write(' \'boringssl_test_targets\': [\n')
358
359 for test in sorted(test_names):
360 test_gypi.write(""" '%s',\n""" % test)
361
362 test_gypi.write(' ],\n }\n}\n')
363
364
Adam Langley9e1a6602015-05-05 17:47:53 -0700365def FindCMakeFiles(directory):
366 """Returns list of all CMakeLists.txt files recursively in directory."""
367 cmakefiles = []
368
369 for (path, _, filenames) in os.walk(directory):
370 for filename in filenames:
371 if filename == 'CMakeLists.txt':
372 cmakefiles.append(os.path.join(path, filename))
373
374 return cmakefiles
375
376
377def NoTests(dent, is_dir):
378 """Filter function that can be passed to FindCFiles in order to remove test
379 sources."""
380 if is_dir:
381 return dent != 'test'
382 return 'test.' not in dent and not dent.startswith('example_')
383
384
385def OnlyTests(dent, is_dir):
386 """Filter function that can be passed to FindCFiles in order to remove
387 non-test sources."""
388 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400389 return dent != 'test'
Adam Langley9e1a6602015-05-05 17:47:53 -0700390 return '_test.' in dent or dent.startswith('example_')
391
392
David Benjamin26073832015-05-11 20:52:48 -0400393def AllFiles(dent, is_dir):
394 """Filter function that can be passed to FindCFiles in order to include all
395 sources."""
396 return True
397
398
Adam Langley049ef412015-06-09 18:20:57 -0700399def SSLHeaderFiles(dent, is_dir):
400 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h']
401
402
Adam Langley9e1a6602015-05-05 17:47:53 -0700403def FindCFiles(directory, filter_func):
404 """Recurses through directory and returns a list of paths to all the C source
405 files that pass filter_func."""
406 cfiles = []
407
408 for (path, dirnames, filenames) in os.walk(directory):
409 for filename in filenames:
410 if not filename.endswith('.c') and not filename.endswith('.cc'):
411 continue
412 if not filter_func(filename, False):
413 continue
414 cfiles.append(os.path.join(path, filename))
415
416 for (i, dirname) in enumerate(dirnames):
417 if not filter_func(dirname, True):
418 del dirnames[i]
419
420 return cfiles
421
422
Adam Langley049ef412015-06-09 18:20:57 -0700423def FindHeaderFiles(directory, filter_func):
424 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
425 hfiles = []
426
427 for (path, dirnames, filenames) in os.walk(directory):
428 for filename in filenames:
429 if not filename.endswith('.h'):
430 continue
431 if not filter_func(filename, False):
432 continue
433 hfiles.append(os.path.join(path, filename))
434
435 return hfiles
436
437
Adam Langley9e1a6602015-05-05 17:47:53 -0700438def ExtractPerlAsmFromCMakeFile(cmakefile):
439 """Parses the contents of the CMakeLists.txt file passed as an argument and
440 returns a list of all the perlasm() directives found in the file."""
441 perlasms = []
442 with open(cmakefile) as f:
443 for line in f:
444 line = line.strip()
445 if not line.startswith('perlasm('):
446 continue
447 if not line.endswith(')'):
448 raise ValueError('Bad perlasm line in %s' % cmakefile)
449 # Remove "perlasm(" from start and ")" from end
450 params = line[8:-1].split()
451 if len(params) < 2:
452 raise ValueError('Bad perlasm line in %s' % cmakefile)
453 perlasms.append({
454 'extra_args': params[2:],
455 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
456 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
457 })
458
459 return perlasms
460
461
462def ReadPerlAsmOperations():
463 """Returns a list of all perlasm() directives found in CMake config files in
464 src/."""
465 perlasms = []
466 cmakefiles = FindCMakeFiles('src')
467
468 for cmakefile in cmakefiles:
469 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
470
471 return perlasms
472
473
474def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
475 """Runs the a perlasm script and puts the output into output_filename."""
476 base_dir = os.path.dirname(output_filename)
477 if not os.path.isdir(base_dir):
478 os.makedirs(base_dir)
479 output = subprocess.check_output(
480 ['perl', input_filename, perlasm_style] + extra_args)
481 with open(output_filename, 'w+') as out_file:
482 out_file.write(output)
483
484
485def ArchForAsmFilename(filename):
486 """Returns the architectures that a given asm file should be compiled for
487 based on substrings in the filename."""
488
489 if 'x86_64' in filename or 'avx2' in filename:
490 return ['x86_64']
491 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
492 return ['x86']
493 elif 'armx' in filename:
494 return ['arm', 'aarch64']
495 elif 'armv8' in filename:
496 return ['aarch64']
497 elif 'arm' in filename:
498 return ['arm']
499 else:
500 raise ValueError('Unknown arch for asm filename: ' + filename)
501
502
503def WriteAsmFiles(perlasms):
504 """Generates asm files from perlasm directives for each supported OS x
505 platform combination."""
506 asmfiles = {}
507
508 for osarch in OS_ARCH_COMBOS:
509 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
510 key = (osname, arch)
511 outDir = '%s-%s' % key
512
513 for perlasm in perlasms:
514 filename = os.path.basename(perlasm['input'])
515 output = perlasm['output']
516 if not output.startswith('src'):
517 raise ValueError('output missing src: %s' % output)
518 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200519 if output.endswith('-armx.${ASM_EXT}'):
520 output = output.replace('-armx',
521 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700522 output = output.replace('${ASM_EXT}', asm_ext)
523
524 if arch in ArchForAsmFilename(filename):
525 PerlAsm(output, perlasm['input'], perlasm_style,
526 perlasm['extra_args'] + extra_args)
527 asmfiles.setdefault(key, []).append(output)
528
529 for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
530 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
531
532 return asmfiles
533
534
Adam Langley049ef412015-06-09 18:20:57 -0700535def main(platforms):
Adam Langley9e1a6602015-05-05 17:47:53 -0700536 crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
537 ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400538 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langley9e1a6602015-05-05 17:47:53 -0700539
540 # Generate err_data.c
541 with open('err_data.c', 'w+') as err_data:
542 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
543 cwd=os.path.join('src', 'crypto', 'err'),
544 stdout=err_data)
545 crypto_c_files.append('err_data.c')
546
David Benjamin38d01c62016-04-21 18:47:57 -0400547 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
548 AllFiles)
David Benjamin26073832015-05-11 20:52:48 -0400549
Adam Langley9e1a6602015-05-05 17:47:53 -0700550 test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
551 test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
552
David Benjamin38d01c62016-04-21 18:47:57 -0400553 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
554
Adam Langley049ef412015-06-09 18:20:57 -0700555 ssl_h_files = (
556 FindHeaderFiles(
557 os.path.join('src', 'include', 'openssl'),
558 SSLHeaderFiles))
559
560 def NotSSLHeaderFiles(filename, is_dir):
561 return not SSLHeaderFiles(filename, is_dir)
562 crypto_h_files = (
563 FindHeaderFiles(
564 os.path.join('src', 'include', 'openssl'),
565 NotSSLHeaderFiles))
566
567 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
568 crypto_internal_h_files = FindHeaderFiles(
569 os.path.join('src', 'crypto'), NoTests)
570
Adam Langley9c164b22015-06-10 18:54:47 -0700571 with open('src/util/all_tests.json', 'r') as f:
572 tests = json.load(f)
David Benjaminf277add2016-03-09 14:38:24 -0500573 # Skip tests for libdecrepit. Consumers import that manually.
574 tests = [test for test in tests if not test[0].startswith("decrepit/")]
Adam Langley9c164b22015-06-10 18:54:47 -0700575 test_binaries = set([test[0] for test in tests])
576 test_sources = set([
577 test.replace('.cc', '').replace('.c', '').replace(
578 'src/',
579 '')
580 for test in test_c_files])
581 if test_binaries != test_sources:
582 print 'Test sources and configured tests do not match'
583 a = test_binaries.difference(test_sources)
584 if len(a) > 0:
585 print 'These tests are configured without sources: ' + str(a)
586 b = test_sources.difference(test_binaries)
587 if len(b) > 0:
588 print 'These test sources are not configured: ' + str(b)
589
Adam Langley9e1a6602015-05-05 17:47:53 -0700590 files = {
591 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700592 'crypto_headers': crypto_h_files,
593 'crypto_internal_headers': crypto_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400594 'fuzz': fuzz_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700595 'ssl': ssl_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700596 'ssl_headers': ssl_h_files,
597 'ssl_internal_headers': ssl_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400598 'tool': tool_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700599 'test': test_c_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400600 'test_support': test_support_c_files,
Adam Langley9c164b22015-06-10 18:54:47 -0700601 'tests': tests,
Adam Langley9e1a6602015-05-05 17:47:53 -0700602 }
603
604 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
605
Adam Langley049ef412015-06-09 18:20:57 -0700606 for platform in platforms:
607 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700608
609 return 0
610
611
612def Usage():
David Benjamin38d01c62016-04-21 18:47:57 -0400613 print 'Usage: python %s [android|android-standalone|bazel|gn|gyp]' % sys.argv[0]
Adam Langley9e1a6602015-05-05 17:47:53 -0700614 sys.exit(1)
615
616
617if __name__ == '__main__':
Adam Langley049ef412015-06-09 18:20:57 -0700618 if len(sys.argv) < 2:
Adam Langley9e1a6602015-05-05 17:47:53 -0700619 Usage()
620
Adam Langley049ef412015-06-09 18:20:57 -0700621 platforms = []
622 for s in sys.argv[1:]:
David Benjamin38d01c62016-04-21 18:47:57 -0400623 if s == 'android':
Adam Langley049ef412015-06-09 18:20:57 -0700624 platforms.append(Android())
625 elif s == 'android-standalone':
626 platforms.append(AndroidStandalone())
627 elif s == 'bazel':
628 platforms.append(Bazel())
David Benjamin38d01c62016-04-21 18:47:57 -0400629 elif s == 'gn':
630 platforms.append(GN())
631 elif s == 'gyp':
632 platforms.append(GYP())
Adam Langley049ef412015-06-09 18:20:57 -0700633 else:
634 Usage()
Adam Langley9e1a6602015-05-05 17:47:53 -0700635
Adam Langley049ef412015-06-09 18:20:57 -0700636 sys.exit(main(platforms))