blob: f7758220e3c83ae482bb11e8ba340a1cef160d42 [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
6import desugaredlibrary.CustomConversionAsmRewriterTask
Jake Wharton2d7aab82019-09-13 10:24:26 -04007import dx.DexMergerTask
8import dx.DxTask
Ian Zerny5fffb0a2019-02-11 13:54:22 +01009import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +020010import org.gradle.internal.os.OperatingSystem
Ian Zernyb2d27c42019-02-20 09:09:41 +010011import tasks.DownloadDependency
Clément Béra8dde69d2022-10-26 15:40:31 +020012import smali.SmaliTask
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000013import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020014import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020015
Ian Zerny5fffb0a2019-02-11 13:54:22 +010016buildscript {
17 repositories {
Rico Wind23a05112019-03-27 08:00:44 +010018 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010019 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010020 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010021 mavenCentral()
Jake Wharton5e5b5232019-09-17 16:13:32 -040022 gradlePluginPortal()
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010023 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010024 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010025}
26
27plugins {
28 id "net.ltgt.errorprone" version "0.7"
29}
30
31apply plugin: 'java'
32apply plugin: 'idea'
33
Sebastien Hertz143ed112018-02-13 14:26:41 +010034ext {
35 androidSupportVersion = '25.4.0'
Clément Bérac8b2c152022-06-22 08:23:47 +020036 asmVersion = '9.3' // When updating update tools/asmifier.py, build.src and Toolhelper as well.
Sebastien Hertz143ed112018-02-13 14:26:41 +010037 espressoVersion = '3.0.0'
38 fastutilVersion = '7.2.0'
Søren Gjessea93b4262021-12-08 14:40:10 +010039 guavaVersion = '30.1.1-jre'
Sebastien Hertz143ed112018-02-13 14:26:41 +010040 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020041 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010042 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080043 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +010044 // The kotlin version is only here to specify the kotlin language level,
45 // all kotlin compilations are done in tests.
Morten Krogh-Jespersenc9e17cb2021-11-30 08:22:54 +010046 kotlinVersion = '1.6.0'
Morten Krogh-Jespersenfef91252022-07-04 14:30:21 +020047 kotlinExtMetadataJVMVersion = '0.5.0'
Sebastien Hertz143ed112018-02-13 14:26:41 +010048 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010049 errorproneVersion = '2.3.2'
clementbera4f9c2a92019-07-09 08:50:37 +020050 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010051}
52
Mads Ager418d1ca2017-05-22 09:35:49 +020053repositories {
Rico Wind23a05112019-03-27 08:00:44 +010054 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010055 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010056 }
Jake Wharton5e5b5232019-09-17 16:13:32 -040057 google()
Mads Ager418d1ca2017-05-22 09:35:49 +020058 mavenCentral()
59}
60
Jinseong Jeon05064e12018-07-03 00:21:12 -070061if (project.hasProperty('with_code_coverage')) {
62 apply plugin: 'jacoco'
63}
64
Mads Ager418d1ca2017-05-22 09:35:49 +020065// Custom source set for example tests and generated tests.
66sourceSets {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020067 main {
68 java {
69 srcDirs = ['src/main/java']
70 }
71 resources {
72 srcDirs "third_party/api_database/api_database"
73 }
74 }
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +020075 main11 {
76 java {
77 srcDirs = ['src/main/java']
78 }
Morten Krogh-Jespersen798aac02021-10-06 15:32:20 +020079 resources {
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +020080 srcDirs "third_party/api_database/api_database"
Morten Krogh-Jespersen798aac02021-10-06 15:32:20 +020081 }
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +020082 }
Clément Béraffc2d6a2022-08-02 13:03:04 +020083 main17 {
84 java {
85 srcDirs = ['src/main/java']
86 }
87 resources {
88 srcDirs "third_party/api_database/api_database"
89 }
90 }
Mads Ager418d1ca2017-05-22 09:35:49 +020091 test {
92 java {
93 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020094 'src/test/java',
95 'build/generated/test/java',
96 ]
97 }
98 }
Yohann Rousselbb571622017-11-09 10:47:36 +010099 apiUsageSample {
100 java {
Mathias Rave3f3c522018-05-30 08:22:17 +0200101 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
102 include 'com/android/tools/apiusagesample/*.java'
103 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
104 include 'com/android/tools/r8/D8CommandParser.java'
105 include 'com/android/tools/r8/R8CommandParser.java'
106 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +0100107 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100108 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100109 cfSegments {
110 java {
111 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
112 }
113 output.resourcesDir = 'build/classes/cfSegments'
114 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100115 libraryDesugarConversions {
116 java {
117 srcDirs = ['src/library_desugar/java']
118 }
119 output.resourcesDir = 'build/classes/library_desugar_conversions'
120 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200121 debugTestResources {
122 java {
123 srcDirs = ['src/test/debugTestResources']
124 }
125 output.resourcesDir = 'build/classes/debugTestResources'
126 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200127 debugTestResourcesJava8 {
128 java {
129 srcDirs = ['src/test/debugTestResourcesJava8']
130 }
131 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
132 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200133 examples {
134 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800135 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200136 }
137 output.resourcesDir = 'build/classes/examples'
138 }
Ian Zernyd3020482019-04-25 07:05:04 +0200139 examplesJava9 {
140 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200141 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200142 }
143 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500144 examplesJava10 {
145 java {
146 srcDirs = ['src/test/examplesJava10']
147 }
148 }
Ian Zernyd3020482019-04-25 07:05:04 +0200149 examplesJava11 {
150 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200151 srcDirs = ['src/test/examplesJava11']
152 }
153 }
Søren Gjessee9966932021-09-15 17:08:37 +0200154 examplesJava17 {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100155 java {
Søren Gjessee9966932021-09-15 17:08:37 +0200156 srcDirs = ['src/test/examplesJava17']
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100157 }
158 }
Søren Gjessed1e08992022-02-07 16:46:31 +0100159 examplesJava18 {
160 java {
161 srcDirs = ['src/test/examplesJava18']
162 }
163 }
clementberaefa10522019-07-11 11:20:46 +0200164 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200165 java {
166 srcDirs = ['src/test/testngrunner']
167 }
168 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200169 examplesAndroidN {
170 java {
171 srcDirs = ['src/test/examplesAndroidN']
172 }
173 output.resourcesDir = 'build/classes/examplesAndroidN'
174 }
175 examplesAndroidO {
176 java {
177 srcDirs = ['src/test/examplesAndroidO']
178 }
179 output.resourcesDir = 'build/classes/examplesAndroidO'
180 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200181 examplesAndroidP {
182 java {
183 srcDirs = ['src/test/examplesAndroidP']
184 }
185 output.resourcesDir = 'build/classes/examplesAndroidP'
186 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200187 examplesProto {
188 java {
189 srcDirs = ['src/test/examplesProto']
190 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200191 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
192 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200193 output.resourcesDir = 'build/classes/examplesProto'
194 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100195 kotlinR8TestResources {
196 java {
197 srcDirs = ['src/test/kotlinR8TestResources']
198 }
199 output.resourcesDir = 'build/classes/kotlinR8TestResources'
200 }
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100201 keepanno {
202 java {
Ian Zerny172aca22022-11-03 13:07:48 +0100203 srcDirs = ['src/keepanno/java']
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100204 }
205 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200206}
207
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800208// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
209// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
210// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
211// for context.
212idea {
213 sourceSets.all { SourceSet sources ->
214 module {
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100215 if (sources.name == "main" || sources.name == "keepanno") {
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800216 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100217 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800218 } else {
219 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100220 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800221 }
222 }
223 }
224}
225
Yohann Roussel126f6872017-08-03 16:25:32 +0200226configurations {
227 supportLibs
228}
229
Mads Ager418d1ca2017-05-22 09:35:49 +0200230dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100231 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
232 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200233 // Include all of guava when compiling the code, but exclude annotations that we don't
234 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100235 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100236 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200237 exclude group: 'com.google.errorprone'
238 exclude group: 'com.google.code.findbugs'
239 exclude group: 'com.google.j2objc'
240 exclude group: 'org.codehaus.mojo'
241 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100242 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
243 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
244 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
245 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
246 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
247 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
248 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200249
250 main11Implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
251 main11Implementation "com.google.code.gson:gson:$gsonVersion"
252 // Include all of guava when compiling the code, but exclude annotations that we don't
253 // need from the packaging.
254 main11CompileOnly("com.google.guava:guava:$guavaVersion")
255 main11Implementation("com.google.guava:guava:$guavaVersion", {
256 exclude group: 'com.google.errorprone'
257 exclude group: 'com.google.code.findbugs'
258 exclude group: 'com.google.j2objc'
259 exclude group: 'org.codehaus.mojo'
260 })
261 main11Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
262 main11Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
263 main11Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
264 main11Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
265 main11Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
266 main11Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
267 main11Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200268
Clément Béraffc2d6a2022-08-02 13:03:04 +0200269 main17Implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
270 main17Implementation "com.google.code.gson:gson:$gsonVersion"
271 // Include all of guava when compiling the code, but exclude annotations that we don't
272 // need from the packaging.
273 main17CompileOnly("com.google.guava:guava:$guavaVersion")
274 main17Implementation("com.google.guava:guava:$guavaVersion", {
275 exclude group: 'com.google.errorprone'
276 exclude group: 'com.google.code.findbugs'
277 exclude group: 'com.google.j2objc'
278 exclude group: 'org.codehaus.mojo'
279 })
280 main17Implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
281 main17Implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
282 main17Implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
283 main17Implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
284 main17Implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
285 main17Implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
286 main17Implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
287
clementberaefa10522019-07-11 11:20:46 +0200288 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Ian Zerny161ff742022-01-20 12:39:40 +0100289
Mads Ager418d1ca2017-05-22 09:35:49 +0200290 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100291 testCompile "junit:junit:$junitVersion"
Ian Zerny161ff742022-01-20 12:39:40 +0100292 testCompile "com.google.guava:guava:$guavaVersion"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100293 testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
294 testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100295 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200296 testCompile files('third_party/jasmin/jasmin-2.4.jar')
297 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200298 testCompile files('third_party/ddmlib/ddmlib.jar')
Ian Zerny161ff742022-01-20 12:39:40 +0100299 testCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
300 testCompile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
301 testCompile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
302 testCompile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
303 testCompile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
304 testCompile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
305
Sebastien Hertz143ed112018-02-13 14:26:41 +0100306 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
307 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200308 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100309 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800310 examplesCompile "junit:junit:$junitVersion"
311 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100312 supportLibs "com.android.support:support-v4:$androidSupportVersion"
313 supportLibs "junit:junit:$junitVersion"
314 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100315 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100316 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100317 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100318 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Ian Zernyfcd0adb2022-11-02 16:15:59 +0100319
320 keepannoCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
321 keepannoCompile "com.google.guava:guava:$guavaVersion"
322 testCompile sourceSets.keepanno.output
323 testRuntime sourceSets.keepanno.output
Stephan Herhut417a72a2017-07-18 10:38:30 +0200324}
325
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100326def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100327def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200328def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100329def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100330def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +0200331def java11ClassFiles = "$buildDir/classes/java/mainJava11"
332def r8RetracePath = "$buildDir/libs/r8retrace.jar"
333def r8RetraceExludeDepsPath = "$buildDir/libs/r8retrace-exclude-deps.jar"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100334
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200335def osString = OperatingSystem.current().isLinux() ? "linux" :
336 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200337
338def cloudDependencies = [
339 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200340 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100341 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200342 ],
343 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200344 "android_cts_baseline",
Morten Krogh-Jespersena31c3442022-06-02 21:07:50 +0200345 "android_jar/libcore_latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200346 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100347 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200348 "android_jar/lib-v19",
349 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100350 "android_jar/lib-v22",
351 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200352 "android_jar/lib-v24",
353 "android_jar/lib-v25",
354 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100355 "android_jar/lib-v27",
356 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200357 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200358 "android_jar/lib-v30",
Søren Gjesse8c15ecd2021-03-22 16:41:53 +0100359 "android_jar/lib-v31",
Søren Gjesse29c8c5b2021-11-01 10:30:57 +0100360 "android_jar/lib-v32",
Søren Gjessea1f2c512022-02-04 09:51:45 +0100361 "android_jar/lib-v33",
Christoffer Quist Adamsen84da5262022-08-24 13:54:21 +0200362 "android_jar/lib-master",
Morten Krogh-Jespersen4e10d682022-05-05 15:57:47 +0200363 "api_database/api_database",
Morten Krogh-Jespersen7a47b732021-05-11 17:32:34 +0200364 "api-outlining/simple-app-dump",
Ian Zerny0d806882021-09-30 15:17:40 +0200365 "binary_compatibility_tests/compiler_api_tests",
Christoffer Quist Adamsen541fb222022-08-11 15:00:41 +0200366 "bundletool/bundletool-1.11.0",
Rico Windf72fa152018-10-22 15:41:03 +0200367 "core-lambda-stubs",
Søren Gjesse7dee79d2022-03-17 13:50:48 +0100368 "dagger/2.41",
Rico Windf72fa152018-10-22 15:41:03 +0200369 "dart-sdk",
370 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200371 "gradle/gradle",
Christoffer Quist Adamsene1821392022-02-15 14:58:03 +0100372 "google/google-java-format/1.14.0",
Ian Zerny33c1c582019-09-17 12:43:45 +0200373 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200374 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200375 "jacoco/0.8.2",
376 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200377 "jasmin",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100378 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200379 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200380 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200381 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200382 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200383 "kotlin/kotlin-compiler-1.3.11",
384 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200385 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen1c801b02021-02-11 10:15:23 +0100386 "kotlin/kotlin-compiler-1.4.20",
Morten Krogh-Jespersena9705f52021-07-05 11:28:02 +0200387 "kotlin/kotlin-compiler-1.5.0",
Morten Krogh-Jespersen61683192021-11-25 11:14:47 +0100388 "kotlin/kotlin-compiler-1.6.0",
Morten Krogh-Jespersen3100d182022-07-05 13:05:54 +0200389 "kotlin/kotlin-compiler-1.7.0",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200390 "kotlinx-coroutines-1.3.6",
Clément Béra8dde69d2022-10-26 15:40:31 +0200391 "multidex",
Mathias Rav5285faf2018-03-20 14:16:32 +0100392 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200393 "openjdk/desugar_jdk_libs",
Clément Béracac269b2021-03-17 07:53:43 +0000394 "openjdk/desugar_jdk_libs_11",
Ian Zernyc4598882022-02-25 19:26:44 +0100395 "openjdk/desugar_jdk_libs_legacy",
Søren Gjesse09c3dd02021-06-17 08:21:51 +0200396 "openjdk/desugar_jdk_libs_releases/1.0.9",
397 "openjdk/desugar_jdk_libs_releases/1.0.10",
398 "openjdk/desugar_jdk_libs_releases/1.1.0",
399 "openjdk/desugar_jdk_libs_releases/1.1.1",
400 "openjdk/desugar_jdk_libs_releases/1.1.5",
clementbera8dbfeda2019-07-03 11:24:13 +0200401 "openjdk/jdk-11-test",
Ian Zernye5886582022-03-03 11:01:08 +0100402 "opensource-apps/tivi",
Rico Windf72fa152018-10-22 15:41:03 +0200403 "proguard/proguard5.2.1",
404 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200405 "proguard/proguard-7.0.0",
Morten Krogh-Jespersen0cade312022-03-22 13:40:21 +0000406 "retrace_benchmark",
Morten Krogh-Jespersen7cbae972021-08-31 16:54:31 +0200407 "retrace/binary_compatibility",
Ian Zernyfad3a3c2022-03-30 19:55:42 +0200408 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200409 "r8-releases/2.0.74",
Ian Zerny20d576f2022-03-28 19:16:38 +0200410 "r8-releases/3.2.54",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200411 "r8mappings",
412 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200413 ],
414 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
415 // container on other platforms where supported.
416 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200417 "linux/art",
418 "linux/art-5.1.1",
419 "linux/art-6.0.1",
420 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100421 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100422 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100423 "linux/art-10.0.0",
Søren Gjesse953f7c42021-08-18 16:42:06 +0200424 "linux/host/art-12.0.0-beta4",
Søren Gjesseb8e64e02022-08-18 13:42:50 +0200425 "linux/host/art-13.0.0",
Søren Gjesse76a5e332022-08-16 13:26:46 +0200426 "linux/host/art-master",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200427 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100428 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200429 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200430 ]
431]
432
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100433def cloudSystemDependencies = [
434 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200435 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200436 "openjdk/jdk8/linux-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100437 "openjdk/jdk-11/linux",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100438 "openjdk/jdk-17/linux",
439 "openjdk/jdk-18/linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100440 ],
441 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200442 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200443 "openjdk/jdk8/darwin-x86",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100444 "openjdk/jdk-11/osx",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100445 "openjdk/jdk-17/osx",
446 "openjdk/jdk-18/osx"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100447 ],
448 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200449 "third_party": ["openjdk/openjdk-9.0.4/windows",
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100450 "openjdk/jdk-11/windows",
Søren Gjesse0b11ff82022-02-07 12:57:07 +0100451 "openjdk/jdk-17/windows",
452 "openjdk/jdk-18/windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100453 ],
454]
455
456if (OperatingSystem.current().isWindows()) {
457 cloudSystemDependencies.windows.each { entry ->
458 cloudDependencies.get(entry.key).addAll(entry.value)
459 }
460} else if (OperatingSystem.current().isLinux()) {
461 cloudSystemDependencies.linux.each { entry ->
462 cloudDependencies.get(entry.key).addAll(entry.value)
463 }
464} else if (OperatingSystem.current().isMacOsX()) {
465 cloudSystemDependencies.osx.each { entry ->
466 cloudDependencies.get(entry.key).addAll(entry.value)
467 }
468} else {
469 println "WARNING: Unsupported system: " + OperatingSystem.current()
470}
471
472def getDownloadDepsTaskName(entryKey, entryFile) {
473 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
474}
475
Mads Ager418d1ca2017-05-22 09:35:49 +0200476cloudDependencies.each { entry ->
477 entry.value.each { entryFile ->
Morten Krogh-Jespersenc3e7ab92022-05-03 15:12:04 +0200478 task (getDownloadDepsTaskName(entry.key, entryFile), type: DownloadDependency) {
Ian Zernyb2d27c42019-02-20 09:09:41 +0100479 type DownloadDependency.Type.GOOGLE_STORAGE
480 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200481 }
482 }
483}
484
485def x20Dependencies = [
486 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200487 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700488 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200489 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200490 "chrome/monochrome_public_minimal_apks/chrome_200520",
Clément Béra5da4e352021-01-27 18:16:27 +0000491 "chrome/clank_google3_prebuilt",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100492 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100493 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200494 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100495 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200496 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200497 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200498 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200499 "gmscore/gmscore_v10",
Rico Windf72fa152018-10-22 15:41:03 +0200500 "gmscore/latest",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200501 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200502 "proguard/proguard_internal_159423826",
503 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200504 "proto",
505 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200506 "retrace_internal",
Christoffer Quist Adamsen62fcc152022-06-03 14:01:35 +0200507 "youtube/youtube.android_16.20",
508 "youtube/youtube.android_17.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200509 ],
510]
511
512x20Dependencies.each { entry ->
513 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100514 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
515 type DownloadDependency.Type.X20
516 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200517 }
518 }
519}
520
Rico Wind897bb712017-05-23 10:44:29 +0200521task downloadProguard {
522 cloudDependencies.each { entry ->
523 entry.value.each { entryFile ->
524 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100525 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200526 }
527 }
528 }
529}
530
Rico Windf6c74ce2018-12-04 08:50:55 +0100531task downloadOpenJDKrt {
532 cloudDependencies.each { entry ->
533 entry.value.each { entryFile ->
534 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100535 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100536 }
537 }
538 }
539}
540
Tamas Kenez427205b2017-06-29 15:57:09 +0200541task downloadDx {
542 cloudDependencies.each { entry ->
543 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200544 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100545 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200546 }
547 }
548 }
549}
550
Tamas Kenez0e10c562017-06-08 10:00:34 +0200551task downloadAndroidCts {
552 cloudDependencies.each { entry ->
553 entry.value.each { entryFile ->
554 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100555 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200556 }
557 }
558 }
559}
560
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200561task downloadCloudDeps() {
Mads Ager418d1ca2017-05-22 09:35:49 +0200562 cloudDependencies.each { entry ->
563 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100564 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200565 }
566 }
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200567}
568
569task downloadX20Deps() {
570 x20Dependencies.each { entry ->
571 entry.value.each { entryFile ->
572 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200573 }
574 }
575}
576
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200577task downloadDeps {
578 dependsOn downloadCloudDeps
579 if (!project.hasProperty('no_internal')) {
580 dependsOn downloadX20Deps
581 }
582}
583
Mads Ager418d1ca2017-05-22 09:35:49 +0200584allprojects {
585 sourceCompatibility = JavaVersion.VERSION_1_8
586 targetCompatibility = JavaVersion.VERSION_1_8
587}
588
Rico Wind266336c2019-02-25 10:11:38 +0100589// TODO(ricow): Remove debug prints
590println("NOTE: Current operating system: " + OperatingSystem.current())
591println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
592
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100593// Check if running with the JDK location from tools/jdk.py.
594if (OperatingSystem.current().isWindows()) {
595 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100596 compileJava.options.encoding = "UTF-8"
597 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100598} else {
599 def javaHomeOut = new StringBuilder()
600 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400601 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100602 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
603 def jdkHome = new File(javaHomeOut.toString().trim())
604 if (!jdkHome.exists()) {
605 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
606 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
607 println("WARNING: Gradle is running in a non-pinned Java"
608 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000609 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100610 } else {
611 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100612 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200613}
614
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200615compileJava.dependsOn downloadCloudDeps
Morten Krogh-Jespersenc1bc4a02021-06-18 08:13:02 +0200616
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100617sourceSets.configureEach { sourceSet ->
618 tasks.named(sourceSet.compileJavaTaskName).configure {
619 // Default disable errorprone (enabled and setup below).
620 options.errorprone.enabled = false
621 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100622 // Run all compilation tasks in a forked subprocess.
623 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100624 // Javac often runs out of stack space when compiling the tests.
625 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200626 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100627 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200628 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100629 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
630 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
631 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200632}
633
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100634def setJdkCompilationWithCompatibility(String sourceSet, String javaHome, JavaVersion compatibility, boolean enablePreview) {
635 tasks.named(sourceSet).get().configure {
636 def jdkDir = "third_party/openjdk/${javaHome}/"
637 options.fork = true
638 options.forkOptions.jvmArgs = []
639 if (enablePreview) {
640 options.compilerArgs.add('--enable-preview')
641 }
642 if (OperatingSystem.current().isLinux()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200643 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/linux")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100644 options.forkOptions.javaHome = file(jdkDir + 'linux')
645 } else if (OperatingSystem.current().isMacOsX()) {
Søren Gjesse96b37252021-08-09 16:08:05 +0200646 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/osx")
Jake Whartonbd3196b2021-03-16 15:48:08 -0400647 options.forkOptions.javaHome = compatibility > JavaVersion.VERSION_1_9
648 ? file(jdkDir + 'osx/Contents/Home')
649 : file(jdkDir + 'osx')
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100650 } else {
Søren Gjesse96b37252021-08-09 16:08:05 +0200651 dependsOn getDownloadDepsTaskName("third_party", "openjdk/" + javaHome + "/windows")
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100652 options.forkOptions.javaHome = file(jdkDir + 'windows')
653 }
654 sourceCompatibility = compatibility
655 targetCompatibility = compatibility
Ian Zernyd3020482019-04-25 07:05:04 +0200656 }
Ian Zernyd3020482019-04-25 07:05:04 +0200657}
658
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100659setJdkCompilationWithCompatibility(
Ian Zerny3ac86842022-10-05 11:49:35 +0200660 sourceSets.main.compileJavaTaskName,
661 'jdk-11',
662 JavaVersion.VERSION_11,
663 false);
664
665setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100666 sourceSets.examplesJava9.compileJavaTaskName,
667 'openjdk-9.0.4',
668 JavaVersion.VERSION_1_9,
669 false)
670setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100671 sourceSets.examplesJava10.compileJavaTaskName,
672 'jdk-11',
673 JavaVersion.VERSION_1_10,
674 false)
675setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200676 sourceSets.main11.compileJavaTaskName,
677 'jdk-11',
678 JavaVersion.VERSION_11,
679 false)
680setJdkCompilationWithCompatibility(
Clément Béraffc2d6a2022-08-02 13:03:04 +0200681 sourceSets.main17.compileJavaTaskName,
682 'jdk-17',
683 JavaVersion.VERSION_17,
684 false)
685setJdkCompilationWithCompatibility(
Morten Krogh-Jespersen43a4ef32020-11-25 16:59:33 +0100686 sourceSets.examplesJava11.compileJavaTaskName,
687 'jdk-11',
688 JavaVersion.VERSION_11,
689 false)
690setJdkCompilationWithCompatibility(
691 sourceSets.examplesTestNGRunner.compileJavaTaskName,
692 'jdk-11',
693 JavaVersion.VERSION_11,
694 false)
695setJdkCompilationWithCompatibility(
Søren Gjessee9966932021-09-15 17:08:37 +0200696 sourceSets.examplesJava17.compileJavaTaskName,
697 'jdk-17',
698 JavaVersion.VERSION_17,
699 false)
Søren Gjessed1e08992022-02-07 16:46:31 +0100700setJdkCompilationWithCompatibility(
701 sourceSets.examplesJava18.compileJavaTaskName,
702 'jdk-18',
703 // TODO(b/218293990): Update Gradle to get JavaVersion.VERSION_18.
704 JavaVersion.VERSION_17,
705 false)
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100706
Clément Bérac94b6202021-09-28 11:16:58 +0000707task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
708 from sourceSets.examplesTestNGRunner.compileClasspath
709 include "**/**.jar"
710 into file("$buildDir/test/jdk11Tests")
711}
712
713task compileTestNGRunner (type: JavaCompile) {
714 dependsOn provideJdk11TestsDependencies
Clément Béra98d5b602021-09-29 06:27:21 +0000715 destinationDir = file("$buildDir/classes/java/examplesTestNGRunner")
Clément Bérac94b6202021-09-28 11:16:58 +0000716 source = sourceSets.examplesTestNGRunner.allSource
717 classpath = sourceSets.examplesTestNGRunner.compileClasspath
718}
719
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100720if (!project.hasProperty('without_error_prone') &&
721 // Don't enable error prone on Java 8 as the plugin setup does not support it.
722 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200723 compileJava {
724 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100725 options.errorprone.enabled = true
726 options.errorprone.disableAllChecks = true
727 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
Christoffer Quist Adamsen7bed1092020-05-04 11:08:00 +0200728 options.errorprone.check('CollectionIncompatibleType', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100729 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
730 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
731 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
732 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
733 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
734 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
735 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
736 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
737 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
738 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
739 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
740 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
741 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
742 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
743 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
744 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
745 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
746 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200747 }
748}
749
Yohann Roussel7f47c032017-09-14 12:19:06 +0200750task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200751 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100752
Yohann Roussel7f47c032017-09-14 12:19:06 +0200753 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100754 def runtimeClasspath = configurations.findByName("runtimeClasspath")
755 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
756
Yohann Roussel7f47c032017-09-14 12:19:06 +0200757 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100758
Yohann Roussel7f47c032017-09-14 12:19:06 +0200759 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100760 def dependencies = []
761 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
762 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
763 dependencies.add("${identifier.group}:${identifier.module}")
764 }
765 def libraryLicenses = file('LIBRARY-LICENSE').text
766 dependencies.each {
767 if (!libraryLicenses.contains("- artifact: $it")) {
768 throw new GradleException("No license for $it in LIBRARY_LICENSE")
769 }
770 }
771
Yohann Roussel7f47c032017-09-14 12:19:06 +0200772 license.getParentFile().mkdirs()
773 license.createNewFile()
774 license.text = "This file lists all licenses for code distributed.\n"
775 license.text += "All non-library code has the following 3-Clause BSD license.\n"
776 license.text += "\n"
777 license.text += "\n"
778 license.text += file('LICENSE').text
779 license.text += "\n"
780 license.text += "\n"
781 license.text += "Summary of distributed libraries:\n"
782 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100783 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200784 license.text += "\n"
785 license.text += "\n"
786 license.text += "Licenses details:\n"
787 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
788 license.text += "\n"
789 license.text += "\n"
790 license.text += file.text
791 }
792 }
793}
794
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100795def repackageDepFile(file) {
796 if (file.getName().endsWith('.jar')) {
797 return zipTree(file).matching {
798 exclude '**/module-info.class'
799 exclude 'META-INF/maven/**'
800 exclude 'META-INF/LICENSE.txt'
801 exclude 'META-INF/MANIFEST.MF'
802 }
803 } else {
804 return fileTree(file)
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700805 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200806}
807
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100808task repackageDeps(type: Jar) {
Morten Krogh-Jespersenb9620512021-06-18 11:01:05 +0200809 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100810 dependsOn project.configurations.runtimeClasspath
811 project.configurations.runtimeClasspath.forEach {
812 from repackageDepFile(it)
813 }
814 archiveFileName = 'deps_all.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000815}
816
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100817task repackageTestDeps(type: Jar) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200818 dependsOn downloadCloudDeps
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100819 dependsOn project.configurations.testCompile
820 project.configurations.testCompile.forEach {
821 from repackageDepFile(it)
822 }
823 archiveFileName = 'test_deps_all.jar'
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200824}
825
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100826task repackageSources(type: Jar) {
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100827 // If this fails then remove all generated folders from
828 // build/classes/java/test that is not {com,dalvik}
Mads Ager418d1ca2017-05-22 09:35:49 +0200829 from sourceSets.main.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100830 archiveFileName = 'sources_main.jar'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000831}
832
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100833task repackageSources11(type: Jar) {
Morten Krogh-Jespersen013c30b2021-10-06 10:32:10 +0200834 from sourceSets.main11.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100835 archiveFileName = 'sources_main_11.jar'
clementbera0bca05e2019-05-29 14:11:18 +0200836}
837
Clément Béraffc2d6a2022-08-02 13:03:04 +0200838task repackageSources17(type: Jar) {
839 from sourceSets.main17.output
840 archiveFileName = 'sources_main_17.jar'
841}
842
Søren Gjesse145d9e82022-05-24 08:12:13 +0200843def r8CreateTask(name, baseName, sources, includeLibraryLicenses, includeSwissArmyKnife) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100844 return tasks.create("r8Create${name}", Jar) {
Morten Krogh-Jespersenb4b33eb2022-05-06 16:47:08 +0200845 entryCompression ZipEntryCompression.STORED
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100846 dependsOn sources
Søren Gjesse145d9e82022-05-24 08:12:13 +0200847 dependsOn files('LICENSE')
848 if (includeLibraryLicenses) {
849 from consolidatedLicense.outputs.files
850 } else {
851 from files('LICENSE')
852 }
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100853 from sources.collect { zipTree(it) }
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +0100854 exclude "$buildDir/classes/**"
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100855 archiveFileName = baseName
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200856 if (includeSwissArmyKnife) {
857 manifest {
858 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
859 }
860 }
861 exclude "META-INF/*.kotlin_module"
862 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200863 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200864}
865
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200866def r8RelocateTask(r8Task, output) {
867 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
868 dependsOn r8WithDeps
869 dependsOn r8Task
870 outputs.file output
871 workingDir = projectDir
872 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200873 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200874 "relocator",
875 "--input",
876 r8Task.outputs.files[0],
877 "--output",
878 output,
879 "--map",
880 "com.google.common->com.android.tools.r8.com.google.common",
881 "--map",
882 "com.google.gson->com.android.tools.r8.com.google.gson",
883 "--map",
884 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
885 "--map",
886 "joptsimple->com.android.tools.r8.joptsimple",
887 "--map",
888 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
889 "--map",
890 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
891 "--map",
892 "kotlin->com.android.tools.r8.jetbrains.kotlin",
893 "--map",
894 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
895 "--map",
896 "org.jetbrains->com.android.tools.r8.org.jetbrains",
897 "--map",
Søren Gjessebeb5d872021-09-07 12:49:24 +0200898 "org.intellij->com.android.tools.r8.org.intellij",
899 "--map",
900 "org.checkerframework->com.android.tools.r8.org.checkerframework"
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200901 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200902 }
903}
904
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200905task r8WithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200906 dependsOn repackageSources
907 dependsOn repackageDeps
908 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200909 def r8Task = r8CreateTask(
910 'WithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100911 'r8_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200912 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200913 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200914 true)
915 dependsOn r8Task
916 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200917}
918
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200919task r8WithDeps11 {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200920 dependsOn repackageSources11
921 dependsOn repackageDeps
922 inputs.files ([repackageSources11.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200923 def r8Task = r8CreateTask(
924 'WithDeps11',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100925 'r8_with_deps_11.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200926 repackageSources11.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200927 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200928 true)
929 dependsOn r8Task
930 outputs.files r8Task.outputs.files
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100931}
932
Clément Béraffc2d6a2022-08-02 13:03:04 +0200933task r8WithDeps17 {
934 dependsOn repackageSources17
935 dependsOn repackageDeps
936 inputs.files ([repackageSources17.outputs, repackageDeps.outputs])
937 def r8Task = r8CreateTask(
938 'WithDeps17',
939 'r8_with_deps_17.jar',
940 repackageSources17.outputs.files + repackageDeps.outputs.files,
941 true,
942 true)
943 dependsOn r8Task
944 outputs.files r8Task.outputs.files
945}
946
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200947task r8WithRelocatedDeps {
948 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
949 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200950 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200951 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200952}
953
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200954task r8WithRelocatedDeps11 {
955 def output = "${buildDir}/libs/r8_with_relocated_deps_11.jar"
956 dependsOn r8RelocateTask(r8WithDeps11, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200957 inputs.files r8WithDeps11.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200958 outputs.file output
959}
960
Clément Béraffc2d6a2022-08-02 13:03:04 +0200961task r8WithRelocatedDeps17 {
962 def output = "${buildDir}/libs/r8_with_relocated_deps_17.jar"
963 dependsOn r8RelocateTask(r8WithDeps17, output)
964 inputs.files r8WithDeps17.outputs.files
965 outputs.file output
966}
967
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200968task r8WithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200969 dependsOn repackageSources
970 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200971 def r8Task = r8CreateTask(
972 'WithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100973 'r8_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200974 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200975 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200976 true)
977 dependsOn r8Task
978 outputs.files r8Task.outputs.files
979}
980
981task r8(type: Copy) {
982 def r8Task = project.hasProperty("exclude_deps")
983 ? r8WithoutDeps : r8WithRelocatedDeps
984 dependsOn r8Task
985 from r8Task.outputs.files[0]
986 into file("${buildDir}/libs")
987 rename { String fileName -> "r8.jar" }
988 outputs.file "${buildDir}/libs/r8.jar"
989}
990
991task r8NoManifestWithoutDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200992 dependsOn repackageSources
993 inputs.files repackageSources.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200994 def r8Task = r8CreateTask(
995 'NoManifestWithoutDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +0100996 'r8_no_manifest_without_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +0200997 repackageSources.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +0200998 false,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200999 false)
1000 dependsOn r8Task
1001 outputs.files r8Task.outputs.files
1002}
1003
1004task r8NoManifestWithDeps {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001005 dependsOn repackageSources
1006 inputs.files ([repackageSources.outputs, repackageDeps.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001007 def r8Task = r8CreateTask(
1008 'NoManifestWithDeps',
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001009 'r8_no_manifest_with_deps.jar',
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001010 repackageSources.outputs.files + repackageDeps.outputs.files,
Søren Gjesse145d9e82022-05-24 08:12:13 +02001011 true,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001012 false)
1013 dependsOn r8Task
1014 outputs.files r8Task.outputs.files
1015}
1016
1017task r8NoManifestWithRelocatedDeps {
1018 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
1019 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001020 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001021 outputs.file output
1022}
1023
1024task r8NoManifest(type: Copy) {
1025 def r8Task = project.hasProperty("exclude_deps")
1026 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
1027 dependsOn r8Task
1028 from r8Task.outputs.files[0]
1029 into file("${buildDir}/libs")
1030 rename { String fileName -> "r8_no_manifest.jar" }
1031 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +01001032}
1033
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001034def baseCompilerCommandLine(compiler, args = []) {
1035 // Execute r8 commands against a stable r8 with dependencies.
1036 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
1037 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
1038 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
1039}
1040
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001041def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001042 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001043 return baseCompilerCommandLine("r8", args)
1044}
1045
1046def baseD8CommandLine(args = []) {
1047 // Execute r8 commands against a stable r8 with dependencies.
1048 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001049}
1050
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001051def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
1052 def allArgs = [
1053 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001054 input,
1055 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001056 "--pg-map-output", output + ".map",
Ian Zerny3ac86842022-10-05 11:49:35 +02001057 "--lib", org.gradle.internal.jvm.Jvm.current().javaHome,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001058 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
1059 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001060}
1061
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001062def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
1063 def allArgs = [
1064 "--classfile",
1065 input,
1066 "--output", output,
1067 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
1068 ] + args + libs.collectMany { ["--lib", it] }
1069 return baseD8CommandLine(allArgs)
1070}
1071
Ian Zernycf8ef512022-05-04 14:54:16 +02001072def r8LibCreateTask(name, pgConfs = [], r8Task, output, libs = [], classpath = [], excldeps=false) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001073 return tasks.create("r8Lib${name}", Exec) {
Ian Zernya0d27cf2021-10-14 13:55:34 +02001074 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001075 outputs.file output
1076 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001077 dependsOn r8WithRelocatedDeps
1078 dependsOn r8Task
Ian Zernya0d27cf2021-10-14 13:55:34 +02001079 commandLine ([
Ian Zerny99613a02022-02-23 11:50:13 +01001080 "python3", "tools/create_r8lib.py",
Ian Zernya0d27cf2021-10-14 13:55:34 +02001081 "--r8jar", r8Task.outputs.files[0],
1082 "--output", output]
Ian Zernycf8ef512022-05-04 14:54:16 +02001083 + (excldeps ? ['--excldeps-variant'] : [])
Ian Zernya0d27cf2021-10-14 13:55:34 +02001084 + (pgConfs.collectMany { ["--pg-conf", it] })
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001085 + (libs.collectMany { ["--lib", it] })
1086 + (classpath.collectMany { ["--classpath", it] }))
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001087 workingDir = projectDir
1088 }
1089}
1090
Clément Bérac8b2c152022-06-22 08:23:47 +02001091task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001092 from sourceSets.libraryDesugarConversions.output
1093 include "java/**/*.class"
Clément Bérac8b2c152022-06-22 08:23:47 +02001094 baseName 'library_desugar_conversions_raw'
1095 destinationDir file('build/tmp/desugaredlibrary')
1096}
1097
1098task buildLibraryDesugarConversions(type: CustomConversionAsmRewriterTask, dependsOn: rawBuildLibraryDesugarConversions) {
Clément Béra37085f62022-06-22 11:14:31 +02001099 rawJar = file("build/tmp/desugaredlibrary/library_desugar_conversions_raw.zip")
Clément Bérac8b2c152022-06-22 08:23:47 +02001100 outputDirectory = file("build/libs")
Søren Gjesse17fc67d2019-12-04 14:50:17 +01001101}
1102
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001103task testJarSources(type: Jar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
1104 archiveFileName = "r8testsbase.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001105 from sourceSets.test.output
Ian Zernyfcd0adb2022-11-02 16:15:59 +01001106 from sourceSets.keepanno.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001107 // We only want to include tests that use R8 when generating keep rules for applymapping.
1108 include "com/android/tools/r8/**"
Christoffer Quist Adamsen5f0a2872022-07-05 13:05:08 +02001109 include "android/**"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001110 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001111}
1112
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001113task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +02001114 dependsOn r8WithDeps
1115 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001116 def output = "$buildDir/libs/r8tests.jar"
1117 outputs.file output
1118 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001119 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001120 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +02001121 "relocator",
1122 "--input",
1123 testJarSources.outputs.files[0],
1124 "--output",
1125 output,
1126 "--map",
1127 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
1128 ])
1129}
1130
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001131task generateR8LibKeepRules(type: Exec) {
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001132 // Depend on r8WithRelocatedDeps to ensure that we do not have external
1133 // dependencies crossing the boundary.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001134 dependsOn r8WithDeps
1135 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001136 dependsOn testJar
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001137 dependsOn repackageTestDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001138 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001139 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001140 r8WithDeps.outputs,
1141 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001142 repackageDeps.outputs,
1143 repackageTestDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +02001144 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001145 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001146 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001147 "tracereferences",
1148 "--keep-rules",
1149 "--allowobfuscation",
1150 "--lib",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001151 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001152 "--lib",
1153 repackageDeps.outputs.files[0],
1154 "--lib",
1155 repackageTestDeps.outputs.files[0],
1156 "--target",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +02001157 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001158 "--source",
1159 testJar.outputs.files[0],
1160 "--output",
1161 r8LibGeneratedKeepRulesPath])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001162 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001163}
1164
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001165task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001166 dependsOn r8LibCreateTask(
1167 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001168 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001169 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001170 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001171 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001172 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001173 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001174}
1175
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001176task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001177 dependsOn r8LibCreateTask(
Ian Zernya0d27cf2021-10-14 13:55:34 +02001178 "MainNoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001179 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001180 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001181 r8LibExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001182 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001183 repackageDeps.outputs.files,
1184 true,
Morten Krogh-Jespersenb329ac42021-09-09 09:16:16 +02001185 ).dependsOn(repackageDeps)
1186 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDeps.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001187 outputs.file r8LibExludeDepsPath
1188}
1189
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001190task R8Desugared(type: Exec) {
1191 dependsOn downloadOpenJDKrt
1192 dependsOn r8NoManifestWithRelocatedDeps
1193 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1194 commandLine d8CfCommandLine(
1195 r8NoManifestWithRelocatedDeps.outputs.files[0],
1196 r8DesugaredPath,
1197 ["--release"])
1198 workingDir = projectDir
1199 outputs.file r8DesugaredPath
1200}
1201
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001202task R8Retrace {
1203 dependsOn R8Lib
1204 dependsOn r8LibCreateTask(
1205 "Retrace",
1206 ["src/main/keep_retrace.txt"],
1207 R8Lib,
1208 r8RetracePath,
1209 ).dependsOn(R8Lib)
1210 outputs.file r8RetracePath
1211}
1212
1213task R8RetraceNoDeps {
1214 dependsOn R8LibNoDeps
1215 dependsOn r8LibCreateTask(
1216 "RetraceNoDeps",
1217 ["src/main/keep_retrace.txt"],
1218 R8LibNoDeps,
1219 r8RetraceExludeDepsPath,
Morten Krogh-Jespersen378aa612021-11-23 13:27:25 +01001220 [],
Ian Zernycf8ef512022-05-04 14:54:16 +02001221 repackageDeps.outputs.files,
1222 true,
Morten Krogh-Jespersen98ee89a2021-10-25 20:59:02 +02001223 ).dependsOn(R8LibNoDeps)
1224 outputs.file r8RetraceExludeDepsPath
1225}
1226
Mads Ager418d1ca2017-05-22 09:35:49 +02001227task sourceJar(type: Jar, dependsOn: classes) {
1228 classifier = 'src'
1229 from sourceSets.main.allSource
1230}
1231
Mads Ager418d1ca2017-05-22 09:35:49 +02001232artifacts {
1233 archives sourceJar
1234}
1235
1236task createArtTests(type: Exec) {
1237 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001238 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001239 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001240 outputs.dir outputDir
1241 dependsOn downloadDeps
Ian Zerny99613a02022-02-23 11:50:13 +01001242 commandLine "python3", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001243 workingDir = projectDir
1244}
1245
Mads Ager418d1ca2017-05-22 09:35:49 +02001246compileTestJava {
1247 dependsOn createArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001248}
1249
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001250task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1251 from sourceSets.cfSegments.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001252 archiveFileName = 'cf_segments.jar'
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001253 destinationDir file('build/libs')
1254}
1255
Ian Zerny923a0c12018-01-03 10:59:18 +01001256task buildR8ApiUsageSample(type: Jar) {
1257 from sourceSets.apiUsageSample.output
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001258 archiveFileName = 'r8_api_usage_sample.jar'
Ian Zerny923a0c12018-01-03 10:59:18 +01001259 destinationDir file('tests')
1260}
1261
Yohann Roussel548ae942018-01-05 11:13:28 +01001262task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001263 dependsOn buildR8ApiUsageSample
1264}
1265
Mads Ager418d1ca2017-05-22 09:35:49 +02001266task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001267 def resourcesDir = file("src/test/debugTestResources")
1268 def hostJar = "debug_test_resources.jar"
1269 task "compile_debugTestResources"(type: JavaCompile) {
1270 source = fileTree(dir: resourcesDir, include: '**/*.java')
1271 destinationDir = file("build/test/debugTestResources/classes")
1272 classpath = sourceSets.main.compileClasspath
1273 sourceCompatibility = JavaVersion.VERSION_1_7
1274 targetCompatibility = JavaVersion.VERSION_1_7
1275 options.compilerArgs += ["-g", "-Xlint:-options"]
1276 }
1277 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1278 archiveName = hostJar
1279 destinationDir = file("build/test/")
1280 from "build/test/debugTestResources/classes"
1281 include "**/*.class"
1282 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001283 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1284 def java8HostJar = "debug_test_resources_java8.jar"
1285 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1286 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1287 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1288 classpath = sourceSets.main.compileClasspath
1289 sourceCompatibility = JavaVersion.VERSION_1_8
1290 targetCompatibility = JavaVersion.VERSION_1_8
1291 options.compilerArgs += ["-g", "-Xlint:-options"]
1292 }
1293 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1294 archiveName = java8HostJar
1295 destinationDir = file("build/test/")
1296 from "build/test/debugTestResourcesJava8/classes"
1297 include "**/*.class"
1298 }
1299 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001300 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001301 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +02001302}
1303
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001304// Examples used by tests, where Android specific APIs are used.
1305task buildExampleAndroidApi(type: JavaCompile) {
1306 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1307 destinationDir = file("build/test/examplesAndroidApi/classes")
1308 classpath = files("third_party/android_jar/lib-v26/android.jar")
1309 sourceCompatibility = JavaVersion.VERSION_1_8
1310 targetCompatibility = JavaVersion.VERSION_1_8
1311}
1312
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001313task buildProtoGeneratedSources {
1314 def examplesProtoDir = file("src/test/examplesProto")
1315 examplesProtoDir.eachDir { dir ->
1316 def name = dir.getName()
1317 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1318 source = {
1319 file('third_party/proto').listFiles()
1320 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1321 .collect { zipTree(it) }
1322 }
1323 destinationDir = file("build/generated/test/proto/${name}_classes")
1324 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1325 sourceCompatibility = JavaVersion.VERSION_1_8
1326 targetCompatibility = JavaVersion.VERSION_1_8
1327 }
1328 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1329 archiveName = "${name}.jar"
1330 destinationDir = file("build/generated/test/proto")
1331 from "build/generated/test/proto/${name}_classes"
1332 include "/**/*.class"
1333 }
1334 dependsOn "jar_proto_generated_source_${name}"
1335 }
1336}
1337
1338task buildExamplesProto {
1339 def examplesProtoDir = file("src/test/examplesProto")
1340 def examplesProtoOutputDir = file("build/test/examplesProto");
1341 dependsOn buildProtoGeneratedSources
1342 task "compile_examples_proto"(type: JavaCompile) {
1343 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1344 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001345 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1346 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001347 sourceCompatibility = JavaVersion.VERSION_1_8
1348 targetCompatibility = JavaVersion.VERSION_1_8
1349 }
1350 examplesProtoDir.eachDir { dir ->
1351 def name = dir.getName()
1352 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1353 archiveName = "${name}.jar"
1354 destinationDir = examplesProtoOutputDir
1355 from "build/test/examplesProto/classes"
1356 include name + "/**/*.class"
1357 }
1358 dependsOn "jar_examples_proto_${name}"
1359 }
1360}
1361
Lars Bakc91e87e2017-08-18 08:53:10 +02001362// Proto lite generated code yields warnings when compiling with javac.
1363// We change the options passed to javac to ignore it.
1364compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1365
Søren Gjesse7320ce52018-05-07 15:45:22 +02001366
Mads Ager418d1ca2017-05-22 09:35:49 +02001367task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001368 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001369 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001370 def proguardScript
1371 if (OperatingSystem.current().isWindows()) {
1372 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1373 } else {
1374 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1375 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001376 task extractExamplesRuntime(type: Sync) {
1377 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001378 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001379 include "**/*.class"
1380 includeEmptyDirs false
1381 into "$buildDir/runtime/examples/"
1382 }
1383
Søren Gjesse7320ce52018-05-07 15:45:22 +02001384 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1385 from examplesDir
1386 exclude "**/*.java"
1387 exclude "**/keep-rules*.txt"
1388 into file("build/test/examples/classes")
1389 }
1390
1391 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001392 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001393 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001394 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001395 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001396 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001397 sourceCompatibility = JavaVersion.VERSION_1_7
1398 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001399 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1400 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001401 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1402 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001403 include "**/*.java"
1404 destinationDir = file("build/test/examples/classes_debuginfo_all")
1405 classpath = sourceSets.examples.compileClasspath
1406 sourceCompatibility = JavaVersion.VERSION_1_7
1407 targetCompatibility = JavaVersion.VERSION_1_7
1408 options.compilerArgs = ["-g", "-Xlint:none"]
1409 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001410 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1411 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001412 include "**/*.java"
1413 destinationDir = file("build/test/examples/classes_debuginfo_none")
1414 classpath = sourceSets.examples.compileClasspath
1415 sourceCompatibility = JavaVersion.VERSION_1_7
1416 targetCompatibility = JavaVersion.VERSION_1_7
1417 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001418 }
1419 examplesDir.eachDir { dir ->
1420 def name = dir.getName();
1421 def exampleOutputDir = file("build/test/examples");
1422 def jarName = "${name}.jar"
1423 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001424 dependsOn "jar_example_${name}_debuginfo_all"
1425 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001426 dependsOn "extractExamplesRuntime"
1427 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001428 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1429 def proguardConfigPath = "${dir}/proguard.cfg"
1430 if (new File(proguardConfigPath).exists()) {
1431 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1432 archiveName = "${name}_pre_proguard.jar"
1433 destinationDir = exampleOutputDir
1434 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001435 include name + "/**/*.class"
1436 with runtimeDependencies
1437 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001438 }
1439 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1440 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1441 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1442 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001443 inputs.files files(
1444 tasks.getByPath("pre_proguard_example_${name}"),
1445 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001446 // Enable these to get stdout and stderr redirected to files...
1447 // standardOutput = new FileOutputStream('proguard.stdout')
1448 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001449 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001450 " -outjars ${proguardJarPath}" +
1451 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001452 " -printmapping ${proguardMapPath}"
1453 if (OperatingSystem.current().isWindows()) {
1454 executable "${proguardScript}"
1455 args "${proguardArguments}"
1456 } else {
1457 executable "bash"
1458 args "-c", "${proguardScript} '${proguardArguments}'"
1459 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001460 outputs.file proguardJarPath
1461 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001462 // TODO: Consider performing distinct proguard compilations.
1463 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1464 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001465 into "${exampleOutputDir}"
1466 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001467 }
1468 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1469 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001470 into "${exampleOutputDir}"
1471 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001472 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001473 } else {
1474 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001475 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001476 destinationDir = exampleOutputDir
1477 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001478 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001479 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001480 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001481 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001482 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1483 archiveName = "${name}_debuginfo_all.jar"
1484 destinationDir = exampleOutputDir
1485 from "build/test/examples/classes_debuginfo_all"
1486 include name + "/**/*.class"
1487 with runtimeDependencies
1488 includeEmptyDirs false
1489 }
1490 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1491 archiveName = "${name}_debuginfo_none.jar"
1492 destinationDir = exampleOutputDir
1493 from "build/test/examples/classes_debuginfo_none"
1494 include name + "/**/*.class"
1495 with runtimeDependencies
1496 includeEmptyDirs false
1497 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001498 }
1499 }
1500}
1501
1502task buildExampleAndroidNJars {
1503 dependsOn downloadDeps
1504 def examplesDir = file("src/test/examplesAndroidN")
1505 task "compile_examplesAndroidN"(type: JavaCompile) {
1506 source = fileTree(dir: examplesDir, include: '**/*.java')
1507 destinationDir = file("build/test/examplesAndroidN/classes")
1508 classpath = sourceSets.main.compileClasspath
1509 sourceCompatibility = JavaVersion.VERSION_1_8
1510 targetCompatibility = JavaVersion.VERSION_1_8
1511 options.compilerArgs += ["-Xlint:-options"]
1512 }
1513 examplesDir.eachDir { dir ->
1514 def name = dir.getName();
1515 def exampleOutputDir = file("build/test/examplesAndroidN");
1516 def jarName = "${name}.jar"
1517 dependsOn "jar_examplesAndroidN_${name}"
1518 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1519 archiveName = jarName
1520 destinationDir = exampleOutputDir
1521 from "build/test/examplesAndroidN/classes"
1522 include "**/" + name + "/**/*.class"
1523 }
1524 }
1525}
1526
1527
1528task buildExampleAndroidOJars {
1529 dependsOn downloadDeps
1530 def examplesDir = file("src/test/examplesAndroidO")
1531 // NOTE: we want to enable a scenario when test needs to reference some
1532 // classes generated by legacy (1.6) Java compiler to test some specific
1533 // behaviour. To do so we compile all the java files located in sub-directory
1534 // called 'legacy' with Java 1.6, then compile the rest of the files with
1535 // Java 1.8 and a reference to previously generated 1.6 classes.
1536
1537 // Compiling all classes in dirs 'legacy' with old Java version.
1538 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1539 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1540 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1541 classpath = sourceSets.main.compileClasspath
1542 sourceCompatibility = JavaVersion.VERSION_1_6
1543 targetCompatibility = JavaVersion.VERSION_1_6
1544 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1545 }
1546 // Compiling the rest of the files as Java 1.8 code.
1547 task "compile_examplesAndroidO"(type: JavaCompile) {
1548 dependsOn "compile_examplesAndroidO_Legacy"
1549 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1550 destinationDir = file("build/test/examplesAndroidO/classes")
1551 classpath = sourceSets.main.compileClasspath
1552 classpath += files("build/test/examplesAndroidOLegacy/classes")
1553 sourceCompatibility = JavaVersion.VERSION_1_8
1554 targetCompatibility = JavaVersion.VERSION_1_8
1555 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1556 }
1557 examplesDir.eachDir { dir ->
1558 def name = dir.getName();
1559 def destinationDir = file("build/test/examplesAndroidO/classes");
1560 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1561 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1562 dependsOn: "compile_examplesAndroidO") {
1563 main = name + ".TestGenerator"
1564 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1565 args destinationDir
1566 }
1567 } else {
1568 task "generate_examplesAndroidO_${name}" () {}
1569 }
1570 }
1571 examplesDir.eachDir { dir ->
1572 def name = dir.getName();
1573 def exampleOutputDir = file("build/test/examplesAndroidO");
1574 def jarName = "${name}.jar"
1575 dependsOn "jar_examplesAndroidO_${name}"
1576 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1577 "generate_examplesAndroidO_${name}"]) {
1578 archiveName = jarName
1579 destinationDir = exampleOutputDir
1580 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1581 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1582 include "**/" + name + "/**/*.class"
1583 // Do not include generator into the test runtime jar, it is not useful.
1584 // Otherwise, shrinking will need ASM jars.
1585 exclude "**/TestGenerator*"
1586 }
1587 }
1588}
1589
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001590task buildExampleAndroidPJars {
1591 dependsOn downloadDeps
1592 def examplesDir = file("src/test/examplesAndroidP")
1593
1594 task "compile_examplesAndroidP"(type: JavaCompile) {
1595 source = fileTree(dir: examplesDir, include: '**/*.java')
1596 destinationDir = file("build/test/examplesAndroidP/classes")
1597 classpath = sourceSets.main.compileClasspath
1598 sourceCompatibility = JavaVersion.VERSION_1_8
1599 targetCompatibility = JavaVersion.VERSION_1_8
1600 options.compilerArgs += ["-Xlint:-options"]
1601 }
1602 examplesDir.eachDir { dir ->
1603 def name = dir.getName();
1604 def destinationDir = file("build/test/examplesAndroidP/classes");
1605 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1606 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1607 dependsOn: "compile_examplesAndroidP") {
1608 main = name + ".TestGenerator"
1609 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1610 args destinationDir
1611 }
1612 } else {
1613 task "generate_examplesAndroidP_${name}" () {}
1614 }
1615 }
1616 examplesDir.eachDir { dir ->
1617 def name = dir.getName();
1618 def exampleOutputDir = file("build/test/examplesAndroidP");
1619 def jarName = "${name}.jar"
1620 dependsOn "jar_examplesAndroidP_${name}"
1621 task "jar_examplesAndroidP_${name}"(type: Jar,
1622 dependsOn: ["compile_examplesAndroidP",
1623 "generate_examplesAndroidP_${name}"]) {
1624 archiveName = jarName
1625 destinationDir = exampleOutputDir
1626 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1627 include "**/" + name + "/**/*.class"
1628 // Do not include generator into the test runtime jar, it is not useful.
1629 // Otherwise, shrinking will need ASM jars.
1630 exclude "**/TestGenerator*"
1631 }
1632 }
1633}
1634
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001635def buildExampleJarsCreateTask(javaVersion, sourceSet) {
1636 return tasks.create("buildExample${javaVersion}Jars") {
1637 def examplesDir = file("src/test/examples${javaVersion}")
1638 examplesDir.eachDir { dir ->
1639 def name = dir.getName();
1640 def exampleOutputDir = file("build/test/examples${javaVersion}");
1641 def jarName = "${name}.jar"
1642 dependsOn "jar_examples${javaVersion}_${name}"
1643 task "jar_examples${javaVersion}_${name}"(type: Jar) {
1644 archiveName = jarName
1645 destinationDir = exampleOutputDir
1646 from sourceSet.output
1647 include "**/" + name + "/**/*.class"
1648 }
Mikaël Peltier61633d42017-10-13 16:51:06 +02001649 }
1650 }
1651}
1652
Morten Krogh-Jespersen0ed04d42020-11-25 15:46:21 +01001653buildExampleJarsCreateTask("Java9", sourceSets.examplesJava9)
1654buildExampleJarsCreateTask("Java10", sourceSets.examplesJava10)
1655buildExampleJarsCreateTask("Java11", sourceSets.examplesJava11)
Søren Gjessee9966932021-09-15 17:08:37 +02001656buildExampleJarsCreateTask("Java17", sourceSets.examplesJava17)
Søren Gjessed1e08992022-02-07 16:46:31 +01001657buildExampleJarsCreateTask("Java18", sourceSets.examplesJava18)
clementberad7ab1dd2019-04-16 16:05:00 +02001658
clementberaa92e3cd2019-07-12 14:13:22 +02001659task provideArtFrameworksDependencies {
1660 cloudDependencies.tools.forEach({ art ->
1661 if (art.contains("art")) {
1662 def taskName = art.replace('/','_')
1663 dependsOn "patch_${taskName}"
1664 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1665 from "tools/${art}/framework"
1666 include "**.jar"
1667 into file("tools/${art}/out/host/linux-x86/framework")
1668 }
1669 }
1670 })
1671}
1672
Sebastien Hertzd3313772018-01-16 14:12:37 +01001673task buildKotlinR8TestResources {
1674 def examplesDir = file("src/test/kotlinR8TestResources")
1675 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001676 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1677 def name = dir.getName()
1678 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001679 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001680 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001681 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001682 task "${taskName}Java"(type: JavaCompile) {
1683 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1684 destinationDir = file(javaOutput)
1685 classpath = sourceSets.main.compileClasspath
1686 sourceCompatibility = JavaVersion.VERSION_1_6
1687 targetCompatibility = JavaVersion.VERSION_1_6
1688 options.compilerArgs += ["-g", "-Xlint:-options"]
1689 }
1690 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1691 archiveName = javaOutputJarName
1692 destinationDir = file(javaOutputJarDir)
1693 from javaOutput
1694 include "**/*.class"
1695 }
Morten Krogh-Jespersen358c8a72021-02-24 11:07:57 +01001696 dependsOn "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001697 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001698 }
1699}
1700
Mads Ager418d1ca2017-05-22 09:35:49 +02001701task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001702 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1703 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1704 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001705 } else if (!OperatingSystem.current().isLinux()) {
1706 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001707 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001708 return;
1709 }
1710 dependsOn buildDebugTestResourcesJars
1711 dependsOn buildExampleJars
1712 dependsOn buildExampleAndroidNJars
1713 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001714 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001715 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001716 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001717 dependsOn buildExampleJava11Jars
Søren Gjessee9966932021-09-15 17:08:37 +02001718 dependsOn buildExampleJava17Jars
Søren Gjessed1e08992022-02-07 16:46:31 +01001719 dependsOn buildExampleJava18Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001720 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001721 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001722 def noDexTests = [
1723 "multidex",
1724 "multidex002",
1725 "multidex004",
1726 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001727 examplesDir.eachDir { dir ->
1728 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001729 if (!(name in noDexTests)) {
1730 dependsOn "dex_example_${name}"
1731 def exampleOutputDir = file("build/test/examples/" + name);
1732 def dexPath = file("${exampleOutputDir}")
1733 def debug = (name == "throwing")
1734 if (!dexPath.exists()) {
1735 dexPath.mkdirs()
1736 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001737 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001738 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1739 destination = dexPath
1740 debug = debug
1741 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001742 }
1743 }
1744}
1745
1746task buildSmali {
1747 def smaliDir = file("src/test/smali")
1748 smaliDir.eachDirRecurse() { dir ->
1749 def name = dir.getName();
1750 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1751 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1752 smaliOutputDir.mkdirs()
1753 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001754 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001755 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1756 def javaFiles = fileTree(dir: dir, include: '*.java')
1757 def destDir = smaliOutputDir;
1758 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1759 def intermediateFileName = "${name}-intermediate.dex";
1760 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1761 if (javaFiles.empty) {
1762 if (!smaliFiles.empty) {
1763 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001764 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001765 source = smaliFiles
1766 destination = destFile
1767 }
1768 }
1769 } else {
Rico Wind01c15c62021-04-22 17:30:41 +00001770 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001771 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001772 source = smaliFiles
1773 destination = intermediateFile
1774 }
1775 task "${taskName}_java"(type: JavaCompile) {
1776 source = javaFiles
1777 destinationDir destDir
1778 classpath = sourceSets.main.compileClasspath
1779 sourceCompatibility = JavaVersion.VERSION_1_7
1780 targetCompatibility = JavaVersion.VERSION_1_7
1781 options.compilerArgs += ["-Xlint:-options"]
1782 }
1783 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1784 archiveName = "Test.jar"
1785 destinationDir = destDir
1786 from fileTree(dir: destDir, include: 'Test.class')
1787 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001788 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001789 source = fileTree(dir: destDir, include: 'Test.jar')
1790 destination = destDir
1791 }
1792 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001793 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001794 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1795 destination = destFile
1796 }
1797 }
1798 }
1799}
1800
1801tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001802 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001803 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001804 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001805 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001806 if (userDefinedCoresPerFork) {
1807 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1808 } else {
1809 // On normal work machines this seems to give the best test execution time (without freezing)
Rico Wind3d4113e2021-09-30 07:50:43 +02001810 maxParallelForks = processors.intdiv(3) ?: 1
1811 // On low cpu count machines (bots) we under subscribe, so increase the count.
1812 if (processors == 8) {
Rico Wind59f7fb02021-10-25 09:01:39 +02001813 maxParallelForks = 3
Rico Wind3d4113e2021-09-30 07:50:43 +02001814 }
Rico Wind73da9f12019-09-19 09:27:07 +02001815 }
Rico Windc56f21c2019-03-12 07:29:57 +01001816 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001817
Mads Ager418d1ca2017-05-22 09:35:49 +02001818 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001819 if (project.hasProperty('disable_assertions')) {
1820 enableAssertions = false
1821 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001822 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001823 if (project.hasProperty('test_xmx')) {
1824 maxHeapSize = project.property('test_xmx')
1825 } else {
1826 maxHeapSize = "4G"
1827 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001828}
1829
1830task buildPreNJdwpTestsJar(type: Jar) {
Morten Krogh-Jespersenfe0edea2021-12-20 13:36:45 +01001831 archiveFileName = 'jdwp-tests-preN.jar'
Mads Ager418d1ca2017-05-22 09:35:49 +02001832 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1833 // Exclude the classes containing java8
1834 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1835 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1836 includeEmptyDirs = false
1837}
1838
Ian Zerny74143162017-11-24 13:46:35 +01001839task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1840 def inFile = buildPreNJdwpTestsJar.archivePath
1841 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001842 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001843 outputs.file outFile
1844 if (OperatingSystem.current().isWindows()) {
1845 executable file("tools/windows/dx/bin/dx.bat")
1846 } else if (OperatingSystem.current().isMacOsX()) {
1847 executable file("tools/mac/dx/bin/dx");
1848 } else {
1849 executable file("tools/linux/dx/bin/dx");
1850 }
1851 args "--dex"
1852 args "--output=${outFile}"
1853 args inFile
1854}
1855
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001856task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1857 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001858}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001859
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001860task generateR8TestKeepRules {
1861 def path = "build/generated/r8tests-keep.txt"
1862 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001863 dependsOn R8Lib
1864 doLast {
1865 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001866-dontshrink
1867-dontoptimize
1868-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001869-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001870"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001871 }
1872}
1873
1874task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001875 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1876 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001877 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001878 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001879 dependsOn generateR8TestKeepRules
1880 dependsOn testJar
1881 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1882 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1883 return pkg.toString().endsWith(".jar")
1884 } + ["${buildDir}/classes/java/test"]
1885 inputs.files testJar.outputs.files +
1886 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001887 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001888 commandLine = r8CfCommandLine(
1889 testJar.outputs.files[0],
1890 outputPath,
1891 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001892 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1893 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001894 workingDir = projectDir
1895 outputs.file outputPath
1896}
1897
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001898task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001899 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001900 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001901 dependsOn R8Lib
1902 delete r8LibTestPath
1903 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1904 def examplesDir = file("build/test")
1905 examplesDir.eachDir { dir ->
1906 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001907 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001908 from ("${buildDir}/runtime/examples")
1909 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001910 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001911}
1912
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001913def shouldRetrace() {
1914 return project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')
1915}
1916
1917def retrace(Throwable exception) {
1918 def out = new StringBuffer()
1919 def err = new StringBuffer()
Ian Zerny99613a02022-02-23 11:50:13 +01001920 def command = "python3 tools/retrace.py --quiet"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001921 def header = "RETRACED STACKTRACE";
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001922 out.append("\n--------------------------------------\n")
1923 out.append("${header}\n")
1924 out.append("--------------------------------------\n")
1925 Process process = command.execute()
1926 def processIn = new PrintStream(process.getOut())
1927 process.consumeProcessOutput(out, err)
1928 exception.printStackTrace(processIn)
1929 processIn.flush()
1930 processIn.close()
1931 def errorDuringRetracing = process.waitFor() != 0
1932 if (errorDuringRetracing) {
1933 out.append("ERROR DURING RETRACING\n")
1934 out.append(err.toString())
1935 }
1936 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1937 out.append("\n\n--------------------------------------\n")
1938 out.append("OBFUSCATED STACKTRACE\n")
1939 out.append("--------------------------------------\n")
1940 }
1941 return out.toString()
1942}
1943
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001944def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001945 filterStackTraces(result)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001946 if (shouldRetrace()) {
1947 def exception = new Exception(retrace(result.exception))
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001948 exception.setStackTrace([] as StackTraceElement[])
1949 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001950 }
1951}
1952
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001953def filterStackTraces(TestResult result) {
1954 for (Throwable throwable : result.getExceptions()) {
1955 filterStackTrace(throwable)
1956 }
1957}
1958
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001959// It would be nice to do this in a non-destructive way...
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001960def filterStackTrace(Throwable exception) {
1961 if (!project.hasProperty('print_full_stacktraces')) {
1962 def elements = []
1963 def skipped = []
1964 for (StackTraceElement element : exception.getStackTrace()) {
1965 if (element.toString().contains("com.android.tools.r8")) {
1966 elements.addAll(skipped)
1967 elements.add(element)
1968 skipped.clear()
1969 } else {
1970 skipped.add(element)
1971 }
1972 }
1973 exception.setStackTrace(elements as StackTraceElement[])
1974 }
1975}
1976
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001977def printAllStackTracesToFile(List<Throwable> exceptions, File out) {
1978 new PrintStream(new FileOutputStream(out)).withCloseable {printer ->
1979 exceptions.forEach { it.printStackTrace(printer) }
1980 }
1981}
1982
Ian Zerny89f16cf2021-04-29 21:10:09 +02001983static def escapeHtml(String string) {
1984 return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
1985}
1986
1987static def urlEncode(String string) {
1988 // Not sure why, but the + also needs to be converted to have working links.
1989 return URLEncoder.encode(string, "UTF-8").replace("+","%20")
1990}
1991
Ian Zerny9a0e96a2021-04-28 12:35:49 +02001992def ensureDir(File dir) {
1993 dir.mkdirs()
1994 return dir
1995}
1996
Ian Zerny89f16cf2021-04-29 21:10:09 +02001997// Some of our test parameters have new lines :-( We really don't want test names to span lines.
1998static def sanitizedTestName(testDesc) {
1999 if (testDesc.getName().contains("\n")) {
2000 throw new RuntimeException("Unsupported use of newline in test name: '${testDesc.getName()}'")
2001 }
2002 return testDesc.getName()
2003}
2004
2005static def desanitizedTestName(testName) {
2006 return testName
2007}
2008
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002009def getTestReportEntryDir(reportDir, testDesc) {
2010 return ensureDir(reportDir.toPath()
2011 .resolve(testDesc.getClassName())
Ian Zerny89f16cf2021-04-29 21:10:09 +02002012 .resolve(sanitizedTestName(testDesc))
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002013 .toFile())
2014}
2015
Ian Zerny89f16cf2021-04-29 21:10:09 +02002016def getTestReportEntryURL(reportDir, testDesc) {
2017 def classDir = urlEncode(testDesc.getClassName())
2018 def testDir = urlEncode(sanitizedTestName(testDesc))
2019 return "file://${reportDir}/${classDir}/${testDir}"
2020}
2021
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002022def getTestResultEntryOutputFile(reportDir, testDesc, fileName) {
2023 def dir = getTestReportEntryDir(reportDir, testDesc).toPath()
2024 return dir.resolve(fileName).toFile()
2025}
2026
Ian Zerny89f16cf2021-04-29 21:10:09 +02002027def withTestResultEntryWriter(reportDir, testDesc, fileName, append, fn) {
2028 def file = getTestResultEntryOutputFile(reportDir, testDesc, fileName)
2029 new FileWriter(file, append).withCloseable fn
2030}
2031
Ian Zerny27ea4c72021-04-29 22:35:49 +02002032static def getGitBranchName() {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002033 def out = new StringBuilder()
2034 def err = new StringBuilder()
2035 def proc = "git rev-parse --abbrev-ref HEAD".execute()
2036 proc.waitForProcessOutput(out, err)
Ian Zerny27ea4c72021-04-29 22:35:49 +02002037 return out.toString().trim()
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002038}
2039
Ian Zerny27ea4c72021-04-29 22:35:49 +02002040static def getFreshTestReportIndex(File reportDir) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002041 def number = 0
2042 while (true) {
2043 def freshIndex = reportDir.toPath().resolve("index.${number++}.html").toFile()
2044 if (!freshIndex.exists()) {
2045 return freshIndex
2046 }
2047 }
2048}
2049
2050def forEachTestReportAlreadyX(File reportDir, fileName, onTest) {
2051 def out = new StringBuilder()
2052 def err = new StringBuilder()
2053 def proc = "find . -name ${fileName}".execute([], reportDir)
2054 proc.waitForProcessOutput(out, err)
2055 def outString = out.toString()
2056 outString.eachLine {
2057 // Lines are of the form: ./<class>/<name>/FAILURE
2058 def clazz = null
2059 def name = null
2060 try {
2061 def trimmed = it.trim()
2062 def line = trimmed.substring(2)
2063 def sep = line.indexOf("/")
2064 clazz = line.substring(0, sep)
2065 name = line.substring(sep + 1, line.length() - fileName.length() - 1)
2066 } catch (Exception e) {
2067 logger.lifecycle("WARNING: failed attempt to read test description from: '${it}'")
2068 return
2069 }
2070 onTest(clazz, desanitizedTestName(name))
2071 }
2072 return !outString.trim().isEmpty()
2073}
2074
2075def forEachTestReportAlreadyFailing(File reportDir, onFailureTest) {
2076 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.FAILURE.name(), onFailureTest)
2077}
2078
2079def forEachTestReportAlreadyPassing(File reportDir, onSucceededTest) {
2080 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SUCCESS.name(), onSucceededTest)
2081}
2082
2083def forEachTestReportAlreadySkipped(File reportDir, onSucceededTest) {
2084 return forEachTestReportAlreadyX(reportDir, TestResult.ResultType.SKIPPED.name(), onSucceededTest)
2085}
2086
Ian Zerny27ea4c72021-04-29 22:35:49 +02002087def setUpTestingState(Test task) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002088 // Hide all test events from the console, they are written to the report.
2089 task.testLogging { events = [] }
2090
Ian Zernycae764d2021-08-16 08:25:15 +02002091 def branch = project.hasProperty('testing-state-name')
2092 ? project.getProperty('testing-state-name')
2093 : getGitBranchName()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002094 def reportDir = file("${buildDir}/test-state/${branch}")
Ian Zerny89f16cf2021-04-29 21:10:09 +02002095 def index = reportDir.toPath().resolve("index.html").toFile()
Ian Zerny27ea4c72021-04-29 22:35:49 +02002096 def resetState = project.hasProperty('reset-testing-state')
2097 def reportDirExists = reportDir.exists()
2098 def resuming = !resetState && reportDirExists
Ian Zerny89f16cf2021-04-29 21:10:09 +02002099
2100 def hasFailingTests = false;
2101 if (resuming) {
2102 // Test filtering happens before the test execution is initiated so compute it here.
2103 // If there are still failing tests in the report, include only those.
2104 hasFailingTests = forEachTestReportAlreadyFailing(reportDir, {
2105 clazz, name -> task.filter.includeTestsMatching("$clazz.$name")
2106 })
2107 // Otherwise exclude all of the test already marked as succeeding.
2108 if (!hasFailingTests) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002109 // Also allow the test to overall succeed if there are no remaining tests that match,
2110 // which is natural if the state already succeeded in full.
2111 task.filter.failOnNoMatchingTests = false
Ian Zerny89f16cf2021-04-29 21:10:09 +02002112 forEachTestReportAlreadyPassing(reportDir, {
2113 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2114 })
2115 forEachTestReportAlreadySkipped(reportDir, {
2116 clazz, name -> task.filter.excludeTestsMatching("$clazz.$name")
2117 })
2118 }
2119 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002120
2121 task.beforeSuite { desc ->
2122 if (!desc.parent) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002123 def parentReport = null
Ian Zerny27ea4c72021-04-29 22:35:49 +02002124 if (resetState && reportDirExists) {
2125 delete reportDir
2126 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002127 if (resuming) {
2128 if (index.exists()) {
2129 parentReport = getFreshTestReportIndex(reportDir)
2130 index.renameTo(parentReport)
2131 }
2132 } else {
2133 reportDir.mkdirs()
2134 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002135 def runPrefix = resuming ? "Resuming" : "Starting"
2136 def title = "${runPrefix} @ ${branch}"
2137 // Print a console link to the test report for easy access.
2138 println "${runPrefix} test, report written to:"
2139 println " file://${index}"
2140 // Print the new index content.
2141 index << "<html><head><title>${title}</title>"
2142 index << "<style> * { font-family: monospace; }</style>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002143 index << "<meta http-equiv='refresh' content='10' />"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002144 index << "</head><body><h1>${title}</h1>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002145 index << "<p>Run on: ${new Date()}</p>"
2146 index << "<p>Git branch: ${branch}</p>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002147 if (parentReport != null) {
2148 index << "<p><a href=\"file://${parentReport}\">Previous result index</a></p>"
2149 }
2150 index << "<p><a href=\"file://${index}\">Most recent result index</a></p>"
2151 index << "<p><a href=\"file://${reportDir}\">Test directories</a></p>"
Morten Krogh-Jespersende7ddfa2021-09-03 12:37:32 +02002152 index << "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002153 }
2154 }
2155
2156 task.afterSuite { desc, result ->
2157 if (!desc.parent) {
2158 // Update the final test results in the index.
2159 index << "</ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002160 if (result.resultType == TestResult.ResultType.SUCCESS) {
2161 if (hasFailingTests) {
2162 index << "<h2>Rerun of failed tests now pass!</h2>"
2163 index << "<h2>Rerun again to continue with outstanding tests!</h2>"
2164 } else {
2165 index << "<h2 style=\"background-color:#62D856\">GREEN BAR == YOU ROCK!</h2>"
2166 }
2167 } else if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny27ea4c72021-04-29 22:35:49 +02002168 index << "<h2 style=\"background-color:#6D130A\">Some tests failed: ${result.resultType.name()}</h2><ul>"
Ian Zerny89f16cf2021-04-29 21:10:09 +02002169 } else {
2170 index << "<h2>Tests finished: ${result.resultType.name()}</h2><ul>"
2171 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002172 index << "<li>Number of tests: ${result.testCount}"
2173 index << "<li>Failing tests: ${result.failedTestCount}"
2174 index << "<li>Successful tests: ${result.successfulTestCount}"
2175 index << "<li>Skipped tests: ${result.skippedTestCount}"
2176 index << "</ul></body></html>"
2177 }
2178 }
2179
2180 // Events to stdout/err are appended to the files in the test directories.
2181 task.onOutput { desc, event ->
Ian Zerny89f16cf2021-04-29 21:10:09 +02002182 withTestResultEntryWriter(reportDir, desc, event.getDestination().name(), true, {
2183 it.append(event.getMessage())
2184 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002185 }
2186
Ian Zerny27ea4c72021-04-29 22:35:49 +02002187 task.beforeTest { desc ->
2188 // Remove any stale output files before running the test.
2189 for (def destType : TestOutputEvent.Destination.values()) {
2190 def destFile = getTestResultEntryOutputFile(reportDir, desc, destType.name())
2191 if (destFile.exists()) {
2192 delete destFile
2193 }
2194 }
2195 }
2196
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002197 task.afterTest { desc, result ->
2198 if (result.getTestCount() != 1) {
2199 throw new IllegalStateException("Unexpected test with more than one result: ${desc}")
2200 }
Ian Zerny89f16cf2021-04-29 21:10:09 +02002201 // Clear any previous result files.
2202 for (def resultType : TestResult.ResultType.values()) {
2203 delete getTestResultEntryOutputFile(reportDir, desc, resultType.name())
2204 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002205 // Emit the result type status in a file of the same name: SUCCESS, FAILURE or SKIPPED.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002206 withTestResultEntryWriter(reportDir, desc, result.getResultType().name(), false, {
2207 it.append(result.getResultType().name())
2208 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002209 // Emit the test time.
Ian Zerny89f16cf2021-04-29 21:10:09 +02002210 withTestResultEntryWriter(reportDir, desc, "time", false, {
2211 it.append("${result.getEndTime() - result.getStartTime()}")
2212 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002213 // For failed tests, update the index and emit stack trace information.
2214 if (result.resultType == TestResult.ResultType.FAILURE) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002215 def title = escapeHtml("${desc.className}.${desc.name}")
2216 def link = getTestReportEntryURL(reportDir, desc)
2217 index << "<li><a href=\"${link}\">${title}</a></li>"
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002218 if (!result.exceptions.isEmpty()) {
2219 printAllStackTracesToFile(
2220 result.exceptions,
2221 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002222 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002223 desc,
2224 "exceptions-raw.txt"))
2225 filterStackTraces(result)
2226 printAllStackTracesToFile(
2227 result.exceptions,
2228 getTestResultEntryOutputFile(
Ian Zerny89f16cf2021-04-29 21:10:09 +02002229 reportDir,
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002230 desc,
2231 "exceptions-filtered.txt"))
2232 if (shouldRetrace()) {
Ian Zerny89f16cf2021-04-29 21:10:09 +02002233 withTestResultEntryWriter(reportDir, desc, "exceptions-retraced.txt", false, { writer ->
2234 result.exceptions.forEach { writer.append(retrace(it)) }
2235 })
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002236 }
2237 }
2238 }
2239 }
2240}
2241
Rico Windf2f4c292021-04-23 07:06:13 +02002242def testTimes = [:]
Ian Zerny475e4012021-04-29 14:01:49 +02002243def numberOfTestTimesToPrint = 100
Rico Windf2f4c292021-04-23 07:06:13 +02002244
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002245test { task ->
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002246
2247 dependsOn buildLibraryDesugarConversions
2248 dependsOn getJarsFromSupportLibs
2249 // R8.jar is required for running bootstrap tests.
2250 dependsOn r8
2251
Ian Zerny27ea4c72021-04-29 22:35:49 +02002252 def useTestingState = project.hasProperty('testing-state')
2253 if (useTestingState) {
2254 setUpTestingState(task)
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002255 }
2256
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02002257 if (project.hasProperty('generate_golden_files_to')) {
2258 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
2259 assert project.hasProperty('HEAD_sha1')
2260 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2261 }
2262
2263 if (project.hasProperty('use_golden_files_in')) {
2264 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
2265 assert project.hasProperty('HEAD_sha1')
2266 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
2267 }
Ian Zerny4b0de282019-06-28 09:32:24 +02002268
Morten Krogh-Jespersendcb967e2021-12-02 11:18:39 +01002269 if (project.hasProperty('kotlin_compiler_dev')) {
2270 systemProperty 'com.android.tools.r8.kotlincompilerdev', '1';
2271 }
2272
2273 if (project.hasProperty('kotlin_compiler_old')) {
2274 systemProperty 'com.android.tools.r8.kotlincompilerold', '1';
2275 }
Morten Krogh-Jespersen52a26852021-04-28 16:20:36 +02002276
Ian Zerny27ea4c72021-04-29 22:35:49 +02002277 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002278 testLogging.exceptionFormat = 'full'
2279 if (project.hasProperty('print_test_stdout')) {
2280 testLogging.showStandardStreams = true
2281 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002282 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002283 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01002284 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002285 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02002286 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02002287
Ian Zerny324d7612019-03-20 10:52:28 +01002288 // Forward runtime configurations for test parameters.
2289 if (project.hasProperty('runtimes')) {
2290 println "NOTE: Running with runtimes: " + project.property('runtimes')
2291 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01002292 }
2293
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02002294 if (project.hasProperty('slow_tests')) {
2295 systemProperty 'slow_tests', project.property('slow_tests')
2296 }
2297
Søren Gjesseef195772021-03-11 16:04:42 +01002298
2299 if (project.hasProperty('desugar_jdk_json_dir')) {
2300 systemProperty 'desugar_jdk_json_dir', project.property('desugar_jdk_json_dir')
2301 }
Søren Gjesse4a45f9b2021-02-11 14:05:29 +01002302 if (project.hasProperty('desugar_jdk_libs')) {
2303 systemProperty 'desugar_jdk_libs', project.property('desugar_jdk_libs')
2304 }
2305
Ian Zerny27ea4c72021-04-29 22:35:49 +02002306 if (!useTestingState) {
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002307 if (project.hasProperty('print_times') || project.hasProperty('one_line_per_test')) {
2308 afterTest { desc, result ->
2309 def executionTime = (result.endTime - result.startTime) / 1000
2310 testTimes["${desc.name} [${desc.className}]"] = executionTime
2311 }
2312 afterSuite { desc, result ->
2313 // parent is null if all tests are done.
2314 if (desc.parent == null) {
2315 def sortedTimes = testTimes.sort({ e1, e2 -> e2.value <=> e1.value })
2316 sortedTimes.eachWithIndex { key, value, i ->
2317 if (i < numberOfTestTimesToPrint) println "$key: $value"
2318 }
2319 }
2320 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002321 }
Rico Windf2f4c292021-04-23 07:06:13 +02002322
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002323 if (project.hasProperty('one_line_per_test')) {
2324 beforeTest { desc ->
2325 println "Start executing test ${desc.name} [${desc.className}]"
Rico Windf88b6be2018-12-11 15:14:05 +01002326 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002327
2328 afterTest { desc, result ->
2329 if (result.resultType == TestResult.ResultType.FAILURE) {
2330 printStackTrace(result)
2331 }
2332 if (project.hasProperty('update_test_timestamp')) {
2333 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
2334 }
2335 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
Rico Windda6836e2018-12-07 12:32:03 +01002336 }
Ian Zerny9a0e96a2021-04-28 12:35:49 +02002337 } else {
2338 afterTest { desc, result ->
2339 if (result.resultType == TestResult.ResultType.FAILURE) {
2340 printStackTrace(result)
2341 }
Rico Windf88b6be2018-12-11 15:14:05 +01002342 }
2343 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002344 }
2345 if (project.hasProperty('no_internal')) {
2346 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02002347 } else {
2348 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002349 }
2350 if (project.hasProperty('only_internal')) {
2351 include "com/android/tools/r8/internal/**"
2352 }
Rico Wind4e218292019-03-07 12:44:49 +01002353
Rico Windba151112020-10-01 08:16:33 +02002354 if (project.hasProperty('test_namespace')) {
2355 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2356 }
2357
Ian Zerny3ced9262022-03-29 11:06:02 +02002358 if (project.hasProperty('tool') && project.property('tool') == 'd8') {
2359 // Don't run anything, deprecated
2360 println "Running with deprecated tool d8, not running any tests"
2361 include ""
Mads Ager418d1ca2017-05-22 09:35:49 +02002362 }
2363 if (!project.hasProperty('all_tests')) {
2364 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002365 }
Rico Windbc820812022-05-31 09:19:56 +02002366 if (project.hasProperty('no_arttests')) {
2367 exclude "com/android/tools/r8/art/**"
2368 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002369 if (project.hasProperty('shard_count') ) {
2370 assert project.hasProperty('shard_number')
2371 int shard_count = project.getProperty('shard_count') as Integer
2372 int shard_number = project.getProperty('shard_number') as Integer
2373 assert shard_count < 65536
2374 assert shard_number < shard_count
2375 exclude {
2376 entry ->
2377 // Don't leave out directories. Leaving out a directory means all entries below.
2378 if (entry.file.isDirectory()) {
2379 return false
2380 }
2381 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2382 int hash = Integer.parseInt(first4, 16)
2383 return hash % shard_count != shard_number
2384 }
2385 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002386 if (project.hasProperty('test_dir')) {
2387 systemProperty 'test_dir', project.property('test_dir')
2388 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002389 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002390 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002391 // R8lib should be used instead of the main output and all the tests in
2392 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002393 classpath = sourceSets.test.runtimeClasspath.filter {
2394 !it.getAbsolutePath().contains("/build/")
2395 }
2396 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002397 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002398 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002399 if (OperatingSystem.current().isLinux()
2400 || OperatingSystem.current().isMacOsX()
2401 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002402 if (OperatingSystem.current().isMacOsX()) {
2403 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2404 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2405 "See tools/docker/README.md for details.")
2406 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002407 if (OperatingSystem.current().isWindows()) {
2408 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2409 "Art only runs on Linux and tests requiring Art will be skipped")
2410 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002411 dependsOn downloadDeps
2412 dependsOn buildExamples
Sebastien Hertzd3313772018-01-16 14:12:37 +01002413 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002414 dependsOn buildSmali
Mads Ager418d1ca2017-05-22 09:35:49 +02002415 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002416 dependsOn buildPreNJdwpTestsDex
Clément Bérac94b6202021-09-28 11:16:58 +00002417 dependsOn compileTestNGRunner
clementberaa92e3cd2019-07-12 14:13:22 +02002418 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002419 } else {
2420 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002421 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002422 }
2423}
2424
2425// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2426//
2427// To build and upload a new set of the Art tests for use with R8 follow these steps:
2428//
2429// First of all an Android checkout is required. Currently it must be located
2430// in $HOME/android/master.
2431//
2432// TODO(ricow): simplify this
2433//
2434// Before: update the checked in art, see scripts/update-host-art.sh
2435//
2436// 1. Get an android checkout in $HOME/android/master and apply the patch from
2437// https://android-review.googlesource.com/#/c/294187/
2438//
2439// 2. run the following commands in the Android checkout directory:
2440//
2441// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002442// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2443// m desugar
2444// m -j30 test-art-host
2445// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2446//
2447// Without running the test.py command the classes.jar file used by desugar in
2448// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2449// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002450//
2451// 3. In the R8 project root directory, make sure we have a clean state before starting:
2452// tools/gradle.py downloadDeps
2453// tools/gradle.py clean
2454// rm -rf tests/art
2455//
2456// 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 +02002457// Make sure you have smali on your path, please use the build binary in the
2458// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2459// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2460// 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 +02002461// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2462// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002463//
Søren Gjesse34b77732017-07-07 13:56:21 +02002464// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002465//
2466// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2467// skippedTests with an explanation. Rerun from step 3.
2468//
2469// 5. Run the tests:
2470// tools/gradle.py clean
2471// tools/test.py
2472//
Søren Gjesse34b77732017-07-07 13:56:21 +02002473// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2474// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2475// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002476//
Søren Gjesse34b77732017-07-07 13:56:21 +02002477// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002478// cd tests
2479// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002480//
2481// 7. Update the manifest file describing the Android repo used:
2482// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002483
Mads Ager418d1ca2017-05-22 09:35:49 +02002484def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002485
2486def artTestDir = file("${androidCheckoutDir}/art/test")
2487
2488if (project.hasProperty('android_source')) {
2489 task buildArtTests {
2490 outputs.upToDateWhen { false }
2491 def toBeTriaged = [
2492 "903-hello-tagging",
2493 "904-object-allocation",
2494 "905-object-free",
2495 "906-iterate-heap",
2496 "907-get-loaded-classes",
2497 "908-gc-start-finish",
2498 "954-invoke-polymorphic-verifier",
2499 "955-methodhandles-smali",
2500 "596-monitor-inflation",
2501 ]
2502 def skippedTests = toBeTriaged + [
2503 // This test produces no jar.
2504 "000-nop",
2505 // This does not build, as it tests the error when the application exceeds more
2506 // than 65536 methods
2507 "089-many-methods",
2508 // Requires some jack beta jar
2509 "956-methodhandles",
2510 ]
2511
2512 def skippedTestsDx = [
2513 // Tests with custom build scripts, where javac is not passed the options
2514 // -source 1.7 -target 1.7.
2515 "462-checker-inlining-across-dex-files",
2516 "556-invoke-super",
2517 "569-checker-pattern-replacement",
2518 // These tests use jack even when --build-with-javac-dx is specified.
2519 "004-JniTest",
2520 "048-reflect-v8",
2521 "146-bad-interface",
2522 "563-checker-invoke-super",
2523 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2524 "604-hot-static-interface",
2525 "957-methodhandle-transforms",
2526 "958-methodhandle-emulated-stackframe",
2527 "959-invoke-polymorphic-accessors",
2528 "961-default-iface-resolution-gen",
2529 "962-iface-static",
2530 "963-default-range-smali",
2531 "964-default-iface-init-gen",
2532 "965-default-verify",
2533 "966-default-conflict",
2534 "967-default-ame",
2535 "968-default-partial-compile-gen",
2536 "969-iface-super",
2537 "970-iface-super-resolution-gen",
2538 "971-iface-super",
2539 // These tests does not build with --build-with-javac-dx
2540 "004-NativeAllocations", // Javac error
2541 "031-class-attributes",
2542 "138-duplicate-classes-check",
2543 "157-void-class", // Javac error
2544 "580-checker-string-factory-intrinsics",
2545 "612-jit-dex-cache",
2546 "613-inlining-dex-cache",
2547 "900-hello-plugin", // --experimental agents
2548 "901-hello-ti-agent", // --experimental agents
2549 "902-hello-transformation", // --experimental agents
2550 "909-attach-agent", // --experimental agents
2551 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2552 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2553 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2554 "960-default-smali", // --experimental default-methods
2555 // These tests force the build to use jack
2556 "953-invoke-polymorphic-compiler",
2557 "958-methodhandle-stackframe",
2558 ]
2559
2560 def artTestBuildDir = file("${projectDir}/tests/art")
2561
2562 if (androidCheckoutDir.exists()) {
2563 dependsOn downloadDeps
2564 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002565 artTestDir.eachDir { dir ->
2566 def name = dir.getName();
2567 def markerFile = dir.toPath().resolve("info.txt").toFile();
2568 if (markerFile.exists() && !(name in skippedTests)) {
2569 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002570 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002571 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002572 }
2573 }
2574 }
2575 doFirst {
2576 if (!androidCheckoutDir.exists()) {
2577 throw new InvalidUserDataException(
2578 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002579 }
2580 }
2581 doLast {
2582 copy {
2583 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2584 into file("${artTestBuildDir}/lib64")
2585 include 'lib*.so'
2586 }
2587 copy {
2588 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2589 into file("${artTestBuildDir}/lib64")
2590 include 'libart.so'
2591 include 'libbacktrace.so'
2592 include 'libbase.so'
2593 include 'libc++.so'
2594 include 'libcutils.so'
2595 include 'liblz4.so'
2596 include 'liblzma.so'
2597 include 'libnativebridge.so'
2598 include 'libnativeloader.so'
2599 include 'libsigchain.so'
2600 include 'libunwind.so'
2601 include 'libziparchive.so'
2602 }
2603 copy {
2604 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2605 into file("${artTestBuildDir}/lib")
2606 include 'lib*.so'
2607 }
2608 copy {
2609 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2610 into file("${artTestBuildDir}/lib")
2611 include 'libart.so'
2612 include 'libbacktrace.so'
2613 include 'libbase.so'
2614 include 'libc++.so'
2615 include 'libcutils.so'
2616 include 'liblz4.so'
2617 include 'liblzma.so'
2618 include 'libnativebridge.so'
2619 include 'libnativeloader.so'
2620 include 'libsigchain.so'
2621 include 'libunwind.so'
2622 include 'libziparchive.so'
2623 }
2624 }
2625 }
2626}
2627
Rico Windde2af6c2019-03-26 15:21:08 +01002628def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002629 def artTestDir = file("${androidCheckoutDir}/art/test")
2630 def artRunTestScript = file("${artTestDir}/run-test")
2631 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002632 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002633
Søren Gjesse34b77732017-07-07 13:56:21 +02002634 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002635 def buildTask = "build_art_test_dx_${name}"
2636 def sanitizeTask = "sanitize_art_test_dx_${name}"
2637 def copyCheckTask = "copy_check_art_test_dx_${name}"
2638 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002639
2640 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002641 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002642 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2643 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002644 task "$buildTask"(type: Exec) {
2645 outputs.upToDateWhen { false }
2646 inputs.file buildInputs
2647 executable "${artRunTestScript}"
2648 args "--host"
2649 args "--build-only"
2650 args "--build-with-javac-dx"
2651 args "--output-path", "${testDir}"
2652 args "${name}"
2653 environment DX: "${dxExecutable.absolutePath}"
2654 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2655 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2656 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002657 }
2658 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2659 outputs.upToDateWhen { false }
2660 executable "/bin/bash"
2661 args "-c"
2662 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2663 " ${testDir}/classes-ex ${testDir}/check"
2664 }
2665
2666 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002667 // Directory that contains smali files is either smali, or smali/art
2668 def smali_dir = file("${dir}/smali/art")
2669 if (smali_dir.exists()) {
2670 workingDir "${testDir}/smali/art"
2671 } else {
2672 workingDir "${testDir}/smali"
2673 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002674 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002675 // This is the command line options for smali prior to 2.2.1, where smali got a new
2676 // command line interface.
2677 args "-c", "smali a *.smali"
2678 // This is the command line options for smali 2.2.1 and later.
2679 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002680 }
2681
2682 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2683 def smali_dir = file("${dir}/smali")
2684 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002685 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002686 dependsOn smaliToDexTask
2687 }
2688 from("${artTestDir}/${name}") {
2689 include 'check'
2690 }
2691 into testDir
2692 }
2693
2694 return copyCheckTask
2695}
2696
2697task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002698 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002699 classpath = sourceSets.main.compileClasspath
2700 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002701 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002702 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002703 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002704 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002705 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002706 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002707 include '**/com/android/tools/r8/CompilationMode.java'
2708 include '**/com/android/tools/r8/D8.java'
2709 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002710 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2711 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002712 include '**/com/android/tools/r8/Diagnostic.java'
2713 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002714 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2715 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002716 include '**/com/android/tools/r8/ProgramConsumer.java'
2717 include '**/com/android/tools/r8/ProgramResource.java'
2718 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002719 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002720 include '**/com/android/tools/r8/ResourceException.java'
2721 include '**/com/android/tools/r8/StringConsumer.java'
2722 include '**/com/android/tools/r8/StringResource.java'
2723 include '**/com/android/tools/r8/Version.java'
2724 include '**/com/android/tools/r8/origin/*.java'
2725}
2726
2727task javadocR8(type: Javadoc) {
2728 title "R8 API"
2729 classpath = sourceSets.main.compileClasspath
2730 source = sourceSets.main.allJava
2731 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2732 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2733 include '**/com/android/tools/r8/BaseCommand.java'
2734 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2735 include '**/com/android/tools/r8/ClassFileConsumer.java'
2736 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2737 include '**/com/android/tools/r8/CompilationFailedException.java'
2738 include '**/com/android/tools/r8/CompilationMode.java'
2739 include '**/com/android/tools/r8/R8.java'
2740 include '**/com/android/tools/r8/R8Command.java'
2741 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2742 include '**/com/android/tools/r8/Diagnostic.java'
2743 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002744 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2745 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002746 include '**/com/android/tools/r8/ProgramConsumer.java'
2747 include '**/com/android/tools/r8/ProgramResource.java'
2748 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2749 include '**/com/android/tools/r8/Resource.java'
2750 include '**/com/android/tools/r8/ResourceException.java'
2751 include '**/com/android/tools/r8/StringConsumer.java'
2752 include '**/com/android/tools/r8/StringResource.java'
2753 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002754 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002755}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002756
2757task copyMavenDeps(type: Copy) {
2758 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002759 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002760 from configurations.testCompile into "$buildDir/deps"
2761}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002762
Rico Wind23a05112019-03-27 08:00:44 +01002763task printMavenDeps {
2764 // Only actually print to stdout when we are updating.
2765 if (project.hasProperty('updatemavendeps')) {
2766 for (Configuration config : configurations) {
2767 if (!config.isCanBeResolved()) {
2768 continue
2769 }
2770 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2771 it.selected.id
2772 }
2773 def result = dependencies.createArtifactResolutionQuery()
2774 .forComponents(componentIds)
2775 .withArtifacts(MavenModule, MavenPomArtifact)
2776 .execute()
2777 for (component in result.resolvedComponents) {
2778 component.getArtifacts(MavenPomArtifact).each {
2779 println "POM: ${it.file} ${component.id}"
2780 }
2781 }
2782 config.each {
2783 println "JAR: ${it}"
2784 }
2785 }
2786 }
2787}
Ian Zerny9713c032020-01-23 11:41:58 +01002788
2789allprojects {
2790 tasks.withType(Exec) {
2791 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002792 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002793 }
2794 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002795}