1 import com.android.ndkports.AdHocPortTask
2 import com.android.ndkports.AndroidExecutableTestTask
3 import com.android.ndkports.CMakeCompatibleVersion
4
5 val portVersion = "3.2.1"
6
7 group = "com.android.ndk.thirdparty"
8 version = "$portVersion${rootProject.extra.get("snapshotSuffix")}"
9
<lambda>null10 plugins {
11 id("maven-publish")
12 id("com.android.ndkports.NdkPorts")
13 distribution
14 }
15
<lambda>null16 ndkPorts {
17 ndkPath.set(File(project.findProperty("ndkPath") as String))
18 source.set(project.file("src.tar.gz"))
19 minSdkVersion.set(21)
20 }
21
<lambda>null22 val buildTask = tasks.register<AdHocPortTask>("buildPort") {
23 builder {
24 run {
25 args(
26 sourceDirectory.resolve("Configure").absolutePath,
27 "android-${toolchain.abi.archName}",
28 "-D__ANDROID_API__=${toolchain.api}",
29 "--prefix=${installDirectory.absolutePath}",
30 "--openssldir=${installDirectory.absolutePath}",
31 "no-sctp",
32 "shared"
33 )
34
35 env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
36 env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
37 }
38
39 run {
40 args("make", "-j$ncpus", "SHLIB_EXT=.so")
41
42 env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
43 env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
44 }
45
46 run {
47 args("make", "install_sw", "SHLIB_EXT=.so")
48
49 env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
50 env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
51 }
52 }
53 }
54
<lambda>null55 tasks.prefabPackage {
56 version.set(CMakeCompatibleVersion.parse(portVersion))
57
58 licensePath.set("LICENSE.txt")
59
60 modules {
61 create("crypto")
62 create("ssl")
63 }
64 }
65
<lambda>null66 tasks.register<AndroidExecutableTestTask>("test") {
67 val srcDir = tasks.extractSrc.get().outDir.asFile.get()
68 val testSrc = srcDir.resolve("test/ssl-tests")
69 val deviceTestRelPath = File("testconf")
70
71 val unsupportedTests = listOf(
72 // This test is empty and appears to just be broken in 1.1.1k.
73 "16-certstatus.conf",
74 // zlib support is not enabled.
75 "22-compression.conf",
76 // Android does not support SCTP sockets and this test requires them.
77 "29-dtls-sctp-label-bug.conf"
78 )
79
80 push {
81 val ignoredExtensions = listOf("o", "d")
82 val buildDirectory = buildTask.get().buildDirectoryFor(abi)
83 push(
84 srcDir.resolve("test/ct/log_list.conf"), File("log_list.conf")
85 )
86 for (file in buildDirectory.walk()) {
87 if (!file.isFile) {
88 continue
89 }
90
91 if (file.extension in ignoredExtensions) {
92 continue
93 }
94
95 push(file, file.relativeTo(buildDirectory))
96 }
97 for (file in testSrc.walk()) {
98 if (file.extension == "conf") {
99 push(
100 file, deviceTestRelPath.resolve(file.relativeTo(testSrc))
101 )
102 }
103 }
104 push(srcDir.resolve("test/certs"), File("certs"))
105 }
106
107 run {
108 // https://github.com/openssl/openssl/blob/master/test/README.ssltest.md
109 val sslTest = deviceDirectory.resolve("test/ssl_test")
110 val ctlogFile = deviceDirectory.resolve("log_list.conf")
111 val testCertDir = deviceDirectory.resolve("certs")
112 for (file in testSrc.walk()) {
113 val test = deviceDirectory.resolve(deviceTestRelPath)
114 .resolve(file.relativeTo(testSrc))
115 if (file.extension == "conf" && file.name !in unsupportedTests) {
116 shellTest(
117 file.relativeTo(testSrc).toString(), listOf(
118 "LD_LIBRARY_PATH=$deviceDirectory",
119 "CTLOG_FILE=$ctlogFile",
120 "TEST_CERTS_DIR=$testCertDir",
121 sslTest.toString(),
122 test.toString()
123 )
124 )
125 }
126 }
127 }
128 }
129
<lambda>null130 publishing {
131 publications {
132 create<MavenPublication>("maven") {
133 from(components["prefab"])
134 pom {
135 name.set("OpenSSL")
136 description.set("The ndkports AAR for OpenSSL.")
137 url.set(
138 "https://android.googlesource.com/platform/tools/ndkports"
139 )
140 licenses {
141 license {
142 name.set("Dual OpenSSL and SSLeay License")
143 url.set("https://www.openssl.org/source/license-openssl-ssleay.txt")
144 distribution.set("repo")
145 }
146 }
147 developers {
148 developer {
149 name.set("The Android Open Source Project")
150 }
151 }
152 scm {
153 url.set("https://android.googlesource.com/platform/tools/ndkports")
154 connection.set("scm:git:https://android.googlesource.com/platform/tools/ndkports")
155 }
156 }
157 }
158 }
159
160 repositories {
161 maven {
162 url = uri("${project.buildDir}/repository")
163 }
164 }
165 }
166
<lambda>null167 distributions {
168 main {
169 contents {
170 from("${project.buildDir}/repository")
171 include("**/*.aar")
172 include("**/*.pom")
173 }
174 }
175 }
176
<lambda>null177 tasks {
178 distZip {
179 dependsOn("publish")
180 destinationDirectory.set(File(rootProject.buildDir, "distributions"))
181 }
182 }
183