blob: 08b9ebd8bea40a4ba70968db220ba52ee6a772d4 [file] [log] [blame]
Kenny Rootebc029b2019-10-02 03:46:29 -07001import org.gradle.util.VersionNumber
2
nmittler7782d132016-11-22 11:34:01 -08003buildscript {
Kenny Root483541f2021-01-18 15:05:04 -08004 ext.android_tools = 'com.android.tools.build:gradle:4.1.0'
Pete Bentleyfc9750b2020-11-25 17:52:36 +00005 ext.errorproneVersion = '2.4.0'
Kenny Rootebc029b2019-10-02 03:46:29 -07006 ext.errorproneJavacVersion = '9+181-r4173-1'
nmittler7782d132016-11-22 11:34:01 -08007 repositories {
Kenny Root08e7ef92018-07-03 19:27:00 +09008 google()
Nathan Mittleree6f5782017-02-27 13:17:39 -08009 jcenter()
10 }
11 dependencies {
Kenny Root08e7ef92018-07-03 19:27:00 +090012 // This must be applied in the root project otherwise each subproject will
13 // have it in a different ClassLoader.
14 classpath android_tools
Kenny Rootebc029b2019-10-02 03:46:29 -070015 classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.0'
nmittler7782d132016-11-22 11:34:01 -080016 }
17}
18
Kenny Root08e7ef92018-07-03 19:27:00 +090019plugins {
Kenny Root57925792019-10-02 11:08:22 -070020 // Add dependency for build script so we can access Git from our
21 // build script.
Kenny Rootebc029b2019-10-02 03:46:29 -070022 id 'org.ajoberstar.grgit' version '3.1.1'
Pete Bentleyfc9750b2020-11-25 17:52:36 +000023 id 'net.ltgt.errorprone' version '1.3.0'
Kenny Root08e7ef92018-07-03 19:27:00 +090024}
25
nmittler7782d132016-11-22 11:34:01 -080026subprojects {
Adam Vartaniane56b72a2017-08-07 11:49:48 +010027 def androidProject = ((project.name == 'conscrypt-android')
28 || (project.name == 'conscrypt-android-platform')
29 || (project.name == 'conscrypt-benchmark-android')
30 || (project.name == 'conscrypt-benchmark-caliper'))
Kenny Root08e7ef92018-07-03 19:27:00 +090031 if (androidProject) {
32 repositories {
33 google()
34 }
35 } else {
36 apply plugin: 'java-library'
nmittler7782d132016-11-22 11:34:01 -080037 apply plugin: 'cpp'
Nathan Mittler36311a32016-12-22 13:19:59 -080038
39 model {
40 toolChains {
Kenny Root08e7ef92018-07-03 19:27:00 +090041 visualCpp(VisualCpp)
Nathan Mittler36311a32016-12-22 13:19:59 -080042 // Prefer Clang over Gcc (order here matters!)
43 clang(Clang)
44 gcc(Gcc)
45 }
46 }
nmittler7782d132016-11-22 11:34:01 -080047 }
nmittler7782d132016-11-22 11:34:01 -080048 apply plugin: "idea"
Adam Vartanianb216fa32019-09-27 15:27:12 +010049 apply plugin: "jacoco"
Kenny Roota679eec2017-03-16 14:51:10 -070050 apply plugin: "net.ltgt.errorprone"
nmittler7782d132016-11-22 11:34:01 -080051
52 group = "org.conscrypt"
53 description = 'Conscrypt is an alternate Java Security Provider that uses BoringSSL'
Pete Bentleya80a8492021-03-23 11:18:47 +000054 version = "2.6-SNAPSHOT"
nmittler7782d132016-11-22 11:34:01 -080055
56 ext {
Nathan Mittlerf998b642017-01-31 16:56:17 -080057 os = org.gradle.internal.os.OperatingSystem.current();
58 if (os.isLinux()) {
59 osName = "linux"
60 } else if (os.isMacOsX()) {
61 osName = "osx"
62 } else if (os.isWindows()) {
63 osName = "windows"
64 } else {
65 throw new GradleException("Unsupported os: " + os.name)
66 }
67
Ben Sidhom3b634222018-04-06 04:04:11 -070068 if (project.hasProperty("boringsslHome")) {
69 boringsslHome = project.property("boringsslHome")
70 } else {
71 boringsslHome = "$System.env.BORINGSSL_HOME"
72 }
73
Nathan Mittlerce593c82017-06-16 13:18:38 -070074 boringsslIncludeDir = normalizePath("$boringsslHome/include")
75 boringssl32BuildDir = normalizePath("$boringsslHome/build32")
76 boringssl64BuildDir = normalizePath("$boringsslHome/build64")
Ben Sidhom3b634222018-04-06 04:04:11 -070077
78 if (project.hasProperty("jdkHome")) {
79 jdkHome = project.property("jdkHome")
80 } else {
81 jdkHome = "$System.env.JAVA_HOME"
82 }
Nathan Mittlerce593c82017-06-16 13:18:38 -070083 jdkIncludeDir = normalizePath("$jdkHome/include")
nmittler7782d132016-11-22 11:34:01 -080084 // Needs to be binary compatible with androidMinSdkVersion
85 androidMinJavaVersion = JavaVersion.VERSION_1_7
nmittler7782d132016-11-22 11:34:01 -080086
Kenny Root0327d942017-01-12 12:09:20 -080087 build32Bit = file("$boringssl32BuildDir").exists()
88 build64Bit = file("$boringssl64BuildDir").exists()
89
nmittler7782d132016-11-22 11:34:01 -080090 // Ensure the environment is configured properly.
nmittler7782d132016-11-22 11:34:01 -080091 assert file("$boringsslHome").exists()
92 assert file("$boringsslIncludeDir").exists()
Kenny Root0327d942017-01-12 12:09:20 -080093 assert build32Bit || build64Bit
nmittler7782d132016-11-22 11:34:01 -080094 assert file("$jdkHome").exists()
95 assert file("$jdkIncludeDir").exists()
96
Nathan Mittleree6f5782017-02-27 13:17:39 -080097 // Get the commit hash for BoringSSL.
Kenny Root08e7ef92018-07-03 19:27:00 +090098 boringSslGit = org.ajoberstar.grgit.Grgit.open(dir: boringsslHome)
Nathan Mittleree6f5782017-02-27 13:17:39 -080099 boringSslVersion = boringSslGit.head().id
100
Nathan Mittler401f1c42017-08-15 10:12:26 -0700101 // Allow the java executable to be specified via env/property for each architecture.
102 javaExecutable32 = System.getProperty('javaExecutable32', System.env.CONSCRYPT_JAVA_EXECUTABLE_32)
103 javaExecutable64 = System.getProperty('javaExecutable64', System.env.CONSCRYPT_JAVA_EXECUTABLE_64)
104
Kenny Rootebc029b2019-10-02 03:46:29 -0700105 jmhVersion = '1.21'
nmittler7782d132016-11-22 11:34:01 -0800106 libraries = [
Kenny Root08e7ef92018-07-03 19:27:00 +0900107 android_tools: android_tools,
Nathan Mittler6c291c52017-03-27 17:33:17 -0700108 roboelectric: 'org.robolectric:android-all:7.1.0_r7-robolectric-0',
nmittler7782d132016-11-22 11:34:01 -0800109
110 // Test dependencies.
Kenny Rootebc029b2019-10-02 03:46:29 -0700111 bouncycastle_apis: 'org.bouncycastle:bcpkix-jdk15on:1.63',
112 bouncycastle_provider: 'org.bouncycastle:bcprov-jdk15on:1.63',
Pete Bentley05779862022-04-13 11:54:29 +0000113 junit : 'junit:junit:4.12',
Kenny Root84162152019-11-04 10:40:19 -0800114 mockito: 'org.mockito:mockito-core:2.28.2',
115 truth : 'com.google.truth:truth:1.0',
Nathan Mittlerf998b642017-01-31 16:56:17 -0800116
117 // Benchmark dependencies
Nathan Mittler0c6f7672017-02-03 17:45:14 -0800118 jmh_core: "org.openjdk.jmh:jmh-core:${jmhVersion}",
Nathan Mittlerf278d122017-02-15 10:18:22 -0800119 jmh_generator_annprocess: "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}",
120 jmh_generator_asm: "org.openjdk.jmh:jmh-generator-asm:${jmhVersion}",
121 jmh_generator_bytecode: "org.openjdk.jmh:jmh-generator-bytecode:${jmhVersion}",
122 jmh_generator_reflection: "org.openjdk.jmh:jmh-generator-reflection:${jmhVersion}",
Kenny Rootebc029b2019-10-02 03:46:29 -0700123 netty_handler: 'io.netty:netty-handler:4.1.24.Final',
124 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.26.Final',
Chad Brubaker62190cd2015-04-03 12:17:33 -0700125 ]
Adam Vartanianab0b1232017-11-21 09:33:22 +0000126
127 signJar = { jarPath ->
128 if (rootProject.hasProperty('signingKeystore') && rootProject.hasProperty('signingPassword')) {
129 def command = 'jarsigner -keystore ' + rootProject.signingKeystore +
130 ' -storepass ' + rootProject.signingPassword +
131 ' ' + jarPath + ' signingcert'
132 def process = command.execute()
133 process.waitFor()
134 if (process.exitValue()) {
135 throw new GradleException('Jar signing failed for ' + jarPath + ': ' + process.text)
136 }
137 }
138 }
Chad Brubaker62190cd2015-04-03 12:17:33 -0700139 }
Justin Moreyba94b3d2014-06-10 16:23:32 -0500140
nmittler7782d132016-11-22 11:34:01 -0800141 repositories {
142 mavenCentral()
143 mavenLocal()
144 jcenter()
Jie Daia958f452015-07-01 13:52:08 -0700145 }
Jie Daia958f452015-07-01 13:52:08 -0700146
Adam Vartanianb216fa32019-09-27 15:27:12 +0100147 jacoco {
148 toolVersion = "0.8.4"
149 }
150
Kenny Rootebc029b2019-10-02 03:46:29 -0700151 dependencies {
152 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
153 errorproneJavac("com.google.errorprone:javac:$errorproneJavacVersion")
154 }
155
Kenny Rootad84d432020-09-09 12:32:43 -0700156 tasks.register("generateProperties", WriteProperties) {
Adam Vartanianbc9e9c32018-10-03 09:38:19 +0100157 ext {
158 parsedVersion = VersionNumber.parse(version)
159 }
160 property("org.conscrypt.version.major", parsedVersion.getMajor())
161 property("org.conscrypt.version.minor", parsedVersion.getMinor())
162 property("org.conscrypt.version.patch", parsedVersion.getMicro())
163 property("org.conscrypt.boringssl.version", boringSslVersion)
164 outputFile "build/generated/resources/org/conscrypt/conscrypt.properties"
165 }
166
nmittler7782d132016-11-22 11:34:01 -0800167 if (!androidProject) {
Pete Bentleyc36e4552021-07-15 18:07:55 +0100168 sourceCompatibility = JavaVersion.VERSION_1_8
169 targetCompatibility = JavaVersion.VERSION_1_8
Nathan Mittlerf998b642017-01-31 16:56:17 -0800170
Kenny Rootad84d432020-09-09 12:32:43 -0700171 [tasks.named("compileJava"), tasks.named("compileTestJava")].forEach { t ->
172 t.configure {
173 options.compilerArgs += ["-Xlint:all", "-Xlint:-options", '-Xmaxwarns', '9999999']
174 options.encoding = "UTF-8"
175 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
176 options.compilerArgs += ["-Werror"]
177 }
nmittler7782d132016-11-22 11:34:01 -0800178 }
179 }
180
Kenny Rootad84d432020-09-09 12:32:43 -0700181 tasks.named("compileTestJava").configure {
nmittler7782d132016-11-22 11:34:01 -0800182 // serialVersionUID is basically guaranteed to be useless in our tests
183 options.compilerArgs += ["-Xlint:-serial"]
184 }
185
Kenny Rootad84d432020-09-09 12:32:43 -0700186 tasks.named("jar").configure {
187 manifest {
188 attributes('Implementation-Title': name,
189 'Implementation-Version': version,
190 'Built-By': System.getProperty('user.name'),
191 'Built-JDK': System.getProperty('java.version'),
192 'Source-Compatibility': sourceCompatibility,
193 'Target-Compatibility': targetCompatibility)
194 }
nmittler7782d132016-11-22 11:34:01 -0800195 }
196
197 javadoc.options {
198 encoding = 'UTF-8'
199 links 'https://docs.oracle.com/javase/8/docs/api/'
200 }
201
202 // Disable JavaDoc doclint on Java 8. It's annoying.
203 if (JavaVersion.current().isJava8Compatible()) {
204 allprojects {
205 tasks.withType(Javadoc) {
206 options.addStringOption('Xdoclint:none', '-quiet')
207 }
208 }
209 }
210
Kenny Rootad84d432020-09-09 12:32:43 -0700211 tasks.register("javadocJar", Jar) {
nmittler7782d132016-11-22 11:34:01 -0800212 classifier = 'javadoc'
213 from javadoc
214 }
215
Kenny Rootad84d432020-09-09 12:32:43 -0700216 tasks.register("sourcesJar", Jar) {
nmittler7782d132016-11-22 11:34:01 -0800217 classifier = 'sources'
218 from sourceSets.main.allSource
219 }
220
nmittler7782d132016-11-22 11:34:01 -0800221 // At a test failure, log the stack trace to the console so that we don't
222 // have to open the HTML in a browser.
223 test {
224 testLogging {
225 exceptionFormat = 'full'
226 showExceptions true
227 showCauses true
228 showStackTraces true
Nathan Mittler9e01a702017-08-09 11:04:48 -0700229 showStandardStreams = true
nmittler7782d132016-11-22 11:34:01 -0800230 }
Nathan Mittler9e01a702017-08-09 11:04:48 -0700231 // Enable logging for all conscrypt classes while running tests.
232 systemProperty 'java.util.logging.config.file', "${rootDir}/test_logging.properties"
nmittler7782d132016-11-22 11:34:01 -0800233 maxHeapSize = '1500m'
Nathan Mittler401f1c42017-08-15 10:12:26 -0700234
235 // Override the default executable if manually specified
236 if (build64Bit && javaExecutable64 != null) {
237 executable javaExecutable64
238 } else if (build32Bit && javaExecutable32 != null) {
239 executable javaExecutable32
240 }
nmittler7782d132016-11-22 11:34:01 -0800241 }
Jie Daia958f452015-07-01 13:52:08 -0700242 }
243}
Nathan Mittlerce593c82017-06-16 13:18:38 -0700244
245static String normalizePath(path) {
246 new File(path.toString()).absolutePath
247}