• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import org.ajoberstar.grgit.Grgit
2import org.gradle.util.VersionNumber
3
4buildscript {
5    ext.android_tools = 'com.android.tools.build:gradle:7.4.0'
6    ext.errorproneVersion = '2.4.0'
7    ext.errorproneJavacVersion = '9+181-r4173-1'
8    repositories {
9        google()
10        mavenCentral()
11    }
12    dependencies {
13        // This must be applied in the root project otherwise each subproject will
14        // have it in a different ClassLoader.
15        classpath android_tools
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    id "com.google.osdetector" version "1.7.3"
25    id "biz.aQute.bnd.builder" version "6.4.0" apply false
26}
27
28subprojects {
29    def androidProject = ((project.name == 'conscrypt-android')
30            || (project.name == 'conscrypt-android-platform')
31            || (project.name == 'conscrypt-benchmark-android')
32            || (project.name == 'conscrypt-benchmark-caliper'))
33    if (androidProject) {
34        repositories {
35            google()
36        }
37    } else {
38        apply plugin: 'java-library'
39        apply plugin: 'cpp'
40
41        model {
42            toolChains {
43                visualCpp(VisualCpp)
44                // Prefer Clang over Gcc (order here matters!)
45                clang(Clang) {
46                    // Gradle 7.x still seems to get confused about toolchains on Mac
47                    // so explicitly add -arch args.
48                    target("osx_aarch64") {
49                        cppCompiler.withArguments { args ->
50                            args << "-arch" << "arm64"
51                        }
52                        linker.withArguments { args ->
53                            args << "-arch" << "arm64"
54                        }
55                    }
56                    target("osx_x86-64") {
57                        cppCompiler.withArguments { args ->
58                            args << "-arch" << "x86_64"
59                        }
60                        linker.withArguments { args ->
61                            args << "-arch" << "x86_64"
62                        }
63                    }
64                }
65                gcc(Gcc)
66            }
67        }
68    }
69    apply plugin: "idea"
70    apply plugin: "jacoco"
71    apply plugin: "net.ltgt.errorprone"
72
73    group = "org.conscrypt"
74    description = 'Conscrypt is an alternate Java Security Provider that uses BoringSSL'
75    version = "2.6-SNAPSHOT"
76
77    ext {
78        // Needs to be binary compatible with androidMinSdkVersion
79        androidMinJavaVersion = JavaVersion.VERSION_1_8
80
81        if (project.hasProperty("boringsslHome")) {
82            boringsslHome = project.property("boringsslHome")
83        } else {
84            boringsslHome = "$System.env.BORINGSSL_HOME"
85        }
86        boringsslIncludeDir = normalizePath("$boringsslHome/include")
87
88        // Ensure the environment is configured properly.
89        assert file("$boringsslIncludeDir").exists()
90
91        // Get the commit hash for BoringSSL.
92        boringSslGit = Grgit.open(dir: boringsslHome)
93        boringSslVersion = boringSslGit.head().id
94
95        jmhVersion = '1.21'
96        libraries = [
97                android_tools: android_tools,
98                roboelectric: 'org.robolectric:android-all:7.1.0_r7-robolectric-0',
99
100                // Test dependencies.
101                bouncycastle_apis: 'org.bouncycastle:bcpkix-jdk15on:1.63',
102                bouncycastle_provider: 'org.bouncycastle:bcprov-jdk15on:1.63',
103                junit  : 'junit:junit:4.12',
104                mockito: 'org.mockito:mockito-core:2.28.2',
105                truth  : 'com.google.truth:truth:1.0',
106
107                // Benchmark dependencies
108                jmh_core: "org.openjdk.jmh:jmh-core:${jmhVersion}",
109                jmh_generator_annprocess: "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}",
110                jmh_generator_asm: "org.openjdk.jmh:jmh-generator-asm:${jmhVersion}",
111                jmh_generator_bytecode: "org.openjdk.jmh:jmh-generator-bytecode:${jmhVersion}",
112                jmh_generator_reflection: "org.openjdk.jmh:jmh-generator-reflection:${jmhVersion}",
113                netty_handler: 'io.netty:netty-handler:4.1.24.Final',
114                netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.26.Final',
115        ]
116
117        signJar = { jarPath ->
118            if (rootProject.hasProperty('signingKeystore') && rootProject.hasProperty('signingPassword')) {
119                def command = 'jarsigner -keystore ' + rootProject.signingKeystore +
120                        ' -storepass ' + rootProject.signingPassword +
121                        ' ' + jarPath + ' signingcert'
122                def process = command.execute()
123                process.waitFor()
124                if (process.exitValue()) {
125                    throw new RuntimeException('Jar signing failed for ' + jarPath + ': ' + process.text)
126                }
127            }
128        }
129    }
130
131    repositories {
132        mavenCentral()
133        mavenLocal()
134    }
135
136    jacoco {
137        toolVersion = "0.8.4"
138    }
139
140    dependencies {
141        errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
142        errorproneJavac("com.google.errorprone:javac:$errorproneJavacVersion")
143    }
144
145    tasks.register("generateProperties", WriteProperties) {
146        ext {
147            parsedVersion = VersionNumber.parse(version)
148        }
149        property("org.conscrypt.version.major", parsedVersion.getMajor())
150        property("org.conscrypt.version.minor", parsedVersion.getMinor())
151        property("org.conscrypt.version.patch", parsedVersion.getMicro())
152        property("org.conscrypt.boringssl.version", boringSslVersion)
153        outputFile "build/generated/resources/org/conscrypt/conscrypt.properties"
154    }
155
156    if (!androidProject) {
157        java {
158            toolchain {
159                // Compile with a real JDK 8 so we don't end up with accidental dependencies
160                // on Java 11 bootclasspath, e.g. ByteBuffer.flip().
161                languageVersion = JavaLanguageVersion.of(8)
162            }
163        }
164
165        [tasks.named("compileJava"), tasks.named("compileTestJava")].forEach { t ->
166            t.configure {
167                options.compilerArgs += ["-Xlint:all", "-Xlint:-options", '-Xmaxwarns', '9999999']
168                options.encoding = "UTF-8"
169                if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
170                    options.compilerArgs += ["-Werror"]
171                }
172            }
173        }
174
175        tasks.named("compileTestJava").configure {
176            // serialVersionUID is basically guaranteed to be useless in our tests
177            options.compilerArgs += ["-Xlint:-serial"]
178        }
179
180        tasks.named("jar").configure {
181            manifest {
182                attributes('Implementation-Title': name,
183                        'Implementation-Version': archiveVersion,
184                        'Built-By': System.getProperty('user.name'),
185                        'Built-JDK': System.getProperty('java.version'),
186                        'Source-Compatibility': sourceCompatibility,
187                        'Target-Compatibility': targetCompatibility)
188            }
189        }
190
191        javadoc.options {
192            encoding = 'UTF-8'
193            links 'https://docs.oracle.com/javase/8/docs/api/'
194        }
195
196        // All non-Android projects build with Java 8, so disable doclint as it's noisy.
197        allprojects {
198            tasks.withType(Javadoc) {
199                options.addStringOption('Xdoclint:none', '-quiet')
200            }
201        }
202
203        tasks.register("javadocJar", Jar) {
204            classifier = 'javadoc'
205            from javadoc
206        }
207
208        tasks.register("sourcesJar", Jar) {
209            classifier = 'sources'
210            from sourceSets.main.allSource
211        }
212
213        // At a test failure, log the stack trace to the console so that we don't
214        // have to open the HTML in a browser.
215        test {
216            testLogging {
217                exceptionFormat = 'full'
218                showExceptions true
219                showCauses true
220                showStackTraces true
221                showStandardStreams = true
222            }
223            // Enable logging for all conscrypt classes while running tests.
224            systemProperty 'java.util.logging.config.file', "${rootDir}/test_logging.properties"
225            maxHeapSize = '1500m'
226        }
227    }
228}
229
230static String normalizePath(path) {
231    new File(path.toString()).absolutePath
232}
233