blob: 4b948af91ab7e8164ebc63058ca70cceb72e054c [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
Søren Gjesse63a53a92023-05-03 14:33:02 +020010import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000011import tasks.GetJarsFromConfiguration
Mads Ager418d1ca2017-05-22 09:35:49 +020012
Ian Zerny5fffb0a2019-02-11 13:54:22 +010013plugins {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010014 id "net.ltgt.errorprone" version "2.0.2"
Ian Zerny5fffb0a2019-02-11 13:54:22 +010015}
16
17apply plugin: 'java'
18apply plugin: 'idea'
19
Sebastien Hertz143ed112018-02-13 14:26:41 +010020ext {
Søren Gjesse44faa872023-05-23 12:21:22 +020021 // When updating dependencies also update and run
22 // tools/create_local_maven_with_dependencies.py
Sebastien Hertz143ed112018-02-13 14:26:41 +010023 androidSupportVersion = '25.4.0'
Ian Zerny0b4f14a2023-04-28 09:51:12 +020024 asmVersion = '9.5' // When updating update tools/asmifier.py, build.src and Toolhelper as well.
Søren Gjesse780c2e82023-03-21 09:48:13 +010025 javassistVersion = '3.29.2-GA'
Sebastien Hertz143ed112018-02-13 14:26:41 +010026 espressoVersion = '3.0.0'
Søren Gjessef5688fb2023-05-03 15:08:14 +020027 fastutilVersion = '7.2.1'
Søren Gjesse63a53a92023-05-03 14:33:02 +020028 guavaVersion = '31.1-jre'
Mads Ager48dd79e2018-05-15 09:13:55 +020029 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010030 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080031 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +010032 // The kotlin version is only here to specify the kotlin language level,
33 // all kotlin compilations are done in tests.
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +010034 kotlinVersion = '1.8.0'
Morten Krogh-Jespersen789ab762023-06-08 10:45:51 +020035 kotlinExtMetadataJVMVersion = '0.6.2'
Søren Gjessea599e652023-05-03 14:35:06 +020036 smaliVersion = '3.0.3'
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010037 errorproneVersion = '2.18.0'
clementbera4f9c2a92019-07-09 08:50:37 +020038 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010039}
40
Mads Ager418d1ca2017-05-22 09:35:49 +020041repositories {
Søren Gjesse44faa872023-05-23 12:21:22 +020042 maven {
43 url uri('file:third_party/dependencies')
44 }
Mads Ager418d1ca2017-05-22 09:35:49 +020045}
46
Jinseong Jeon05064e12018-07-03 00:21:12 -070047if (project.hasProperty('with_code_coverage')) {
48 apply plugin: 'jacoco'
49}
50
Mads Ager418d1ca2017-05-22 09:35:49 +020051// Custom source set for example tests and generated tests.
52sourceSets {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020053 main {
54 java {
Ian Zernyc1582852023-01-30 13:45:36 +010055 srcDirs = ['src/main/java', 'src/keepanno/java']
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020056 }
57 resources {
58 srcDirs "third_party/api_database/api_database"
59 }
60 }
Clément Béraffc2d6a2022-08-02 13:03:04 +020061 main17 {
62 java {
Ian Zernyc1582852023-01-30 13:45:36 +010063 srcDirs = ['src/main/java', 'src/keepanno/java']
Clément Béraffc2d6a2022-08-02 13:03:04 +020064 }
65 resources {
66 srcDirs "third_party/api_database/api_database"
67 }
68 }
Mads Ager418d1ca2017-05-22 09:35:49 +020069 test {
70 java {
71 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020072 'src/test/java',
73 'build/generated/test/java',
74 ]
75 }
76 }
Yohann Rousselbb571622017-11-09 10:47:36 +010077 apiUsageSample {
78 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020079 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
80 include 'com/android/tools/apiusagesample/*.java'
81 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
82 include 'com/android/tools/r8/D8CommandParser.java'
83 include 'com/android/tools/r8/R8CommandParser.java'
84 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010085 }
Yohann Rousselbb571622017-11-09 10:47:36 +010086 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010087 cfSegments {
88 java {
89 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
90 }
91 output.resourcesDir = 'build/classes/cfSegments'
92 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +010093 libraryDesugarConversions {
94 java {
95 srcDirs = ['src/library_desugar/java']
96 }
97 output.resourcesDir = 'build/classes/library_desugar_conversions'
98 }
Mads Ager418d1ca2017-05-22 09:35:49 +020099 debugTestResources {
100 java {
101 srcDirs = ['src/test/debugTestResources']
102 }
103 output.resourcesDir = 'build/classes/debugTestResources'
104 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200105 debugTestResourcesJava8 {
106 java {
107 srcDirs = ['src/test/debugTestResourcesJava8']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
110 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200111 examples {
112 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800113 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200114 }
115 output.resourcesDir = 'build/classes/examples'
116 }
Ian Zernyd3020482019-04-25 07:05:04 +0200117 examplesJava9 {
118 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200119 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200120 }
121 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500122 examplesJava10 {
123 java {
124 srcDirs = ['src/test/examplesJava10']
125 }
126 }
Ian Zernyd3020482019-04-25 07:05:04 +0200127 examplesJava11 {
128 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200129 srcDirs = ['src/test/examplesJava11']
130 }
131 }
Søren Gjessee9966932021-09-15 17:08:37 +0200132 examplesJava17 {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100133 java {
Søren Gjessee9966932021-09-15 17:08:37 +0200134 srcDirs = ['src/test/examplesJava17']
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100135 }
136 }
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200137 examplesJava20 {
Søren Gjessed1e08992022-02-07 16:46:31 +0100138 java {
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200139 srcDirs = ['src/test/examplesJava20']
Søren Gjessed1e08992022-02-07 16:46:31 +0100140 }
141 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200142 examplesAndroidN {
143 java {
144 srcDirs = ['src/test/examplesAndroidN']
145 }
146 output.resourcesDir = 'build/classes/examplesAndroidN'
147 }
148 examplesAndroidO {
149 java {
150 srcDirs = ['src/test/examplesAndroidO']
151 }
152 output.resourcesDir = 'build/classes/examplesAndroidO'
153 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200154 examplesAndroidP {
155 java {
156 srcDirs = ['src/test/examplesAndroidP']
157 }
158 output.resourcesDir = 'build/classes/examplesAndroidP'
159 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200160 examplesProto {
161 java {
162 srcDirs = ['src/test/examplesProto']
163 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200164 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
165 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200166 output.resourcesDir = 'build/classes/examplesProto'
167 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100168 kotlinR8TestResources {
169 java {
170 srcDirs = ['src/test/kotlinR8TestResources']
171 }
172 output.resourcesDir = 'build/classes/kotlinR8TestResources'
173 }
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100174 keepanno {
175 java {
Ian Zerny172aca22022-11-03 13:07:48 +0100176 srcDirs = ['src/keepanno/java']
Ian Zernya87869c2023-01-31 08:38:21 +0100177 include 'com/android/tools/r8/keepanno/annotations/*.java'
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100178 }
179 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200180}
181
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800182// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
183// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
184// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
185// for context.
186idea {
187 sourceSets.all { SourceSet sources ->
188 module {
Ian Zernyc1582852023-01-30 13:45:36 +0100189 if (sources.name == "main") {
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800190 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100191 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800192 } else {
193 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100194 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800195 }
196 }
197 }
198}
199
Yohann Roussel126f6872017-08-03 16:25:32 +0200200configurations {
201 supportLibs
202}
203
Mads Ager418d1ca2017-05-22 09:35:49 +0200204dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100205 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200206 // Include all of guava when compiling the code, but exclude annotations that we don't
207 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100208 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100209 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200210 exclude group: 'com.google.errorprone'
211 exclude group: 'com.google.code.findbugs'
212 exclude group: 'com.google.j2objc'
213 exclude group: 'org.codehaus.mojo'
Søren Gjesse308a4702023-05-31 12:27:12 +0200214 exclude group: 'com.google.guava', module: 'listenablefuture'
215 exclude group: 'com.google.guava', module: 'failureaccess'
Mads Ager0aa48052017-09-15 12:39:15 +0200216 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100217 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
218 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
219 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
220 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
221 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
222 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
223 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200224
Clément Béraffc2d6a2022-08-02 13:03:04 +0200225 main17Implementation "com.google.code.gson:gson:$gsonVersion"
226 // Include all of guava when compiling the code, but exclude annotations that we don't
227 // need from the packaging.
228 main17CompileOnly("com.google.guava:guava:$guavaVersion")
229 main17Implementation("com.google.guava:guava:$guavaVersion", {
230 exclude group: 'com.google.errorprone'
231 exclude group: 'com.google.code.findbugs'
232 exclude group: 'com.google.j2objc'
233 exclude group: 'org.codehaus.mojo'
234 })
235 main17Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
236 main17Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
237 main17Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
238 main17Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
239 main17Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
240 main17Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
241 main17Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +0100242
Mads Ager418d1ca2017-05-22 09:35:49 +0200243 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100244 testCompile "junit:junit:$junitVersion"
Ian Zerny161ff742022-01-20 12:39:40 +0100245 testCompile "com.google.guava:guava:$guavaVersion"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100246 testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
247 testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
Søren Gjessea599e652023-05-03 14:35:06 +0200248 testCompile group: 'com.android.tools.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200249 testCompile files('third_party/jasmin/jasmin-2.4.jar')
250 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200251 testCompile files('third_party/ddmlib/ddmlib.jar')
Ian Zerny161ff742022-01-20 12:39:40 +0100252 testCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
253 testCompile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
254 testCompile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
255 testCompile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
256 testCompile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
257 testCompile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
Søren Gjesse780c2e82023-03-21 09:48:13 +0100258 testCompile group: 'org.javassist', name: 'javassist', version: javassistVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100259
Sebastien Hertz143ed112018-02-13 14:26:41 +0100260 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
261 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200262 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100263 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800264 examplesCompile "junit:junit:$junitVersion"
265 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100266 supportLibs "com.android.support:support-v4:$androidSupportVersion"
267 supportLibs "junit:junit:$junitVersion"
268 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100269 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100270 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100271 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100272 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100273
274 keepannoCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
275 keepannoCompile "com.google.guava:guava:$guavaVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200276}
277
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100278def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100279def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200280def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100281def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100282def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +0200283def java11ClassFiles = "$buildDir/classes/java/mainJava11"
284def r8RetracePath = "$buildDir/libs/r8retrace.jar"
285def r8RetraceExludeDepsPath = "$buildDir/libs/r8retrace-exclude-deps.jar"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100286
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200287def osString = OperatingSystem.current().isLinux() ? "linux" :
288 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200289
290def cloudDependencies = [
291 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200292 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100293 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200294 ],
295 "third_party": [
Rico Winde4aee2a2023-01-26 13:46:40 +0100296 "aapt2",
Rico Windf72fa152018-10-22 15:41:03 +0200297 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200298 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200299 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100300 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200301 "android_jar/lib-v19",
302 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100303 "android_jar/lib-v22",
304 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200305 "android_jar/lib-v24",
306 "android_jar/lib-v25",
307 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100308 "android_jar/lib-v27",
309 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200310 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200311 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100312 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100313 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100314 "android_jar/lib-v33",
Morten Krogh-Jespersenfdbe3272023-02-10 12:25:07 +0100315 "android_jar/lib-v34",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200316 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200317 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200318 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200319 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200320 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200321 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100322 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200323 "dart-sdk",
324 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200325 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100326 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200327 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200328 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200329 "jacoco/0.8.2",
330 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200331 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100332 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200333 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200334 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200335 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200336 "rhino-android-1.1.1",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200337 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100338 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200339 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100340 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200341 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen47efa232023-01-20 11:12:06 +0100342 "kotlin/kotlin-compiler-1.8.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200343 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200344 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100345 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200346 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000347 "openjdk/desugar_jdk_libs_11",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200348 "openjdk/desugar_jdk_libs_releases/1.0.9",
349 "openjdk/desugar_jdk_libs_releases/1.0.10",
350 "openjdk/desugar_jdk_libs_releases/1.1.0",
351 "openjdk/desugar_jdk_libs_releases/1.1.1",
352 "openjdk/desugar_jdk_libs_releases/1.1.5",
Clément Béraaa7f9fa2023-08-01 14:29:23 +0200353 "openjdk/desugar_jdk_libs_releases/2.0.3",
clementbera8dbfeda2019-07-03 11:24:13 +0200354 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100355 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200356 "proguard/proguard5.2.1",
357 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200358 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000359 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200360 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200361 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200362 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200363 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200364 "r8mappings",
Morten Krogh-Jespersen062e2c12023-06-26 11:18:13 +0200365 "smali",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200366 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200367 ],
368 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
369 // container on other platforms where supported.
370 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200371 "linux/art",
372 "linux/art-5.1.1",
373 "linux/art-6.0.1",
374 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100375 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100376 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100377 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200378 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200379 "linux/host/art-13.0.0",
Søren Gjesse59460962023-07-31 10:43:44 +0200380 "linux/host/art-14.0.0-beta3",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200381 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200382 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100383 "linux/dalvik-4.0.4",
Mads Ager418d1ca2017-05-22 09:35:49 +0200384 ]
385]
386
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100387def cloudSystemDependencies = [
388 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200389 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200390 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100391 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100392 "openjdk/jdk-17/linux",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200393 "openjdk/jdk-20/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100394 ],
395 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200396 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200397 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100398 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100399 "openjdk/jdk-17/osx",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200400 "openjdk/jdk-20/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100401 ],
402 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200403 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100404 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100405 "openjdk/jdk-17/windows",
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200406 "openjdk/jdk-20/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100407 ],
408]
409
410if (OperatingSystem.current().isWindows()) {
411 cloudSystemDependencies.windows.each { entry ->
412 cloudDependencies.get(entry.key).addAll(entry.value)
413 }
414} else if (OperatingSystem.current().isLinux()) {
415 cloudSystemDependencies.linux.each { entry ->
416 cloudDependencies.get(entry.key).addAll(entry.value)
417 }
418} else if (OperatingSystem.current().isMacOsX()) {
419 cloudSystemDependencies.osx.each { entry ->
420 cloudDependencies.get(entry.key).addAll(entry.value)
421 }
422} else {
423 println "WARNING: Unsupported system: " + OperatingSystem.current()
424}
425
426def getDownloadDepsTaskName(entryKey, entryFile) {
427 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
428}
429
Mads Ager418d1ca2017-05-22 09:35:49 +0200430cloudDependencies.each { entry ->
431 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200432 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100433 type DownloadDependency.Type.GOOGLE_STORAGE
434 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200435 }
436 }
437}
438
439def x20Dependencies = [
440 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200441 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700442 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200443 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200444 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000445 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100446 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100447 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200448 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100449 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200450 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200451 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200452 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200453 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200454 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200455 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200456 "proguard/proguard_internal_159423826",
457 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200458 "proto",
459 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200460 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200461 "youtube/youtube.android_16.20",
462 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200463 ],
464]
465
466x20Dependencies.each { entry ->
467 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100468 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
469 type DownloadDependency.Type.X20
470 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200471 }
472 }
473}
474
Rico Windf6c74ce2018-12-04 08:50:55 +0100475task downloadOpenJDKrt {
476 cloudDependencies.each { entry ->
477 entry.value.each { entryFile ->
478 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100479 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100480 }
481 }
482 }
483}
484
Tamas Kenez0e10c562017-06-08 10:00:34 +0200485task downloadAndroidCts {
486 cloudDependencies.each { entry ->
487 entry.value.each { entryFile ->
488 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100489 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200490 }
491 }
492 }
493}
494
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200495task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200496 cloudDependencies.each { entry ->
497 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100498 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200499 }
500 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200501}
502
503task downloadX20Deps() {
504 x20Dependencies.each { entry ->
505 entry.value.each { entryFile ->
506 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200507 }
508 }
509}
510
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200511task downloadDeps {
512 dependsOn downloadCloudDeps
513 if (!project.hasProperty('no_internal')) {
514 dependsOn downloadX20Deps
515 }
516}
517
Mads Ager418d1ca2017-05-22 09:35:49 +0200518allprojects {
519 sourceCompatibility = JavaVersion.VERSION_1_8
520 targetCompatibility = JavaVersion.VERSION_1_8
521}
522
Rico Wind266336c2019-02-25 10:11:38 +0100523// TODO(ricow): Remove debug prints
524println("NOTE: Current operating system: " + OperatingSystem.current())
525println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
526
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100527// Check if running with the JDK location from tools/jdk.py.
528if (OperatingSystem.current().isWindows()) {
529 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100530 compileJava.options.encoding = "UTF-8"
531 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100532} else {
533 def javaHomeOut = new StringBuilder()
534 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400535 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100536 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
537 def jdkHome = new File(javaHomeOut.toString().trim())
538 if (!jdkHome.exists()) {
539 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
540 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
541 println("WARNING: Gradle is running in a non-pinned Java"
542 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000543 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100544 } else {
545 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100546 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200547}
548
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200549compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200550
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100551sourceSets.configureEach { sourceSet ->
552 tasks.named(sourceSet.compileJavaTaskName).configure {
553 // Default disable errorprone (enabled and setup below).
554 options.errorprone.enabled = false
555 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100556 // Run all compilation tasks in a forked subprocess.
557 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100558 // Javac often runs out of stack space when compiling the tests.
559 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200560 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100561 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200562 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100563 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
564 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
565 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200566}
567
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100568def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
569 tasks.named(sourceSet).get().configure {
570 def jdkDir = "third_party/openjdk/${javaHome}/"
571 options.fork = true
572 options.forkOptions.jvmArgs = []
573 if (enablePreview) {
574 options.compilerArgs.add('--enable-preview')
575 }
576 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200577 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100578 options.forkOptions.javaHome = file(jdkDir + 'linux')
579 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200580 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400581 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
582 ? file(jdkDir + 'osx/Contents/Home')
583 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100584 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200585 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100586 options.forkOptions.javaHome = file(jdkDir + 'windows')
587 }
588 sourceCompatibility = compatibility
589 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200590 }
Ian Zernyd3020482019-04-25 07:05:04 +0200591}
592
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100593setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200594 sourceSets.main.compileJavaTaskName,
595 'jdk-11',
596 JavaVersion.VERSION_11,
597 false);
598
599setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100600 sourceSets.examplesJava9.compileJavaTaskName,
601 'openjdk-9.0.4',
602 JavaVersion.VERSION_1_9,
603 false)
604setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100605 sourceSets.examplesJava10.compileJavaTaskName,
606 'jdk-11',
607 JavaVersion.VERSION_1_10,
608 false)
609setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200610 sourceSets.main17.compileJavaTaskName,
611 'jdk-17',
612 JavaVersion.VERSION_17,
613 false)
614setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100615 sourceSets.examplesJava11.compileJavaTaskName,
616 'jdk-11',
617 JavaVersion.VERSION_11,
618 false)
619setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200620 sourceSets.examplesJava17.compileJavaTaskName,
621 'jdk-17',
622 JavaVersion.VERSION_17,
623 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100624setJdkCompilationWithCompatibility(
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +0200625 sourceSets.examplesJava20.compileJavaTaskName,
626 'jdk-20',
Søren Gjessed1e08992022-02-07 16:46:31 +0100627 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
628 JavaVersion.VERSION_17,
629 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100630
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100631if (!project.hasProperty('without_error_prone') &&
632 // Don't enable error prone on Java 8 as the plugin setup does not support it.
633 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200634 compileJava {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100635
636 // Enable error prone for D8/R8 main sources and make all warnings errors.
637 // Warnings that we have chosen not to fix (or suppress) are disabled outright below.
638 options.compilerArgs << "-Werror"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100639 options.errorprone.enabled = true
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100640
641 // Non-default / Experimental checks - explicitly enforced.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100642 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100643 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100644 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
645 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
646 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100647
Ian Zernyf19e5e92023-03-03 12:04:45 +0100648 // TODO(b/270510095): These should likely be fixed/suppressed and become hard failures.
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100649 options.errorprone.check('UnusedVariable', CheckSeverity.OFF)
650 options.errorprone.check('EqualsUnsafeCast', CheckSeverity.OFF)
651 options.errorprone.check('TypeParameterUnusedInFormals', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100652 options.errorprone.check('ImmutableEnumChecker', CheckSeverity.OFF)
653 options.errorprone.check('BadImport', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100654 options.errorprone.check('ComplexBooleanConstant', CheckSeverity.OFF)
655 options.errorprone.check('StreamToIterable', CheckSeverity.OFF)
656 options.errorprone.check('HidingField', CheckSeverity.OFF)
657 options.errorprone.check('StreamResourceLeak', CheckSeverity.OFF)
658 options.errorprone.check('CatchAndPrintStackTrace', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100659 options.errorprone.check('NonCanonicalType', CheckSeverity.OFF)
660 options.errorprone.check('UnusedNestedClass', CheckSeverity.OFF)
661 options.errorprone.check('AmbiguousMethodReference', CheckSeverity.OFF)
662 options.errorprone.check('InvalidParam', CheckSeverity.OFF)
663 options.errorprone.check('CharacterGetNumericValue', CheckSeverity.OFF)
664 options.errorprone.check('ModifyCollectionInEnhancedForLoop', CheckSeverity.OFF)
665 options.errorprone.check('EmptyCatch', CheckSeverity.OFF)
666 options.errorprone.check('ArgumentSelectionDefectChecker', CheckSeverity.OFF)
667 options.errorprone.check('ImmutableAnnotationChecker', CheckSeverity.OFF)
668 options.errorprone.check('ObjectToString', CheckSeverity.OFF)
669 options.errorprone.check('DoNotClaimAnnotations', CheckSeverity.OFF)
670 options.errorprone.check('AnnotateFormatMethod', CheckSeverity.OFF)
671
672 // TODO(b/270537614): Remove finalize uses.
673 options.errorprone.check('Finalize', CheckSeverity.OFF)
674
675 // The following warnings could/should be active but are hit by R8 now so silence them.
676 options.errorprone.check('EqualsGetClass', CheckSeverity.OFF)
677 options.errorprone.check('MixedMutabilityReturnType', CheckSeverity.OFF)
678 options.errorprone.check('UnnecessaryParentheses', CheckSeverity.OFF)
679 options.errorprone.check('DoNotCallSuggester', CheckSeverity.OFF)
680 options.errorprone.check('InlineMeSuggester', CheckSeverity.OFF)
681 options.errorprone.check('MutablePublicArray', CheckSeverity.OFF)
682 options.errorprone.check('DefaultCharset', CheckSeverity.OFF)
683 options.errorprone.check('InconsistentCapitalization', CheckSeverity.OFF)
684 options.errorprone.check('InlineFormatString', CheckSeverity.OFF)
685 options.errorprone.check('MissingImplementsComparable', CheckSeverity.OFF)
686
687 // Warnings that cause unwanted edits (e.g., inability to write informative asserts).
688 options.errorprone.check('AlreadyChecked', CheckSeverity.OFF)
689
690 // JavaDoc related warnings. Would be nice to resolve but of no real consequence.
691 options.errorprone.check('InvalidLink', CheckSeverity.OFF)
692 options.errorprone.check('InvalidBlockTag', CheckSeverity.OFF)
693 options.errorprone.check('InvalidInlineTag', CheckSeverity.OFF)
694 options.errorprone.check('EmptyBlockTag', CheckSeverity.OFF)
695 options.errorprone.check('MissingSummary', CheckSeverity.OFF)
696 options.errorprone.check('UnrecognisedJavadocTag', CheckSeverity.OFF)
697 options.errorprone.check('AlmostJavadoc', CheckSeverity.OFF)
698
699 // Moving away from identity and canonical items is not planned.
700 options.errorprone.check('ReferenceEquality', CheckSeverity.OFF)
701 options.errorprone.check('IdentityHashMapUsage', CheckSeverity.OFF)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200702 }
703}
704
Yohann Roussel7f47c032017-09-14 12:19:06 +0200705task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200706 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100707
Yohann Roussel7f47c032017-09-14 12:19:06 +0200708 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100709 def runtimeClasspath = configurations.findByName("runtimeClasspath")
710 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
711
Yohann Roussel7f47c032017-09-14 12:19:06 +0200712 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100713
Yohann Roussel7f47c032017-09-14 12:19:06 +0200714 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100715 def dependencies = []
716 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
717 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
718 dependencies.add("${identifier.group}:${identifier.module}")
719 }
720 def libraryLicenses = file('LIBRARY-LICENSE').text
721 dependencies.each {
722 if (!libraryLicenses.contains("- artifact: $it")) {
723 throw new GradleException("No license for $it in LIBRARY_LICENSE")
724 }
725 }
726
Yohann Roussel7f47c032017-09-14 12:19:06 +0200727 license.getParentFile().mkdirs()
728 license.createNewFile()
729 license.text = "This file lists all licenses for code distributed.\n"
730 license.text += "All non-library code has the following 3-Clause BSD license.\n"
731 license.text += "\n"
732 license.text += "\n"
733 license.text += file('LICENSE').text
734 license.text += "\n"
735 license.text += "\n"
736 license.text += "Summary of distributed libraries:\n"
737 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100738 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200739 license.text += "\n"
740 license.text += "\n"
741 license.text += "Licenses details:\n"
742 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
743 license.text += "\n"
744 license.text += "\n"
745 license.text += file.text
746 }
747 }
748}
749
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100750def repackageDepFile(file) {
751 if (file.getName().endsWith('.jar')) {
752 return zipTree(file).matching {
753 exclude '**/module-info.class'
754 exclude 'META-INF/maven/**'
755 exclude 'META-INF/LICENSE.txt'
756 exclude 'META-INF/MANIFEST.MF'
757 }
758 } else {
759 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700760 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200761}
762
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100763task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200764 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100765 dependsOn project.configurations.runtimeClasspath
766 project.configurations.runtimeClasspath.forEach {
767 from repackageDepFile(it)
768 }
769 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000770}
771
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100772task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200773 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100774 dependsOn project.configurations.testCompile
775 project.configurations.testCompile.forEach {
776 from repackageDepFile(it)
777 }
778 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200779}
780
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100781task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100782 // If this fails then remove all generated folders from
783 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200784 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100785 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000786}
787
Clément Béraffc2d6a2022-08-02 13:03:04 +0200788task repackageSources17(type: Jar) {
789 from sourceSets.main17.output
790 archiveFileName = 'sources_main_17.jar'
791}
792
Søren Gjesse145d9e82022-05-24 08:12:13 +0200793def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100794 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200795 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100796 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200797 dependsOn files('LICENSE')
798 if (includeLibraryLicenses) {
799 from consolidatedLicense.outputs.files
800 } else {
801 from files('LICENSE')
802 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100803 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100804 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100805 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200806 if (includeSwissArmyKnife) {
807 manifest {
808 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
809 }
810 }
811 exclude "META-INF/*.kotlin_module"
812 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200813 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200814}
815
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200816def r8RelocateTask(r8Task, output) {
817 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
818 dependsOn r8WithDeps
819 dependsOn r8Task
820 outputs.file output
821 workingDir = projectDir
822 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200823 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200824 "relocator",
825 "--input",
826 r8Task.outputs.files[0],
827 "--output",
828 output,
829 "--map",
830 "com.google.common->com.android.tools.r8.com.google.common",
831 "--map",
832 "com.google.gson->com.android.tools.r8.com.google.gson",
833 "--map",
834 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
835 "--map",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200836 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
837 "--map",
838 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
839 "--map",
840 "kotlin->com.android.tools.r8.jetbrains.kotlin",
841 "--map",
842 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
843 "--map",
844 "org.jetbrains->com.android.tools.r8.org.jetbrains",
845 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200846 "org.intellij->com.android.tools.r8.org.intellij",
847 "--map",
848 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200849 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200850 }
851}
852
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200853task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200854 dependsOn repackageSources
855 dependsOn repackageDeps
856 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200857 def r8Task = r8CreateTask(
858 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100859 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200860 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200861 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200862 true)
863 dependsOn r8Task
864 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200865}
866
Clément Béraffc2d6a2022-08-02 13:03:04 +0200867task r8WithDeps17 {
868 dependsOn repackageSources17
869 dependsOn repackageDeps
870 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
871 def r8Task = r8CreateTask(
872 'WithDeps17',
873 'r8_with_deps_17.jar',
874 repackageSources17.outputs.files + repackageDeps.outputs.files,
875 true,
876 true)
877 dependsOn r8Task
878 outputs.files r8Task.outputs.files
879}
880
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200881task r8WithRelocatedDeps {
882 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
883 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200884 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200885 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200886}
887
Clément Béraffc2d6a2022-08-02 13:03:04 +0200888task r8WithRelocatedDeps17 {
889 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
890 dependsOn r8RelocateTask(r8WithDeps17, output)
891 inputs.files r8WithDeps17.outputs.files
892 outputs.file output
893}
894
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200895task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200896 dependsOn repackageSources
897 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200898 def r8Task = r8CreateTask(
899 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100900 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200901 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200902 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200903 true)
904 dependsOn r8Task
905 outputs.files r8Task.outputs.files
906}
907
908task r8(type: Copy) {
909 def r8Task = project.hasProperty("exclude_deps")
910 ? r8WithoutDeps : r8WithRelocatedDeps
911 dependsOn r8Task
912 from r8Task.outputs.files[0]
913 into file("${buildDir}/libs")
914 rename { String fileName -> "r8.jar" }
915 outputs.file "${buildDir}/libs/r8.jar"
916}
917
918task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200919 dependsOn repackageSources
920 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200921 def r8Task = r8CreateTask(
922 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100923 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200924 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200925 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200926 false)
927 dependsOn r8Task
928 outputs.files r8Task.outputs.files
929}
930
931task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200932 dependsOn repackageSources
933 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200934 def r8Task = r8CreateTask(
935 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100936 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200937 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200938 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200939 false)
940 dependsOn r8Task
941 outputs.files r8Task.outputs.files
942}
943
944task r8NoManifestWithRelocatedDeps {
945 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
946 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200947 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200948 outputs.file output
949}
950
951task r8NoManifest(type: Copy) {
952 def r8Task = project.hasProperty("exclude_deps")
953 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
954 dependsOn r8Task
955 from r8Task.outputs.files[0]
956 into file("${buildDir}/libs")
957 rename { String fileName -> "r8_no_manifest.jar" }
958 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100959}
960
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200961def baseCompilerCommandLine(compiler, args = []) {
962 // Execute r8 commands against a stable r8 with dependencies.
963 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
964 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
965 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
966}
967
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100968def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200969 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200970 return baseCompilerCommandLine("r8", args)
971}
972
973def baseD8CommandLine(args = []) {
974 // Execute r8 commands against a stable r8 with dependencies.
975 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100976}
977
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200978def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
979 def allArgs = [
980 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100981 input,
982 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100983 "--pg-map-output", output + ".map",
Morten Krogh-Jesperseneda55812023-04-25 09:26:07 +0200984 "--partition-map-output", output + "_map.zip",
Ian Zerny3ac86842022-10-05 11:49:35 +0200985 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200986 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
987 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100988}
989
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200990def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
991 def allArgs = [
992 "--classfile",
993 input,
994 "--output", output,
995 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
996 ] + args + libs.collectMany { ["--lib", it] }
997 return baseD8CommandLine(allArgs)
998}
999
Ian Zernycf8ef512022-05-04 14:54:16 +02001000def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001001 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001002 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001003 outputs.file output
1004 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001005 dependsOn r8WithRelocatedDeps
1006 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001007 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001008 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001009 "--r8jar", r8Task.outputs.files[0],
1010 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001011 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001012 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001013 + (libs.collectMany { ["--lib", it] })
1014 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001015 workingDir = projectDir
1016 }
1017}
1018
Clément Bérac8b2c152022-06-22 08:23:47 +02001019task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001020 from sourceSets.libraryDesugarConversions.output
1021 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001022 baseName 'library_desugar_conversions_raw'
1023 destinationDir file('build/tmp/desugaredlibrary')
1024}
1025
1026task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001027 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001028 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001029}
1030
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001031task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1032 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001033 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001034 // We only want to include tests that use R8 when generating keep rules for applymapping.
1035 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001036 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001037 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001038}
1039
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001040task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001041 dependsOn r8WithDeps
1042 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001043 def output = "$buildDir/libs/r8tests.jar"
1044 outputs.file output
1045 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001046 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001047 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001048 "relocator",
1049 "--input",
1050 testJarSources.outputs.files[0],
1051 "--output",
1052 output,
1053 "--map",
1054 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1055 ])
1056}
1057
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001058task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001059 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1060 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001061 dependsOn r8WithDeps
1062 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001063 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001064 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001065 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001066 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001067 r8WithDeps.outputs,
1068 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001069 repackageDeps.outputs,
1070 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001071 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001072 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001073 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001074 "tracereferences",
1075 "--keep-rules",
1076 "--allowobfuscation",
1077 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001078 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001079 "--lib",
1080 repackageDeps.outputs.files[0],
1081 "--lib",
1082 repackageTestDeps.outputs.files[0],
1083 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001084 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001085 "--source",
1086 testJar.outputs.files[0],
1087 "--output",
1088 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001089 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001090}
1091
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001092task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001093 dependsOn r8LibCreateTask(
1094 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001095 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001096 r8NoManifestWithRelocatedDeps,
Søren Gjesse63a53a92023-05-03 14:33:02 +02001097 r8LibPath
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001098 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001099 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001100 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001101}
1102
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001103task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001104 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001105 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001106 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001107 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001108 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001109 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001110 repackageDeps.outputs.files,
1111 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001112 ).dependsOn(repackageDeps)
1113 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001114 outputs.file r8LibExludeDepsPath
1115}
1116
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001117task R8Desugared(type: Exec) {
1118 dependsOn downloadOpenJDKrt
1119 dependsOn r8NoManifestWithRelocatedDeps
1120 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1121 commandLine d8CfCommandLine(
1122 r8NoManifestWithRelocatedDeps.outputs.files[0],
1123 r8DesugaredPath,
1124 ["--release"])
1125 workingDir = projectDir
1126 outputs.file r8DesugaredPath
1127}
1128
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001129task R8Retrace {
1130 dependsOn R8Lib
1131 dependsOn r8LibCreateTask(
1132 "Retrace",
1133 ["src/main/keep_retrace.txt"],
1134 R8Lib,
1135 r8RetracePath,
1136 ).dependsOn(R8Lib)
1137 outputs.file r8RetracePath
1138}
1139
1140task R8RetraceNoDeps {
1141 dependsOn R8LibNoDeps
1142 dependsOn r8LibCreateTask(
1143 "RetraceNoDeps",
1144 ["src/main/keep_retrace.txt"],
1145 R8LibNoDeps,
1146 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001147 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001148 repackageDeps.outputs.files,
1149 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001150 ).dependsOn(R8LibNoDeps)
1151 outputs.file r8RetraceExludeDepsPath
1152}
1153
Mads Ager418d1ca2017-05-22 09:35:49 +02001154task sourceJar(type: Jar, dependsOn: classes) {
1155 classifier = 'src'
1156 from sourceSets.main.allSource
1157}
1158
Ian Zernya87869c2023-01-31 08:38:21 +01001159task keepAnnoJar(type: Jar) {
1160 archiveFileName = "keepanno-annotations.jar"
1161 from sourceSets.keepanno.output
1162}
1163
Mads Ager418d1ca2017-05-22 09:35:49 +02001164artifacts {
1165 archives sourceJar
1166}
1167
1168task createArtTests(type: Exec) {
1169 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001170 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001171 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001172 outputs.dir outputDir
1173 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001174 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001175 workingDir = projectDir
1176}
1177
Mads Ager418d1ca2017-05-22 09:35:49 +02001178compileTestJava {
1179 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001180}
1181
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001182task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1183 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001184 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001185 destinationDir file('build/libs')
1186}
1187
Ian Zerny923a0c12018-01-03 10:59:18 +01001188task buildR8ApiUsageSample(type: Jar) {
1189 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001190 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001191 destinationDir file('tests')
1192}
1193
Yohann Roussel548ae942018-01-05 11:13:28 +01001194task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001195 dependsOn buildR8ApiUsageSample
1196}
1197
Mads Ager418d1ca2017-05-22 09:35:49 +02001198task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001199 def resourcesDir = file("src/test/debugTestResources")
1200 def hostJar = "debug_test_resources.jar"
1201 task "compile_debugTestResources"(type: JavaCompile) {
1202 source = fileTree(dir: resourcesDir, include: '**/*.java')
1203 destinationDir = file("build/test/debugTestResources/classes")
1204 classpath = sourceSets.main.compileClasspath
1205 sourceCompatibility = JavaVersion.VERSION_1_7
1206 targetCompatibility = JavaVersion.VERSION_1_7
1207 options.compilerArgs += ["-g", "-Xlint:-options"]
1208 }
1209 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1210 archiveName = hostJar
1211 destinationDir = file("build/test/")
1212 from "build/test/debugTestResources/classes"
1213 include "**/*.class"
1214 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001215 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1216 def java8HostJar = "debug_test_resources_java8.jar"
1217 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1218 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1219 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1220 classpath = sourceSets.main.compileClasspath
1221 sourceCompatibility = JavaVersion.VERSION_1_8
1222 targetCompatibility = JavaVersion.VERSION_1_8
1223 options.compilerArgs += ["-g", "-Xlint:-options"]
1224 }
1225 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1226 archiveName = java8HostJar
1227 destinationDir = file("build/test/")
1228 from "build/test/debugTestResourcesJava8/classes"
1229 include "**/*.class"
1230 }
1231 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001232 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001233 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001234}
1235
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001236// Examples used by tests, where Android specific APIs are used.
1237task buildExampleAndroidApi(type: JavaCompile) {
1238 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1239 destinationDir = file("build/test/examplesAndroidApi/classes")
1240 classpath = files("third_party/android_jar/lib-v26/android.jar")
1241 sourceCompatibility = JavaVersion.VERSION_1_8
1242 targetCompatibility = JavaVersion.VERSION_1_8
1243}
1244
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001245task buildProtoGeneratedSources {
1246 def examplesProtoDir = file("src/test/examplesProto")
1247 examplesProtoDir.eachDir { dir ->
1248 def name = dir.getName()
1249 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1250 source = {
1251 file('third_party/proto').listFiles()
1252 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1253 .collect { zipTree(it) }
1254 }
1255 destinationDir = file("build/generated/test/proto/${name}_classes")
1256 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1257 sourceCompatibility = JavaVersion.VERSION_1_8
1258 targetCompatibility = JavaVersion.VERSION_1_8
1259 }
1260 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1261 archiveName = "${name}.jar"
1262 destinationDir = file("build/generated/test/proto")
1263 from "build/generated/test/proto/${name}_classes"
1264 include "/**/*.class"
1265 }
1266 dependsOn "jar_proto_generated_source_${name}"
1267 }
1268}
1269
1270task buildExamplesProto {
1271 def examplesProtoDir = file("src/test/examplesProto")
1272 def examplesProtoOutputDir = file("build/test/examplesProto");
1273 dependsOn buildProtoGeneratedSources
1274 task "compile_examples_proto"(type: JavaCompile) {
1275 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1276 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001277 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1278 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001279 sourceCompatibility = JavaVersion.VERSION_1_8
1280 targetCompatibility = JavaVersion.VERSION_1_8
1281 }
1282 examplesProtoDir.eachDir { dir ->
1283 def name = dir.getName()
1284 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1285 archiveName = "${name}.jar"
1286 destinationDir = examplesProtoOutputDir
1287 from "build/test/examplesProto/classes"
1288 include name + "/**/*.class"
1289 }
1290 dependsOn "jar_examples_proto_${name}"
1291 }
1292}
1293
Lars Bakc91e87e2017-08-18 08:53:10 +02001294// Proto lite generated code yields warnings when compiling with javac.
1295// We change the options passed to javac to ignore it.
1296compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1297
Søren Gjesse7320ce52018-05-07 15:45:22 +02001298
Mads Ager418d1ca2017-05-22 09:35:49 +02001299task buildExampleJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001300 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001301 task extractExamplesRuntime(type: Sync) {
1302 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001303 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001304 include "**/*.class"
1305 includeEmptyDirs false
1306 into "$buildDir/runtime/examples/"
1307 }
1308
Søren Gjesse7320ce52018-05-07 15:45:22 +02001309 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1310 from examplesDir
1311 exclude "**/*.java"
1312 exclude "**/keep-rules*.txt"
1313 into file("build/test/examples/classes")
1314 }
1315
1316 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001317 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001318 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001319 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001320 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001321 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001322 sourceCompatibility = JavaVersion.VERSION_1_7
1323 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001324 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1325 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001326 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1327 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001328 include "**/*.java"
1329 destinationDir = file("build/test/examples/classes_debuginfo_all")
1330 classpath = sourceSets.examples.compileClasspath
1331 sourceCompatibility = JavaVersion.VERSION_1_7
1332 targetCompatibility = JavaVersion.VERSION_1_7
1333 options.compilerArgs = ["-g", "-Xlint:none"]
1334 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001335 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1336 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001337 include "**/*.java"
1338 destinationDir = file("build/test/examples/classes_debuginfo_none")
1339 classpath = sourceSets.examples.compileClasspath
1340 sourceCompatibility = JavaVersion.VERSION_1_7
1341 targetCompatibility = JavaVersion.VERSION_1_7
1342 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001343 }
1344 examplesDir.eachDir { dir ->
1345 def name = dir.getName();
1346 def exampleOutputDir = file("build/test/examples");
1347 def jarName = "${name}.jar"
1348 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001349 dependsOn "jar_example_${name}_debuginfo_all"
1350 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001351 dependsOn "extractExamplesRuntime"
1352 def runtimeDependencies = copySpec { }
Ian Zernyaea82c82023-05-11 08:55:40 +02001353 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1354 archiveName = "${name}.jar"
1355 destinationDir = exampleOutputDir
1356 from "build/test/examples/classes"
1357 include name + "/**/*"
1358 with runtimeDependencies
1359 includeEmptyDirs true
1360 }
1361 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1362 archiveName = "${name}_debuginfo_all.jar"
1363 destinationDir = exampleOutputDir
1364 from "build/test/examples/classes_debuginfo_all"
1365 include name + "/**/*.class"
1366 with runtimeDependencies
1367 includeEmptyDirs false
1368 }
1369 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1370 archiveName = "${name}_debuginfo_none.jar"
1371 destinationDir = exampleOutputDir
1372 from "build/test/examples/classes_debuginfo_none"
1373 include name + "/**/*.class"
1374 with runtimeDependencies
1375 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001376 }
1377 }
1378}
1379
1380task buildExampleAndroidNJars {
1381 dependsOn downloadDeps
1382 def examplesDir = file("src/test/examplesAndroidN")
1383 task "compile_examplesAndroidN"(type: JavaCompile) {
1384 source = fileTree(dir: examplesDir, include: '**/*.java')
1385 destinationDir = file("build/test/examplesAndroidN/classes")
1386 classpath = sourceSets.main.compileClasspath
1387 sourceCompatibility = JavaVersion.VERSION_1_8
1388 targetCompatibility = JavaVersion.VERSION_1_8
1389 options.compilerArgs += ["-Xlint:-options"]
1390 }
1391 examplesDir.eachDir { dir ->
1392 def name = dir.getName();
1393 def exampleOutputDir = file("build/test/examplesAndroidN");
1394 def jarName = "${name}.jar"
1395 dependsOn "jar_examplesAndroidN_${name}"
1396 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1397 archiveName = jarName
1398 destinationDir = exampleOutputDir
1399 from "build/test/examplesAndroidN/classes"
1400 include "**/" + name + "/**/*.class"
1401 }
1402 }
1403}
1404
1405
1406task buildExampleAndroidOJars {
1407 dependsOn downloadDeps
1408 def examplesDir = file("src/test/examplesAndroidO")
1409 // NOTE: we want to enable a scenario when test needs to reference some
1410 // classes generated by legacy (1.6) Java compiler to test some specific
1411 // behaviour. To do so we compile all the java files located in sub-directory
1412 // called 'legacy' with Java 1.6, then compile the rest of the files with
1413 // Java 1.8 and a reference to previously generated 1.6 classes.
1414
1415 // Compiling all classes in dirs 'legacy' with old Java version.
1416 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1417 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1418 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1419 classpath = sourceSets.main.compileClasspath
1420 sourceCompatibility = JavaVersion.VERSION_1_6
1421 targetCompatibility = JavaVersion.VERSION_1_6
1422 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1423 }
1424 // Compiling the rest of the files as Java 1.8 code.
1425 task "compile_examplesAndroidO"(type: JavaCompile) {
1426 dependsOn "compile_examplesAndroidO_Legacy"
1427 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1428 destinationDir = file("build/test/examplesAndroidO/classes")
1429 classpath = sourceSets.main.compileClasspath
1430 classpath += files("build/test/examplesAndroidOLegacy/classes")
1431 sourceCompatibility = JavaVersion.VERSION_1_8
1432 targetCompatibility = JavaVersion.VERSION_1_8
1433 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1434 }
1435 examplesDir.eachDir { dir ->
1436 def name = dir.getName();
1437 def destinationDir = file("build/test/examplesAndroidO/classes");
1438 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1439 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1440 dependsOn: "compile_examplesAndroidO") {
1441 main = name + ".TestGenerator"
1442 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1443 args destinationDir
1444 }
1445 } else {
1446 task "generate_examplesAndroidO_${name}" () {}
1447 }
1448 }
1449 examplesDir.eachDir { dir ->
1450 def name = dir.getName();
1451 def exampleOutputDir = file("build/test/examplesAndroidO");
1452 def jarName = "${name}.jar"
1453 dependsOn "jar_examplesAndroidO_${name}"
1454 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1455 "generate_examplesAndroidO_${name}"]) {
1456 archiveName = jarName
1457 destinationDir = exampleOutputDir
1458 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1459 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1460 include "**/" + name + "/**/*.class"
1461 // Do not include generator into the test runtime jar, it is not useful.
1462 // Otherwise, shrinking will need ASM jars.
1463 exclude "**/TestGenerator*"
1464 }
1465 }
1466}
1467
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001468task buildExampleAndroidPJars {
1469 dependsOn downloadDeps
1470 def examplesDir = file("src/test/examplesAndroidP")
1471
1472 task "compile_examplesAndroidP"(type: JavaCompile) {
1473 source = fileTree(dir: examplesDir, include: '**/*.java')
1474 destinationDir = file("build/test/examplesAndroidP/classes")
1475 classpath = sourceSets.main.compileClasspath
1476 sourceCompatibility = JavaVersion.VERSION_1_8
1477 targetCompatibility = JavaVersion.VERSION_1_8
1478 options.compilerArgs += ["-Xlint:-options"]
1479 }
1480 examplesDir.eachDir { dir ->
1481 def name = dir.getName();
1482 def destinationDir = file("build/test/examplesAndroidP/classes");
1483 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1484 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1485 dependsOn: "compile_examplesAndroidP") {
1486 main = name + ".TestGenerator"
1487 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1488 args destinationDir
1489 }
1490 } else {
1491 task "generate_examplesAndroidP_${name}" () {}
1492 }
1493 }
1494 examplesDir.eachDir { dir ->
1495 def name = dir.getName();
1496 def exampleOutputDir = file("build/test/examplesAndroidP");
1497 def jarName = "${name}.jar"
1498 dependsOn "jar_examplesAndroidP_${name}"
1499 task "jar_examplesAndroidP_${name}"(type: Jar,
1500 dependsOn: ["compile_examplesAndroidP",
1501 "generate_examplesAndroidP_${name}"]) {
1502 archiveName = jarName
1503 destinationDir = exampleOutputDir
1504 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1505 include "**/" + name + "/**/*.class"
1506 // Do not include generator into the test runtime jar, it is not useful.
1507 // Otherwise, shrinking will need ASM jars.
1508 exclude "**/TestGenerator*"
1509 }
1510 }
1511}
1512
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001513def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1514 return tasks.create("buildExample${javaVersion}Jars") {
1515 def examplesDir = file("src/test/examples${javaVersion}")
1516 examplesDir.eachDir { dir ->
1517 def name = dir.getName();
1518 def exampleOutputDir = file("build/test/examples${javaVersion}");
1519 def jarName = "${name}.jar"
1520 dependsOn "jar_examples${javaVersion}_${name}"
1521 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1522 archiveName = jarName
1523 destinationDir = exampleOutputDir
1524 from sourceSet.output
1525 include "**/" + name + "/**/*.class"
1526 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001527 }
1528 }
1529}
1530
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001531buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1532buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1533buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001534buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +02001535buildExampleJarsCreateTask("Java20", sourceSets.examplesJava20)
clementberad7ab1dd2019-04-16 16:05:00 +02001536
clementberaa92e3cd2019-07-12 14:13:22 +02001537task provideArtFrameworksDependencies {
1538 cloudDependencies.tools.forEach({ art ->
1539 if (art.contains("art")) {
1540 def taskName = art.replace('/','_')
1541 dependsOn "patch_${taskName}"
1542 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1543 from "tools/${art}/framework"
1544 include "**.jar"
1545 into file("tools/${art}/out/host/linux-x86/framework")
1546 }
1547 }
1548 })
1549}
1550
Sebastien Hertzd3313772018-01-16 14:12:37 +01001551task buildKotlinR8TestResources {
1552 def examplesDir = file("src/test/kotlinR8TestResources")
1553 examplesDir.eachDir { dir ->
Morten Krogh-Jespersen5c79e4e2023-06-27 16:34:04 +02001554 def name = dir.getName()
1555 def taskName = "jar_kotlinR8TestResources_${name}"
1556 def javaOutput = "build/test/kotlinR8TestResources/${name}/java"
1557 def javaOutputJarName = "${name}.jar"
1558 def javaOutputJarDir = "build/test/kotlinR8TestResources"
1559 task "${taskName}Java"(type: JavaCompile) {
1560 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1561 destinationDir = file(javaOutput)
1562 classpath = sourceSets.main.compileClasspath
1563 sourceCompatibility = JavaVersion.VERSION_1_8
1564 targetCompatibility = JavaVersion.VERSION_1_8
1565 options.compilerArgs += ["-g", "-Xlint:-options"]
Sebastien Hertzd3313772018-01-16 14:12:37 +01001566 }
Morten Krogh-Jespersen5c79e4e2023-06-27 16:34:04 +02001567 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1568 archiveName = javaOutputJarName
1569 destinationDir = file(javaOutputJarDir)
1570 from javaOutput
1571 include "**/*.class"
1572 }
1573 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001574 }
1575}
1576
Mads Ager418d1ca2017-05-22 09:35:49 +02001577task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001578 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1579 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1580 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001581 } else if (!OperatingSystem.current().isLinux()) {
1582 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001583 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001584 return;
1585 }
1586 dependsOn buildDebugTestResourcesJars
1587 dependsOn buildExampleJars
1588 dependsOn buildExampleAndroidNJars
1589 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001590 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001591 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001592 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001593 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001594 dependsOn buildExampleJava17Jars
Søren Gjesse4b6b5fc2023-05-12 09:53:47 +02001595 dependsOn buildExampleJava20Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001596 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001597 def examplesDir = file("src/test/examples")
1598 examplesDir.eachDir { dir ->
Rico Wind9f8ccd22023-03-03 11:04:58 +01001599 def exampleOutputDir = file("build/test/examples/" + dir.getName());
1600 if (!exampleOutputDir.exists()) {
1601 exampleOutputDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02001602 }
1603 }
1604}
1605
Mads Ager418d1ca2017-05-22 09:35:49 +02001606tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001607 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001608 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001609 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001610 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001611 if (userDefinedCoresPerFork) {
1612 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1613 } else {
1614 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001615 maxParallelForks = processors.intdiv(3) ?: 1
1616 // On low cpu count machines (bots) we under subscribe, so increase the count.
1617 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001618 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001619 }
Rico Wind73da9f12019-09-19 09:27:07 +02001620 }
Rico Windc56f21c2019-03-12 07:29:57 +01001621 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001622
Mads Ager418d1ca2017-05-22 09:35:49 +02001623 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001624 if (project.hasProperty('disable_assertions')) {
1625 enableAssertions = false
1626 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001627 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001628 if (project.hasProperty('test_xmx')) {
1629 maxHeapSize = project.property('test_xmx')
1630 } else {
1631 maxHeapSize = "4G"
1632 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001633}
1634
1635task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001636 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001637 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1638 // Exclude the classes containing java8
1639 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1640 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1641 includeEmptyDirs = false
1642}
1643
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001644task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1645 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001646}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001647
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001648task generateR8TestKeepRules {
1649 def path = "build/generated/r8tests-keep.txt"
1650 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001651 dependsOn R8Lib
1652 doLast {
1653 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001654-dontshrink
1655-dontoptimize
1656-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001657-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001658"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001659 }
1660}
1661
1662task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001663 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1664 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001665 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001666 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001667 dependsOn generateR8TestKeepRules
1668 dependsOn testJar
1669 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1670 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1671 return pkg.toString().endsWith(".jar")
1672 } + ["${buildDir}/classes/java/test"]
1673 inputs.files testJar.outputs.files +
1674 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001675 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001676 commandLine = r8CfCommandLine(
1677 testJar.outputs.files[0],
1678 outputPath,
1679 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001680 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1681 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001682 workingDir = projectDir
1683 outputs.file outputPath
1684}
1685
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001686task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001687 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001688 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001689 dependsOn R8Lib
1690 delete r8LibTestPath
1691 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1692 def examplesDir = file("build/test")
1693 examplesDir.eachDir { dir ->
1694 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001695 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001696 from ("${buildDir}/runtime/examples")
1697 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001698 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001699}
1700
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001701def shouldRetrace() {
1702 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1703}
1704
1705def retrace(Throwable exception) {
1706 def out = new StringBuffer()
1707 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001708 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001709 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001710 out.append("\n--------------------------------------\n")
1711 out.append("${header}\n")
1712 out.append("--------------------------------------\n")
1713 Process process = command.execute()
1714 def processIn = new PrintStream(process.getOut())
1715 process.consumeProcessOutput(out, err)
1716 exception.printStackTrace(processIn)
1717 processIn.flush()
1718 processIn.close()
1719 def errorDuringRetracing = process.waitFor() != 0
1720 if (errorDuringRetracing) {
1721 out.append("ERROR DURING RETRACING\n")
1722 out.append(err.toString())
1723 }
1724 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1725 out.append("\n\n--------------------------------------\n")
1726 out.append("OBFUSCATED STACKTRACE\n")
1727 out.append("--------------------------------------\n")
1728 }
1729 return out.toString()
1730}
1731
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001732def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001733 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001734 if (shouldRetrace()) {
1735 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001736 exception.setStackTrace([] as StackTraceElement[])
1737 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001738 }
1739}
1740
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001741def filterStackTraces(TestResult result) {
1742 for (Throwable throwable : result.getExceptions()) {
1743 filterStackTrace(throwable)
1744 }
1745}
1746
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001747// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001748def filterStackTrace(Throwable exception) {
1749 if (!project.hasProperty('print_full_stacktraces')) {
1750 def elements = []
1751 def skipped = []
1752 for (StackTraceElement element : exception.getStackTrace()) {
1753 if (element.toString().contains("com.android.tools.r8")) {
1754 elements.addAll(skipped)
1755 elements.add(element)
1756 skipped.clear()
1757 } else {
1758 skipped.add(element)
1759 }
1760 }
1761 exception.setStackTrace(elements as StackTraceElement[])
1762 }
1763}
1764
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001765def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1766 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1767 exceptions.forEach { it.printStackTrace(printer) }
1768 }
1769}
1770
Ian Zerny89f16cf2021-04-29 21:10:09 +02001771static def escapeHtml(String string) {
1772 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1773}
1774
1775static def urlEncode(String string) {
1776 // Not sure why, but the + also needs to be converted to have working links.
1777 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1778}
1779
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001780def ensureDir(File dir) {
1781 dir.mkdirs()
1782 return dir
1783}
1784
Ian Zerny89f16cf2021-04-29 21:10:09 +02001785// Some of our test parameters have new lines :-( We really don't want test names to span lines.
1786static def sanitizedTestName(testDesc) {
1787 if (testDesc.getName().contains("\n")) {
1788 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
1789 }
1790 return testDesc.getName()
1791}
1792
1793static def desanitizedTestName(testName) {
1794 return testName
1795}
1796
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001797def getTestReportEntryDir(reportDir, testDesc) {
1798 return ensureDir(reportDir.toPath()
1799 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02001800 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001801 .toFile())
1802}
1803
Ian Zerny89f16cf2021-04-29 21:10:09 +02001804def getTestReportEntryURL(reportDir, testDesc) {
1805 def classDir = urlEncode(testDesc.getClassName())
1806 def testDir = urlEncode(sanitizedTestName(testDesc))
1807 return "file://${reportDir}/${classDir}/${testDir}"
1808}
1809
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001810def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
1811 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
1812 return dir.resolve(fileName).toFile()
1813}
1814
Ian Zerny89f16cf2021-04-29 21:10:09 +02001815def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
1816 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
1817 new FileWriter(file, append).withCloseable fn
1818}
1819
Ian Zerny27ea4c72021-04-29 22:35:49 +02001820static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001821 def out = new StringBuilder()
1822 def err = new StringBuilder()
1823 def proc = "git rev-parse --abbrev-ref HEAD".execute()
1824 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02001825 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001826}
1827
Ian Zerny27ea4c72021-04-29 22:35:49 +02001828static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02001829 def number = 0
1830 while (true) {
1831 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
1832 if (!freshIndex.exists()) {
1833 return freshIndex
1834 }
1835 }
1836}
1837
1838def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
1839 def out = new StringBuilder()
1840 def err = new StringBuilder()
1841 def proc = "find . -name ${fileName}".execute([], reportDir)
1842 proc.waitForProcessOutput(out, err)
1843 def outString = out.toString()
1844 outString.eachLine {
1845 // Lines are of the form: ./<class>/<name>/FAILURE
1846 def clazz = null
1847 def name = null
1848 try {
1849 def trimmed = it.trim()
1850 def line = trimmed.substring(2)
1851 def sep = line.indexOf("/")
1852 clazz = line.substring(0, sep)
1853 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
1854 } catch (Exception e) {
1855 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
1856 return
1857 }
1858 onTest(clazz, desanitizedTestName(name))
1859 }
1860 return !outString.trim().isEmpty()
1861}
1862
1863def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
1864 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
1865}
1866
1867def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
1868 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
1869}
1870
1871def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
1872 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
1873}
1874
Ian Zerny27ea4c72021-04-29 22:35:49 +02001875def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001876 // Hide all test events from the console, they are written to the report.
1877 task.testLogging { events = [] }
1878
Ian Zernycae764d2021-08-16 08:25:15 +02001879 def branch = project.hasProperty('testing-state-name')
1880 ? project.getProperty('testing-state-name')
1881 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02001882 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02001883 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02001884 def resetState = project.hasProperty('reset-testing-state')
1885 def reportDirExists = reportDir.exists()
1886 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02001887
1888 def hasFailingTests = false;
1889 if (resuming) {
1890 // Test filtering happens before the test execution is initiated so compute it here.
1891 // If there are still failing tests in the report, include only those.
1892 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
1893 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
1894 })
1895 // Otherwise exclude all of the test already marked as succeeding.
1896 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02001897 // Also allow the test to overall succeed if there are no remaining tests that match,
1898 // which is natural if the state already succeeded in full.
1899 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02001900 forEachTestReportAlreadyPassing(reportDir, {
1901 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
1902 })
1903 forEachTestReportAlreadySkipped(reportDir, {
1904 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
1905 })
1906 }
1907 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001908
1909 task.beforeSuite { desc ->
1910 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02001911 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02001912 if (resetState && reportDirExists) {
1913 delete reportDir
1914 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02001915 if (resuming) {
1916 if (index.exists()) {
1917 parentReport = getFreshTestReportIndex(reportDir)
1918 index.renameTo(parentReport)
1919 }
1920 } else {
1921 reportDir.mkdirs()
1922 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02001923 def runPrefix = resuming ? "Resuming" : "Starting"
1924 def title = "${runPrefix} @ ${branch}"
1925 // Print a console link to the test report for easy access.
1926 println "${runPrefix} test, report written to:"
1927 println " file://${index}"
1928 // Print the new index content.
1929 index << "<html><head><title>${title}</title>"
1930 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02001931 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02001932 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001933 index << "<p>Run on: ${new Date()}</p>"
1934 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02001935 if (parentReport != null) {
1936 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
1937 }
1938 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
1939 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02001940 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001941 }
1942 }
1943
1944 task.afterSuite { desc, result ->
1945 if (!desc.parent) {
1946 // Update the final test results in the index.
1947 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02001948 if (result.resultType == TestResult.ResultType.SUCCESS) {
1949 if (hasFailingTests) {
1950 index << "<h2>Rerun of failed tests now pass!</h2>"
1951 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
1952 } else {
1953 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
1954 }
1955 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02001956 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02001957 } else {
1958 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
1959 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001960 index << "<li>Number of tests: ${result.testCount}"
1961 index << "<li>Failing tests: ${result.failedTestCount}"
1962 index << "<li>Successful tests: ${result.successfulTestCount}"
1963 index << "<li>Skipped tests: ${result.skippedTestCount}"
1964 index << "</ul></body></html>"
1965 }
1966 }
1967
1968 // Events to stdout/err are appended to the files in the test directories.
1969 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02001970 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
1971 it.append(event.getMessage())
1972 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001973 }
1974
Ian Zerny27ea4c72021-04-29 22:35:49 +02001975 task.beforeTest { desc ->
1976 // Remove any stale output files before running the test.
1977 for (def destType : TestOutputEvent.Destination.values()) {
1978 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
1979 if (destFile.exists()) {
1980 delete destFile
1981 }
1982 }
1983 }
1984
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001985 task.afterTest { desc, result ->
1986 if (result.getTestCount() != 1) {
1987 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
1988 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02001989 // Clear any previous result files.
1990 for (def resultType : TestResult.ResultType.values()) {
1991 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
1992 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001993 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02001994 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
1995 it.append(result.getResultType().name())
1996 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001997 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02001998 withTestResultEntryWriter(reportDir, desc, "time", false, {
1999 it.append("${result.getEndTime() - result.getStartTime()}")
2000 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002001 // For failed tests, update the index and emit stack trace information.
2002 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002003 def title = escapeHtml("${desc.className}.${desc.name}")
2004 def link = getTestReportEntryURL(reportDir, desc)
2005 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002006 if (!result.exceptions.isEmpty()) {
2007 printAllStackTracesToFile(
2008 result.exceptions,
2009 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002010 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002011 desc,
2012 "exceptions-raw.txt"))
2013 filterStackTraces(result)
2014 printAllStackTracesToFile(
2015 result.exceptions,
2016 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002017 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002018 desc,
2019 "exceptions-filtered.txt"))
2020 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002021 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2022 result.exceptions.forEach { writer.append(retrace(it)) }
2023 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002024 }
2025 }
2026 }
2027 }
2028}
2029
Rico Windf2f4c292021-04-23 07:06:13 +02002030def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002031def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002032
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002033test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002034
Ian Zernyc1582852023-01-30 13:45:36 +01002035 dependsOn sourceSets.keepanno.output
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002036 dependsOn buildLibraryDesugarConversions
2037 dependsOn getJarsFromSupportLibs
2038 // R8.jar is required for running bootstrap tests.
2039 dependsOn r8
2040
Ian Zerny27ea4c72021-04-29 22:35:49 +02002041 def useTestingState = project.hasProperty('testing-state')
2042 if (useTestingState) {
2043 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002044 }
2045
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002046 if (project.hasProperty('generate_golden_files_to')) {
2047 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2048 assert project.hasProperty('HEAD_sha1')
2049 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2050 }
2051
2052 if (project.hasProperty('use_golden_files_in')) {
2053 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2054 assert project.hasProperty('HEAD_sha1')
2055 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2056 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002057
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002058 if (project.hasProperty('kotlin_compiler_dev')) {
2059 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2060 }
2061
2062 if (project.hasProperty('kotlin_compiler_old')) {
2063 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2064 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002065
Ian Zerny27ea4c72021-04-29 22:35:49 +02002066 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002067 testLogging.exceptionFormat = 'full'
2068 if (project.hasProperty('print_test_stdout')) {
2069 testLogging.showStandardStreams = true
2070 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002071 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002072 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002073 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002074 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002075 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002076
Ian Zerny324d7612019-03-20 10:52:28 +01002077 // Forward runtime configurations for test parameters.
2078 if (project.hasProperty('runtimes')) {
2079 println "NOTE: Running with runtimes: " + project.property('runtimes')
2080 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002081 }
2082
Christoffer Quist Adamsen3b3a4b02023-02-06 13:43:30 +01002083 if (project.hasProperty('art_profile_rewriting_completeness_check')) {
2084 String key = 'com.android.tools.r8.artprofilerewritingcompletenesscheck'
2085 String value = project.property('art_profile_rewriting_completeness_check')
2086 systemProperty key, value
2087 }
2088
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002089 if (project.hasProperty('slow_tests')) {
2090 systemProperty 'slow_tests', project.property('slow_tests')
2091 }
2092
Søren Gjesseef195772021-03-11 16:04:42 +01002093
2094 if (project.hasProperty('desugar_jdk_json_dir')) {
2095 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2096 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002097 if (project.hasProperty('desugar_jdk_libs')) {
2098 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2099 }
2100
Ian Zerny27ea4c72021-04-29 22:35:49 +02002101 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002102 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2103 afterTest { desc, result ->
2104 def executionTime = (result.endTime - result.startTime) / 1000
2105 testTimes["${desc.name} [${desc.className}]"] = executionTime
2106 }
2107 afterSuite { desc, result ->
2108 // parent is null if all tests are done.
2109 if (desc.parent == null) {
2110 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2111 sortedTimes.eachWithIndex { key, value, i ->
Rico Windf94f4302023-01-03 10:57:10 +01002112 println "$key: $value"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002113 }
2114 }
2115 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002116 }
Rico Windf2f4c292021-04-23 07:06:13 +02002117
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002118 if (project.hasProperty('one_line_per_test')) {
2119 beforeTest { desc ->
2120 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002121 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002122
2123 afterTest { desc, result ->
2124 if (result.resultType == TestResult.ResultType.FAILURE) {
2125 printStackTrace(result)
2126 }
2127 if (project.hasProperty('update_test_timestamp')) {
2128 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2129 }
2130 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002131 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002132 } else {
2133 afterTest { desc, result ->
2134 if (result.resultType == TestResult.ResultType.FAILURE) {
2135 printStackTrace(result)
2136 }
Rico Windf88b6be2018-12-11 15:14:05 +01002137 }
2138 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002139 }
2140 if (project.hasProperty('no_internal')) {
2141 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002142 } else {
2143 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002144 }
2145 if (project.hasProperty('only_internal')) {
2146 include "com/android/tools/r8/internal/**"
2147 }
Rico Wind4e218292019-03-07 12:44:49 +01002148
Rico Windba151112020-10-01 08:16:33 +02002149 if (project.hasProperty('test_namespace')) {
2150 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2151 }
2152
Ian Zerny3ced9262022-03-29 11:06:02 +02002153 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2154 // Don't run anything, deprecated
2155 println "Running with deprecated tool d8, not running any tests"
2156 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002157 }
Rico Windbc820812022-05-31 09:19:56 +02002158 if (project.hasProperty('no_arttests')) {
2159 exclude "com/android/tools/r8/art/**"
2160 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002161 if (project.hasProperty('shard_count') ) {
2162 assert project.hasProperty('shard_number')
2163 int shard_count = project.getProperty('shard_count') as Integer
2164 int shard_number = project.getProperty('shard_number') as Integer
2165 assert shard_count < 65536
2166 assert shard_number < shard_count
2167 exclude {
2168 entry ->
2169 // Don't leave out directories. Leaving out a directory means all entries below.
2170 if (entry.file.isDirectory()) {
2171 return false
2172 }
2173 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2174 int hash = Integer.parseInt(first4, 16)
2175 return hash % shard_count != shard_number
2176 }
2177 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002178 if (project.hasProperty('test_dir')) {
2179 systemProperty 'test_dir', project.property('test_dir')
2180 }
Rico Windfc645a22023-06-14 12:37:18 +02002181 if (project.hasProperty('command_cache_dir')) {
2182 systemProperty 'command_cache_dir', project.property('command_cache_dir')
Rico Wind841eee32023-06-12 10:47:03 +02002183 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002184 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002185 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002186 // R8lib should be used instead of the main output and all the tests in
2187 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002188 classpath = sourceSets.test.runtimeClasspath.filter {
2189 !it.getAbsolutePath().contains("/build/")
2190 }
2191 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002192 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002193 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002194 if (OperatingSystem.current().isLinux()
2195 || OperatingSystem.current().isMacOsX()
2196 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002197 if (OperatingSystem.current().isMacOsX()) {
2198 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2199 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2200 "See tools/docker/README.md for details.")
2201 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002202 if (OperatingSystem.current().isWindows()) {
2203 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2204 "Art only runs on Linux and tests requiring Art will be skipped")
2205 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002206 dependsOn downloadDeps
2207 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002208 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002209 dependsOn buildPreNJdwpTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02002210 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002211 } else {
2212 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002213 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002214 }
2215}
2216
Mads Ager418d1ca2017-05-22 09:35:49 +02002217
2218task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002219 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002220 classpath = sourceSets.main.compileClasspath
2221 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002222 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002223 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002224 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002225 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002226 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002227 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002228 include '**/com/android/tools/r8/CompilationMode.java'
2229 include '**/com/android/tools/r8/D8.java'
2230 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002231 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2232 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002233 include '**/com/android/tools/r8/Diagnostic.java'
2234 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002235 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2236 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002237 include '**/com/android/tools/r8/ProgramConsumer.java'
2238 include '**/com/android/tools/r8/ProgramResource.java'
2239 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002240 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002241 include '**/com/android/tools/r8/ResourceException.java'
2242 include '**/com/android/tools/r8/StringConsumer.java'
2243 include '**/com/android/tools/r8/StringResource.java'
2244 include '**/com/android/tools/r8/Version.java'
2245 include '**/com/android/tools/r8/origin/*.java'
2246}
2247
2248task javadocR8(type: Javadoc) {
2249 title "R8 API"
2250 classpath = sourceSets.main.compileClasspath
2251 source = sourceSets.main.allJava
2252 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2253 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2254 include '**/com/android/tools/r8/BaseCommand.java'
2255 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2256 include '**/com/android/tools/r8/ClassFileConsumer.java'
2257 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2258 include '**/com/android/tools/r8/CompilationFailedException.java'
2259 include '**/com/android/tools/r8/CompilationMode.java'
2260 include '**/com/android/tools/r8/R8.java'
2261 include '**/com/android/tools/r8/R8Command.java'
2262 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2263 include '**/com/android/tools/r8/Diagnostic.java'
2264 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002265 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2266 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002267 include '**/com/android/tools/r8/ProgramConsumer.java'
2268 include '**/com/android/tools/r8/ProgramResource.java'
2269 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2270 include '**/com/android/tools/r8/Resource.java'
2271 include '**/com/android/tools/r8/ResourceException.java'
2272 include '**/com/android/tools/r8/StringConsumer.java'
2273 include '**/com/android/tools/r8/StringResource.java'
2274 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002275 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002276}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002277
2278task copyMavenDeps(type: Copy) {
2279 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002280 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002281 from configurations.testCompile into "$buildDir/deps"
2282}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002283
Rico Wind23a05112019-03-27 08:00:44 +01002284task printMavenDeps {
2285 // Only actually print to stdout when we are updating.
2286 if (project.hasProperty('updatemavendeps')) {
2287 for (Configuration config : configurations) {
2288 if (!config.isCanBeResolved()) {
2289 continue
2290 }
2291 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2292 it.selected.id
2293 }
2294 def result = dependencies.createArtifactResolutionQuery()
2295 .forComponents(componentIds)
2296 .withArtifacts(MavenModule, MavenPomArtifact)
2297 .execute()
2298 for (component in result.resolvedComponents) {
2299 component.getArtifacts(MavenPomArtifact).each {
2300 println "POM: ${it.file} ${component.id}"
2301 }
2302 }
2303 config.each {
2304 println "JAR: ${it}"
2305 }
2306 }
2307 }
2308}
Ian Zerny9713c032020-01-23 11:41:58 +01002309
2310allprojects {
2311 tasks.withType(Exec) {
2312 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002313 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002314 }
2315 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002316}