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