blob: a9990d7fb8a3b0311d577e94718ce39a81b8e1e1 [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
Jake Wharton2d7aab82019-09-13 10:24:26 -04008import dx.DexMergerTask
9import dx.DxTask
Ian Zerny5fffb0a2019-02-11 13:54:22 +010010import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +020011import org.gradle.internal.os.OperatingSystem
Ian Zernyb2d27c42019-02-20 09:09:41 +010012import tasks.DownloadDependency
Clément Béra8dde69d2022-10-26 15:40:31 +020013import smali.SmaliTask
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000014import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020015import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020016
Ian Zerny5fffb0a2019-02-11 13:54:22 +010017buildscript {
18 repositories {
19 mavenCentral()
Jake Wharton5e5b5232019-09-17 16:13:32 -040020 gradlePluginPortal()
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010021 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010022 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010023}
24
25plugins {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010026 id "net.ltgt.errorprone" version "2.0.2"
Ian Zerny5fffb0a2019-02-11 13:54:22 +010027}
28
29apply plugin: 'java'
30apply plugin: 'idea'
31
Sebastien Hertz143ed112018-02-13 14:26:41 +010032ext {
33 androidSupportVersion = '25.4.0'
Søren Gjesse2792ced2022-12-15 16:06:08 +010034 asmVersion = '9.4' // When updating update tools/asmifier.py, build.src and Toolhelper as well.
Sebastien Hertz143ed112018-02-13 14:26:41 +010035 espressoVersion = '3.0.0'
36 fastutilVersion = '7.2.0'
Søren Gjessea93b4262021-12-08 14:40:10 +010037 guavaVersion = '30.1.1-jre'
Sebastien Hertz143ed112018-02-13 14:26:41 +010038 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020039 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010040 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080041 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +010042 // The kotlin version is only here to specify the kotlin language level,
43 // all kotlin compilations are done in tests.
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +010044 kotlinVersion = '1.8.0'
45 kotlinExtMetadataJVMVersion = '0.6.0'
Sebastien Hertz143ed112018-02-13 14:26:41 +010046 smaliVersion = '2.2b4'
Ian Zerny1a1ef0a2023-02-23 21:00:50 +010047 errorproneVersion = '2.18.0'
clementbera4f9c2a92019-07-09 08:50:37 +020048 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010049}
50
Mads Ager418d1ca2017-05-22 09:35:49 +020051repositories {
Jake Wharton5e5b5232019-09-17 16:13:32 -040052 google()
Mads Ager418d1ca2017-05-22 09:35:49 +020053 mavenCentral()
54}
55
Jinseong Jeon05064e12018-07-03 00:21:12 -070056if (project.hasProperty('with_code_coverage')) {
57 apply plugin: 'jacoco'
58}
59
Mads Ager418d1ca2017-05-22 09:35:49 +020060// Custom source set for example tests and generated tests.
61sourceSets {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020062 main {
63 java {
Ian Zernyc1582852023-01-30 13:45:36 +010064 srcDirs = ['src/main/java', 'src/keepanno/java']
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020065 }
66 resources {
67 srcDirs "third_party/api_database/api_database"
68 }
69 }
Clément Béraffc2d6a2022-08-02 13:03:04 +020070 main17 {
71 java {
Ian Zernyc1582852023-01-30 13:45:36 +010072 srcDirs = ['src/main/java', 'src/keepanno/java']
Clément Béraffc2d6a2022-08-02 13:03:04 +020073 }
74 resources {
75 srcDirs "third_party/api_database/api_database"
76 }
77 }
Mads Ager418d1ca2017-05-22 09:35:49 +020078 test {
79 java {
80 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020081 'src/test/java',
82 'build/generated/test/java',
83 ]
84 }
85 }
Yohann Rousselbb571622017-11-09 10:47:36 +010086 apiUsageSample {
87 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020088 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
89 include 'com/android/tools/apiusagesample/*.java'
90 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
91 include 'com/android/tools/r8/D8CommandParser.java'
92 include 'com/android/tools/r8/R8CommandParser.java'
93 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010094 }
Yohann Rousselbb571622017-11-09 10:47:36 +010095 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010096 cfSegments {
97 java {
98 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
99 }
100 output.resourcesDir = 'build/classes/cfSegments'
101 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100102 libraryDesugarConversions {
103 java {
104 srcDirs = ['src/library_desugar/java']
105 }
106 output.resourcesDir = 'build/classes/library_desugar_conversions'
107 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200108 debugTestResources {
109 java {
110 srcDirs = ['src/test/debugTestResources']
111 }
112 output.resourcesDir = 'build/classes/debugTestResources'
113 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200114 debugTestResourcesJava8 {
115 java {
116 srcDirs = ['src/test/debugTestResourcesJava8']
117 }
118 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
119 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200120 examples {
121 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800122 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200123 }
124 output.resourcesDir = 'build/classes/examples'
125 }
Ian Zernyd3020482019-04-25 07:05:04 +0200126 examplesJava9 {
127 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200128 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200129 }
130 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500131 examplesJava10 {
132 java {
133 srcDirs = ['src/test/examplesJava10']
134 }
135 }
Ian Zernyd3020482019-04-25 07:05:04 +0200136 examplesJava11 {
137 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200138 srcDirs = ['src/test/examplesJava11']
139 }
140 }
Søren Gjessee9966932021-09-15 17:08:37 +0200141 examplesJava17 {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100142 java {
Søren Gjessee9966932021-09-15 17:08:37 +0200143 srcDirs = ['src/test/examplesJava17']
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100144 }
145 }
Søren Gjessed1e08992022-02-07 16:46:31 +0100146 examplesJava18 {
147 java {
148 srcDirs = ['src/test/examplesJava18']
149 }
150 }
clementberaefa10522019-07-11 11:20:46 +0200151 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200152 java {
153 srcDirs = ['src/test/testngrunner']
154 }
155 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200156 examplesAndroidN {
157 java {
158 srcDirs = ['src/test/examplesAndroidN']
159 }
160 output.resourcesDir = 'build/classes/examplesAndroidN'
161 }
162 examplesAndroidO {
163 java {
164 srcDirs = ['src/test/examplesAndroidO']
165 }
166 output.resourcesDir = 'build/classes/examplesAndroidO'
167 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200168 examplesAndroidP {
169 java {
170 srcDirs = ['src/test/examplesAndroidP']
171 }
172 output.resourcesDir = 'build/classes/examplesAndroidP'
173 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200174 examplesProto {
175 java {
176 srcDirs = ['src/test/examplesProto']
177 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200178 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
179 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200180 output.resourcesDir = 'build/classes/examplesProto'
181 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100182 kotlinR8TestResources {
183 java {
184 srcDirs = ['src/test/kotlinR8TestResources']
185 }
186 output.resourcesDir = 'build/classes/kotlinR8TestResources'
187 }
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100188 keepanno {
189 java {
Ian Zerny172aca22022-11-03 13:07:48 +0100190 srcDirs = ['src/keepanno/java']
Ian Zernya87869c2023-01-31 08:38:21 +0100191 include 'com/android/tools/r8/keepanno/annotations/*.java'
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100192 }
193 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200194}
195
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800196// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
197// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
198// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
199// for context.
200idea {
201 sourceSets.all { SourceSet sources ->
202 module {
Ian Zernyc1582852023-01-30 13:45:36 +0100203 if (sources.name == "main") {
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800204 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100205 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800206 } else {
207 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100208 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800209 }
210 }
211 }
212}
213
Yohann Roussel126f6872017-08-03 16:25:32 +0200214configurations {
215 supportLibs
216}
217
Mads Ager418d1ca2017-05-22 09:35:49 +0200218dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100219 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
220 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200221 // Include all of guava when compiling the code, but exclude annotations that we don't
222 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100223 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100224 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200225 exclude group: 'com.google.errorprone'
226 exclude group: 'com.google.code.findbugs'
227 exclude group: 'com.google.j2objc'
228 exclude group: 'org.codehaus.mojo'
229 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100230 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
231 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
232 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
233 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
234 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
235 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
236 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200237
Clément Béraffc2d6a2022-08-02 13:03:04 +0200238 main17Implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
239 main17Implementation "com.google.code.gson:gson:$gsonVersion"
240 // Include all of guava when compiling the code, but exclude annotations that we don't
241 // need from the packaging.
242 main17CompileOnly("com.google.guava:guava:$guavaVersion")
243 main17Implementation("com.google.guava:guava:$guavaVersion", {
244 exclude group: 'com.google.errorprone'
245 exclude group: 'com.google.code.findbugs'
246 exclude group: 'com.google.j2objc'
247 exclude group: 'org.codehaus.mojo'
248 })
249 main17Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
250 main17Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
251 main17Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
252 main17Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
253 main17Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
254 main17Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
255 main17Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen1240b3d2023-02-02 12:59:42 +0100256
clementberaefa10522019-07-11 11:20:46 +0200257 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100258
Mads Ager418d1ca2017-05-22 09:35:49 +0200259 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100260 testCompile "junit:junit:$junitVersion"
Ian Zerny161ff742022-01-20 12:39:40 +0100261 testCompile "com.google.guava:guava:$guavaVersion"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100262 testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
263 testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100264 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200265 testCompile files('third_party/jasmin/jasmin-2.4.jar')
266 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200267 testCompile files('third_party/ddmlib/ddmlib.jar')
Ian Zerny161ff742022-01-20 12:39:40 +0100268 testCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
269 testCompile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
270 testCompile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
271 testCompile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
272 testCompile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
273 testCompile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
274
Sebastien Hertz143ed112018-02-13 14:26:41 +0100275 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
276 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200277 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100278 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800279 examplesCompile "junit:junit:$junitVersion"
280 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100281 supportLibs "com.android.support:support-v4:$androidSupportVersion"
282 supportLibs "junit:junit:$junitVersion"
283 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100284 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100285 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100286 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100287 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100288
289 keepannoCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
290 keepannoCompile "com.google.guava:guava:$guavaVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200291}
292
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100293def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100294def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200295def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100296def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100297def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +0200298def java11ClassFiles = "$buildDir/classes/java/mainJava11"
299def r8RetracePath = "$buildDir/libs/r8retrace.jar"
300def r8RetraceExludeDepsPath = "$buildDir/libs/r8retrace-exclude-deps.jar"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100301
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200302def osString = OperatingSystem.current().isLinux() ? "linux" :
303 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200304
305def cloudDependencies = [
306 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200307 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100308 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200309 ],
310 "third_party": [
Rico Winde4aee2a2023-01-26 13:46:40 +0100311 "aapt2",
Rico Windf72fa152018-10-22 15:41:03 +0200312 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200313 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200314 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100315 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200316 "android_jar/lib-v19",
317 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100318 "android_jar/lib-v22",
319 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200320 "android_jar/lib-v24",
321 "android_jar/lib-v25",
322 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100323 "android_jar/lib-v27",
324 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200325 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200326 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100327 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100328 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100329 "android_jar/lib-v33",
Morten Krogh-Jespersenfdbe3272023-02-10 12:25:07 +0100330 "android_jar/lib-v34",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200331 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200332 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200333 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200334 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200335 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200336 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100337 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200338 "dart-sdk",
339 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200340 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100341 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200342 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200343 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200344 "jacoco/0.8.2",
345 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200346 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100347 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200348 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200349 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200350 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200351 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200352 "kotlin/kotlin-compiler-1.3.11",
353 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200354 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100355 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200356 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100357 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200358 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen47efa232023-01-20 11:12:06 +0100359 "kotlin/kotlin-compiler-1.8.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200360 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200361 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100362 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200363 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000364 "openjdk/desugar_jdk_libs_11",
Ian Zernyc4598882022-02-25 19:26:44 +0100365 "openjdk/desugar_jdk_libs_legacy",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200366 "openjdk/desugar_jdk_libs_releases/1.0.9",
367 "openjdk/desugar_jdk_libs_releases/1.0.10",
368 "openjdk/desugar_jdk_libs_releases/1.1.0",
369 "openjdk/desugar_jdk_libs_releases/1.1.1",
370 "openjdk/desugar_jdk_libs_releases/1.1.5",
clementbera8dbfeda2019-07-03 11:24:13 +0200371 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100372 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200373 "proguard/proguard5.2.1",
374 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200375 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000376 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200377 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200378 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200379 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200380 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200381 "r8mappings",
382 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200383 ],
384 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
385 // container on other platforms where supported.
386 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200387 "linux/art",
388 "linux/art-5.1.1",
389 "linux/art-6.0.1",
390 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100391 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100392 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100393 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200394 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200395 "linux/host/art-13.0.0",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200396 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200397 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100398 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200399 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200400 ]
401]
402
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100403def cloudSystemDependencies = [
404 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200405 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200406 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100407 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100408 "openjdk/jdk-17/linux",
409 "openjdk/jdk-18/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100410 ],
411 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200412 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200413 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100414 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100415 "openjdk/jdk-17/osx",
416 "openjdk/jdk-18/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100417 ],
418 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200419 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100420 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100421 "openjdk/jdk-17/windows",
422 "openjdk/jdk-18/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100423 ],
424]
425
426if (OperatingSystem.current().isWindows()) {
427 cloudSystemDependencies.windows.each { entry ->
428 cloudDependencies.get(entry.key).addAll(entry.value)
429 }
430} else if (OperatingSystem.current().isLinux()) {
431 cloudSystemDependencies.linux.each { entry ->
432 cloudDependencies.get(entry.key).addAll(entry.value)
433 }
434} else if (OperatingSystem.current().isMacOsX()) {
435 cloudSystemDependencies.osx.each { entry ->
436 cloudDependencies.get(entry.key).addAll(entry.value)
437 }
438} else {
439 println "WARNING: Unsupported system: " + OperatingSystem.current()
440}
441
442def getDownloadDepsTaskName(entryKey, entryFile) {
443 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
444}
445
Mads Ager418d1ca2017-05-22 09:35:49 +0200446cloudDependencies.each { entry ->
447 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200448 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100449 type DownloadDependency.Type.GOOGLE_STORAGE
450 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200451 }
452 }
453}
454
455def x20Dependencies = [
456 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200457 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700458 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200459 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200460 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000461 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100462 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100463 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200464 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100465 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200466 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200467 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200468 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200469 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200470 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200471 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200472 "proguard/proguard_internal_159423826",
473 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200474 "proto",
475 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200476 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200477 "youtube/youtube.android_16.20",
478 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200479 ],
480]
481
482x20Dependencies.each { entry ->
483 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100484 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
485 type DownloadDependency.Type.X20
486 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200487 }
488 }
489}
490
Rico Wind897bb712017-05-23 10:44:29 +0200491task downloadProguard {
492 cloudDependencies.each { entry ->
493 entry.value.each { entryFile ->
494 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100495 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200496 }
497 }
498 }
499}
500
Rico Windf6c74ce2018-12-04 08:50:55 +0100501task downloadOpenJDKrt {
502 cloudDependencies.each { entry ->
503 entry.value.each { entryFile ->
504 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100505 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100506 }
507 }
508 }
509}
510
Tamas Kenez427205b2017-06-29 15:57:09 +0200511task downloadDx {
512 cloudDependencies.each { entry ->
513 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200514 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100515 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200516 }
517 }
518 }
519}
520
Tamas Kenez0e10c562017-06-08 10:00:34 +0200521task downloadAndroidCts {
522 cloudDependencies.each { entry ->
523 entry.value.each { entryFile ->
524 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100525 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200526 }
527 }
528 }
529}
530
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200531task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200532 cloudDependencies.each { entry ->
533 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100534 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200535 }
536 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200537}
538
539task downloadX20Deps() {
540 x20Dependencies.each { entry ->
541 entry.value.each { entryFile ->
542 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200543 }
544 }
545}
546
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200547task downloadDeps {
548 dependsOn downloadCloudDeps
549 if (!project.hasProperty('no_internal')) {
550 dependsOn downloadX20Deps
551 }
552}
553
Mads Ager418d1ca2017-05-22 09:35:49 +0200554allprojects {
555 sourceCompatibility = JavaVersion.VERSION_1_8
556 targetCompatibility = JavaVersion.VERSION_1_8
557}
558
Rico Wind266336c2019-02-25 10:11:38 +0100559// TODO(ricow): Remove debug prints
560println("NOTE: Current operating system: " + OperatingSystem.current())
561println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
562
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100563// Check if running with the JDK location from tools/jdk.py.
564if (OperatingSystem.current().isWindows()) {
565 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100566 compileJava.options.encoding = "UTF-8"
567 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100568} else {
569 def javaHomeOut = new StringBuilder()
570 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400571 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100572 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
573 def jdkHome = new File(javaHomeOut.toString().trim())
574 if (!jdkHome.exists()) {
575 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
576 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
577 println("WARNING: Gradle is running in a non-pinned Java"
578 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000579 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100580 } else {
581 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100582 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200583}
584
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200585compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200586
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100587sourceSets.configureEach { sourceSet ->
588 tasks.named(sourceSet.compileJavaTaskName).configure {
589 // Default disable errorprone (enabled and setup below).
590 options.errorprone.enabled = false
591 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100592 // Run all compilation tasks in a forked subprocess.
593 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100594 // Javac often runs out of stack space when compiling the tests.
595 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200596 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100597 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200598 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100599 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
600 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
601 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200602}
603
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100604def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
605 tasks.named(sourceSet).get().configure {
606 def jdkDir = "third_party/openjdk/${javaHome}/"
607 options.fork = true
608 options.forkOptions.jvmArgs = []
609 if (enablePreview) {
610 options.compilerArgs.add('--enable-preview')
611 }
612 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200613 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100614 options.forkOptions.javaHome = file(jdkDir + 'linux')
615 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200616 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400617 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
618 ? file(jdkDir + 'osx/Contents/Home')
619 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100620 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200621 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100622 options.forkOptions.javaHome = file(jdkDir + 'windows')
623 }
624 sourceCompatibility = compatibility
625 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200626 }
Ian Zernyd3020482019-04-25 07:05:04 +0200627}
628
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100629setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200630 sourceSets.main.compileJavaTaskName,
631 'jdk-11',
632 JavaVersion.VERSION_11,
633 false);
634
635setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100636 sourceSets.examplesJava9.compileJavaTaskName,
637 'openjdk-9.0.4',
638 JavaVersion.VERSION_1_9,
639 false)
640setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100641 sourceSets.examplesJava10.compileJavaTaskName,
642 'jdk-11',
643 JavaVersion.VERSION_1_10,
644 false)
645setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200646 sourceSets.main17.compileJavaTaskName,
647 'jdk-17',
648 JavaVersion.VERSION_17,
649 false)
650setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100651 sourceSets.examplesJava11.compileJavaTaskName,
652 'jdk-11',
653 JavaVersion.VERSION_11,
654 false)
655setJdkCompilationWithCompatibility(
656 sourceSets.examplesTestNGRunner.compileJavaTaskName,
657 'jdk-11',
658 JavaVersion.VERSION_11,
659 false)
660setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200661 sourceSets.examplesJava17.compileJavaTaskName,
662 'jdk-17',
663 JavaVersion.VERSION_17,
664 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100665setJdkCompilationWithCompatibility(
666 sourceSets.examplesJava18.compileJavaTaskName,
667 'jdk-18',
668 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
669 JavaVersion.VERSION_17,
670 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100671
Clément Bérac94b6202021-09-28 11:16:58 +0000672task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
673 from sourceSets.examplesTestNGRunner.compileClasspath
674 include "**/**.jar"
675 into file("$buildDir/test/jdk11Tests")
676}
677
678task compileTestNGRunner (type: JavaCompile) {
679 dependsOn provideJdk11TestsDependencies
Clément Béra98d5b602021-09-29 06:27:21 +0000680 destinationDir = file("$buildDir/classes/java/examplesTestNGRunner")
Clément Bérac94b6202021-09-28 11:16:58 +0000681 source = sourceSets.examplesTestNGRunner.allSource
682 classpath = sourceSets.examplesTestNGRunner.compileClasspath
683}
684
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100685if (!project.hasProperty('without_error_prone') &&
686 // Don't enable error prone on Java 8 as the plugin setup does not support it.
687 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200688 compileJava {
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100689
690 // Enable error prone for D8/R8 main sources and make all warnings errors.
691 // Warnings that we have chosen not to fix (or suppress) are disabled outright below.
692 options.compilerArgs << "-Werror"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100693 options.errorprone.enabled = true
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100694
695 // Non-default / Experimental checks - explicitly enforced.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100696 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100697 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100698 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
699 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
700 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100701
702 // TODO(b/270534077): These should likely be fixed/suppressed and become hard failures.
703 options.errorprone.check('JdkObsolete', CheckSeverity.OFF)
Ian Zerny1a1ef0a2023-02-23 21:00:50 +0100704 options.errorprone.check('UnusedVariable', CheckSeverity.OFF)
705 options.errorprone.check('EqualsUnsafeCast', CheckSeverity.OFF)
706 options.errorprone.check('TypeParameterUnusedInFormals', CheckSeverity.OFF)
707 options.errorprone.check('LoopOverCharArray', CheckSeverity.OFF)
708 options.errorprone.check('ImmutableEnumChecker', CheckSeverity.OFF)
709 options.errorprone.check('BadImport', CheckSeverity.OFF)
710 options.errorprone.check('StringSplitter', CheckSeverity.OFF)
711 options.errorprone.check('ComplexBooleanConstant', CheckSeverity.OFF)
712 options.errorprone.check('StreamToIterable', CheckSeverity.OFF)
713 options.errorprone.check('HidingField', CheckSeverity.OFF)
714 options.errorprone.check('StreamResourceLeak', CheckSeverity.OFF)
715 options.errorprone.check('CatchAndPrintStackTrace', CheckSeverity.OFF)
716 options.errorprone.check('ShortCircuitBoolean', CheckSeverity.OFF)
717 options.errorprone.check('NonCanonicalType', CheckSeverity.OFF)
718 options.errorprone.check('UnusedNestedClass', CheckSeverity.OFF)
719 options.errorprone.check('AmbiguousMethodReference', CheckSeverity.OFF)
720 options.errorprone.check('InvalidParam', CheckSeverity.OFF)
721 options.errorprone.check('CharacterGetNumericValue', CheckSeverity.OFF)
722 options.errorprone.check('ModifyCollectionInEnhancedForLoop', CheckSeverity.OFF)
723 options.errorprone.check('EmptyCatch', CheckSeverity.OFF)
724 options.errorprone.check('ArgumentSelectionDefectChecker', CheckSeverity.OFF)
725 options.errorprone.check('ImmutableAnnotationChecker', CheckSeverity.OFF)
726 options.errorprone.check('ObjectToString', CheckSeverity.OFF)
727 options.errorprone.check('DoNotClaimAnnotations', CheckSeverity.OFF)
728 options.errorprone.check('AnnotateFormatMethod', CheckSeverity.OFF)
729
730 // TODO(b/270537614): Remove finalize uses.
731 options.errorprone.check('Finalize', CheckSeverity.OFF)
732
733 // The following warnings could/should be active but are hit by R8 now so silence them.
734 options.errorprone.check('EqualsGetClass', CheckSeverity.OFF)
735 options.errorprone.check('MixedMutabilityReturnType', CheckSeverity.OFF)
736 options.errorprone.check('UnnecessaryParentheses', CheckSeverity.OFF)
737 options.errorprone.check('DoNotCallSuggester', CheckSeverity.OFF)
738 options.errorprone.check('InlineMeSuggester', CheckSeverity.OFF)
739 options.errorprone.check('MutablePublicArray', CheckSeverity.OFF)
740 options.errorprone.check('DefaultCharset', CheckSeverity.OFF)
741 options.errorprone.check('InconsistentCapitalization', CheckSeverity.OFF)
742 options.errorprone.check('InlineFormatString', CheckSeverity.OFF)
743 options.errorprone.check('MissingImplementsComparable', CheckSeverity.OFF)
744
745 // Warnings that cause unwanted edits (e.g., inability to write informative asserts).
746 options.errorprone.check('AlreadyChecked', CheckSeverity.OFF)
747
748 // JavaDoc related warnings. Would be nice to resolve but of no real consequence.
749 options.errorprone.check('InvalidLink', CheckSeverity.OFF)
750 options.errorprone.check('InvalidBlockTag', CheckSeverity.OFF)
751 options.errorprone.check('InvalidInlineTag', CheckSeverity.OFF)
752 options.errorprone.check('EmptyBlockTag', CheckSeverity.OFF)
753 options.errorprone.check('MissingSummary', CheckSeverity.OFF)
754 options.errorprone.check('UnrecognisedJavadocTag', CheckSeverity.OFF)
755 options.errorprone.check('AlmostJavadoc', CheckSeverity.OFF)
756
757 // Moving away from identity and canonical items is not planned.
758 options.errorprone.check('ReferenceEquality', CheckSeverity.OFF)
759 options.errorprone.check('IdentityHashMapUsage', CheckSeverity.OFF)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200760 }
761}
762
Yohann Roussel7f47c032017-09-14 12:19:06 +0200763task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200764 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100765
Yohann Roussel7f47c032017-09-14 12:19:06 +0200766 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100767 def runtimeClasspath = configurations.findByName("runtimeClasspath")
768 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
769
Yohann Roussel7f47c032017-09-14 12:19:06 +0200770 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100771
Yohann Roussel7f47c032017-09-14 12:19:06 +0200772 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100773 def dependencies = []
774 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
775 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
776 dependencies.add("${identifier.group}:${identifier.module}")
777 }
778 def libraryLicenses = file('LIBRARY-LICENSE').text
779 dependencies.each {
780 if (!libraryLicenses.contains("- artifact: $it")) {
781 throw new GradleException("No license for $it in LIBRARY_LICENSE")
782 }
783 }
784
Yohann Roussel7f47c032017-09-14 12:19:06 +0200785 license.getParentFile().mkdirs()
786 license.createNewFile()
787 license.text = "This file lists all licenses for code distributed.\n"
788 license.text += "All non-library code has the following 3-Clause BSD license.\n"
789 license.text += "\n"
790 license.text += "\n"
791 license.text += file('LICENSE').text
792 license.text += "\n"
793 license.text += "\n"
794 license.text += "Summary of distributed libraries:\n"
795 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100796 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200797 license.text += "\n"
798 license.text += "\n"
799 license.text += "Licenses details:\n"
800 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
801 license.text += "\n"
802 license.text += "\n"
803 license.text += file.text
804 }
805 }
806}
807
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100808def repackageDepFile(file) {
809 if (file.getName().endsWith('.jar')) {
810 return zipTree(file).matching {
811 exclude '**/module-info.class'
812 exclude 'META-INF/maven/**'
813 exclude 'META-INF/LICENSE.txt'
814 exclude 'META-INF/MANIFEST.MF'
815 }
816 } else {
817 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700818 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200819}
820
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100821task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200822 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100823 dependsOn project.configurations.runtimeClasspath
824 project.configurations.runtimeClasspath.forEach {
825 from repackageDepFile(it)
826 }
827 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000828}
829
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100830task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200831 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100832 dependsOn project.configurations.testCompile
833 project.configurations.testCompile.forEach {
834 from repackageDepFile(it)
835 }
836 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200837}
838
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100839task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100840 // If this fails then remove all generated folders from
841 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200842 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100843 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000844}
845
Clément Béraffc2d6a2022-08-02 13:03:04 +0200846task repackageSources17(type: Jar) {
847 from sourceSets.main17.output
848 archiveFileName = 'sources_main_17.jar'
849}
850
Søren Gjesse145d9e82022-05-24 08:12:13 +0200851def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100852 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200853 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100854 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200855 dependsOn files('LICENSE')
856 if (includeLibraryLicenses) {
857 from consolidatedLicense.outputs.files
858 } else {
859 from files('LICENSE')
860 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100861 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100862 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100863 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200864 if (includeSwissArmyKnife) {
865 manifest {
866 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
867 }
868 }
869 exclude "META-INF/*.kotlin_module"
870 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200871 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200872}
873
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200874def r8RelocateTask(r8Task, output) {
875 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
876 dependsOn r8WithDeps
877 dependsOn r8Task
878 outputs.file output
879 workingDir = projectDir
880 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200881 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200882 "relocator",
883 "--input",
884 r8Task.outputs.files[0],
885 "--output",
886 output,
887 "--map",
888 "com.google.common->com.android.tools.r8.com.google.common",
889 "--map",
890 "com.google.gson->com.android.tools.r8.com.google.gson",
891 "--map",
892 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
893 "--map",
894 "joptsimple->com.android.tools.r8.joptsimple",
895 "--map",
896 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
897 "--map",
898 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
899 "--map",
900 "kotlin->com.android.tools.r8.jetbrains.kotlin",
901 "--map",
902 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
903 "--map",
904 "org.jetbrains->com.android.tools.r8.org.jetbrains",
905 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200906 "org.intellij->com.android.tools.r8.org.intellij",
907 "--map",
908 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200909 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200910 }
911}
912
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200913task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200914 dependsOn repackageSources
915 dependsOn repackageDeps
916 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200917 def r8Task = r8CreateTask(
918 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100919 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200920 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200921 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200922 true)
923 dependsOn r8Task
924 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200925}
926
Clément Béraffc2d6a2022-08-02 13:03:04 +0200927task r8WithDeps17 {
928 dependsOn repackageSources17
929 dependsOn repackageDeps
930 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
931 def r8Task = r8CreateTask(
932 'WithDeps17',
933 'r8_with_deps_17.jar',
934 repackageSources17.outputs.files + repackageDeps.outputs.files,
935 true,
936 true)
937 dependsOn r8Task
938 outputs.files r8Task.outputs.files
939}
940
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200941task r8WithRelocatedDeps {
942 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
943 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200944 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200945 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200946}
947
Clément Béraffc2d6a2022-08-02 13:03:04 +0200948task r8WithRelocatedDeps17 {
949 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
950 dependsOn r8RelocateTask(r8WithDeps17, output)
951 inputs.files r8WithDeps17.outputs.files
952 outputs.file output
953}
954
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200955task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200956 dependsOn repackageSources
957 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200958 def r8Task = r8CreateTask(
959 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100960 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200961 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200962 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200963 true)
964 dependsOn r8Task
965 outputs.files r8Task.outputs.files
966}
967
968task r8(type: Copy) {
969 def r8Task = project.hasProperty("exclude_deps")
970 ? r8WithoutDeps : r8WithRelocatedDeps
971 dependsOn r8Task
972 from r8Task.outputs.files[0]
973 into file("${buildDir}/libs")
974 rename { String fileName -> "r8.jar" }
975 outputs.file "${buildDir}/libs/r8.jar"
976}
977
978task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200979 dependsOn repackageSources
980 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200981 def r8Task = r8CreateTask(
982 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100983 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200984 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200985 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200986 false)
987 dependsOn r8Task
988 outputs.files r8Task.outputs.files
989}
990
991task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200992 dependsOn repackageSources
993 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200994 def r8Task = r8CreateTask(
995 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100996 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200997 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200998 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200999 false)
1000 dependsOn r8Task
1001 outputs.files r8Task.outputs.files
1002}
1003
1004task r8NoManifestWithRelocatedDeps {
1005 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
1006 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001007 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001008 outputs.file output
1009}
1010
1011task r8NoManifest(type: Copy) {
1012 def r8Task = project.hasProperty("exclude_deps")
1013 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
1014 dependsOn r8Task
1015 from r8Task.outputs.files[0]
1016 into file("${buildDir}/libs")
1017 rename { String fileName -> "r8_no_manifest.jar" }
1018 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +01001019}
1020
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001021def baseCompilerCommandLine(compiler, args = []) {
1022 // Execute r8 commands against a stable r8 with dependencies.
1023 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
1024 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
1025 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
1026}
1027
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001028def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001029 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001030 return baseCompilerCommandLine("r8", args)
1031}
1032
1033def baseD8CommandLine(args = []) {
1034 // Execute r8 commands against a stable r8 with dependencies.
1035 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001036}
1037
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001038def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
1039 def allArgs = [
1040 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001041 input,
1042 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001043 "--pg-map-output", output + ".map",
Ian Zerny3ac86842022-10-05 11:49:35 +02001044 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001045 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
1046 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001047}
1048
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001049def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
1050 def allArgs = [
1051 "--classfile",
1052 input,
1053 "--output", output,
1054 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
1055 ] + args + libs.collectMany { ["--lib", it] }
1056 return baseD8CommandLine(allArgs)
1057}
1058
Ian Zernycf8ef512022-05-04 14:54:16 +02001059def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001060 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001061 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001062 outputs.file output
1063 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001064 dependsOn r8WithRelocatedDeps
1065 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001066 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001067 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001068 "--r8jar", r8Task.outputs.files[0],
1069 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001070 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001071 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001072 + (libs.collectMany { ["--lib", it] })
1073 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001074 workingDir = projectDir
1075 }
1076}
1077
Clément Bérac8b2c152022-06-22 08:23:47 +02001078task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001079 from sourceSets.libraryDesugarConversions.output
1080 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001081 baseName 'library_desugar_conversions_raw'
1082 destinationDir file('build/tmp/desugaredlibrary')
1083}
1084
1085task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001086 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001087 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001088}
1089
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001090task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1091 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001092 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001093 // We only want to include tests that use R8 when generating keep rules for applymapping.
1094 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001095 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001096 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001097}
1098
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001099task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001100 dependsOn r8WithDeps
1101 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001102 def output = "$buildDir/libs/r8tests.jar"
1103 outputs.file output
1104 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001105 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001106 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001107 "relocator",
1108 "--input",
1109 testJarSources.outputs.files[0],
1110 "--output",
1111 output,
1112 "--map",
1113 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1114 ])
1115}
1116
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001117task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001118 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1119 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001120 dependsOn r8WithDeps
1121 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001122 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001123 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001124 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001125 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001126 r8WithDeps.outputs,
1127 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001128 repackageDeps.outputs,
1129 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001130 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001131 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001132 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001133 "tracereferences",
1134 "--keep-rules",
1135 "--allowobfuscation",
1136 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001137 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001138 "--lib",
1139 repackageDeps.outputs.files[0],
1140 "--lib",
1141 repackageTestDeps.outputs.files[0],
1142 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001143 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001144 "--source",
1145 testJar.outputs.files[0],
1146 "--output",
1147 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001148 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001149}
1150
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001151task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001152 dependsOn r8LibCreateTask(
1153 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001154 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001155 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001156 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001157 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001158 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001159 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001160}
1161
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001162task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001163 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001164 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001165 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001166 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001167 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001168 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001169 repackageDeps.outputs.files,
1170 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001171 ).dependsOn(repackageDeps)
1172 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001173 outputs.file r8LibExludeDepsPath
1174}
1175
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001176task R8Desugared(type: Exec) {
1177 dependsOn downloadOpenJDKrt
1178 dependsOn r8NoManifestWithRelocatedDeps
1179 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1180 commandLine d8CfCommandLine(
1181 r8NoManifestWithRelocatedDeps.outputs.files[0],
1182 r8DesugaredPath,
1183 ["--release"])
1184 workingDir = projectDir
1185 outputs.file r8DesugaredPath
1186}
1187
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001188task R8Retrace {
1189 dependsOn R8Lib
1190 dependsOn r8LibCreateTask(
1191 "Retrace",
1192 ["src/main/keep_retrace.txt"],
1193 R8Lib,
1194 r8RetracePath,
1195 ).dependsOn(R8Lib)
1196 outputs.file r8RetracePath
1197}
1198
1199task R8RetraceNoDeps {
1200 dependsOn R8LibNoDeps
1201 dependsOn r8LibCreateTask(
1202 "RetraceNoDeps",
1203 ["src/main/keep_retrace.txt"],
1204 R8LibNoDeps,
1205 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001206 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001207 repackageDeps.outputs.files,
1208 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001209 ).dependsOn(R8LibNoDeps)
1210 outputs.file r8RetraceExludeDepsPath
1211}
1212
Mads Ager418d1ca2017-05-22 09:35:49 +02001213task sourceJar(type: Jar, dependsOn: classes) {
1214 classifier = 'src'
1215 from sourceSets.main.allSource
1216}
1217
Ian Zernya87869c2023-01-31 08:38:21 +01001218task keepAnnoJar(type: Jar) {
1219 archiveFileName = "keepanno-annotations.jar"
1220 from sourceSets.keepanno.output
1221}
1222
Mads Ager418d1ca2017-05-22 09:35:49 +02001223artifacts {
1224 archives sourceJar
1225}
1226
1227task createArtTests(type: Exec) {
1228 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001229 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001230 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001231 outputs.dir outputDir
1232 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001233 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001234 workingDir = projectDir
1235}
1236
Mads Ager418d1ca2017-05-22 09:35:49 +02001237compileTestJava {
1238 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001239}
1240
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001241task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1242 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001243 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001244 destinationDir file('build/libs')
1245}
1246
Ian Zerny923a0c12018-01-03 10:59:18 +01001247task buildR8ApiUsageSample(type: Jar) {
1248 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001249 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001250 destinationDir file('tests')
1251}
1252
Yohann Roussel548ae942018-01-05 11:13:28 +01001253task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001254 dependsOn buildR8ApiUsageSample
1255}
1256
Mads Ager418d1ca2017-05-22 09:35:49 +02001257task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001258 def resourcesDir = file("src/test/debugTestResources")
1259 def hostJar = "debug_test_resources.jar"
1260 task "compile_debugTestResources"(type: JavaCompile) {
1261 source = fileTree(dir: resourcesDir, include: '**/*.java')
1262 destinationDir = file("build/test/debugTestResources/classes")
1263 classpath = sourceSets.main.compileClasspath
1264 sourceCompatibility = JavaVersion.VERSION_1_7
1265 targetCompatibility = JavaVersion.VERSION_1_7
1266 options.compilerArgs += ["-g", "-Xlint:-options"]
1267 }
1268 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1269 archiveName = hostJar
1270 destinationDir = file("build/test/")
1271 from "build/test/debugTestResources/classes"
1272 include "**/*.class"
1273 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001274 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1275 def java8HostJar = "debug_test_resources_java8.jar"
1276 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1277 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1278 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1279 classpath = sourceSets.main.compileClasspath
1280 sourceCompatibility = JavaVersion.VERSION_1_8
1281 targetCompatibility = JavaVersion.VERSION_1_8
1282 options.compilerArgs += ["-g", "-Xlint:-options"]
1283 }
1284 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1285 archiveName = java8HostJar
1286 destinationDir = file("build/test/")
1287 from "build/test/debugTestResourcesJava8/classes"
1288 include "**/*.class"
1289 }
1290 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001291 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001292 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001293}
1294
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001295// Examples used by tests, where Android specific APIs are used.
1296task buildExampleAndroidApi(type: JavaCompile) {
1297 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1298 destinationDir = file("build/test/examplesAndroidApi/classes")
1299 classpath = files("third_party/android_jar/lib-v26/android.jar")
1300 sourceCompatibility = JavaVersion.VERSION_1_8
1301 targetCompatibility = JavaVersion.VERSION_1_8
1302}
1303
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001304task buildProtoGeneratedSources {
1305 def examplesProtoDir = file("src/test/examplesProto")
1306 examplesProtoDir.eachDir { dir ->
1307 def name = dir.getName()
1308 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1309 source = {
1310 file('third_party/proto').listFiles()
1311 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1312 .collect { zipTree(it) }
1313 }
1314 destinationDir = file("build/generated/test/proto/${name}_classes")
1315 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1316 sourceCompatibility = JavaVersion.VERSION_1_8
1317 targetCompatibility = JavaVersion.VERSION_1_8
1318 }
1319 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1320 archiveName = "${name}.jar"
1321 destinationDir = file("build/generated/test/proto")
1322 from "build/generated/test/proto/${name}_classes"
1323 include "/**/*.class"
1324 }
1325 dependsOn "jar_proto_generated_source_${name}"
1326 }
1327}
1328
1329task buildExamplesProto {
1330 def examplesProtoDir = file("src/test/examplesProto")
1331 def examplesProtoOutputDir = file("build/test/examplesProto");
1332 dependsOn buildProtoGeneratedSources
1333 task "compile_examples_proto"(type: JavaCompile) {
1334 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1335 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001336 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1337 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001338 sourceCompatibility = JavaVersion.VERSION_1_8
1339 targetCompatibility = JavaVersion.VERSION_1_8
1340 }
1341 examplesProtoDir.eachDir { dir ->
1342 def name = dir.getName()
1343 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1344 archiveName = "${name}.jar"
1345 destinationDir = examplesProtoOutputDir
1346 from "build/test/examplesProto/classes"
1347 include name + "/**/*.class"
1348 }
1349 dependsOn "jar_examples_proto_${name}"
1350 }
1351}
1352
Lars Bakc91e87e2017-08-18 08:53:10 +02001353// Proto lite generated code yields warnings when compiling with javac.
1354// We change the options passed to javac to ignore it.
1355compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1356
Søren Gjesse7320ce52018-05-07 15:45:22 +02001357
Mads Ager418d1ca2017-05-22 09:35:49 +02001358task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001359 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001360 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001361 def proguardScript
1362 if (OperatingSystem.current().isWindows()) {
1363 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1364 } else {
1365 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1366 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001367 task extractExamplesRuntime(type: Sync) {
1368 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001369 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001370 include "**/*.class"
1371 includeEmptyDirs false
1372 into "$buildDir/runtime/examples/"
1373 }
1374
Søren Gjesse7320ce52018-05-07 15:45:22 +02001375 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1376 from examplesDir
1377 exclude "**/*.java"
1378 exclude "**/keep-rules*.txt"
1379 into file("build/test/examples/classes")
1380 }
1381
1382 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001383 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001384 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001385 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001386 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001387 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001388 sourceCompatibility = JavaVersion.VERSION_1_7
1389 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001390 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1391 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001392 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1393 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001394 include "**/*.java"
1395 destinationDir = file("build/test/examples/classes_debuginfo_all")
1396 classpath = sourceSets.examples.compileClasspath
1397 sourceCompatibility = JavaVersion.VERSION_1_7
1398 targetCompatibility = JavaVersion.VERSION_1_7
1399 options.compilerArgs = ["-g", "-Xlint:none"]
1400 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001401 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1402 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001403 include "**/*.java"
1404 destinationDir = file("build/test/examples/classes_debuginfo_none")
1405 classpath = sourceSets.examples.compileClasspath
1406 sourceCompatibility = JavaVersion.VERSION_1_7
1407 targetCompatibility = JavaVersion.VERSION_1_7
1408 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001409 }
1410 examplesDir.eachDir { dir ->
1411 def name = dir.getName();
1412 def exampleOutputDir = file("build/test/examples");
1413 def jarName = "${name}.jar"
1414 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001415 dependsOn "jar_example_${name}_debuginfo_all"
1416 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001417 dependsOn "extractExamplesRuntime"
1418 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001419 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1420 def proguardConfigPath = "${dir}/proguard.cfg"
1421 if (new File(proguardConfigPath).exists()) {
1422 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1423 archiveName = "${name}_pre_proguard.jar"
1424 destinationDir = exampleOutputDir
1425 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001426 include name + "/**/*.class"
1427 with runtimeDependencies
1428 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001429 }
1430 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1431 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1432 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1433 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001434 inputs.files files(
1435 tasks.getByPath("pre_proguard_example_${name}"),
1436 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001437 // Enable these to get stdout and stderr redirected to files...
1438 // standardOutput = new FileOutputStream('proguard.stdout')
1439 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001440 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001441 " -outjars ${proguardJarPath}" +
1442 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001443 " -printmapping ${proguardMapPath}"
1444 if (OperatingSystem.current().isWindows()) {
1445 executable "${proguardScript}"
1446 args "${proguardArguments}"
1447 } else {
1448 executable "bash"
1449 args "-c", "${proguardScript} '${proguardArguments}'"
1450 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001451 outputs.file proguardJarPath
1452 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001453 // TODO: Consider performing distinct proguard compilations.
1454 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1455 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001456 into "${exampleOutputDir}"
1457 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001458 }
1459 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1460 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001461 into "${exampleOutputDir}"
1462 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001463 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001464 } else {
1465 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001466 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001467 destinationDir = exampleOutputDir
1468 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001469 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001470 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001471 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001472 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001473 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1474 archiveName = "${name}_debuginfo_all.jar"
1475 destinationDir = exampleOutputDir
1476 from "build/test/examples/classes_debuginfo_all"
1477 include name + "/**/*.class"
1478 with runtimeDependencies
1479 includeEmptyDirs false
1480 }
1481 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1482 archiveName = "${name}_debuginfo_none.jar"
1483 destinationDir = exampleOutputDir
1484 from "build/test/examples/classes_debuginfo_none"
1485 include name + "/**/*.class"
1486 with runtimeDependencies
1487 includeEmptyDirs false
1488 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001489 }
1490 }
1491}
1492
1493task buildExampleAndroidNJars {
1494 dependsOn downloadDeps
1495 def examplesDir = file("src/test/examplesAndroidN")
1496 task "compile_examplesAndroidN"(type: JavaCompile) {
1497 source = fileTree(dir: examplesDir, include: '**/*.java')
1498 destinationDir = file("build/test/examplesAndroidN/classes")
1499 classpath = sourceSets.main.compileClasspath
1500 sourceCompatibility = JavaVersion.VERSION_1_8
1501 targetCompatibility = JavaVersion.VERSION_1_8
1502 options.compilerArgs += ["-Xlint:-options"]
1503 }
1504 examplesDir.eachDir { dir ->
1505 def name = dir.getName();
1506 def exampleOutputDir = file("build/test/examplesAndroidN");
1507 def jarName = "${name}.jar"
1508 dependsOn "jar_examplesAndroidN_${name}"
1509 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1510 archiveName = jarName
1511 destinationDir = exampleOutputDir
1512 from "build/test/examplesAndroidN/classes"
1513 include "**/" + name + "/**/*.class"
1514 }
1515 }
1516}
1517
1518
1519task buildExampleAndroidOJars {
1520 dependsOn downloadDeps
1521 def examplesDir = file("src/test/examplesAndroidO")
1522 // NOTE: we want to enable a scenario when test needs to reference some
1523 // classes generated by legacy (1.6) Java compiler to test some specific
1524 // behaviour. To do so we compile all the java files located in sub-directory
1525 // called 'legacy' with Java 1.6, then compile the rest of the files with
1526 // Java 1.8 and a reference to previously generated 1.6 classes.
1527
1528 // Compiling all classes in dirs 'legacy' with old Java version.
1529 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1530 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1531 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1532 classpath = sourceSets.main.compileClasspath
1533 sourceCompatibility = JavaVersion.VERSION_1_6
1534 targetCompatibility = JavaVersion.VERSION_1_6
1535 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1536 }
1537 // Compiling the rest of the files as Java 1.8 code.
1538 task "compile_examplesAndroidO"(type: JavaCompile) {
1539 dependsOn "compile_examplesAndroidO_Legacy"
1540 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1541 destinationDir = file("build/test/examplesAndroidO/classes")
1542 classpath = sourceSets.main.compileClasspath
1543 classpath += files("build/test/examplesAndroidOLegacy/classes")
1544 sourceCompatibility = JavaVersion.VERSION_1_8
1545 targetCompatibility = JavaVersion.VERSION_1_8
1546 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1547 }
1548 examplesDir.eachDir { dir ->
1549 def name = dir.getName();
1550 def destinationDir = file("build/test/examplesAndroidO/classes");
1551 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1552 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1553 dependsOn: "compile_examplesAndroidO") {
1554 main = name + ".TestGenerator"
1555 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1556 args destinationDir
1557 }
1558 } else {
1559 task "generate_examplesAndroidO_${name}" () {}
1560 }
1561 }
1562 examplesDir.eachDir { dir ->
1563 def name = dir.getName();
1564 def exampleOutputDir = file("build/test/examplesAndroidO");
1565 def jarName = "${name}.jar"
1566 dependsOn "jar_examplesAndroidO_${name}"
1567 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1568 "generate_examplesAndroidO_${name}"]) {
1569 archiveName = jarName
1570 destinationDir = exampleOutputDir
1571 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1572 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1573 include "**/" + name + "/**/*.class"
1574 // Do not include generator into the test runtime jar, it is not useful.
1575 // Otherwise, shrinking will need ASM jars.
1576 exclude "**/TestGenerator*"
1577 }
1578 }
1579}
1580
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001581task buildExampleAndroidPJars {
1582 dependsOn downloadDeps
1583 def examplesDir = file("src/test/examplesAndroidP")
1584
1585 task "compile_examplesAndroidP"(type: JavaCompile) {
1586 source = fileTree(dir: examplesDir, include: '**/*.java')
1587 destinationDir = file("build/test/examplesAndroidP/classes")
1588 classpath = sourceSets.main.compileClasspath
1589 sourceCompatibility = JavaVersion.VERSION_1_8
1590 targetCompatibility = JavaVersion.VERSION_1_8
1591 options.compilerArgs += ["-Xlint:-options"]
1592 }
1593 examplesDir.eachDir { dir ->
1594 def name = dir.getName();
1595 def destinationDir = file("build/test/examplesAndroidP/classes");
1596 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1597 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1598 dependsOn: "compile_examplesAndroidP") {
1599 main = name + ".TestGenerator"
1600 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1601 args destinationDir
1602 }
1603 } else {
1604 task "generate_examplesAndroidP_${name}" () {}
1605 }
1606 }
1607 examplesDir.eachDir { dir ->
1608 def name = dir.getName();
1609 def exampleOutputDir = file("build/test/examplesAndroidP");
1610 def jarName = "${name}.jar"
1611 dependsOn "jar_examplesAndroidP_${name}"
1612 task "jar_examplesAndroidP_${name}"(type: Jar,
1613 dependsOn: ["compile_examplesAndroidP",
1614 "generate_examplesAndroidP_${name}"]) {
1615 archiveName = jarName
1616 destinationDir = exampleOutputDir
1617 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1618 include "**/" + name + "/**/*.class"
1619 // Do not include generator into the test runtime jar, it is not useful.
1620 // Otherwise, shrinking will need ASM jars.
1621 exclude "**/TestGenerator*"
1622 }
1623 }
1624}
1625
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001626def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1627 return tasks.create("buildExample${javaVersion}Jars") {
1628 def examplesDir = file("src/test/examples${javaVersion}")
1629 examplesDir.eachDir { dir ->
1630 def name = dir.getName();
1631 def exampleOutputDir = file("build/test/examples${javaVersion}");
1632 def jarName = "${name}.jar"
1633 dependsOn "jar_examples${javaVersion}_${name}"
1634 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1635 archiveName = jarName
1636 destinationDir = exampleOutputDir
1637 from sourceSet.output
1638 include "**/" + name + "/**/*.class"
1639 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001640 }
1641 }
1642}
1643
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001644buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1645buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1646buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001647buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjessed1e08992022-02-07 16:46:31 +01001648buildExampleJarsCreateTask("Java18", sourceSets.examplesJava18)
clementberad7ab1dd2019-04-16 16:05:00 +02001649
clementberaa92e3cd2019-07-12 14:13:22 +02001650task provideArtFrameworksDependencies {
1651 cloudDependencies.tools.forEach({ art ->
1652 if (art.contains("art")) {
1653 def taskName = art.replace('/','_')
1654 dependsOn "patch_${taskName}"
1655 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1656 from "tools/${art}/framework"
1657 include "**.jar"
1658 into file("tools/${art}/out/host/linux-x86/framework")
1659 }
1660 }
1661 })
1662}
1663
Sebastien Hertzd3313772018-01-16 14:12:37 +01001664task buildKotlinR8TestResources {
1665 def examplesDir = file("src/test/kotlinR8TestResources")
1666 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001667 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1668 def name = dir.getName()
1669 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001670 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001671 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001672 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001673 task "${taskName}Java"(type: JavaCompile) {
1674 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1675 destinationDir = file(javaOutput)
1676 classpath = sourceSets.main.compileClasspath
1677 sourceCompatibility = JavaVersion.VERSION_1_6
1678 targetCompatibility = JavaVersion.VERSION_1_6
1679 options.compilerArgs += ["-g", "-Xlint:-options"]
1680 }
1681 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1682 archiveName = javaOutputJarName
1683 destinationDir = file(javaOutputJarDir)
1684 from javaOutput
1685 include "**/*.class"
1686 }
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +01001687 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001688 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001689 }
1690}
1691
Mads Ager418d1ca2017-05-22 09:35:49 +02001692task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001693 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1694 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1695 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001696 } else if (!OperatingSystem.current().isLinux()) {
1697 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001698 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001699 return;
1700 }
1701 dependsOn buildDebugTestResourcesJars
1702 dependsOn buildExampleJars
1703 dependsOn buildExampleAndroidNJars
1704 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001705 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001706 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001707 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001708 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001709 dependsOn buildExampleJava17Jars
Søren Gjessed1e08992022-02-07 16:46:31 +01001710 dependsOn buildExampleJava18Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001711 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001712 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001713 def noDexTests = [
1714 "multidex",
1715 "multidex002",
1716 "multidex004",
1717 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001718 examplesDir.eachDir { dir ->
1719 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001720 if (!(name in noDexTests)) {
1721 dependsOn "dex_example_${name}"
1722 def exampleOutputDir = file("build/test/examples/" + name);
1723 def dexPath = file("${exampleOutputDir}")
1724 def debug = (name == "throwing")
1725 if (!dexPath.exists()) {
1726 dexPath.mkdirs()
1727 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001728 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001729 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1730 destination = dexPath
1731 debug = debug
1732 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001733 }
1734 }
1735}
1736
1737task buildSmali {
1738 def smaliDir = file("src/test/smali")
1739 smaliDir.eachDirRecurse() { dir ->
1740 def name = dir.getName();
1741 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1742 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1743 smaliOutputDir.mkdirs()
1744 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001745 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001746 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1747 def javaFiles = fileTree(dir: dir, include: '*.java')
1748 def destDir = smaliOutputDir;
1749 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1750 def intermediateFileName = "${name}-intermediate.dex";
1751 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1752 if (javaFiles.empty) {
1753 if (!smaliFiles.empty) {
1754 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001755 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001756 source = smaliFiles
1757 destination = destFile
1758 }
1759 }
1760 } else {
Rico Wind01c15c62021-04-22 17:30:41 +00001761 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001762 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001763 source = smaliFiles
1764 destination = intermediateFile
1765 }
1766 task "${taskName}_java"(type: JavaCompile) {
1767 source = javaFiles
1768 destinationDir destDir
1769 classpath = sourceSets.main.compileClasspath
1770 sourceCompatibility = JavaVersion.VERSION_1_7
1771 targetCompatibility = JavaVersion.VERSION_1_7
1772 options.compilerArgs += ["-Xlint:-options"]
1773 }
1774 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1775 archiveName = "Test.jar"
1776 destinationDir = destDir
1777 from fileTree(dir: destDir, include: 'Test.class')
1778 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001779 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001780 source = fileTree(dir: destDir, include: 'Test.jar')
1781 destination = destDir
1782 }
1783 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001784 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001785 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1786 destination = destFile
1787 }
1788 }
1789 }
1790}
1791
1792tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001793 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001794 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001795 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001796 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001797 if (userDefinedCoresPerFork) {
1798 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1799 } else {
1800 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001801 maxParallelForks = processors.intdiv(3) ?: 1
1802 // On low cpu count machines (bots) we under subscribe, so increase the count.
1803 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001804 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001805 }
Rico Wind73da9f12019-09-19 09:27:07 +02001806 }
Rico Windc56f21c2019-03-12 07:29:57 +01001807 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001808
Mads Ager418d1ca2017-05-22 09:35:49 +02001809 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001810 if (project.hasProperty('disable_assertions')) {
1811 enableAssertions = false
1812 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001813 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001814 if (project.hasProperty('test_xmx')) {
1815 maxHeapSize = project.property('test_xmx')
1816 } else {
1817 maxHeapSize = "4G"
1818 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001819}
1820
1821task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001822 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001823 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1824 // Exclude the classes containing java8
1825 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1826 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1827 includeEmptyDirs = false
1828}
1829
Ian Zerny74143162017-11-24 13:46:35 +01001830task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1831 def inFile = buildPreNJdwpTestsJar.archivePath
1832 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001833 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001834 outputs.file outFile
1835 if (OperatingSystem.current().isWindows()) {
1836 executable file("tools/windows/dx/bin/dx.bat")
1837 } else if (OperatingSystem.current().isMacOsX()) {
1838 executable file("tools/mac/dx/bin/dx");
1839 } else {
1840 executable file("tools/linux/dx/bin/dx");
1841 }
1842 args "--dex"
1843 args "--output=${outFile}"
1844 args inFile
1845}
1846
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001847task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1848 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001849}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001850
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001851task generateR8TestKeepRules {
1852 def path = "build/generated/r8tests-keep.txt"
1853 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001854 dependsOn R8Lib
1855 doLast {
1856 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001857-dontshrink
1858-dontoptimize
1859-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001860-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001861"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001862 }
1863}
1864
1865task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001866 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1867 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001868 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001869 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001870 dependsOn generateR8TestKeepRules
1871 dependsOn testJar
1872 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1873 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1874 return pkg.toString().endsWith(".jar")
1875 } + ["${buildDir}/classes/java/test"]
1876 inputs.files testJar.outputs.files +
1877 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001878 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001879 commandLine = r8CfCommandLine(
1880 testJar.outputs.files[0],
1881 outputPath,
1882 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001883 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1884 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001885 workingDir = projectDir
1886 outputs.file outputPath
1887}
1888
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001889task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001890 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001891 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001892 dependsOn R8Lib
1893 delete r8LibTestPath
1894 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1895 def examplesDir = file("build/test")
1896 examplesDir.eachDir { dir ->
1897 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001898 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001899 from ("${buildDir}/runtime/examples")
1900 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001901 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001902}
1903
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001904def shouldRetrace() {
1905 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1906}
1907
1908def retrace(Throwable exception) {
1909 def out = new StringBuffer()
1910 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001911 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001912 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001913 out.append("\n--------------------------------------\n")
1914 out.append("${header}\n")
1915 out.append("--------------------------------------\n")
1916 Process process = command.execute()
1917 def processIn = new PrintStream(process.getOut())
1918 process.consumeProcessOutput(out, err)
1919 exception.printStackTrace(processIn)
1920 processIn.flush()
1921 processIn.close()
1922 def errorDuringRetracing = process.waitFor() != 0
1923 if (errorDuringRetracing) {
1924 out.append("ERROR DURING RETRACING\n")
1925 out.append(err.toString())
1926 }
1927 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1928 out.append("\n\n--------------------------------------\n")
1929 out.append("OBFUSCATED STACKTRACE\n")
1930 out.append("--------------------------------------\n")
1931 }
1932 return out.toString()
1933}
1934
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001935def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001936 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001937 if (shouldRetrace()) {
1938 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001939 exception.setStackTrace([] as StackTraceElement[])
1940 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001941 }
1942}
1943
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001944def filterStackTraces(TestResult result) {
1945 for (Throwable throwable : result.getExceptions()) {
1946 filterStackTrace(throwable)
1947 }
1948}
1949
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001950// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001951def filterStackTrace(Throwable exception) {
1952 if (!project.hasProperty('print_full_stacktraces')) {
1953 def elements = []
1954 def skipped = []
1955 for (StackTraceElement element : exception.getStackTrace()) {
1956 if (element.toString().contains("com.android.tools.r8")) {
1957 elements.addAll(skipped)
1958 elements.add(element)
1959 skipped.clear()
1960 } else {
1961 skipped.add(element)
1962 }
1963 }
1964 exception.setStackTrace(elements as StackTraceElement[])
1965 }
1966}
1967
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001968def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1969 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1970 exceptions.forEach { it.printStackTrace(printer) }
1971 }
1972}
1973
Ian Zerny89f16cf2021-04-29 21:10:09 +02001974static def escapeHtml(String string) {
1975 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1976}
1977
1978static def urlEncode(String string) {
1979 // Not sure why, but the + also needs to be converted to have working links.
1980 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1981}
1982
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001983def ensureDir(File dir) {
1984 dir.mkdirs()
1985 return dir
1986}
1987
Ian Zerny89f16cf2021-04-29 21:10:09 +02001988// Some of our test parameters have new lines :-( We really don't want test names to span lines.
1989static def sanitizedTestName(testDesc) {
1990 if (testDesc.getName().contains("\n")) {
1991 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
1992 }
1993 return testDesc.getName()
1994}
1995
1996static def desanitizedTestName(testName) {
1997 return testName
1998}
1999
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002000def getTestReportEntryDir(reportDir, testDesc) {
2001 return ensureDir(reportDir.toPath()
2002 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02002003 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002004 .toFile())
2005}
2006
Ian Zerny89f16cf2021-04-29 21:10:09 +02002007def getTestReportEntryURL(reportDir, testDesc) {
2008 def classDir = urlEncode(testDesc.getClassName())
2009 def testDir = urlEncode(sanitizedTestName(testDesc))
2010 return "file://${reportDir}/${classDir}/${testDir}"
2011}
2012
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002013def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
2014 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
2015 return dir.resolve(fileName).toFile()
2016}
2017
Ian Zerny89f16cf2021-04-29 21:10:09 +02002018def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
2019 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
2020 new FileWriter(file, append).withCloseable fn
2021}
2022
Ian Zerny27ea4c72021-04-29 22:35:49 +02002023static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002024 def out = new StringBuilder()
2025 def err = new StringBuilder()
2026 def proc = "git rev-parse --abbrev-ref HEAD".execute()
2027 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02002028 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002029}
2030
Ian Zerny27ea4c72021-04-29 22:35:49 +02002031static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002032 def number = 0
2033 while (true) {
2034 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
2035 if (!freshIndex.exists()) {
2036 return freshIndex
2037 }
2038 }
2039}
2040
2041def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
2042 def out = new StringBuilder()
2043 def err = new StringBuilder()
2044 def proc = "find . -name ${fileName}".execute([], reportDir)
2045 proc.waitForProcessOutput(out, err)
2046 def outString = out.toString()
2047 outString.eachLine {
2048 // Lines are of the form: ./<class>/<name>/FAILURE
2049 def clazz = null
2050 def name = null
2051 try {
2052 def trimmed = it.trim()
2053 def line = trimmed.substring(2)
2054 def sep = line.indexOf("/")
2055 clazz = line.substring(0, sep)
2056 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
2057 } catch (Exception e) {
2058 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
2059 return
2060 }
2061 onTest(clazz, desanitizedTestName(name))
2062 }
2063 return !outString.trim().isEmpty()
2064}
2065
2066def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
2067 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
2068}
2069
2070def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
2071 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
2072}
2073
2074def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
2075 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
2076}
2077
Ian Zerny27ea4c72021-04-29 22:35:49 +02002078def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002079 // Hide all test events from the console, they are written to the report.
2080 task.testLogging { events = [] }
2081
Ian Zernycae764d2021-08-16 08:25:15 +02002082 def branch = project.hasProperty('testing-state-name')
2083 ? project.getProperty('testing-state-name')
2084 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002085 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02002086 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002087 def resetState = project.hasProperty('reset-testing-state')
2088 def reportDirExists = reportDir.exists()
2089 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02002090
2091 def hasFailingTests = false;
2092 if (resuming) {
2093 // Test filtering happens before the test execution is initiated so compute it here.
2094 // If there are still failing tests in the report, include only those.
2095 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
2096 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
2097 })
2098 // Otherwise exclude all of the test already marked as succeeding.
2099 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002100 // Also allow the test to overall succeed if there are no remaining tests that match,
2101 // which is natural if the state already succeeded in full.
2102 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02002103 forEachTestReportAlreadyPassing(reportDir, {
2104 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2105 })
2106 forEachTestReportAlreadySkipped(reportDir, {
2107 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2108 })
2109 }
2110 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002111
2112 task.beforeSuite { desc ->
2113 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002114 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02002115 if (resetState && reportDirExists) {
2116 delete reportDir
2117 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002118 if (resuming) {
2119 if (index.exists()) {
2120 parentReport = getFreshTestReportIndex(reportDir)
2121 index.renameTo(parentReport)
2122 }
2123 } else {
2124 reportDir.mkdirs()
2125 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002126 def runPrefix = resuming ? "Resuming" : "Starting"
2127 def title = "${runPrefix} @ ${branch}"
2128 // Print a console link to the test report for easy access.
2129 println "${runPrefix} test, report written to:"
2130 println " file://${index}"
2131 // Print the new index content.
2132 index << "<html><head><title>${title}</title>"
2133 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002134 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002135 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002136 index << "<p>Run on: ${new Date()}</p>"
2137 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002138 if (parentReport != null) {
2139 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
2140 }
2141 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
2142 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002143 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002144 }
2145 }
2146
2147 task.afterSuite { desc, result ->
2148 if (!desc.parent) {
2149 // Update the final test results in the index.
2150 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002151 if (result.resultType == TestResult.ResultType.SUCCESS) {
2152 if (hasFailingTests) {
2153 index << "<h2>Rerun of failed tests now pass!</h2>"
2154 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
2155 } else {
2156 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
2157 }
2158 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002159 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002160 } else {
2161 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
2162 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002163 index << "<li>Number of tests: ${result.testCount}"
2164 index << "<li>Failing tests: ${result.failedTestCount}"
2165 index << "<li>Successful tests: ${result.successfulTestCount}"
2166 index << "<li>Skipped tests: ${result.skippedTestCount}"
2167 index << "</ul></body></html>"
2168 }
2169 }
2170
2171 // Events to stdout/err are appended to the files in the test directories.
2172 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02002173 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
2174 it.append(event.getMessage())
2175 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002176 }
2177
Ian Zerny27ea4c72021-04-29 22:35:49 +02002178 task.beforeTest { desc ->
2179 // Remove any stale output files before running the test.
2180 for (def destType : TestOutputEvent.Destination.values()) {
2181 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
2182 if (destFile.exists()) {
2183 delete destFile
2184 }
2185 }
2186 }
2187
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002188 task.afterTest { desc, result ->
2189 if (result.getTestCount() != 1) {
2190 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
2191 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002192 // Clear any previous result files.
2193 for (def resultType : TestResult.ResultType.values()) {
2194 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
2195 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002196 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002197 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
2198 it.append(result.getResultType().name())
2199 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002200 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002201 withTestResultEntryWriter(reportDir, desc, "time", false, {
2202 it.append("${result.getEndTime() - result.getStartTime()}")
2203 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002204 // For failed tests, update the index and emit stack trace information.
2205 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002206 def title = escapeHtml("${desc.className}.${desc.name}")
2207 def link = getTestReportEntryURL(reportDir, desc)
2208 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002209 if (!result.exceptions.isEmpty()) {
2210 printAllStackTracesToFile(
2211 result.exceptions,
2212 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002213 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002214 desc,
2215 "exceptions-raw.txt"))
2216 filterStackTraces(result)
2217 printAllStackTracesToFile(
2218 result.exceptions,
2219 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002220 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002221 desc,
2222 "exceptions-filtered.txt"))
2223 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002224 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2225 result.exceptions.forEach { writer.append(retrace(it)) }
2226 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002227 }
2228 }
2229 }
2230 }
2231}
2232
Rico Windf2f4c292021-04-23 07:06:13 +02002233def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002234def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002235
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002236test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002237
Ian Zernyc1582852023-01-30 13:45:36 +01002238 dependsOn sourceSets.keepanno.output
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002239 dependsOn buildLibraryDesugarConversions
2240 dependsOn getJarsFromSupportLibs
2241 // R8.jar is required for running bootstrap tests.
2242 dependsOn r8
2243
Ian Zerny27ea4c72021-04-29 22:35:49 +02002244 def useTestingState = project.hasProperty('testing-state')
2245 if (useTestingState) {
2246 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002247 }
2248
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002249 if (project.hasProperty('generate_golden_files_to')) {
2250 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2251 assert project.hasProperty('HEAD_sha1')
2252 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2253 }
2254
2255 if (project.hasProperty('use_golden_files_in')) {
2256 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2257 assert project.hasProperty('HEAD_sha1')
2258 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2259 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002260
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002261 if (project.hasProperty('kotlin_compiler_dev')) {
2262 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2263 }
2264
2265 if (project.hasProperty('kotlin_compiler_old')) {
2266 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2267 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002268
Ian Zerny27ea4c72021-04-29 22:35:49 +02002269 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002270 testLogging.exceptionFormat = 'full'
2271 if (project.hasProperty('print_test_stdout')) {
2272 testLogging.showStandardStreams = true
2273 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002274 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002275 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002276 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002277 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002278 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002279
Ian Zerny324d7612019-03-20 10:52:28 +01002280 // Forward runtime configurations for test parameters.
2281 if (project.hasProperty('runtimes')) {
2282 println "NOTE: Running with runtimes: " + project.property('runtimes')
2283 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002284 }
2285
Christoffer Quist Adamsen3b3a4b02023-02-06 13:43:30 +01002286 if (project.hasProperty('art_profile_rewriting_completeness_check')) {
2287 String key = 'com.android.tools.r8.artprofilerewritingcompletenesscheck'
2288 String value = project.property('art_profile_rewriting_completeness_check')
2289 systemProperty key, value
2290 }
2291
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002292 if (project.hasProperty('slow_tests')) {
2293 systemProperty 'slow_tests', project.property('slow_tests')
2294 }
2295
Søren Gjesseef195772021-03-11 16:04:42 +01002296
2297 if (project.hasProperty('desugar_jdk_json_dir')) {
2298 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2299 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002300 if (project.hasProperty('desugar_jdk_libs')) {
2301 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2302 }
2303
Ian Zerny27ea4c72021-04-29 22:35:49 +02002304 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002305 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2306 afterTest { desc, result ->
2307 def executionTime = (result.endTime - result.startTime) / 1000
2308 testTimes["${desc.name} [${desc.className}]"] = executionTime
2309 }
2310 afterSuite { desc, result ->
2311 // parent is null if all tests are done.
2312 if (desc.parent == null) {
2313 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2314 sortedTimes.eachWithIndex { key, value, i ->
Rico Windf94f4302023-01-03 10:57:10 +01002315 println "$key: $value"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002316 }
2317 }
2318 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002319 }
Rico Windf2f4c292021-04-23 07:06:13 +02002320
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002321 if (project.hasProperty('one_line_per_test')) {
2322 beforeTest { desc ->
2323 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002324 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002325
2326 afterTest { desc, result ->
2327 if (result.resultType == TestResult.ResultType.FAILURE) {
2328 printStackTrace(result)
2329 }
2330 if (project.hasProperty('update_test_timestamp')) {
2331 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2332 }
2333 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002334 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002335 } else {
2336 afterTest { desc, result ->
2337 if (result.resultType == TestResult.ResultType.FAILURE) {
2338 printStackTrace(result)
2339 }
Rico Windf88b6be2018-12-11 15:14:05 +01002340 }
2341 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002342 }
2343 if (project.hasProperty('no_internal')) {
2344 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002345 } else {
2346 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002347 }
2348 if (project.hasProperty('only_internal')) {
2349 include "com/android/tools/r8/internal/**"
2350 }
Rico Wind4e218292019-03-07 12:44:49 +01002351
Rico Windba151112020-10-01 08:16:33 +02002352 if (project.hasProperty('test_namespace')) {
2353 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2354 }
2355
Ian Zerny3ced9262022-03-29 11:06:02 +02002356 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2357 // Don't run anything, deprecated
2358 println "Running with deprecated tool d8, not running any tests"
2359 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002360 }
2361 if (!project.hasProperty('all_tests')) {
2362 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002363 }
Rico Windbc820812022-05-31 09:19:56 +02002364 if (project.hasProperty('no_arttests')) {
2365 exclude "com/android/tools/r8/art/**"
2366 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002367 if (project.hasProperty('shard_count') ) {
2368 assert project.hasProperty('shard_number')
2369 int shard_count = project.getProperty('shard_count') as Integer
2370 int shard_number = project.getProperty('shard_number') as Integer
2371 assert shard_count < 65536
2372 assert shard_number < shard_count
2373 exclude {
2374 entry ->
2375 // Don't leave out directories. Leaving out a directory means all entries below.
2376 if (entry.file.isDirectory()) {
2377 return false
2378 }
2379 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2380 int hash = Integer.parseInt(first4, 16)
2381 return hash % shard_count != shard_number
2382 }
2383 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002384 if (project.hasProperty('test_dir')) {
2385 systemProperty 'test_dir', project.property('test_dir')
2386 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002387 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002388 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002389 // R8lib should be used instead of the main output and all the tests in
2390 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002391 classpath = sourceSets.test.runtimeClasspath.filter {
2392 !it.getAbsolutePath().contains("/build/")
2393 }
2394 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002395 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002396 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002397 if (OperatingSystem.current().isLinux()
2398 || OperatingSystem.current().isMacOsX()
2399 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002400 if (OperatingSystem.current().isMacOsX()) {
2401 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2402 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2403 "See tools/docker/README.md for details.")
2404 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002405 if (OperatingSystem.current().isWindows()) {
2406 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2407 "Art only runs on Linux and tests requiring Art will be skipped")
2408 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002409 dependsOn downloadDeps
2410 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002411 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002412 dependsOn buildSmali
Mads Ager418d1ca2017-05-22 09:35:49 +02002413 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002414 dependsOn buildPreNJdwpTestsDex
Clément Bérac94b6202021-09-28 11:16:58 +00002415 dependsOn compileTestNGRunner
clementberaa92e3cd2019-07-12 14:13:22 +02002416 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002417 } else {
2418 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002419 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002420 }
2421}
2422
2423// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2424//
2425// To build and upload a new set of the Art tests for use with R8 follow these steps:
2426//
2427// First of all an Android checkout is required. Currently it must be located
2428// in $HOME/android/master.
2429//
2430// TODO(ricow): simplify this
2431//
2432// Before: update the checked in art, see scripts/update-host-art.sh
2433//
2434// 1. Get an android checkout in $HOME/android/master and apply the patch from
2435// https://android-review.googlesource.com/#/c/294187/
2436//
2437// 2. run the following commands in the Android checkout directory:
2438//
2439// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002440// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2441// m desugar
2442// m -j30 test-art-host
2443// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2444//
2445// Without running the test.py command the classes.jar file used by desugar in
2446// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2447// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002448//
2449// 3. In the R8 project root directory, make sure we have a clean state before starting:
2450// tools/gradle.py downloadDeps
2451// tools/gradle.py clean
2452// rm -rf tests/art
2453//
2454// 4. Now build in the R8 checkout (-P hack to not generate dirs when not running this target)
Søren Gjesse34b77732017-07-07 13:56:21 +02002455// Make sure you have smali on your path, please use the build binary in the
2456// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2457// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2458// need to change as smali got a completely new command line interface in version 2.2.1.
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002459// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2460// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002461//
Søren Gjesse34b77732017-07-07 13:56:21 +02002462// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002463//
2464// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2465// skippedTests with an explanation. Rerun from step 3.
2466//
2467// 5. Run the tests:
2468// tools/gradle.py clean
2469// tools/test.py
2470//
Søren Gjesse34b77732017-07-07 13:56:21 +02002471// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2472// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2473// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002474//
Søren Gjesse34b77732017-07-07 13:56:21 +02002475// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002476// cd tests
2477// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002478//
2479// 7. Update the manifest file describing the Android repo used:
2480// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002481
Mads Ager418d1ca2017-05-22 09:35:49 +02002482def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002483
2484def artTestDir = file("${androidCheckoutDir}/art/test")
2485
2486if (project.hasProperty('android_source')) {
2487 task buildArtTests {
2488 outputs.upToDateWhen { false }
2489 def toBeTriaged = [
2490 "903-hello-tagging",
2491 "904-object-allocation",
2492 "905-object-free",
2493 "906-iterate-heap",
2494 "907-get-loaded-classes",
2495 "908-gc-start-finish",
2496 "954-invoke-polymorphic-verifier",
2497 "955-methodhandles-smali",
2498 "596-monitor-inflation",
2499 ]
2500 def skippedTests = toBeTriaged + [
2501 // This test produces no jar.
2502 "000-nop",
2503 // This does not build, as it tests the error when the application exceeds more
2504 // than 65536 methods
2505 "089-many-methods",
2506 // Requires some jack beta jar
2507 "956-methodhandles",
2508 ]
2509
2510 def skippedTestsDx = [
2511 // Tests with custom build scripts, where javac is not passed the options
2512 // -source 1.7 -target 1.7.
2513 "462-checker-inlining-across-dex-files",
2514 "556-invoke-super",
2515 "569-checker-pattern-replacement",
2516 // These tests use jack even when --build-with-javac-dx is specified.
2517 "004-JniTest",
2518 "048-reflect-v8",
2519 "146-bad-interface",
2520 "563-checker-invoke-super",
2521 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2522 "604-hot-static-interface",
2523 "957-methodhandle-transforms",
2524 "958-methodhandle-emulated-stackframe",
2525 "959-invoke-polymorphic-accessors",
2526 "961-default-iface-resolution-gen",
2527 "962-iface-static",
2528 "963-default-range-smali",
2529 "964-default-iface-init-gen",
2530 "965-default-verify",
2531 "966-default-conflict",
2532 "967-default-ame",
2533 "968-default-partial-compile-gen",
2534 "969-iface-super",
2535 "970-iface-super-resolution-gen",
2536 "971-iface-super",
2537 // These tests does not build with --build-with-javac-dx
2538 "004-NativeAllocations", // Javac error
2539 "031-class-attributes",
2540 "138-duplicate-classes-check",
2541 "157-void-class", // Javac error
2542 "580-checker-string-factory-intrinsics",
2543 "612-jit-dex-cache",
2544 "613-inlining-dex-cache",
2545 "900-hello-plugin", // --experimental agents
2546 "901-hello-ti-agent", // --experimental agents
2547 "902-hello-transformation", // --experimental agents
2548 "909-attach-agent", // --experimental agents
2549 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2550 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2551 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2552 "960-default-smali", // --experimental default-methods
2553 // These tests force the build to use jack
2554 "953-invoke-polymorphic-compiler",
2555 "958-methodhandle-stackframe",
2556 ]
2557
2558 def artTestBuildDir = file("${projectDir}/tests/art")
2559
2560 if (androidCheckoutDir.exists()) {
2561 dependsOn downloadDeps
2562 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002563 artTestDir.eachDir { dir ->
2564 def name = dir.getName();
2565 def markerFile = dir.toPath().resolve("info.txt").toFile();
2566 if (markerFile.exists() && !(name in skippedTests)) {
2567 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002568 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002569 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002570 }
2571 }
2572 }
2573 doFirst {
2574 if (!androidCheckoutDir.exists()) {
2575 throw new InvalidUserDataException(
2576 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002577 }
2578 }
2579 doLast {
2580 copy {
2581 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2582 into file("${artTestBuildDir}/lib64")
2583 include 'lib*.so'
2584 }
2585 copy {
2586 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2587 into file("${artTestBuildDir}/lib64")
2588 include 'libart.so'
2589 include 'libbacktrace.so'
2590 include 'libbase.so'
2591 include 'libc++.so'
2592 include 'libcutils.so'
2593 include 'liblz4.so'
2594 include 'liblzma.so'
2595 include 'libnativebridge.so'
2596 include 'libnativeloader.so'
2597 include 'libsigchain.so'
2598 include 'libunwind.so'
2599 include 'libziparchive.so'
2600 }
2601 copy {
2602 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2603 into file("${artTestBuildDir}/lib")
2604 include 'lib*.so'
2605 }
2606 copy {
2607 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2608 into file("${artTestBuildDir}/lib")
2609 include 'libart.so'
2610 include 'libbacktrace.so'
2611 include 'libbase.so'
2612 include 'libc++.so'
2613 include 'libcutils.so'
2614 include 'liblz4.so'
2615 include 'liblzma.so'
2616 include 'libnativebridge.so'
2617 include 'libnativeloader.so'
2618 include 'libsigchain.so'
2619 include 'libunwind.so'
2620 include 'libziparchive.so'
2621 }
2622 }
2623 }
2624}
2625
Rico Windde2af6c2019-03-26 15:21:08 +01002626def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002627 def artTestDir = file("${androidCheckoutDir}/art/test")
2628 def artRunTestScript = file("${artTestDir}/run-test")
2629 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002630 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002631
Søren Gjesse34b77732017-07-07 13:56:21 +02002632 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002633 def buildTask = "build_art_test_dx_${name}"
2634 def sanitizeTask = "sanitize_art_test_dx_${name}"
2635 def copyCheckTask = "copy_check_art_test_dx_${name}"
2636 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002637
2638 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002639 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002640 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2641 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002642 task "$buildTask"(type: Exec) {
2643 outputs.upToDateWhen { false }
2644 inputs.file buildInputs
2645 executable "${artRunTestScript}"
2646 args "--host"
2647 args "--build-only"
2648 args "--build-with-javac-dx"
2649 args "--output-path", "${testDir}"
2650 args "${name}"
2651 environment DX: "${dxExecutable.absolutePath}"
2652 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2653 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2654 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002655 }
2656 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2657 outputs.upToDateWhen { false }
2658 executable "/bin/bash"
2659 args "-c"
2660 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2661 " ${testDir}/classes-ex ${testDir}/check"
2662 }
2663
2664 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002665 // Directory that contains smali files is either smali, or smali/art
2666 def smali_dir = file("${dir}/smali/art")
2667 if (smali_dir.exists()) {
2668 workingDir "${testDir}/smali/art"
2669 } else {
2670 workingDir "${testDir}/smali"
2671 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002672 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002673 // This is the command line options for smali prior to 2.2.1, where smali got a new
2674 // command line interface.
2675 args "-c", "smali a *.smali"
2676 // This is the command line options for smali 2.2.1 and later.
2677 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002678 }
2679
2680 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2681 def smali_dir = file("${dir}/smali")
2682 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002683 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002684 dependsOn smaliToDexTask
2685 }
2686 from("${artTestDir}/${name}") {
2687 include 'check'
2688 }
2689 into testDir
2690 }
2691
2692 return copyCheckTask
2693}
2694
2695task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002696 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002697 classpath = sourceSets.main.compileClasspath
2698 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002699 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002700 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002701 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002702 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002703 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002704 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002705 include '**/com/android/tools/r8/CompilationMode.java'
2706 include '**/com/android/tools/r8/D8.java'
2707 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002708 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2709 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002710 include '**/com/android/tools/r8/Diagnostic.java'
2711 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002712 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2713 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002714 include '**/com/android/tools/r8/ProgramConsumer.java'
2715 include '**/com/android/tools/r8/ProgramResource.java'
2716 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002717 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002718 include '**/com/android/tools/r8/ResourceException.java'
2719 include '**/com/android/tools/r8/StringConsumer.java'
2720 include '**/com/android/tools/r8/StringResource.java'
2721 include '**/com/android/tools/r8/Version.java'
2722 include '**/com/android/tools/r8/origin/*.java'
2723}
2724
2725task javadocR8(type: Javadoc) {
2726 title "R8 API"
2727 classpath = sourceSets.main.compileClasspath
2728 source = sourceSets.main.allJava
2729 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2730 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2731 include '**/com/android/tools/r8/BaseCommand.java'
2732 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2733 include '**/com/android/tools/r8/ClassFileConsumer.java'
2734 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2735 include '**/com/android/tools/r8/CompilationFailedException.java'
2736 include '**/com/android/tools/r8/CompilationMode.java'
2737 include '**/com/android/tools/r8/R8.java'
2738 include '**/com/android/tools/r8/R8Command.java'
2739 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2740 include '**/com/android/tools/r8/Diagnostic.java'
2741 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002742 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2743 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002744 include '**/com/android/tools/r8/ProgramConsumer.java'
2745 include '**/com/android/tools/r8/ProgramResource.java'
2746 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2747 include '**/com/android/tools/r8/Resource.java'
2748 include '**/com/android/tools/r8/ResourceException.java'
2749 include '**/com/android/tools/r8/StringConsumer.java'
2750 include '**/com/android/tools/r8/StringResource.java'
2751 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002752 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002753}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002754
2755task copyMavenDeps(type: Copy) {
2756 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002757 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002758 from configurations.testCompile into "$buildDir/deps"
2759}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002760
Rico Wind23a05112019-03-27 08:00:44 +01002761task printMavenDeps {
2762 // Only actually print to stdout when we are updating.
2763 if (project.hasProperty('updatemavendeps')) {
2764 for (Configuration config : configurations) {
2765 if (!config.isCanBeResolved()) {
2766 continue
2767 }
2768 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2769 it.selected.id
2770 }
2771 def result = dependencies.createArtifactResolutionQuery()
2772 .forComponents(componentIds)
2773 .withArtifacts(MavenModule, MavenPomArtifact)
2774 .execute()
2775 for (component in result.resolvedComponents) {
2776 component.getArtifacts(MavenPomArtifact).each {
2777 println "POM: ${it.file} ${component.id}"
2778 }
2779 }
2780 config.each {
2781 println "JAR: ${it}"
2782 }
2783 }
2784 }
2785}
Ian Zerny9713c032020-01-23 11:41:58 +01002786
2787allprojects {
2788 tasks.withType(Exec) {
2789 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002790 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002791 }
2792 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002793}