• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.1l"
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 }
32 
<lambda>null33 ndkPorts {
34     ndkPath.set(File(project.findProperty("ndkPath") as String))
35     source.set(project.file("src.tar.gz"))
36     minSdkVersion.set(16)
37 }
38 
<lambda>null39 val buildTask = tasks.register<AdHocPortTask>("buildPort") {
40     builder {
41         run {
42             args(
43                 sourceDirectory.resolve("Configure").absolutePath,
44                 "android-${toolchain.abi.archName}",
45                 "-D__ANDROID_API__=${toolchain.api}",
46                 "--prefix=${installDirectory.absolutePath}",
47                 "--openssldir=${installDirectory.absolutePath}",
48                 "no-sctp",
49                 "shared"
50             )
51 
52             env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
53             env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
54         }
55 
56         run {
57             args("make", "-j$ncpus", "SHLIB_EXT=.so")
58 
59             env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
60             env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
61         }
62 
63         run {
64             args("make", "install_sw", "SHLIB_EXT=.so")
65 
66             env("ANDROID_NDK", toolchain.ndk.path.absolutePath)
67             env("PATH", "${toolchain.binDir}:${System.getenv("PATH")}")
68         }
69     }
70 }
71 
<lambda>null72 tasks.prefabPackage {
73     version.set(prefabVersion)
74 
75     modules {
76         create("crypto")
77         create("ssl")
78     }
79 }
80 
<lambda>null81 tasks.register<AndroidExecutableTestTask>("test") {
82     val srcDir = tasks.extractSrc.get().outDir.asFile.get()
83     val testSrc = srcDir.resolve("test/ssl-tests")
84     val deviceTestRelPath = File("testconf")
85 
86     val unsupportedTests = listOf(
87         // This test is empty and appears to just be broken in 1.1.1k.
88         "16-certstatus.conf",
89         // zlib support is not enabled.
90         "22-compression.conf",
91         // Android does not support SCTP sockets and this test requires them.
92         "29-dtls-sctp-label-bug.conf"
93     )
94 
95     push {
96         val ignoredExtensions = listOf("o", "d")
97         val buildDirectory = buildTask.get().buildDirectoryFor(abi)
98         push(
99             srcDir.resolve("test/ct/log_list.conf"), File("log_list.conf")
100         )
101         for (file in buildDirectory.walk()) {
102             if (!file.isFile) {
103                 continue
104             }
105 
106             if (file.extension in ignoredExtensions) {
107                 continue
108             }
109 
110             push(file, file.relativeTo(buildDirectory))
111         }
112         for (file in testSrc.walk()) {
113             if (file.extension == "conf") {
114                 push(
115                     file, deviceTestRelPath.resolve(file.relativeTo(testSrc))
116                 )
117             }
118         }
119         push(srcDir.resolve("test/certs"), File("certs"))
120     }
121 
122     run {
123         // https://github.com/openssl/openssl/blob/master/test/README.ssltest.md
124         val sslTest = deviceDirectory.resolve("test/ssl_test")
125         val ctlogFile = deviceDirectory.resolve("log_list.conf")
126         val testCertDir = deviceDirectory.resolve("certs")
127         for (file in testSrc.walk()) {
128             val test = deviceDirectory.resolve(deviceTestRelPath)
129                 .resolve(file.relativeTo(testSrc))
130             if (file.extension == "conf" && file.name !in unsupportedTests) {
131                 shellTest(
132                     file.relativeTo(testSrc).toString(), listOf(
133                         "LD_LIBRARY_PATH=$deviceDirectory",
134                         "CTLOG_FILE=$ctlogFile",
135                         "TEST_CERTS_DIR=$testCertDir",
136                         sslTest.toString(),
137                         test.toString()
138                     )
139                 )
140             }
141         }
142     }
143 }
144 
<lambda>null145 publishing {
146     publications {
147         create<MavenPublication>("maven") {
148             from(components["prefab"])
149             pom {
150                 name.set("OpenSSL")
151                 description.set("The ndkports AAR for OpenSSL.")
152                 url.set(
153                     "https://android.googlesource.com/platform/tools/ndkports"
154                 )
155                 licenses {
156                     license {
157                         name.set("Dual OpenSSL and SSLeay License")
158                         url.set("https://www.openssl.org/source/license-openssl-ssleay.txt")
159                         distribution.set("repo")
160                     }
161                 }
162                 developers {
163                     developer {
164                         name.set("The Android Open Source Project")
165                     }
166                 }
167                 scm {
168                     url.set("https://android.googlesource.com/platform/tools/ndkports")
169                     connection.set("scm:git:https://android.googlesource.com/platform/tools/ndkports")
170                 }
171             }
172         }
173     }
174 
175     repositories {
176         maven {
177             url = uri("${rootProject.buildDir}/repository")
178         }
179     }
180 }
181