-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_build_files.py
707 lines (578 loc) · 25.7 KB
/
generate_build_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# coding=utf8
# Copyright (c) 2015, Google Inc.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""Enumerates source files for consumption by various build systems."""
import optparse
import os
import subprocess
import sys
import json
PREFIX = None
EMBED_TEST_DATA = False
def PathOf(x):
return x if not PREFIX else os.path.join(PREFIX, x)
LICENSE_TEMPLATE = """Copyright (c) 2015, Google Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.""".split("\n")
def LicenseHeader(comment):
lines = []
for line in LICENSE_TEMPLATE:
if not line:
lines.append(comment)
else:
lines.append("%s %s" % (comment, line))
lines.append("")
return "\n".join(lines)
class Android(object):
def __init__(self):
self.header = LicenseHeader("#") + """
# This file is created by generate_build_files.py. Do not edit manually.
"""
def PrintVariableSection(self, out, name, files):
out.write('%s := \\\n' % name)
for f in sorted(files):
out.write(' %s\\\n' % f)
out.write('\n')
def WriteFiles(self, files):
# New Android.bp format
with open('sources.bp', 'w+') as blueprint:
blueprint.write(self.header.replace('#', '//'))
# Separate out BCM files to allow different compilation rules (specific to Android FIPS)
bcm_c_files = files['bcm_crypto']
non_bcm_c_files = [file for file in files['crypto'] if file not in bcm_c_files]
non_bcm_asm = self.FilterBcmAsm(files['crypto_asm'], False)
bcm_asm = self.FilterBcmAsm(files['crypto_asm'], True)
self.PrintDefaults(blueprint, 'libcrypto_sources', non_bcm_c_files, asm_files=non_bcm_asm)
self.PrintDefaults(blueprint, 'libcrypto_bcm_sources', bcm_c_files, asm_files=bcm_asm)
self.PrintDefaults(blueprint, 'libssl_sources', files['ssl'])
self.PrintDefaults(blueprint, 'bssl_sources', files['tool'])
self.PrintDefaults(blueprint, 'boringssl_test_support_sources', files['test_support'])
self.PrintDefaults(blueprint, 'boringssl_crypto_test_sources', files['crypto_test'], data=files['crypto_test_data'])
self.PrintDefaults(blueprint, 'boringssl_ssl_test_sources', files['ssl_test'])
self.PrintDefaults(blueprint, 'libpki_sources', files['pki'])
# Legacy Android.mk format, only used by Trusty in new branches
with open('sources.mk', 'w+') as makefile:
makefile.write(self.header)
makefile.write('\n')
self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
self.PrintVariableSection(makefile, 'crypto_sources_asm',
files['crypto_asm'])
def PrintDefaults(self, blueprint, name, files, asm_files=[], data=[]):
"""Print a cc_defaults section from a list of C files and optionally assembly outputs"""
if asm_files:
blueprint.write('\n')
blueprint.write('%s_asm = [\n' % name)
for f in sorted(asm_files):
blueprint.write(' "%s",\n' % f)
blueprint.write(']\n')
blueprint.write('\n')
blueprint.write('cc_defaults {\n')
blueprint.write(' name: "%s",\n' % name)
blueprint.write(' srcs: [\n')
for f in sorted(files):
blueprint.write(' "%s",\n' % f)
blueprint.write(' ],\n')
if data:
blueprint.write(' data: [\n')
for f in sorted(data):
blueprint.write(' "%s",\n' % f)
blueprint.write(' ],\n')
if asm_files:
blueprint.write(' target: {\n')
# Only emit asm for Linux. On Windows, BoringSSL requires NASM, which is
# not available in AOSP. On Darwin, the assembly works fine, but it
# conflicts with Android's FIPS build. See b/294399371.
blueprint.write(' linux: {\n')
blueprint.write(' srcs: %s_asm,\n' % name)
blueprint.write(' },\n')
blueprint.write(' darwin: {\n')
blueprint.write(' cflags: ["-DOPENSSL_NO_ASM"],\n')
blueprint.write(' },\n')
blueprint.write(' windows: {\n')
blueprint.write(' cflags: ["-DOPENSSL_NO_ASM"],\n')
blueprint.write(' },\n')
blueprint.write(' },\n')
blueprint.write('}\n')
def FilterBcmAsm(self, asm, want_bcm):
"""Filter a list of assembly outputs based on whether they belong in BCM
Args:
asm: Assembly file list to filter
want_bcm: If true then include BCM files, otherwise do not
Returns:
A copy of |asm| with files filtered according to |want_bcm|
"""
# TODO(https://crbug.com/boringssl/542): Rather than filtering by filename,
# use the variable listed in the CMake perlasm line, available in
# ExtractPerlAsmFromCMakeFile.
return filter(lambda p: ("/crypto/fipsmodule/" in p) == want_bcm, asm)
class AndroidCMake(object):
def __init__(self):
self.header = LicenseHeader("#") + """
# This file is created by generate_build_files.py. Do not edit manually.
# To specify a custom path prefix, set BORINGSSL_ROOT before including this
# file, or use list(TRANSFORM ... PREPEND) from CMake 3.12.
"""
def PrintVariableSection(self, out, name, files):
out.write('set(%s\n' % name)
for f in sorted(files):
# Ideally adding the prefix would be the caller's job, but
# list(TRANSFORM ... PREPEND) is only available starting CMake 3.12. When
# sources.cmake is the source of truth, we can ask Android to either write
# a CMake function or update to 3.12.
out.write(' ${BORINGSSL_ROOT}%s\n' % f)
out.write(')\n')
def WriteFiles(self, files):
# The Android emulator uses a custom CMake buildsystem.
#
# TODO(crbug.com/boringssl/542): Move our various source lists into
# sources.cmake and have Android consume that directly.
with open('android-sources.cmake', 'w+') as out:
out.write(self.header)
self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
self.PrintVariableSection(out, 'crypto_sources_asm', files['crypto_asm'])
self.PrintVariableSection(out, 'crypto_sources_nasm',
files['crypto_nasm'])
self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
self.PrintVariableSection(out, 'tool_sources', files['tool'])
self.PrintVariableSection(out, 'test_support_sources',
files['test_support'])
self.PrintVariableSection(out, 'crypto_test_sources',
files['crypto_test'])
self.PrintVariableSection(out, 'crypto_test_data',
files['crypto_test_data'])
self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
class Bazel(object):
"""Bazel outputs files suitable for including in Bazel files."""
def __init__(self):
self.firstSection = True
self.header = \
"""# This file is created by generate_build_files.py. Do not edit manually.
"""
def PrintVariableSection(self, out, name, files):
if not self.firstSection:
out.write('\n')
self.firstSection = False
out.write('%s = [\n' % name)
for f in sorted(files):
out.write(' "%s",\n' % PathOf(f))
out.write(']\n')
def WriteFiles(self, files):
with open('BUILD.generated.bzl', 'w+') as out:
out.write(self.header)
self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
self.PrintVariableSection(out, 'fips_fragments', files['fips_fragments'])
self.PrintVariableSection(
out, 'ssl_internal_headers', files['ssl_internal_headers'])
self.PrintVariableSection(out, 'ssl_sources', files['ssl'])
self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
self.PrintVariableSection(
out, 'crypto_internal_headers', files['crypto_internal_headers'])
self.PrintVariableSection(out, 'crypto_sources', files['crypto'])
self.PrintVariableSection(out, 'crypto_sources_asm', files['crypto_asm'])
self.PrintVariableSection(out, 'crypto_sources_nasm', files['crypto_nasm'])
self.PrintVariableSection(out, 'pki_headers', files['pki_headers'])
self.PrintVariableSection(
out, 'pki_internal_headers', files['pki_internal_headers'])
self.PrintVariableSection(out, 'pki_sources', files['pki'])
self.PrintVariableSection(out, 'rust_bssl_sys', files['rust_bssl_sys'])
self.PrintVariableSection(out, 'rust_bssl_crypto', files['rust_bssl_crypto'])
self.PrintVariableSection(out, 'tool_sources', files['tool'])
self.PrintVariableSection(out, 'tool_headers', files['tool_headers'])
with open('BUILD.generated_tests.bzl', 'w+') as out:
out.write(self.header)
out.write('test_support_sources = [\n')
for filename in sorted(files['test_support'] +
files['test_support_headers'] +
files['crypto_internal_headers'] +
files['pki_internal_headers'] +
files['ssl_internal_headers']):
out.write(' "%s",\n' % PathOf(filename))
out.write(']\n')
self.PrintVariableSection(out, 'crypto_test_sources',
files['crypto_test'])
self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
self.PrintVariableSection(out, 'pki_test_sources',
files['pki_test'])
self.PrintVariableSection(out, 'crypto_test_data',
files['crypto_test_data'])
self.PrintVariableSection(out, 'pki_test_data',
files['pki_test_data'])
self.PrintVariableSection(out, 'urandom_test_sources',
files['urandom_test'])
class Eureka(object):
def __init__(self):
self.header = LicenseHeader("#") + """
# This file is created by generate_build_files.py. Do not edit manually.
"""
def PrintVariableSection(self, out, name, files):
out.write('%s := \\\n' % name)
for f in sorted(files):
out.write(' %s\\\n' % f)
out.write('\n')
def WriteFiles(self, files):
# Legacy Android.mk format
with open('eureka.mk', 'w+') as makefile:
makefile.write(self.header)
self.PrintVariableSection(makefile, 'crypto_sources', files['crypto'])
self.PrintVariableSection(makefile, 'crypto_sources_asm',
files['crypto_asm'])
self.PrintVariableSection(makefile, 'crypto_sources_nasm',
files['crypto_nasm'])
self.PrintVariableSection(makefile, 'ssl_sources', files['ssl'])
self.PrintVariableSection(makefile, 'tool_sources', files['tool'])
class GN(object):
def __init__(self):
self.firstSection = True
self.header = LicenseHeader("#") + """
# This file is created by generate_build_files.py. Do not edit manually.
"""
def PrintVariableSection(self, out, name, files):
if not self.firstSection:
out.write('\n')
self.firstSection = False
if len(files) == 0:
out.write('%s = []\n' % name)
elif len(files) == 1:
out.write('%s = [ "%s" ]\n' % (name, files[0]))
else:
out.write('%s = [\n' % name)
for f in sorted(files):
out.write(' "%s",\n' % f)
out.write(']\n')
def WriteFiles(self, files):
with open('BUILD.generated.gni', 'w+') as out:
out.write(self.header)
self.PrintVariableSection(out, 'crypto_sources',
files['crypto'] +
files['crypto_internal_headers'])
self.PrintVariableSection(out, 'crypto_sources_asm', files['crypto_asm'])
self.PrintVariableSection(out, 'crypto_sources_nasm',
files['crypto_nasm'])
self.PrintVariableSection(out, 'crypto_headers', files['crypto_headers'])
self.PrintVariableSection(out, 'rust_bssl_sys', files['rust_bssl_sys'])
self.PrintVariableSection(out, 'rust_bssl_crypto',
files['rust_bssl_crypto'])
self.PrintVariableSection(out, 'ssl_sources',
files['ssl'] + files['ssl_internal_headers'])
self.PrintVariableSection(out, 'ssl_headers', files['ssl_headers'])
self.PrintVariableSection(out, 'pki_sources', files['pki'])
self.PrintVariableSection(out, 'pki_internal_headers',
files['pki_internal_headers'])
self.PrintVariableSection(out, 'pki_headers', files['pki_headers'])
self.PrintVariableSection(out, 'tool_sources',
files['tool'] + files['tool_headers'])
fuzzers = [os.path.splitext(os.path.basename(fuzzer))[0]
for fuzzer in files['fuzz']]
self.PrintVariableSection(out, 'fuzzers', fuzzers)
with open('BUILD.generated_tests.gni', 'w+') as out:
self.firstSection = True
out.write(self.header)
self.PrintVariableSection(out, 'test_support_sources',
files['test_support'] +
files['test_support_headers'])
self.PrintVariableSection(out, 'crypto_test_sources',
files['crypto_test'])
self.PrintVariableSection(out, 'crypto_test_data',
files['crypto_test_data'])
self.PrintVariableSection(out, 'pki_test_data',
files['pki_test_data'])
self.PrintVariableSection(out, 'ssl_test_sources', files['ssl_test'])
self.PrintVariableSection(out, 'pki_test_sources', files['pki_test'])
class GYP(object):
def __init__(self):
self.header = LicenseHeader("#") + """
# This file is created by generate_build_files.py. Do not edit manually.
"""
def PrintVariableSection(self, out, name, files):
out.write(' \'%s\': [\n' % name)
for f in sorted(files):
out.write(' \'%s\',\n' % f)
out.write(' ],\n')
def WriteFiles(self, files):
with open('boringssl.gypi', 'w+') as gypi:
gypi.write(self.header + '{\n \'variables\': {\n')
self.PrintVariableSection(gypi, 'boringssl_ssl_sources',
files['ssl'] + files['ssl_headers'] +
files['ssl_internal_headers'])
self.PrintVariableSection(gypi, 'boringssl_crypto_sources',
files['crypto'] + files['crypto_headers'] +
files['crypto_internal_headers'])
self.PrintVariableSection(gypi, 'boringssl_crypto_asm_sources',
files['crypto_asm'])
self.PrintVariableSection(gypi, 'boringssl_crypto_nasm_sources',
files['crypto_nasm'])
gypi.write(' }\n}\n')
class CMake(object):
def __init__(self):
self.header = LicenseHeader("#") + R'''
# This file is created by generate_build_files.py. Do not edit manually.
cmake_minimum_required(VERSION 3.16)
project(BoringSSL LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-common -fno-exceptions -fno-rtti")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fno-common")
endif()
# pthread_rwlock_t requires a feature flag on glibc.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
endif()
if(WIN32)
add_definitions(-D_HAS_EXCEPTIONS=0)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)
# Allow use of fopen.
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_definitions(-DBORINGSSL_IMPLEMENTATION)
if(OPENSSL_NO_ASM)
add_definitions(-DOPENSSL_NO_ASM)
else()
# On x86 and x86_64 Windows, we use the NASM output.
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86")
enable_language(ASM_NASM)
set(OPENSSL_NASM TRUE)
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
else()
enable_language(ASM)
set(OPENSSL_ASM TRUE)
# Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older
# CMake versions.
if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19)
if(CMAKE_OSX_SYSROOT)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
endif()
foreach(arch ${CMAKE_OSX_ARCHITECTURES})
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
endforeach()
endif()
if(NOT WIN32)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
endif()
# Clang's integerated assembler does not support debug symbols.
if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
endif()
endif()
endif()
if(BUILD_SHARED_LIBS)
add_definitions(-DBORINGSSL_SHARED_LIBRARY)
# Enable position-independent code globally. This is needed because
# some library targets are OBJECT libraries.
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
'''
def PrintLibrary(self, out, name, files, libs=[]):
out.write('add_library(\n')
out.write(' %s\n\n' % name)
for f in sorted(files):
out.write(' %s\n' % PathOf(f))
out.write(')\n\n')
if libs:
out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
def PrintExe(self, out, name, files, libs):
out.write('add_executable(\n')
out.write(' %s\n\n' % name)
for f in sorted(files):
out.write(' %s\n' % PathOf(f))
out.write(')\n\n')
out.write('target_link_libraries(%s %s)\n\n' % (name, ' '.join(libs)))
def PrintVariable(self, out, name, files):
out.write('set(\n')
out.write(' %s\n\n' % name)
for f in sorted(files):
out.write(' %s\n' % PathOf(f))
out.write(')\n\n')
def WriteFiles(self, files):
with open('CMakeLists.txt', 'w+') as cmake:
cmake.write(self.header)
self.PrintVariable(cmake, 'CRYPTO_SOURCES_ASM', files['crypto_asm'])
self.PrintVariable(cmake, 'CRYPTO_SOURCES_NASM', files['crypto_nasm'])
cmake.write(
R'''if(OPENSSL_ASM)
list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_ASM})
endif()
if(OPENSSL_NASM)
list(APPEND CRYPTO_SOURCES_ASM_USED ${CRYPTO_SOURCES_NASM})
endif()
''')
self.PrintLibrary(cmake, 'crypto',
files['crypto'] + ['${CRYPTO_SOURCES_ASM_USED}'])
cmake.write('target_include_directories(crypto PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include>)\n\n')
self.PrintLibrary(cmake, 'ssl', files['ssl'], ['crypto'])
self.PrintExe(cmake, 'bssl', files['tool'], ['ssl', 'crypto'])
cmake.write(
R'''if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
find_package(Threads REQUIRED)
target_link_libraries(crypto Threads::Threads)
endif()
if(WIN32)
target_link_libraries(crypto ws2_32)
endif()
''')
class JSON(object):
def WriteFiles(self, files):
with open('sources.json', 'w+') as f:
json.dump(files, f, sort_keys=True, indent=2)
def NoTestsNorFIPSFragments(path, dent, is_dir):
return (NoTests(path, dent, is_dir) and
(is_dir or not OnlyFIPSFragments(path, dent, is_dir)))
def NoTests(path, dent, is_dir):
"""Filter function that can be passed to FindCFiles in order to remove test
sources."""
if is_dir:
return dent != 'test'
return 'test.' not in dent
def AllFiles(path, dent, is_dir):
"""Filter function that can be passed to FindCFiles in order to include all
sources."""
return True
def NoTestRunnerFiles(path, dent, is_dir):
"""Filter function that can be passed to FindCFiles or FindHeaderFiles in
order to exclude test runner files."""
# NOTE(martinkr): This prevents .h/.cc files in src/ssl/test/runner, which
# are in their own subpackage, from being included in boringssl/BUILD files.
return not is_dir or dent != 'runner'
def FindCFiles(directory, filter_func):
"""Recurses through directory and returns a list of paths to all the C source
files that pass filter_func."""
cfiles = []
for (path, dirnames, filenames) in os.walk(directory):
for filename in filenames:
if not filename.endswith('.c') and not filename.endswith('.cc'):
continue
if not filter_func(path, filename, False):
continue
cfiles.append(os.path.join(path, filename))
for (i, dirname) in enumerate(dirnames):
if not filter_func(path, dirname, True):
del dirnames[i]
cfiles.sort()
return cfiles
def FindHeaderFiles(directory, filter_func):
"""Recurses through directory and returns a list of paths to all the header files that pass filter_func."""
hfiles = []
for (path, dirnames, filenames) in os.walk(directory):
for filename in filenames:
if not filename.endswith('.h'):
continue
if not filter_func(path, filename, False):
continue
hfiles.append(os.path.join(path, filename))
for (i, dirname) in enumerate(dirnames):
if not filter_func(path, dirname, True):
del dirnames[i]
hfiles.sort()
return hfiles
def PrefixWithSrc(files):
return ['src/' + x for x in files]
def main(platforms):
with open(os.path.join('src', 'gen', 'sources.json')) as f:
sources = json.load(f)
# TODO(crbug.com/boringssl/542): generate_build_files.py historically reported
# all the assembly files as part of libcrypto. Merge them for now, but we
# should split them out later.
crypto = sorted(sources['bcm']['srcs'] + sources['crypto']['srcs'])
crypto_asm = sorted(sources['bcm']['asm'] + sources['crypto']['asm'] +
sources['test_support']['asm'])
crypto_nasm = sorted(sources['bcm']['nasm'] + sources['crypto']['nasm'] +
sources['test_support']['nasm'])
if EMBED_TEST_DATA:
with open('crypto_test_data.cc', 'w+') as out:
subprocess.check_call(
['go', 'run', 'util/embed_test_data.go'] + sources['crypto_test']['data'],
cwd='src',
stdout=out)
files = {
'bcm_crypto': PrefixWithSrc(sources['bcm']['srcs']),
'crypto': PrefixWithSrc(crypto),
'crypto_asm': PrefixWithSrc(crypto_asm),
'crypto_nasm': PrefixWithSrc(crypto_nasm),
'crypto_headers': PrefixWithSrc(sources['crypto']['hdrs']),
'crypto_internal_headers':
PrefixWithSrc(sources['crypto']['internal_hdrs']),
'crypto_test': PrefixWithSrc(sources['crypto_test']['srcs']),
'crypto_test_data': PrefixWithSrc(sources['crypto_test']['data']),
'fips_fragments': PrefixWithSrc(sources['bcm']['internal_hdrs']),
'fuzz': PrefixWithSrc(sources['fuzz']['srcs']),
'pki': PrefixWithSrc(sources['pki']['srcs']),
'pki_headers': PrefixWithSrc(sources['pki']['hdrs']),
'pki_internal_headers': PrefixWithSrc(sources['pki']['internal_hdrs']),
'pki_test': PrefixWithSrc(sources['pki_test']['srcs']),
'pki_test_data': PrefixWithSrc(sources['pki_test']['data']),
'rust_bssl_crypto': PrefixWithSrc(sources['rust_bssl_crypto']['srcs']),
'rust_bssl_sys': PrefixWithSrc(sources['rust_bssl_sys']['srcs']),
'ssl': PrefixWithSrc(sources['ssl']['srcs']),
'ssl_headers': PrefixWithSrc(sources['ssl']['hdrs']),
'ssl_internal_headers': PrefixWithSrc(sources['ssl']['internal_hdrs']),
'ssl_test': PrefixWithSrc(sources['ssl_test']['srcs']),
'tool': PrefixWithSrc(sources['bssl']['srcs']),
'tool_headers': PrefixWithSrc(sources['bssl']['internal_hdrs']),
'test_support': PrefixWithSrc(sources['test_support']['srcs']),
'test_support_headers':
PrefixWithSrc(sources['test_support']['internal_hdrs']),
'urandom_test': PrefixWithSrc(sources['urandom_test']['srcs']),
}
for platform in platforms:
platform.WriteFiles(files)
return 0
ALL_PLATFORMS = {
'android': Android,
'android-cmake': AndroidCMake,
'bazel': Bazel,
'cmake': CMake,
'eureka': Eureka,
'gn': GN,
'gyp': GYP,
'json': JSON,
}
if __name__ == '__main__':
parser = optparse.OptionParser(
usage='Usage: %%prog [--prefix=<path>] [all|%s]' %
'|'.join(sorted(ALL_PLATFORMS.keys())))
parser.add_option('--prefix', dest='prefix',
help='For Bazel, prepend argument to all source files')
parser.add_option(
'--embed_test_data', dest='embed_test_data', action='store_true',
help='Generates the legacy crypto_test_data.cc file. To use, build with' +
' -DBORINGSSL_CUSTOM_GET_TEST_DATA and add this file to ' +
'crypto_test.')
options, args = parser.parse_args(sys.argv[1:])
PREFIX = options.prefix
EMBED_TEST_DATA = options.embed_test_data
if not args:
parser.print_help()
sys.exit(1)
if 'all' in args:
platforms = [platform() for platform in ALL_PLATFORMS.values()]
else:
platforms = []
for s in args:
platform = ALL_PLATFORMS.get(s)
if platform is None:
parser.print_help()
sys.exit(1)
platforms.append(platform())
sys.exit(main(platforms))