blob: 462e42532300886504579597b8a8d57f094fe4dc [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 Winde4aee2a2023-01-26 13:46:40 +0100345 "aapt2",
Rico Windf72fa152018-10-22 15:41:03 +0200346 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200347 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200348 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100349 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200350 "android_jar/lib-v19",
351 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100352 "android_jar/lib-v22",
353 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200354 "android_jar/lib-v24",
355 "android_jar/lib-v25",
356 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100357 "android_jar/lib-v27",
358 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200359 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200360 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100361 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100362 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100363 "android_jar/lib-v33",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200364 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200365 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200366 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200367 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200368 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200369 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100370 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200371 "dart-sdk",
372 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200373 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100374 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200375 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200376 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200377 "jacoco/0.8.2",
378 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200379 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100380 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200381 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200382 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200383 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200384 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200385 "kotlin/kotlin-compiler-1.3.11",
386 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200387 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100388 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200389 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100390 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200391 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen47efa232023-01-20 11:12:06 +0100392 "kotlin/kotlin-compiler-1.8.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200393 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200394 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100395 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200396 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000397 "openjdk/desugar_jdk_libs_11",
Ian Zernyc4598882022-02-25 19:26:44 +0100398 "openjdk/desugar_jdk_libs_legacy",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200399 "openjdk/desugar_jdk_libs_releases/1.0.9",
400 "openjdk/desugar_jdk_libs_releases/1.0.10",
401 "openjdk/desugar_jdk_libs_releases/1.1.0",
402 "openjdk/desugar_jdk_libs_releases/1.1.1",
403 "openjdk/desugar_jdk_libs_releases/1.1.5",
clementbera8dbfeda2019-07-03 11:24:13 +0200404 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100405 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200406 "proguard/proguard5.2.1",
407 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200408 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000409 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200410 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200411 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200412 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200413 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200414 "r8mappings",
415 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200416 ],
417 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
418 // container on other platforms where supported.
419 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200420 "linux/art",
421 "linux/art-5.1.1",
422 "linux/art-6.0.1",
423 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100424 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100425 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100426 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200427 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200428 "linux/host/art-13.0.0",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200429 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200430 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100431 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200432 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200433 ]
434]
435
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100436def cloudSystemDependencies = [
437 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200438 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200439 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100440 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100441 "openjdk/jdk-17/linux",
442 "openjdk/jdk-18/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100443 ],
444 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200445 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200446 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100447 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100448 "openjdk/jdk-17/osx",
449 "openjdk/jdk-18/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100450 ],
451 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200452 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100453 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100454 "openjdk/jdk-17/windows",
455 "openjdk/jdk-18/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100456 ],
457]
458
459if (OperatingSystem.current().isWindows()) {
460 cloudSystemDependencies.windows.each { entry ->
461 cloudDependencies.get(entry.key).addAll(entry.value)
462 }
463} else if (OperatingSystem.current().isLinux()) {
464 cloudSystemDependencies.linux.each { entry ->
465 cloudDependencies.get(entry.key).addAll(entry.value)
466 }
467} else if (OperatingSystem.current().isMacOsX()) {
468 cloudSystemDependencies.osx.each { entry ->
469 cloudDependencies.get(entry.key).addAll(entry.value)
470 }
471} else {
472 println "WARNING: Unsupported system: " + OperatingSystem.current()
473}
474
475def getDownloadDepsTaskName(entryKey, entryFile) {
476 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
477}
478
Mads Ager418d1ca2017-05-22 09:35:49 +0200479cloudDependencies.each { entry ->
480 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200481 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100482 type DownloadDependency.Type.GOOGLE_STORAGE
483 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200484 }
485 }
486}
487
488def x20Dependencies = [
489 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200490 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700491 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200492 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200493 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000494 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100495 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100496 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200497 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100498 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200499 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200500 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200501 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200502 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200503 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200504 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200505 "proguard/proguard_internal_159423826",
506 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200507 "proto",
508 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200509 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200510 "youtube/youtube.android_16.20",
511 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200512 ],
513]
514
515x20Dependencies.each { entry ->
516 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100517 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
518 type DownloadDependency.Type.X20
519 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200520 }
521 }
522}
523
Rico Wind897bb712017-05-23 10:44:29 +0200524task downloadProguard {
525 cloudDependencies.each { entry ->
526 entry.value.each { entryFile ->
527 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100528 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200529 }
530 }
531 }
532}
533
Rico Windf6c74ce2018-12-04 08:50:55 +0100534task downloadOpenJDKrt {
535 cloudDependencies.each { entry ->
536 entry.value.each { entryFile ->
537 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100538 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100539 }
540 }
541 }
542}
543
Tamas Kenez427205b2017-06-29 15:57:09 +0200544task downloadDx {
545 cloudDependencies.each { entry ->
546 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200547 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100548 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200549 }
550 }
551 }
552}
553
Tamas Kenez0e10c562017-06-08 10:00:34 +0200554task downloadAndroidCts {
555 cloudDependencies.each { entry ->
556 entry.value.each { entryFile ->
557 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100558 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200559 }
560 }
561 }
562}
563
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200564task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200565 cloudDependencies.each { entry ->
566 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100567 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200568 }
569 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200570}
571
572task downloadX20Deps() {
573 x20Dependencies.each { entry ->
574 entry.value.each { entryFile ->
575 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200576 }
577 }
578}
579
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200580task downloadDeps {
581 dependsOn downloadCloudDeps
582 if (!project.hasProperty('no_internal')) {
583 dependsOn downloadX20Deps
584 }
585}
586
Mads Ager418d1ca2017-05-22 09:35:49 +0200587allprojects {
588 sourceCompatibility = JavaVersion.VERSION_1_8
589 targetCompatibility = JavaVersion.VERSION_1_8
590}
591
Rico Wind266336c2019-02-25 10:11:38 +0100592// TODO(ricow): Remove debug prints
593println("NOTE: Current operating system: " + OperatingSystem.current())
594println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
595
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100596// Check if running with the JDK location from tools/jdk.py.
597if (OperatingSystem.current().isWindows()) {
598 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100599 compileJava.options.encoding = "UTF-8"
600 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100601} else {
602 def javaHomeOut = new StringBuilder()
603 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400604 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100605 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
606 def jdkHome = new File(javaHomeOut.toString().trim())
607 if (!jdkHome.exists()) {
608 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
609 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
610 println("WARNING: Gradle is running in a non-pinned Java"
611 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000612 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100613 } else {
614 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100615 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200616}
617
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200618compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200619
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100620sourceSets.configureEach { sourceSet ->
621 tasks.named(sourceSet.compileJavaTaskName).configure {
622 // Default disable errorprone (enabled and setup below).
623 options.errorprone.enabled = false
624 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100625 // Run all compilation tasks in a forked subprocess.
626 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100627 // Javac often runs out of stack space when compiling the tests.
628 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200629 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100630 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200631 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100632 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
633 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
634 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200635}
636
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100637def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
638 tasks.named(sourceSet).get().configure {
639 def jdkDir = "third_party/openjdk/${javaHome}/"
640 options.fork = true
641 options.forkOptions.jvmArgs = []
642 if (enablePreview) {
643 options.compilerArgs.add('--enable-preview')
644 }
645 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200646 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100647 options.forkOptions.javaHome = file(jdkDir + 'linux')
648 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200649 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400650 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
651 ? file(jdkDir + 'osx/Contents/Home')
652 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100653 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200654 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100655 options.forkOptions.javaHome = file(jdkDir + 'windows')
656 }
657 sourceCompatibility = compatibility
658 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200659 }
Ian Zernyd3020482019-04-25 07:05:04 +0200660}
661
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100662setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200663 sourceSets.main.compileJavaTaskName,
664 'jdk-11',
665 JavaVersion.VERSION_11,
666 false);
667
668setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100669 sourceSets.examplesJava9.compileJavaTaskName,
670 'openjdk-9.0.4',
671 JavaVersion.VERSION_1_9,
672 false)
673setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100674 sourceSets.examplesJava10.compileJavaTaskName,
675 'jdk-11',
676 JavaVersion.VERSION_1_10,
677 false)
678setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200679 sourceSets.main11.compileJavaTaskName,
680 'jdk-11',
681 JavaVersion.VERSION_11,
682 false)
683setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200684 sourceSets.main17.compileJavaTaskName,
685 'jdk-17',
686 JavaVersion.VERSION_17,
687 false)
688setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100689 sourceSets.examplesJava11.compileJavaTaskName,
690 'jdk-11',
691 JavaVersion.VERSION_11,
692 false)
693setJdkCompilationWithCompatibility(
694 sourceSets.examplesTestNGRunner.compileJavaTaskName,
695 'jdk-11',
696 JavaVersion.VERSION_11,
697 false)
698setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200699 sourceSets.examplesJava17.compileJavaTaskName,
700 'jdk-17',
701 JavaVersion.VERSION_17,
702 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100703setJdkCompilationWithCompatibility(
704 sourceSets.examplesJava18.compileJavaTaskName,
705 'jdk-18',
706 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
707 JavaVersion.VERSION_17,
708 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100709
Clément Bérac94b6202021-09-28 11:16:58 +0000710task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
711 from sourceSets.examplesTestNGRunner.compileClasspath
712 include "**/**.jar"
713 into file("$buildDir/test/jdk11Tests")
714}
715
716task compileTestNGRunner (type: JavaCompile) {
717 dependsOn provideJdk11TestsDependencies
Clément Béra98d5b602021-09-29 06:27:21 +0000718 destinationDir = file("$buildDir/classes/java/examplesTestNGRunner")
Clément Bérac94b6202021-09-28 11:16:58 +0000719 source = sourceSets.examplesTestNGRunner.allSource
720 classpath = sourceSets.examplesTestNGRunner.compileClasspath
721}
722
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100723if (!project.hasProperty('without_error_prone') &&
724 // Don't enable error prone on Java 8 as the plugin setup does not support it.
725 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200726 compileJava {
727 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100728 options.errorprone.enabled = true
729 options.errorprone.disableAllChecks = true
730 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
Christoffer Quist Adamsen7bed1092020-05-04 11:08:00 +0200731 options.errorprone.check('CollectionIncompatibleType', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100732 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
733 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
734 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
735 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
736 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
737 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
738 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
739 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
740 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
741 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
742 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
743 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
744 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
745 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
746 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
747 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
748 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
749 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200750 }
751}
752
Yohann Roussel7f47c032017-09-14 12:19:06 +0200753task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200754 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100755
Yohann Roussel7f47c032017-09-14 12:19:06 +0200756 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100757 def runtimeClasspath = configurations.findByName("runtimeClasspath")
758 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
759
Yohann Roussel7f47c032017-09-14 12:19:06 +0200760 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100761
Yohann Roussel7f47c032017-09-14 12:19:06 +0200762 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100763 def dependencies = []
764 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
765 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
766 dependencies.add("${identifier.group}:${identifier.module}")
767 }
768 def libraryLicenses = file('LIBRARY-LICENSE').text
769 dependencies.each {
770 if (!libraryLicenses.contains("- artifact: $it")) {
771 throw new GradleException("No license for $it in LIBRARY_LICENSE")
772 }
773 }
774
Yohann Roussel7f47c032017-09-14 12:19:06 +0200775 license.getParentFile().mkdirs()
776 license.createNewFile()
777 license.text = "This file lists all licenses for code distributed.\n"
778 license.text += "All non-library code has the following 3-Clause BSD license.\n"
779 license.text += "\n"
780 license.text += "\n"
781 license.text += file('LICENSE').text
782 license.text += "\n"
783 license.text += "\n"
784 license.text += "Summary of distributed libraries:\n"
785 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100786 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200787 license.text += "\n"
788 license.text += "\n"
789 license.text += "Licenses details:\n"
790 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
791 license.text += "\n"
792 license.text += "\n"
793 license.text += file.text
794 }
795 }
796}
797
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100798def repackageDepFile(file) {
799 if (file.getName().endsWith('.jar')) {
800 return zipTree(file).matching {
801 exclude '**/module-info.class'
802 exclude 'META-INF/maven/**'
803 exclude 'META-INF/LICENSE.txt'
804 exclude 'META-INF/MANIFEST.MF'
805 }
806 } else {
807 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700808 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200809}
810
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100811task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200812 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100813 dependsOn project.configurations.runtimeClasspath
814 project.configurations.runtimeClasspath.forEach {
815 from repackageDepFile(it)
816 }
817 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000818}
819
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100820task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200821 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100822 dependsOn project.configurations.testCompile
823 project.configurations.testCompile.forEach {
824 from repackageDepFile(it)
825 }
826 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200827}
828
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100829task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100830 // If this fails then remove all generated folders from
831 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200832 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100833 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000834}
835
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100836task repackageSources11(type: Jar) {
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200837 from sourceSets.main11.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100838 archiveFileName = 'sources_main_11.jar'
clementbera0bca05e2019-05-29 14:11:18 +0200839}
840
Clément Béraffc2d6a2022-08-02 13:03:04 +0200841task repackageSources17(type: Jar) {
842 from sourceSets.main17.output
843 archiveFileName = 'sources_main_17.jar'
844}
845
Søren Gjesse145d9e82022-05-24 08:12:13 +0200846def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100847 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200848 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100849 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200850 dependsOn files('LICENSE')
851 if (includeLibraryLicenses) {
852 from consolidatedLicense.outputs.files
853 } else {
854 from files('LICENSE')
855 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100856 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100857 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100858 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200859 if (includeSwissArmyKnife) {
860 manifest {
861 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
862 }
863 }
864 exclude "META-INF/*.kotlin_module"
865 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200866 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200867}
868
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200869def r8RelocateTask(r8Task, output) {
870 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
871 dependsOn r8WithDeps
872 dependsOn r8Task
873 outputs.file output
874 workingDir = projectDir
875 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200876 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200877 "relocator",
878 "--input",
879 r8Task.outputs.files[0],
880 "--output",
881 output,
882 "--map",
883 "com.google.common->com.android.tools.r8.com.google.common",
884 "--map",
885 "com.google.gson->com.android.tools.r8.com.google.gson",
886 "--map",
887 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
888 "--map",
889 "joptsimple->com.android.tools.r8.joptsimple",
890 "--map",
891 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
892 "--map",
893 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
894 "--map",
895 "kotlin->com.android.tools.r8.jetbrains.kotlin",
896 "--map",
897 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
898 "--map",
899 "org.jetbrains->com.android.tools.r8.org.jetbrains",
900 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200901 "org.intellij->com.android.tools.r8.org.intellij",
902 "--map",
903 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200904 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200905 }
906}
907
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200908task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200909 dependsOn repackageSources
910 dependsOn repackageDeps
911 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200912 def r8Task = r8CreateTask(
913 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100914 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200915 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200916 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200917 true)
918 dependsOn r8Task
919 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200920}
921
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200922task r8WithDeps11 {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200923 dependsOn repackageSources11
924 dependsOn repackageDeps
925 inputs.files ([repackageSources11.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200926 def r8Task = r8CreateTask(
927 'WithDeps11',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100928 'r8_with_deps_11.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200929 repackageSources11.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200930 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200931 true)
932 dependsOn r8Task
933 outputs.files r8Task.outputs.files
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100934}
935
Clément Béraffc2d6a2022-08-02 13:03:04 +0200936task r8WithDeps17 {
937 dependsOn repackageSources17
938 dependsOn repackageDeps
939 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
940 def r8Task = r8CreateTask(
941 'WithDeps17',
942 'r8_with_deps_17.jar',
943 repackageSources17.outputs.files + repackageDeps.outputs.files,
944 true,
945 true)
946 dependsOn r8Task
947 outputs.files r8Task.outputs.files
948}
949
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200950task r8WithRelocatedDeps {
951 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
952 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200953 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200954 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200955}
956
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200957task r8WithRelocatedDeps11 {
958 def output = "${buildDir}/libs/r8_with_relocated_deps_11.jar"
959 dependsOn r8RelocateTask(r8WithDeps11, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200960 inputs.files r8WithDeps11.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200961 outputs.file output
962}
963
Clément Béraffc2d6a2022-08-02 13:03:04 +0200964task r8WithRelocatedDeps17 {
965 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
966 dependsOn r8RelocateTask(r8WithDeps17, output)
967 inputs.files r8WithDeps17.outputs.files
968 outputs.file output
969}
970
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200971task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200972 dependsOn repackageSources
973 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200974 def r8Task = r8CreateTask(
975 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100976 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200977 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200978 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200979 true)
980 dependsOn r8Task
981 outputs.files r8Task.outputs.files
982}
983
984task r8(type: Copy) {
985 def r8Task = project.hasProperty("exclude_deps")
986 ? r8WithoutDeps : r8WithRelocatedDeps
987 dependsOn r8Task
988 from r8Task.outputs.files[0]
989 into file("${buildDir}/libs")
990 rename { String fileName -> "r8.jar" }
991 outputs.file "${buildDir}/libs/r8.jar"
992}
993
994task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200995 dependsOn repackageSources
996 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200997 def r8Task = r8CreateTask(
998 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100999 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001000 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +02001001 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001002 false)
1003 dependsOn r8Task
1004 outputs.files r8Task.outputs.files
1005}
1006
1007task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001008 dependsOn repackageSources
1009 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001010 def r8Task = r8CreateTask(
1011 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001012 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001013 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +02001014 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001015 false)
1016 dependsOn r8Task
1017 outputs.files r8Task.outputs.files
1018}
1019
1020task r8NoManifestWithRelocatedDeps {
1021 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
1022 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001023 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001024 outputs.file output
1025}
1026
1027task r8NoManifest(type: Copy) {
1028 def r8Task = project.hasProperty("exclude_deps")
1029 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
1030 dependsOn r8Task
1031 from r8Task.outputs.files[0]
1032 into file("${buildDir}/libs")
1033 rename { String fileName -> "r8_no_manifest.jar" }
1034 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +01001035}
1036
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001037def baseCompilerCommandLine(compiler, args = []) {
1038 // Execute r8 commands against a stable r8 with dependencies.
1039 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
1040 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
1041 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
1042}
1043
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001044def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001045 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001046 return baseCompilerCommandLine("r8", args)
1047}
1048
1049def baseD8CommandLine(args = []) {
1050 // Execute r8 commands against a stable r8 with dependencies.
1051 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001052}
1053
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001054def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
1055 def allArgs = [
1056 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001057 input,
1058 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001059 "--pg-map-output", output + ".map",
Ian Zerny3ac86842022-10-05 11:49:35 +02001060 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001061 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
1062 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001063}
1064
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001065def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
1066 def allArgs = [
1067 "--classfile",
1068 input,
1069 "--output", output,
1070 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
1071 ] + args + libs.collectMany { ["--lib", it] }
1072 return baseD8CommandLine(allArgs)
1073}
1074
Ian Zernycf8ef512022-05-04 14:54:16 +02001075def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001076 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001077 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001078 outputs.file output
1079 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001080 dependsOn r8WithRelocatedDeps
1081 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001082 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001083 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001084 "--r8jar", r8Task.outputs.files[0],
1085 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001086 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001087 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001088 + (libs.collectMany { ["--lib", it] })
1089 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001090 workingDir = projectDir
1091 }
1092}
1093
Clément Bérac8b2c152022-06-22 08:23:47 +02001094task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001095 from sourceSets.libraryDesugarConversions.output
1096 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001097 baseName 'library_desugar_conversions_raw'
1098 destinationDir file('build/tmp/desugaredlibrary')
1099}
1100
1101task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001102 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001103 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001104}
1105
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001106task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1107 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001108 from sourceSets.test.output
Ian Zernyfcd0adb2022-11-02 16:15:59 +01001109 from sourceSets.keepanno.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001110 // We only want to include tests that use R8 when generating keep rules for applymapping.
1111 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001112 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001113 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001114}
1115
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001116task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001117 dependsOn r8WithDeps
1118 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001119 def output = "$buildDir/libs/r8tests.jar"
1120 outputs.file output
1121 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001122 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001123 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001124 "relocator",
1125 "--input",
1126 testJarSources.outputs.files[0],
1127 "--output",
1128 output,
1129 "--map",
1130 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1131 ])
1132}
1133
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001134task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001135 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1136 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001137 dependsOn r8WithDeps
1138 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001139 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001140 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001141 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001142 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001143 r8WithDeps.outputs,
1144 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001145 repackageDeps.outputs,
1146 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001147 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001148 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001149 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001150 "tracereferences",
1151 "--keep-rules",
1152 "--allowobfuscation",
1153 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001154 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001155 "--lib",
1156 repackageDeps.outputs.files[0],
1157 "--lib",
1158 repackageTestDeps.outputs.files[0],
1159 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001160 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001161 "--source",
1162 testJar.outputs.files[0],
1163 "--output",
1164 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001165 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001166}
1167
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001168task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001169 dependsOn r8LibCreateTask(
1170 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001171 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001172 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001173 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001174 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001175 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001176 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001177}
1178
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001179task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001180 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001181 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001182 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001183 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001184 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001185 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001186 repackageDeps.outputs.files,
1187 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001188 ).dependsOn(repackageDeps)
1189 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001190 outputs.file r8LibExludeDepsPath
1191}
1192
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001193task R8Desugared(type: Exec) {
1194 dependsOn downloadOpenJDKrt
1195 dependsOn r8NoManifestWithRelocatedDeps
1196 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1197 commandLine d8CfCommandLine(
1198 r8NoManifestWithRelocatedDeps.outputs.files[0],
1199 r8DesugaredPath,
1200 ["--release"])
1201 workingDir = projectDir
1202 outputs.file r8DesugaredPath
1203}
1204
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001205task R8Retrace {
1206 dependsOn R8Lib
1207 dependsOn r8LibCreateTask(
1208 "Retrace",
1209 ["src/main/keep_retrace.txt"],
1210 R8Lib,
1211 r8RetracePath,
1212 ).dependsOn(R8Lib)
1213 outputs.file r8RetracePath
1214}
1215
1216task R8RetraceNoDeps {
1217 dependsOn R8LibNoDeps
1218 dependsOn r8LibCreateTask(
1219 "RetraceNoDeps",
1220 ["src/main/keep_retrace.txt"],
1221 R8LibNoDeps,
1222 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001223 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001224 repackageDeps.outputs.files,
1225 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001226 ).dependsOn(R8LibNoDeps)
1227 outputs.file r8RetraceExludeDepsPath
1228}
1229
Mads Ager418d1ca2017-05-22 09:35:49 +02001230task sourceJar(type: Jar, dependsOn: classes) {
1231 classifier = 'src'
1232 from sourceSets.main.allSource
1233}
1234
Mads Ager418d1ca2017-05-22 09:35:49 +02001235artifacts {
1236 archives sourceJar
1237}
1238
1239task createArtTests(type: Exec) {
1240 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001241 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001242 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001243 outputs.dir outputDir
1244 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001245 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001246 workingDir = projectDir
1247}
1248
Mads Ager418d1ca2017-05-22 09:35:49 +02001249compileTestJava {
1250 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001251}
1252
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001253task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1254 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001255 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001256 destinationDir file('build/libs')
1257}
1258
Ian Zerny923a0c12018-01-03 10:59:18 +01001259task buildR8ApiUsageSample(type: Jar) {
1260 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001261 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001262 destinationDir file('tests')
1263}
1264
Yohann Roussel548ae942018-01-05 11:13:28 +01001265task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001266 dependsOn buildR8ApiUsageSample
1267}
1268
Mads Ager418d1ca2017-05-22 09:35:49 +02001269task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001270 def resourcesDir = file("src/test/debugTestResources")
1271 def hostJar = "debug_test_resources.jar"
1272 task "compile_debugTestResources"(type: JavaCompile) {
1273 source = fileTree(dir: resourcesDir, include: '**/*.java')
1274 destinationDir = file("build/test/debugTestResources/classes")
1275 classpath = sourceSets.main.compileClasspath
1276 sourceCompatibility = JavaVersion.VERSION_1_7
1277 targetCompatibility = JavaVersion.VERSION_1_7
1278 options.compilerArgs += ["-g", "-Xlint:-options"]
1279 }
1280 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1281 archiveName = hostJar
1282 destinationDir = file("build/test/")
1283 from "build/test/debugTestResources/classes"
1284 include "**/*.class"
1285 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001286 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1287 def java8HostJar = "debug_test_resources_java8.jar"
1288 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1289 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1290 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1291 classpath = sourceSets.main.compileClasspath
1292 sourceCompatibility = JavaVersion.VERSION_1_8
1293 targetCompatibility = JavaVersion.VERSION_1_8
1294 options.compilerArgs += ["-g", "-Xlint:-options"]
1295 }
1296 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1297 archiveName = java8HostJar
1298 destinationDir = file("build/test/")
1299 from "build/test/debugTestResourcesJava8/classes"
1300 include "**/*.class"
1301 }
1302 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001303 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001304 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001305}
1306
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001307// Examples used by tests, where Android specific APIs are used.
1308task buildExampleAndroidApi(type: JavaCompile) {
1309 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1310 destinationDir = file("build/test/examplesAndroidApi/classes")
1311 classpath = files("third_party/android_jar/lib-v26/android.jar")
1312 sourceCompatibility = JavaVersion.VERSION_1_8
1313 targetCompatibility = JavaVersion.VERSION_1_8
1314}
1315
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001316task buildProtoGeneratedSources {
1317 def examplesProtoDir = file("src/test/examplesProto")
1318 examplesProtoDir.eachDir { dir ->
1319 def name = dir.getName()
1320 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1321 source = {
1322 file('third_party/proto').listFiles()
1323 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1324 .collect { zipTree(it) }
1325 }
1326 destinationDir = file("build/generated/test/proto/${name}_classes")
1327 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1328 sourceCompatibility = JavaVersion.VERSION_1_8
1329 targetCompatibility = JavaVersion.VERSION_1_8
1330 }
1331 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1332 archiveName = "${name}.jar"
1333 destinationDir = file("build/generated/test/proto")
1334 from "build/generated/test/proto/${name}_classes"
1335 include "/**/*.class"
1336 }
1337 dependsOn "jar_proto_generated_source_${name}"
1338 }
1339}
1340
1341task buildExamplesProto {
1342 def examplesProtoDir = file("src/test/examplesProto")
1343 def examplesProtoOutputDir = file("build/test/examplesProto");
1344 dependsOn buildProtoGeneratedSources
1345 task "compile_examples_proto"(type: JavaCompile) {
1346 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1347 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001348 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1349 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001350 sourceCompatibility = JavaVersion.VERSION_1_8
1351 targetCompatibility = JavaVersion.VERSION_1_8
1352 }
1353 examplesProtoDir.eachDir { dir ->
1354 def name = dir.getName()
1355 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1356 archiveName = "${name}.jar"
1357 destinationDir = examplesProtoOutputDir
1358 from "build/test/examplesProto/classes"
1359 include name + "/**/*.class"
1360 }
1361 dependsOn "jar_examples_proto_${name}"
1362 }
1363}
1364
Lars Bakc91e87e2017-08-18 08:53:10 +02001365// Proto lite generated code yields warnings when compiling with javac.
1366// We change the options passed to javac to ignore it.
1367compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1368
Søren Gjesse7320ce52018-05-07 15:45:22 +02001369
Mads Ager418d1ca2017-05-22 09:35:49 +02001370task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001371 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001372 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001373 def proguardScript
1374 if (OperatingSystem.current().isWindows()) {
1375 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1376 } else {
1377 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1378 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001379 task extractExamplesRuntime(type: Sync) {
1380 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001381 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001382 include "**/*.class"
1383 includeEmptyDirs false
1384 into "$buildDir/runtime/examples/"
1385 }
1386
Søren Gjesse7320ce52018-05-07 15:45:22 +02001387 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1388 from examplesDir
1389 exclude "**/*.java"
1390 exclude "**/keep-rules*.txt"
1391 into file("build/test/examples/classes")
1392 }
1393
1394 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001395 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001396 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001397 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001398 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001399 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001400 sourceCompatibility = JavaVersion.VERSION_1_7
1401 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001402 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1403 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001404 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1405 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001406 include "**/*.java"
1407 destinationDir = file("build/test/examples/classes_debuginfo_all")
1408 classpath = sourceSets.examples.compileClasspath
1409 sourceCompatibility = JavaVersion.VERSION_1_7
1410 targetCompatibility = JavaVersion.VERSION_1_7
1411 options.compilerArgs = ["-g", "-Xlint:none"]
1412 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001413 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1414 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001415 include "**/*.java"
1416 destinationDir = file("build/test/examples/classes_debuginfo_none")
1417 classpath = sourceSets.examples.compileClasspath
1418 sourceCompatibility = JavaVersion.VERSION_1_7
1419 targetCompatibility = JavaVersion.VERSION_1_7
1420 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001421 }
1422 examplesDir.eachDir { dir ->
1423 def name = dir.getName();
1424 def exampleOutputDir = file("build/test/examples");
1425 def jarName = "${name}.jar"
1426 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001427 dependsOn "jar_example_${name}_debuginfo_all"
1428 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001429 dependsOn "extractExamplesRuntime"
1430 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001431 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1432 def proguardConfigPath = "${dir}/proguard.cfg"
1433 if (new File(proguardConfigPath).exists()) {
1434 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1435 archiveName = "${name}_pre_proguard.jar"
1436 destinationDir = exampleOutputDir
1437 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001438 include name + "/**/*.class"
1439 with runtimeDependencies
1440 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001441 }
1442 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1443 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1444 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1445 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001446 inputs.files files(
1447 tasks.getByPath("pre_proguard_example_${name}"),
1448 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001449 // Enable these to get stdout and stderr redirected to files...
1450 // standardOutput = new FileOutputStream('proguard.stdout')
1451 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001452 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001453 " -outjars ${proguardJarPath}" +
1454 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001455 " -printmapping ${proguardMapPath}"
1456 if (OperatingSystem.current().isWindows()) {
1457 executable "${proguardScript}"
1458 args "${proguardArguments}"
1459 } else {
1460 executable "bash"
1461 args "-c", "${proguardScript} '${proguardArguments}'"
1462 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001463 outputs.file proguardJarPath
1464 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001465 // TODO: Consider performing distinct proguard compilations.
1466 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1467 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001468 into "${exampleOutputDir}"
1469 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001470 }
1471 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1472 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001473 into "${exampleOutputDir}"
1474 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001475 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001476 } else {
1477 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001478 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001479 destinationDir = exampleOutputDir
1480 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001481 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001482 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001483 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001484 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001485 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1486 archiveName = "${name}_debuginfo_all.jar"
1487 destinationDir = exampleOutputDir
1488 from "build/test/examples/classes_debuginfo_all"
1489 include name + "/**/*.class"
1490 with runtimeDependencies
1491 includeEmptyDirs false
1492 }
1493 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1494 archiveName = "${name}_debuginfo_none.jar"
1495 destinationDir = exampleOutputDir
1496 from "build/test/examples/classes_debuginfo_none"
1497 include name + "/**/*.class"
1498 with runtimeDependencies
1499 includeEmptyDirs false
1500 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001501 }
1502 }
1503}
1504
1505task buildExampleAndroidNJars {
1506 dependsOn downloadDeps
1507 def examplesDir = file("src/test/examplesAndroidN")
1508 task "compile_examplesAndroidN"(type: JavaCompile) {
1509 source = fileTree(dir: examplesDir, include: '**/*.java')
1510 destinationDir = file("build/test/examplesAndroidN/classes")
1511 classpath = sourceSets.main.compileClasspath
1512 sourceCompatibility = JavaVersion.VERSION_1_8
1513 targetCompatibility = JavaVersion.VERSION_1_8
1514 options.compilerArgs += ["-Xlint:-options"]
1515 }
1516 examplesDir.eachDir { dir ->
1517 def name = dir.getName();
1518 def exampleOutputDir = file("build/test/examplesAndroidN");
1519 def jarName = "${name}.jar"
1520 dependsOn "jar_examplesAndroidN_${name}"
1521 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1522 archiveName = jarName
1523 destinationDir = exampleOutputDir
1524 from "build/test/examplesAndroidN/classes"
1525 include "**/" + name + "/**/*.class"
1526 }
1527 }
1528}
1529
1530
1531task buildExampleAndroidOJars {
1532 dependsOn downloadDeps
1533 def examplesDir = file("src/test/examplesAndroidO")
1534 // NOTE: we want to enable a scenario when test needs to reference some
1535 // classes generated by legacy (1.6) Java compiler to test some specific
1536 // behaviour. To do so we compile all the java files located in sub-directory
1537 // called 'legacy' with Java 1.6, then compile the rest of the files with
1538 // Java 1.8 and a reference to previously generated 1.6 classes.
1539
1540 // Compiling all classes in dirs 'legacy' with old Java version.
1541 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1542 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1543 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1544 classpath = sourceSets.main.compileClasspath
1545 sourceCompatibility = JavaVersion.VERSION_1_6
1546 targetCompatibility = JavaVersion.VERSION_1_6
1547 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1548 }
1549 // Compiling the rest of the files as Java 1.8 code.
1550 task "compile_examplesAndroidO"(type: JavaCompile) {
1551 dependsOn "compile_examplesAndroidO_Legacy"
1552 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1553 destinationDir = file("build/test/examplesAndroidO/classes")
1554 classpath = sourceSets.main.compileClasspath
1555 classpath += files("build/test/examplesAndroidOLegacy/classes")
1556 sourceCompatibility = JavaVersion.VERSION_1_8
1557 targetCompatibility = JavaVersion.VERSION_1_8
1558 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1559 }
1560 examplesDir.eachDir { dir ->
1561 def name = dir.getName();
1562 def destinationDir = file("build/test/examplesAndroidO/classes");
1563 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1564 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1565 dependsOn: "compile_examplesAndroidO") {
1566 main = name + ".TestGenerator"
1567 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1568 args destinationDir
1569 }
1570 } else {
1571 task "generate_examplesAndroidO_${name}" () {}
1572 }
1573 }
1574 examplesDir.eachDir { dir ->
1575 def name = dir.getName();
1576 def exampleOutputDir = file("build/test/examplesAndroidO");
1577 def jarName = "${name}.jar"
1578 dependsOn "jar_examplesAndroidO_${name}"
1579 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1580 "generate_examplesAndroidO_${name}"]) {
1581 archiveName = jarName
1582 destinationDir = exampleOutputDir
1583 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1584 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1585 include "**/" + name + "/**/*.class"
1586 // Do not include generator into the test runtime jar, it is not useful.
1587 // Otherwise, shrinking will need ASM jars.
1588 exclude "**/TestGenerator*"
1589 }
1590 }
1591}
1592
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001593task buildExampleAndroidPJars {
1594 dependsOn downloadDeps
1595 def examplesDir = file("src/test/examplesAndroidP")
1596
1597 task "compile_examplesAndroidP"(type: JavaCompile) {
1598 source = fileTree(dir: examplesDir, include: '**/*.java')
1599 destinationDir = file("build/test/examplesAndroidP/classes")
1600 classpath = sourceSets.main.compileClasspath
1601 sourceCompatibility = JavaVersion.VERSION_1_8
1602 targetCompatibility = JavaVersion.VERSION_1_8
1603 options.compilerArgs += ["-Xlint:-options"]
1604 }
1605 examplesDir.eachDir { dir ->
1606 def name = dir.getName();
1607 def destinationDir = file("build/test/examplesAndroidP/classes");
1608 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1609 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1610 dependsOn: "compile_examplesAndroidP") {
1611 main = name + ".TestGenerator"
1612 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1613 args destinationDir
1614 }
1615 } else {
1616 task "generate_examplesAndroidP_${name}" () {}
1617 }
1618 }
1619 examplesDir.eachDir { dir ->
1620 def name = dir.getName();
1621 def exampleOutputDir = file("build/test/examplesAndroidP");
1622 def jarName = "${name}.jar"
1623 dependsOn "jar_examplesAndroidP_${name}"
1624 task "jar_examplesAndroidP_${name}"(type: Jar,
1625 dependsOn: ["compile_examplesAndroidP",
1626 "generate_examplesAndroidP_${name}"]) {
1627 archiveName = jarName
1628 destinationDir = exampleOutputDir
1629 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1630 include "**/" + name + "/**/*.class"
1631 // Do not include generator into the test runtime jar, it is not useful.
1632 // Otherwise, shrinking will need ASM jars.
1633 exclude "**/TestGenerator*"
1634 }
1635 }
1636}
1637
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001638def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1639 return tasks.create("buildExample${javaVersion}Jars") {
1640 def examplesDir = file("src/test/examples${javaVersion}")
1641 examplesDir.eachDir { dir ->
1642 def name = dir.getName();
1643 def exampleOutputDir = file("build/test/examples${javaVersion}");
1644 def jarName = "${name}.jar"
1645 dependsOn "jar_examples${javaVersion}_${name}"
1646 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1647 archiveName = jarName
1648 destinationDir = exampleOutputDir
1649 from sourceSet.output
1650 include "**/" + name + "/**/*.class"
1651 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001652 }
1653 }
1654}
1655
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001656buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1657buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1658buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001659buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjessed1e08992022-02-07 16:46:31 +01001660buildExampleJarsCreateTask("Java18", sourceSets.examplesJava18)
clementberad7ab1dd2019-04-16 16:05:00 +02001661
clementberaa92e3cd2019-07-12 14:13:22 +02001662task provideArtFrameworksDependencies {
1663 cloudDependencies.tools.forEach({ art ->
1664 if (art.contains("art")) {
1665 def taskName = art.replace('/','_')
1666 dependsOn "patch_${taskName}"
1667 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1668 from "tools/${art}/framework"
1669 include "**.jar"
1670 into file("tools/${art}/out/host/linux-x86/framework")
1671 }
1672 }
1673 })
1674}
1675
Sebastien Hertzd3313772018-01-16 14:12:37 +01001676task buildKotlinR8TestResources {
1677 def examplesDir = file("src/test/kotlinR8TestResources")
1678 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001679 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1680 def name = dir.getName()
1681 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001682 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001683 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001684 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001685 task "${taskName}Java"(type: JavaCompile) {
1686 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1687 destinationDir = file(javaOutput)
1688 classpath = sourceSets.main.compileClasspath
1689 sourceCompatibility = JavaVersion.VERSION_1_6
1690 targetCompatibility = JavaVersion.VERSION_1_6
1691 options.compilerArgs += ["-g", "-Xlint:-options"]
1692 }
1693 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1694 archiveName = javaOutputJarName
1695 destinationDir = file(javaOutputJarDir)
1696 from javaOutput
1697 include "**/*.class"
1698 }
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +01001699 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001700 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001701 }
1702}
1703
Mads Ager418d1ca2017-05-22 09:35:49 +02001704task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001705 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1706 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1707 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001708 } else if (!OperatingSystem.current().isLinux()) {
1709 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001710 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001711 return;
1712 }
1713 dependsOn buildDebugTestResourcesJars
1714 dependsOn buildExampleJars
1715 dependsOn buildExampleAndroidNJars
1716 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001717 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001718 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001719 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001720 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001721 dependsOn buildExampleJava17Jars
Søren Gjessed1e08992022-02-07 16:46:31 +01001722 dependsOn buildExampleJava18Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001723 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001724 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001725 def noDexTests = [
1726 "multidex",
1727 "multidex002",
1728 "multidex004",
1729 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001730 examplesDir.eachDir { dir ->
1731 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001732 if (!(name in noDexTests)) {
1733 dependsOn "dex_example_${name}"
1734 def exampleOutputDir = file("build/test/examples/" + name);
1735 def dexPath = file("${exampleOutputDir}")
1736 def debug = (name == "throwing")
1737 if (!dexPath.exists()) {
1738 dexPath.mkdirs()
1739 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001740 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001741 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1742 destination = dexPath
1743 debug = debug
1744 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001745 }
1746 }
1747}
1748
1749task buildSmali {
1750 def smaliDir = file("src/test/smali")
1751 smaliDir.eachDirRecurse() { dir ->
1752 def name = dir.getName();
1753 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1754 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1755 smaliOutputDir.mkdirs()
1756 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001757 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001758 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1759 def javaFiles = fileTree(dir: dir, include: '*.java')
1760 def destDir = smaliOutputDir;
1761 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1762 def intermediateFileName = "${name}-intermediate.dex";
1763 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1764 if (javaFiles.empty) {
1765 if (!smaliFiles.empty) {
1766 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001767 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001768 source = smaliFiles
1769 destination = destFile
1770 }
1771 }
1772 } else {
Rico Wind01c15c62021-04-22 17:30:41 +00001773 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001774 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001775 source = smaliFiles
1776 destination = intermediateFile
1777 }
1778 task "${taskName}_java"(type: JavaCompile) {
1779 source = javaFiles
1780 destinationDir destDir
1781 classpath = sourceSets.main.compileClasspath
1782 sourceCompatibility = JavaVersion.VERSION_1_7
1783 targetCompatibility = JavaVersion.VERSION_1_7
1784 options.compilerArgs += ["-Xlint:-options"]
1785 }
1786 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1787 archiveName = "Test.jar"
1788 destinationDir = destDir
1789 from fileTree(dir: destDir, include: 'Test.class')
1790 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001791 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001792 source = fileTree(dir: destDir, include: 'Test.jar')
1793 destination = destDir
1794 }
1795 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001796 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001797 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1798 destination = destFile
1799 }
1800 }
1801 }
1802}
1803
1804tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001805 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001806 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001807 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001808 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001809 if (userDefinedCoresPerFork) {
1810 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1811 } else {
1812 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001813 maxParallelForks = processors.intdiv(3) ?: 1
1814 // On low cpu count machines (bots) we under subscribe, so increase the count.
1815 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001816 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001817 }
Rico Wind73da9f12019-09-19 09:27:07 +02001818 }
Rico Windc56f21c2019-03-12 07:29:57 +01001819 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001820
Mads Ager418d1ca2017-05-22 09:35:49 +02001821 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001822 if (project.hasProperty('disable_assertions')) {
1823 enableAssertions = false
1824 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001825 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001826 if (project.hasProperty('test_xmx')) {
1827 maxHeapSize = project.property('test_xmx')
1828 } else {
1829 maxHeapSize = "4G"
1830 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001831}
1832
1833task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001834 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001835 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1836 // Exclude the classes containing java8
1837 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1838 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1839 includeEmptyDirs = false
1840}
1841
Ian Zerny74143162017-11-24 13:46:35 +01001842task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1843 def inFile = buildPreNJdwpTestsJar.archivePath
1844 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001845 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001846 outputs.file outFile
1847 if (OperatingSystem.current().isWindows()) {
1848 executable file("tools/windows/dx/bin/dx.bat")
1849 } else if (OperatingSystem.current().isMacOsX()) {
1850 executable file("tools/mac/dx/bin/dx");
1851 } else {
1852 executable file("tools/linux/dx/bin/dx");
1853 }
1854 args "--dex"
1855 args "--output=${outFile}"
1856 args inFile
1857}
1858
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001859task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1860 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001861}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001862
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001863task generateR8TestKeepRules {
1864 def path = "build/generated/r8tests-keep.txt"
1865 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001866 dependsOn R8Lib
1867 doLast {
1868 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001869-dontshrink
1870-dontoptimize
1871-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001872-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001873"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001874 }
1875}
1876
1877task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001878 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1879 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001880 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001881 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001882 dependsOn generateR8TestKeepRules
1883 dependsOn testJar
1884 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1885 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1886 return pkg.toString().endsWith(".jar")
1887 } + ["${buildDir}/classes/java/test"]
1888 inputs.files testJar.outputs.files +
1889 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001890 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001891 commandLine = r8CfCommandLine(
1892 testJar.outputs.files[0],
1893 outputPath,
1894 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001895 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1896 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001897 workingDir = projectDir
1898 outputs.file outputPath
1899}
1900
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001901task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001902 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001903 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001904 dependsOn R8Lib
1905 delete r8LibTestPath
1906 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1907 def examplesDir = file("build/test")
1908 examplesDir.eachDir { dir ->
1909 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001910 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001911 from ("${buildDir}/runtime/examples")
1912 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001913 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001914}
1915
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001916def shouldRetrace() {
1917 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1918}
1919
1920def retrace(Throwable exception) {
1921 def out = new StringBuffer()
1922 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001923 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001924 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001925 out.append("\n--------------------------------------\n")
1926 out.append("${header}\n")
1927 out.append("--------------------------------------\n")
1928 Process process = command.execute()
1929 def processIn = new PrintStream(process.getOut())
1930 process.consumeProcessOutput(out, err)
1931 exception.printStackTrace(processIn)
1932 processIn.flush()
1933 processIn.close()
1934 def errorDuringRetracing = process.waitFor() != 0
1935 if (errorDuringRetracing) {
1936 out.append("ERROR DURING RETRACING\n")
1937 out.append(err.toString())
1938 }
1939 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1940 out.append("\n\n--------------------------------------\n")
1941 out.append("OBFUSCATED STACKTRACE\n")
1942 out.append("--------------------------------------\n")
1943 }
1944 return out.toString()
1945}
1946
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001947def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001948 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001949 if (shouldRetrace()) {
1950 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001951 exception.setStackTrace([] as StackTraceElement[])
1952 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001953 }
1954}
1955
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001956def filterStackTraces(TestResult result) {
1957 for (Throwable throwable : result.getExceptions()) {
1958 filterStackTrace(throwable)
1959 }
1960}
1961
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001962// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001963def filterStackTrace(Throwable exception) {
1964 if (!project.hasProperty('print_full_stacktraces')) {
1965 def elements = []
1966 def skipped = []
1967 for (StackTraceElement element : exception.getStackTrace()) {
1968 if (element.toString().contains("com.android.tools.r8")) {
1969 elements.addAll(skipped)
1970 elements.add(element)
1971 skipped.clear()
1972 } else {
1973 skipped.add(element)
1974 }
1975 }
1976 exception.setStackTrace(elements as StackTraceElement[])
1977 }
1978}
1979
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001980def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1981 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1982 exceptions.forEach { it.printStackTrace(printer) }
1983 }
1984}
1985
Ian Zerny89f16cf2021-04-29 21:10:09 +02001986static def escapeHtml(String string) {
1987 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1988}
1989
1990static def urlEncode(String string) {
1991 // Not sure why, but the + also needs to be converted to have working links.
1992 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1993}
1994
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001995def ensureDir(File dir) {
1996 dir.mkdirs()
1997 return dir
1998}
1999
Ian Zerny89f16cf2021-04-29 21:10:09 +02002000// Some of our test parameters have new lines :-( We really don't want test names to span lines.
2001static def sanitizedTestName(testDesc) {
2002 if (testDesc.getName().contains("\n")) {
2003 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
2004 }
2005 return testDesc.getName()
2006}
2007
2008static def desanitizedTestName(testName) {
2009 return testName
2010}
2011
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002012def getTestReportEntryDir(reportDir, testDesc) {
2013 return ensureDir(reportDir.toPath()
2014 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02002015 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002016 .toFile())
2017}
2018
Ian Zerny89f16cf2021-04-29 21:10:09 +02002019def getTestReportEntryURL(reportDir, testDesc) {
2020 def classDir = urlEncode(testDesc.getClassName())
2021 def testDir = urlEncode(sanitizedTestName(testDesc))
2022 return "file://${reportDir}/${classDir}/${testDir}"
2023}
2024
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002025def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
2026 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
2027 return dir.resolve(fileName).toFile()
2028}
2029
Ian Zerny89f16cf2021-04-29 21:10:09 +02002030def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
2031 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
2032 new FileWriter(file, append).withCloseable fn
2033}
2034
Ian Zerny27ea4c72021-04-29 22:35:49 +02002035static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002036 def out = new StringBuilder()
2037 def err = new StringBuilder()
2038 def proc = "git rev-parse --abbrev-ref HEAD".execute()
2039 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02002040 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002041}
2042
Ian Zerny27ea4c72021-04-29 22:35:49 +02002043static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002044 def number = 0
2045 while (true) {
2046 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
2047 if (!freshIndex.exists()) {
2048 return freshIndex
2049 }
2050 }
2051}
2052
2053def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
2054 def out = new StringBuilder()
2055 def err = new StringBuilder()
2056 def proc = "find . -name ${fileName}".execute([], reportDir)
2057 proc.waitForProcessOutput(out, err)
2058 def outString = out.toString()
2059 outString.eachLine {
2060 // Lines are of the form: ./<class>/<name>/FAILURE
2061 def clazz = null
2062 def name = null
2063 try {
2064 def trimmed = it.trim()
2065 def line = trimmed.substring(2)
2066 def sep = line.indexOf("/")
2067 clazz = line.substring(0, sep)
2068 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
2069 } catch (Exception e) {
2070 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
2071 return
2072 }
2073 onTest(clazz, desanitizedTestName(name))
2074 }
2075 return !outString.trim().isEmpty()
2076}
2077
2078def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
2079 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
2080}
2081
2082def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
2083 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
2084}
2085
2086def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
2087 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
2088}
2089
Ian Zerny27ea4c72021-04-29 22:35:49 +02002090def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002091 // Hide all test events from the console, they are written to the report.
2092 task.testLogging { events = [] }
2093
Ian Zernycae764d2021-08-16 08:25:15 +02002094 def branch = project.hasProperty('testing-state-name')
2095 ? project.getProperty('testing-state-name')
2096 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002097 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02002098 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002099 def resetState = project.hasProperty('reset-testing-state')
2100 def reportDirExists = reportDir.exists()
2101 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02002102
2103 def hasFailingTests = false;
2104 if (resuming) {
2105 // Test filtering happens before the test execution is initiated so compute it here.
2106 // If there are still failing tests in the report, include only those.
2107 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
2108 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
2109 })
2110 // Otherwise exclude all of the test already marked as succeeding.
2111 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002112 // Also allow the test to overall succeed if there are no remaining tests that match,
2113 // which is natural if the state already succeeded in full.
2114 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02002115 forEachTestReportAlreadyPassing(reportDir, {
2116 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2117 })
2118 forEachTestReportAlreadySkipped(reportDir, {
2119 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2120 })
2121 }
2122 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002123
2124 task.beforeSuite { desc ->
2125 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002126 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02002127 if (resetState && reportDirExists) {
2128 delete reportDir
2129 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002130 if (resuming) {
2131 if (index.exists()) {
2132 parentReport = getFreshTestReportIndex(reportDir)
2133 index.renameTo(parentReport)
2134 }
2135 } else {
2136 reportDir.mkdirs()
2137 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002138 def runPrefix = resuming ? "Resuming" : "Starting"
2139 def title = "${runPrefix} @ ${branch}"
2140 // Print a console link to the test report for easy access.
2141 println "${runPrefix} test, report written to:"
2142 println " file://${index}"
2143 // Print the new index content.
2144 index << "<html><head><title>${title}</title>"
2145 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002146 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002147 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002148 index << "<p>Run on: ${new Date()}</p>"
2149 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002150 if (parentReport != null) {
2151 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
2152 }
2153 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
2154 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002155 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002156 }
2157 }
2158
2159 task.afterSuite { desc, result ->
2160 if (!desc.parent) {
2161 // Update the final test results in the index.
2162 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002163 if (result.resultType == TestResult.ResultType.SUCCESS) {
2164 if (hasFailingTests) {
2165 index << "<h2>Rerun of failed tests now pass!</h2>"
2166 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
2167 } else {
2168 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
2169 }
2170 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002171 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002172 } else {
2173 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
2174 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002175 index << "<li>Number of tests: ${result.testCount}"
2176 index << "<li>Failing tests: ${result.failedTestCount}"
2177 index << "<li>Successful tests: ${result.successfulTestCount}"
2178 index << "<li>Skipped tests: ${result.skippedTestCount}"
2179 index << "</ul></body></html>"
2180 }
2181 }
2182
2183 // Events to stdout/err are appended to the files in the test directories.
2184 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02002185 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
2186 it.append(event.getMessage())
2187 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002188 }
2189
Ian Zerny27ea4c72021-04-29 22:35:49 +02002190 task.beforeTest { desc ->
2191 // Remove any stale output files before running the test.
2192 for (def destType : TestOutputEvent.Destination.values()) {
2193 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
2194 if (destFile.exists()) {
2195 delete destFile
2196 }
2197 }
2198 }
2199
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002200 task.afterTest { desc, result ->
2201 if (result.getTestCount() != 1) {
2202 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
2203 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002204 // Clear any previous result files.
2205 for (def resultType : TestResult.ResultType.values()) {
2206 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
2207 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002208 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002209 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
2210 it.append(result.getResultType().name())
2211 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002212 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002213 withTestResultEntryWriter(reportDir, desc, "time", false, {
2214 it.append("${result.getEndTime() - result.getStartTime()}")
2215 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002216 // For failed tests, update the index and emit stack trace information.
2217 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002218 def title = escapeHtml("${desc.className}.${desc.name}")
2219 def link = getTestReportEntryURL(reportDir, desc)
2220 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002221 if (!result.exceptions.isEmpty()) {
2222 printAllStackTracesToFile(
2223 result.exceptions,
2224 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002225 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002226 desc,
2227 "exceptions-raw.txt"))
2228 filterStackTraces(result)
2229 printAllStackTracesToFile(
2230 result.exceptions,
2231 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002232 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002233 desc,
2234 "exceptions-filtered.txt"))
2235 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002236 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2237 result.exceptions.forEach { writer.append(retrace(it)) }
2238 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002239 }
2240 }
2241 }
2242 }
2243}
2244
Rico Windf2f4c292021-04-23 07:06:13 +02002245def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002246def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002247
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002248test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002249
2250 dependsOn buildLibraryDesugarConversions
2251 dependsOn getJarsFromSupportLibs
2252 // R8.jar is required for running bootstrap tests.
2253 dependsOn r8
2254
Ian Zerny27ea4c72021-04-29 22:35:49 +02002255 def useTestingState = project.hasProperty('testing-state')
2256 if (useTestingState) {
2257 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002258 }
2259
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002260 if (project.hasProperty('generate_golden_files_to')) {
2261 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2262 assert project.hasProperty('HEAD_sha1')
2263 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2264 }
2265
2266 if (project.hasProperty('use_golden_files_in')) {
2267 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2268 assert project.hasProperty('HEAD_sha1')
2269 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2270 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002271
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002272 if (project.hasProperty('kotlin_compiler_dev')) {
2273 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2274 }
2275
2276 if (project.hasProperty('kotlin_compiler_old')) {
2277 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2278 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002279
Ian Zerny27ea4c72021-04-29 22:35:49 +02002280 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002281 testLogging.exceptionFormat = 'full'
2282 if (project.hasProperty('print_test_stdout')) {
2283 testLogging.showStandardStreams = true
2284 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002285 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002286 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002287 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002288 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002289 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002290
Ian Zerny324d7612019-03-20 10:52:28 +01002291 // Forward runtime configurations for test parameters.
2292 if (project.hasProperty('runtimes')) {
2293 println "NOTE: Running with runtimes: " + project.property('runtimes')
2294 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002295 }
2296
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002297 if (project.hasProperty('slow_tests')) {
2298 systemProperty 'slow_tests', project.property('slow_tests')
2299 }
2300
Søren Gjesseef195772021-03-11 16:04:42 +01002301
2302 if (project.hasProperty('desugar_jdk_json_dir')) {
2303 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2304 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002305 if (project.hasProperty('desugar_jdk_libs')) {
2306 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2307 }
2308
Ian Zerny27ea4c72021-04-29 22:35:49 +02002309 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002310 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2311 afterTest { desc, result ->
2312 def executionTime = (result.endTime - result.startTime) / 1000
2313 testTimes["${desc.name} [${desc.className}]"] = executionTime
2314 }
2315 afterSuite { desc, result ->
2316 // parent is null if all tests are done.
2317 if (desc.parent == null) {
2318 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2319 sortedTimes.eachWithIndex { key, value, i ->
Rico Windf94f4302023-01-03 10:57:10 +01002320 println "$key: $value"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002321 }
2322 }
2323 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002324 }
Rico Windf2f4c292021-04-23 07:06:13 +02002325
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002326 if (project.hasProperty('one_line_per_test')) {
2327 beforeTest { desc ->
2328 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002329 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002330
2331 afterTest { desc, result ->
2332 if (result.resultType == TestResult.ResultType.FAILURE) {
2333 printStackTrace(result)
2334 }
2335 if (project.hasProperty('update_test_timestamp')) {
2336 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2337 }
2338 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002339 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002340 } else {
2341 afterTest { desc, result ->
2342 if (result.resultType == TestResult.ResultType.FAILURE) {
2343 printStackTrace(result)
2344 }
Rico Windf88b6be2018-12-11 15:14:05 +01002345 }
2346 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002347 }
2348 if (project.hasProperty('no_internal')) {
2349 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002350 } else {
2351 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002352 }
2353 if (project.hasProperty('only_internal')) {
2354 include "com/android/tools/r8/internal/**"
2355 }
Rico Wind4e218292019-03-07 12:44:49 +01002356
Rico Windba151112020-10-01 08:16:33 +02002357 if (project.hasProperty('test_namespace')) {
2358 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2359 }
2360
Ian Zerny3ced9262022-03-29 11:06:02 +02002361 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2362 // Don't run anything, deprecated
2363 println "Running with deprecated tool d8, not running any tests"
2364 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002365 }
2366 if (!project.hasProperty('all_tests')) {
2367 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002368 }
Rico Windbc820812022-05-31 09:19:56 +02002369 if (project.hasProperty('no_arttests')) {
2370 exclude "com/android/tools/r8/art/**"
2371 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002372 if (project.hasProperty('shard_count') ) {
2373 assert project.hasProperty('shard_number')
2374 int shard_count = project.getProperty('shard_count') as Integer
2375 int shard_number = project.getProperty('shard_number') as Integer
2376 assert shard_count < 65536
2377 assert shard_number < shard_count
2378 exclude {
2379 entry ->
2380 // Don't leave out directories. Leaving out a directory means all entries below.
2381 if (entry.file.isDirectory()) {
2382 return false
2383 }
2384 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2385 int hash = Integer.parseInt(first4, 16)
2386 return hash % shard_count != shard_number
2387 }
2388 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002389 if (project.hasProperty('test_dir')) {
2390 systemProperty 'test_dir', project.property('test_dir')
2391 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002392 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002393 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002394 // R8lib should be used instead of the main output and all the tests in
2395 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002396 classpath = sourceSets.test.runtimeClasspath.filter {
2397 !it.getAbsolutePath().contains("/build/")
2398 }
2399 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002400 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002401 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002402 if (OperatingSystem.current().isLinux()
2403 || OperatingSystem.current().isMacOsX()
2404 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002405 if (OperatingSystem.current().isMacOsX()) {
2406 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2407 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2408 "See tools/docker/README.md for details.")
2409 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002410 if (OperatingSystem.current().isWindows()) {
2411 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2412 "Art only runs on Linux and tests requiring Art will be skipped")
2413 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002414 dependsOn downloadDeps
2415 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002416 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002417 dependsOn buildSmali
Mads Ager418d1ca2017-05-22 09:35:49 +02002418 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002419 dependsOn buildPreNJdwpTestsDex
Clément Bérac94b6202021-09-28 11:16:58 +00002420 dependsOn compileTestNGRunner
clementberaa92e3cd2019-07-12 14:13:22 +02002421 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002422 } else {
2423 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002424 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002425 }
2426}
2427
2428// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2429//
2430// To build and upload a new set of the Art tests for use with R8 follow these steps:
2431//
2432// First of all an Android checkout is required. Currently it must be located
2433// in $HOME/android/master.
2434//
2435// TODO(ricow): simplify this
2436//
2437// Before: update the checked in art, see scripts/update-host-art.sh
2438//
2439// 1. Get an android checkout in $HOME/android/master and apply the patch from
2440// https://android-review.googlesource.com/#/c/294187/
2441//
2442// 2. run the following commands in the Android checkout directory:
2443//
2444// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002445// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2446// m desugar
2447// m -j30 test-art-host
2448// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2449//
2450// Without running the test.py command the classes.jar file used by desugar in
2451// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2452// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002453//
2454// 3. In the R8 project root directory, make sure we have a clean state before starting:
2455// tools/gradle.py downloadDeps
2456// tools/gradle.py clean
2457// rm -rf tests/art
2458//
2459// 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 +02002460// Make sure you have smali on your path, please use the build binary in the
2461// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2462// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2463// 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 +02002464// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2465// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002466//
Søren Gjesse34b77732017-07-07 13:56:21 +02002467// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002468//
2469// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2470// skippedTests with an explanation. Rerun from step 3.
2471//
2472// 5. Run the tests:
2473// tools/gradle.py clean
2474// tools/test.py
2475//
Søren Gjesse34b77732017-07-07 13:56:21 +02002476// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2477// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2478// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002479//
Søren Gjesse34b77732017-07-07 13:56:21 +02002480// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002481// cd tests
2482// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002483//
2484// 7. Update the manifest file describing the Android repo used:
2485// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002486
Mads Ager418d1ca2017-05-22 09:35:49 +02002487def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002488
2489def artTestDir = file("${androidCheckoutDir}/art/test")
2490
2491if (project.hasProperty('android_source')) {
2492 task buildArtTests {
2493 outputs.upToDateWhen { false }
2494 def toBeTriaged = [
2495 "903-hello-tagging",
2496 "904-object-allocation",
2497 "905-object-free",
2498 "906-iterate-heap",
2499 "907-get-loaded-classes",
2500 "908-gc-start-finish",
2501 "954-invoke-polymorphic-verifier",
2502 "955-methodhandles-smali",
2503 "596-monitor-inflation",
2504 ]
2505 def skippedTests = toBeTriaged + [
2506 // This test produces no jar.
2507 "000-nop",
2508 // This does not build, as it tests the error when the application exceeds more
2509 // than 65536 methods
2510 "089-many-methods",
2511 // Requires some jack beta jar
2512 "956-methodhandles",
2513 ]
2514
2515 def skippedTestsDx = [
2516 // Tests with custom build scripts, where javac is not passed the options
2517 // -source 1.7 -target 1.7.
2518 "462-checker-inlining-across-dex-files",
2519 "556-invoke-super",
2520 "569-checker-pattern-replacement",
2521 // These tests use jack even when --build-with-javac-dx is specified.
2522 "004-JniTest",
2523 "048-reflect-v8",
2524 "146-bad-interface",
2525 "563-checker-invoke-super",
2526 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2527 "604-hot-static-interface",
2528 "957-methodhandle-transforms",
2529 "958-methodhandle-emulated-stackframe",
2530 "959-invoke-polymorphic-accessors",
2531 "961-default-iface-resolution-gen",
2532 "962-iface-static",
2533 "963-default-range-smali",
2534 "964-default-iface-init-gen",
2535 "965-default-verify",
2536 "966-default-conflict",
2537 "967-default-ame",
2538 "968-default-partial-compile-gen",
2539 "969-iface-super",
2540 "970-iface-super-resolution-gen",
2541 "971-iface-super",
2542 // These tests does not build with --build-with-javac-dx
2543 "004-NativeAllocations", // Javac error
2544 "031-class-attributes",
2545 "138-duplicate-classes-check",
2546 "157-void-class", // Javac error
2547 "580-checker-string-factory-intrinsics",
2548 "612-jit-dex-cache",
2549 "613-inlining-dex-cache",
2550 "900-hello-plugin", // --experimental agents
2551 "901-hello-ti-agent", // --experimental agents
2552 "902-hello-transformation", // --experimental agents
2553 "909-attach-agent", // --experimental agents
2554 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2555 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2556 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2557 "960-default-smali", // --experimental default-methods
2558 // These tests force the build to use jack
2559 "953-invoke-polymorphic-compiler",
2560 "958-methodhandle-stackframe",
2561 ]
2562
2563 def artTestBuildDir = file("${projectDir}/tests/art")
2564
2565 if (androidCheckoutDir.exists()) {
2566 dependsOn downloadDeps
2567 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002568 artTestDir.eachDir { dir ->
2569 def name = dir.getName();
2570 def markerFile = dir.toPath().resolve("info.txt").toFile();
2571 if (markerFile.exists() && !(name in skippedTests)) {
2572 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002573 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002574 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002575 }
2576 }
2577 }
2578 doFirst {
2579 if (!androidCheckoutDir.exists()) {
2580 throw new InvalidUserDataException(
2581 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002582 }
2583 }
2584 doLast {
2585 copy {
2586 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2587 into file("${artTestBuildDir}/lib64")
2588 include 'lib*.so'
2589 }
2590 copy {
2591 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2592 into file("${artTestBuildDir}/lib64")
2593 include 'libart.so'
2594 include 'libbacktrace.so'
2595 include 'libbase.so'
2596 include 'libc++.so'
2597 include 'libcutils.so'
2598 include 'liblz4.so'
2599 include 'liblzma.so'
2600 include 'libnativebridge.so'
2601 include 'libnativeloader.so'
2602 include 'libsigchain.so'
2603 include 'libunwind.so'
2604 include 'libziparchive.so'
2605 }
2606 copy {
2607 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2608 into file("${artTestBuildDir}/lib")
2609 include 'lib*.so'
2610 }
2611 copy {
2612 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2613 into file("${artTestBuildDir}/lib")
2614 include 'libart.so'
2615 include 'libbacktrace.so'
2616 include 'libbase.so'
2617 include 'libc++.so'
2618 include 'libcutils.so'
2619 include 'liblz4.so'
2620 include 'liblzma.so'
2621 include 'libnativebridge.so'
2622 include 'libnativeloader.so'
2623 include 'libsigchain.so'
2624 include 'libunwind.so'
2625 include 'libziparchive.so'
2626 }
2627 }
2628 }
2629}
2630
Rico Windde2af6c2019-03-26 15:21:08 +01002631def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002632 def artTestDir = file("${androidCheckoutDir}/art/test")
2633 def artRunTestScript = file("${artTestDir}/run-test")
2634 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002635 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002636
Søren Gjesse34b77732017-07-07 13:56:21 +02002637 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002638 def buildTask = "build_art_test_dx_${name}"
2639 def sanitizeTask = "sanitize_art_test_dx_${name}"
2640 def copyCheckTask = "copy_check_art_test_dx_${name}"
2641 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002642
2643 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002644 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002645 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2646 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002647 task "$buildTask"(type: Exec) {
2648 outputs.upToDateWhen { false }
2649 inputs.file buildInputs
2650 executable "${artRunTestScript}"
2651 args "--host"
2652 args "--build-only"
2653 args "--build-with-javac-dx"
2654 args "--output-path", "${testDir}"
2655 args "${name}"
2656 environment DX: "${dxExecutable.absolutePath}"
2657 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2658 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2659 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002660 }
2661 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2662 outputs.upToDateWhen { false }
2663 executable "/bin/bash"
2664 args "-c"
2665 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2666 " ${testDir}/classes-ex ${testDir}/check"
2667 }
2668
2669 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002670 // Directory that contains smali files is either smali, or smali/art
2671 def smali_dir = file("${dir}/smali/art")
2672 if (smali_dir.exists()) {
2673 workingDir "${testDir}/smali/art"
2674 } else {
2675 workingDir "${testDir}/smali"
2676 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002677 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002678 // This is the command line options for smali prior to 2.2.1, where smali got a new
2679 // command line interface.
2680 args "-c", "smali a *.smali"
2681 // This is the command line options for smali 2.2.1 and later.
2682 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002683 }
2684
2685 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2686 def smali_dir = file("${dir}/smali")
2687 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002688 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002689 dependsOn smaliToDexTask
2690 }
2691 from("${artTestDir}/${name}") {
2692 include 'check'
2693 }
2694 into testDir
2695 }
2696
2697 return copyCheckTask
2698}
2699
2700task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002701 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002702 classpath = sourceSets.main.compileClasspath
2703 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002704 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002705 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002706 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002707 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002708 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002709 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002710 include '**/com/android/tools/r8/CompilationMode.java'
2711 include '**/com/android/tools/r8/D8.java'
2712 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002713 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2714 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002715 include '**/com/android/tools/r8/Diagnostic.java'
2716 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002717 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2718 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002719 include '**/com/android/tools/r8/ProgramConsumer.java'
2720 include '**/com/android/tools/r8/ProgramResource.java'
2721 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002722 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002723 include '**/com/android/tools/r8/ResourceException.java'
2724 include '**/com/android/tools/r8/StringConsumer.java'
2725 include '**/com/android/tools/r8/StringResource.java'
2726 include '**/com/android/tools/r8/Version.java'
2727 include '**/com/android/tools/r8/origin/*.java'
2728}
2729
2730task javadocR8(type: Javadoc) {
2731 title "R8 API"
2732 classpath = sourceSets.main.compileClasspath
2733 source = sourceSets.main.allJava
2734 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2735 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2736 include '**/com/android/tools/r8/BaseCommand.java'
2737 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2738 include '**/com/android/tools/r8/ClassFileConsumer.java'
2739 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2740 include '**/com/android/tools/r8/CompilationFailedException.java'
2741 include '**/com/android/tools/r8/CompilationMode.java'
2742 include '**/com/android/tools/r8/R8.java'
2743 include '**/com/android/tools/r8/R8Command.java'
2744 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2745 include '**/com/android/tools/r8/Diagnostic.java'
2746 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002747 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2748 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002749 include '**/com/android/tools/r8/ProgramConsumer.java'
2750 include '**/com/android/tools/r8/ProgramResource.java'
2751 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2752 include '**/com/android/tools/r8/Resource.java'
2753 include '**/com/android/tools/r8/ResourceException.java'
2754 include '**/com/android/tools/r8/StringConsumer.java'
2755 include '**/com/android/tools/r8/StringResource.java'
2756 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002757 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002758}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002759
2760task copyMavenDeps(type: Copy) {
2761 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002762 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002763 from configurations.testCompile into "$buildDir/deps"
2764}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002765
Rico Wind23a05112019-03-27 08:00:44 +01002766task printMavenDeps {
2767 // Only actually print to stdout when we are updating.
2768 if (project.hasProperty('updatemavendeps')) {
2769 for (Configuration config : configurations) {
2770 if (!config.isCanBeResolved()) {
2771 continue
2772 }
2773 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2774 it.selected.id
2775 }
2776 def result = dependencies.createArtifactResolutionQuery()
2777 .forComponents(componentIds)
2778 .withArtifacts(MavenModule, MavenPomArtifact)
2779 .execute()
2780 for (component in result.resolvedComponents) {
2781 component.getArtifacts(MavenPomArtifact).each {
2782 println "POM: ${it.file} ${component.id}"
2783 }
2784 }
2785 config.each {
2786 println "JAR: ${it}"
2787 }
2788 }
2789 }
2790}
Ian Zerny9713c032020-01-23 11:41:58 +01002791
2792allprojects {
2793 tasks.withType(Exec) {
2794 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002795 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002796 }
2797 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002798}