blob: f016148f29a169ef5ad13573869a1042277ad446 [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 {
Rico Wind23a05112019-03-27 08:00:44 +010019 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010020 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010021 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010022 mavenCentral()
Jake Wharton5e5b5232019-09-17 16:13:32 -040023 gradlePluginPortal()
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010024 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010025 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010026}
27
28plugins {
29 id "net.ltgt.errorprone" version "0.7"
30}
31
32apply plugin: 'java'
33apply plugin: 'idea'
34
Sebastien Hertz143ed112018-02-13 14:26:41 +010035ext {
36 androidSupportVersion = '25.4.0'
Søren Gjesse2792ced2022-12-15 16:06:08 +010037 asmVersion = '9.4' // When updating update tools/asmifier.py, build.src and Toolhelper as well.
Sebastien Hertz143ed112018-02-13 14:26:41 +010038 espressoVersion = '3.0.0'
39 fastutilVersion = '7.2.0'
Søren Gjessea93b4262021-12-08 14:40:10 +010040 guavaVersion = '30.1.1-jre'
Sebastien Hertz143ed112018-02-13 14:26:41 +010041 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020042 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010043 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080044 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +010045 // The kotlin version is only here to specify the kotlin language level,
46 // all kotlin compilations are done in tests.
Morten Krogh-Jespersen04d43e32023-01-20 19:02:11 +010047 kotlinVersion = '1.8.0'
48 kotlinExtMetadataJVMVersion = '0.6.0'
Sebastien Hertz143ed112018-02-13 14:26:41 +010049 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010050 errorproneVersion = '2.3.2'
clementbera4f9c2a92019-07-09 08:50:37 +020051 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010052}
53
Mads Ager418d1ca2017-05-22 09:35:49 +020054repositories {
Rico Wind23a05112019-03-27 08:00:44 +010055 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010056 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010057 }
Jake Wharton5e5b5232019-09-17 16:13:32 -040058 google()
Mads Ager418d1ca2017-05-22 09:35:49 +020059 mavenCentral()
60}
61
Jinseong Jeon05064e12018-07-03 00:21:12 -070062if (project.hasProperty('with_code_coverage')) {
63 apply plugin: 'jacoco'
64}
65
Mads Ager418d1ca2017-05-22 09:35:49 +020066// Custom source set for example tests and generated tests.
67sourceSets {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020068 main {
69 java {
70 srcDirs = ['src/main/java']
71 }
72 resources {
73 srcDirs "third_party/api_database/api_database"
74 }
75 }
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +020076 main11 {
77 java {
78 srcDirs = ['src/main/java']
79 }
Morten Krogh-Jespersen798aac02021-10-06 15:32:20 +020080 resources {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020081 srcDirs "third_party/api_database/api_database"
Morten Krogh-Jespersen798aac02021-10-06 15:32:20 +020082 }
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +020083 }
Clément Béraffc2d6a2022-08-02 13:03:04 +020084 main17 {
85 java {
86 srcDirs = ['src/main/java']
87 }
88 resources {
89 srcDirs "third_party/api_database/api_database"
90 }
91 }
Mads Ager418d1ca2017-05-22 09:35:49 +020092 test {
93 java {
94 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020095 'src/test/java',
96 'build/generated/test/java',
97 ]
98 }
99 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100100 apiUsageSample {
101 java {
Mathias Rave3f3c522018-05-30 08:22:17 +0200102 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
103 include 'com/android/tools/apiusagesample/*.java'
104 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
105 include 'com/android/tools/r8/D8CommandParser.java'
106 include 'com/android/tools/r8/R8CommandParser.java'
107 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +0100108 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100109 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100110 cfSegments {
111 java {
112 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
113 }
114 output.resourcesDir = 'build/classes/cfSegments'
115 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100116 libraryDesugarConversions {
117 java {
118 srcDirs = ['src/library_desugar/java']
119 }
120 output.resourcesDir = 'build/classes/library_desugar_conversions'
121 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200122 debugTestResources {
123 java {
124 srcDirs = ['src/test/debugTestResources']
125 }
126 output.resourcesDir = 'build/classes/debugTestResources'
127 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200128 debugTestResourcesJava8 {
129 java {
130 srcDirs = ['src/test/debugTestResourcesJava8']
131 }
132 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
133 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200134 examples {
135 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800136 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200137 }
138 output.resourcesDir = 'build/classes/examples'
139 }
Ian Zernyd3020482019-04-25 07:05:04 +0200140 examplesJava9 {
141 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200142 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200143 }
144 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500145 examplesJava10 {
146 java {
147 srcDirs = ['src/test/examplesJava10']
148 }
149 }
Ian Zernyd3020482019-04-25 07:05:04 +0200150 examplesJava11 {
151 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200152 srcDirs = ['src/test/examplesJava11']
153 }
154 }
Søren Gjessee9966932021-09-15 17:08:37 +0200155 examplesJava17 {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100156 java {
Søren Gjessee9966932021-09-15 17:08:37 +0200157 srcDirs = ['src/test/examplesJava17']
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100158 }
159 }
Søren Gjessed1e08992022-02-07 16:46:31 +0100160 examplesJava18 {
161 java {
162 srcDirs = ['src/test/examplesJava18']
163 }
164 }
clementberaefa10522019-07-11 11:20:46 +0200165 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200166 java {
167 srcDirs = ['src/test/testngrunner']
168 }
169 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200170 examplesAndroidN {
171 java {
172 srcDirs = ['src/test/examplesAndroidN']
173 }
174 output.resourcesDir = 'build/classes/examplesAndroidN'
175 }
176 examplesAndroidO {
177 java {
178 srcDirs = ['src/test/examplesAndroidO']
179 }
180 output.resourcesDir = 'build/classes/examplesAndroidO'
181 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200182 examplesAndroidP {
183 java {
184 srcDirs = ['src/test/examplesAndroidP']
185 }
186 output.resourcesDir = 'build/classes/examplesAndroidP'
187 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200188 examplesProto {
189 java {
190 srcDirs = ['src/test/examplesProto']
191 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200192 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
193 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200194 output.resourcesDir = 'build/classes/examplesProto'
195 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100196 kotlinR8TestResources {
197 java {
198 srcDirs = ['src/test/kotlinR8TestResources']
199 }
200 output.resourcesDir = 'build/classes/kotlinR8TestResources'
201 }
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100202 keepanno {
203 java {
Ian Zerny172aca22022-11-03 13:07:48 +0100204 srcDirs = ['src/keepanno/java']
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100205 }
206 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200207}
208
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800209// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
210// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
211// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
212// for context.
213idea {
214 sourceSets.all { SourceSet sources ->
215 module {
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100216 if (sources.name == "main" || sources.name == "keepanno") {
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800217 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100218 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800219 } else {
220 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100221 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800222 }
223 }
224 }
225}
226
Yohann Roussel126f6872017-08-03 16:25:32 +0200227configurations {
228 supportLibs
229}
230
Mads Ager418d1ca2017-05-22 09:35:49 +0200231dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100232 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
233 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200234 // Include all of guava when compiling the code, but exclude annotations that we don't
235 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100236 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100237 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200238 exclude group: 'com.google.errorprone'
239 exclude group: 'com.google.code.findbugs'
240 exclude group: 'com.google.j2objc'
241 exclude group: 'org.codehaus.mojo'
242 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100243 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
244 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
245 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
246 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
247 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
248 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
249 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200250
251 main11Implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
252 main11Implementation "com.google.code.gson:gson:$gsonVersion"
253 // Include all of guava when compiling the code, but exclude annotations that we don't
254 // need from the packaging.
255 main11CompileOnly("com.google.guava:guava:$guavaVersion")
256 main11Implementation("com.google.guava:guava:$guavaVersion", {
257 exclude group: 'com.google.errorprone'
258 exclude group: 'com.google.code.findbugs'
259 exclude group: 'com.google.j2objc'
260 exclude group: 'org.codehaus.mojo'
261 })
262 main11Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
263 main11Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
264 main11Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
265 main11Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
266 main11Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
267 main11Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
268 main11Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200269
Clément Béraffc2d6a2022-08-02 13:03:04 +0200270 main17Implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
271 main17Implementation "com.google.code.gson:gson:$gsonVersion"
272 // Include all of guava when compiling the code, but exclude annotations that we don't
273 // need from the packaging.
274 main17CompileOnly("com.google.guava:guava:$guavaVersion")
275 main17Implementation("com.google.guava:guava:$guavaVersion", {
276 exclude group: 'com.google.errorprone'
277 exclude group: 'com.google.code.findbugs'
278 exclude group: 'com.google.j2objc'
279 exclude group: 'org.codehaus.mojo'
280 })
281 main17Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
282 main17Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
283 main17Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
284 main17Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
285 main17Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
286 main17Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
287 main17Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen04d43e32023-01-20 19:02:11 +0100288
clementberaefa10522019-07-11 11:20:46 +0200289 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100290
Mads Ager418d1ca2017-05-22 09:35:49 +0200291 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100292 testCompile "junit:junit:$junitVersion"
Ian Zerny161ff742022-01-20 12:39:40 +0100293 testCompile "com.google.guava:guava:$guavaVersion"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100294 testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
295 testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100296 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200297 testCompile files('third_party/jasmin/jasmin-2.4.jar')
298 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200299 testCompile files('third_party/ddmlib/ddmlib.jar')
Ian Zerny161ff742022-01-20 12:39:40 +0100300 testCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
301 testCompile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
302 testCompile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
303 testCompile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
304 testCompile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
305 testCompile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
306
Sebastien Hertz143ed112018-02-13 14:26:41 +0100307 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
308 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200309 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100310 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800311 examplesCompile "junit:junit:$junitVersion"
312 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100313 supportLibs "com.android.support:support-v4:$androidSupportVersion"
314 supportLibs "junit:junit:$junitVersion"
315 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100316 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100317 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100318 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100319 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100320
321 keepannoCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
322 keepannoCompile "com.google.guava:guava:$guavaVersion"
323 testCompile sourceSets.keepanno.output
324 testRuntime sourceSets.keepanno.output
Stephan Herhut417a72a2017-07-18 10:38:30 +0200325}
326
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100327def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100328def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200329def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100330def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100331def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +0200332def java11ClassFiles = "$buildDir/classes/java/mainJava11"
333def r8RetracePath = "$buildDir/libs/r8retrace.jar"
334def r8RetraceExludeDepsPath = "$buildDir/libs/r8retrace-exclude-deps.jar"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100335
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200336def osString = OperatingSystem.current().isLinux() ? "linux" :
337 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200338
339def cloudDependencies = [
340 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200341 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100342 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200343 ],
344 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200345 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200346 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200347 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100348 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200349 "android_jar/lib-v19",
350 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100351 "android_jar/lib-v22",
352 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200353 "android_jar/lib-v24",
354 "android_jar/lib-v25",
355 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100356 "android_jar/lib-v27",
357 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200358 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200359 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100360 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100361 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100362 "android_jar/lib-v33",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200363 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200364 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200365 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200366 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200367 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200368 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100369 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200370 "dart-sdk",
371 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200372 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100373 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200374 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200375 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200376 "jacoco/0.8.2",
377 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200378 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100379 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200380 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200381 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200382 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200383 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200384 "kotlin/kotlin-compiler-1.3.11",
385 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200386 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100387 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200388 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100389 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200390 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen47efa232023-01-20 11:12:06 +0100391 "kotlin/kotlin-compiler-1.8.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200392 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200393 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100394 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200395 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000396 "openjdk/desugar_jdk_libs_11",
Ian Zernyc4598882022-02-25 19:26:44 +0100397 "openjdk/desugar_jdk_libs_legacy",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200398 "openjdk/desugar_jdk_libs_releases/1.0.9",
399 "openjdk/desugar_jdk_libs_releases/1.0.10",
400 "openjdk/desugar_jdk_libs_releases/1.1.0",
401 "openjdk/desugar_jdk_libs_releases/1.1.1",
402 "openjdk/desugar_jdk_libs_releases/1.1.5",
clementbera8dbfeda2019-07-03 11:24:13 +0200403 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100404 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200405 "proguard/proguard5.2.1",
406 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200407 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000408 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200409 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200410 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200411 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200412 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200413 "r8mappings",
414 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200415 ],
416 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
417 // container on other platforms where supported.
418 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200419 "linux/art",
420 "linux/art-5.1.1",
421 "linux/art-6.0.1",
422 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100423 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100424 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100425 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200426 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200427 "linux/host/art-13.0.0",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200428 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200429 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100430 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200431 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200432 ]
433]
434
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100435def cloudSystemDependencies = [
436 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200437 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200438 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100439 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100440 "openjdk/jdk-17/linux",
441 "openjdk/jdk-18/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100442 ],
443 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200444 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200445 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100446 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100447 "openjdk/jdk-17/osx",
448 "openjdk/jdk-18/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100449 ],
450 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200451 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100452 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100453 "openjdk/jdk-17/windows",
454 "openjdk/jdk-18/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100455 ],
456]
457
458if (OperatingSystem.current().isWindows()) {
459 cloudSystemDependencies.windows.each { entry ->
460 cloudDependencies.get(entry.key).addAll(entry.value)
461 }
462} else if (OperatingSystem.current().isLinux()) {
463 cloudSystemDependencies.linux.each { entry ->
464 cloudDependencies.get(entry.key).addAll(entry.value)
465 }
466} else if (OperatingSystem.current().isMacOsX()) {
467 cloudSystemDependencies.osx.each { entry ->
468 cloudDependencies.get(entry.key).addAll(entry.value)
469 }
470} else {
471 println "WARNING: Unsupported system: " + OperatingSystem.current()
472}
473
474def getDownloadDepsTaskName(entryKey, entryFile) {
475 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
476}
477
Mads Ager418d1ca2017-05-22 09:35:49 +0200478cloudDependencies.each { entry ->
479 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200480 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100481 type DownloadDependency.Type.GOOGLE_STORAGE
482 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200483 }
484 }
485}
486
487def x20Dependencies = [
488 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200489 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700490 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200491 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200492 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000493 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100494 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100495 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200496 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100497 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200498 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200499 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200500 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200501 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200502 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200503 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200504 "proguard/proguard_internal_159423826",
505 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200506 "proto",
507 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200508 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200509 "youtube/youtube.android_16.20",
510 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200511 ],
512]
513
514x20Dependencies.each { entry ->
515 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100516 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
517 type DownloadDependency.Type.X20
518 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200519 }
520 }
521}
522
Rico Wind897bb712017-05-23 10:44:29 +0200523task downloadProguard {
524 cloudDependencies.each { entry ->
525 entry.value.each { entryFile ->
526 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100527 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200528 }
529 }
530 }
531}
532
Rico Windf6c74ce2018-12-04 08:50:55 +0100533task downloadOpenJDKrt {
534 cloudDependencies.each { entry ->
535 entry.value.each { entryFile ->
536 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100537 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100538 }
539 }
540 }
541}
542
Tamas Kenez427205b2017-06-29 15:57:09 +0200543task downloadDx {
544 cloudDependencies.each { entry ->
545 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200546 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100547 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200548 }
549 }
550 }
551}
552
Tamas Kenez0e10c562017-06-08 10:00:34 +0200553task downloadAndroidCts {
554 cloudDependencies.each { entry ->
555 entry.value.each { entryFile ->
556 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100557 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200558 }
559 }
560 }
561}
562
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200563task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200564 cloudDependencies.each { entry ->
565 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100566 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200567 }
568 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200569}
570
571task downloadX20Deps() {
572 x20Dependencies.each { entry ->
573 entry.value.each { entryFile ->
574 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200575 }
576 }
577}
578
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200579task downloadDeps {
580 dependsOn downloadCloudDeps
581 if (!project.hasProperty('no_internal')) {
582 dependsOn downloadX20Deps
583 }
584}
585
Mads Ager418d1ca2017-05-22 09:35:49 +0200586allprojects {
587 sourceCompatibility = JavaVersion.VERSION_1_8
588 targetCompatibility = JavaVersion.VERSION_1_8
589}
590
Rico Wind266336c2019-02-25 10:11:38 +0100591// TODO(ricow): Remove debug prints
592println("NOTE: Current operating system: " + OperatingSystem.current())
593println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
594
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100595// Check if running with the JDK location from tools/jdk.py.
596if (OperatingSystem.current().isWindows()) {
597 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100598 compileJava.options.encoding = "UTF-8"
599 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100600} else {
601 def javaHomeOut = new StringBuilder()
602 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400603 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100604 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
605 def jdkHome = new File(javaHomeOut.toString().trim())
606 if (!jdkHome.exists()) {
607 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
608 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
609 println("WARNING: Gradle is running in a non-pinned Java"
610 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000611 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100612 } else {
613 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100614 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200615}
616
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200617compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200618
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100619sourceSets.configureEach { sourceSet ->
620 tasks.named(sourceSet.compileJavaTaskName).configure {
621 // Default disable errorprone (enabled and setup below).
622 options.errorprone.enabled = false
623 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100624 // Run all compilation tasks in a forked subprocess.
625 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100626 // Javac often runs out of stack space when compiling the tests.
627 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200628 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100629 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200630 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100631 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
632 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
633 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200634}
635
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100636def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
637 tasks.named(sourceSet).get().configure {
638 def jdkDir = "third_party/openjdk/${javaHome}/"
639 options.fork = true
640 options.forkOptions.jvmArgs = []
641 if (enablePreview) {
642 options.compilerArgs.add('--enable-preview')
643 }
644 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200645 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100646 options.forkOptions.javaHome = file(jdkDir + 'linux')
647 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200648 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400649 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
650 ? file(jdkDir + 'osx/Contents/Home')
651 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100652 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200653 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100654 options.forkOptions.javaHome = file(jdkDir + 'windows')
655 }
656 sourceCompatibility = compatibility
657 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200658 }
Ian Zernyd3020482019-04-25 07:05:04 +0200659}
660
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100661setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200662 sourceSets.main.compileJavaTaskName,
663 'jdk-11',
664 JavaVersion.VERSION_11,
665 false);
666
667setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100668 sourceSets.examplesJava9.compileJavaTaskName,
669 'openjdk-9.0.4',
670 JavaVersion.VERSION_1_9,
671 false)
672setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100673 sourceSets.examplesJava10.compileJavaTaskName,
674 'jdk-11',
675 JavaVersion.VERSION_1_10,
676 false)
677setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200678 sourceSets.main11.compileJavaTaskName,
679 'jdk-11',
680 JavaVersion.VERSION_11,
681 false)
682setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200683 sourceSets.main17.compileJavaTaskName,
684 'jdk-17',
685 JavaVersion.VERSION_17,
686 false)
687setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100688 sourceSets.examplesJava11.compileJavaTaskName,
689 'jdk-11',
690 JavaVersion.VERSION_11,
691 false)
692setJdkCompilationWithCompatibility(
693 sourceSets.examplesTestNGRunner.compileJavaTaskName,
694 'jdk-11',
695 JavaVersion.VERSION_11,
696 false)
697setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200698 sourceSets.examplesJava17.compileJavaTaskName,
699 'jdk-17',
700 JavaVersion.VERSION_17,
701 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100702setJdkCompilationWithCompatibility(
703 sourceSets.examplesJava18.compileJavaTaskName,
704 'jdk-18',
705 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
706 JavaVersion.VERSION_17,
707 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100708
Clément Bérac94b6202021-09-28 11:16:58 +0000709task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
710 from sourceSets.examplesTestNGRunner.compileClasspath
711 include "**/**.jar"
712 into file("$buildDir/test/jdk11Tests")
713}
714
715task compileTestNGRunner (type: JavaCompile) {
716 dependsOn provideJdk11TestsDependencies
Clément Béra98d5b602021-09-29 06:27:21 +0000717 destinationDir = file("$buildDir/classes/java/examplesTestNGRunner")
Clément Bérac94b6202021-09-28 11:16:58 +0000718 source = sourceSets.examplesTestNGRunner.allSource
719 classpath = sourceSets.examplesTestNGRunner.compileClasspath
720}
721
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100722if (!project.hasProperty('without_error_prone') &&
723 // Don't enable error prone on Java 8 as the plugin setup does not support it.
724 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200725 compileJava {
726 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100727 options.errorprone.enabled = true
728 options.errorprone.disableAllChecks = true
729 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
Christoffer Quist Adamsen7bed1092020-05-04 11:08:00 +0200730 options.errorprone.check('CollectionIncompatibleType', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100731 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
732 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
733 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
734 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
735 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
736 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
737 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
738 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
739 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
740 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
741 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
742 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
743 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
744 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
745 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
746 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
747 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
748 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200749 }
750}
751
Yohann Roussel7f47c032017-09-14 12:19:06 +0200752task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200753 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100754
Yohann Roussel7f47c032017-09-14 12:19:06 +0200755 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100756 def runtimeClasspath = configurations.findByName("runtimeClasspath")
757 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
758
Yohann Roussel7f47c032017-09-14 12:19:06 +0200759 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100760
Yohann Roussel7f47c032017-09-14 12:19:06 +0200761 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100762 def dependencies = []
763 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
764 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
765 dependencies.add("${identifier.group}:${identifier.module}")
766 }
767 def libraryLicenses = file('LIBRARY-LICENSE').text
768 dependencies.each {
769 if (!libraryLicenses.contains("- artifact: $it")) {
770 throw new GradleException("No license for $it in LIBRARY_LICENSE")
771 }
772 }
773
Yohann Roussel7f47c032017-09-14 12:19:06 +0200774 license.getParentFile().mkdirs()
775 license.createNewFile()
776 license.text = "This file lists all licenses for code distributed.\n"
777 license.text += "All non-library code has the following 3-Clause BSD license.\n"
778 license.text += "\n"
779 license.text += "\n"
780 license.text += file('LICENSE').text
781 license.text += "\n"
782 license.text += "\n"
783 license.text += "Summary of distributed libraries:\n"
784 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100785 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200786 license.text += "\n"
787 license.text += "\n"
788 license.text += "Licenses details:\n"
789 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
790 license.text += "\n"
791 license.text += "\n"
792 license.text += file.text
793 }
794 }
795}
796
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100797def repackageDepFile(file) {
798 if (file.getName().endsWith('.jar')) {
799 return zipTree(file).matching {
800 exclude '**/module-info.class'
801 exclude 'META-INF/maven/**'
802 exclude 'META-INF/LICENSE.txt'
803 exclude 'META-INF/MANIFEST.MF'
804 }
805 } else {
806 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700807 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200808}
809
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100810task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200811 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100812 dependsOn project.configurations.runtimeClasspath
813 project.configurations.runtimeClasspath.forEach {
814 from repackageDepFile(it)
815 }
816 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000817}
818
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100819task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200820 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100821 dependsOn project.configurations.testCompile
822 project.configurations.testCompile.forEach {
823 from repackageDepFile(it)
824 }
825 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200826}
827
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100828task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100829 // If this fails then remove all generated folders from
830 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200831 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100832 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000833}
834
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100835task repackageSources11(type: Jar) {
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200836 from sourceSets.main11.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100837 archiveFileName = 'sources_main_11.jar'
clementbera0bca05e2019-05-29 14:11:18 +0200838}
839
Clément Béraffc2d6a2022-08-02 13:03:04 +0200840task repackageSources17(type: Jar) {
841 from sourceSets.main17.output
842 archiveFileName = 'sources_main_17.jar'
843}
844
Søren Gjesse145d9e82022-05-24 08:12:13 +0200845def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100846 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200847 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100848 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200849 dependsOn files('LICENSE')
850 if (includeLibraryLicenses) {
851 from consolidatedLicense.outputs.files
852 } else {
853 from files('LICENSE')
854 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100855 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100856 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100857 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200858 if (includeSwissArmyKnife) {
859 manifest {
860 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
861 }
862 }
863 exclude "META-INF/*.kotlin_module"
864 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200865 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200866}
867
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200868def r8RelocateTask(r8Task, output) {
869 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
870 dependsOn r8WithDeps
871 dependsOn r8Task
872 outputs.file output
873 workingDir = projectDir
874 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200875 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200876 "relocator",
877 "--input",
878 r8Task.outputs.files[0],
879 "--output",
880 output,
881 "--map",
882 "com.google.common->com.android.tools.r8.com.google.common",
883 "--map",
884 "com.google.gson->com.android.tools.r8.com.google.gson",
885 "--map",
886 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
887 "--map",
888 "joptsimple->com.android.tools.r8.joptsimple",
889 "--map",
890 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
891 "--map",
892 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
893 "--map",
894 "kotlin->com.android.tools.r8.jetbrains.kotlin",
895 "--map",
896 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
897 "--map",
898 "org.jetbrains->com.android.tools.r8.org.jetbrains",
899 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200900 "org.intellij->com.android.tools.r8.org.intellij",
901 "--map",
902 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200903 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200904 }
905}
906
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200907task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200908 dependsOn repackageSources
909 dependsOn repackageDeps
910 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200911 def r8Task = r8CreateTask(
912 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100913 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200914 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200915 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200916 true)
917 dependsOn r8Task
918 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200919}
920
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200921task r8WithDeps11 {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200922 dependsOn repackageSources11
923 dependsOn repackageDeps
924 inputs.files ([repackageSources11.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200925 def r8Task = r8CreateTask(
926 'WithDeps11',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100927 'r8_with_deps_11.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200928 repackageSources11.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200929 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200930 true)
931 dependsOn r8Task
932 outputs.files r8Task.outputs.files
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100933}
934
Clément Béraffc2d6a2022-08-02 13:03:04 +0200935task r8WithDeps17 {
936 dependsOn repackageSources17
937 dependsOn repackageDeps
938 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
939 def r8Task = r8CreateTask(
940 'WithDeps17',
941 'r8_with_deps_17.jar',
942 repackageSources17.outputs.files + repackageDeps.outputs.files,
943 true,
944 true)
945 dependsOn r8Task
946 outputs.files r8Task.outputs.files
947}
948
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200949task r8WithRelocatedDeps {
950 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
951 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200952 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200953 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200954}
955
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200956task r8WithRelocatedDeps11 {
957 def output = "${buildDir}/libs/r8_with_relocated_deps_11.jar"
958 dependsOn r8RelocateTask(r8WithDeps11, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200959 inputs.files r8WithDeps11.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200960 outputs.file output
961}
962
Clément Béraffc2d6a2022-08-02 13:03:04 +0200963task r8WithRelocatedDeps17 {
964 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
965 dependsOn r8RelocateTask(r8WithDeps17, output)
966 inputs.files r8WithDeps17.outputs.files
967 outputs.file output
968}
969
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200970task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200971 dependsOn repackageSources
972 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200973 def r8Task = r8CreateTask(
974 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100975 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200976 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200977 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200978 true)
979 dependsOn r8Task
980 outputs.files r8Task.outputs.files
981}
982
983task r8(type: Copy) {
984 def r8Task = project.hasProperty("exclude_deps")
985 ? r8WithoutDeps : r8WithRelocatedDeps
986 dependsOn r8Task
987 from r8Task.outputs.files[0]
988 into file("${buildDir}/libs")
989 rename { String fileName -> "r8.jar" }
990 outputs.file "${buildDir}/libs/r8.jar"
991}
992
993task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200994 dependsOn repackageSources
995 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200996 def r8Task = r8CreateTask(
997 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100998 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200999 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +02001000 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001001 false)
1002 dependsOn r8Task
1003 outputs.files r8Task.outputs.files
1004}
1005
1006task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001007 dependsOn repackageSources
1008 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001009 def r8Task = r8CreateTask(
1010 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001011 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001012 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +02001013 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001014 false)
1015 dependsOn r8Task
1016 outputs.files r8Task.outputs.files
1017}
1018
1019task r8NoManifestWithRelocatedDeps {
1020 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
1021 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001022 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001023 outputs.file output
1024}
1025
1026task r8NoManifest(type: Copy) {
1027 def r8Task = project.hasProperty("exclude_deps")
1028 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
1029 dependsOn r8Task
1030 from r8Task.outputs.files[0]
1031 into file("${buildDir}/libs")
1032 rename { String fileName -> "r8_no_manifest.jar" }
1033 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +01001034}
1035
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001036def baseCompilerCommandLine(compiler, args = []) {
1037 // Execute r8 commands against a stable r8 with dependencies.
1038 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
1039 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
1040 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
1041}
1042
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001043def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001044 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001045 return baseCompilerCommandLine("r8", args)
1046}
1047
1048def baseD8CommandLine(args = []) {
1049 // Execute r8 commands against a stable r8 with dependencies.
1050 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001051}
1052
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001053def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
1054 def allArgs = [
1055 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001056 input,
1057 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001058 "--pg-map-output", output + ".map",
Ian Zerny3ac86842022-10-05 11:49:35 +02001059 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001060 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
1061 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001062}
1063
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001064def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
1065 def allArgs = [
1066 "--classfile",
1067 input,
1068 "--output", output,
1069 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
1070 ] + args + libs.collectMany { ["--lib", it] }
1071 return baseD8CommandLine(allArgs)
1072}
1073
Ian Zernycf8ef512022-05-04 14:54:16 +02001074def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001075 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001076 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001077 outputs.file output
1078 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001079 dependsOn r8WithRelocatedDeps
1080 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001081 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001082 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001083 "--r8jar", r8Task.outputs.files[0],
1084 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001085 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001086 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001087 + (libs.collectMany { ["--lib", it] })
1088 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001089 workingDir = projectDir
1090 }
1091}
1092
Clément Bérac8b2c152022-06-22 08:23:47 +02001093task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001094 from sourceSets.libraryDesugarConversions.output
1095 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001096 baseName 'library_desugar_conversions_raw'
1097 destinationDir file('build/tmp/desugaredlibrary')
1098}
1099
1100task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001101 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001102 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001103}
1104
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001105task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1106 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001107 from sourceSets.test.output
Ian Zernyfcd0adb2022-11-02 16:15:59 +01001108 from sourceSets.keepanno.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001109 // We only want to include tests that use R8 when generating keep rules for applymapping.
1110 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001111 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001112 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001113}
1114
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001115task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001116 dependsOn r8WithDeps
1117 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001118 def output = "$buildDir/libs/r8tests.jar"
1119 outputs.file output
1120 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001121 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001122 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001123 "relocator",
1124 "--input",
1125 testJarSources.outputs.files[0],
1126 "--output",
1127 output,
1128 "--map",
1129 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1130 ])
1131}
1132
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001133task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001134 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1135 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001136 dependsOn r8WithDeps
1137 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001138 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001139 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001140 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001141 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001142 r8WithDeps.outputs,
1143 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001144 repackageDeps.outputs,
1145 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001146 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001147 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001148 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001149 "tracereferences",
1150 "--keep-rules",
1151 "--allowobfuscation",
1152 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001153 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001154 "--lib",
1155 repackageDeps.outputs.files[0],
1156 "--lib",
1157 repackageTestDeps.outputs.files[0],
1158 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001159 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001160 "--source",
1161 testJar.outputs.files[0],
1162 "--output",
1163 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001164 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001165}
1166
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001167task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001168 dependsOn r8LibCreateTask(
1169 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001170 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001171 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001172 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001173 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001174 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001175 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001176}
1177
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001178task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001179 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001180 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001181 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001182 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001183 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001184 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001185 repackageDeps.outputs.files,
1186 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001187 ).dependsOn(repackageDeps)
1188 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001189 outputs.file r8LibExludeDepsPath
1190}
1191
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001192task R8Desugared(type: Exec) {
1193 dependsOn downloadOpenJDKrt
1194 dependsOn r8NoManifestWithRelocatedDeps
1195 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1196 commandLine d8CfCommandLine(
1197 r8NoManifestWithRelocatedDeps.outputs.files[0],
1198 r8DesugaredPath,
1199 ["--release"])
1200 workingDir = projectDir
1201 outputs.file r8DesugaredPath
1202}
1203
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001204task R8Retrace {
1205 dependsOn R8Lib
1206 dependsOn r8LibCreateTask(
1207 "Retrace",
1208 ["src/main/keep_retrace.txt"],
1209 R8Lib,
1210 r8RetracePath,
1211 ).dependsOn(R8Lib)
1212 outputs.file r8RetracePath
1213}
1214
1215task R8RetraceNoDeps {
1216 dependsOn R8LibNoDeps
1217 dependsOn r8LibCreateTask(
1218 "RetraceNoDeps",
1219 ["src/main/keep_retrace.txt"],
1220 R8LibNoDeps,
1221 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001222 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001223 repackageDeps.outputs.files,
1224 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001225 ).dependsOn(R8LibNoDeps)
1226 outputs.file r8RetraceExludeDepsPath
1227}
1228
Mads Ager418d1ca2017-05-22 09:35:49 +02001229task sourceJar(type: Jar, dependsOn: classes) {
1230 classifier = 'src'
1231 from sourceSets.main.allSource
1232}
1233
Mads Ager418d1ca2017-05-22 09:35:49 +02001234artifacts {
1235 archives sourceJar
1236}
1237
1238task createArtTests(type: Exec) {
1239 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001240 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001241 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001242 outputs.dir outputDir
1243 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001244 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001245 workingDir = projectDir
1246}
1247
Mads Ager418d1ca2017-05-22 09:35:49 +02001248compileTestJava {
1249 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001250}
1251
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001252task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1253 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001254 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001255 destinationDir file('build/libs')
1256}
1257
Ian Zerny923a0c12018-01-03 10:59:18 +01001258task buildR8ApiUsageSample(type: Jar) {
1259 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001260 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001261 destinationDir file('tests')
1262}
1263
Yohann Roussel548ae942018-01-05 11:13:28 +01001264task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001265 dependsOn buildR8ApiUsageSample
1266}
1267
Mads Ager418d1ca2017-05-22 09:35:49 +02001268task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001269 def resourcesDir = file("src/test/debugTestResources")
1270 def hostJar = "debug_test_resources.jar"
1271 task "compile_debugTestResources"(type: JavaCompile) {
1272 source = fileTree(dir: resourcesDir, include: '**/*.java')
1273 destinationDir = file("build/test/debugTestResources/classes")
1274 classpath = sourceSets.main.compileClasspath
1275 sourceCompatibility = JavaVersion.VERSION_1_7
1276 targetCompatibility = JavaVersion.VERSION_1_7
1277 options.compilerArgs += ["-g", "-Xlint:-options"]
1278 }
1279 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1280 archiveName = hostJar
1281 destinationDir = file("build/test/")
1282 from "build/test/debugTestResources/classes"
1283 include "**/*.class"
1284 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001285 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1286 def java8HostJar = "debug_test_resources_java8.jar"
1287 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1288 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1289 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1290 classpath = sourceSets.main.compileClasspath
1291 sourceCompatibility = JavaVersion.VERSION_1_8
1292 targetCompatibility = JavaVersion.VERSION_1_8
1293 options.compilerArgs += ["-g", "-Xlint:-options"]
1294 }
1295 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1296 archiveName = java8HostJar
1297 destinationDir = file("build/test/")
1298 from "build/test/debugTestResourcesJava8/classes"
1299 include "**/*.class"
1300 }
1301 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001302 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001303 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001304}
1305
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001306// Examples used by tests, where Android specific APIs are used.
1307task buildExampleAndroidApi(type: JavaCompile) {
1308 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1309 destinationDir = file("build/test/examplesAndroidApi/classes")
1310 classpath = files("third_party/android_jar/lib-v26/android.jar")
1311 sourceCompatibility = JavaVersion.VERSION_1_8
1312 targetCompatibility = JavaVersion.VERSION_1_8
1313}
1314
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001315task buildProtoGeneratedSources {
1316 def examplesProtoDir = file("src/test/examplesProto")
1317 examplesProtoDir.eachDir { dir ->
1318 def name = dir.getName()
1319 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1320 source = {
1321 file('third_party/proto').listFiles()
1322 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1323 .collect { zipTree(it) }
1324 }
1325 destinationDir = file("build/generated/test/proto/${name}_classes")
1326 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1327 sourceCompatibility = JavaVersion.VERSION_1_8
1328 targetCompatibility = JavaVersion.VERSION_1_8
1329 }
1330 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1331 archiveName = "${name}.jar"
1332 destinationDir = file("build/generated/test/proto")
1333 from "build/generated/test/proto/${name}_classes"
1334 include "/**/*.class"
1335 }
1336 dependsOn "jar_proto_generated_source_${name}"
1337 }
1338}
1339
1340task buildExamplesProto {
1341 def examplesProtoDir = file("src/test/examplesProto")
1342 def examplesProtoOutputDir = file("build/test/examplesProto");
1343 dependsOn buildProtoGeneratedSources
1344 task "compile_examples_proto"(type: JavaCompile) {
1345 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1346 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001347 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1348 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001349 sourceCompatibility = JavaVersion.VERSION_1_8
1350 targetCompatibility = JavaVersion.VERSION_1_8
1351 }
1352 examplesProtoDir.eachDir { dir ->
1353 def name = dir.getName()
1354 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1355 archiveName = "${name}.jar"
1356 destinationDir = examplesProtoOutputDir
1357 from "build/test/examplesProto/classes"
1358 include name + "/**/*.class"
1359 }
1360 dependsOn "jar_examples_proto_${name}"
1361 }
1362}
1363
Lars Bakc91e87e2017-08-18 08:53:10 +02001364// Proto lite generated code yields warnings when compiling with javac.
1365// We change the options passed to javac to ignore it.
1366compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1367
Søren Gjesse7320ce52018-05-07 15:45:22 +02001368
Mads Ager418d1ca2017-05-22 09:35:49 +02001369task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001370 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001371 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001372 def proguardScript
1373 if (OperatingSystem.current().isWindows()) {
1374 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1375 } else {
1376 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1377 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001378 task extractExamplesRuntime(type: Sync) {
1379 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001380 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001381 include "**/*.class"
1382 includeEmptyDirs false
1383 into "$buildDir/runtime/examples/"
1384 }
1385
Søren Gjesse7320ce52018-05-07 15:45:22 +02001386 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1387 from examplesDir
1388 exclude "**/*.java"
1389 exclude "**/keep-rules*.txt"
1390 into file("build/test/examples/classes")
1391 }
1392
1393 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001394 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001395 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001396 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001397 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001398 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001399 sourceCompatibility = JavaVersion.VERSION_1_7
1400 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001401 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1402 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001403 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1404 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001405 include "**/*.java"
1406 destinationDir = file("build/test/examples/classes_debuginfo_all")
1407 classpath = sourceSets.examples.compileClasspath
1408 sourceCompatibility = JavaVersion.VERSION_1_7
1409 targetCompatibility = JavaVersion.VERSION_1_7
1410 options.compilerArgs = ["-g", "-Xlint:none"]
1411 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001412 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1413 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001414 include "**/*.java"
1415 destinationDir = file("build/test/examples/classes_debuginfo_none")
1416 classpath = sourceSets.examples.compileClasspath
1417 sourceCompatibility = JavaVersion.VERSION_1_7
1418 targetCompatibility = JavaVersion.VERSION_1_7
1419 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001420 }
1421 examplesDir.eachDir { dir ->
1422 def name = dir.getName();
1423 def exampleOutputDir = file("build/test/examples");
1424 def jarName = "${name}.jar"
1425 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001426 dependsOn "jar_example_${name}_debuginfo_all"
1427 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001428 dependsOn "extractExamplesRuntime"
1429 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001430 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1431 def proguardConfigPath = "${dir}/proguard.cfg"
1432 if (new File(proguardConfigPath).exists()) {
1433 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1434 archiveName = "${name}_pre_proguard.jar"
1435 destinationDir = exampleOutputDir
1436 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001437 include name + "/**/*.class"
1438 with runtimeDependencies
1439 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001440 }
1441 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1442 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1443 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1444 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001445 inputs.files files(
1446 tasks.getByPath("pre_proguard_example_${name}"),
1447 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001448 // Enable these to get stdout and stderr redirected to files...
1449 // standardOutput = new FileOutputStream('proguard.stdout')
1450 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001451 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001452 " -outjars ${proguardJarPath}" +
1453 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001454 " -printmapping ${proguardMapPath}"
1455 if (OperatingSystem.current().isWindows()) {
1456 executable "${proguardScript}"
1457 args "${proguardArguments}"
1458 } else {
1459 executable "bash"
1460 args "-c", "${proguardScript} '${proguardArguments}'"
1461 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001462 outputs.file proguardJarPath
1463 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001464 // TODO: Consider performing distinct proguard compilations.
1465 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1466 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001467 into "${exampleOutputDir}"
1468 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001469 }
1470 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1471 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001472 into "${exampleOutputDir}"
1473 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001474 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001475 } else {
1476 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001477 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001478 destinationDir = exampleOutputDir
1479 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001480 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001481 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001482 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001483 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001484 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1485 archiveName = "${name}_debuginfo_all.jar"
1486 destinationDir = exampleOutputDir
1487 from "build/test/examples/classes_debuginfo_all"
1488 include name + "/**/*.class"
1489 with runtimeDependencies
1490 includeEmptyDirs false
1491 }
1492 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1493 archiveName = "${name}_debuginfo_none.jar"
1494 destinationDir = exampleOutputDir
1495 from "build/test/examples/classes_debuginfo_none"
1496 include name + "/**/*.class"
1497 with runtimeDependencies
1498 includeEmptyDirs false
1499 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001500 }
1501 }
1502}
1503
1504task buildExampleAndroidNJars {
1505 dependsOn downloadDeps
1506 def examplesDir = file("src/test/examplesAndroidN")
1507 task "compile_examplesAndroidN"(type: JavaCompile) {
1508 source = fileTree(dir: examplesDir, include: '**/*.java')
1509 destinationDir = file("build/test/examplesAndroidN/classes")
1510 classpath = sourceSets.main.compileClasspath
1511 sourceCompatibility = JavaVersion.VERSION_1_8
1512 targetCompatibility = JavaVersion.VERSION_1_8
1513 options.compilerArgs += ["-Xlint:-options"]
1514 }
1515 examplesDir.eachDir { dir ->
1516 def name = dir.getName();
1517 def exampleOutputDir = file("build/test/examplesAndroidN");
1518 def jarName = "${name}.jar"
1519 dependsOn "jar_examplesAndroidN_${name}"
1520 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1521 archiveName = jarName
1522 destinationDir = exampleOutputDir
1523 from "build/test/examplesAndroidN/classes"
1524 include "**/" + name + "/**/*.class"
1525 }
1526 }
1527}
1528
1529
1530task buildExampleAndroidOJars {
1531 dependsOn downloadDeps
1532 def examplesDir = file("src/test/examplesAndroidO")
1533 // NOTE: we want to enable a scenario when test needs to reference some
1534 // classes generated by legacy (1.6) Java compiler to test some specific
1535 // behaviour. To do so we compile all the java files located in sub-directory
1536 // called 'legacy' with Java 1.6, then compile the rest of the files with
1537 // Java 1.8 and a reference to previously generated 1.6 classes.
1538
1539 // Compiling all classes in dirs 'legacy' with old Java version.
1540 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1541 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1542 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1543 classpath = sourceSets.main.compileClasspath
1544 sourceCompatibility = JavaVersion.VERSION_1_6
1545 targetCompatibility = JavaVersion.VERSION_1_6
1546 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1547 }
1548 // Compiling the rest of the files as Java 1.8 code.
1549 task "compile_examplesAndroidO"(type: JavaCompile) {
1550 dependsOn "compile_examplesAndroidO_Legacy"
1551 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1552 destinationDir = file("build/test/examplesAndroidO/classes")
1553 classpath = sourceSets.main.compileClasspath
1554 classpath += files("build/test/examplesAndroidOLegacy/classes")
1555 sourceCompatibility = JavaVersion.VERSION_1_8
1556 targetCompatibility = JavaVersion.VERSION_1_8
1557 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1558 }
1559 examplesDir.eachDir { dir ->
1560 def name = dir.getName();
1561 def destinationDir = file("build/test/examplesAndroidO/classes");
1562 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1563 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1564 dependsOn: "compile_examplesAndroidO") {
1565 main = name + ".TestGenerator"
1566 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1567 args destinationDir
1568 }
1569 } else {
1570 task "generate_examplesAndroidO_${name}" () {}
1571 }
1572 }
1573 examplesDir.eachDir { dir ->
1574 def name = dir.getName();
1575 def exampleOutputDir = file("build/test/examplesAndroidO");
1576 def jarName = "${name}.jar"
1577 dependsOn "jar_examplesAndroidO_${name}"
1578 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1579 "generate_examplesAndroidO_${name}"]) {
1580 archiveName = jarName
1581 destinationDir = exampleOutputDir
1582 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1583 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1584 include "**/" + name + "/**/*.class"
1585 // Do not include generator into the test runtime jar, it is not useful.
1586 // Otherwise, shrinking will need ASM jars.
1587 exclude "**/TestGenerator*"
1588 }
1589 }
1590}
1591
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001592task buildExampleAndroidPJars {
1593 dependsOn downloadDeps
1594 def examplesDir = file("src/test/examplesAndroidP")
1595
1596 task "compile_examplesAndroidP"(type: JavaCompile) {
1597 source = fileTree(dir: examplesDir, include: '**/*.java')
1598 destinationDir = file("build/test/examplesAndroidP/classes")
1599 classpath = sourceSets.main.compileClasspath
1600 sourceCompatibility = JavaVersion.VERSION_1_8
1601 targetCompatibility = JavaVersion.VERSION_1_8
1602 options.compilerArgs += ["-Xlint:-options"]
1603 }
1604 examplesDir.eachDir { dir ->
1605 def name = dir.getName();
1606 def destinationDir = file("build/test/examplesAndroidP/classes");
1607 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1608 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1609 dependsOn: "compile_examplesAndroidP") {
1610 main = name + ".TestGenerator"
1611 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1612 args destinationDir
1613 }
1614 } else {
1615 task "generate_examplesAndroidP_${name}" () {}
1616 }
1617 }
1618 examplesDir.eachDir { dir ->
1619 def name = dir.getName();
1620 def exampleOutputDir = file("build/test/examplesAndroidP");
1621 def jarName = "${name}.jar"
1622 dependsOn "jar_examplesAndroidP_${name}"
1623 task "jar_examplesAndroidP_${name}"(type: Jar,
1624 dependsOn: ["compile_examplesAndroidP",
1625 "generate_examplesAndroidP_${name}"]) {
1626 archiveName = jarName
1627 destinationDir = exampleOutputDir
1628 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1629 include "**/" + name + "/**/*.class"
1630 // Do not include generator into the test runtime jar, it is not useful.
1631 // Otherwise, shrinking will need ASM jars.
1632 exclude "**/TestGenerator*"
1633 }
1634 }
1635}
1636
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001637def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1638 return tasks.create("buildExample${javaVersion}Jars") {
1639 def examplesDir = file("src/test/examples${javaVersion}")
1640 examplesDir.eachDir { dir ->
1641 def name = dir.getName();
1642 def exampleOutputDir = file("build/test/examples${javaVersion}");
1643 def jarName = "${name}.jar"
1644 dependsOn "jar_examples${javaVersion}_${name}"
1645 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1646 archiveName = jarName
1647 destinationDir = exampleOutputDir
1648 from sourceSet.output
1649 include "**/" + name + "/**/*.class"
1650 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001651 }
1652 }
1653}
1654
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001655buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1656buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1657buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001658buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjessed1e08992022-02-07 16:46:31 +01001659buildExampleJarsCreateTask("Java18", sourceSets.examplesJava18)
clementberad7ab1dd2019-04-16 16:05:00 +02001660
clementberaa92e3cd2019-07-12 14:13:22 +02001661task provideArtFrameworksDependencies {
1662 cloudDependencies.tools.forEach({ art ->
1663 if (art.contains("art")) {
1664 def taskName = art.replace('/','_')
1665 dependsOn "patch_${taskName}"
1666 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1667 from "tools/${art}/framework"
1668 include "**.jar"
1669 into file("tools/${art}/out/host/linux-x86/framework")
1670 }
1671 }
1672 })
1673}
1674
Sebastien Hertzd3313772018-01-16 14:12:37 +01001675task buildKotlinR8TestResources {
1676 def examplesDir = file("src/test/kotlinR8TestResources")
1677 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001678 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1679 def name = dir.getName()
1680 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001681 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001682 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001683 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001684 task "${taskName}Java"(type: JavaCompile) {
1685 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1686 destinationDir = file(javaOutput)
1687 classpath = sourceSets.main.compileClasspath
1688 sourceCompatibility = JavaVersion.VERSION_1_6
1689 targetCompatibility = JavaVersion.VERSION_1_6
1690 options.compilerArgs += ["-g", "-Xlint:-options"]
1691 }
1692 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1693 archiveName = javaOutputJarName
1694 destinationDir = file(javaOutputJarDir)
1695 from javaOutput
1696 include "**/*.class"
1697 }
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +01001698 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001699 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001700 }
1701}
1702
Mads Ager418d1ca2017-05-22 09:35:49 +02001703task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001704 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1705 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1706 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001707 } else if (!OperatingSystem.current().isLinux()) {
1708 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001709 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001710 return;
1711 }
1712 dependsOn buildDebugTestResourcesJars
1713 dependsOn buildExampleJars
1714 dependsOn buildExampleAndroidNJars
1715 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001716 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001717 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001718 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001719 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001720 dependsOn buildExampleJava17Jars
Søren Gjessed1e08992022-02-07 16:46:31 +01001721 dependsOn buildExampleJava18Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001722 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001723 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001724 def noDexTests = [
1725 "multidex",
1726 "multidex002",
1727 "multidex004",
1728 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001729 examplesDir.eachDir { dir ->
1730 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001731 if (!(name in noDexTests)) {
1732 dependsOn "dex_example_${name}"
1733 def exampleOutputDir = file("build/test/examples/" + name);
1734 def dexPath = file("${exampleOutputDir}")
1735 def debug = (name == "throwing")
1736 if (!dexPath.exists()) {
1737 dexPath.mkdirs()
1738 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001739 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001740 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1741 destination = dexPath
1742 debug = debug
1743 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001744 }
1745 }
1746}
1747
1748task buildSmali {
1749 def smaliDir = file("src/test/smali")
1750 smaliDir.eachDirRecurse() { dir ->
1751 def name = dir.getName();
1752 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1753 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1754 smaliOutputDir.mkdirs()
1755 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001756 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001757 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1758 def javaFiles = fileTree(dir: dir, include: '*.java')
1759 def destDir = smaliOutputDir;
1760 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1761 def intermediateFileName = "${name}-intermediate.dex";
1762 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1763 if (javaFiles.empty) {
1764 if (!smaliFiles.empty) {
1765 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001766 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001767 source = smaliFiles
1768 destination = destFile
1769 }
1770 }
1771 } else {
Rico Wind01c15c62021-04-22 17:30:41 +00001772 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001773 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001774 source = smaliFiles
1775 destination = intermediateFile
1776 }
1777 task "${taskName}_java"(type: JavaCompile) {
1778 source = javaFiles
1779 destinationDir destDir
1780 classpath = sourceSets.main.compileClasspath
1781 sourceCompatibility = JavaVersion.VERSION_1_7
1782 targetCompatibility = JavaVersion.VERSION_1_7
1783 options.compilerArgs += ["-Xlint:-options"]
1784 }
1785 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1786 archiveName = "Test.jar"
1787 destinationDir = destDir
1788 from fileTree(dir: destDir, include: 'Test.class')
1789 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001790 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001791 source = fileTree(dir: destDir, include: 'Test.jar')
1792 destination = destDir
1793 }
1794 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001795 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001796 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1797 destination = destFile
1798 }
1799 }
1800 }
1801}
1802
1803tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001804 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001805 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001806 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001807 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001808 if (userDefinedCoresPerFork) {
1809 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1810 } else {
1811 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001812 maxParallelForks = processors.intdiv(3) ?: 1
1813 // On low cpu count machines (bots) we under subscribe, so increase the count.
1814 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001815 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001816 }
Rico Wind73da9f12019-09-19 09:27:07 +02001817 }
Rico Windc56f21c2019-03-12 07:29:57 +01001818 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001819
Mads Ager418d1ca2017-05-22 09:35:49 +02001820 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001821 if (project.hasProperty('disable_assertions')) {
1822 enableAssertions = false
1823 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001824 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001825 if (project.hasProperty('test_xmx')) {
1826 maxHeapSize = project.property('test_xmx')
1827 } else {
1828 maxHeapSize = "4G"
1829 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001830}
1831
1832task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001833 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001834 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1835 // Exclude the classes containing java8
1836 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1837 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1838 includeEmptyDirs = false
1839}
1840
Ian Zerny74143162017-11-24 13:46:35 +01001841task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1842 def inFile = buildPreNJdwpTestsJar.archivePath
1843 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001844 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001845 outputs.file outFile
1846 if (OperatingSystem.current().isWindows()) {
1847 executable file("tools/windows/dx/bin/dx.bat")
1848 } else if (OperatingSystem.current().isMacOsX()) {
1849 executable file("tools/mac/dx/bin/dx");
1850 } else {
1851 executable file("tools/linux/dx/bin/dx");
1852 }
1853 args "--dex"
1854 args "--output=${outFile}"
1855 args inFile
1856}
1857
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001858task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1859 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001860}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001861
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001862task generateR8TestKeepRules {
1863 def path = "build/generated/r8tests-keep.txt"
1864 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001865 dependsOn R8Lib
1866 doLast {
1867 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001868-dontshrink
1869-dontoptimize
1870-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001871-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001872"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001873 }
1874}
1875
1876task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001877 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1878 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001879 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001880 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001881 dependsOn generateR8TestKeepRules
1882 dependsOn testJar
1883 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1884 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1885 return pkg.toString().endsWith(".jar")
1886 } + ["${buildDir}/classes/java/test"]
1887 inputs.files testJar.outputs.files +
1888 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001889 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001890 commandLine = r8CfCommandLine(
1891 testJar.outputs.files[0],
1892 outputPath,
1893 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001894 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1895 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001896 workingDir = projectDir
1897 outputs.file outputPath
1898}
1899
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001900task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001901 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001902 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001903 dependsOn R8Lib
1904 delete r8LibTestPath
1905 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1906 def examplesDir = file("build/test")
1907 examplesDir.eachDir { dir ->
1908 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001909 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001910 from ("${buildDir}/runtime/examples")
1911 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001912 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001913}
1914
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001915def shouldRetrace() {
1916 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1917}
1918
1919def retrace(Throwable exception) {
1920 def out = new StringBuffer()
1921 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001922 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001923 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001924 out.append("\n--------------------------------------\n")
1925 out.append("${header}\n")
1926 out.append("--------------------------------------\n")
1927 Process process = command.execute()
1928 def processIn = new PrintStream(process.getOut())
1929 process.consumeProcessOutput(out, err)
1930 exception.printStackTrace(processIn)
1931 processIn.flush()
1932 processIn.close()
1933 def errorDuringRetracing = process.waitFor() != 0
1934 if (errorDuringRetracing) {
1935 out.append("ERROR DURING RETRACING\n")
1936 out.append(err.toString())
1937 }
1938 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1939 out.append("\n\n--------------------------------------\n")
1940 out.append("OBFUSCATED STACKTRACE\n")
1941 out.append("--------------------------------------\n")
1942 }
1943 return out.toString()
1944}
1945
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001946def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001947 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001948 if (shouldRetrace()) {
1949 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001950 exception.setStackTrace([] as StackTraceElement[])
1951 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001952 }
1953}
1954
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001955def filterStackTraces(TestResult result) {
1956 for (Throwable throwable : result.getExceptions()) {
1957 filterStackTrace(throwable)
1958 }
1959}
1960
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001961// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001962def filterStackTrace(Throwable exception) {
1963 if (!project.hasProperty('print_full_stacktraces')) {
1964 def elements = []
1965 def skipped = []
1966 for (StackTraceElement element : exception.getStackTrace()) {
1967 if (element.toString().contains("com.android.tools.r8")) {
1968 elements.addAll(skipped)
1969 elements.add(element)
1970 skipped.clear()
1971 } else {
1972 skipped.add(element)
1973 }
1974 }
1975 exception.setStackTrace(elements as StackTraceElement[])
1976 }
1977}
1978
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001979def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1980 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1981 exceptions.forEach { it.printStackTrace(printer) }
1982 }
1983}
1984
Ian Zerny89f16cf2021-04-29 21:10:09 +02001985static def escapeHtml(String string) {
1986 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1987}
1988
1989static def urlEncode(String string) {
1990 // Not sure why, but the + also needs to be converted to have working links.
1991 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1992}
1993
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001994def ensureDir(File dir) {
1995 dir.mkdirs()
1996 return dir
1997}
1998
Ian Zerny89f16cf2021-04-29 21:10:09 +02001999// Some of our test parameters have new lines :-( We really don't want test names to span lines.
2000static def sanitizedTestName(testDesc) {
2001 if (testDesc.getName().contains("\n")) {
2002 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
2003 }
2004 return testDesc.getName()
2005}
2006
2007static def desanitizedTestName(testName) {
2008 return testName
2009}
2010
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002011def getTestReportEntryDir(reportDir, testDesc) {
2012 return ensureDir(reportDir.toPath()
2013 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02002014 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002015 .toFile())
2016}
2017
Ian Zerny89f16cf2021-04-29 21:10:09 +02002018def getTestReportEntryURL(reportDir, testDesc) {
2019 def classDir = urlEncode(testDesc.getClassName())
2020 def testDir = urlEncode(sanitizedTestName(testDesc))
2021 return "file://${reportDir}/${classDir}/${testDir}"
2022}
2023
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002024def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
2025 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
2026 return dir.resolve(fileName).toFile()
2027}
2028
Ian Zerny89f16cf2021-04-29 21:10:09 +02002029def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
2030 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
2031 new FileWriter(file, append).withCloseable fn
2032}
2033
Ian Zerny27ea4c72021-04-29 22:35:49 +02002034static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002035 def out = new StringBuilder()
2036 def err = new StringBuilder()
2037 def proc = "git rev-parse --abbrev-ref HEAD".execute()
2038 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02002039 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002040}
2041
Ian Zerny27ea4c72021-04-29 22:35:49 +02002042static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002043 def number = 0
2044 while (true) {
2045 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
2046 if (!freshIndex.exists()) {
2047 return freshIndex
2048 }
2049 }
2050}
2051
2052def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
2053 def out = new StringBuilder()
2054 def err = new StringBuilder()
2055 def proc = "find . -name ${fileName}".execute([], reportDir)
2056 proc.waitForProcessOutput(out, err)
2057 def outString = out.toString()
2058 outString.eachLine {
2059 // Lines are of the form: ./<class>/<name>/FAILURE
2060 def clazz = null
2061 def name = null
2062 try {
2063 def trimmed = it.trim()
2064 def line = trimmed.substring(2)
2065 def sep = line.indexOf("/")
2066 clazz = line.substring(0, sep)
2067 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
2068 } catch (Exception e) {
2069 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
2070 return
2071 }
2072 onTest(clazz, desanitizedTestName(name))
2073 }
2074 return !outString.trim().isEmpty()
2075}
2076
2077def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
2078 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
2079}
2080
2081def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
2082 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
2083}
2084
2085def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
2086 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
2087}
2088
Ian Zerny27ea4c72021-04-29 22:35:49 +02002089def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002090 // Hide all test events from the console, they are written to the report.
2091 task.testLogging { events = [] }
2092
Ian Zernycae764d2021-08-16 08:25:15 +02002093 def branch = project.hasProperty('testing-state-name')
2094 ? project.getProperty('testing-state-name')
2095 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002096 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02002097 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002098 def resetState = project.hasProperty('reset-testing-state')
2099 def reportDirExists = reportDir.exists()
2100 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02002101
2102 def hasFailingTests = false;
2103 if (resuming) {
2104 // Test filtering happens before the test execution is initiated so compute it here.
2105 // If there are still failing tests in the report, include only those.
2106 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
2107 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
2108 })
2109 // Otherwise exclude all of the test already marked as succeeding.
2110 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002111 // Also allow the test to overall succeed if there are no remaining tests that match,
2112 // which is natural if the state already succeeded in full.
2113 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02002114 forEachTestReportAlreadyPassing(reportDir, {
2115 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2116 })
2117 forEachTestReportAlreadySkipped(reportDir, {
2118 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2119 })
2120 }
2121 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002122
2123 task.beforeSuite { desc ->
2124 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002125 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02002126 if (resetState && reportDirExists) {
2127 delete reportDir
2128 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002129 if (resuming) {
2130 if (index.exists()) {
2131 parentReport = getFreshTestReportIndex(reportDir)
2132 index.renameTo(parentReport)
2133 }
2134 } else {
2135 reportDir.mkdirs()
2136 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002137 def runPrefix = resuming ? "Resuming" : "Starting"
2138 def title = "${runPrefix} @ ${branch}"
2139 // Print a console link to the test report for easy access.
2140 println "${runPrefix} test, report written to:"
2141 println " file://${index}"
2142 // Print the new index content.
2143 index << "<html><head><title>${title}</title>"
2144 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002145 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002146 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002147 index << "<p>Run on: ${new Date()}</p>"
2148 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002149 if (parentReport != null) {
2150 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
2151 }
2152 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
2153 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002154 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002155 }
2156 }
2157
2158 task.afterSuite { desc, result ->
2159 if (!desc.parent) {
2160 // Update the final test results in the index.
2161 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002162 if (result.resultType == TestResult.ResultType.SUCCESS) {
2163 if (hasFailingTests) {
2164 index << "<h2>Rerun of failed tests now pass!</h2>"
2165 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
2166 } else {
2167 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
2168 }
2169 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002170 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002171 } else {
2172 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
2173 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002174 index << "<li>Number of tests: ${result.testCount}"
2175 index << "<li>Failing tests: ${result.failedTestCount}"
2176 index << "<li>Successful tests: ${result.successfulTestCount}"
2177 index << "<li>Skipped tests: ${result.skippedTestCount}"
2178 index << "</ul></body></html>"
2179 }
2180 }
2181
2182 // Events to stdout/err are appended to the files in the test directories.
2183 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02002184 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
2185 it.append(event.getMessage())
2186 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002187 }
2188
Ian Zerny27ea4c72021-04-29 22:35:49 +02002189 task.beforeTest { desc ->
2190 // Remove any stale output files before running the test.
2191 for (def destType : TestOutputEvent.Destination.values()) {
2192 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
2193 if (destFile.exists()) {
2194 delete destFile
2195 }
2196 }
2197 }
2198
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002199 task.afterTest { desc, result ->
2200 if (result.getTestCount() != 1) {
2201 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
2202 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002203 // Clear any previous result files.
2204 for (def resultType : TestResult.ResultType.values()) {
2205 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
2206 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002207 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002208 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
2209 it.append(result.getResultType().name())
2210 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002211 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002212 withTestResultEntryWriter(reportDir, desc, "time", false, {
2213 it.append("${result.getEndTime() - result.getStartTime()}")
2214 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002215 // For failed tests, update the index and emit stack trace information.
2216 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002217 def title = escapeHtml("${desc.className}.${desc.name}")
2218 def link = getTestReportEntryURL(reportDir, desc)
2219 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002220 if (!result.exceptions.isEmpty()) {
2221 printAllStackTracesToFile(
2222 result.exceptions,
2223 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002224 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002225 desc,
2226 "exceptions-raw.txt"))
2227 filterStackTraces(result)
2228 printAllStackTracesToFile(
2229 result.exceptions,
2230 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002231 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002232 desc,
2233 "exceptions-filtered.txt"))
2234 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002235 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2236 result.exceptions.forEach { writer.append(retrace(it)) }
2237 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002238 }
2239 }
2240 }
2241 }
2242}
2243
Rico Windf2f4c292021-04-23 07:06:13 +02002244def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002245def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002246
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002247test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002248
2249 dependsOn buildLibraryDesugarConversions
2250 dependsOn getJarsFromSupportLibs
2251 // R8.jar is required for running bootstrap tests.
2252 dependsOn r8
2253
Ian Zerny27ea4c72021-04-29 22:35:49 +02002254 def useTestingState = project.hasProperty('testing-state')
2255 if (useTestingState) {
2256 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002257 }
2258
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002259 if (project.hasProperty('generate_golden_files_to')) {
2260 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2261 assert project.hasProperty('HEAD_sha1')
2262 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2263 }
2264
2265 if (project.hasProperty('use_golden_files_in')) {
2266 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2267 assert project.hasProperty('HEAD_sha1')
2268 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2269 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002270
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002271 if (project.hasProperty('kotlin_compiler_dev')) {
2272 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2273 }
2274
2275 if (project.hasProperty('kotlin_compiler_old')) {
2276 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2277 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002278
Ian Zerny27ea4c72021-04-29 22:35:49 +02002279 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002280 testLogging.exceptionFormat = 'full'
2281 if (project.hasProperty('print_test_stdout')) {
2282 testLogging.showStandardStreams = true
2283 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002284 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002285 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002286 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002287 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002288 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002289
Ian Zerny324d7612019-03-20 10:52:28 +01002290 // Forward runtime configurations for test parameters.
2291 if (project.hasProperty('runtimes')) {
2292 println "NOTE: Running with runtimes: " + project.property('runtimes')
2293 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002294 }
2295
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002296 if (project.hasProperty('slow_tests')) {
2297 systemProperty 'slow_tests', project.property('slow_tests')
2298 }
2299
Søren Gjesseef195772021-03-11 16:04:42 +01002300
2301 if (project.hasProperty('desugar_jdk_json_dir')) {
2302 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2303 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002304 if (project.hasProperty('desugar_jdk_libs')) {
2305 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2306 }
2307
Ian Zerny27ea4c72021-04-29 22:35:49 +02002308 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002309 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2310 afterTest { desc, result ->
2311 def executionTime = (result.endTime - result.startTime) / 1000
2312 testTimes["${desc.name} [${desc.className}]"] = executionTime
2313 }
2314 afterSuite { desc, result ->
2315 // parent is null if all tests are done.
2316 if (desc.parent == null) {
2317 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2318 sortedTimes.eachWithIndex { key, value, i ->
Rico Windf94f4302023-01-03 10:57:10 +01002319 println "$key: $value"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002320 }
2321 }
2322 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002323 }
Rico Windf2f4c292021-04-23 07:06:13 +02002324
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002325 if (project.hasProperty('one_line_per_test')) {
2326 beforeTest { desc ->
2327 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002328 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002329
2330 afterTest { desc, result ->
2331 if (result.resultType == TestResult.ResultType.FAILURE) {
2332 printStackTrace(result)
2333 }
2334 if (project.hasProperty('update_test_timestamp')) {
2335 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2336 }
2337 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002338 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002339 } else {
2340 afterTest { desc, result ->
2341 if (result.resultType == TestResult.ResultType.FAILURE) {
2342 printStackTrace(result)
2343 }
Rico Windf88b6be2018-12-11 15:14:05 +01002344 }
2345 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002346 }
2347 if (project.hasProperty('no_internal')) {
2348 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002349 } else {
2350 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002351 }
2352 if (project.hasProperty('only_internal')) {
2353 include "com/android/tools/r8/internal/**"
2354 }
Rico Wind4e218292019-03-07 12:44:49 +01002355
Rico Windba151112020-10-01 08:16:33 +02002356 if (project.hasProperty('test_namespace')) {
2357 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2358 }
2359
Ian Zerny3ced9262022-03-29 11:06:02 +02002360 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2361 // Don't run anything, deprecated
2362 println "Running with deprecated tool d8, not running any tests"
2363 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002364 }
2365 if (!project.hasProperty('all_tests')) {
2366 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002367 }
Rico Windbc820812022-05-31 09:19:56 +02002368 if (project.hasProperty('no_arttests')) {
2369 exclude "com/android/tools/r8/art/**"
2370 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002371 if (project.hasProperty('shard_count') ) {
2372 assert project.hasProperty('shard_number')
2373 int shard_count = project.getProperty('shard_count') as Integer
2374 int shard_number = project.getProperty('shard_number') as Integer
2375 assert shard_count < 65536
2376 assert shard_number < shard_count
2377 exclude {
2378 entry ->
2379 // Don't leave out directories. Leaving out a directory means all entries below.
2380 if (entry.file.isDirectory()) {
2381 return false
2382 }
2383 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2384 int hash = Integer.parseInt(first4, 16)
2385 return hash % shard_count != shard_number
2386 }
2387 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002388 if (project.hasProperty('test_dir')) {
2389 systemProperty 'test_dir', project.property('test_dir')
2390 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002391 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002392 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002393 // R8lib should be used instead of the main output and all the tests in
2394 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002395 classpath = sourceSets.test.runtimeClasspath.filter {
2396 !it.getAbsolutePath().contains("/build/")
2397 }
2398 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002399 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002400 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002401 if (OperatingSystem.current().isLinux()
2402 || OperatingSystem.current().isMacOsX()
2403 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002404 if (OperatingSystem.current().isMacOsX()) {
2405 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2406 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2407 "See tools/docker/README.md for details.")
2408 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002409 if (OperatingSystem.current().isWindows()) {
2410 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2411 "Art only runs on Linux and tests requiring Art will be skipped")
2412 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002413 dependsOn downloadDeps
2414 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002415 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002416 dependsOn buildSmali
Mads Ager418d1ca2017-05-22 09:35:49 +02002417 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002418 dependsOn buildPreNJdwpTestsDex
Clément Bérac94b6202021-09-28 11:16:58 +00002419 dependsOn compileTestNGRunner
clementberaa92e3cd2019-07-12 14:13:22 +02002420 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002421 } else {
2422 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002423 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002424 }
2425}
2426
2427// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2428//
2429// To build and upload a new set of the Art tests for use with R8 follow these steps:
2430//
2431// First of all an Android checkout is required. Currently it must be located
2432// in $HOME/android/master.
2433//
2434// TODO(ricow): simplify this
2435//
2436// Before: update the checked in art, see scripts/update-host-art.sh
2437//
2438// 1. Get an android checkout in $HOME/android/master and apply the patch from
2439// https://android-review.googlesource.com/#/c/294187/
2440//
2441// 2. run the following commands in the Android checkout directory:
2442//
2443// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002444// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2445// m desugar
2446// m -j30 test-art-host
2447// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2448//
2449// Without running the test.py command the classes.jar file used by desugar in
2450// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2451// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002452//
2453// 3. In the R8 project root directory, make sure we have a clean state before starting:
2454// tools/gradle.py downloadDeps
2455// tools/gradle.py clean
2456// rm -rf tests/art
2457//
2458// 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 +02002459// Make sure you have smali on your path, please use the build binary in the
2460// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2461// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2462// 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 +02002463// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2464// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002465//
Søren Gjesse34b77732017-07-07 13:56:21 +02002466// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002467//
2468// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2469// skippedTests with an explanation. Rerun from step 3.
2470//
2471// 5. Run the tests:
2472// tools/gradle.py clean
2473// tools/test.py
2474//
Søren Gjesse34b77732017-07-07 13:56:21 +02002475// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2476// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2477// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002478//
Søren Gjesse34b77732017-07-07 13:56:21 +02002479// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002480// cd tests
2481// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002482//
2483// 7. Update the manifest file describing the Android repo used:
2484// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002485
Mads Ager418d1ca2017-05-22 09:35:49 +02002486def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002487
2488def artTestDir = file("${androidCheckoutDir}/art/test")
2489
2490if (project.hasProperty('android_source')) {
2491 task buildArtTests {
2492 outputs.upToDateWhen { false }
2493 def toBeTriaged = [
2494 "903-hello-tagging",
2495 "904-object-allocation",
2496 "905-object-free",
2497 "906-iterate-heap",
2498 "907-get-loaded-classes",
2499 "908-gc-start-finish",
2500 "954-invoke-polymorphic-verifier",
2501 "955-methodhandles-smali",
2502 "596-monitor-inflation",
2503 ]
2504 def skippedTests = toBeTriaged + [
2505 // This test produces no jar.
2506 "000-nop",
2507 // This does not build, as it tests the error when the application exceeds more
2508 // than 65536 methods
2509 "089-many-methods",
2510 // Requires some jack beta jar
2511 "956-methodhandles",
2512 ]
2513
2514 def skippedTestsDx = [
2515 // Tests with custom build scripts, where javac is not passed the options
2516 // -source 1.7 -target 1.7.
2517 "462-checker-inlining-across-dex-files",
2518 "556-invoke-super",
2519 "569-checker-pattern-replacement",
2520 // These tests use jack even when --build-with-javac-dx is specified.
2521 "004-JniTest",
2522 "048-reflect-v8",
2523 "146-bad-interface",
2524 "563-checker-invoke-super",
2525 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2526 "604-hot-static-interface",
2527 "957-methodhandle-transforms",
2528 "958-methodhandle-emulated-stackframe",
2529 "959-invoke-polymorphic-accessors",
2530 "961-default-iface-resolution-gen",
2531 "962-iface-static",
2532 "963-default-range-smali",
2533 "964-default-iface-init-gen",
2534 "965-default-verify",
2535 "966-default-conflict",
2536 "967-default-ame",
2537 "968-default-partial-compile-gen",
2538 "969-iface-super",
2539 "970-iface-super-resolution-gen",
2540 "971-iface-super",
2541 // These tests does not build with --build-with-javac-dx
2542 "004-NativeAllocations", // Javac error
2543 "031-class-attributes",
2544 "138-duplicate-classes-check",
2545 "157-void-class", // Javac error
2546 "580-checker-string-factory-intrinsics",
2547 "612-jit-dex-cache",
2548 "613-inlining-dex-cache",
2549 "900-hello-plugin", // --experimental agents
2550 "901-hello-ti-agent", // --experimental agents
2551 "902-hello-transformation", // --experimental agents
2552 "909-attach-agent", // --experimental agents
2553 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2554 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2555 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2556 "960-default-smali", // --experimental default-methods
2557 // These tests force the build to use jack
2558 "953-invoke-polymorphic-compiler",
2559 "958-methodhandle-stackframe",
2560 ]
2561
2562 def artTestBuildDir = file("${projectDir}/tests/art")
2563
2564 if (androidCheckoutDir.exists()) {
2565 dependsOn downloadDeps
2566 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002567 artTestDir.eachDir { dir ->
2568 def name = dir.getName();
2569 def markerFile = dir.toPath().resolve("info.txt").toFile();
2570 if (markerFile.exists() && !(name in skippedTests)) {
2571 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002572 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002573 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002574 }
2575 }
2576 }
2577 doFirst {
2578 if (!androidCheckoutDir.exists()) {
2579 throw new InvalidUserDataException(
2580 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002581 }
2582 }
2583 doLast {
2584 copy {
2585 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2586 into file("${artTestBuildDir}/lib64")
2587 include 'lib*.so'
2588 }
2589 copy {
2590 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2591 into file("${artTestBuildDir}/lib64")
2592 include 'libart.so'
2593 include 'libbacktrace.so'
2594 include 'libbase.so'
2595 include 'libc++.so'
2596 include 'libcutils.so'
2597 include 'liblz4.so'
2598 include 'liblzma.so'
2599 include 'libnativebridge.so'
2600 include 'libnativeloader.so'
2601 include 'libsigchain.so'
2602 include 'libunwind.so'
2603 include 'libziparchive.so'
2604 }
2605 copy {
2606 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2607 into file("${artTestBuildDir}/lib")
2608 include 'lib*.so'
2609 }
2610 copy {
2611 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2612 into file("${artTestBuildDir}/lib")
2613 include 'libart.so'
2614 include 'libbacktrace.so'
2615 include 'libbase.so'
2616 include 'libc++.so'
2617 include 'libcutils.so'
2618 include 'liblz4.so'
2619 include 'liblzma.so'
2620 include 'libnativebridge.so'
2621 include 'libnativeloader.so'
2622 include 'libsigchain.so'
2623 include 'libunwind.so'
2624 include 'libziparchive.so'
2625 }
2626 }
2627 }
2628}
2629
Rico Windde2af6c2019-03-26 15:21:08 +01002630def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002631 def artTestDir = file("${androidCheckoutDir}/art/test")
2632 def artRunTestScript = file("${artTestDir}/run-test")
2633 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002634 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002635
Søren Gjesse34b77732017-07-07 13:56:21 +02002636 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002637 def buildTask = "build_art_test_dx_${name}"
2638 def sanitizeTask = "sanitize_art_test_dx_${name}"
2639 def copyCheckTask = "copy_check_art_test_dx_${name}"
2640 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002641
2642 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002643 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002644 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2645 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002646 task "$buildTask"(type: Exec) {
2647 outputs.upToDateWhen { false }
2648 inputs.file buildInputs
2649 executable "${artRunTestScript}"
2650 args "--host"
2651 args "--build-only"
2652 args "--build-with-javac-dx"
2653 args "--output-path", "${testDir}"
2654 args "${name}"
2655 environment DX: "${dxExecutable.absolutePath}"
2656 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2657 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2658 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002659 }
2660 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2661 outputs.upToDateWhen { false }
2662 executable "/bin/bash"
2663 args "-c"
2664 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2665 " ${testDir}/classes-ex ${testDir}/check"
2666 }
2667
2668 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002669 // Directory that contains smali files is either smali, or smali/art
2670 def smali_dir = file("${dir}/smali/art")
2671 if (smali_dir.exists()) {
2672 workingDir "${testDir}/smali/art"
2673 } else {
2674 workingDir "${testDir}/smali"
2675 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002676 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002677 // This is the command line options for smali prior to 2.2.1, where smali got a new
2678 // command line interface.
2679 args "-c", "smali a *.smali"
2680 // This is the command line options for smali 2.2.1 and later.
2681 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002682 }
2683
2684 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2685 def smali_dir = file("${dir}/smali")
2686 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002687 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002688 dependsOn smaliToDexTask
2689 }
2690 from("${artTestDir}/${name}") {
2691 include 'check'
2692 }
2693 into testDir
2694 }
2695
2696 return copyCheckTask
2697}
2698
2699task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002700 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002701 classpath = sourceSets.main.compileClasspath
2702 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002703 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002704 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002705 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002706 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002707 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002708 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002709 include '**/com/android/tools/r8/CompilationMode.java'
2710 include '**/com/android/tools/r8/D8.java'
2711 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002712 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2713 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002714 include '**/com/android/tools/r8/Diagnostic.java'
2715 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002716 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2717 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002718 include '**/com/android/tools/r8/ProgramConsumer.java'
2719 include '**/com/android/tools/r8/ProgramResource.java'
2720 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002721 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002722 include '**/com/android/tools/r8/ResourceException.java'
2723 include '**/com/android/tools/r8/StringConsumer.java'
2724 include '**/com/android/tools/r8/StringResource.java'
2725 include '**/com/android/tools/r8/Version.java'
2726 include '**/com/android/tools/r8/origin/*.java'
2727}
2728
2729task javadocR8(type: Javadoc) {
2730 title "R8 API"
2731 classpath = sourceSets.main.compileClasspath
2732 source = sourceSets.main.allJava
2733 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2734 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2735 include '**/com/android/tools/r8/BaseCommand.java'
2736 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2737 include '**/com/android/tools/r8/ClassFileConsumer.java'
2738 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2739 include '**/com/android/tools/r8/CompilationFailedException.java'
2740 include '**/com/android/tools/r8/CompilationMode.java'
2741 include '**/com/android/tools/r8/R8.java'
2742 include '**/com/android/tools/r8/R8Command.java'
2743 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2744 include '**/com/android/tools/r8/Diagnostic.java'
2745 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002746 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2747 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002748 include '**/com/android/tools/r8/ProgramConsumer.java'
2749 include '**/com/android/tools/r8/ProgramResource.java'
2750 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2751 include '**/com/android/tools/r8/Resource.java'
2752 include '**/com/android/tools/r8/ResourceException.java'
2753 include '**/com/android/tools/r8/StringConsumer.java'
2754 include '**/com/android/tools/r8/StringResource.java'
2755 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002756 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002757}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002758
2759task copyMavenDeps(type: Copy) {
2760 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002761 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002762 from configurations.testCompile into "$buildDir/deps"
2763}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002764
Rico Wind23a05112019-03-27 08:00:44 +01002765task printMavenDeps {
2766 // Only actually print to stdout when we are updating.
2767 if (project.hasProperty('updatemavendeps')) {
2768 for (Configuration config : configurations) {
2769 if (!config.isCanBeResolved()) {
2770 continue
2771 }
2772 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2773 it.selected.id
2774 }
2775 def result = dependencies.createArtifactResolutionQuery()
2776 .forComponents(componentIds)
2777 .withArtifacts(MavenModule, MavenPomArtifact)
2778 .execute()
2779 for (component in result.resolvedComponents) {
2780 component.getArtifacts(MavenPomArtifact).each {
2781 println "POM: ${it.file} ${component.id}"
2782 }
2783 }
2784 config.each {
2785 println "JAR: ${it}"
2786 }
2787 }
2788 }
2789}
Ian Zerny9713c032020-01-23 11:41:58 +01002790
2791allprojects {
2792 tasks.withType(Exec) {
2793 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002794 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002795 }
2796 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002797}