blob: 76c390b8999c62ba90b1f786ddd99269c4799ec8 [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
Matt Braithwaite16695892016-06-09 09:34:11 -070015"""Enumerates source files for consumption by various build systems."""
Adam Langley9e1a6602015-05-05 17:47:53 -070016
Matt Braithwaite16695892016-06-09 09:34:11 -070017import optparse
Adam Langley9e1a6602015-05-05 17:47:53 -070018import os
19import subprocess
20import sys
Adam Langley9c164b22015-06-10 18:54:47 -070021import json
Adam Langley9e1a6602015-05-05 17:47:53 -070022
23
24# OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for
25# that platform and the extension used by asm files.
26OS_ARCH_COMBOS = [
27 ('linux', 'arm', 'linux32', [], 'S'),
28 ('linux', 'aarch64', 'linux64', [], 'S'),
29 ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
30 ('linux', 'x86_64', 'elf', [], 'S'),
31 ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
32 ('mac', 'x86_64', 'macosx', [], 'S'),
33 ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
34 ('win', 'x86_64', 'nasm', [], 'asm'),
35]
36
37# NON_PERL_FILES enumerates assembly files that are not processed by the
38# perlasm system.
39NON_PERL_FILES = {
40 ('linux', 'arm'): [
Adam Langley7b8b9c12016-01-04 07:13:00 -080041 'src/crypto/curve25519/asm/x25519-asm-arm.S',
David Benjamin3c4a5cb2016-03-29 17:43:31 -040042 'src/crypto/poly1305/poly1305_arm_asm.S',
Adam Langley9e1a6602015-05-05 17:47:53 -070043 ],
Matt Braithwaitee021a242016-01-14 13:41:46 -080044 ('linux', 'x86_64'): [
45 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
46 ],
Piotr Sikora8ca0b412016-06-02 11:59:21 -070047 ('mac', 'x86_64'): [
48 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
49 ],
Adam Langley9e1a6602015-05-05 17:47:53 -070050}
51
Matt Braithwaite16695892016-06-09 09:34:11 -070052PREFIX = None
53
54
55def PathOf(x):
56 return x if not PREFIX else os.path.join(PREFIX, x)
57
Adam Langley9e1a6602015-05-05 17:47:53 -070058
Adam Langley9e1a6602015-05-05 17:47:53 -070059class Android(object):
60
61 def __init__(self):
62 self.header = \
63"""# Copyright (C) 2015 The Android Open Source Project
64#
65# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
67# You may obtain a copy of the License at
68#
69# http://www.apache.org/licenses/LICENSE-2.0
70#
71# Unless required by applicable law or agreed to in writing, software
72# distributed under the License is distributed on an "AS IS" BASIS,
73# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74# See the License for the specific language governing permissions and
75# limitations under the License.
76
77"""
78
Adam Langley049ef412015-06-09 18:20:57 -070079 def ExtraFiles(self):
80 return ['android_compat_hacks.c', 'android_compat_keywrap.c']
81
Adam Langley9e1a6602015-05-05 17:47:53 -070082 def PrintVariableSection(self, out, name, files):
83 out.write('%s := \\\n' % name)
84 for f in sorted(files):
85 out.write(' %s\\\n' % f)
86 out.write('\n')
87
88 def WriteFiles(self, files, asm_outputs):
89 with open('sources.mk', 'w+') as makefile:
90 makefile.write(self.header)
91
Piotr Sikora6ae67df2015-11-23 18:46:33 -080092 crypto_files = files['crypto'] + self.ExtraFiles()
93 self.PrintVariableSection(makefile, 'crypto_sources', crypto_files)
Adam Langley9e1a6602015-05-05 17:47:53 -070094 self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
95 self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
96
97 for ((osname, arch), asm_files) in asm_outputs:
98 self.PrintVariableSection(
99 makefile, '%s_%s_sources' % (osname, arch), asm_files)
100
101
Adam Langley049ef412015-06-09 18:20:57 -0700102class AndroidStandalone(Android):
103 """AndroidStandalone is for Android builds outside of the Android-system, i.e.
104
105 for applications that wish wish to ship BoringSSL.
106 """
107
108 def ExtraFiles(self):
109 return []
110
111
112class Bazel(object):
113 """Bazel outputs files suitable for including in Bazel files."""
114
115 def __init__(self):
116 self.firstSection = True
117 self.header = \
118"""# This file is created by generate_build_files.py. Do not edit manually.
119
120"""
121
122 def PrintVariableSection(self, out, name, files):
123 if not self.firstSection:
124 out.write('\n')
125 self.firstSection = False
126
127 out.write('%s = [\n' % name)
128 for f in sorted(files):
Matt Braithwaite16695892016-06-09 09:34:11 -0700129 out.write(' "%s",\n' % PathOf(f))
Adam Langley049ef412015-06-09 18:20:57 -0700130 out.write(']\n')
131
132 def WriteFiles(self, files, asm_outputs):
Chuck Haysc608d6b2015-10-06 17:54:16 -0700133 with open('BUILD.generated.bzl', 'w+') as out:
Adam Langley049ef412015-06-09 18:20:57 -0700134 out.write(self.header)
135
136 self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
137 self.PrintVariableSection(
138 out, 'ssl_internal_headers', files['ssl_internal_headers'])
139 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
140 self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
141 self.PrintVariableSection(
142 out, 'crypto_internal_headers', files['crypto_internal_headers'])
143 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
144 self.PrintVariableSection(out, 'tool_sources', files['tool'])
145
146 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700147 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700148 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700149
Chuck Haysc608d6b2015-10-06 17:54:16 -0700150 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700151 out.write(self.header)
152
153 out.write('test_support_sources = [\n')
154 for filename in files['test_support']:
155 if os.path.basename(filename) == 'malloc.cc':
156 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700157 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700158
Chuck Haysc608d6b2015-10-06 17:54:16 -0700159 out.write(']\n\n')
160
161 out.write('def create_tests(copts):\n')
162 out.write(' test_support_sources_complete = test_support_sources + \\\n')
Matt Braithwaite16695892016-06-09 09:34:11 -0700163 out.write(' native.glob(["%s"])\n' % PathOf("src/crypto/test/*.h"))
Adam Langley9c164b22015-06-10 18:54:47 -0700164 name_counts = {}
165 for test in files['tests']:
166 name = os.path.basename(test[0])
167 name_counts[name] = name_counts.get(name, 0) + 1
168
169 first = True
170 for test in files['tests']:
171 name = os.path.basename(test[0])
172 if name_counts[name] > 1:
173 if '/' in test[1]:
174 name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
175 else:
176 name += '_' + test[1].replace('-', '_')
177
178 if not first:
179 out.write('\n')
180 first = False
181
182 src_prefix = 'src/' + test[0]
183 for src in files['test']:
184 if src.startswith(src_prefix):
185 src = src
186 break
187 else:
188 raise ValueError("Can't find source for %s" % test[0])
189
Chuck Haysc608d6b2015-10-06 17:54:16 -0700190 out.write(' native.cc_test(\n')
191 out.write(' name = "%s",\n' % name)
192 out.write(' size = "small",\n')
Matt Braithwaite16695892016-06-09 09:34:11 -0700193 out.write(' srcs = ["%s"] + test_support_sources_complete,\n' %
194 PathOf(src))
Adam Langley9c164b22015-06-10 18:54:47 -0700195
196 data_files = []
197 if len(test) > 1:
198
Chuck Haysc608d6b2015-10-06 17:54:16 -0700199 out.write(' args = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700200 for arg in test[1:]:
201 if '/' in arg:
Matt Braithwaite16695892016-06-09 09:34:11 -0700202 out.write(' "$(location %s)",\n' %
203 PathOf(os.path.join('src', arg)))
Adam Langley9c164b22015-06-10 18:54:47 -0700204 data_files.append('src/%s' % arg)
205 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700206 out.write(' "%s",\n' % arg)
207 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700208
Chuck Haysc608d6b2015-10-06 17:54:16 -0700209 out.write(' copts = copts,\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700210
211 if len(data_files) > 0:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700212 out.write(' data = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700213 for filename in data_files:
Matt Braithwaite16695892016-06-09 09:34:11 -0700214 out.write(' "%s",\n' % PathOf(filename))
Chuck Haysc608d6b2015-10-06 17:54:16 -0700215 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700216
217 if 'ssl/' in test[0]:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700218 out.write(' deps = [\n')
219 out.write(' ":crypto",\n')
220 out.write(' ":ssl",\n')
221 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700222 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700223 out.write(' deps = [":crypto"],\n')
224 out.write(' )\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700225
Adam Langley049ef412015-06-09 18:20:57 -0700226
David Benjamin38d01c62016-04-21 18:47:57 -0400227class GN(object):
228
229 def __init__(self):
230 self.firstSection = True
231 self.header = \
232"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
233# Use of this source code is governed by a BSD-style license that can be
234# found in the LICENSE file.
235
236# This file is created by generate_build_files.py. Do not edit manually.
237
238"""
239
240 def PrintVariableSection(self, out, name, files):
241 if not self.firstSection:
242 out.write('\n')
243 self.firstSection = False
244
245 out.write('%s = [\n' % name)
246 for f in sorted(files):
247 out.write(' "%s",\n' % f)
248 out.write(']\n')
249
250 def WriteFiles(self, files, asm_outputs):
251 with open('BUILD.generated.gni', 'w+') as out:
252 out.write(self.header)
253
254 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
255 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
256
257 for ((osname, arch), asm_files) in asm_outputs:
258 self.PrintVariableSection(
259 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
260
261 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
262 for fuzzer in files['fuzz']]
263 self.PrintVariableSection(out, 'fuzzers', fuzzers)
264
265 with open('BUILD.generated_tests.gni', 'w+') as out:
266 self.firstSection = True
267 out.write(self.header)
268
269 self.PrintVariableSection(out, '_test_support_sources',
270 files['test_support'])
271 out.write('\n')
272
273 out.write('template("create_tests") {\n')
274
275 all_tests = []
276 for test in sorted(files['test']):
277 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
278 all_tests.append(test_name)
279
280 out.write(' executable("%s") {\n' % test_name)
281 out.write(' sources = [\n')
282 out.write(' "%s",\n' % test)
283 out.write(' ]\n')
284 out.write(' sources += _test_support_sources\n')
David Benjaminb3be1cf2016-04-27 19:15:06 -0400285 out.write(' if (defined(invoker.configs_exclude)) {\n')
286 out.write(' configs -= invoker.configs_exclude\n')
287 out.write(' }\n')
David Benjamin38d01c62016-04-21 18:47:57 -0400288 out.write(' configs += invoker.configs\n')
289 out.write(' deps = invoker.deps\n')
290 out.write(' }\n')
291 out.write('\n')
292
293 out.write(' group(target_name) {\n')
294 out.write(' deps = [\n')
295 for test_name in sorted(all_tests):
296 out.write(' ":%s",\n' % test_name)
297 out.write(' ]\n')
298 out.write(' }\n')
299 out.write('}\n')
300
301
302class GYP(object):
303
304 def __init__(self):
305 self.header = \
306"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
307# Use of this source code is governed by a BSD-style license that can be
308# found in the LICENSE file.
309
310# This file is created by generate_build_files.py. Do not edit manually.
311
312"""
313
314 def PrintVariableSection(self, out, name, files):
315 out.write(' \'%s\': [\n' % name)
316 for f in sorted(files):
317 out.write(' \'%s\',\n' % f)
318 out.write(' ],\n')
319
320 def WriteFiles(self, files, asm_outputs):
321 with open('boringssl.gypi', 'w+') as gypi:
322 gypi.write(self.header + '{\n \'variables\': {\n')
323
324 self.PrintVariableSection(
325 gypi, 'boringssl_ssl_sources', files['ssl'])
326 self.PrintVariableSection(
327 gypi, 'boringssl_crypto_sources', files['crypto'])
328
329 for ((osname, arch), asm_files) in asm_outputs:
330 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
331 (osname, arch), asm_files)
332
333 gypi.write(' }\n}\n')
334
335 with open('boringssl_tests.gypi', 'w+') as test_gypi:
336 test_gypi.write(self.header + '{\n \'targets\': [\n')
337
338 test_names = []
339 for test in sorted(files['test']):
340 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
341 test_gypi.write(""" {
342 'target_name': '%s',
343 'type': 'executable',
344 'dependencies': [
345 'boringssl.gyp:boringssl',
346 ],
347 'sources': [
348 '%s',
349 '<@(boringssl_test_support_sources)',
350 ],
351 # TODO(davidben): Fix size_t truncations in BoringSSL.
352 # https://crbug.com/429039
353 'msvs_disabled_warnings': [ 4267, ],
354 },\n""" % (test_name, test))
355 test_names.append(test_name)
356
357 test_names.sort()
358
359 test_gypi.write(' ],\n \'variables\': {\n')
360
361 self.PrintVariableSection(
362 test_gypi, 'boringssl_test_support_sources', files['test_support'])
363
364 test_gypi.write(' \'boringssl_test_targets\': [\n')
365
366 for test in sorted(test_names):
367 test_gypi.write(""" '%s',\n""" % test)
368
369 test_gypi.write(' ],\n }\n}\n')
370
371
Adam Langley9e1a6602015-05-05 17:47:53 -0700372def FindCMakeFiles(directory):
373 """Returns list of all CMakeLists.txt files recursively in directory."""
374 cmakefiles = []
375
376 for (path, _, filenames) in os.walk(directory):
377 for filename in filenames:
378 if filename == 'CMakeLists.txt':
379 cmakefiles.append(os.path.join(path, filename))
380
381 return cmakefiles
382
383
384def NoTests(dent, is_dir):
385 """Filter function that can be passed to FindCFiles in order to remove test
386 sources."""
387 if is_dir:
388 return dent != 'test'
389 return 'test.' not in dent and not dent.startswith('example_')
390
391
392def OnlyTests(dent, is_dir):
393 """Filter function that can be passed to FindCFiles in order to remove
394 non-test sources."""
395 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400396 return dent != 'test'
Adam Langley9e1a6602015-05-05 17:47:53 -0700397 return '_test.' in dent or dent.startswith('example_')
398
399
David Benjamin26073832015-05-11 20:52:48 -0400400def AllFiles(dent, is_dir):
401 """Filter function that can be passed to FindCFiles in order to include all
402 sources."""
403 return True
404
405
Adam Langley049ef412015-06-09 18:20:57 -0700406def SSLHeaderFiles(dent, is_dir):
407 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h']
408
409
Adam Langley9e1a6602015-05-05 17:47:53 -0700410def FindCFiles(directory, filter_func):
411 """Recurses through directory and returns a list of paths to all the C source
412 files that pass filter_func."""
413 cfiles = []
414
415 for (path, dirnames, filenames) in os.walk(directory):
416 for filename in filenames:
417 if not filename.endswith('.c') and not filename.endswith('.cc'):
418 continue
419 if not filter_func(filename, False):
420 continue
421 cfiles.append(os.path.join(path, filename))
422
423 for (i, dirname) in enumerate(dirnames):
424 if not filter_func(dirname, True):
425 del dirnames[i]
426
427 return cfiles
428
429
Adam Langley049ef412015-06-09 18:20:57 -0700430def FindHeaderFiles(directory, filter_func):
431 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
432 hfiles = []
433
434 for (path, dirnames, filenames) in os.walk(directory):
435 for filename in filenames:
436 if not filename.endswith('.h'):
437 continue
438 if not filter_func(filename, False):
439 continue
440 hfiles.append(os.path.join(path, filename))
441
442 return hfiles
443
444
Adam Langley9e1a6602015-05-05 17:47:53 -0700445def ExtractPerlAsmFromCMakeFile(cmakefile):
446 """Parses the contents of the CMakeLists.txt file passed as an argument and
447 returns a list of all the perlasm() directives found in the file."""
448 perlasms = []
449 with open(cmakefile) as f:
450 for line in f:
451 line = line.strip()
452 if not line.startswith('perlasm('):
453 continue
454 if not line.endswith(')'):
455 raise ValueError('Bad perlasm line in %s' % cmakefile)
456 # Remove "perlasm(" from start and ")" from end
457 params = line[8:-1].split()
458 if len(params) < 2:
459 raise ValueError('Bad perlasm line in %s' % cmakefile)
460 perlasms.append({
461 'extra_args': params[2:],
462 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
463 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
464 })
465
466 return perlasms
467
468
469def ReadPerlAsmOperations():
470 """Returns a list of all perlasm() directives found in CMake config files in
471 src/."""
472 perlasms = []
473 cmakefiles = FindCMakeFiles('src')
474
475 for cmakefile in cmakefiles:
476 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
477
478 return perlasms
479
480
481def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
482 """Runs the a perlasm script and puts the output into output_filename."""
483 base_dir = os.path.dirname(output_filename)
484 if not os.path.isdir(base_dir):
485 os.makedirs(base_dir)
486 output = subprocess.check_output(
487 ['perl', input_filename, perlasm_style] + extra_args)
488 with open(output_filename, 'w+') as out_file:
489 out_file.write(output)
490
491
492def ArchForAsmFilename(filename):
493 """Returns the architectures that a given asm file should be compiled for
494 based on substrings in the filename."""
495
496 if 'x86_64' in filename or 'avx2' in filename:
497 return ['x86_64']
498 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
499 return ['x86']
500 elif 'armx' in filename:
501 return ['arm', 'aarch64']
502 elif 'armv8' in filename:
503 return ['aarch64']
504 elif 'arm' in filename:
505 return ['arm']
506 else:
507 raise ValueError('Unknown arch for asm filename: ' + filename)
508
509
510def WriteAsmFiles(perlasms):
511 """Generates asm files from perlasm directives for each supported OS x
512 platform combination."""
513 asmfiles = {}
514
515 for osarch in OS_ARCH_COMBOS:
516 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
517 key = (osname, arch)
518 outDir = '%s-%s' % key
519
520 for perlasm in perlasms:
521 filename = os.path.basename(perlasm['input'])
522 output = perlasm['output']
523 if not output.startswith('src'):
524 raise ValueError('output missing src: %s' % output)
525 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200526 if output.endswith('-armx.${ASM_EXT}'):
527 output = output.replace('-armx',
528 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700529 output = output.replace('${ASM_EXT}', asm_ext)
530
531 if arch in ArchForAsmFilename(filename):
532 PerlAsm(output, perlasm['input'], perlasm_style,
533 perlasm['extra_args'] + extra_args)
534 asmfiles.setdefault(key, []).append(output)
535
536 for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
537 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
538
539 return asmfiles
540
541
Adam Langley049ef412015-06-09 18:20:57 -0700542def main(platforms):
Adam Langley9e1a6602015-05-05 17:47:53 -0700543 crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
544 ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400545 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langley9e1a6602015-05-05 17:47:53 -0700546
547 # Generate err_data.c
548 with open('err_data.c', 'w+') as err_data:
549 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
550 cwd=os.path.join('src', 'crypto', 'err'),
551 stdout=err_data)
552 crypto_c_files.append('err_data.c')
553
David Benjamin38d01c62016-04-21 18:47:57 -0400554 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
555 AllFiles)
David Benjamin26073832015-05-11 20:52:48 -0400556
Adam Langley9e1a6602015-05-05 17:47:53 -0700557 test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
558 test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
559
David Benjamin38d01c62016-04-21 18:47:57 -0400560 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
561
Adam Langley049ef412015-06-09 18:20:57 -0700562 ssl_h_files = (
563 FindHeaderFiles(
564 os.path.join('src', 'include', 'openssl'),
565 SSLHeaderFiles))
566
567 def NotSSLHeaderFiles(filename, is_dir):
568 return not SSLHeaderFiles(filename, is_dir)
569 crypto_h_files = (
570 FindHeaderFiles(
571 os.path.join('src', 'include', 'openssl'),
572 NotSSLHeaderFiles))
573
574 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
575 crypto_internal_h_files = FindHeaderFiles(
576 os.path.join('src', 'crypto'), NoTests)
577
Adam Langley9c164b22015-06-10 18:54:47 -0700578 with open('src/util/all_tests.json', 'r') as f:
579 tests = json.load(f)
David Benjaminf277add2016-03-09 14:38:24 -0500580 # Skip tests for libdecrepit. Consumers import that manually.
581 tests = [test for test in tests if not test[0].startswith("decrepit/")]
Adam Langley9c164b22015-06-10 18:54:47 -0700582 test_binaries = set([test[0] for test in tests])
583 test_sources = set([
584 test.replace('.cc', '').replace('.c', '').replace(
585 'src/',
586 '')
587 for test in test_c_files])
588 if test_binaries != test_sources:
589 print 'Test sources and configured tests do not match'
590 a = test_binaries.difference(test_sources)
591 if len(a) > 0:
592 print 'These tests are configured without sources: ' + str(a)
593 b = test_sources.difference(test_binaries)
594 if len(b) > 0:
595 print 'These test sources are not configured: ' + str(b)
596
Adam Langley9e1a6602015-05-05 17:47:53 -0700597 files = {
598 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700599 'crypto_headers': crypto_h_files,
600 'crypto_internal_headers': crypto_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400601 'fuzz': fuzz_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700602 'ssl': ssl_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700603 'ssl_headers': ssl_h_files,
604 'ssl_internal_headers': ssl_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400605 'tool': tool_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700606 'test': test_c_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400607 'test_support': test_support_c_files,
Adam Langley9c164b22015-06-10 18:54:47 -0700608 'tests': tests,
Adam Langley9e1a6602015-05-05 17:47:53 -0700609 }
610
611 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
612
Adam Langley049ef412015-06-09 18:20:57 -0700613 for platform in platforms:
614 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700615
616 return 0
617
618
Adam Langley9e1a6602015-05-05 17:47:53 -0700619if __name__ == '__main__':
Matt Braithwaite16695892016-06-09 09:34:11 -0700620 parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]'
621 ' [android|android-standalone|bazel|gn|gyp]')
622 parser.add_option('--prefix', dest='prefix',
623 help='For Bazel, prepend argument to all source files')
624 options, args = parser.parse_args(sys.argv[1:])
625 PREFIX = options.prefix
626
627 if not args:
628 parser.print_help()
629 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700630
Adam Langley049ef412015-06-09 18:20:57 -0700631 platforms = []
Matt Braithwaite16695892016-06-09 09:34:11 -0700632 for s in args:
David Benjamin38d01c62016-04-21 18:47:57 -0400633 if s == 'android':
Adam Langley049ef412015-06-09 18:20:57 -0700634 platforms.append(Android())
635 elif s == 'android-standalone':
636 platforms.append(AndroidStandalone())
637 elif s == 'bazel':
638 platforms.append(Bazel())
David Benjamin38d01c62016-04-21 18:47:57 -0400639 elif s == 'gn':
640 platforms.append(GN())
641 elif s == 'gyp':
642 platforms.append(GYP())
Adam Langley049ef412015-06-09 18:20:57 -0700643 else:
Matt Braithwaite16695892016-06-09 09:34:11 -0700644 parser.print_help()
645 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700646
Adam Langley049ef412015-06-09 18:20:57 -0700647 sys.exit(main(platforms))