blob: a3721fe5c809163ec8c66f4d91851a0e8b55f932 [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 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070048}
49
50
Adam Langley9e1a6602015-05-05 17:47:53 -070051class Android(object):
52
53 def __init__(self):
54 self.header = \
55"""# Copyright (C) 2015 The Android Open Source Project
56#
57# Licensed under the Apache License, Version 2.0 (the "License");
58# you may not use this file except in compliance with the License.
59# You may obtain a copy of the License at
60#
61# http://www.apache.org/licenses/LICENSE-2.0
62#
63# Unless required by applicable law or agreed to in writing, software
64# distributed under the License is distributed on an "AS IS" BASIS,
65# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66# See the License for the specific language governing permissions and
67# limitations under the License.
68
69"""
70
Adam Langley049ef412015-06-09 18:20:57 -070071 def ExtraFiles(self):
72 return ['android_compat_hacks.c', 'android_compat_keywrap.c']
73
Adam Langley9e1a6602015-05-05 17:47:53 -070074 def PrintVariableSection(self, out, name, files):
75 out.write('%s := \\\n' % name)
76 for f in sorted(files):
77 out.write(' %s\\\n' % f)
78 out.write('\n')
79
80 def WriteFiles(self, files, asm_outputs):
81 with open('sources.mk', 'w+') as makefile:
82 makefile.write(self.header)
83
Piotr Sikora6ae67df2015-11-23 18:46:33 -080084 crypto_files = files['crypto'] + self.ExtraFiles()
85 self.PrintVariableSection(makefile, 'crypto_sources', crypto_files)
Adam Langley9e1a6602015-05-05 17:47:53 -070086 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
87 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
88
89 for ((osname, arch), asm_files) in asm_outputs:
90 self.PrintVariableSection(
91 makefile, '%s_%s_sources' % (osname, arch), asm_files)
92
93
Adam Langley049ef412015-06-09 18:20:57 -070094class AndroidStandalone(Android):
95 """AndroidStandalone is for Android builds outside of the Android-system, i.e.
96
97 for applications that wish wish to ship BoringSSL.
98 """
99
100 def ExtraFiles(self):
101 return []
102
103
104class Bazel(object):
105 """Bazel outputs files suitable for including in Bazel files."""
106
107 def __init__(self):
108 self.firstSection = True
109 self.header = \
110"""# This file is created by generate_build_files.py. Do not edit manually.
111
112"""
113
114 def PrintVariableSection(self, out, name, files):
115 if not self.firstSection:
116 out.write('\n')
117 self.firstSection = False
118
119 out.write('%s = [\n' % name)
120 for f in sorted(files):
121 out.write(' "%s",\n' % f)
122 out.write(']\n')
123
124 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700125 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700126 out.write(self.header)
127
128 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
129 self.PrintVariableSection(
130 out, 'ssl_internal_headers', files['ssl_internal_headers'])
131 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
132 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
133 self.PrintVariableSection(
134 out, 'crypto_internal_headers', files['crypto_internal_headers'])
135 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
136 self.PrintVariableSection(out, 'tool_sources', files['tool'])
137
138 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700139 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700140 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700141
Chuck Haysc608d6b2015-10-06 17:54:16 -0700142 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700143 out.write(self.header)
144
145 out.write('test_support_sources = [\n')
146 for filename in files['test_support']:
147 if os.path.basename(filename) == 'malloc.cc':
148 continue
149 out.write(' "%s",\n' % filename)
Adam Langley9c164b22015-06-10 18:54:47 -0700150
Chuck Haysc608d6b2015-10-06 17:54:16 -0700151 out.write(']\n\n')
152
153 out.write('def create_tests(copts):\n')
154 out.write(' test_support_sources_complete = test_support_sources + \\\n')
155 out.write(' native.glob(["src/crypto/test/*.h"])\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700156 name_counts = {}
157 for test in files['tests']:
158 name = os.path.basename(test[0])
159 name_counts[name] = name_counts.get(name, 0) + 1
160
161 first = True
162 for test in files['tests']:
163 name = os.path.basename(test[0])
164 if name_counts[name] > 1:
165 if '/' in test[1]:
166 name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
167 else:
168 name += '_' + test[1].replace('-', '_')
169
170 if not first:
171 out.write('\n')
172 first = False
173
174 src_prefix = 'src/' + test[0]
175 for src in files['test']:
176 if src.startswith(src_prefix):
177 src = src
178 break
179 else:
180 raise ValueError("Can't find source for %s" % test[0])
181
Chuck Haysc608d6b2015-10-06 17:54:16 -0700182 out.write(' native.cc_test(\n')
183 out.write(' name = "%s",\n' % name)
184 out.write(' size = "small",\n')
185 out.write(' srcs = ["%s"] + test_support_sources_complete,\n' % src)
Adam Langley9c164b22015-06-10 18:54:47 -0700186
187 data_files = []
188 if len(test) > 1:
189
Chuck Haysc608d6b2015-10-06 17:54:16 -0700190 out.write(' args = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700191 for arg in test[1:]:
192 if '/' in arg:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700193 out.write(' "$(location src/%s)",\n' % arg)
Adam Langley9c164b22015-06-10 18:54:47 -0700194 data_files.append('src/%s' % arg)
195 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700196 out.write(' "%s",\n' % arg)
197 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700198
Chuck Haysc608d6b2015-10-06 17:54:16 -0700199 out.write(' copts = copts,\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700200
201 if len(data_files) > 0:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700202 out.write(' data = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700203 for filename in data_files:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700204 out.write(' "%s",\n' % filename)
205 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700206
207 if 'ssl/' in test[0]:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700208 out.write(' deps = [\n')
209 out.write(' ":crypto",\n')
210 out.write(' ":ssl",\n')
211 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700212 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700213 out.write(' deps = [":crypto"],\n')
214 out.write(' )\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700215
Adam Langley049ef412015-06-09 18:20:57 -0700216
David Benjamin38d01c62016-04-21 18:47:57 -0400217class GN(object):
218
219 def __init__(self):
220 self.firstSection = True
221 self.header = \
222"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
223# Use of this source code is governed by a BSD-style license that can be
224# found in the LICENSE file.
225
226# This file is created by generate_build_files.py. Do not edit manually.
227
228"""
229
230 def PrintVariableSection(self, out, name, files):
231 if not self.firstSection:
232 out.write('\n')
233 self.firstSection = False
234
235 out.write('%s = [\n' % name)
236 for f in sorted(files):
237 out.write(' "%s",\n' % f)
238 out.write(']\n')
239
240 def WriteFiles(self, files, asm_outputs):
241 with open('BUILD.generated.gni', 'w+') as out:
242 out.write(self.header)
243
244 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
245 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
246
247 for ((osname, arch), asm_files) in asm_outputs:
248 self.PrintVariableSection(
249 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
250
251 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
252 for fuzzer in files['fuzz']]
253 self.PrintVariableSection(out, 'fuzzers', fuzzers)
254
255 with open('BUILD.generated_tests.gni', 'w+') as out:
256 self.firstSection = True
257 out.write(self.header)
258
259 self.PrintVariableSection(out, '_test_support_sources',
260 files['test_support'])
261 out.write('\n')
262
263 out.write('template("create_tests") {\n')
264
265 all_tests = []
266 for test in sorted(files['test']):
267 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
268 all_tests.append(test_name)
269
270 out.write(' executable("%s") {\n' % test_name)
271 out.write(' sources = [\n')
272 out.write(' "%s",\n' % test)
273 out.write(' ]\n')
274 out.write(' sources += _test_support_sources\n')
David Benjaminb3be1cf2016-04-27 19:15:06 -0400275 out.write(' if (defined(invoker.configs_exclude)) {\n')
276 out.write(' configs -= invoker.configs_exclude\n')
277 out.write(' }\n')
David Benjamin38d01c62016-04-21 18:47:57 -0400278 out.write(' configs += invoker.configs\n')
279 out.write(' deps = invoker.deps\n')
280 out.write(' }\n')
281 out.write('\n')
282
283 out.write(' group(target_name) {\n')
284 out.write(' deps = [\n')
285 for test_name in sorted(all_tests):
286 out.write(' ":%s",\n' % test_name)
287 out.write(' ]\n')
288 out.write(' }\n')
289 out.write('}\n')
290
291
292class GYP(object):
293
294 def __init__(self):
295 self.header = \
296"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
297# Use of this source code is governed by a BSD-style license that can be
298# found in the LICENSE file.
299
300# This file is created by generate_build_files.py. Do not edit manually.
301
302"""
303
304 def PrintVariableSection(self, out, name, files):
305 out.write(' \'%s\': [\n' % name)
306 for f in sorted(files):
307 out.write(' \'%s\',\n' % f)
308 out.write(' ],\n')
309
310 def WriteFiles(self, files, asm_outputs):
311 with open('boringssl.gypi', 'w+') as gypi:
312 gypi.write(self.header + '{\n \'variables\': {\n')
313
314 self.PrintVariableSection(
315 gypi, 'boringssl_ssl_sources', files['ssl'])
316 self.PrintVariableSection(
317 gypi, 'boringssl_crypto_sources', files['crypto'])
318
319 for ((osname, arch), asm_files) in asm_outputs:
320 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
321 (osname, arch), asm_files)
322
323 gypi.write(' }\n}\n')
324
325 with open('boringssl_tests.gypi', 'w+') as test_gypi:
326 test_gypi.write(self.header + '{\n \'targets\': [\n')
327
328 test_names = []
329 for test in sorted(files['test']):
330 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
331 test_gypi.write(""" {
332 'target_name': '%s',
333 'type': 'executable',
334 'dependencies': [
335 'boringssl.gyp:boringssl',
336 ],
337 'sources': [
338 '%s',
339 '<@(boringssl_test_support_sources)',
340 ],
341 # TODO(davidben): Fix size_t truncations in BoringSSL.
342 # https://crbug.com/429039
343 'msvs_disabled_warnings': [ 4267, ],
344 },\n""" % (test_name, test))
345 test_names.append(test_name)
346
347 test_names.sort()
348
349 test_gypi.write(' ],\n \'variables\': {\n')
350
351 self.PrintVariableSection(
352 test_gypi, 'boringssl_test_support_sources', files['test_support'])
353
354 test_gypi.write(' \'boringssl_test_targets\': [\n')
355
356 for test in sorted(test_names):
357 test_gypi.write(""" '%s',\n""" % test)
358
359 test_gypi.write(' ],\n }\n}\n')
360
361
Adam Langley9e1a6602015-05-05 17:47:53 -0700362def FindCMakeFiles(directory):
363 """Returns list of all CMakeLists.txt files recursively in directory."""
364 cmakefiles = []
365
366 for (path, _, filenames) in os.walk(directory):
367 for filename in filenames:
368 if filename == 'CMakeLists.txt':
369 cmakefiles.append(os.path.join(path, filename))
370
371 return cmakefiles
372
373
374def NoTests(dent, is_dir):
375 """Filter function that can be passed to FindCFiles in order to remove test
376 sources."""
377 if is_dir:
378 return dent != 'test'
379 return 'test.' not in dent and not dent.startswith('example_')
380
381
382def OnlyTests(dent, is_dir):
383 """Filter function that can be passed to FindCFiles in order to remove
384 non-test sources."""
385 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400386 return dent != 'test'
Adam Langley9e1a6602015-05-05 17:47:53 -0700387 return '_test.' in dent or dent.startswith('example_')
388
389
David Benjamin26073832015-05-11 20:52:48 -0400390def AllFiles(dent, is_dir):
391 """Filter function that can be passed to FindCFiles in order to include all
392 sources."""
393 return True
394
395
Adam Langley049ef412015-06-09 18:20:57 -0700396def SSLHeaderFiles(dent, is_dir):
397 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h']
398
399
Adam Langley9e1a6602015-05-05 17:47:53 -0700400def FindCFiles(directory, filter_func):
401 """Recurses through directory and returns a list of paths to all the C source
402 files that pass filter_func."""
403 cfiles = []
404
405 for (path, dirnames, filenames) in os.walk(directory):
406 for filename in filenames:
407 if not filename.endswith('.c') and not filename.endswith('.cc'):
408 continue
409 if not filter_func(filename, False):
410 continue
411 cfiles.append(os.path.join(path, filename))
412
413 for (i, dirname) in enumerate(dirnames):
414 if not filter_func(dirname, True):
415 del dirnames[i]
416
417 return cfiles
418
419
Adam Langley049ef412015-06-09 18:20:57 -0700420def FindHeaderFiles(directory, filter_func):
421 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
422 hfiles = []
423
424 for (path, dirnames, filenames) in os.walk(directory):
425 for filename in filenames:
426 if not filename.endswith('.h'):
427 continue
428 if not filter_func(filename, False):
429 continue
430 hfiles.append(os.path.join(path, filename))
431
432 return hfiles
433
434
Adam Langley9e1a6602015-05-05 17:47:53 -0700435def ExtractPerlAsmFromCMakeFile(cmakefile):
436 """Parses the contents of the CMakeLists.txt file passed as an argument and
437 returns a list of all the perlasm() directives found in the file."""
438 perlasms = []
439 with open(cmakefile) as f:
440 for line in f:
441 line = line.strip()
442 if not line.startswith('perlasm('):
443 continue
444 if not line.endswith(')'):
445 raise ValueError('Bad perlasm line in %s' % cmakefile)
446 # Remove "perlasm(" from start and ")" from end
447 params = line[8:-1].split()
448 if len(params) < 2:
449 raise ValueError('Bad perlasm line in %s' % cmakefile)
450 perlasms.append({
451 'extra_args': params[2:],
452 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
453 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
454 })
455
456 return perlasms
457
458
459def ReadPerlAsmOperations():
460 """Returns a list of all perlasm() directives found in CMake config files in
461 src/."""
462 perlasms = []
463 cmakefiles = FindCMakeFiles('src')
464
465 for cmakefile in cmakefiles:
466 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
467
468 return perlasms
469
470
471def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
472 """Runs the a perlasm script and puts the output into output_filename."""
473 base_dir = os.path.dirname(output_filename)
474 if not os.path.isdir(base_dir):
475 os.makedirs(base_dir)
476 output = subprocess.check_output(
477 ['perl', input_filename, perlasm_style] + extra_args)
478 with open(output_filename, 'w+') as out_file:
479 out_file.write(output)
480
481
482def ArchForAsmFilename(filename):
483 """Returns the architectures that a given asm file should be compiled for
484 based on substrings in the filename."""
485
486 if 'x86_64' in filename or 'avx2' in filename:
487 return ['x86_64']
488 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
489 return ['x86']
490 elif 'armx' in filename:
491 return ['arm', 'aarch64']
492 elif 'armv8' in filename:
493 return ['aarch64']
494 elif 'arm' in filename:
495 return ['arm']
496 else:
497 raise ValueError('Unknown arch for asm filename: ' + filename)
498
499
500def WriteAsmFiles(perlasms):
501 """Generates asm files from perlasm directives for each supported OS x
502 platform combination."""
503 asmfiles = {}
504
505 for osarch in OS_ARCH_COMBOS:
506 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
507 key = (osname, arch)
508 outDir = '%s-%s' % key
509
510 for perlasm in perlasms:
511 filename = os.path.basename(perlasm['input'])
512 output = perlasm['output']
513 if not output.startswith('src'):
514 raise ValueError('output missing src: %s' % output)
515 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200516 if output.endswith('-armx.${ASM_EXT}'):
517 output = output.replace('-armx',
518 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700519 output = output.replace('${ASM_EXT}', asm_ext)
520
521 if arch in ArchForAsmFilename(filename):
522 PerlAsm(output, perlasm['input'], perlasm_style,
523 perlasm['extra_args'] + extra_args)
524 asmfiles.setdefault(key, []).append(output)
525
526 for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
527 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
528
529 return asmfiles
530
531
Adam Langley049ef412015-06-09 18:20:57 -0700532def main(platforms):
Adam Langley9e1a6602015-05-05 17:47:53 -0700533 crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
534 ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400535 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langley9e1a6602015-05-05 17:47:53 -0700536
537 # Generate err_data.c
538 with open('err_data.c', 'w+') as err_data:
539 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
540 cwd=os.path.join('src', 'crypto', 'err'),
541 stdout=err_data)
542 crypto_c_files.append('err_data.c')
543
David Benjamin38d01c62016-04-21 18:47:57 -0400544 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
545 AllFiles)
David Benjamin26073832015-05-11 20:52:48 -0400546
Adam Langley9e1a6602015-05-05 17:47:53 -0700547 test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
548 test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
549
David Benjamin38d01c62016-04-21 18:47:57 -0400550 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
551
Adam Langley049ef412015-06-09 18:20:57 -0700552 ssl_h_files = (
553 FindHeaderFiles(
554 os.path.join('src', 'include', 'openssl'),
555 SSLHeaderFiles))
556
557 def NotSSLHeaderFiles(filename, is_dir):
558 return not SSLHeaderFiles(filename, is_dir)
559 crypto_h_files = (
560 FindHeaderFiles(
561 os.path.join('src', 'include', 'openssl'),
562 NotSSLHeaderFiles))
563
564 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
565 crypto_internal_h_files = FindHeaderFiles(
566 os.path.join('src', 'crypto'), NoTests)
567
Adam Langley9c164b22015-06-10 18:54:47 -0700568 with open('src/util/all_tests.json', 'r') as f:
569 tests = json.load(f)
David Benjaminf277add2016-03-09 14:38:24 -0500570 # Skip tests for libdecrepit. Consumers import that manually.
571 tests = [test for test in tests if not test[0].startswith("decrepit/")]
Adam Langley9c164b22015-06-10 18:54:47 -0700572 test_binaries = set([test[0] for test in tests])
573 test_sources = set([
574 test.replace('.cc', '').replace('.c', '').replace(
575 'src/',
576 '')
577 for test in test_c_files])
578 if test_binaries != test_sources:
579 print 'Test sources and configured tests do not match'
580 a = test_binaries.difference(test_sources)
581 if len(a) > 0:
582 print 'These tests are configured without sources: ' + str(a)
583 b = test_sources.difference(test_binaries)
584 if len(b) > 0:
585 print 'These test sources are not configured: ' + str(b)
586
Adam Langley9e1a6602015-05-05 17:47:53 -0700587 files = {
588 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700589 'crypto_headers': crypto_h_files,
590 'crypto_internal_headers': crypto_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400591 'fuzz': fuzz_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700592 'ssl': ssl_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700593 'ssl_headers': ssl_h_files,
594 'ssl_internal_headers': ssl_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400595 'tool': tool_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700596 'test': test_c_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400597 'test_support': test_support_c_files,
Adam Langley9c164b22015-06-10 18:54:47 -0700598 'tests': tests,
Adam Langley9e1a6602015-05-05 17:47:53 -0700599 }
600
601 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
602
Adam Langley049ef412015-06-09 18:20:57 -0700603 for platform in platforms:
604 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700605
606 return 0
607
608
609def Usage():
David Benjamin38d01c62016-04-21 18:47:57 -0400610 print 'Usage: python %s [android|android-standalone|bazel|gn|gyp]' % sys.argv[0]
Adam Langley9e1a6602015-05-05 17:47:53 -0700611 sys.exit(1)
612
613
614if __name__ == '__main__':
Adam Langley049ef412015-06-09 18:20:57 -0700615 if len(sys.argv) < 2:
Adam Langley9e1a6602015-05-05 17:47:53 -0700616 Usage()
617
Adam Langley049ef412015-06-09 18:20:57 -0700618 platforms = []
619 for s in sys.argv[1:]:
David Benjamin38d01c62016-04-21 18:47:57 -0400620 if s == 'android':
Adam Langley049ef412015-06-09 18:20:57 -0700621 platforms.append(Android())
622 elif s == 'android-standalone':
623 platforms.append(AndroidStandalone())
624 elif s == 'bazel':
625 platforms.append(Bazel())
David Benjamin38d01c62016-04-21 18:47:57 -0400626 elif s == 'gn':
627 platforms.append(GN())
628 elif s == 'gyp':
629 platforms.append(GYP())
Adam Langley049ef412015-06-09 18:20:57 -0700630 else:
631 Usage()
Adam Langley9e1a6602015-05-05 17:47:53 -0700632
Adam Langley049ef412015-06-09 18:20:57 -0700633 sys.exit(main(platforms))