blob: 0efd0cc022f3cb138142c47aa609b56ce85fa437 [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'])
Adam Langleyf11f2332016-06-30 11:56:19 -0700145 self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
Adam Langley049ef412015-06-09 18:20:57 -0700146
147 for ((osname, arch), asm_files) in asm_outputs:
Adam Langley049ef412015-06-09 18:20:57 -0700148 self.PrintVariableSection(
Piotr Sikora3f5fe602015-10-28 12:24:35 -0700149 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
Adam Langley049ef412015-06-09 18:20:57 -0700150
Chuck Haysc608d6b2015-10-06 17:54:16 -0700151 with open('BUILD.generated_tests.bzl', 'w+') as out:
Adam Langley9c164b22015-06-10 18:54:47 -0700152 out.write(self.header)
153
154 out.write('test_support_sources = [\n')
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700155 for filename in (files['test_support'] +
156 files['crypto_internal_headers'] +
157 files['ssl_internal_headers']):
Adam Langley9c164b22015-06-10 18:54:47 -0700158 if os.path.basename(filename) == 'malloc.cc':
159 continue
Matt Braithwaite16695892016-06-09 09:34:11 -0700160 out.write(' "%s",\n' % PathOf(filename))
Adam Langley9c164b22015-06-10 18:54:47 -0700161
Chuck Haysc608d6b2015-10-06 17:54:16 -0700162 out.write(']\n\n')
163
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700164 out.write('def create_tests(copts, crypto, ssl):\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700165 name_counts = {}
166 for test in files['tests']:
167 name = os.path.basename(test[0])
168 name_counts[name] = name_counts.get(name, 0) + 1
169
170 first = True
171 for test in files['tests']:
172 name = os.path.basename(test[0])
173 if name_counts[name] > 1:
174 if '/' in test[1]:
175 name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
176 else:
177 name += '_' + test[1].replace('-', '_')
178
179 if not first:
180 out.write('\n')
181 first = False
182
183 src_prefix = 'src/' + test[0]
184 for src in files['test']:
185 if src.startswith(src_prefix):
186 src = src
187 break
188 else:
189 raise ValueError("Can't find source for %s" % test[0])
190
Chuck Haysc608d6b2015-10-06 17:54:16 -0700191 out.write(' native.cc_test(\n')
192 out.write(' name = "%s",\n' % name)
193 out.write(' size = "small",\n')
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700194 out.write(' srcs = ["%s"] + test_support_sources,\n' %
Matt Braithwaite16695892016-06-09 09:34:11 -0700195 PathOf(src))
Adam Langley9c164b22015-06-10 18:54:47 -0700196
197 data_files = []
198 if len(test) > 1:
199
Chuck Haysc608d6b2015-10-06 17:54:16 -0700200 out.write(' args = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700201 for arg in test[1:]:
202 if '/' in arg:
Matt Braithwaite16695892016-06-09 09:34:11 -0700203 out.write(' "$(location %s)",\n' %
204 PathOf(os.path.join('src', arg)))
Adam Langley9c164b22015-06-10 18:54:47 -0700205 data_files.append('src/%s' % arg)
206 else:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700207 out.write(' "%s",\n' % arg)
208 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700209
Chuck Haysc608d6b2015-10-06 17:54:16 -0700210 out.write(' copts = copts,\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700211
212 if len(data_files) > 0:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700213 out.write(' data = [\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700214 for filename in data_files:
Matt Braithwaite16695892016-06-09 09:34:11 -0700215 out.write(' "%s",\n' % PathOf(filename))
Chuck Haysc608d6b2015-10-06 17:54:16 -0700216 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700217
218 if 'ssl/' in test[0]:
Chuck Haysc608d6b2015-10-06 17:54:16 -0700219 out.write(' deps = [\n')
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700220 out.write(' crypto,\n')
221 out.write(' ssl,\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700222 out.write(' ],\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700223 else:
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700224 out.write(' deps = [crypto],\n')
Chuck Haysc608d6b2015-10-06 17:54:16 -0700225 out.write(' )\n')
Adam Langley9c164b22015-06-10 18:54:47 -0700226
Adam Langley049ef412015-06-09 18:20:57 -0700227
David Benjamin38d01c62016-04-21 18:47:57 -0400228class GN(object):
229
230 def __init__(self):
231 self.firstSection = True
232 self.header = \
233"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
234# Use of this source code is governed by a BSD-style license that can be
235# found in the LICENSE file.
236
237# This file is created by generate_build_files.py. Do not edit manually.
238
239"""
240
241 def PrintVariableSection(self, out, name, files):
242 if not self.firstSection:
243 out.write('\n')
244 self.firstSection = False
245
246 out.write('%s = [\n' % name)
247 for f in sorted(files):
248 out.write(' "%s",\n' % f)
249 out.write(']\n')
250
251 def WriteFiles(self, files, asm_outputs):
252 with open('BUILD.generated.gni', 'w+') as out:
253 out.write(self.header)
254
255 self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
256 self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
257
258 for ((osname, arch), asm_files) in asm_outputs:
259 self.PrintVariableSection(
260 out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
261
262 fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
263 for fuzzer in files['fuzz']]
264 self.PrintVariableSection(out, 'fuzzers', fuzzers)
265
266 with open('BUILD.generated_tests.gni', 'w+') as out:
267 self.firstSection = True
268 out.write(self.header)
269
270 self.PrintVariableSection(out, '_test_support_sources',
271 files['test_support'])
272 out.write('\n')
273
274 out.write('template("create_tests") {\n')
275
276 all_tests = []
277 for test in sorted(files['test']):
278 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
279 all_tests.append(test_name)
280
281 out.write(' executable("%s") {\n' % test_name)
282 out.write(' sources = [\n')
283 out.write(' "%s",\n' % test)
284 out.write(' ]\n')
285 out.write(' sources += _test_support_sources\n')
David Benjaminb3be1cf2016-04-27 19:15:06 -0400286 out.write(' if (defined(invoker.configs_exclude)) {\n')
287 out.write(' configs -= invoker.configs_exclude\n')
288 out.write(' }\n')
David Benjamin38d01c62016-04-21 18:47:57 -0400289 out.write(' configs += invoker.configs\n')
290 out.write(' deps = invoker.deps\n')
291 out.write(' }\n')
292 out.write('\n')
293
294 out.write(' group(target_name) {\n')
295 out.write(' deps = [\n')
296 for test_name in sorted(all_tests):
297 out.write(' ":%s",\n' % test_name)
298 out.write(' ]\n')
299 out.write(' }\n')
300 out.write('}\n')
301
302
303class GYP(object):
304
305 def __init__(self):
306 self.header = \
307"""# Copyright (c) 2016 The Chromium Authors. All rights reserved.
308# Use of this source code is governed by a BSD-style license that can be
309# found in the LICENSE file.
310
311# This file is created by generate_build_files.py. Do not edit manually.
312
313"""
314
315 def PrintVariableSection(self, out, name, files):
316 out.write(' \'%s\': [\n' % name)
317 for f in sorted(files):
318 out.write(' \'%s\',\n' % f)
319 out.write(' ],\n')
320
321 def WriteFiles(self, files, asm_outputs):
322 with open('boringssl.gypi', 'w+') as gypi:
323 gypi.write(self.header + '{\n \'variables\': {\n')
324
325 self.PrintVariableSection(
326 gypi, 'boringssl_ssl_sources', files['ssl'])
327 self.PrintVariableSection(
328 gypi, 'boringssl_crypto_sources', files['crypto'])
329
330 for ((osname, arch), asm_files) in asm_outputs:
331 self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
332 (osname, arch), asm_files)
333
334 gypi.write(' }\n}\n')
335
336 with open('boringssl_tests.gypi', 'w+') as test_gypi:
337 test_gypi.write(self.header + '{\n \'targets\': [\n')
338
339 test_names = []
340 for test in sorted(files['test']):
341 test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
342 test_gypi.write(""" {
343 'target_name': '%s',
344 'type': 'executable',
345 'dependencies': [
346 'boringssl.gyp:boringssl',
347 ],
348 'sources': [
349 '%s',
350 '<@(boringssl_test_support_sources)',
351 ],
352 # TODO(davidben): Fix size_t truncations in BoringSSL.
353 # https://crbug.com/429039
354 'msvs_disabled_warnings': [ 4267, ],
355 },\n""" % (test_name, test))
356 test_names.append(test_name)
357
358 test_names.sort()
359
360 test_gypi.write(' ],\n \'variables\': {\n')
361
362 self.PrintVariableSection(
363 test_gypi, 'boringssl_test_support_sources', files['test_support'])
364
365 test_gypi.write(' \'boringssl_test_targets\': [\n')
366
367 for test in sorted(test_names):
368 test_gypi.write(""" '%s',\n""" % test)
369
370 test_gypi.write(' ],\n }\n}\n')
371
372
Adam Langley9e1a6602015-05-05 17:47:53 -0700373def FindCMakeFiles(directory):
374 """Returns list of all CMakeLists.txt files recursively in directory."""
375 cmakefiles = []
376
377 for (path, _, filenames) in os.walk(directory):
378 for filename in filenames:
379 if filename == 'CMakeLists.txt':
380 cmakefiles.append(os.path.join(path, filename))
381
382 return cmakefiles
383
384
385def NoTests(dent, is_dir):
386 """Filter function that can be passed to FindCFiles in order to remove test
387 sources."""
388 if is_dir:
389 return dent != 'test'
390 return 'test.' not in dent and not dent.startswith('example_')
391
392
393def OnlyTests(dent, is_dir):
394 """Filter function that can be passed to FindCFiles in order to remove
395 non-test sources."""
396 if is_dir:
David Benjamin26073832015-05-11 20:52:48 -0400397 return dent != 'test'
Adam Langley9e1a6602015-05-05 17:47:53 -0700398 return '_test.' in dent or dent.startswith('example_')
399
400
David Benjamin26073832015-05-11 20:52:48 -0400401def AllFiles(dent, is_dir):
402 """Filter function that can be passed to FindCFiles in order to include all
403 sources."""
404 return True
405
406
Adam Langley049ef412015-06-09 18:20:57 -0700407def SSLHeaderFiles(dent, is_dir):
408 return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h']
409
410
Adam Langley9e1a6602015-05-05 17:47:53 -0700411def FindCFiles(directory, filter_func):
412 """Recurses through directory and returns a list of paths to all the C source
413 files that pass filter_func."""
414 cfiles = []
415
416 for (path, dirnames, filenames) in os.walk(directory):
417 for filename in filenames:
418 if not filename.endswith('.c') and not filename.endswith('.cc'):
419 continue
420 if not filter_func(filename, False):
421 continue
422 cfiles.append(os.path.join(path, filename))
423
424 for (i, dirname) in enumerate(dirnames):
425 if not filter_func(dirname, True):
426 del dirnames[i]
427
428 return cfiles
429
430
Adam Langley049ef412015-06-09 18:20:57 -0700431def FindHeaderFiles(directory, filter_func):
432 """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
433 hfiles = []
434
435 for (path, dirnames, filenames) in os.walk(directory):
436 for filename in filenames:
437 if not filename.endswith('.h'):
438 continue
439 if not filter_func(filename, False):
440 continue
441 hfiles.append(os.path.join(path, filename))
442
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700443 for (i, dirname) in enumerate(dirnames):
444 if not filter_func(dirname, True):
445 del dirnames[i]
446
Adam Langley049ef412015-06-09 18:20:57 -0700447 return hfiles
448
449
Adam Langley9e1a6602015-05-05 17:47:53 -0700450def ExtractPerlAsmFromCMakeFile(cmakefile):
451 """Parses the contents of the CMakeLists.txt file passed as an argument and
452 returns a list of all the perlasm() directives found in the file."""
453 perlasms = []
454 with open(cmakefile) as f:
455 for line in f:
456 line = line.strip()
457 if not line.startswith('perlasm('):
458 continue
459 if not line.endswith(')'):
460 raise ValueError('Bad perlasm line in %s' % cmakefile)
461 # Remove "perlasm(" from start and ")" from end
462 params = line[8:-1].split()
463 if len(params) < 2:
464 raise ValueError('Bad perlasm line in %s' % cmakefile)
465 perlasms.append({
466 'extra_args': params[2:],
467 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
468 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
469 })
470
471 return perlasms
472
473
474def ReadPerlAsmOperations():
475 """Returns a list of all perlasm() directives found in CMake config files in
476 src/."""
477 perlasms = []
478 cmakefiles = FindCMakeFiles('src')
479
480 for cmakefile in cmakefiles:
481 perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
482
483 return perlasms
484
485
486def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
487 """Runs the a perlasm script and puts the output into output_filename."""
488 base_dir = os.path.dirname(output_filename)
489 if not os.path.isdir(base_dir):
490 os.makedirs(base_dir)
David Benjaminfdd8e9c2016-06-26 13:18:50 -0400491 subprocess.check_call(
492 ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
Adam Langley9e1a6602015-05-05 17:47:53 -0700493
494
495def ArchForAsmFilename(filename):
496 """Returns the architectures that a given asm file should be compiled for
497 based on substrings in the filename."""
498
499 if 'x86_64' in filename or 'avx2' in filename:
500 return ['x86_64']
501 elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
502 return ['x86']
503 elif 'armx' in filename:
504 return ['arm', 'aarch64']
505 elif 'armv8' in filename:
506 return ['aarch64']
507 elif 'arm' in filename:
508 return ['arm']
509 else:
510 raise ValueError('Unknown arch for asm filename: ' + filename)
511
512
513def WriteAsmFiles(perlasms):
514 """Generates asm files from perlasm directives for each supported OS x
515 platform combination."""
516 asmfiles = {}
517
518 for osarch in OS_ARCH_COMBOS:
519 (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
520 key = (osname, arch)
521 outDir = '%s-%s' % key
522
523 for perlasm in perlasms:
524 filename = os.path.basename(perlasm['input'])
525 output = perlasm['output']
526 if not output.startswith('src'):
527 raise ValueError('output missing src: %s' % output)
528 output = os.path.join(outDir, output[4:])
William Hessec618c402015-06-22 16:34:02 +0200529 if output.endswith('-armx.${ASM_EXT}'):
530 output = output.replace('-armx',
531 '-armx64' if arch == 'aarch64' else '-armx32')
Adam Langley9e1a6602015-05-05 17:47:53 -0700532 output = output.replace('${ASM_EXT}', asm_ext)
533
534 if arch in ArchForAsmFilename(filename):
535 PerlAsm(output, perlasm['input'], perlasm_style,
536 perlasm['extra_args'] + extra_args)
537 asmfiles.setdefault(key, []).append(output)
538
539 for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
540 asmfiles.setdefault(key, []).extend(non_perl_asm_files)
541
542 return asmfiles
543
544
Adam Langley049ef412015-06-09 18:20:57 -0700545def main(platforms):
Adam Langley9e1a6602015-05-05 17:47:53 -0700546 crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
547 ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
David Benjamin38d01c62016-04-21 18:47:57 -0400548 tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
Adam Langleyf11f2332016-06-30 11:56:19 -0700549 tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
Adam Langley9e1a6602015-05-05 17:47:53 -0700550
551 # Generate err_data.c
552 with open('err_data.c', 'w+') as err_data:
553 subprocess.check_call(['go', 'run', 'err_data_generate.go'],
554 cwd=os.path.join('src', 'crypto', 'err'),
555 stdout=err_data)
556 crypto_c_files.append('err_data.c')
557
David Benjamin38d01c62016-04-21 18:47:57 -0400558 test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
559 AllFiles)
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700560 test_support_h_files = (
561 FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
562 FindHeaderFiles(os.path.join('src', 'ssl', 'test'), AllFiles))
David Benjamin26073832015-05-11 20:52:48 -0400563
Adam Langley9e1a6602015-05-05 17:47:53 -0700564 test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
565 test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
566
David Benjamin38d01c62016-04-21 18:47:57 -0400567 fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
568
Adam Langley049ef412015-06-09 18:20:57 -0700569 ssl_h_files = (
570 FindHeaderFiles(
571 os.path.join('src', 'include', 'openssl'),
572 SSLHeaderFiles))
573
574 def NotSSLHeaderFiles(filename, is_dir):
575 return not SSLHeaderFiles(filename, is_dir)
576 crypto_h_files = (
577 FindHeaderFiles(
578 os.path.join('src', 'include', 'openssl'),
579 NotSSLHeaderFiles))
580
581 ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
582 crypto_internal_h_files = FindHeaderFiles(
583 os.path.join('src', 'crypto'), NoTests)
584
Adam Langley9c164b22015-06-10 18:54:47 -0700585 with open('src/util/all_tests.json', 'r') as f:
586 tests = json.load(f)
David Benjaminf277add2016-03-09 14:38:24 -0500587 # Skip tests for libdecrepit. Consumers import that manually.
588 tests = [test for test in tests if not test[0].startswith("decrepit/")]
Adam Langley9c164b22015-06-10 18:54:47 -0700589 test_binaries = set([test[0] for test in tests])
590 test_sources = set([
591 test.replace('.cc', '').replace('.c', '').replace(
592 'src/',
593 '')
594 for test in test_c_files])
595 if test_binaries != test_sources:
596 print 'Test sources and configured tests do not match'
597 a = test_binaries.difference(test_sources)
598 if len(a) > 0:
599 print 'These tests are configured without sources: ' + str(a)
600 b = test_sources.difference(test_binaries)
601 if len(b) > 0:
602 print 'These test sources are not configured: ' + str(b)
603
Adam Langley9e1a6602015-05-05 17:47:53 -0700604 files = {
605 'crypto': crypto_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700606 'crypto_headers': crypto_h_files,
607 'crypto_internal_headers': crypto_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400608 'fuzz': fuzz_c_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700609 'ssl': ssl_c_files,
Adam Langley049ef412015-06-09 18:20:57 -0700610 'ssl_headers': ssl_h_files,
611 'ssl_internal_headers': ssl_internal_h_files,
David Benjamin38d01c62016-04-21 18:47:57 -0400612 'tool': tool_c_files,
Adam Langleyf11f2332016-06-30 11:56:19 -0700613 'tool_headers': tool_h_files,
Adam Langley9e1a6602015-05-05 17:47:53 -0700614 'test': test_c_files,
Matt Braithwaitedfdd49c2016-06-13 17:06:48 -0700615 'test_support': test_support_h_files + test_support_c_files,
Adam Langley9c164b22015-06-10 18:54:47 -0700616 'tests': tests,
Adam Langley9e1a6602015-05-05 17:47:53 -0700617 }
618
619 asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
620
Adam Langley049ef412015-06-09 18:20:57 -0700621 for platform in platforms:
622 platform.WriteFiles(files, asm_outputs)
Adam Langley9e1a6602015-05-05 17:47:53 -0700623
624 return 0
625
626
Adam Langley9e1a6602015-05-05 17:47:53 -0700627if __name__ == '__main__':
Matt Braithwaite16695892016-06-09 09:34:11 -0700628 parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]'
629 ' [android|android-standalone|bazel|gn|gyp]')
630 parser.add_option('--prefix', dest='prefix',
631 help='For Bazel, prepend argument to all source files')
632 options, args = parser.parse_args(sys.argv[1:])
633 PREFIX = options.prefix
634
635 if not args:
636 parser.print_help()
637 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700638
Adam Langley049ef412015-06-09 18:20:57 -0700639 platforms = []
Matt Braithwaite16695892016-06-09 09:34:11 -0700640 for s in args:
David Benjamin38d01c62016-04-21 18:47:57 -0400641 if s == 'android':
Adam Langley049ef412015-06-09 18:20:57 -0700642 platforms.append(Android())
643 elif s == 'android-standalone':
644 platforms.append(AndroidStandalone())
645 elif s == 'bazel':
646 platforms.append(Bazel())
David Benjamin38d01c62016-04-21 18:47:57 -0400647 elif s == 'gn':
648 platforms.append(GN())
649 elif s == 'gyp':
650 platforms.append(GYP())
Adam Langley049ef412015-06-09 18:20:57 -0700651 else:
Matt Braithwaite16695892016-06-09 09:34:11 -0700652 parser.print_help()
653 sys.exit(1)
Adam Langley9e1a6602015-05-05 17:47:53 -0700654
Adam Langley049ef412015-06-09 18:20:57 -0700655 sys.exit(main(platforms))