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.
 
 
 
 
 
 

755 lines
25 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', 'ppc64le', 'ppc64le', [], 'S'),
  26. ('linux', 'x86', 'elf', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
  27. ('linux', 'x86_64', 'elf', [], 'S'),
  28. ('mac', 'x86', 'macosx', ['-fPIC', '-DOPENSSL_IA32_SSE2'], 'S'),
  29. ('mac', 'x86_64', 'macosx', [], 'S'),
  30. ('win', 'x86', 'win32n', ['-DOPENSSL_IA32_SSE2'], 'asm'),
  31. ('win', 'x86_64', 'nasm', [], 'asm'),
  32. ]
  33. # NON_PERL_FILES enumerates assembly files that are not processed by the
  34. # perlasm system.
  35. NON_PERL_FILES = {
  36. ('linux', 'arm'): [
  37. 'src/crypto/curve25519/asm/x25519-asm-arm.S',
  38. 'src/crypto/poly1305/poly1305_arm_asm.S',
  39. ],
  40. ('linux', 'x86_64'): [
  41. 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
  42. ],
  43. ('mac', 'x86_64'): [
  44. 'src/crypto/curve25519/asm/x25519-asm-x86_64.S',
  45. ],
  46. }
  47. PREFIX = None
  48. def PathOf(x):
  49. return x if not PREFIX else os.path.join(PREFIX, x)
  50. class Android(object):
  51. def __init__(self):
  52. self.header = \
  53. """# Copyright (C) 2015 The Android Open Source Project
  54. #
  55. # Licensed under the Apache License, Version 2.0 (the "License");
  56. # you may not use this file except in compliance with the License.
  57. # You may obtain a copy of the License at
  58. #
  59. # http://www.apache.org/licenses/LICENSE-2.0
  60. #
  61. # Unless required by applicable law or agreed to in writing, software
  62. # distributed under the License is distributed on an "AS IS" BASIS,
  63. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  64. # See the License for the specific language governing permissions and
  65. # limitations under the License.
  66. # This file is created by generate_build_files.py. Do not edit manually.
  67. """
  68. def PrintVariableSection(self, out, name, files):
  69. out.write('%s := \\\n' % name)
  70. for f in sorted(files):
  71. out.write(' %s\\\n' % f)
  72. out.write('\n')
  73. def WriteFiles(self, files, asm_outputs):
  74. # New Android.bp format
  75. with open('sources.bp', 'w+') as blueprint:
  76. blueprint.write(self.header.replace('#', '//'))
  77. blueprint.write('cc_defaults {\n')
  78. blueprint.write(' name: "libcrypto_sources",\n')
  79. blueprint.write(' srcs: [\n')
  80. for f in sorted(files['crypto']):
  81. blueprint.write(' "%s",\n' % f)
  82. blueprint.write(' ],\n')
  83. blueprint.write(' target: {\n')
  84. for ((osname, arch), asm_files) in asm_outputs:
  85. if osname != 'linux' or arch == 'ppc64le':
  86. continue
  87. if arch == 'aarch64':
  88. arch = 'arm64'
  89. blueprint.write(' android_%s: {\n' % arch)
  90. blueprint.write(' srcs: [\n')
  91. for f in sorted(asm_files):
  92. blueprint.write(' "%s",\n' % f)
  93. blueprint.write(' ],\n')
  94. blueprint.write(' },\n')
  95. if arch == 'x86' or arch == 'x86_64':
  96. blueprint.write(' linux_%s: {\n' % arch)
  97. blueprint.write(' srcs: [\n')
  98. for f in sorted(asm_files):
  99. blueprint.write(' "%s",\n' % f)
  100. blueprint.write(' ],\n')
  101. blueprint.write(' },\n')
  102. blueprint.write(' },\n')
  103. blueprint.write('}\n\n')
  104. blueprint.write('cc_defaults {\n')
  105. blueprint.write(' name: "libssl_sources",\n')
  106. blueprint.write(' srcs: [\n')
  107. for f in sorted(files['ssl']):
  108. blueprint.write(' "%s",\n' % f)
  109. blueprint.write(' ],\n')
  110. blueprint.write('}\n\n')
  111. blueprint.write('cc_defaults {\n')
  112. blueprint.write(' name: "bssl_sources",\n')
  113. blueprint.write(' srcs: [\n')
  114. for f in sorted(files['tool']):
  115. blueprint.write(' "%s",\n' % f)
  116. blueprint.write(' ],\n')
  117. blueprint.write('}\n\n')
  118. blueprint.write('cc_defaults {\n')
  119. blueprint.write(' name: "boringssl_test_support_sources",\n')
  120. blueprint.write(' srcs: [\n')
  121. for f in sorted(files['test_support']):
  122. blueprint.write(' "%s",\n' % f)
  123. blueprint.write(' ],\n')
  124. blueprint.write('}\n\n')
  125. blueprint.write('cc_defaults {\n')
  126. blueprint.write(' name: "boringssl_crypto_test_sources",\n')
  127. blueprint.write(' srcs: [\n')
  128. for f in sorted(files['crypto_test']):
  129. blueprint.write(' "%s",\n' % f)
  130. blueprint.write(' ],\n')
  131. blueprint.write('}\n\n')
  132. blueprint.write('cc_defaults {\n')
  133. blueprint.write(' name: "boringssl_ssl_test_sources",\n')
  134. blueprint.write(' srcs: [\n')
  135. for f in sorted(files['ssl_test']):
  136. blueprint.write(' "%s",\n' % f)
  137. blueprint.write(' ],\n')
  138. blueprint.write('}\n\n')
  139. blueprint.write('cc_defaults {\n')
  140. blueprint.write(' name: "boringssl_tests_sources",\n')
  141. blueprint.write(' srcs: [\n')
  142. for f in sorted(files['test']):
  143. blueprint.write(' "%s",\n' % f)
  144. blueprint.write(' ],\n')
  145. blueprint.write('}\n')
  146. # Legacy Android.mk format, only used by Trusty in new branches
  147. with open('sources.mk', 'w+') as makefile:
  148. makefile.write(self.header)
  149. self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
  150. for ((osname, arch), asm_files) in asm_outputs:
  151. if osname != 'linux':
  152. continue
  153. self.PrintVariableSection(
  154. makefile, '%s_%s_sources' % (osname, arch), asm_files)
  155. class Bazel(object):
  156. """Bazel outputs files suitable for including in Bazel files."""
  157. def __init__(self):
  158. self.firstSection = True
  159. self.header = \
  160. """# This file is created by generate_build_files.py. Do not edit manually.
  161. """
  162. def PrintVariableSection(self, out, name, files):
  163. if not self.firstSection:
  164. out.write('\n')
  165. self.firstSection = False
  166. out.write('%s = [\n' % name)
  167. for f in sorted(files):
  168. out.write(' "%s",\n' % PathOf(f))
  169. out.write(']\n')
  170. def WriteFiles(self, files, asm_outputs):
  171. with open('BUILD.generated.bzl', 'w+') as out:
  172. out.write(self.header)
  173. self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
  174. self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
  175. self.PrintVariableSection(
  176. out, 'ssl_internal_headers', files['ssl_internal_headers'])
  177. self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
  178. self.PrintVariableSection(out, 'ssl_c_sources', files['ssl_c'])
  179. self.PrintVariableSection(out, 'ssl_cc_sources', files['ssl_cc'])
  180. self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
  181. self.PrintVariableSection(
  182. out, 'crypto_internal_headers', files['crypto_internal_headers'])
  183. self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
  184. self.PrintVariableSection(out, 'tool_sources', files['tool'])
  185. self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
  186. for ((osname, arch), asm_files) in asm_outputs:
  187. self.PrintVariableSection(
  188. out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
  189. with open('BUILD.generated_tests.bzl', 'w+') as out:
  190. out.write(self.header)
  191. out.write('test_support_sources = [\n')
  192. for filename in sorted(files['test_support'] +
  193. files['test_support_headers'] +
  194. files['crypto_internal_headers'] +
  195. files['ssl_internal_headers']):
  196. if os.path.basename(filename) == 'malloc.cc':
  197. continue
  198. out.write(' "%s",\n' % PathOf(filename))
  199. out.write(']\n\n')
  200. self.PrintVariableSection(out, 'crypto_test_sources',
  201. files['crypto_test'])
  202. self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
  203. out.write('def create_tests(copts, crypto, ssl):\n')
  204. name_counts = {}
  205. for test in files['tests']:
  206. name = os.path.basename(test[0])
  207. name_counts[name] = name_counts.get(name, 0) + 1
  208. first = True
  209. for test in files['tests']:
  210. name = os.path.basename(test[0])
  211. if name_counts[name] > 1:
  212. if '/' in test[1]:
  213. name += '_' + os.path.splitext(os.path.basename(test[1]))[0]
  214. else:
  215. name += '_' + test[1].replace('-', '_')
  216. if not first:
  217. out.write('\n')
  218. first = False
  219. src_prefix = 'src/' + test[0]
  220. for src in files['test']:
  221. if src.startswith(src_prefix):
  222. src = src
  223. break
  224. else:
  225. raise ValueError("Can't find source for %s" % test[0])
  226. out.write(' native.cc_test(\n')
  227. out.write(' name = "%s",\n' % name)
  228. out.write(' size = "small",\n')
  229. out.write(' srcs = ["%s"] + test_support_sources,\n' %
  230. PathOf(src))
  231. data_files = []
  232. if len(test) > 1:
  233. out.write(' args = [\n')
  234. for arg in test[1:]:
  235. if '/' in arg:
  236. out.write(' "$(location %s)",\n' %
  237. PathOf(os.path.join('src', arg)))
  238. data_files.append('src/%s' % arg)
  239. else:
  240. out.write(' "%s",\n' % arg)
  241. out.write(' ],\n')
  242. out.write(' copts = copts + ["-DBORINGSSL_SHARED_LIBRARY"],\n')
  243. if len(data_files) > 0:
  244. out.write(' data = [\n')
  245. for filename in data_files:
  246. out.write(' "%s",\n' % PathOf(filename))
  247. out.write(' ],\n')
  248. if 'ssl/' in test[0]:
  249. out.write(' deps = [\n')
  250. out.write(' crypto,\n')
  251. out.write(' ssl,\n')
  252. out.write(' ],\n')
  253. else:
  254. out.write(' deps = [crypto],\n')
  255. out.write(' )\n')
  256. class GN(object):
  257. def __init__(self):
  258. self.firstSection = True
  259. self.header = \
  260. """# Copyright (c) 2016 The Chromium Authors. All rights reserved.
  261. # Use of this source code is governed by a BSD-style license that can be
  262. # found in the LICENSE file.
  263. # This file is created by generate_build_files.py. Do not edit manually.
  264. """
  265. def PrintVariableSection(self, out, name, files):
  266. if not self.firstSection:
  267. out.write('\n')
  268. self.firstSection = False
  269. out.write('%s = [\n' % name)
  270. for f in sorted(files):
  271. out.write(' "%s",\n' % f)
  272. out.write(']\n')
  273. def WriteFiles(self, files, asm_outputs):
  274. with open('BUILD.generated.gni', 'w+') as out:
  275. out.write(self.header)
  276. self.PrintVariableSection(out, 'crypto_sources',
  277. files['crypto'] + files['crypto_headers'] +
  278. files['crypto_internal_headers'])
  279. self.PrintVariableSection(out, 'ssl_sources',
  280. files['ssl'] + files['ssl_headers'] +
  281. files['ssl_internal_headers'])
  282. for ((osname, arch), asm_files) in asm_outputs:
  283. self.PrintVariableSection(
  284. out, 'crypto_sources_%s_%s' % (osname, arch), asm_files)
  285. fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
  286. for fuzzer in files['fuzz']]
  287. self.PrintVariableSection(out, 'fuzzers', fuzzers)
  288. with open('BUILD.generated_tests.gni', 'w+') as out:
  289. self.firstSection = True
  290. out.write(self.header)
  291. self.PrintVariableSection(out, 'test_support_sources',
  292. files['test_support'] +
  293. files['test_support_headers'])
  294. self.PrintVariableSection(out, 'crypto_test_sources',
  295. files['crypto_test'])
  296. self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
  297. out.write('\n')
  298. out.write('template("create_tests") {\n')
  299. all_tests = []
  300. for test in sorted(files['test']):
  301. test_name = 'boringssl_%s' % os.path.splitext(os.path.basename(test))[0]
  302. all_tests.append(test_name)
  303. out.write(' executable("%s") {\n' % test_name)
  304. out.write(' sources = [\n')
  305. out.write(' "%s",\n' % test)
  306. out.write(' ]\n')
  307. out.write(' sources += test_support_sources\n')
  308. out.write(' if (defined(invoker.configs_exclude)) {\n')
  309. out.write(' configs -= invoker.configs_exclude\n')
  310. out.write(' }\n')
  311. out.write(' configs += invoker.configs\n')
  312. out.write(' deps = invoker.deps\n')
  313. out.write(' }\n')
  314. out.write('\n')
  315. out.write(' group(target_name) {\n')
  316. out.write(' deps = [\n')
  317. for test_name in sorted(all_tests):
  318. out.write(' ":%s",\n' % test_name)
  319. out.write(' ]\n')
  320. out.write(' }\n')
  321. out.write('}\n')
  322. class GYP(object):
  323. def __init__(self):
  324. self.header = \
  325. """# Copyright (c) 2016 The Chromium Authors. All rights reserved.
  326. # Use of this source code is governed by a BSD-style license that can be
  327. # found in the LICENSE file.
  328. # This file is created by generate_build_files.py. Do not edit manually.
  329. """
  330. def PrintVariableSection(self, out, name, files):
  331. out.write(' \'%s\': [\n' % name)
  332. for f in sorted(files):
  333. out.write(' \'%s\',\n' % f)
  334. out.write(' ],\n')
  335. def WriteFiles(self, files, asm_outputs):
  336. with open('boringssl.gypi', 'w+') as gypi:
  337. gypi.write(self.header + '{\n \'variables\': {\n')
  338. self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
  339. files['ssl'] + files['ssl_headers'] +
  340. files['ssl_internal_headers'])
  341. self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
  342. files['crypto'] + files['crypto_headers'] +
  343. files['crypto_internal_headers'])
  344. for ((osname, arch), asm_files) in asm_outputs:
  345. self.PrintVariableSection(gypi, 'boringssl_%s_%s_sources' %
  346. (osname, arch), asm_files)
  347. gypi.write(' }\n}\n')
  348. def FindCMakeFiles(directory):
  349. """Returns list of all CMakeLists.txt files recursively in directory."""
  350. cmakefiles = []
  351. for (path, _, filenames) in os.walk(directory):
  352. for filename in filenames:
  353. if filename == 'CMakeLists.txt':
  354. cmakefiles.append(os.path.join(path, filename))
  355. return cmakefiles
  356. def OnlyFIPSFragments(path, dent, is_dir):
  357. return is_dir or path.startswith(
  358. os.path.join('src', 'crypto', 'fipsmodule', ''))
  359. def NoTestsNorFIPSFragments(path, dent, is_dir):
  360. return (NoTests(path, dent, is_dir) and
  361. (is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
  362. def NoTests(path, dent, is_dir):
  363. """Filter function that can be passed to FindCFiles in order to remove test
  364. sources."""
  365. if is_dir:
  366. return dent != 'test'
  367. return 'test.' not in dent and not dent.startswith('example_')
  368. def OnlyTests(path, dent, is_dir):
  369. """Filter function that can be passed to FindCFiles in order to remove
  370. non-test sources."""
  371. if is_dir:
  372. return dent != 'test'
  373. return '_test.' in dent or dent.startswith('example_')
  374. def AllFiles(path, dent, is_dir):
  375. """Filter function that can be passed to FindCFiles in order to include all
  376. sources."""
  377. return True
  378. def NoTestRunnerFiles(path, dent, is_dir):
  379. """Filter function that can be passed to FindCFiles or FindHeaderFiles in
  380. order to exclude test runner files."""
  381. # NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
  382. # are in their own subpackage, from being included in boringssl/BUILD files.
  383. return not is_dir or dent != 'runner'
  384. def NotGTestMain(path, dent, is_dir):
  385. return dent != 'gtest_main.cc'
  386. def SSLHeaderFiles(path, 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(path, filename, False):
  397. continue
  398. cfiles.append(os.path.join(path, filename))
  399. for (i, dirname) in enumerate(dirnames):
  400. if not filter_func(path, 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(path, filename, False):
  411. continue
  412. hfiles.append(os.path.join(path, filename))
  413. for (i, dirname) in enumerate(dirnames):
  414. if not filter_func(path, 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. elif 'ppc' in filename:
  467. return ['ppc64le']
  468. else:
  469. raise ValueError('Unknown arch for asm filename: ' + filename)
  470. def WriteAsmFiles(perlasms):
  471. """Generates asm files from perlasm directives for each supported OS x
  472. platform combination."""
  473. asmfiles = {}
  474. for osarch in OS_ARCH_COMBOS:
  475. (osname, arch, perlasm_style, extra_args, asm_ext) = osarch
  476. key = (osname, arch)
  477. outDir = '%s-%s' % key
  478. for perlasm in perlasms:
  479. filename = os.path.basename(perlasm['input'])
  480. output = perlasm['output']
  481. if not output.startswith('src'):
  482. raise ValueError('output missing src: %s' % output)
  483. output = os.path.join(outDir, output[4:])
  484. if output.endswith('-armx.${ASM_EXT}'):
  485. output = output.replace('-armx',
  486. '-armx64' if arch == 'aarch64' else '-armx32')
  487. output = output.replace('${ASM_EXT}', asm_ext)
  488. if arch in ArchForAsmFilename(filename):
  489. PerlAsm(output, perlasm['input'], perlasm_style,
  490. perlasm['extra_args'] + extra_args)
  491. asmfiles.setdefault(key, []).append(output)
  492. for (key, non_perl_asm_files) in NON_PERL_FILES.iteritems():
  493. asmfiles.setdefault(key, []).extend(non_perl_asm_files)
  494. return asmfiles
  495. def IsGTest(path):
  496. with open(path) as f:
  497. return "#include <gtest/gtest.h>" in f.read()
  498. def main(platforms):
  499. crypto_c_files = FindCFiles(os.path.join('src', 'crypto'), NoTestsNorFIPSFragments)
  500. fips_fragments = FindCFiles(os.path.join('src', 'crypto', 'fipsmodule'), OnlyFIPSFragments)
  501. ssl_source_files = FindCFiles(os.path.join('src', 'ssl'), NoTests)
  502. tool_c_files = FindCFiles(os.path.join('src', 'tool'), NoTests)
  503. tool_h_files = FindHeaderFiles(os.path.join('src', 'tool'), AllFiles)
  504. # Generate err_data.c
  505. with open('err_data.c', 'w+') as err_data:
  506. subprocess.check_call(['go', 'run', 'err_data_generate.go'],
  507. cwd=os.path.join('src', 'crypto', 'err'),
  508. stdout=err_data)
  509. crypto_c_files.append('err_data.c')
  510. test_support_c_files = FindCFiles(os.path.join('src', 'crypto', 'test'),
  511. NotGTestMain)
  512. test_support_h_files = (
  513. FindHeaderFiles(os.path.join('src', 'crypto', 'test'), AllFiles) +
  514. FindHeaderFiles(os.path.join('src', 'ssl', 'test'), NoTestRunnerFiles))
  515. test_c_files = []
  516. crypto_test_files = ['src/crypto/test/gtest_main.cc']
  517. # TODO(davidben): Remove this loop once all tests are converted.
  518. for path in FindCFiles(os.path.join('src', 'crypto'), OnlyTests):
  519. if IsGTest(path):
  520. crypto_test_files.append(path)
  521. else:
  522. test_c_files.append(path)
  523. ssl_test_files = FindCFiles(os.path.join('src', 'ssl'), OnlyTests)
  524. ssl_test_files.append('src/crypto/test/gtest_main.cc')
  525. fuzz_c_files = FindCFiles(os.path.join('src', 'fuzz'), NoTests)
  526. ssl_h_files = (
  527. FindHeaderFiles(
  528. os.path.join('src', 'include', 'openssl'),
  529. SSLHeaderFiles))
  530. def NotSSLHeaderFiles(path, filename, is_dir):
  531. return not SSLHeaderFiles(path, filename, is_dir)
  532. crypto_h_files = (
  533. FindHeaderFiles(
  534. os.path.join('src', 'include', 'openssl'),
  535. NotSSLHeaderFiles))
  536. ssl_internal_h_files = FindHeaderFiles(os.path.join('src', 'ssl'), NoTests)
  537. crypto_internal_h_files = FindHeaderFiles(
  538. os.path.join('src', 'crypto'), NoTests)
  539. with open('src/util/all_tests.json', 'r') as f:
  540. tests = json.load(f)
  541. # For now, GTest-based tests are specified manually.
  542. tests = [test for test in tests if test[0] not in ['crypto/crypto_test',
  543. 'decrepit/decrepit_test',
  544. 'ssl/ssl_test']]
  545. test_binaries = set([test[0] for test in tests])
  546. test_sources = set([
  547. test.replace('.cc', '').replace('.c', '').replace(
  548. 'src/',
  549. '')
  550. for test in test_c_files])
  551. if test_binaries != test_sources:
  552. print 'Test sources and configured tests do not match'
  553. a = test_binaries.difference(test_sources)
  554. if len(a) > 0:
  555. print 'These tests are configured without sources: ' + str(a)
  556. b = test_sources.difference(test_binaries)
  557. if len(b) > 0:
  558. print 'These test sources are not configured: ' + str(b)
  559. files = {
  560. 'crypto': crypto_c_files,
  561. 'crypto_headers': crypto_h_files,
  562. 'crypto_internal_headers': crypto_internal_h_files,
  563. 'crypto_test': sorted(crypto_test_files),
  564. 'fips_fragments': fips_fragments,
  565. 'fuzz': fuzz_c_files,
  566. 'ssl': ssl_source_files,
  567. 'ssl_c': [s for s in ssl_source_files if s.endswith('.c')],
  568. 'ssl_cc': [s for s in ssl_source_files if s.endswith('.cc')],
  569. 'ssl_headers': ssl_h_files,
  570. 'ssl_internal_headers': ssl_internal_h_files,
  571. 'ssl_test': sorted(ssl_test_files),
  572. 'tool': tool_c_files,
  573. 'tool_headers': tool_h_files,
  574. 'test': test_c_files,
  575. 'test_support': test_support_c_files,
  576. 'test_support_headers': test_support_h_files,
  577. 'tests': tests,
  578. }
  579. asm_outputs = sorted(WriteAsmFiles(ReadPerlAsmOperations()).iteritems())
  580. for platform in platforms:
  581. platform.WriteFiles(files, asm_outputs)
  582. return 0
  583. if __name__ == '__main__':
  584. parser = optparse.OptionParser(usage='Usage: %prog [--prefix=<path>]'
  585. ' [android|bazel|gn|gyp]')
  586. parser.add_option('--prefix', dest='prefix',
  587. help='For Bazel, prepend argument to all source files')
  588. options, args = parser.parse_args(sys.argv[1:])
  589. PREFIX = options.prefix
  590. if not args:
  591. parser.print_help()
  592. sys.exit(1)
  593. platforms = []
  594. for s in args:
  595. if s == 'android':
  596. platforms.append(Android())
  597. elif s == 'bazel':
  598. platforms.append(Bazel())
  599. elif s == 'gn':
  600. platforms.append(GN())
  601. elif s == 'gyp':
  602. platforms.append(GYP())
  603. else:
  604. parser.print_help()
  605. sys.exit(1)
  606. sys.exit(main(platforms))