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