forked from corretto/amazon-corretto-crypto-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
496 lines (433 loc) · 16.1 KB
/
build.gradle
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
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import groovy.xml.*
plugins {
id 'maven-publish'
id 'signing'
}
group = 'software.amazon.cryptools'
version = '1.7.0'
def openssl_version = '1.1.1n'
def opensslSrcPath = "${buildDir}/openssl/openssl-${openssl_version}"
configurations {
openssl
jacocoAgent
testDep.extendsFrom(jacocoAgent)
stagingJar
testRunner
}
repositories {
mavenCentral {
content { excludeGroup("openssl-src") }
}
// Fake Ivy Repository for current OpenSSL sources
ivy {
url 'https://www.openssl.org/source/'
patternLayout {
artifact '/[module]-[revision].[ext]'
}
metadataSources { artifact() }
content { includeGroup("openssl-src") }
}
// Fake Ivy Repository for old OpenSSL sources
ivy {
url 'https://www.openssl.org/source/old/1.1.1/'
patternLayout {
artifact '/[module]-[revision].[ext]'
}
metadataSources { artifact() }
content { includeGroup("openssl-src") }
}
}
dependencies {
// Separate so we can extract the jar for the agent specifically
jacocoAgent group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.7', classifier: 'runtime'
// Separate so we can extract the jar for the runner specifically
testRunner group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: '1.6.2'
testDep 'org.junit.jupiter:junit-jupiter:5.6.2'
testDep 'org.junit.vintage:junit-vintage-engine:5.6.2'
testDep 'org.bouncycastle:bcprov-debug-jdk15on:1.69'
testDep 'org.bouncycastle:bcpkix-jdk15on:1.69'
testDep 'commons-codec:commons-codec:1.12'
testDep 'org.hamcrest:hamcrest:2.1'
testDep 'org.jacoco:org.jacoco.core:0.8.3'
testDep 'org.jacoco:org.jacoco.report:0.8.3'
openssl "openssl-src:openssl:${openssl_version}@tar.gz"
}
defaultTasks 'release'
task getOpensslSrc(type: Copy) {
def tarPath = project.configurations.openssl.find {it.name.startsWith("openssl-") }
def tarFile = file(tarPath)
doFirst {
exec {
workingDir tarFile.parent
commandLine 'sha256sum', '--check', "${projectDir}/openssl.sha256"
}
mkdir "${buildDir}/openssl/bin"
}
def outputDir = file("${buildDir}/openssl/")
from tarTree(tarFile)
into outputDir
}
task buildOpenSsl {
outputs.dir("${buildDir}/openssl/bin/")
dependsOn getOpensslSrc
doLast {
exec {
workingDir opensslSrcPath
executable './config'
args '-fPIC', '-ffunction-sections', '-fdata-sections', "--prefix=${buildDir}/openssl/bin"
args 'no-autoload-config', 'no-capieng', 'no-cms', 'no-comp', 'no-ct', 'no-dgram', 'no-devcryptoeng'
args 'no-gost', 'no-hw-padlock', 'no-nextprotoneg', 'no-ocsp', 'no-psk', 'no-rfc3779', 'no-shared'
args 'no-sock', 'no-srp', 'no-srtp', 'threads', 'no-ts', "no-bf", "no-cast", "no-md2", "no-rc2"
args "no-rc4", "no-rc5", "no-srp", 'no-comp', 'no-hw', 'no-mdc2'
}
exec {
workingDir opensslSrcPath
commandLine 'make', 'depend'
}
exec {
workingDir opensslSrcPath
commandLine 'make', '-j', Runtime.runtime.availableProcessors()
}
exec {
workingDir opensslSrcPath
commandLine 'make', 'install_sw'
}
}
}
task executeCmake(type: Exec) {
outputs.dir("${buildDir}/cmake")
inputs.dir("${buildDir}/openssl/bin/")
inputs.dir("${projectDir}/src")
inputs.dir("${projectDir}/tst")
inputs.dir("${projectDir}/csrc")
inputs.dir("${projectDir}/CMake")
inputs.dir("${projectDir}/etc")
inputs.dir("${projectDir}/extra-jar-files")
inputs.dir("${projectDir}/test-data")
inputs.dir("${projectDir}/template-src")
dependsOn buildOpenSsl
workingDir "${buildDir}/cmake"
def prebuiltJar = null
if (project.hasProperty('stagingUrl')) {
mkdir "${buildDir}/tmp"
exec {
workingDir "${buildDir}/tmp"
commandLine 'wget', "${stagingUrl}/software/amazon/cryptools/${project.name}/${stagingVersion}/${project.name}-${stagingVersion}-linux-x86_64.jar"
}
prebuiltJar = "${buildDir}/tmp/${project.name}-${stagingVersion}-linux-x86_64.jar"
} else if (System.properties['prebuiltJar'] != null) {
prebuiltJar = "${projectDir}/" + System.properties['prebuiltJar']
}
executable 'cmake'
args 'cmake', "-DTEST_CLASSPATH=${configurations.testDep.asPath}", "-DJACOCO_AGENT_JAR=${configurations.jacocoAgent.singleFile}"
args "-DOPENSSL_ROOT_DIR=${buildDir}/openssl/bin", '-DCMAKE_BUILD_TYPE=Release', '-DPROVIDER_VERSION_STRING=' + version
args "-DTEST_RUNNER_JAR=${configurations.testRunner.singleFile}"
if (prebuiltJar != null) {
args '-DSIGNED_JAR=' + prebuiltJar
}
if (System.properties['TEST_JAVA_HOME'] != null) {
args '-DTEST_JAVA_HOME=' + System.properties['TEST_JAVA_HOME']
}
if (System.properties['TEST_JAVA_MAJOR_VERSION'] != null) {
args '-DTEST_JAVA_MAJOR_VERSION=' + System.properties['TEST_JAVA_MAJOR_VERSION']
}
if (System.properties['SINGLE_TEST'] != null) {
args '-DSINGLE_TEST=' + System.properties['SINGLE_TEST']
}
args projectDir
}
task build_objects(type: Exec) {
dependsOn executeCmake
outputs.file("${buildDir}/cmake/AmazonCorrettoCryptoProvider.jar")
workingDir "${buildDir}/cmake"
commandLine 'make', '-j', Runtime.runtime.availableProcessors(), 'accp-jar'
}
task build(overwrite:true) {
dependsOn build_objects
outputs.file("${buildDir}/lib/AmazonCorrettoCryptoProvider.jar")
doLast {
mkdir "${buildDir}/lib"
if (project.hasProperty('jcecertAlias')) {
ant.signjar(
alias: jcecertAlias,
jar: "${buildDir}/cmake/AmazonCorrettoCryptoProvider.jar",
destDir: "${buildDir}/lib",
storepass: jcecertPassword,
keystore: "${project.gradle.gradleUserHomeDir}/${jcecertJks}",
tsaurl: "http://timestamp.digicert.com"
)
} else {
copy {
from("${buildDir}/cmake") {
include 'AmazonCorrettoCryptoProvider.jar'
}
into "${buildDir}/lib"
}
}
}
}
task emptyJar(type: Jar) {
archiveFileName = 'empty.jar'
archiveClassifier = null
destinationDirectory = file("${buildDir}/lib")
}
task javadoc(type: Jar) {
dependsOn executeCmake
doFirst {
mkdir "${buildDir}/lib"
exec {
workingDir "${buildDir}/cmake"
commandLine 'make', 'javadoc'
}
}
archiveFileName = 'AmazonCorrettoCryptoProvider-javadoc.jar'
archiveClassifier = 'javadoc'
destinationDirectory = file("${buildDir}/lib")
from "${buildDir}/cmake/javadoc/AmazonCorrettoCryptoProvider/"
}
task src_jar {
dependsOn executeCmake
outputs.file("${buildDir}/lib/AmazonCorrettoCryptoProvider-sources.jar")
doLast {
mkdir "${buildDir}/lib"
exec {
workingDir "${buildDir}/cmake"
commandLine 'make', 'accp-jar-source'
}
copy {
from("${buildDir}/cmake") {
include 'AmazonCorrettoCryptoProvider-sources.jar'
}
into "${buildDir}/lib"
}
}
}
task test_extra_checks(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-junit-extra-checks'
}
task test(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check'
}
task single_test(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-junit-single'
}
task test_integration(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-integration'
}
task test_integration_extra_checks(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-integration-extra-checks'
}
task dieharder(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-dieharder'
}
task dieharder_threads(type: Exec) {
dependsOn executeCmake
workingDir "${buildDir}/cmake"
commandLine 'make', 'check-dieharder-threads'
}
task dieharder_all {
dependsOn dieharder, dieharder_threads
}
task coverage_clean(type: Delete) {
delete fileTree("${buildDir}/cmake-coverage") {
include '**/*.gcda'
}
delete "${buildDir}/reports/cpp"
}
task coverage_cmake(type: Exec) {
dependsOn coverage_clean, buildOpenSsl
doFirst {
if (System.properties['prebuiltJar'] != null) {
ant.fail("Cannot run coverage with a prebuilt jar")
}
mkdir "${buildDir}/cmake-coverage"
}
workingDir "${buildDir}/cmake-coverage"
executable 'cmake'
args "-DTEST_CLASSPATH=${configurations.testDep.asPath}"
args "-DJACOCO_AGENT_JAR=${configurations.jacocoAgent.singleFile}"
args "-DOPENSSL_ROOT_DIR=${buildDir}/openssl/bin"
args '-DCMAKE_BUILD_TYPE=Coverage', '-DCOVERAGE=ON', '-DENABLE_NATIVE_TEST_HOOKS=ON'
args '-DPROVIDER_VERSION_STRING=' + version, projectDir
args "-DTEST_RUNNER_JAR=${configurations.testRunner.singleFile}"
if (System.properties['SINGLE_TEST'] != null) {
args '-DSINGLE_TEST=' + System.properties['SINGLE_TEST']
}
}
task coverage_exec(type: Exec) {
dependsOn coverage_cmake, coverage_clean
doFirst {
if (System.properties['prebuiltJar'] != null) {
ant.fail("Cannot run coverage with a prebuilt jar")
}
}
workingDir "${buildDir}/cmake-coverage"
commandLine 'make', 'coverage'
}
task coverage_java_report(type: Copy) {
doFirst {
mkdir "${buildDir}/reports/java"
}
dependsOn coverage_exec
from "${buildDir}/cmake-coverage/coverage/results/html/"
into "${buildDir}/reports/java"
}
task coverage_cpp_report {
dependsOn coverage_exec
doFirst {
mkdir "${buildDir}/reports/cpp"
}
doLast {
exec {
workingDir "${buildDir}/cmake-coverage"
commandLine 'lcov', '--capture', '--directory', "${buildDir}/cmake-coverage/CMakeFiles/amazonCorrettoCryptoProvider.dir/csrc", '--output-file', "${buildDir}/cmake-coverage/coverage.info", '--rc', 'lcov_branch_coverage=1'
}
// Convert absolute to relative paths
exec {
workingDir "${buildDir}/cmake-coverage"
commandLine 'perl', '-i', '-pe', "s[^SF:${projectDir}/*][SF:]", "${buildDir}/cmake-coverage/coverage.info"
}
// lcov captures coverage data for inline functions in system headers; strip this out to avoid
// polluting our metrics with unused STL code.
exec {
workingDir "${buildDir}/cmake-coverage"
commandLine 'lcov', '-e', "${buildDir}/cmake-coverage/coverage.info", 'csrc/*', '--rc', 'lcov_branch_coverage=1'
standardOutput = new FileOutputStream("${buildDir}/reports/cpp/coverage.info")
}
exec {
workingDir projectDir
commandLine 'genhtml', '-o', "${buildDir}/reports/cpp", '--rc', 'genhtml_branch_coverage=1', "${buildDir}/reports/cpp/coverage.info"
}
}
}
task coverage {
dependsOn coverage_java_report, coverage_cpp_report
}
task release {
dependsOn build, test, coverage, javadoc, src_jar
}
task overkill {
dependsOn test, test_extra_checks, test_integration, test_integration_extra_checks, dieharder_all
}
if (project.hasProperty('mavenUser') && project.hasProperty('jcecertAlias')) {
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = project.name
artifact source: file("${buildDir}/lib/AmazonCorrettoCryptoProvider.jar"),classifier:"linux-x86_64",extension:"jar"
artifact emptyJar
artifact javadoc
artifact source: file("${buildDir}/lib/AmazonCorrettoCryptoProvider-sources.jar"),classifier:"sources",extension:"jar"
pom {
name = "Amazon Corretto Crypto Provider"
description = 'The Amazon Corretto Crypto Provider (ACCP) is a collection of high-performance cryptographic implementations exposed via the standard JCA/JCE interfaces.'
url = 'https://github.com/corretto/amazon-corretto-crypto-provider'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
url = 'https://github.com/corretto/amazon-corretto-crypto-provider.git'
connection = 'scm:git:[email protected]:corretto/amazon-corretto-crypto-provider.git'
developerConnection = 'scm:git:[email protected]:corretto/amazon-corretto-crypto-provider.git'
}
developers {
developer {
id = 'amazonwebservices'
organization = 'Amazon Web Services'
organizationUrl = 'https://aws.amazon.com'
}
}
}
}
}
repositories {
maven {
url = 'https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username mavenUser
password mavenPassword
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
} else {
task publish(overwrite: true) {
doFirst {
ant.fail('Insufficient configuration for publishing')
}
}
task sign {
doFirst {
ant.fail('Insufficient configuration for signing')
}
}
}
task clean(overwrite: true, type: Delete) {
delete "${buildDir}/cmake"
delete "${buildDir}/cmake-coverage"
delete "${buildDir}/lib"
delete "${buildDir}/reports"
delete "${buildDir}/publications"
}
task deep_clean(type: Delete) {
delete buildDir
}
task generateEclipseClasspath {
doLast {
file(".classpath").withWriter { writer ->
// Create MarkupBuilder with 4 space indent
def xml = new MarkupBuilder(new IndentPrinter(writer, " ", true))
xml.doubleQuotes = true
xml.mkp.xmlDeclaration(version: '1.0', encoding: 'utf-8')
xml.classpath {
classpathentry('kind': 'con', 'path': 'org.eclipse.jdt.launching.JRE_CONTAINER') {
attributes {
attribute('name': 'module', 'value': 'true')
}
}
classpathentry('kind': 'src', 'output': 'build/eclipse/src', 'path': 'src')
classpathentry('kind': 'src', 'output': 'build/eclipse/template-src', 'path': 'template-src')
classpathentry('kind': 'src', 'output': 'build/eclipse/tst', 'path': 'tst') {
attributes {
attribute('name': 'test', 'value': 'true')
}
}
classpathentry('kind': 'src', 'output': 'build/eclipse/src', 'path': 'build/cmake/generated-java') {
attributes {
attribute('name': 'optional', 'value': 'true')
}
}
classpathentry('kind': 'src', 'output': 'build/eclipse/src', 'path': 'build/coverage-cmake/generated-java') {
attributes {
attribute('name': 'optional', 'value': 'true')
}
}
configurations.testDep.files.each{f ->
classpathentry('kind': 'lib', 'path': f) {
attribute('name': 'test', 'value': 'true')
}
}
} // xml.classpath
} // file.withWriter
} // doLast
} // generateEclipseClasspath