• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import org.gradle.util.VersionNumber
2
3buildscript {
4    ext.android_tools = 'com.android.tools.build:gradle:4.1.0'
5    ext.errorproneVersion = '2.4.0'
6    ext.errorproneJavacVersion = '9+181-r4173-1'
7    repositories {
8        google()
9        jcenter()
10    }
11    dependencies {
12        // This must be applied in the root project otherwise each subproject will
13        // have it in a different ClassLoader.
14        classpath android_tools
15        classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.0'
16    }
17}
18
19plugins {
20    // Add dependency for build script so we can access Git from our
21    // build script.
22    id 'org.ajoberstar.grgit' version '3.1.1'
23    id 'net.ltgt.errorprone' version '1.3.0'
24}
25
26subprojects {
27    def androidProject = ((project.name == 'conscrypt-android')
28            || (project.name == 'conscrypt-android-platform')
29            || (project.name == 'conscrypt-benchmark-android')
30            || (project.name == 'conscrypt-benchmark-caliper'))
31    if (androidProject) {
32        repositories {
33            google()
34        }
35    } else {
36        apply plugin: 'java-library'
37        apply plugin: 'cpp'
38
39        model {
40            toolChains {
41                visualCpp(VisualCpp)
42                // Prefer Clang over Gcc (order here matters!)
43                clang(Clang)
44                gcc(Gcc)
45            }
46        }
47    }
48    apply plugin: "idea"
49    apply plugin: "jacoco"
50    apply plugin: "net.ltgt.errorprone"
51
52    group = "org.conscrypt"
53    description = 'Conscrypt is an alternate Java Security Provider that uses BoringSSL'
54    version = "2.6-SNAPSHOT"
55
56    ext {
57        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
68        if (project.hasProperty("boringsslHome")) {
69            boringsslHome = project.property("boringsslHome")
70        } else {
71            boringsslHome = "$System.env.BORINGSSL_HOME"
72        }
73
74        boringsslIncludeDir = normalizePath("$boringsslHome/include")
75        boringssl32BuildDir = normalizePath("$boringsslHome/build32")
76        boringssl64BuildDir = normalizePath("$boringsslHome/build64")
77
78        if (project.hasProperty("jdkHome")) {
79            jdkHome = project.property("jdkHome")
80        } else {
81            jdkHome = "$System.env.JAVA_HOME"
82        }
83        jdkIncludeDir = normalizePath("$jdkHome/include")
84        // Needs to be binary compatible with androidMinSdkVersion
85        androidMinJavaVersion = JavaVersion.VERSION_1_7
86
87        build32Bit = file("$boringssl32BuildDir").exists()
88        build64Bit = file("$boringssl64BuildDir").exists()
89
90        // Ensure the environment is configured properly.
91        assert file("$boringsslHome").exists()
92        assert file("$boringsslIncludeDir").exists()
93        assert build32Bit || build64Bit
94        assert file("$jdkHome").exists()
95        assert file("$jdkIncludeDir").exists()
96
97        // Get the commit hash for BoringSSL.
98        boringSslGit = org.ajoberstar.grgit.Grgit.open(dir: boringsslHome)
99        boringSslVersion = boringSslGit.head().id
100
101        // 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
105        jmhVersion = '1.21'
106        libraries = [
107                android_tools: android_tools,
108                roboelectric: 'org.robolectric:android-all:7.1.0_r7-robolectric-0',
109
110                // Test dependencies.
111                bouncycastle_apis: 'org.bouncycastle:bcpkix-jdk15on:1.63',
112                bouncycastle_provider: 'org.bouncycastle:bcprov-jdk15on:1.63',
113                junit  : 'junit:junit:4.12',
114                mockito: 'org.mockito:mockito-core:2.28.2',
115                truth  : 'com.google.truth:truth:1.0',
116
117                // Benchmark dependencies
118                jmh_core: "org.openjdk.jmh:jmh-core:${jmhVersion}",
119                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}",
123                netty_handler: 'io.netty:netty-handler:4.1.24.Final',
124                netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.26.Final',
125        ]
126
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        }
139    }
140
141    repositories {
142        mavenCentral()
143        mavenLocal()
144        jcenter()
145    }
146
147    jacoco {
148        toolVersion = "0.8.4"
149    }
150
151    dependencies {
152        errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
153        errorproneJavac("com.google.errorprone:javac:$errorproneJavacVersion")
154    }
155
156    tasks.register("generateProperties", WriteProperties) {
157        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
167    if (!androidProject) {
168        sourceCompatibility = JavaVersion.VERSION_1_8
169        targetCompatibility = JavaVersion.VERSION_1_8
170
171        [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                }
178            }
179        }
180
181        tasks.named("compileTestJava").configure {
182            // serialVersionUID is basically guaranteed to be useless in our tests
183            options.compilerArgs += ["-Xlint:-serial"]
184        }
185
186        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            }
195        }
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
211        tasks.register("javadocJar", Jar) {
212            classifier = 'javadoc'
213            from javadoc
214        }
215
216        tasks.register("sourcesJar", Jar) {
217            classifier = 'sources'
218            from sourceSets.main.allSource
219        }
220
221        // 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
229                showStandardStreams = true
230            }
231            // Enable logging for all conscrypt classes while running tests.
232            systemProperty 'java.util.logging.config.file', "${rootDir}/test_logging.properties"
233            maxHeapSize = '1500m'
234
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            }
241        }
242    }
243}
244
245static String normalizePath(path) {
246    new File(path.toString()).absolutePath
247}
248