@@ -14,123 +14,27 @@ import org.codehaus.groovy.runtime.InvokerHelper
14
14
15
15
description = ' Conscrypt: OpenJdk'
16
16
17
- // Gradle mostly uses Java os.arch names for architectures which feeds into default
18
- // targetPlatform names. Notable exception Gradle 6.9.x reports MacOS/ARM as
19
- // arm-v8.
20
- //
21
- // The Maven osdetector plugin (which we recommend to developers) uses different
22
- // arch names, so that's what we need for artifacts.
23
- //
24
- // This class encapsulates both naming schemes as well as other per-platform information
25
- // about native builds, more of which will migrate in here over time.
26
- enum NativeBuildInfo {
27
- WINDOWS_X86_64 (" windows" , " x86_64" ),
28
- LINUX_X86_64 (" linux" , " x86_64" ),
29
- MAC_X86_64 (" osx" , " x86_64" ) {
30
- String libDir () {
31
- " build.x86"
32
- }
33
- },
34
- MAC_AARCH64 (" osx" , " aarch_64" ) {
35
- String libDir() {
36
- " build.arm"
37
- }
38
- };
39
-
40
- static String buildDir = " FIXME" // See below
41
-
42
- public final String os
43
- public final String arch
44
-
45
- // Maps osdetector arch to Gradle equivalent.
46
- private static final gradleArchMap = [
47
- " aarch_64" : " aarch64" ,
48
- " x86_64" : " x86-64" ,
49
- ]
50
-
51
- NativeBuildInfo (String os, String arch) {
52
- this . os = os
53
- this . arch = arch
54
- }
55
-
56
- // Classifier as generated by Maven osdetector.
57
- String mavenClassifier () {
58
- " ${ os} -${ arch} "
59
- }
60
-
61
- // Gradle equivalent to Maven arch
62
- String gradleArch () {
63
- gradleArch(arch)
64
- }
65
-
66
- // Output directory for native resources
67
- String nativeResourcesDir () {
68
- " $buildDir /${ mavenClassifier()} /native-resources"
69
- }
70
-
71
- // Directory for native resources inside final jar.
72
- String jarNativeResourcesDir () {
73
- nativeResourcesDir() + ' /META-INF/native'
74
- }
75
-
76
- // Target platform identifier as used by Gradle
77
- String targetPlatform () {
78
- " ${ os} _${ gradleArch()} "
79
- }
80
-
81
- String libDir () {
82
- " build64"
83
- }
84
-
85
- static String gradleArch (String arch ) {
86
- gradleArchMap. get(arch)
87
- }
88
-
89
- static NativeBuildInfo findForGradle (String os , String arch ) {
90
- values(). find {
91
- it. os == os && it. gradleArch() == arch
92
- }
93
- }
94
-
95
- static NativeBuildInfo find (String os , String arch ) {
96
- values(). find {
97
- it. os == os && it. arch == arch
98
- }
99
- }
100
-
101
- static NativeBuildInfo find (NativePlatform targetPlatform ) {
102
- String targetOS = targetPlatform. operatingSystem. name
103
- String targetArch = targetPlatform. architecture. name
104
- def result = findForGradle(targetOS, targetArch)
105
- assert result != null : " Unknown target platform: ${ targetOS} -${ targetArch} "
106
- result
107
- }
108
-
109
- static findAll (String os ) {
110
- values(). findAll {
111
- it. os == os
112
- }
113
- }
114
- }
115
-
116
- // TODO: There has to be a better way of accessing Gradle properties from Groovy code than this
117
- NativeBuildInfo . buildDir = " $buildDir "
118
-
119
17
ext {
120
18
jniSourceDir = " $rootDir /common/src/jni"
121
19
assert file(" $jniSourceDir " ). exists()
122
20
123
21
// Decide which targets we should build and test
124
- nativeBuilds = NativeBuildInfo . findAll(" ${ osdetector.os} " )
125
- buildToTest = NativeBuildInfo . find(" ${ osdetector.os} " , " ${ osdetector.arch} " )
22
+ nativeResolver = new NativeBuildResolver (project. layout. buildDirectory)
23
+ nativeBuilds = nativeResolver. findAll(" ${ osdetector.os} " )
24
+ buildToTest = nativeResolver. find(" ${ osdetector.os} " , " ${ osdetector.arch} " )
126
25
127
26
assert ! nativeBuilds. isEmpty() : " No native builds selected."
128
27
assert buildToTest != null : " No test build selected for os.arch = ${ osdetector.arch} "
129
28
130
29
// Compatibility with other sub-projects
131
- preferredSourceSet = buildToTest. mavenClassifier()
132
- preferredNativeFileDir = buildToTest. nativeResourcesDir()
30
+ preferredSourceSet = buildToTest. mavenClassifier
31
+ preferredNativeFileDir = buildToTest. nativeResourcesDir
32
+ }
33
+
34
+ nativeBuilds. each { build ->
35
+ logger. warn(" Building native JNI for $build " )
133
36
}
37
+ logger. warn(" Testing against $buildToTest " )
134
38
135
39
// Since we're not taking a direct dependency on the constants module, we need to add an
136
40
// explicit task dependency to make sure the code is generated.
@@ -162,14 +66,14 @@ sourceSets {
162
66
srcDirs + = " ${ rootDir} /common/src/test/resources"
163
67
// This shouldn't be needed but seems to help IntelliJ locate the native artifact.
164
68
// srcDirs += preferredNativeFileDir
165
- srcDirs + = buildToTest. nativeResourcesDir()
69
+ srcDirs + = buildToTest. nativeResourcesDir
166
70
}
167
71
}
168
72
169
73
// Add the source sets for each of the native builds
170
- nativeBuilds. each { nativeBuild ->
171
- String sourceSetName = nativeBuild . mavenClassifier()
172
- String nativeDir = nativeBuild . nativeResourcesDir()
74
+ nativeBuilds. each { nativeBuildInfo ->
75
+ String sourceSetName = nativeBuildInfo . mavenClassifier
76
+ String nativeDir = nativeBuildInfo . nativeResourcesDir
173
77
174
78
// Main sources for the native build
175
79
" $sourceSetName " {
@@ -293,23 +197,23 @@ dependencies {
293
197
platformCompileOnly sourceSets. main. output
294
198
}
295
199
296
- nativeBuilds. each { nativeBuild ->
200
+ nativeBuilds. each { nativeBuildInfo ->
297
201
// Create the JAR task and add it's output to the published archives for this project
298
- addNativeJar(nativeBuild )
202
+ addNativeJar(nativeBuildInfo )
299
203
300
204
// Build the classes as part of the standard build.
301
- classes. dependsOn sourceSets[nativeBuild . mavenClassifier() ]. classesTaskName
205
+ classes. dependsOn sourceSets[nativeBuildInfo . mavenClassifier]. classesTaskName
302
206
}
303
207
304
208
// Adds a JAR task for the native library.
305
- def addNativeJar (NativeBuildInfo nativeBuild ) {
209
+ def addNativeJar (NativeBuildInfo nativeBuildInfo ) {
306
210
// Create a JAR for this configuration and add it to the output archives.
307
- SourceSet sourceSet = sourceSets[nativeBuild . mavenClassifier() ]
211
+ SourceSet sourceSet = sourceSets[nativeBuildInfo . mavenClassifier]
308
212
def jarTask = tasks. register(sourceSet. jarTaskName, Jar ) { Jar t ->
309
213
// Depend on the regular classes task
310
214
dependsOn classes
311
215
manifest = jar. manifest
312
- archiveClassifier = nativeBuild . mavenClassifier()
216
+ archiveClassifier = nativeBuildInfo . mavenClassifier
313
217
314
218
from sourceSet. output + sourceSets. main. output
315
219
@@ -392,8 +296,8 @@ model {
392
296
components {
393
297
// Builds the JNI library.
394
298
conscrypt_openjdk_jni(NativeLibrarySpec ) {
395
- nativeBuilds. each { nativeBuild ->
396
- targetPlatform nativeBuild . targetPlatform()
299
+ nativeBuilds. each { nativeBuildInfo ->
300
+ targetPlatform nativeBuildInfo . targetPlatform
397
301
}
398
302
399
303
sources {
@@ -410,8 +314,9 @@ model {
410
314
withType (SharedLibraryBinarySpec ) {
411
315
cppCompiler. define " CONSCRYPT_OPENJDK"
412
316
def jdkIncludeDir = jniIncludeDir()
413
- def nativeBuild = NativeBuildInfo . find(targetPlatform)
414
- String libPath = " $boringsslHome /${ nativeBuild.libDir()} "
317
+ def copy = targetPlatform
318
+ def nativeBuildInfo = nativeResolver. find(targetPlatform)
319
+ String libPath = boringsslHome + ' /' + nativeBuildInfo. boringBuildDir
415
320
416
321
if (toolChain in Clang || toolChain in Gcc ) {
417
322
cppCompiler. args " -Wall" ,
@@ -503,8 +408,8 @@ model {
503
408
504
409
tasks { t ->
505
410
$. binaries. withType(SharedLibraryBinarySpec ). each { binary ->
506
- def nativeBuild = NativeBuildInfo . find(binary. targetPlatform)
507
- def classifier = nativeBuild . mavenClassifier()
411
+ def nativeBuildInfo = nativeResolver . find(binary. targetPlatform)
412
+ def classifier = nativeBuildInfo . mavenClassifier
508
413
def source = binary. sharedLibraryFile
509
414
510
415
// Copies the native library to a resource location that will be included in the jar.
@@ -514,7 +419,7 @@ model {
514
419
// Rename the artifact to include the generated classifier
515
420
rename ' (.+)(\\ .[^\\ .]+)' , " \$ 1-$classifier \$ 2"
516
421
// Everything under will be included in the native jar.
517
- into nativeBuild . jarNativeResourcesDir()
422
+ into nativeBuildInfo . jarNativeResourcesDir
518
423
}
519
424
processResources {
520
425
dependsOn copyTask
0 commit comments