You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

737 lines
24 KiB

  1. # 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. """Enumerates source files for consumption by various build systems."""
  15. import optparse
  16. import os
  17. import subprocess
  18. import sys
  19. import json
  20. # OS_ARCH_COMBOS maps from OS and platform to the OpenSSL assembly "style" for
  21. # that platform and the extension used by asm files.
  22. OS_ARCH_COMBOS = [
  23. ('linux', 'arm', 'linux32', [], 'S'),
  24. ('linux', 'aarch64', 'linux64', [], 'S'),
  25. ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
  26. ('linux', 'x86_64', 'elf', [], 'S'),
  27. ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
  28. ('mac', 'x86_64', 'macosx', [], 'S'),
  29. ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
  30. ('win', 'x86_64', 'nasm', [], 'asm'),
  31. ]
  32. # NON_PERL_FILES enumerates assembly files that are not processed by the
  33. # perlasm system.
  34. NON_PERL_FILES = {
  35. ('linux', 'arm'): [
  36. 'src/crypto/curve25519/asm/x25519-asm-arm.S',
  37. 'src/crypto/poly1305/poly1305_arm_asm.S',
  38. ],
  39. ('linux', 'x86_64'): [
  40. 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
  41. ],
  42. ('mac', 'x86_64'): [
  43. 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
  44. ],
  45. }
  46. PREFIX = None
  47. def PathOf(x):
  48. return x if not PREFIX else os.path.join(PREFIX, x)
  49. class Android(object):
  50. def __init__(self):
  51. self.header = \
  52. """# Copyright (C) 2015 The Android Open Source Project
  53. #
  54. # Licensed under the Apache License, Version 2.0 (the "License");
  55. # you may not use this file except in compliance with the License.
  56. # You may obtain a copy of the License at
  57. #
  58. # http://www.apache.org/licenses/LICENSE-2.0
  59. #
  60. # Unless required by applicable law or agreed to in writing, software
  61. # distributed under the License is distributed on an "AS IS" BASIS,
  62. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  63. # See the License for the specific language governing permissions and
  64. # limitations under the License.
  65. # This file is created by generate_build_files.py. Do not edit manually.
  66. """
  67. def ExtraFiles(self):
  68. return ['android_compat_hacks.c', 'android_compat_keywrap.c']
  69. def PrintVariableSection(self, out, name, files):
  70. out.write('%s := \\\n' % name)
  71. for f in sorted(files):
  72. out.write(' %s\\\n' % f)
  73. out.write('\n')
  74. def WriteFiles(self, files, asm_outputs):
  75. # New Android.bp format
  76. with open('sources.bp', 'w+') as blueprint:
  77. blueprint.write(self.header.replace('#', '//'))
  78. blueprint.write('cc_defaults {\n')
  79. blueprint.write(' name: "libcrypto_sources",\n')
  80. blueprint.write(' srcs: [\n')
  81. for f in sorted(files['crypto'] + self.ExtraFiles()):
  82. blueprint.write(' "%s",\n' % f)
  83. blueprint.write(' ],\n')
  84. blueprint.write(' target: {\n')
  85. for ((osname, arch), asm_files) in asm_outputs:
  86. if osname != 'linux':
  87. continue
  88. if arch == 'aarch64':
  89. arch = 'arm64'
  90. blueprint.write(' android_%s: {\n' % arch)
  91. blueprint.write(' srcs: [\n')
  92. for f in sorted(asm_files):
  93. blueprint.write(' "%s",\n' % f)
  94. blueprint.write(' ],\n')
  95. blueprint.write(' },\n')
  96. if arch == 'x86' or arch == 'x86_64':
  97. blueprint.write(' linux_%s: {\n' % arch)
  98. blueprint.write(' srcs: [\n')
  99. for f in sorted(asm_files):
  100. blueprint.write(' "%s",\n' % f)
  101. blueprint.write(' ],\n')
  102. blueprint.write(' },\n')
  103. blueprint.write(' },\n')
  104. blueprint.write('}\n\n')
  105. blueprint.write('cc_defaults {\n')
  106. blueprint.write(' name: "libssl_sources",\n')
  107. blueprint.write(' srcs: [\n')
  108. for f in sorted(files['ssl']):
  109. blueprint.write(' "%s",\n' % f)
  110. blueprint.write(' ],\n')
  111. blueprint.write('}\n\n')
  112. blueprint.write('cc_defaults {\n')
  113. blueprint.write(' name: "bssl_sources",\n')
  114. blueprint.write(' srcs: [\n')
  115. for f in sorted(files['tool']):
  116. blueprint.write(' "%s",\n' % f)
  117. blueprint.write(' ],\n')
  118. blueprint.write('}\n\n')
  119. blueprint.write('cc_defaults {\n')
  120. blueprint.write(' name: "boringssl_test_support_sources",\n')
  121. blueprint.write(' srcs: [\n')
  122. for f in sorted(files['test_support']):
  123. blueprint.write(' "%s",\n' % f)
  124. blueprint.write(' ],\n')
  125. blueprint.write('}\n\n')
  126. blueprint.write('cc_defaults {\n')
  127. blueprint.write(' name: "boringssl_tests_sources",\n')
  128. blueprint.write(' srcs: [\n')
  129. for f in sorted(files['test']):
  130. blueprint.write(' "%s",\n' % f)
  131. blueprint.write(' ],\n')
  132. blueprint.write('}\n')
  133. # Legacy Android.mk format, only used by Trusty in new branches
  134. with open('sources.mk', 'w+') as makefile:
  135. makefile.write(self.header)
  136. crypto_files = files['crypto'] + self.ExtraFiles()
  137. self.PrintVariableSection(makefile, 'crypto_sources', crypto_files)
  138. for ((osname, arch), asm_files) in asm_outputs:
  139. if osname != 'linux':
  140. continue
  141. self.PrintVariableSection(
  142. makefile, '%s_%s_sources' % (osname, arch), asm_files)
  143. class AndroidStandalone(Android):
  144. """AndroidStandalone is for Android builds outside of the Android-system, i.e.
  145. for applications that wish wish to ship BoringSSL.
  146. """
  147. def ExtraFiles(self):
  148. return []
  149. class Bazel(object):
  150. """Bazel outputs files suitable for including in Bazel files."""
  151. def __init__(self):
  152. self.firstSection = True
  153. self.header = \
  154. """# This file is created by generate_build_files.py. Do not edit manually.
  155. """
  156. def PrintVariableSection(self, out, name, files):
  157. if not self.firstSection:
  158. out.write('\n')
  159. self.firstSection = False
  160. out.write('%s = [\n' % name)
  161. for f in sorted(files):
  162. out.write(' "%s",\n' % PathOf(f))
  163. out.write(']\n')
  164. def WriteFiles(self, files, asm_outputs):
  165. with open('BUILD.generated.bzl', 'w+') as out:
  166. out.write(self.header)
  167. self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
  168. self.PrintVariableSection(
  169. out, 'ssl_internal_headers', files['ssl_internal_headers'])
  170. self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
  171. self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
  172. self.PrintVariableSection(
  173. out, 'crypto_internal_headers', files['crypto_internal_headers'])
  174. self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
  175. self.PrintVariableSection(out, 'tool_sources', files['tool'])
  176. self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
  177. for ((osname, arch), asm_files) in asm_outputs:
  178. self.PrintVariableSection(
  179. out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
  180. with open('BUILD.generated_tests.bzl', 'w+') as out:
  181. out.write(self.header)
  182. out.write('test_support_sources = [\n')
  183. for filename in sorted(files['test_support'] +
  184. files['test_support_headers'] +
  185. files['crypto_internal_headers'] +
  186. files['ssl_internal_headers']):
  187. if os.path.basename(filename) == 'malloc.cc':
  188. continue
  189. out.write(' "%s",\n' % PathOf(filename))
  190. out.write(']\n\n')
  191. out.write('def create_tests(copts, crypto, ssl):\n')
  192. name_counts = {}
  193. for test in files['tests']:
  194. name = os.path.basename(test[0])
  195. name_counts[name] = name_counts.get(name, 0) + 1
  196. first = True
  197. for test in files['tests']:
  198. name = os.path.basename(test[0])
  199. if name_counts[name] > 1:
  200. if '/' in test[1]:
  201. name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
  202. else:
  203. name += '_' + test[1].replace('-', '_')
  204. if not first:
  205. out.write('\n')
  206. first = False
  207. src_prefix = 'src/' + test[0]
  208. for src in files['test']:
  209. if src.startswith(src_prefix):
  210. src = src
  211. break
  212. else:
  213. raise ValueError("Can't find source for %s" % test[0])
  214. out.write(' native.cc_test(\n')
  215. out.write(' name = "%s",\n' % name)
  216. out.write(' size = "small",\n')
  217. out.write(' srcs = ["%s"] + test_support_sources,\n' %
  218. PathOf(src))
  219. data_files = []
  220. if len(test) > 1:
  221. out.write(' args = [\n')
  222. for arg in test[1:]:
  223. if '/' in arg:
  224. out.write(' "$(location %s)",\n' %
  225. PathOf(os.path.join('src', arg)))
  226. data_files.append('src/%s' % arg)
  227. else:
  228. out.write(' "%s",\n' % arg)
  229. out.write(' ],\n')
  230. out.write(' copts = copts,\n')
  231. if len(data_files) > 0:
  232. out.write(' data = [\n')
  233. for filename in data_files:
  234. out.write(' "%s",\n' % PathOf(filename))
  235. out.write(' ],\n')
  236. if 'ssl/' in test[0]:
  237. out.write(' deps = [\n')
  238. out.write(' crypto,\n')
  239. out.write(' ssl,\n')
  240. out.write(' ],\n')
  241. else:
  242. out.write(' deps = [crypto],\n')
  243. out.write(' )\n')
  244. class GN(object):
  245. def __init__(self):
  246. self.firstSection = True
  247. self.header = \
  248. """# Copyright (c) 2016 The Chromium Authors. All rights reserved.
  249. # Use of this source code is governed by a BSD-style license that can be
  250. # found in the LICENSE file.
  251. # This file is created by generate_build_files.py. Do not edit manually.
  252. """
  253. def PrintVariableSection(self, out, name, files):
  254. if not self.firstSection:
  255. out.write('\n')
  256. self.firstSection = False
  257. out.write('%s = [\n' % name)
  258. for f in sorted(files):
  259. out.write(' "%s",\n' % f)
  260. out.write(']\n')
  261. def WriteFiles(self, files, asm_outputs):
  262. with open('BUILD.generated.gni', 'w+') as out:
  263. out.write(self.header)
  264. self.PrintVariableSection(out, 'crypto_sources',
  265. files['crypto'] + files['crypto_headers'] +
  266. files['crypto_internal_headers'])
  267. self.PrintVariableSection(out, 'ssl_sources',
  268. files['ssl'] + files['ssl_headers'] +
  269. files['ssl_internal_headers'])
  270. for ((osname, arch), asm_files) in asm_outputs:
  271. self.PrintVariableSection(
  272. out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
  273. fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
  274. for fuzzer in files['fuzz']]
  275. self.PrintVariableSection(out, 'fuzzers', fuzzers)
  276. with open('BUILD.generated_tests.gni', 'w+') as out:
  277. self.firstSection = True
  278. out.write(self.header)
  279. self.PrintVariableSection(out, '_test_support_sources',
  280. files['test_support'] +
  281. files['test_support_headers'])
  282. out.write('\n')
  283. out.write('template("create_tests") {\n')
  284. all_tests = []
  285. for test in sorted(files['test']):
  286. test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
  287. all_tests.append(test_name)
  288. out.write(' executable("%s") {\n' % test_name)
  289. out.write(' sources = [\n')
  290. out.write(' "%s",\n' % test)
  291. out.write(' ]\n')
  292. out.write(' sources += _test_support_sources\n')
  293. out.write(' if (defined(invoker.configs_exclude)) {\n')
  294. out.write(' configs -= invoker.configs_exclude\n')
  295. out.write(' }\n')
  296. out.write(' configs += invoker.configs\n')
  297. out.write(' deps = invoker.deps\n')
  298. out.write(' }\n')
  299. out.write('\n')
  300. out.write(' group(target_name) {\n')
  301. out.write(' deps = [\n')
  302. for test_name in sorted(all_tests):
  303. out.write(' ":%s",\n' % test_name)
  304. out.write(' ]\n')
  305. out.write(' }\n')
  306. out.write('}\n')
  307. class GYP(object):
  308. def __init__(self):
  309. self.header = \
  310. """# Copyright (c) 2016 The Chromium Authors. All rights reserved.
  311. # Use of this source code is governed by a BSD-style license that can be
  312. # found in the LICENSE file.
  313. # This file is created by generate_build_files.py. Do not edit manually.
  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. def WriteFiles(self, files, asm_outputs):
  321. with open('boringssl.gypi', 'w+') as gypi:
  322. gypi.write(self.header + '{\n \'variables\': {\n')
  323. self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
  324. files['ssl'] + files['ssl_headers'] +
  325. files['ssl_internal_headers'])
  326. self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
  327. files['crypto'] + files['crypto_headers'] +
  328. files['crypto_internal_headers'])
  329. for ((osname, arch), asm_files) in asm_outputs:
  330. self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
  331. (osname, arch), asm_files)
  332. gypi.write(' }\n}\n')
  333. with open('boringssl_tests.gypi', 'w+') as test_gypi:
  334. test_gypi.write(self.header + '{\n \'targets\': [\n')
  335. test_names = []
  336. for test in sorted(files['test']):
  337. test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
  338. test_gypi.write(""" {
  339. 'target_name': '%s',
  340. 'type': 'executable',
  341. 'dependencies': [
  342. 'boringssl.gyp:boringssl',
  343. ],
  344. 'sources': [
  345. '%s',
  346. '<@(boringssl_test_support_sources)',
  347. ],
  348. # TODO(davidben): Fix size_t truncations in BoringSSL.
  349. # https://crbug.com/429039
  350. 'msvs_disabled_warnings': [ 4267, ],
  351. },\n""" % (test_name, test))
  352. test_names.append(test_name)
  353. test_names.sort()
  354. test_gypi.write(' ],\n \'variables\': {\n')
  355. self.PrintVariableSection(test_gypi, 'boringssl_test_support_sources',
  356. files['test_support'] +
  357. files['test_support_headers'])
  358. test_gypi.write(' \'boringssl_test_targets\': [\n')
  359. for test in sorted(test_names):
  360. test_gypi.write(""" '%s',\n""" % test)
  361. test_gypi.write(' ],\n }\n}\n')
  362. def FindCMakeFiles(directory):
  363. """Returns list of all CMakeLists.txt files recursively in directory."""
  364. cmakefiles = []
  365. for (path, _, filenames) in os.walk(directory):
  366. for filename in filenames:
  367. if filename == 'CMakeLists.txt':
  368. cmakefiles.append(os.path.join(path, filename))
  369. return cmakefiles
  370. def NoTests(dent, is_dir):
  371. """Filter function that can be passed to FindCFiles in order to remove test
  372. sources."""
  373. if is_dir:
  374. return dent != 'test'
  375. return 'test.' not in dent and not dent.startswith('example_')
  376. def OnlyTests(dent, is_dir):
  377. """Filter function that can be passed to FindCFiles in order to remove
  378. non-test sources."""
  379. if is_dir:
  380. return dent != 'test'
  381. return '_test.' in dent or dent.startswith('example_')
  382. def AllFiles(dent, is_dir):
  383. """Filter function that can be passed to FindCFiles in order to include all
  384. sources."""
  385. return True
  386. def SSLHeaderFiles(dent, is_dir):
  387. return dent in ['ssl.h', 'tls1.h', 'ssl23.h', 'ssl3.h', 'dtls1.h']
  388. def FindCFiles(directory, filter_func):
  389. """Recurses through directory and returns a list of paths to all the C source
  390. files that pass filter_func."""
  391. cfiles = []
  392. for (path, dirnames, filenames) in os.walk(directory):
  393. for filename in filenames:
  394. if not filename.endswith('.c') and not filename.endswith('.cc'):
  395. continue
  396. if not filter_func(filename, False):
  397. continue
  398. cfiles.append(os.path.join(path, filename))
  399. for (i, dirname) in enumerate(dirnames):
  400. if not filter_func(dirname, True):
  401. del dirnames[i]
  402. return cfiles
  403. def FindHeaderFiles(directory, filter_func):
  404. """Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
  405. hfiles = []
  406. for (path, dirnames, filenames) in os.walk(directory):
  407. for filename in filenames:
  408. if not filename.endswith('.h'):
  409. continue
  410. if not filter_func(filename, False):
  411. continue
  412. hfiles.append(os.path.join(path, filename))
  413. for (i, dirname) in enumerate(dirnames):
  414. if not filter_func(dirname, True):
  415. del dirnames[i]
  416. return hfiles
  417. def ExtractPerlAsmFromCMakeFile(cmakefile):
  418. """Parses the contents of the CMakeLists.txt file passed as an argument and
  419. returns a list of all the perlasm() directives found in the file."""
  420. perlasms = []
  421. with open(cmakefile) as f:
  422. for line in f:
  423. line = line.strip()
  424. if not line.startswith('perlasm('):
  425. continue
  426. if not line.endswith(')'):
  427. raise ValueError('Bad perlasm line in %s' % cmakefile)
  428. # Remove "perlasm(" from start and ")" from end
  429. params = line[8:-1].split()
  430. if len(params) < 2:
  431. raise ValueError('Bad perlasm line in %s' % cmakefile)
  432. perlasms.append({
  433. 'extra_args': params[2:],
  434. 'input': os.path.join(os.path.dirname(cmakefile), params[1]),
  435. 'output': os.path.join(os.path.dirname(cmakefile), params[0]),
  436. })
  437. return perlasms
  438. def ReadPerlAsmOperations():
  439. """Returns a list of all perlasm() directives found in CMake config files in
  440. src/."""
  441. perlasms = []
  442. cmakefiles = FindCMakeFiles('src')
  443. for cmakefile in cmakefiles:
  444. perlasms.extend(ExtractPerlAsmFromCMakeFile(cmakefile))
  445. return perlasms
  446. def PerlAsm(output_filename, input_filename, perlasm_style, extra_args):
  447. """Runs the a perlasm script and puts the output into output_filename."""
  448. base_dir = os.path.dirname(output_filename)
  449. if not os.path.isdir(base_dir):
  450. os.makedirs(base_dir)
  451. subprocess.check_call(
  452. ['perl', input_filename, perlasm_style] + extra_args + [output_filename])
  453. def ArchForAsmFilename(filename):
  454. """Returns the architectures that a given asm file should be compiled for
  455. based on substrings in the filename."""
  456. if 'x86_64' in filename or 'avx2' in filename:
  457. return ['x86_64']
  458. elif ('x86' in filename and 'x86_64' not in filename) or '586' in filename:
  459. return ['x86']
  460. elif 'armx' in filename:
  461. return ['arm', 'aarch64']
  462. elif 'armv8' in filename:
  463. return ['aarch64']
  464. elif 'arm' in filename:
  465. return ['arm']
  466. else:
  467. raise ValueError('Unknown arch for asm filename: ' + filename)
  468. def WriteAsmFiles(perlasms):
  469. """Generates asm files from perlasm directives for each supported OS x
  470. platform combination."""
  471. asmfiles = {}
  472. for osarch in OS_ARCH_COMBOS:
  473. (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
  474. key = (osname, arch)
  475. outDir = '%s-%s' % key
  476. for perlasm in perlasms:
  477. filename = os.path.basename(perlasm['input'])
  478. output = perlasm['output']
  479. if not output.startswith('src'):
  480. raise ValueError('output missing src: %s' % output)
  481. output = os.path.join(outDir, output[4:])
  482. if output.endswith('-armx.${ASM_EXT}'):
  483. output = output.replace('-armx',
  484. '-armx64' if arch == 'aarch64' else '-armx32')
  485. output = output.replace('${ASM_EXT}', asm_ext)
  486. if arch in ArchForAsmFilename(filename):
  487. PerlAsm(output, perlasm['input'], perlasm_style,
  488. perlasm['extra_args'] + extra_args)
  489. asmfiles.setdefault(key, []).append(output)
  490. for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
  491. asmfiles.setdefault(key, []).extend(non_perl_asm_files)
  492. return asmfiles
  493. def main(platforms):
  494. crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTests)
  495. ssl_c_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
  496. tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
  497. tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
  498. # Generate err_data.c
  499. with open('err_data.c', 'w+') as err_data:
  500. subprocess.check_call(['go', 'run', 'err_data_generate.go'],
  501. cwd=os.path.join('src', 'crypto', 'err'),
  502. stdout=err_data)
  503. crypto_c_files.append('err_data.c')
  504. test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
  505. AllFiles)
  506. test_support_h_files = (
  507. FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
  508. FindHeaderFiles(os.path.join('src', 'ssl', 'test'), AllFiles))
  509. test_c_files = FindCFiles(os.path.join('src', 'crypto'), OnlyTests)
  510. test_c_files += FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
  511. fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
  512. ssl_h_files = (
  513. FindHeaderFiles(
  514. os.path.join('src', 'include', 'openssl'),
  515. SSLHeaderFiles))
  516. def NotSSLHeaderFiles(filename, is_dir):
  517. return not SSLHeaderFiles(filename, is_dir)
  518. crypto_h_files = (
  519. FindHeaderFiles(
  520. os.path.join('src', 'include', 'openssl'),
  521. NotSSLHeaderFiles))
  522. ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
  523. crypto_internal_h_files = FindHeaderFiles(
  524. os.path.join('src', 'crypto'), NoTests)
  525. with open('src/util/all_tests.json', 'r') as f:
  526. tests = json.load(f)
  527. # Skip tests for libdecrepit. Consumers import that manually.
  528. tests = [test for test in tests if not test[0].startswith("decrepit/")]
  529. test_binaries = set([test[0] for test in tests])
  530. test_sources = set([
  531. test.replace('.cc', '').replace('.c', '').replace(
  532. 'src/',
  533. '')
  534. for test in test_c_files])
  535. if test_binaries != test_sources:
  536. print 'Test sources and configured tests do not match'
  537. a = test_binaries.difference(test_sources)
  538. if len(a) > 0:
  539. print 'These tests are configured without sources: ' + str(a)
  540. b = test_sources.difference(test_binaries)
  541. if len(b) > 0:
  542. print 'These test sources are not configured: ' + str(b)
  543. files = {
  544. 'crypto': crypto_c_files,
  545. 'crypto_headers': crypto_h_files,
  546. 'crypto_internal_headers': crypto_internal_h_files,
  547. 'fuzz': fuzz_c_files,
  548. 'ssl': ssl_c_files,
  549. 'ssl_headers': ssl_h_files,
  550. 'ssl_internal_headers': ssl_internal_h_files,
  551. 'tool': tool_c_files,
  552. 'tool_headers': tool_h_files,
  553. 'test': test_c_files,
  554. 'test_support': test_support_c_files,
  555. 'test_support_headers': test_support_h_files,
  556. 'tests': tests,
  557. }
  558. asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
  559. for platform in platforms:
  560. platform.WriteFiles(files, asm_outputs)
  561. return 0
  562. if __name__ == '__main__':
  563. parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]'
  564. ' [android|android-standalone|bazel|gn|gyp]')
  565. parser.add_option('--prefix', dest='prefix',
  566. help='For Bazel, prepend argument to all source files')
  567. options, args = parser.parse_args(sys.argv[1:])
  568. PREFIX = options.prefix
  569. if not args:
  570. parser.print_help()
  571. sys.exit(1)
  572. platforms = []
  573. for s in args:
  574. if s == 'android':
  575. platforms.append(Android())
  576. elif s == 'android-standalone':
  577. platforms.append(AndroidStandalone())
  578. elif s == 'bazel':
  579. platforms.append(Bazel())
  580. elif s == 'gn':
  581. platforms.append(GN())
  582. elif s == 'gyp':
  583. platforms.append(GYP())
  584. else:
  585. parser.print_help()
  586. sys.exit(1)
  587. sys.exit(main(platforms))