xref: /aosp_15_r20/external/conscrypt/build.gradle (revision cd0cc2e34ba52cdf454361820a14d744e4bd531d)
1import org.ajoberstar.grgit.Grgit
2import org.gradle.util.VersionNumber
3
4buildscript {
5    repositories {
6        google()
7        mavenCentral()
8    }
9    dependencies {
10        // This must be applied in the root project otherwise each subproject will
11        // have it in a different ClassLoader.
12        classpath libs.android.tools
13    }
14}
15
16plugins {
17    alias libs.plugins.bnd apply false
18    alias libs.plugins.errorprone
19    alias libs.plugins.grgit
20    alias libs.plugins.osdetector
21    alias libs.plugins.task.tree
22}
23
24subprojects {
25    def androidProject = ((project.name == 'conscrypt-android')
26            || (project.name == 'conscrypt-android-platform')
27            || (project.name == 'conscrypt-benchmark-android')
28            || (project.name == 'conscrypt-benchmark-caliper'))
29    if (androidProject) {
30        repositories {
31            google()
32        }
33    } else {
34        apply plugin: 'java-library'
35        apply plugin: 'cpp'
36
37        model {
38            toolChains {
39                visualCpp(VisualCpp)
40                // Prefer Clang over Gcc (order here matters!)
41                clang(Clang) {
42                    // Gradle 7.x still seems to get confused about toolchains on Mac
43                    // so explicitly add -arch args.
44                    target("osx_aarch64") {
45                        cppCompiler.withArguments { args ->
46                            args << "-arch" << "arm64"
47                        }
48                        linker.withArguments { args ->
49                            args << "-arch" << "arm64"
50                        }
51                    }
52                    target("osx_x86-64") {
53                        cppCompiler.withArguments { args ->
54                            args << "-arch" << "x86_64"
55                        }
56                        linker.withArguments { args ->
57                            args << "-arch" << "x86_64"
58                        }
59                    }
60                }
61                gcc(Gcc)
62            }
63        }
64    }
65    apply plugin: "jacoco"
66    apply plugin: libs.plugins.errorprone.get().pluginId
67
68    group = "org.conscrypt"
69    description = 'Conscrypt is an alternate Java Security Provider that uses BoringSSL'
70    version = "2.6-SNAPSHOT"
71
72    ext {
73        // Needs to be binary compatible with androidMinSdkVersion
74        androidMinJavaVersion = JavaVersion.VERSION_1_8
75
76        if (project.hasProperty("boringsslHome")) {
77            boringsslHome = project.property("boringsslHome")
78        } else {
79            boringsslHome = "$System.env.BORINGSSL_HOME"
80        }
81        boringsslIncludeDir = normalizePath("$boringsslHome/include")
82
83        // Ensure the environment is configured properly.
84        assert file("$boringsslIncludeDir").exists()
85
86        // Get the commit hash for BoringSSL.
87        boringSslGit = Grgit.open(dir: boringsslHome)
88        boringSslVersion = boringSslGit.head().id
89
90        signJar = { jarPath ->
91            if (rootProject.hasProperty('signingKeystore') && rootProject.hasProperty('signingPassword')) {
92                def command = 'jarsigner -keystore ' + rootProject.signingKeystore +
93                        ' -storepass ' + rootProject.signingPassword +
94                        ' ' + jarPath + ' signingcert'
95                def process = command.execute()
96                process.waitFor()
97                if (process.exitValue()) {
98                    throw new RuntimeException('Jar signing failed for ' + jarPath + ': ' + process.text)
99                }
100            }
101        }
102    }
103
104    repositories {
105        mavenCentral()
106        mavenLocal()
107    }
108
109    jacoco {
110        toolVersion = libs.versions.jacoco
111    }
112
113    configurations {
114        jacocoAnt
115        jacocoAgent
116    }
117
118    dependencies {
119        jacocoAnt libs.jacoco.ant
120        jacocoAgent libs.jacoco.agent
121    }
122
123    dependencies {
124        errorprone libs.errorprone
125    }
126
127    tasks.register("generateProperties", WriteProperties) {
128        ext {
129            parsedVersion = VersionNumber.parse(version)
130        }
131        property("org.conscrypt.version.major", parsedVersion.getMajor())
132        property("org.conscrypt.version.minor", parsedVersion.getMinor())
133        property("org.conscrypt.version.patch", parsedVersion.getMicro())
134        property("org.conscrypt.boringssl.version", boringSslVersion)
135        outputFile "build/generated/resources/org/conscrypt/conscrypt.properties"
136    }
137
138    if (!androidProject) {
139        java {
140            toolchain {
141                languageVersion = JavaLanguageVersion.of(11)
142            }
143        }
144
145        [tasks.named("compileJava"), tasks.named("compileTestJava")].forEach { t ->
146            t.configure {
147                options.compilerArgs += ["-Xlint:all", "-Xlint:-options", '-Xmaxwarns', '9999999']
148                options.encoding = "UTF-8"
149                options.release = 8
150
151                if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
152                    options.compilerArgs += ["-Werror"]
153                }
154            }
155        }
156
157        tasks.named("compileTestJava").configure {
158            // serialVersionUID is basically guaranteed to be useless in our tests
159            options.compilerArgs += ["-Xlint:-serial"]
160        }
161
162        tasks.named("jar").configure {
163            manifest {
164                attributes('Implementation-Title': name,
165                        'Implementation-Version': archiveVersion,
166                        'Built-By': System.getProperty('user.name'),
167                        'Built-JDK': System.getProperty('java.version'),
168                        'Source-Compatibility': sourceCompatibility,
169                        'Target-Compatibility': targetCompatibility)
170            }
171        }
172
173        javadoc.options {
174            encoding = 'UTF-8'
175            links 'https://docs.oracle.com/en/java/javase/21/docs/api/java.base/'
176        }
177
178        tasks.register("javadocJar", Jar) {
179            archiveClassifier = 'javadoc'
180            from javadoc
181        }
182
183        tasks.register("sourcesJar", Jar) {
184            archiveClassifier = 'sources'
185            from sourceSets.main.allSource
186        }
187
188        // At a test failure, log the stack trace to the console so that we don't
189        // have to open the HTML in a browser.
190        test {
191            testLogging {
192                exceptionFormat = 'full'
193                showExceptions true
194                showCauses true
195                showStackTraces true
196                showStandardStreams = true
197            }
198            // Enable logging for all conscrypt classes while running tests.
199            systemProperty 'java.util.logging.config.file', "${rootDir}/test_logging.properties"
200            maxHeapSize = '1500m'
201        }
202    }
203}
204
205static String normalizePath(path) {
206    new File(path.toString()).absolutePath
207}
208