blob: a4752c44510642e44b3e128342d1464ed6b85e7d [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
Ian Zerny5fffb0a2019-02-11 13:54:22 +01004
Clément Béraffc2d6a2022-08-02 13:03:04 +02005
Clément Béra863e6602023-01-11 13:47:31 +01006
Clément Béraffc2d6a2022-08-02 13:03:04 +02007import desugaredlibrary.CustomConversionAsmRewriterTask
Ian Zerny5fffb0a2019-02-11 13:54:22 +01008import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02009import org.gradle.internal.os.OperatingSystem
Clément Béra8dde69d2022-10-26 15:40:31 +020010import smali.SmaliTask
Søren Gjesse63a53a92023-05-03 14:33:02 +020011import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000012import tasks.GetJarsFromConfiguration
Mads Ager418d1ca2017-05-22 09:35:49 +020013
Ian Zerny5fffb0a2019-02-11 13:54:22 +010014plugins {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010015 id "net.ltgt.errorprone" version "2.0.2"
Ian Zerny5fffb0a2019-02-11 13:54:22 +010016}
17
18apply plugin: 'java'
19apply plugin: 'idea'
20
Sebastien Hertz143ed112018-02-13 14:26:41 +010021ext {
Søren Gjesse44faa872023-05-23 12:21:22 +020022 // When updating dependencies also update and run
23 // tools/create_local_maven_with_dependencies.py
Sebastien Hertz143ed112018-02-13 14:26:41 +010024 androidSupportVersion = '25.4.0'
Ian Zerny0b4f14a2023-04-28 09:51:12 +020025 asmVersion = '9.5' // When updating update tools/asmifier.py, build.src and Toolhelper as well.
Søren Gjesse780c2e82023-03-21 09:48:13 +010026 javassistVersion = '3.29.2-GA'
Sebastien Hertz143ed112018-02-13 14:26:41 +010027 espressoVersion = '3.0.0'
Søren Gjessef5688fb2023-05-03 15:08:14 +020028 fastutilVersion = '7.2.1'
Søren Gjesse63a53a92023-05-03 14:33:02 +020029 guavaVersion = '31.1-jre'
Mads Ager48dd79e2018-05-15 09:13:55 +020030 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010031 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080032 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +010033 // The kotlin version is only here to specify the kotlin language level,
34 // all kotlin compilations are done in tests.
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +010035 kotlinVersion = '1.8.0'
Morten Krogh-Jespersen789ab762023-06-08 10:45:51 +020036 kotlinExtMetadataJVMVersion = '0.6.2'
Søren Gjessea599e652023-05-03 14:35:06 +020037 smaliVersion = '3.0.3'
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010038 errorproneVersion = '2.18.0'
clementbera4f9c2a92019-07-09 08:50:37 +020039 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010040}
41
Mads Ager418d1ca2017-05-22 09:35:49 +020042repositories {
Søren Gjesse44faa872023-05-23 12:21:22 +020043 maven {
44 url uri('file:third_party/dependencies')
45 }
Mads Ager418d1ca2017-05-22 09:35:49 +020046}
47
Jinseong Jeon05064e12018-07-03 00:21:12 -070048if (project.hasProperty('with_code_coverage')) {
49 apply plugin: 'jacoco'
50}
51
Mads Ager418d1ca2017-05-22 09:35:49 +020052// Custom source set for example tests and generated tests.
53sourceSets {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020054 main {
55 java {
Ian Zernyc1582852023-01-30 13:45:36 +010056 srcDirs = ['src/main/java', 'src/keepanno/java']
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020057 }
58 resources {
59 srcDirs "third_party/api_database/api_database"
60 }
61 }
Clément Béraffc2d6a2022-08-02 13:03:04 +020062 main17 {
63 java {
Ian Zernyc1582852023-01-30 13:45:36 +010064 srcDirs = ['src/main/java', 'src/keepanno/java']
Clément Béraffc2d6a2022-08-02 13:03:04 +020065 }
66 resources {
67 srcDirs "third_party/api_database/api_database"
68 }
69 }
Mads Ager418d1ca2017-05-22 09:35:49 +020070 test {
71 java {
72 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020073 'src/test/java',
74 'build/generated/test/java',
75 ]
76 }
77 }
Yohann Rousselbb571622017-11-09 10:47:36 +010078 apiUsageSample {
79 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020080 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
81 include 'com/android/tools/apiusagesample/*.java'
82 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
83 include 'com/android/tools/r8/D8CommandParser.java'
84 include 'com/android/tools/r8/R8CommandParser.java'
85 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010086 }
Yohann Rousselbb571622017-11-09 10:47:36 +010087 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010088 cfSegments {
89 java {
90 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
91 }
92 output.resourcesDir = 'build/classes/cfSegments'
93 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +010094 libraryDesugarConversions {
95 java {
96 srcDirs = ['src/library_desugar/java']
97 }
98 output.resourcesDir = 'build/classes/library_desugar_conversions'
99 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200100 debugTestResources {
101 java {
102 srcDirs = ['src/test/debugTestResources']
103 }
104 output.resourcesDir = 'build/classes/debugTestResources'
105 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200106 debugTestResourcesJava8 {
107 java {
108 srcDirs = ['src/test/debugTestResourcesJava8']
109 }
110 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
111 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200112 examples {
113 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800114 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200115 }
116 output.resourcesDir = 'build/classes/examples'
117 }
Ian Zernyd3020482019-04-25 07:05:04 +0200118 examplesJava9 {
119 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200120 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200121 }
122 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500123 examplesJava10 {
124 java {
125 srcDirs = ['src/test/examplesJava10']
126 }
127 }
Ian Zernyd3020482019-04-25 07:05:04 +0200128 examplesJava11 {
129 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200130 srcDirs = ['src/test/examplesJava11']
131 }
132 }
Søren Gjessee9966932021-09-15 17:08:37 +0200133 examplesJava17 {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100134 java {
Søren Gjessee9966932021-09-15 17:08:37 +0200135 srcDirs = ['src/test/examplesJava17']
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100136 }
137 }
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200138 examplesJava20 {
Søren Gjessed1e08992022-02-07 16:46:31 +0100139 java {
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200140 srcDirs = ['src/test/examplesJava20']
Søren Gjessed1e08992022-02-07 16:46:31 +0100141 }
142 }
clementberaefa10522019-07-11 11:20:46 +0200143 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200144 java {
145 srcDirs = ['src/test/testngrunner']
146 }
147 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200148 examplesAndroidN {
149 java {
150 srcDirs = ['src/test/examplesAndroidN']
151 }
152 output.resourcesDir = 'build/classes/examplesAndroidN'
153 }
154 examplesAndroidO {
155 java {
156 srcDirs = ['src/test/examplesAndroidO']
157 }
158 output.resourcesDir = 'build/classes/examplesAndroidO'
159 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200160 examplesAndroidP {
161 java {
162 srcDirs = ['src/test/examplesAndroidP']
163 }
164 output.resourcesDir = 'build/classes/examplesAndroidP'
165 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200166 examplesProto {
167 java {
168 srcDirs = ['src/test/examplesProto']
169 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200170 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
171 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200172 output.resourcesDir = 'build/classes/examplesProto'
173 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100174 kotlinR8TestResources {
175 java {
176 srcDirs = ['src/test/kotlinR8TestResources']
177 }
178 output.resourcesDir = 'build/classes/kotlinR8TestResources'
179 }
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100180 keepanno {
181 java {
Ian Zerny172aca22022-11-03 13:07:48 +0100182 srcDirs = ['src/keepanno/java']
Ian Zernya87869c2023-01-31 08:38:21 +0100183 include 'com/android/tools/r8/keepanno/annotations/*.java'
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100184 }
185 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200186}
187
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800188// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
189// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
190// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
191// for context.
192idea {
193 sourceSets.all { SourceSet sources ->
194 module {
Ian Zernyc1582852023-01-30 13:45:36 +0100195 if (sources.name == "main") {
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800196 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100197 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800198 } else {
199 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100200 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800201 }
202 }
203 }
204}
205
Yohann Roussel126f6872017-08-03 16:25:32 +0200206configurations {
207 supportLibs
208}
209
Mads Ager418d1ca2017-05-22 09:35:49 +0200210dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100211 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200212 // Include all of guava when compiling the code, but exclude annotations that we don't
213 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100214 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100215 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200216 exclude group: 'com.google.errorprone'
217 exclude group: 'com.google.code.findbugs'
218 exclude group: 'com.google.j2objc'
219 exclude group: 'org.codehaus.mojo'
Søren Gjesse308a4702023-05-31 12:27:12 +0200220 exclude group: 'com.google.guava', module: 'listenablefuture'
221 exclude group: 'com.google.guava', module: 'failureaccess'
Mads Ager0aa48052017-09-15 12:39:15 +0200222 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100223 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
224 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
225 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
226 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
227 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
228 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
229 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200230
Clément Béraffc2d6a2022-08-02 13:03:04 +0200231 main17Implementation "com.google.code.gson:gson:$gsonVersion"
232 // Include all of guava when compiling the code, but exclude annotations that we don't
233 // need from the packaging.
234 main17CompileOnly("com.google.guava:guava:$guavaVersion")
235 main17Implementation("com.google.guava:guava:$guavaVersion", {
236 exclude group: 'com.google.errorprone'
237 exclude group: 'com.google.code.findbugs'
238 exclude group: 'com.google.j2objc'
239 exclude group: 'org.codehaus.mojo'
240 })
241 main17Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
242 main17Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
243 main17Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
244 main17Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
245 main17Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
246 main17Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
247 main17Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +0100248
clementberaefa10522019-07-11 11:20:46 +0200249 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100250
Mads Ager418d1ca2017-05-22 09:35:49 +0200251 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100252 testCompile "junit:junit:$junitVersion"
Ian Zerny161ff742022-01-20 12:39:40 +0100253 testCompile "com.google.guava:guava:$guavaVersion"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100254 testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
255 testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
Søren Gjessea599e652023-05-03 14:35:06 +0200256 testCompile group: 'com.android.tools.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200257 testCompile files('third_party/jasmin/jasmin-2.4.jar')
258 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200259 testCompile files('third_party/ddmlib/ddmlib.jar')
Ian Zerny161ff742022-01-20 12:39:40 +0100260 testCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
261 testCompile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
262 testCompile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
263 testCompile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
264 testCompile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
265 testCompile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
Søren Gjesse780c2e82023-03-21 09:48:13 +0100266 testCompile group: 'org.javassist', name: 'javassist', version: javassistVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100267
Sebastien Hertz143ed112018-02-13 14:26:41 +0100268 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
269 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200270 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100271 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800272 examplesCompile "junit:junit:$junitVersion"
273 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100274 supportLibs "com.android.support:support-v4:$androidSupportVersion"
275 supportLibs "junit:junit:$junitVersion"
276 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100277 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100278 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100279 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100280 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100281
282 keepannoCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
283 keepannoCompile "com.google.guava:guava:$guavaVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200284}
285
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100286def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100287def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200288def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100289def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100290def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +0200291def java11ClassFiles = "$buildDir/classes/java/mainJava11"
292def r8RetracePath = "$buildDir/libs/r8retrace.jar"
293def r8RetraceExludeDepsPath = "$buildDir/libs/r8retrace-exclude-deps.jar"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100294
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200295def osString = OperatingSystem.current().isLinux() ? "linux" :
296 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200297
298def cloudDependencies = [
299 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200300 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100301 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200302 ],
303 "third_party": [
Rico Winde4aee2a2023-01-26 13:46:40 +0100304 "aapt2",
Rico Windf72fa152018-10-22 15:41:03 +0200305 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200306 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200307 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100308 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200309 "android_jar/lib-v19",
310 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100311 "android_jar/lib-v22",
312 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200313 "android_jar/lib-v24",
314 "android_jar/lib-v25",
315 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100316 "android_jar/lib-v27",
317 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200318 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200319 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100320 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100321 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100322 "android_jar/lib-v33",
Morten Krogh-Jespersenfdbe3272023-02-10 12:25:07 +0100323 "android_jar/lib-v34",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200324 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200325 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200326 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200327 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200328 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200329 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100330 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200331 "dart-sdk",
332 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200333 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100334 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200335 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200336 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200337 "jacoco/0.8.2",
338 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200339 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100340 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200341 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200342 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200343 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200344 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200345 "kotlin/kotlin-compiler-1.3.11",
346 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200347 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100348 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200349 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100350 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200351 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen47efa232023-01-20 11:12:06 +0100352 "kotlin/kotlin-compiler-1.8.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200353 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200354 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100355 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200356 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000357 "openjdk/desugar_jdk_libs_11",
Ian Zernyc4598882022-02-25 19:26:44 +0100358 "openjdk/desugar_jdk_libs_legacy",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200359 "openjdk/desugar_jdk_libs_releases/1.0.9",
360 "openjdk/desugar_jdk_libs_releases/1.0.10",
361 "openjdk/desugar_jdk_libs_releases/1.1.0",
362 "openjdk/desugar_jdk_libs_releases/1.1.1",
363 "openjdk/desugar_jdk_libs_releases/1.1.5",
clementbera8dbfeda2019-07-03 11:24:13 +0200364 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100365 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200366 "proguard/proguard5.2.1",
367 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200368 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000369 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200370 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200371 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200372 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200373 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200374 "r8mappings",
375 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200376 ],
377 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
378 // container on other platforms where supported.
379 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200380 "linux/art",
381 "linux/art-5.1.1",
382 "linux/art-6.0.1",
383 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100384 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100385 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100386 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200387 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200388 "linux/host/art-13.0.0",
Søren Gjesseaa3eb742023-03-02 20:00:45 +0100389 "linux/host/art-14.0.0-dp1",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200390 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200391 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100392 "linux/dalvik-4.0.4",
Mads Ager418d1ca2017-05-22 09:35:49 +0200393 ]
394]
395
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100396def cloudSystemDependencies = [
397 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200398 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200399 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100400 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100401 "openjdk/jdk-17/linux",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200402 "openjdk/jdk-20/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100403 ],
404 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200405 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200406 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100407 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100408 "openjdk/jdk-17/osx",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200409 "openjdk/jdk-20/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100410 ],
411 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200412 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100413 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100414 "openjdk/jdk-17/windows",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200415 "openjdk/jdk-20/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100416 ],
417]
418
419if (OperatingSystem.current().isWindows()) {
420 cloudSystemDependencies.windows.each { entry ->
421 cloudDependencies.get(entry.key).addAll(entry.value)
422 }
423} else if (OperatingSystem.current().isLinux()) {
424 cloudSystemDependencies.linux.each { entry ->
425 cloudDependencies.get(entry.key).addAll(entry.value)
426 }
427} else if (OperatingSystem.current().isMacOsX()) {
428 cloudSystemDependencies.osx.each { entry ->
429 cloudDependencies.get(entry.key).addAll(entry.value)
430 }
431} else {
432 println "WARNING: Unsupported system: " + OperatingSystem.current()
433}
434
435def getDownloadDepsTaskName(entryKey, entryFile) {
436 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
437}
438
Mads Ager418d1ca2017-05-22 09:35:49 +0200439cloudDependencies.each { entry ->
440 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200441 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100442 type DownloadDependency.Type.GOOGLE_STORAGE
443 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200444 }
445 }
446}
447
448def x20Dependencies = [
449 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200450 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700451 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200452 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200453 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000454 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100455 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100456 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200457 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100458 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200459 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200460 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200461 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200462 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200463 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200464 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200465 "proguard/proguard_internal_159423826",
466 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200467 "proto",
468 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200469 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200470 "youtube/youtube.android_16.20",
471 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200472 ],
473]
474
475x20Dependencies.each { entry ->
476 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100477 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
478 type DownloadDependency.Type.X20
479 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200480 }
481 }
482}
483
Rico Windf6c74ce2018-12-04 08:50:55 +0100484task downloadOpenJDKrt {
485 cloudDependencies.each { entry ->
486 entry.value.each { entryFile ->
487 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100488 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100489 }
490 }
491 }
492}
493
Tamas Kenez0e10c562017-06-08 10:00:34 +0200494task downloadAndroidCts {
495 cloudDependencies.each { entry ->
496 entry.value.each { entryFile ->
497 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100498 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200499 }
500 }
501 }
502}
503
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200504task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200505 cloudDependencies.each { entry ->
506 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100507 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200508 }
509 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200510}
511
512task downloadX20Deps() {
513 x20Dependencies.each { entry ->
514 entry.value.each { entryFile ->
515 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200516 }
517 }
518}
519
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200520task downloadDeps {
521 dependsOn downloadCloudDeps
522 if (!project.hasProperty('no_internal')) {
523 dependsOn downloadX20Deps
524 }
525}
526
Mads Ager418d1ca2017-05-22 09:35:49 +0200527allprojects {
528 sourceCompatibility = JavaVersion.VERSION_1_8
529 targetCompatibility = JavaVersion.VERSION_1_8
530}
531
Rico Wind266336c2019-02-25 10:11:38 +0100532// TODO(ricow): Remove debug prints
533println("NOTE: Current operating system: " + OperatingSystem.current())
534println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
535
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100536// Check if running with the JDK location from tools/jdk.py.
537if (OperatingSystem.current().isWindows()) {
538 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100539 compileJava.options.encoding = "UTF-8"
540 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100541} else {
542 def javaHomeOut = new StringBuilder()
543 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400544 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100545 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
546 def jdkHome = new File(javaHomeOut.toString().trim())
547 if (!jdkHome.exists()) {
548 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
549 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
550 println("WARNING: Gradle is running in a non-pinned Java"
551 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000552 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100553 } else {
554 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100555 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200556}
557
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200558compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200559
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100560sourceSets.configureEach { sourceSet ->
561 tasks.named(sourceSet.compileJavaTaskName).configure {
562 // Default disable errorprone (enabled and setup below).
563 options.errorprone.enabled = false
564 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100565 // Run all compilation tasks in a forked subprocess.
566 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100567 // Javac often runs out of stack space when compiling the tests.
568 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200569 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100570 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200571 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100572 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
573 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
574 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200575}
576
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100577def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
578 tasks.named(sourceSet).get().configure {
579 def jdkDir = "third_party/openjdk/${javaHome}/"
580 options.fork = true
581 options.forkOptions.jvmArgs = []
582 if (enablePreview) {
583 options.compilerArgs.add('--enable-preview')
584 }
585 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200586 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100587 options.forkOptions.javaHome = file(jdkDir + 'linux')
588 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200589 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400590 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
591 ? file(jdkDir + 'osx/Contents/Home')
592 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100593 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200594 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100595 options.forkOptions.javaHome = file(jdkDir + 'windows')
596 }
597 sourceCompatibility = compatibility
598 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200599 }
Ian Zernyd3020482019-04-25 07:05:04 +0200600}
601
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100602setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200603 sourceSets.main.compileJavaTaskName,
604 'jdk-11',
605 JavaVersion.VERSION_11,
606 false);
607
608setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100609 sourceSets.examplesJava9.compileJavaTaskName,
610 'openjdk-9.0.4',
611 JavaVersion.VERSION_1_9,
612 false)
613setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100614 sourceSets.examplesJava10.compileJavaTaskName,
615 'jdk-11',
616 JavaVersion.VERSION_1_10,
617 false)
618setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200619 sourceSets.main17.compileJavaTaskName,
620 'jdk-17',
621 JavaVersion.VERSION_17,
622 false)
623setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100624 sourceSets.examplesJava11.compileJavaTaskName,
625 'jdk-11',
626 JavaVersion.VERSION_11,
627 false)
628setJdkCompilationWithCompatibility(
629 sourceSets.examplesTestNGRunner.compileJavaTaskName,
630 'jdk-11',
631 JavaVersion.VERSION_11,
632 false)
633setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200634 sourceSets.examplesJava17.compileJavaTaskName,
635 'jdk-17',
636 JavaVersion.VERSION_17,
637 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100638setJdkCompilationWithCompatibility(
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200639 sourceSets.examplesJava20.compileJavaTaskName,
640 'jdk-20',
Søren Gjessed1e08992022-02-07 16:46:31 +0100641 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
642 JavaVersion.VERSION_17,
643 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100644
Clément Bérac94b6202021-09-28 11:16:58 +0000645task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
646 from sourceSets.examplesTestNGRunner.compileClasspath
647 include "**/**.jar"
648 into file("$buildDir/test/jdk11Tests")
649}
650
651task compileTestNGRunner (type: JavaCompile) {
652 dependsOn provideJdk11TestsDependencies
Clément Béra98d5b602021-09-29 06:27:21 +0000653 destinationDir = file("$buildDir/classes/java/examplesTestNGRunner")
Clément Bérac94b6202021-09-28 11:16:58 +0000654 source = sourceSets.examplesTestNGRunner.allSource
655 classpath = sourceSets.examplesTestNGRunner.compileClasspath
656}
657
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100658if (!project.hasProperty('without_error_prone') &&
659 // Don't enable error prone on Java 8 as the plugin setup does not support it.
660 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200661 compileJava {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100662
663 // Enable error prone for D8/R8 main sources and make all warnings errors.
664 // Warnings that we have chosen not to fix (or suppress) are disabled outright below.
665 options.compilerArgs << "-Werror"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100666 options.errorprone.enabled = true
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100667
668 // Non-default / Experimental checks - explicitly enforced.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100669 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100670 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100671 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
672 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
673 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100674
Ian Zernyf19e5e92023-03-03 12:04:45 +0100675 // TODO(b/270510095): These should likely be fixed/suppressed and become hard failures.
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100676 options.errorprone.check('UnusedVariable', CheckSeverity.OFF)
677 options.errorprone.check('EqualsUnsafeCast', CheckSeverity.OFF)
678 options.errorprone.check('TypeParameterUnusedInFormals', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100679 options.errorprone.check('ImmutableEnumChecker', CheckSeverity.OFF)
680 options.errorprone.check('BadImport', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100681 options.errorprone.check('ComplexBooleanConstant', CheckSeverity.OFF)
682 options.errorprone.check('StreamToIterable', CheckSeverity.OFF)
683 options.errorprone.check('HidingField', CheckSeverity.OFF)
684 options.errorprone.check('StreamResourceLeak', CheckSeverity.OFF)
685 options.errorprone.check('CatchAndPrintStackTrace', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100686 options.errorprone.check('NonCanonicalType', CheckSeverity.OFF)
687 options.errorprone.check('UnusedNestedClass', CheckSeverity.OFF)
688 options.errorprone.check('AmbiguousMethodReference', CheckSeverity.OFF)
689 options.errorprone.check('InvalidParam', CheckSeverity.OFF)
690 options.errorprone.check('CharacterGetNumericValue', CheckSeverity.OFF)
691 options.errorprone.check('ModifyCollectionInEnhancedForLoop', CheckSeverity.OFF)
692 options.errorprone.check('EmptyCatch', CheckSeverity.OFF)
693 options.errorprone.check('ArgumentSelectionDefectChecker', CheckSeverity.OFF)
694 options.errorprone.check('ImmutableAnnotationChecker', CheckSeverity.OFF)
695 options.errorprone.check('ObjectToString', CheckSeverity.OFF)
696 options.errorprone.check('DoNotClaimAnnotations', CheckSeverity.OFF)
697 options.errorprone.check('AnnotateFormatMethod', CheckSeverity.OFF)
698
699 // TODO(b/270537614): Remove finalize uses.
700 options.errorprone.check('Finalize', CheckSeverity.OFF)
701
702 // The following warnings could/should be active but are hit by R8 now so silence them.
703 options.errorprone.check('EqualsGetClass', CheckSeverity.OFF)
704 options.errorprone.check('MixedMutabilityReturnType', CheckSeverity.OFF)
705 options.errorprone.check('UnnecessaryParentheses', CheckSeverity.OFF)
706 options.errorprone.check('DoNotCallSuggester', CheckSeverity.OFF)
707 options.errorprone.check('InlineMeSuggester', CheckSeverity.OFF)
708 options.errorprone.check('MutablePublicArray', CheckSeverity.OFF)
709 options.errorprone.check('DefaultCharset', CheckSeverity.OFF)
710 options.errorprone.check('InconsistentCapitalization', CheckSeverity.OFF)
711 options.errorprone.check('InlineFormatString', CheckSeverity.OFF)
712 options.errorprone.check('MissingImplementsComparable', CheckSeverity.OFF)
713
714 // Warnings that cause unwanted edits (e.g., inability to write informative asserts).
715 options.errorprone.check('AlreadyChecked', CheckSeverity.OFF)
716
717 // JavaDoc related warnings. Would be nice to resolve but of no real consequence.
718 options.errorprone.check('InvalidLink', CheckSeverity.OFF)
719 options.errorprone.check('InvalidBlockTag', CheckSeverity.OFF)
720 options.errorprone.check('InvalidInlineTag', CheckSeverity.OFF)
721 options.errorprone.check('EmptyBlockTag', CheckSeverity.OFF)
722 options.errorprone.check('MissingSummary', CheckSeverity.OFF)
723 options.errorprone.check('UnrecognisedJavadocTag', CheckSeverity.OFF)
724 options.errorprone.check('AlmostJavadoc', CheckSeverity.OFF)
725
726 // Moving away from identity and canonical items is not planned.
727 options.errorprone.check('ReferenceEquality', CheckSeverity.OFF)
728 options.errorprone.check('IdentityHashMapUsage', CheckSeverity.OFF)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200729 }
730}
731
Yohann Roussel7f47c032017-09-14 12:19:06 +0200732task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200733 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100734
Yohann Roussel7f47c032017-09-14 12:19:06 +0200735 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100736 def runtimeClasspath = configurations.findByName("runtimeClasspath")
737 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
738
Yohann Roussel7f47c032017-09-14 12:19:06 +0200739 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100740
Yohann Roussel7f47c032017-09-14 12:19:06 +0200741 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100742 def dependencies = []
743 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
744 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
745 dependencies.add("${identifier.group}:${identifier.module}")
746 }
747 def libraryLicenses = file('LIBRARY-LICENSE').text
748 dependencies.each {
749 if (!libraryLicenses.contains("- artifact: $it")) {
750 throw new GradleException("No license for $it in LIBRARY_LICENSE")
751 }
752 }
753
Yohann Roussel7f47c032017-09-14 12:19:06 +0200754 license.getParentFile().mkdirs()
755 license.createNewFile()
756 license.text = "This file lists all licenses for code distributed.\n"
757 license.text += "All non-library code has the following 3-Clause BSD license.\n"
758 license.text += "\n"
759 license.text += "\n"
760 license.text += file('LICENSE').text
761 license.text += "\n"
762 license.text += "\n"
763 license.text += "Summary of distributed libraries:\n"
764 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100765 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200766 license.text += "\n"
767 license.text += "\n"
768 license.text += "Licenses details:\n"
769 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
770 license.text += "\n"
771 license.text += "\n"
772 license.text += file.text
773 }
774 }
775}
776
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100777def repackageDepFile(file) {
778 if (file.getName().endsWith('.jar')) {
779 return zipTree(file).matching {
780 exclude '**/module-info.class'
781 exclude 'META-INF/maven/**'
782 exclude 'META-INF/LICENSE.txt'
783 exclude 'META-INF/MANIFEST.MF'
784 }
785 } else {
786 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700787 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200788}
789
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100790task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200791 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100792 dependsOn project.configurations.runtimeClasspath
793 project.configurations.runtimeClasspath.forEach {
794 from repackageDepFile(it)
795 }
796 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000797}
798
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100799task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200800 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100801 dependsOn project.configurations.testCompile
802 project.configurations.testCompile.forEach {
803 from repackageDepFile(it)
804 }
805 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200806}
807
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100808task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100809 // If this fails then remove all generated folders from
810 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200811 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100812 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000813}
814
Clément Béraffc2d6a2022-08-02 13:03:04 +0200815task repackageSources17(type: Jar) {
816 from sourceSets.main17.output
817 archiveFileName = 'sources_main_17.jar'
818}
819
Søren Gjesse145d9e82022-05-24 08:12:13 +0200820def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100821 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200822 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100823 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200824 dependsOn files('LICENSE')
825 if (includeLibraryLicenses) {
826 from consolidatedLicense.outputs.files
827 } else {
828 from files('LICENSE')
829 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100830 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100831 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100832 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200833 if (includeSwissArmyKnife) {
834 manifest {
835 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
836 }
837 }
838 exclude "META-INF/*.kotlin_module"
839 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200840 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200841}
842
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200843def r8RelocateTask(r8Task, output) {
844 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
845 dependsOn r8WithDeps
846 dependsOn r8Task
847 outputs.file output
848 workingDir = projectDir
849 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200850 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200851 "relocator",
852 "--input",
853 r8Task.outputs.files[0],
854 "--output",
855 output,
856 "--map",
857 "com.google.common->com.android.tools.r8.com.google.common",
858 "--map",
859 "com.google.gson->com.android.tools.r8.com.google.gson",
860 "--map",
861 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
862 "--map",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200863 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
864 "--map",
865 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
866 "--map",
867 "kotlin->com.android.tools.r8.jetbrains.kotlin",
868 "--map",
869 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
870 "--map",
871 "org.jetbrains->com.android.tools.r8.org.jetbrains",
872 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200873 "org.intellij->com.android.tools.r8.org.intellij",
874 "--map",
875 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200876 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200877 }
878}
879
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200880task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200881 dependsOn repackageSources
882 dependsOn repackageDeps
883 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200884 def r8Task = r8CreateTask(
885 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100886 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200887 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200888 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200889 true)
890 dependsOn r8Task
891 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200892}
893
Clément Béraffc2d6a2022-08-02 13:03:04 +0200894task r8WithDeps17 {
895 dependsOn repackageSources17
896 dependsOn repackageDeps
897 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
898 def r8Task = r8CreateTask(
899 'WithDeps17',
900 'r8_with_deps_17.jar',
901 repackageSources17.outputs.files + repackageDeps.outputs.files,
902 true,
903 true)
904 dependsOn r8Task
905 outputs.files r8Task.outputs.files
906}
907
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200908task r8WithRelocatedDeps {
909 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
910 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200911 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200912 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200913}
914
Clément Béraffc2d6a2022-08-02 13:03:04 +0200915task r8WithRelocatedDeps17 {
916 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
917 dependsOn r8RelocateTask(r8WithDeps17, output)
918 inputs.files r8WithDeps17.outputs.files
919 outputs.file output
920}
921
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200922task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200923 dependsOn repackageSources
924 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200925 def r8Task = r8CreateTask(
926 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100927 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200928 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200929 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200930 true)
931 dependsOn r8Task
932 outputs.files r8Task.outputs.files
933}
934
935task r8(type: Copy) {
936 def r8Task = project.hasProperty("exclude_deps")
937 ? r8WithoutDeps : r8WithRelocatedDeps
938 dependsOn r8Task
939 from r8Task.outputs.files[0]
940 into file("${buildDir}/libs")
941 rename { String fileName -> "r8.jar" }
942 outputs.file "${buildDir}/libs/r8.jar"
943}
944
945task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200946 dependsOn repackageSources
947 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200948 def r8Task = r8CreateTask(
949 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100950 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200951 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200952 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200953 false)
954 dependsOn r8Task
955 outputs.files r8Task.outputs.files
956}
957
958task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200959 dependsOn repackageSources
960 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200961 def r8Task = r8CreateTask(
962 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100963 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200964 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200965 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200966 false)
967 dependsOn r8Task
968 outputs.files r8Task.outputs.files
969}
970
971task r8NoManifestWithRelocatedDeps {
972 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
973 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200974 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200975 outputs.file output
976}
977
978task r8NoManifest(type: Copy) {
979 def r8Task = project.hasProperty("exclude_deps")
980 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
981 dependsOn r8Task
982 from r8Task.outputs.files[0]
983 into file("${buildDir}/libs")
984 rename { String fileName -> "r8_no_manifest.jar" }
985 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100986}
987
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200988def baseCompilerCommandLine(compiler, args = []) {
989 // Execute r8 commands against a stable r8 with dependencies.
990 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
991 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
992 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
993}
994
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100995def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200996 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200997 return baseCompilerCommandLine("r8", args)
998}
999
1000def baseD8CommandLine(args = []) {
1001 // Execute r8 commands against a stable r8 with dependencies.
1002 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001003}
1004
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001005def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
1006 def allArgs = [
1007 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001008 input,
1009 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001010 "--pg-map-output", output + ".map",
Morten Krogh-Jesperseneda55812023-04-25 09:26:07 +02001011 "--partition-map-output", output + "_map.zip",
Ian Zerny3ac86842022-10-05 11:49:35 +02001012 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001013 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
1014 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001015}
1016
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001017def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
1018 def allArgs = [
1019 "--classfile",
1020 input,
1021 "--output", output,
1022 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
1023 ] + args + libs.collectMany { ["--lib", it] }
1024 return baseD8CommandLine(allArgs)
1025}
1026
Ian Zernycf8ef512022-05-04 14:54:16 +02001027def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001028 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001029 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001030 outputs.file output
1031 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001032 dependsOn r8WithRelocatedDeps
1033 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001034 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001035 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001036 "--r8jar", r8Task.outputs.files[0],
1037 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001038 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001039 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001040 + (libs.collectMany { ["--lib", it] })
1041 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001042 workingDir = projectDir
1043 }
1044}
1045
Clément Bérac8b2c152022-06-22 08:23:47 +02001046task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001047 from sourceSets.libraryDesugarConversions.output
1048 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001049 baseName 'library_desugar_conversions_raw'
1050 destinationDir file('build/tmp/desugaredlibrary')
1051}
1052
1053task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001054 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001055 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001056}
1057
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001058task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1059 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001060 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001061 // We only want to include tests that use R8 when generating keep rules for applymapping.
1062 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001063 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001064 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001065}
1066
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001067task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001068 dependsOn r8WithDeps
1069 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001070 def output = "$buildDir/libs/r8tests.jar"
1071 outputs.file output
1072 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001073 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001074 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001075 "relocator",
1076 "--input",
1077 testJarSources.outputs.files[0],
1078 "--output",
1079 output,
1080 "--map",
1081 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1082 ])
1083}
1084
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001085task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001086 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1087 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001088 dependsOn r8WithDeps
1089 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001090 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001091 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001092 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001093 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001094 r8WithDeps.outputs,
1095 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001096 repackageDeps.outputs,
1097 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001098 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001099 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001100 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001101 "tracereferences",
1102 "--keep-rules",
1103 "--allowobfuscation",
1104 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001105 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001106 "--lib",
1107 repackageDeps.outputs.files[0],
1108 "--lib",
1109 repackageTestDeps.outputs.files[0],
1110 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001111 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001112 "--source",
1113 testJar.outputs.files[0],
1114 "--output",
1115 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001116 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001117}
1118
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001119task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001120 dependsOn r8LibCreateTask(
1121 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001122 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001123 r8NoManifestWithRelocatedDeps,
Søren Gjesse63a53a92023-05-03 14:33:02 +02001124 r8LibPath
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001125 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001126 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001127 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001128}
1129
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001130task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001131 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001132 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001133 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001134 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001135 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001136 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001137 repackageDeps.outputs.files,
1138 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001139 ).dependsOn(repackageDeps)
1140 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001141 outputs.file r8LibExludeDepsPath
1142}
1143
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001144task R8Desugared(type: Exec) {
1145 dependsOn downloadOpenJDKrt
1146 dependsOn r8NoManifestWithRelocatedDeps
1147 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1148 commandLine d8CfCommandLine(
1149 r8NoManifestWithRelocatedDeps.outputs.files[0],
1150 r8DesugaredPath,
1151 ["--release"])
1152 workingDir = projectDir
1153 outputs.file r8DesugaredPath
1154}
1155
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001156task R8Retrace {
1157 dependsOn R8Lib
1158 dependsOn r8LibCreateTask(
1159 "Retrace",
1160 ["src/main/keep_retrace.txt"],
1161 R8Lib,
1162 r8RetracePath,
1163 ).dependsOn(R8Lib)
1164 outputs.file r8RetracePath
1165}
1166
1167task R8RetraceNoDeps {
1168 dependsOn R8LibNoDeps
1169 dependsOn r8LibCreateTask(
1170 "RetraceNoDeps",
1171 ["src/main/keep_retrace.txt"],
1172 R8LibNoDeps,
1173 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001174 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001175 repackageDeps.outputs.files,
1176 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001177 ).dependsOn(R8LibNoDeps)
1178 outputs.file r8RetraceExludeDepsPath
1179}
1180
Mads Ager418d1ca2017-05-22 09:35:49 +02001181task sourceJar(type: Jar, dependsOn: classes) {
1182 classifier = 'src'
1183 from sourceSets.main.allSource
1184}
1185
Ian Zernya87869c2023-01-31 08:38:21 +01001186task keepAnnoJar(type: Jar) {
1187 archiveFileName = "keepanno-annotations.jar"
1188 from sourceSets.keepanno.output
1189}
1190
Mads Ager418d1ca2017-05-22 09:35:49 +02001191artifacts {
1192 archives sourceJar
1193}
1194
1195task createArtTests(type: Exec) {
1196 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001197 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001198 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001199 outputs.dir outputDir
1200 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001201 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001202 workingDir = projectDir
1203}
1204
Mads Ager418d1ca2017-05-22 09:35:49 +02001205compileTestJava {
1206 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001207}
1208
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001209task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1210 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001211 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001212 destinationDir file('build/libs')
1213}
1214
Ian Zerny923a0c12018-01-03 10:59:18 +01001215task buildR8ApiUsageSample(type: Jar) {
1216 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001217 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001218 destinationDir file('tests')
1219}
1220
Yohann Roussel548ae942018-01-05 11:13:28 +01001221task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001222 dependsOn buildR8ApiUsageSample
1223}
1224
Mads Ager418d1ca2017-05-22 09:35:49 +02001225task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001226 def resourcesDir = file("src/test/debugTestResources")
1227 def hostJar = "debug_test_resources.jar"
1228 task "compile_debugTestResources"(type: JavaCompile) {
1229 source = fileTree(dir: resourcesDir, include: '**/*.java')
1230 destinationDir = file("build/test/debugTestResources/classes")
1231 classpath = sourceSets.main.compileClasspath
1232 sourceCompatibility = JavaVersion.VERSION_1_7
1233 targetCompatibility = JavaVersion.VERSION_1_7
1234 options.compilerArgs += ["-g", "-Xlint:-options"]
1235 }
1236 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1237 archiveName = hostJar
1238 destinationDir = file("build/test/")
1239 from "build/test/debugTestResources/classes"
1240 include "**/*.class"
1241 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001242 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1243 def java8HostJar = "debug_test_resources_java8.jar"
1244 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1245 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1246 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1247 classpath = sourceSets.main.compileClasspath
1248 sourceCompatibility = JavaVersion.VERSION_1_8
1249 targetCompatibility = JavaVersion.VERSION_1_8
1250 options.compilerArgs += ["-g", "-Xlint:-options"]
1251 }
1252 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1253 archiveName = java8HostJar
1254 destinationDir = file("build/test/")
1255 from "build/test/debugTestResourcesJava8/classes"
1256 include "**/*.class"
1257 }
1258 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001259 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001260 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001261}
1262
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001263// Examples used by tests, where Android specific APIs are used.
1264task buildExampleAndroidApi(type: JavaCompile) {
1265 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1266 destinationDir = file("build/test/examplesAndroidApi/classes")
1267 classpath = files("third_party/android_jar/lib-v26/android.jar")
1268 sourceCompatibility = JavaVersion.VERSION_1_8
1269 targetCompatibility = JavaVersion.VERSION_1_8
1270}
1271
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001272task buildProtoGeneratedSources {
1273 def examplesProtoDir = file("src/test/examplesProto")
1274 examplesProtoDir.eachDir { dir ->
1275 def name = dir.getName()
1276 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1277 source = {
1278 file('third_party/proto').listFiles()
1279 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1280 .collect { zipTree(it) }
1281 }
1282 destinationDir = file("build/generated/test/proto/${name}_classes")
1283 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1284 sourceCompatibility = JavaVersion.VERSION_1_8
1285 targetCompatibility = JavaVersion.VERSION_1_8
1286 }
1287 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1288 archiveName = "${name}.jar"
1289 destinationDir = file("build/generated/test/proto")
1290 from "build/generated/test/proto/${name}_classes"
1291 include "/**/*.class"
1292 }
1293 dependsOn "jar_proto_generated_source_${name}"
1294 }
1295}
1296
1297task buildExamplesProto {
1298 def examplesProtoDir = file("src/test/examplesProto")
1299 def examplesProtoOutputDir = file("build/test/examplesProto");
1300 dependsOn buildProtoGeneratedSources
1301 task "compile_examples_proto"(type: JavaCompile) {
1302 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1303 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001304 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1305 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001306 sourceCompatibility = JavaVersion.VERSION_1_8
1307 targetCompatibility = JavaVersion.VERSION_1_8
1308 }
1309 examplesProtoDir.eachDir { dir ->
1310 def name = dir.getName()
1311 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1312 archiveName = "${name}.jar"
1313 destinationDir = examplesProtoOutputDir
1314 from "build/test/examplesProto/classes"
1315 include name + "/**/*.class"
1316 }
1317 dependsOn "jar_examples_proto_${name}"
1318 }
1319}
1320
Lars Bakc91e87e2017-08-18 08:53:10 +02001321// Proto lite generated code yields warnings when compiling with javac.
1322// We change the options passed to javac to ignore it.
1323compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1324
Søren Gjesse7320ce52018-05-07 15:45:22 +02001325
Mads Ager418d1ca2017-05-22 09:35:49 +02001326task buildExampleJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001327 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001328 task extractExamplesRuntime(type: Sync) {
1329 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001330 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001331 include "**/*.class"
1332 includeEmptyDirs false
1333 into "$buildDir/runtime/examples/"
1334 }
1335
Søren Gjesse7320ce52018-05-07 15:45:22 +02001336 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1337 from examplesDir
1338 exclude "**/*.java"
1339 exclude "**/keep-rules*.txt"
1340 into file("build/test/examples/classes")
1341 }
1342
1343 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001344 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001345 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001346 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001347 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001348 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001349 sourceCompatibility = JavaVersion.VERSION_1_7
1350 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001351 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1352 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001353 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1354 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001355 include "**/*.java"
1356 destinationDir = file("build/test/examples/classes_debuginfo_all")
1357 classpath = sourceSets.examples.compileClasspath
1358 sourceCompatibility = JavaVersion.VERSION_1_7
1359 targetCompatibility = JavaVersion.VERSION_1_7
1360 options.compilerArgs = ["-g", "-Xlint:none"]
1361 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001362 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1363 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001364 include "**/*.java"
1365 destinationDir = file("build/test/examples/classes_debuginfo_none")
1366 classpath = sourceSets.examples.compileClasspath
1367 sourceCompatibility = JavaVersion.VERSION_1_7
1368 targetCompatibility = JavaVersion.VERSION_1_7
1369 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001370 }
1371 examplesDir.eachDir { dir ->
1372 def name = dir.getName();
1373 def exampleOutputDir = file("build/test/examples");
1374 def jarName = "${name}.jar"
1375 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001376 dependsOn "jar_example_${name}_debuginfo_all"
1377 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001378 dependsOn "extractExamplesRuntime"
1379 def runtimeDependencies = copySpec { }
Ian Zernyaea82c82023-05-11 08:55:40 +02001380 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1381 archiveName = "${name}.jar"
1382 destinationDir = exampleOutputDir
1383 from "build/test/examples/classes"
1384 include name + "/**/*"
1385 with runtimeDependencies
1386 includeEmptyDirs true
1387 }
1388 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1389 archiveName = "${name}_debuginfo_all.jar"
1390 destinationDir = exampleOutputDir
1391 from "build/test/examples/classes_debuginfo_all"
1392 include name + "/**/*.class"
1393 with runtimeDependencies
1394 includeEmptyDirs false
1395 }
1396 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1397 archiveName = "${name}_debuginfo_none.jar"
1398 destinationDir = exampleOutputDir
1399 from "build/test/examples/classes_debuginfo_none"
1400 include name + "/**/*.class"
1401 with runtimeDependencies
1402 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001403 }
1404 }
1405}
1406
1407task buildExampleAndroidNJars {
1408 dependsOn downloadDeps
1409 def examplesDir = file("src/test/examplesAndroidN")
1410 task "compile_examplesAndroidN"(type: JavaCompile) {
1411 source = fileTree(dir: examplesDir, include: '**/*.java')
1412 destinationDir = file("build/test/examplesAndroidN/classes")
1413 classpath = sourceSets.main.compileClasspath
1414 sourceCompatibility = JavaVersion.VERSION_1_8
1415 targetCompatibility = JavaVersion.VERSION_1_8
1416 options.compilerArgs += ["-Xlint:-options"]
1417 }
1418 examplesDir.eachDir { dir ->
1419 def name = dir.getName();
1420 def exampleOutputDir = file("build/test/examplesAndroidN");
1421 def jarName = "${name}.jar"
1422 dependsOn "jar_examplesAndroidN_${name}"
1423 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1424 archiveName = jarName
1425 destinationDir = exampleOutputDir
1426 from "build/test/examplesAndroidN/classes"
1427 include "**/" + name + "/**/*.class"
1428 }
1429 }
1430}
1431
1432
1433task buildExampleAndroidOJars {
1434 dependsOn downloadDeps
1435 def examplesDir = file("src/test/examplesAndroidO")
1436 // NOTE: we want to enable a scenario when test needs to reference some
1437 // classes generated by legacy (1.6) Java compiler to test some specific
1438 // behaviour. To do so we compile all the java files located in sub-directory
1439 // called 'legacy' with Java 1.6, then compile the rest of the files with
1440 // Java 1.8 and a reference to previously generated 1.6 classes.
1441
1442 // Compiling all classes in dirs 'legacy' with old Java version.
1443 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1444 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1445 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1446 classpath = sourceSets.main.compileClasspath
1447 sourceCompatibility = JavaVersion.VERSION_1_6
1448 targetCompatibility = JavaVersion.VERSION_1_6
1449 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1450 }
1451 // Compiling the rest of the files as Java 1.8 code.
1452 task "compile_examplesAndroidO"(type: JavaCompile) {
1453 dependsOn "compile_examplesAndroidO_Legacy"
1454 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1455 destinationDir = file("build/test/examplesAndroidO/classes")
1456 classpath = sourceSets.main.compileClasspath
1457 classpath += files("build/test/examplesAndroidOLegacy/classes")
1458 sourceCompatibility = JavaVersion.VERSION_1_8
1459 targetCompatibility = JavaVersion.VERSION_1_8
1460 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1461 }
1462 examplesDir.eachDir { dir ->
1463 def name = dir.getName();
1464 def destinationDir = file("build/test/examplesAndroidO/classes");
1465 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1466 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1467 dependsOn: "compile_examplesAndroidO") {
1468 main = name + ".TestGenerator"
1469 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1470 args destinationDir
1471 }
1472 } else {
1473 task "generate_examplesAndroidO_${name}" () {}
1474 }
1475 }
1476 examplesDir.eachDir { dir ->
1477 def name = dir.getName();
1478 def exampleOutputDir = file("build/test/examplesAndroidO");
1479 def jarName = "${name}.jar"
1480 dependsOn "jar_examplesAndroidO_${name}"
1481 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1482 "generate_examplesAndroidO_${name}"]) {
1483 archiveName = jarName
1484 destinationDir = exampleOutputDir
1485 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1486 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1487 include "**/" + name + "/**/*.class"
1488 // Do not include generator into the test runtime jar, it is not useful.
1489 // Otherwise, shrinking will need ASM jars.
1490 exclude "**/TestGenerator*"
1491 }
1492 }
1493}
1494
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001495task buildExampleAndroidPJars {
1496 dependsOn downloadDeps
1497 def examplesDir = file("src/test/examplesAndroidP")
1498
1499 task "compile_examplesAndroidP"(type: JavaCompile) {
1500 source = fileTree(dir: examplesDir, include: '**/*.java')
1501 destinationDir = file("build/test/examplesAndroidP/classes")
1502 classpath = sourceSets.main.compileClasspath
1503 sourceCompatibility = JavaVersion.VERSION_1_8
1504 targetCompatibility = JavaVersion.VERSION_1_8
1505 options.compilerArgs += ["-Xlint:-options"]
1506 }
1507 examplesDir.eachDir { dir ->
1508 def name = dir.getName();
1509 def destinationDir = file("build/test/examplesAndroidP/classes");
1510 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1511 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1512 dependsOn: "compile_examplesAndroidP") {
1513 main = name + ".TestGenerator"
1514 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1515 args destinationDir
1516 }
1517 } else {
1518 task "generate_examplesAndroidP_${name}" () {}
1519 }
1520 }
1521 examplesDir.eachDir { dir ->
1522 def name = dir.getName();
1523 def exampleOutputDir = file("build/test/examplesAndroidP");
1524 def jarName = "${name}.jar"
1525 dependsOn "jar_examplesAndroidP_${name}"
1526 task "jar_examplesAndroidP_${name}"(type: Jar,
1527 dependsOn: ["compile_examplesAndroidP",
1528 "generate_examplesAndroidP_${name}"]) {
1529 archiveName = jarName
1530 destinationDir = exampleOutputDir
1531 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1532 include "**/" + name + "/**/*.class"
1533 // Do not include generator into the test runtime jar, it is not useful.
1534 // Otherwise, shrinking will need ASM jars.
1535 exclude "**/TestGenerator*"
1536 }
1537 }
1538}
1539
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001540def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1541 return tasks.create("buildExample${javaVersion}Jars") {
1542 def examplesDir = file("src/test/examples${javaVersion}")
1543 examplesDir.eachDir { dir ->
1544 def name = dir.getName();
1545 def exampleOutputDir = file("build/test/examples${javaVersion}");
1546 def jarName = "${name}.jar"
1547 dependsOn "jar_examples${javaVersion}_${name}"
1548 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1549 archiveName = jarName
1550 destinationDir = exampleOutputDir
1551 from sourceSet.output
1552 include "**/" + name + "/**/*.class"
1553 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001554 }
1555 }
1556}
1557
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001558buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1559buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1560buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001561buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +02001562buildExampleJarsCreateTask("Java20", sourceSets.examplesJava20)
clementberad7ab1dd2019-04-16 16:05:00 +02001563
clementberaa92e3cd2019-07-12 14:13:22 +02001564task provideArtFrameworksDependencies {
1565 cloudDependencies.tools.forEach({ art ->
1566 if (art.contains("art")) {
1567 def taskName = art.replace('/','_')
1568 dependsOn "patch_${taskName}"
1569 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1570 from "tools/${art}/framework"
1571 include "**.jar"
1572 into file("tools/${art}/out/host/linux-x86/framework")
1573 }
1574 }
1575 })
1576}
1577
Sebastien Hertzd3313772018-01-16 14:12:37 +01001578task buildKotlinR8TestResources {
1579 def examplesDir = file("src/test/kotlinR8TestResources")
1580 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001581 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1582 def name = dir.getName()
1583 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001584 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001585 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001586 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001587 task "${taskName}Java"(type: JavaCompile) {
1588 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1589 destinationDir = file(javaOutput)
1590 classpath = sourceSets.main.compileClasspath
1591 sourceCompatibility = JavaVersion.VERSION_1_6
1592 targetCompatibility = JavaVersion.VERSION_1_6
1593 options.compilerArgs += ["-g", "-Xlint:-options"]
1594 }
1595 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1596 archiveName = javaOutputJarName
1597 destinationDir = file(javaOutputJarDir)
1598 from javaOutput
1599 include "**/*.class"
1600 }
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +01001601 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001602 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001603 }
1604}
1605
Mads Ager418d1ca2017-05-22 09:35:49 +02001606task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001607 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1608 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1609 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001610 } else if (!OperatingSystem.current().isLinux()) {
1611 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001612 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001613 return;
1614 }
1615 dependsOn buildDebugTestResourcesJars
1616 dependsOn buildExampleJars
1617 dependsOn buildExampleAndroidNJars
1618 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001619 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001620 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001621 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001622 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001623 dependsOn buildExampleJava17Jars
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +02001624 dependsOn buildExampleJava20Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001625 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001626 def examplesDir = file("src/test/examples")
1627 examplesDir.eachDir { dir ->
Rico Wind9f8ccd22023-03-03 11:04:58 +01001628 def exampleOutputDir = file("build/test/examples/" + dir.getName());
1629 if (!exampleOutputDir.exists()) {
1630 exampleOutputDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02001631 }
1632 }
1633}
1634
1635task buildSmali {
1636 def smaliDir = file("src/test/smali")
1637 smaliDir.eachDirRecurse() { dir ->
1638 def name = dir.getName();
1639 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1640 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1641 smaliOutputDir.mkdirs()
1642 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001643 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001644 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1645 def javaFiles = fileTree(dir: dir, include: '*.java')
1646 def destDir = smaliOutputDir;
1647 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1648 def intermediateFileName = "${name}-intermediate.dex";
1649 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1650 if (javaFiles.empty) {
1651 if (!smaliFiles.empty) {
1652 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001653 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001654 source = smaliFiles
1655 destination = destFile
1656 }
1657 }
1658 } else {
Rico Wind67af15f2023-03-03 13:18:11 +01001659 dependsOn "${taskName}_smali"
1660 dependsOn "${taskName}_jar"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001661 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001662 source = smaliFiles
Rico Wind67af15f2023-03-03 13:18:11 +01001663 destination = destFile
Mads Ager418d1ca2017-05-22 09:35:49 +02001664 }
1665 task "${taskName}_java"(type: JavaCompile) {
1666 source = javaFiles
1667 destinationDir destDir
1668 classpath = sourceSets.main.compileClasspath
1669 sourceCompatibility = JavaVersion.VERSION_1_7
1670 targetCompatibility = JavaVersion.VERSION_1_7
1671 options.compilerArgs += ["-Xlint:-options"]
1672 }
1673 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1674 archiveName = "Test.jar"
1675 destinationDir = destDir
1676 from fileTree(dir: destDir, include: 'Test.class')
1677 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001678 }
1679 }
1680}
1681
1682tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001683 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001684 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001685 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001686 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001687 if (userDefinedCoresPerFork) {
1688 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1689 } else {
1690 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001691 maxParallelForks = processors.intdiv(3) ?: 1
1692 // On low cpu count machines (bots) we under subscribe, so increase the count.
1693 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001694 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001695 }
Rico Wind73da9f12019-09-19 09:27:07 +02001696 }
Rico Windc56f21c2019-03-12 07:29:57 +01001697 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001698
Mads Ager418d1ca2017-05-22 09:35:49 +02001699 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001700 if (project.hasProperty('disable_assertions')) {
1701 enableAssertions = false
1702 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001703 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001704 if (project.hasProperty('test_xmx')) {
1705 maxHeapSize = project.property('test_xmx')
1706 } else {
1707 maxHeapSize = "4G"
1708 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001709}
1710
1711task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001712 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001713 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1714 // Exclude the classes containing java8
1715 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1716 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1717 includeEmptyDirs = false
1718}
1719
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001720task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1721 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001722}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001723
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001724task generateR8TestKeepRules {
1725 def path = "build/generated/r8tests-keep.txt"
1726 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001727 dependsOn R8Lib
1728 doLast {
1729 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001730-dontshrink
1731-dontoptimize
1732-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001733-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001734"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001735 }
1736}
1737
1738task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001739 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1740 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001741 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001742 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001743 dependsOn generateR8TestKeepRules
1744 dependsOn testJar
1745 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1746 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1747 return pkg.toString().endsWith(".jar")
1748 } + ["${buildDir}/classes/java/test"]
1749 inputs.files testJar.outputs.files +
1750 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001751 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001752 commandLine = r8CfCommandLine(
1753 testJar.outputs.files[0],
1754 outputPath,
1755 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001756 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1757 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001758 workingDir = projectDir
1759 outputs.file outputPath
1760}
1761
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001762task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001763 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001764 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001765 dependsOn R8Lib
1766 delete r8LibTestPath
1767 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1768 def examplesDir = file("build/test")
1769 examplesDir.eachDir { dir ->
1770 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001771 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001772 from ("${buildDir}/runtime/examples")
1773 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001774 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001775}
1776
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001777def shouldRetrace() {
1778 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1779}
1780
1781def retrace(Throwable exception) {
1782 def out = new StringBuffer()
1783 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001784 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001785 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001786 out.append("\n--------------------------------------\n")
1787 out.append("${header}\n")
1788 out.append("--------------------------------------\n")
1789 Process process = command.execute()
1790 def processIn = new PrintStream(process.getOut())
1791 process.consumeProcessOutput(out, err)
1792 exception.printStackTrace(processIn)
1793 processIn.flush()
1794 processIn.close()
1795 def errorDuringRetracing = process.waitFor() != 0
1796 if (errorDuringRetracing) {
1797 out.append("ERROR DURING RETRACING\n")
1798 out.append(err.toString())
1799 }
1800 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1801 out.append("\n\n--------------------------------------\n")
1802 out.append("OBFUSCATED STACKTRACE\n")
1803 out.append("--------------------------------------\n")
1804 }
1805 return out.toString()
1806}
1807
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001808def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001809 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001810 if (shouldRetrace()) {
1811 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001812 exception.setStackTrace([] as StackTraceElement[])
1813 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001814 }
1815}
1816
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001817def filterStackTraces(TestResult result) {
1818 for (Throwable throwable : result.getExceptions()) {
1819 filterStackTrace(throwable)
1820 }
1821}
1822
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001823// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001824def filterStackTrace(Throwable exception) {
1825 if (!project.hasProperty('print_full_stacktraces')) {
1826 def elements = []
1827 def skipped = []
1828 for (StackTraceElement element : exception.getStackTrace()) {
1829 if (element.toString().contains("com.android.tools.r8")) {
1830 elements.addAll(skipped)
1831 elements.add(element)
1832 skipped.clear()
1833 } else {
1834 skipped.add(element)
1835 }
1836 }
1837 exception.setStackTrace(elements as StackTraceElement[])
1838 }
1839}
1840
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001841def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1842 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1843 exceptions.forEach { it.printStackTrace(printer) }
1844 }
1845}
1846
Ian Zerny89f16cf2021-04-29 21:10:09 +02001847static def escapeHtml(String string) {
1848 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1849}
1850
1851static def urlEncode(String string) {
1852 // Not sure why, but the + also needs to be converted to have working links.
1853 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1854}
1855
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001856def ensureDir(File dir) {
1857 dir.mkdirs()
1858 return dir
1859}
1860
Ian Zerny89f16cf2021-04-29 21:10:09 +02001861// Some of our test parameters have new lines :-( We really don't want test names to span lines.
1862static def sanitizedTestName(testDesc) {
1863 if (testDesc.getName().contains("\n")) {
1864 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
1865 }
1866 return testDesc.getName()
1867}
1868
1869static def desanitizedTestName(testName) {
1870 return testName
1871}
1872
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001873def getTestReportEntryDir(reportDir, testDesc) {
1874 return ensureDir(reportDir.toPath()
1875 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02001876 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001877 .toFile())
1878}
1879
Ian Zerny89f16cf2021-04-29 21:10:09 +02001880def getTestReportEntryURL(reportDir, testDesc) {
1881 def classDir = urlEncode(testDesc.getClassName())
1882 def testDir = urlEncode(sanitizedTestName(testDesc))
1883 return "file://${reportDir}/${classDir}/${testDir}"
1884}
1885
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001886def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
1887 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
1888 return dir.resolve(fileName).toFile()
1889}
1890
Ian Zerny89f16cf2021-04-29 21:10:09 +02001891def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
1892 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
1893 new FileWriter(file, append).withCloseable fn
1894}
1895
Ian Zerny27ea4c72021-04-29 22:35:49 +02001896static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001897 def out = new StringBuilder()
1898 def err = new StringBuilder()
1899 def proc = "git rev-parse --abbrev-ref HEAD".execute()
1900 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02001901 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001902}
1903
Ian Zerny27ea4c72021-04-29 22:35:49 +02001904static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02001905 def number = 0
1906 while (true) {
1907 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
1908 if (!freshIndex.exists()) {
1909 return freshIndex
1910 }
1911 }
1912}
1913
1914def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
1915 def out = new StringBuilder()
1916 def err = new StringBuilder()
1917 def proc = "find . -name ${fileName}".execute([], reportDir)
1918 proc.waitForProcessOutput(out, err)
1919 def outString = out.toString()
1920 outString.eachLine {
1921 // Lines are of the form: ./<class>/<name>/FAILURE
1922 def clazz = null
1923 def name = null
1924 try {
1925 def trimmed = it.trim()
1926 def line = trimmed.substring(2)
1927 def sep = line.indexOf("/")
1928 clazz = line.substring(0, sep)
1929 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
1930 } catch (Exception e) {
1931 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
1932 return
1933 }
1934 onTest(clazz, desanitizedTestName(name))
1935 }
1936 return !outString.trim().isEmpty()
1937}
1938
1939def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
1940 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
1941}
1942
1943def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
1944 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
1945}
1946
1947def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
1948 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
1949}
1950
Ian Zerny27ea4c72021-04-29 22:35:49 +02001951def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001952 // Hide all test events from the console, they are written to the report.
1953 task.testLogging { events = [] }
1954
Ian Zernycae764d2021-08-16 08:25:15 +02001955 def branch = project.hasProperty('testing-state-name')
1956 ? project.getProperty('testing-state-name')
1957 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02001958 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02001959 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02001960 def resetState = project.hasProperty('reset-testing-state')
1961 def reportDirExists = reportDir.exists()
1962 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02001963
1964 def hasFailingTests = false;
1965 if (resuming) {
1966 // Test filtering happens before the test execution is initiated so compute it here.
1967 // If there are still failing tests in the report, include only those.
1968 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
1969 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
1970 })
1971 // Otherwise exclude all of the test already marked as succeeding.
1972 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02001973 // Also allow the test to overall succeed if there are no remaining tests that match,
1974 // which is natural if the state already succeeded in full.
1975 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02001976 forEachTestReportAlreadyPassing(reportDir, {
1977 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
1978 })
1979 forEachTestReportAlreadySkipped(reportDir, {
1980 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
1981 })
1982 }
1983 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001984
1985 task.beforeSuite { desc ->
1986 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02001987 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02001988 if (resetState && reportDirExists) {
1989 delete reportDir
1990 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02001991 if (resuming) {
1992 if (index.exists()) {
1993 parentReport = getFreshTestReportIndex(reportDir)
1994 index.renameTo(parentReport)
1995 }
1996 } else {
1997 reportDir.mkdirs()
1998 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02001999 def runPrefix = resuming ? "Resuming" : "Starting"
2000 def title = "${runPrefix} @ ${branch}"
2001 // Print a console link to the test report for easy access.
2002 println "${runPrefix} test, report written to:"
2003 println " file://${index}"
2004 // Print the new index content.
2005 index << "<html><head><title>${title}</title>"
2006 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002007 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002008 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002009 index << "<p>Run on: ${new Date()}</p>"
2010 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002011 if (parentReport != null) {
2012 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
2013 }
2014 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
2015 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002016 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002017 }
2018 }
2019
2020 task.afterSuite { desc, result ->
2021 if (!desc.parent) {
2022 // Update the final test results in the index.
2023 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002024 if (result.resultType == TestResult.ResultType.SUCCESS) {
2025 if (hasFailingTests) {
2026 index << "<h2>Rerun of failed tests now pass!</h2>"
2027 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
2028 } else {
2029 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
2030 }
2031 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002032 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002033 } else {
2034 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
2035 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002036 index << "<li>Number of tests: ${result.testCount}"
2037 index << "<li>Failing tests: ${result.failedTestCount}"
2038 index << "<li>Successful tests: ${result.successfulTestCount}"
2039 index << "<li>Skipped tests: ${result.skippedTestCount}"
2040 index << "</ul></body></html>"
2041 }
2042 }
2043
2044 // Events to stdout/err are appended to the files in the test directories.
2045 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02002046 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
2047 it.append(event.getMessage())
2048 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002049 }
2050
Ian Zerny27ea4c72021-04-29 22:35:49 +02002051 task.beforeTest { desc ->
2052 // Remove any stale output files before running the test.
2053 for (def destType : TestOutputEvent.Destination.values()) {
2054 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
2055 if (destFile.exists()) {
2056 delete destFile
2057 }
2058 }
2059 }
2060
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002061 task.afterTest { desc, result ->
2062 if (result.getTestCount() != 1) {
2063 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
2064 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002065 // Clear any previous result files.
2066 for (def resultType : TestResult.ResultType.values()) {
2067 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
2068 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002069 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002070 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
2071 it.append(result.getResultType().name())
2072 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002073 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002074 withTestResultEntryWriter(reportDir, desc, "time", false, {
2075 it.append("${result.getEndTime() - result.getStartTime()}")
2076 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002077 // For failed tests, update the index and emit stack trace information.
2078 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002079 def title = escapeHtml("${desc.className}.${desc.name}")
2080 def link = getTestReportEntryURL(reportDir, desc)
2081 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002082 if (!result.exceptions.isEmpty()) {
2083 printAllStackTracesToFile(
2084 result.exceptions,
2085 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002086 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002087 desc,
2088 "exceptions-raw.txt"))
2089 filterStackTraces(result)
2090 printAllStackTracesToFile(
2091 result.exceptions,
2092 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002093 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002094 desc,
2095 "exceptions-filtered.txt"))
2096 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002097 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2098 result.exceptions.forEach { writer.append(retrace(it)) }
2099 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002100 }
2101 }
2102 }
2103 }
2104}
2105
Rico Windf2f4c292021-04-23 07:06:13 +02002106def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002107def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002108
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002109test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002110
Ian Zernyc1582852023-01-30 13:45:36 +01002111 dependsOn sourceSets.keepanno.output
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002112 dependsOn buildLibraryDesugarConversions
2113 dependsOn getJarsFromSupportLibs
2114 // R8.jar is required for running bootstrap tests.
2115 dependsOn r8
2116
Ian Zerny27ea4c72021-04-29 22:35:49 +02002117 def useTestingState = project.hasProperty('testing-state')
2118 if (useTestingState) {
2119 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002120 }
2121
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002122 if (project.hasProperty('generate_golden_files_to')) {
2123 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2124 assert project.hasProperty('HEAD_sha1')
2125 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2126 }
2127
2128 if (project.hasProperty('use_golden_files_in')) {
2129 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2130 assert project.hasProperty('HEAD_sha1')
2131 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2132 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002133
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002134 if (project.hasProperty('kotlin_compiler_dev')) {
2135 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2136 }
2137
2138 if (project.hasProperty('kotlin_compiler_old')) {
2139 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2140 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002141
Ian Zerny27ea4c72021-04-29 22:35:49 +02002142 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002143 testLogging.exceptionFormat = 'full'
2144 if (project.hasProperty('print_test_stdout')) {
2145 testLogging.showStandardStreams = true
2146 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002147 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002148 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002149 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002150 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002151 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002152
Ian Zerny324d7612019-03-20 10:52:28 +01002153 // Forward runtime configurations for test parameters.
2154 if (project.hasProperty('runtimes')) {
2155 println "NOTE: Running with runtimes: " + project.property('runtimes')
2156 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002157 }
2158
Christoffer Quist Adamsen3b3a4b02023-02-06 13:43:30 +01002159 if (project.hasProperty('art_profile_rewriting_completeness_check')) {
2160 String key = 'com.android.tools.r8.artprofilerewritingcompletenesscheck'
2161 String value = project.property('art_profile_rewriting_completeness_check')
2162 systemProperty key, value
2163 }
2164
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002165 if (project.hasProperty('slow_tests')) {
2166 systemProperty 'slow_tests', project.property('slow_tests')
2167 }
2168
Søren Gjesseef195772021-03-11 16:04:42 +01002169
2170 if (project.hasProperty('desugar_jdk_json_dir')) {
2171 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2172 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002173 if (project.hasProperty('desugar_jdk_libs')) {
2174 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2175 }
2176
Ian Zerny27ea4c72021-04-29 22:35:49 +02002177 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002178 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2179 afterTest { desc, result ->
2180 def executionTime = (result.endTime - result.startTime) / 1000
2181 testTimes["${desc.name} [${desc.className}]"] = executionTime
2182 }
2183 afterSuite { desc, result ->
2184 // parent is null if all tests are done.
2185 if (desc.parent == null) {
2186 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2187 sortedTimes.eachWithIndex { key, value, i ->
Rico Windf94f4302023-01-03 10:57:10 +01002188 println "$key: $value"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002189 }
2190 }
2191 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002192 }
Rico Windf2f4c292021-04-23 07:06:13 +02002193
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002194 if (project.hasProperty('one_line_per_test')) {
2195 beforeTest { desc ->
2196 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002197 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002198
2199 afterTest { desc, result ->
2200 if (result.resultType == TestResult.ResultType.FAILURE) {
2201 printStackTrace(result)
2202 }
2203 if (project.hasProperty('update_test_timestamp')) {
2204 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2205 }
2206 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002207 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002208 } else {
2209 afterTest { desc, result ->
2210 if (result.resultType == TestResult.ResultType.FAILURE) {
2211 printStackTrace(result)
2212 }
Rico Windf88b6be2018-12-11 15:14:05 +01002213 }
2214 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002215 }
2216 if (project.hasProperty('no_internal')) {
2217 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002218 } else {
2219 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002220 }
2221 if (project.hasProperty('only_internal')) {
2222 include "com/android/tools/r8/internal/**"
2223 }
Rico Wind4e218292019-03-07 12:44:49 +01002224
Rico Windba151112020-10-01 08:16:33 +02002225 if (project.hasProperty('test_namespace')) {
2226 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2227 }
2228
Ian Zerny3ced9262022-03-29 11:06:02 +02002229 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2230 // Don't run anything, deprecated
2231 println "Running with deprecated tool d8, not running any tests"
2232 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002233 }
Rico Windbc820812022-05-31 09:19:56 +02002234 if (project.hasProperty('no_arttests')) {
2235 exclude "com/android/tools/r8/art/**"
2236 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002237 if (project.hasProperty('shard_count') ) {
2238 assert project.hasProperty('shard_number')
2239 int shard_count = project.getProperty('shard_count') as Integer
2240 int shard_number = project.getProperty('shard_number') as Integer
2241 assert shard_count < 65536
2242 assert shard_number < shard_count
2243 exclude {
2244 entry ->
2245 // Don't leave out directories. Leaving out a directory means all entries below.
2246 if (entry.file.isDirectory()) {
2247 return false
2248 }
2249 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2250 int hash = Integer.parseInt(first4, 16)
2251 return hash % shard_count != shard_number
2252 }
2253 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002254 if (project.hasProperty('test_dir')) {
2255 systemProperty 'test_dir', project.property('test_dir')
2256 }
Rico Windfc645a22023-06-14 12:37:18 +02002257 if (project.hasProperty('command_cache_dir')) {
2258 systemProperty 'command_cache_dir', project.property('command_cache_dir')
Rico Wind841eee32023-06-12 10:47:03 +02002259 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002260 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002261 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002262 // R8lib should be used instead of the main output and all the tests in
2263 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002264 classpath = sourceSets.test.runtimeClasspath.filter {
2265 !it.getAbsolutePath().contains("/build/")
2266 }
2267 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002268 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002269 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002270 if (OperatingSystem.current().isLinux()
2271 || OperatingSystem.current().isMacOsX()
2272 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002273 if (OperatingSystem.current().isMacOsX()) {
2274 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2275 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2276 "See tools/docker/README.md for details.")
2277 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002278 if (OperatingSystem.current().isWindows()) {
2279 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2280 "Art only runs on Linux and tests requiring Art will be skipped")
2281 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002282 dependsOn downloadDeps
2283 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002284 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002285 dependsOn buildSmali
Mads Ager418d1ca2017-05-22 09:35:49 +02002286 dependsOn buildPreNJdwpTestsJar
Clément Bérac94b6202021-09-28 11:16:58 +00002287 dependsOn compileTestNGRunner
clementberaa92e3cd2019-07-12 14:13:22 +02002288 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002289 } else {
2290 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002291 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002292 }
2293}
2294
Mads Ager418d1ca2017-05-22 09:35:49 +02002295
2296task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002297 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002298 classpath = sourceSets.main.compileClasspath
2299 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002300 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002301 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002302 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002303 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002304 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002305 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002306 include '**/com/android/tools/r8/CompilationMode.java'
2307 include '**/com/android/tools/r8/D8.java'
2308 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002309 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2310 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002311 include '**/com/android/tools/r8/Diagnostic.java'
2312 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002313 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2314 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002315 include '**/com/android/tools/r8/ProgramConsumer.java'
2316 include '**/com/android/tools/r8/ProgramResource.java'
2317 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002318 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002319 include '**/com/android/tools/r8/ResourceException.java'
2320 include '**/com/android/tools/r8/StringConsumer.java'
2321 include '**/com/android/tools/r8/StringResource.java'
2322 include '**/com/android/tools/r8/Version.java'
2323 include '**/com/android/tools/r8/origin/*.java'
2324}
2325
2326task javadocR8(type: Javadoc) {
2327 title "R8 API"
2328 classpath = sourceSets.main.compileClasspath
2329 source = sourceSets.main.allJava
2330 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2331 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2332 include '**/com/android/tools/r8/BaseCommand.java'
2333 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2334 include '**/com/android/tools/r8/ClassFileConsumer.java'
2335 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2336 include '**/com/android/tools/r8/CompilationFailedException.java'
2337 include '**/com/android/tools/r8/CompilationMode.java'
2338 include '**/com/android/tools/r8/R8.java'
2339 include '**/com/android/tools/r8/R8Command.java'
2340 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2341 include '**/com/android/tools/r8/Diagnostic.java'
2342 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002343 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2344 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002345 include '**/com/android/tools/r8/ProgramConsumer.java'
2346 include '**/com/android/tools/r8/ProgramResource.java'
2347 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2348 include '**/com/android/tools/r8/Resource.java'
2349 include '**/com/android/tools/r8/ResourceException.java'
2350 include '**/com/android/tools/r8/StringConsumer.java'
2351 include '**/com/android/tools/r8/StringResource.java'
2352 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002353 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002354}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002355
2356task copyMavenDeps(type: Copy) {
2357 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002358 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002359 from configurations.testCompile into "$buildDir/deps"
2360}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002361
Rico Wind23a05112019-03-27 08:00:44 +01002362task printMavenDeps {
2363 // Only actually print to stdout when we are updating.
2364 if (project.hasProperty('updatemavendeps')) {
2365 for (Configuration config : configurations) {
2366 if (!config.isCanBeResolved()) {
2367 continue
2368 }
2369 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2370 it.selected.id
2371 }
2372 def result = dependencies.createArtifactResolutionQuery()
2373 .forComponents(componentIds)
2374 .withArtifacts(MavenModule, MavenPomArtifact)
2375 .execute()
2376 for (component in result.resolvedComponents) {
2377 component.getArtifacts(MavenPomArtifact).each {
2378 println "POM: ${it.file} ${component.id}"
2379 }
2380 }
2381 config.each {
2382 println "JAR: ${it}"
2383 }
2384 }
2385 }
2386}
Ian Zerny9713c032020-01-23 11:41:58 +01002387
2388allprojects {
2389 tasks.withType(Exec) {
2390 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002391 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002392 }
2393 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002394}