blob: 981dcfde833993490172336e6d4a94852a4e02d0 [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
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +00005import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Jake Wharton2d7aab82019-09-13 10:24:26 -04006import dx.DexMergerTask
7import dx.DxTask
Ian Zerny5fffb0a2019-02-11 13:54:22 +01008import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02009import org.gradle.internal.os.OperatingSystem
Jake Wharton2d7aab82019-09-13 10:24:26 -040010import smali.SmaliTask
Ian Zernyb2d27c42019-02-20 09:09:41 +010011import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000012import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020013import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020014
Ian Zerny5fffb0a2019-02-11 13:54:22 +010015buildscript {
16 repositories {
Rico Wind23a05112019-03-27 08:00:44 +010017 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010018 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010019 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010020 mavenCentral()
Jake Wharton5e5b5232019-09-17 16:13:32 -040021 gradlePluginPortal()
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010022 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010023 }
24 dependencies {
clementbera0bca05e2019-05-29 14:11:18 +020025 classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010026 }
27}
28
29plugins {
30 id "net.ltgt.errorprone" version "0.7"
31}
32
33apply plugin: 'java'
34apply plugin: 'idea'
35
Sebastien Hertz143ed112018-02-13 14:26:41 +010036ext {
37 androidSupportVersion = '25.4.0'
Morten Krogh-Jespersencd5ca142020-09-11 12:47:19 +020038 asmVersion = '8.0' // When updating update tools/asmifier.py and Toolhelper as well.
Sebastien Hertz143ed112018-02-13 14:26:41 +010039 espressoVersion = '3.0.0'
40 fastutilVersion = '7.2.0'
41 guavaVersion = '23.0'
42 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020043 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010044 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080045 mockitoVersion = '2.10.0'
Morten Krogh-Jespersen3e956732020-05-12 10:56:28 +020046 kotlinVersion = '1.3.72'
Jinseong Jeon20124782019-08-06 22:52:17 -070047 kotlinExtMetadataJVMVersion = '0.1.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 +020053apply from: 'copyAdditionalJctfCommonFiles.gradle'
54
55repositories {
Rico Wind23a05112019-03-27 08:00:44 +010056 maven {
Rico Wind70d614f2020-01-31 08:45:21 +010057 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010058 }
Jake Wharton5e5b5232019-09-17 16:13:32 -040059 google()
Mads Ager418d1ca2017-05-22 09:35:49 +020060 mavenCentral()
61}
62
Jinseong Jeon05064e12018-07-03 00:21:12 -070063if (project.hasProperty('with_code_coverage')) {
64 apply plugin: 'jacoco'
65}
66
Mads Ager418d1ca2017-05-22 09:35:49 +020067// Custom source set for example tests and generated tests.
68sourceSets {
69 test {
70 java {
71 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020072 'src/test/java',
73 'build/generated/test/java',
74 ]
75 }
76 }
Yohann Rousselbb571622017-11-09 10:47:36 +010077 apiUsageSample {
78 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020079 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
80 include 'com/android/tools/apiusagesample/*.java'
81 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
82 include 'com/android/tools/r8/D8CommandParser.java'
83 include 'com/android/tools/r8/R8CommandParser.java'
84 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010085 }
Yohann Rousselbb571622017-11-09 10:47:36 +010086 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010087 cfSegments {
88 java {
89 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
90 }
91 output.resourcesDir = 'build/classes/cfSegments'
92 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +010093 libraryDesugarConversions {
94 java {
95 srcDirs = ['src/library_desugar/java']
96 }
97 output.resourcesDir = 'build/classes/library_desugar_conversions'
98 }
Mads Ager418d1ca2017-05-22 09:35:49 +020099 debugTestResources {
100 java {
101 srcDirs = ['src/test/debugTestResources']
102 }
103 output.resourcesDir = 'build/classes/debugTestResources'
104 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200105 debugTestResourcesJava8 {
106 java {
107 srcDirs = ['src/test/debugTestResourcesJava8']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
110 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200111 debugTestResourcesKotlin {
112 java {
113 srcDirs = ['src/test/debugTestResourcesKotlin']
114 }
115 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
116 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200117 examples {
118 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800119 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200120 }
121 output.resourcesDir = 'build/classes/examples'
122 }
Ian Zernyd3020482019-04-25 07:05:04 +0200123 examplesJava9 {
124 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200125 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200126 }
127 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500128 examplesJava10 {
129 java {
130 srcDirs = ['src/test/examplesJava10']
131 }
132 }
Ian Zernyd3020482019-04-25 07:05:04 +0200133 examplesJava11 {
134 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200135 srcDirs = ['src/test/examplesJava11']
136 }
137 }
clementbera4f9c2a92019-07-09 08:50:37 +0200138 jdk11TimeTests {
139 java {
140 srcDirs = [
141 'third_party/openjdk/jdk-11-test/java/time/tck',
142 'third_party/openjdk/jdk-11-test/java/time/test'
143 ]
144 exclude '**/TestZoneTextPrinterParser.java'
145 }
146 }
clementberaefa10522019-07-11 11:20:46 +0200147 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200148 java {
149 srcDirs = ['src/test/testngrunner']
150 }
151 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100152 examplesKotlin {
153 java {
154 srcDirs = ['src/test/examplesKotlin']
155 }
156 output.resourcesDir = 'build/classes/examplesKotlin'
157 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200158 examplesAndroidN {
159 java {
160 srcDirs = ['src/test/examplesAndroidN']
161 }
162 output.resourcesDir = 'build/classes/examplesAndroidN'
163 }
164 examplesAndroidO {
165 java {
166 srcDirs = ['src/test/examplesAndroidO']
167 }
168 output.resourcesDir = 'build/classes/examplesAndroidO'
169 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200170 examplesAndroidP {
171 java {
172 srcDirs = ['src/test/examplesAndroidP']
173 }
174 output.resourcesDir = 'build/classes/examplesAndroidP'
175 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200176 examplesProto {
177 java {
178 srcDirs = ['src/test/examplesProto']
179 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200180 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
181 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200182 output.resourcesDir = 'build/classes/examplesProto'
183 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200184 jctfCommon {
185 java {
186 srcDirs = [
187 'third_party/jctf/Harness/src',
188 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
189 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
190 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
191 'third_party/jctf/LibTests/src/org',
192 'build/additionalJctfCommonFiles'
193 ]
194 }
195 resources {
196 srcDirs = ['third_party/jctf/LibTests/resources']
197 }
198 }
199 jctfTests {
200 java {
201 srcDirs = [
202 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
203 // 'third_party/jctf/VMTests/src',
204 ]
205 }
206 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100207 kotlinR8TestResources {
208 java {
209 srcDirs = ['src/test/kotlinR8TestResources']
210 }
211 output.resourcesDir = 'build/classes/kotlinR8TestResources'
212 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200213}
214
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800215// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
216// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
217// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
218// for context.
219idea {
220 sourceSets.all { SourceSet sources ->
221 module {
222 if (sources.name == "main") {
223 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100224 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800225 } else {
226 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100227 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800228 }
229 }
230 }
231}
232
Yohann Roussel126f6872017-08-03 16:25:32 +0200233configurations {
234 supportLibs
235}
236
Mads Ager418d1ca2017-05-22 09:35:49 +0200237dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100238 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
239 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200240 // Include all of guava when compiling the code, but exclude annotations that we don't
241 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100242 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100243 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200244 exclude group: 'com.google.errorprone'
245 exclude group: 'com.google.code.findbugs'
246 exclude group: 'com.google.j2objc'
247 exclude group: 'org.codehaus.mojo'
248 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100249 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
250 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
251 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
252 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
253 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
254 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
255 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
clementbera4f9c2a92019-07-09 08:50:37 +0200256 jdk11TimeTestsCompile group: 'org.testng', name: 'testng', version: testngVersion
clementberaefa10522019-07-11 11:20:46 +0200257 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200258 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100259 testCompile "junit:junit:$junitVersion"
260 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200261 testCompile files('third_party/jasmin/jasmin-2.4.jar')
262 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200263 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100264 jctfCommonCompile "junit:junit:$junitVersion"
265 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200266 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100267 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
268 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200269 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100270 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800271 examplesCompile "junit:junit:$junitVersion"
272 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100273 supportLibs "com.android.support:support-v4:$androidSupportVersion"
274 supportLibs "junit:junit:$junitVersion"
275 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100276 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100277 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100278 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
279 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
280 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100281 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Morten Krogh-Jespersen37437e82020-06-03 21:24:19 +0200282 testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.3.31"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200283}
284
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100285def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100286def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200287def r8DesugaredPath = "$buildDir/libs/r8desugared.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100288def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100289def r8LibTestPath = "$buildDir/classes/r8libtest"
clementbera0bca05e2019-05-29 14:11:18 +0200290def java11ClassFiles = "build/classes/java/mainJava11"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100291
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200292def osString = OperatingSystem.current().isLinux() ? "linux" :
293 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200294
295def cloudDependencies = [
296 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200297 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100298 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200299 ],
300 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200301 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200302 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100303 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200304 "android_jar/lib-v19",
305 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100306 "android_jar/lib-v22",
307 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200308 "android_jar/lib-v24",
309 "android_jar/lib-v25",
310 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100311 "android_jar/lib-v27",
312 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200313 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200314 "android_jar/lib-v30",
Rico Windf72fa152018-10-22 15:41:03 +0200315 "core-lambda-stubs",
316 "dart-sdk",
317 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200318 "gradle/gradle",
Ian Zerny33c1c582019-09-17 12:43:45 +0200319 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200320 "iosched_2019",
Søren Gjesse97679312020-10-06 13:44:59 +0200321 "jacoco/0.8.2",
322 "jacoco/0.8.6",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200323 "jasmin",
324 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100325 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200326 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200327 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200328 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200329 "rhino-android-1.1.1",
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +0200330 "kotlin/kotlin-compiler-1.3.11",
331 "kotlin/kotlin-compiler-1.3.41",
Morten Krogh-Jespersend32c8f22020-05-12 10:56:16 +0200332 "kotlin/kotlin-compiler-1.3.72",
Morten Krogh-Jespersen14153472020-05-19 15:40:47 +0200333 "kotlinx-coroutines-1.3.6",
Mathias Rav5285faf2018-03-20 14:16:32 +0100334 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200335 "openjdk/desugar_jdk_libs",
clementbera8dbfeda2019-07-03 11:24:13 +0200336 "openjdk/jdk-11-test",
Rico Windf72fa152018-10-22 15:41:03 +0200337 "proguard/proguard5.2.1",
338 "proguard/proguard6.0.1",
Ian Zerny7c920ac2020-07-01 20:12:01 +0200339 "proguard/proguard-7.0.0",
Mathias Rav891831f2018-04-26 14:51:18 +0200340 "r8",
Ian Zernye0fd0242020-06-23 13:46:14 +0200341 "r8-releases/2.0.74",
Morten Krogh-Jespersen1ba55f52020-04-24 12:49:17 +0200342 "r8mappings",
343 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200344 ],
345 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
346 // container on other platforms where supported.
347 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200348 "linux/art",
349 "linux/art-5.1.1",
350 "linux/art-6.0.1",
351 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100352 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100353 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100354 "linux/art-10.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200355 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100356 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200357 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200358 ]
359]
360
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100361def cloudSystemDependencies = [
362 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200363 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200364 "openjdk/jdk8/linux-x86",
365 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100366 ],
367 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200368 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200369 "openjdk/jdk8/darwin-x86",
370 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100371 ],
372 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200373 "third_party": ["openjdk/openjdk-9.0.4/windows",
374 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100375 ],
376]
377
378if (OperatingSystem.current().isWindows()) {
379 cloudSystemDependencies.windows.each { entry ->
380 cloudDependencies.get(entry.key).addAll(entry.value)
381 }
382} else if (OperatingSystem.current().isLinux()) {
383 cloudSystemDependencies.linux.each { entry ->
384 cloudDependencies.get(entry.key).addAll(entry.value)
385 }
386} else if (OperatingSystem.current().isMacOsX()) {
387 cloudSystemDependencies.osx.each { entry ->
388 cloudDependencies.get(entry.key).addAll(entry.value)
389 }
390} else {
391 println "WARNING: Unsupported system: " + OperatingSystem.current()
392}
393
394def getDownloadDepsTaskName(entryKey, entryFile) {
395 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
396}
397
Mads Ager418d1ca2017-05-22 09:35:49 +0200398cloudDependencies.each { entry ->
399 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100400 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
401 type DownloadDependency.Type.GOOGLE_STORAGE
402 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200403 }
404 }
405}
406
407def x20Dependencies = [
408 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200409 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700410 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200411 "chrome/chrome_200430",
Christoffer Quist Adamsen287c1862020-05-20 15:51:12 +0200412 "chrome/monochrome_public_minimal_apks/chrome_200520",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100413 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100414 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200415 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100416 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200417 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200418 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200419 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200420 "gmscore/gmscore_v10",
421 "gmscore/gmscore_v9",
422 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200423 "gmscore/v4",
424 "gmscore/v5",
425 "gmscore/v6",
426 "gmscore/v7",
427 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200428 "nest/nest_20180926_7c6cfb",
Rico Windf72fa152018-10-22 15:41:03 +0200429 "proguard/proguard_internal_159423826",
430 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200431 "proto",
432 "protobuf-lite",
Morten Krogh-Jespersend87c0662020-06-22 10:45:43 +0200433 "retrace_internal",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200434 "youtube/youtube.android_12.10",
435 "youtube/youtube.android_12.17",
436 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200437 "youtube/youtube.android_13.37",
Søren Gjesse889e09d2019-11-07 16:33:51 +0100438 "youtube/youtube.android_14.19",
Søren Gjesse974707e2020-02-26 09:47:01 +0100439 "youtube/youtube.android_14.44",
Søren Gjesse04638962020-02-28 09:59:30 +0100440 "youtube/youtube.android_15.08",
Christoffer Quist Adamsend839c3f2020-08-20 10:12:34 +0200441 "youtube/youtube.android_15.09",
442 "youtube/youtube.android_15.33"
Mads Ager418d1ca2017-05-22 09:35:49 +0200443 ],
444]
445
446x20Dependencies.each { entry ->
447 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100448 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
449 type DownloadDependency.Type.X20
450 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200451 }
452 }
453}
454
Rico Wind897bb712017-05-23 10:44:29 +0200455task downloadProguard {
456 cloudDependencies.each { entry ->
457 entry.value.each { entryFile ->
458 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100459 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200460 }
461 }
462 }
463}
464
Rico Windf6c74ce2018-12-04 08:50:55 +0100465task downloadOpenJDKrt {
466 cloudDependencies.each { entry ->
467 entry.value.each { entryFile ->
468 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100469 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100470 }
471 }
472 }
473}
474
Tamas Kenez427205b2017-06-29 15:57:09 +0200475task downloadDx {
476 cloudDependencies.each { entry ->
477 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200478 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100479 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200480 }
481 }
482 }
483}
484
Tamas Kenez0e10c562017-06-08 10:00:34 +0200485task downloadAndroidCts {
486 cloudDependencies.each { entry ->
487 entry.value.each { entryFile ->
488 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100489 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200490 }
491 }
492 }
493}
494
Mads Ager418d1ca2017-05-22 09:35:49 +0200495task downloadDeps {
496 cloudDependencies.each { entry ->
497 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100498 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200499 }
500 }
501 if (!project.hasProperty('no_internal')) {
502 x20Dependencies.each { entry ->
503 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100504 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200505 }
506 }
507 }
508}
509
510allprojects {
511 sourceCompatibility = JavaVersion.VERSION_1_8
512 targetCompatibility = JavaVersion.VERSION_1_8
513}
514
Rico Wind266336c2019-02-25 10:11:38 +0100515// TODO(ricow): Remove debug prints
516println("NOTE: Current operating system: " + OperatingSystem.current())
517println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
518
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100519// Check if running with the JDK location from tools/jdk.py.
520if (OperatingSystem.current().isWindows()) {
521 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100522 compileJava.options.encoding = "UTF-8"
523 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100524} else {
525 def javaHomeOut = new StringBuilder()
526 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400527 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100528 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
529 def jdkHome = new File(javaHomeOut.toString().trim())
530 if (!jdkHome.exists()) {
531 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
532 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
533 println("WARNING: Gradle is running in a non-pinned Java"
534 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000535 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100536 } else {
537 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100538 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200539}
540
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100541sourceSets.configureEach { sourceSet ->
542 tasks.named(sourceSet.compileJavaTaskName).configure {
543 // Default disable errorprone (enabled and setup below).
544 options.errorprone.enabled = false
545 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100546 // Run all compilation tasks in a forked subprocess.
547 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100548 // Javac often runs out of stack space when compiling the tests.
549 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200550 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100551 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200552 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100553 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
554 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
555 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200556}
557
Ian Zernyd3020482019-04-25 07:05:04 +0200558tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
559 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200560 options.fork = true
561 options.forkOptions.jvmArgs = []
562 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200563 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200564 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200565 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200566 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200567 options.forkOptions.javaHome = file(jdkDir + 'windows')
568 }
569 sourceCompatibility = JavaVersion.VERSION_1_9
570 targetCompatibility = JavaVersion.VERSION_1_9
571}
572
Jake Wharton2000b2f2019-12-11 20:37:49 -0500573def setJdk11CompilationWithCompatibility(String sourceSet, JavaVersion compatibility) {
clementbera0bdd90f2019-07-06 11:15:23 +0200574 tasks.named(sourceSet).get().configure {
575 def jdkDir = 'third_party/openjdk/jdk-11/'
576 options.fork = true
577 options.forkOptions.jvmArgs = []
578 if (OperatingSystem.current().isLinux()) {
579 options.forkOptions.javaHome = file(jdkDir + 'Linux')
580 } else if (OperatingSystem.current().isMacOsX()) {
581 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
582 } else {
583 options.forkOptions.javaHome = file(jdkDir + 'Windows')
584 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500585 sourceCompatibility = compatibility
586 targetCompatibility = compatibility
clementbera0fe940d2019-04-23 12:45:18 +0200587 }
clementbera0fe940d2019-04-23 12:45:18 +0200588}
589
Jake Wharton2000b2f2019-12-11 20:37:49 -0500590setJdk11CompilationWithCompatibility(sourceSets.examplesJava10.compileJavaTaskName, JavaVersion.VERSION_1_10)
591setJdk11CompilationWithCompatibility(sourceSets.examplesJava11.compileJavaTaskName, JavaVersion.VERSION_11)
592setJdk11CompilationWithCompatibility(sourceSets.examplesTestNGRunner.compileJavaTaskName, JavaVersion.VERSION_11)
593setJdk11CompilationWithCompatibility(sourceSets.jdk11TimeTests.compileJavaTaskName, JavaVersion.VERSION_11)
clementbera0bdd90f2019-07-06 11:15:23 +0200594
clementbera0bca05e2019-05-29 14:11:18 +0200595task compileMainWithJava11 (type: JavaCompile) {
Ian Zernye0dd4c42019-12-02 10:12:15 +0100596 dependsOn downloadDeps
clementbera0bca05e2019-05-29 14:11:18 +0200597 def jdkDir = 'third_party/openjdk/jdk-11/'
598 options.fork = true
599 options.forkOptions.jvmArgs = []
600 if (OperatingSystem.current().isLinux()) {
601 options.forkOptions.javaHome = file(jdkDir + 'Linux')
602 } else if (OperatingSystem.current().isMacOsX()) {
Jake Whartona5204f32019-06-26 08:29:21 -0400603 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
clementbera0bca05e2019-05-29 14:11:18 +0200604 } else {
605 options.forkOptions.javaHome = file(jdkDir + 'Windows')
606 }
607 source = sourceSets.main.allSource
608 destinationDir = file(java11ClassFiles)
609 sourceCompatibility = JavaVersion.VERSION_11
610 targetCompatibility = JavaVersion.VERSION_11
611 classpath = sourceSets.main.compileClasspath
612}
clementbera0fe940d2019-04-23 12:45:18 +0200613
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100614if (!project.hasProperty('without_error_prone') &&
615 // Don't enable error prone on Java 8 as the plugin setup does not support it.
616 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200617 compileJava {
618 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100619 options.errorprone.enabled = true
620 options.errorprone.disableAllChecks = true
621 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
Christoffer Quist Adamsen7bed1092020-05-04 11:08:00 +0200622 options.errorprone.check('CollectionIncompatibleType', CheckSeverity.ERROR)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100623 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
624 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
625 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
626 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
627 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
628 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
629 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
630 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
631 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
632 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
633 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
634 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
635 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
636 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
637 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
638 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
639 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
640 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200641 }
642}
643
Mads Ager418d1ca2017-05-22 09:35:49 +0200644compileJctfCommonJava {
645 dependsOn 'copyAdditionalJctfCommonFiles'
646 options.compilerArgs = ['-Xlint:none']
647}
648
649compileJctfTestsJava {
650 dependsOn 'jctfCommonClasses'
651 options.compilerArgs = ['-Xlint:none']
652}
653
Yohann Roussel7f47c032017-09-14 12:19:06 +0200654task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200655 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100656
Yohann Roussel7f47c032017-09-14 12:19:06 +0200657 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100658 def runtimeClasspath = configurations.findByName("runtimeClasspath")
659 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
660
Yohann Roussel7f47c032017-09-14 12:19:06 +0200661 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100662
Yohann Roussel7f47c032017-09-14 12:19:06 +0200663 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100664 def dependencies = []
665 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
666 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
667 dependencies.add("${identifier.group}:${identifier.module}")
668 }
669 def libraryLicenses = file('LIBRARY-LICENSE').text
670 dependencies.each {
671 if (!libraryLicenses.contains("- artifact: $it")) {
672 throw new GradleException("No license for $it in LIBRARY_LICENSE")
673 }
674 }
675
Yohann Roussel7f47c032017-09-14 12:19:06 +0200676 license.getParentFile().mkdirs()
677 license.createNewFile()
678 license.text = "This file lists all licenses for code distributed.\n"
679 license.text += "All non-library code has the following 3-Clause BSD license.\n"
680 license.text += "\n"
681 license.text += "\n"
682 license.text += file('LICENSE').text
683 license.text += "\n"
684 license.text += "\n"
685 license.text += "Summary of distributed libraries:\n"
686 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100687 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200688 license.text += "\n"
689 license.text += "\n"
690 license.text += "Licenses details:\n"
691 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
692 license.text += "\n"
693 license.text += "\n"
694 license.text += file.text
695 }
696 }
697}
698
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200699static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700700 // Everything under META-INF is not included by default.
701 // Should include before 'relocate' so that the service file path and its content
702 // are properly relocated as well.
703 task.mergeServiceFiles {
704 include 'META-INF/services/*'
705 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200706}
707
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200708task repackageDepsNew(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100709 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200710 mergeServiceFiles(it)
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100711 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700712 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200713 baseName 'deps_all'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000714}
715
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200716task repackageSourcesNew(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200717 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200718 mergeServiceFiles(it)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200719 baseName 'sources_main'
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000720}
721
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200722task repackageSources11New(type: ShadowJar) {
clementbera0bca05e2019-05-29 14:11:18 +0200723 dependsOn compileMainWithJava11
724 from file(java11ClassFiles)
725 mergeServiceFiles(it)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200726 baseName 'sources_main_11'
clementbera0bca05e2019-05-29 14:11:18 +0200727}
728
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200729def r8CreateTask(name, baseNameName, sources, includeSwissArmyKnife) {
730 return tasks.create("r8Create${name}", ShadowJar) {
731 from consolidatedLicense.outputs.files
732 from sources
733 baseName baseNameName
734 classifier = null
735 version = null
736 if (includeSwissArmyKnife) {
737 manifest {
738 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
739 }
740 }
741 exclude "META-INF/*.kotlin_module"
742 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200743 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200744}
745
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200746def r8RelocateTask(r8Task, output) {
747 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
748 dependsOn r8WithDeps
749 dependsOn r8Task
750 outputs.file output
751 workingDir = projectDir
752 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200753 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200754 "relocator",
755 "--input",
756 r8Task.outputs.files[0],
757 "--output",
758 output,
759 "--map",
760 "com.google.common->com.android.tools.r8.com.google.common",
761 "--map",
762 "com.google.gson->com.android.tools.r8.com.google.gson",
763 "--map",
764 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
765 "--map",
766 "joptsimple->com.android.tools.r8.joptsimple",
767 "--map",
768 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
769 "--map",
770 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
771 "--map",
772 "kotlin->com.android.tools.r8.jetbrains.kotlin",
773 "--map",
774 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
775 "--map",
776 "org.jetbrains->com.android.tools.r8.org.jetbrains",
777 "--map",
778 "org.intellij->com.android.tools.r8.org.intellij"
779 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200780 }
781}
782
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200783task r8WithDeps {
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200784 dependsOn repackageSourcesNew
785 dependsOn repackageDepsNew
786 inputs.files ([repackageSourcesNew.outputs, repackageDepsNew.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200787 def r8Task = r8CreateTask(
788 'WithDeps',
789 'r8_with_deps',
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200790 repackageSourcesNew.outputs.files + repackageDepsNew.outputs.files,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200791 true)
792 dependsOn r8Task
793 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200794}
795
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200796task r8WithDeps11 {
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200797 dependsOn repackageSources11New
798 dependsOn repackageDepsNew
799 inputs.files ([repackageSources11New.outputs, repackageDepsNew.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200800 def r8Task = r8CreateTask(
801 'WithDeps11',
802 'r8_with_deps_11',
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200803 repackageSources11New.outputs.files + repackageDepsNew.outputs.files,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200804 true)
805 dependsOn r8Task
806 outputs.files r8Task.outputs.files
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100807}
808
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200809task r8WithRelocatedDeps {
810 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
811 dependsOn r8RelocateTask(r8WithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200812 inputs.files r8WithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200813 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200814}
815
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200816task r8WithRelocatedDeps11 {
817 def output = "${buildDir}/libs/r8_with_relocated_deps_11.jar"
818 dependsOn r8RelocateTask(r8WithDeps11, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200819 inputs.files r8WithDeps11.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200820 outputs.file output
821}
822
823task r8WithoutDeps {
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200824 dependsOn repackageSourcesNew
825 inputs.files repackageSourcesNew.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200826 def r8Task = r8CreateTask(
827 'WithoutDeps',
828 'r8_without_deps',
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200829 repackageSourcesNew.outputs.files,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200830 true)
831 dependsOn r8Task
832 outputs.files r8Task.outputs.files
833}
834
835task r8(type: Copy) {
836 def r8Task = project.hasProperty("exclude_deps")
837 ? r8WithoutDeps : r8WithRelocatedDeps
838 dependsOn r8Task
839 from r8Task.outputs.files[0]
840 into file("${buildDir}/libs")
841 rename { String fileName -> "r8.jar" }
842 outputs.file "${buildDir}/libs/r8.jar"
843}
844
845task r8NoManifestWithoutDeps {
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200846 dependsOn repackageSourcesNew
847 inputs.files repackageSourcesNew.outputs
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200848 def r8Task = r8CreateTask(
849 'NoManifestWithoutDeps',
850 'r8_no_manifest_without_deps',
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200851 repackageSourcesNew.outputs.files,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200852 false)
853 dependsOn r8Task
854 outputs.files r8Task.outputs.files
855}
856
857task r8NoManifestWithDeps {
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200858 dependsOn repackageSourcesNew
859 inputs.files ([repackageSourcesNew.outputs, repackageDepsNew.outputs])
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200860 def r8Task = r8CreateTask(
861 'NoManifestWithDeps',
862 'r8_no_manifest_with_deps',
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200863 repackageSourcesNew.outputs.files + repackageDepsNew.outputs.files,
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200864 false)
865 dependsOn r8Task
866 outputs.files r8Task.outputs.files
867}
868
869task r8NoManifestWithRelocatedDeps {
870 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
871 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200872 inputs.files r8NoManifestWithDeps.outputs.files
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200873 outputs.file output
874}
875
876task r8NoManifest(type: Copy) {
877 def r8Task = project.hasProperty("exclude_deps")
878 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
879 dependsOn r8Task
880 from r8Task.outputs.files[0]
881 into file("${buildDir}/libs")
882 rename { String fileName -> "r8_no_manifest.jar" }
883 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100884}
885
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000886task D8(type: ShadowJar) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200887 dependsOn r8
888 from r8.outputs.files[0]
Mads Ager418d1ca2017-05-22 09:35:49 +0200889 baseName 'd8'
890 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200891 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200892 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200893}
894
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200895def baseCompilerCommandLine(compiler, args = []) {
896 // Execute r8 commands against a stable r8 with dependencies.
897 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx8g).
898 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
899 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + compiler + args
900}
901
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100902def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200903 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200904 return baseCompilerCommandLine("r8", args)
905}
906
907def baseD8CommandLine(args = []) {
908 // Execute r8 commands against a stable r8 with dependencies.
909 return baseCompilerCommandLine("d8", args)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100910}
911
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200912def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
913 def allArgs = [
914 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100915 input,
916 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100917 "--pg-map-output", output + ".map",
918 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200919 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
920 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100921}
922
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200923def d8CfCommandLine(input, output, args = ["--release"], libs = []) {
924 def allArgs = [
925 "--classfile",
926 input,
927 "--output", output,
928 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
929 ] + args + libs.collectMany { ["--lib", it] }
930 return baseD8CommandLine(allArgs)
931}
932
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200933def r8LibCreateTask(name, pgConfs = [], r8Task, output, args = ["--release"], libs = []) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100934 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200935 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs, libs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100936 outputs.file output
937 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100938 dependsOn r8WithRelocatedDeps
939 dependsOn r8Task
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200940 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConfs, args, libs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100941 workingDir = projectDir
942 }
943}
944
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100945task buildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
946 from sourceSets.libraryDesugarConversions.output
947 include "java/**/*.class"
948 baseName 'library_desugar_conversions'
949 destinationDir file('build/libs')
950}
951
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200952task testJarSources(type: ShadowJar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
953 baseName = "r8testsbase"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100954 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200955 // We only want to include tests that use R8 when generating keep rules for applymapping.
956 include "com/android/tools/r8/**"
957 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100958}
959
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200960task testJar(type: Exec) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +0200961 dependsOn r8WithDeps
962 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200963 def output = "$buildDir/libs/r8tests.jar"
964 outputs.file output
965 workingDir = projectDir
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +0200966 inputs.files (testJarSources.outputs.files + r8WithDeps.outputs.files)
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200967 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200968 "relocator",
969 "--input",
970 testJarSources.outputs.files[0],
971 "--output",
972 output,
973 "--map",
974 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
975 ])
976}
977
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200978task generateR8LibKeepRules(type: Exec) {
979 doFirst {
980 // TODO(b/154785341): We should remove this.
981 standardOutput new FileOutputStream(r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100982 }
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200983 // Depend on r8WithDeps for running baseCompilerCommandLine.
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +0200984 dependsOn r8WithDeps
985 dependsOn r8NoManifestWithRelocatedDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200986 dependsOn testJar
987 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +0200988 inputs.files ([
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +0200989 r8WithDeps.outputs,
990 r8NoManifestWithRelocatedDeps.outputs,
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +0200991 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200992 outputs.file r8LibGeneratedKeepRulesPath
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +0200993 commandLine baseCompilerCommandLine([
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200994 "printuses",
995 "--keeprules-allowobfuscation",
996 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersen23d77af2020-05-05 09:34:53 +0200997 r8NoManifestWithRelocatedDeps.outputs.files[0],
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200998 testJar.outputs.files[0]])
999 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +01001000}
1001
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +01001002task R8LibApiOnly {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001003 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], r8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +01001004 outputs.file r8LibPath
1005}
1006
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001007task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001008 dependsOn r8LibCreateTask(
1009 "Main",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001010 ["src/main/keep.txt", generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001011 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001012 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001013 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001014 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001015 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +01001016}
1017
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001018task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001019 dependsOn r8LibCreateTask(
1020 "NoDeps",
Morten Krogh-Jespersen60cb2622020-09-25 21:52:26 +02001021 ["src/main/keep.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001022 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001023 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +02001024 "--release",
Morten Krogh-Jespersen40ac0e42020-05-04 11:26:50 +02001025 repackageDepsNew.outputs.files
1026 ).dependsOn(repackageDepsNew)
1027 inputs.files ([r8NoManifestWithoutDeps.outputs, repackageDepsNew.outputs])
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001028 outputs.file r8LibExludeDepsPath
1029}
1030
Morten Krogh-Jespersen0b2bac72020-08-14 17:51:06 +02001031task R8Desugared(type: Exec) {
1032 dependsOn downloadOpenJDKrt
1033 dependsOn r8NoManifestWithRelocatedDeps
1034 inputs.files r8NoManifestWithRelocatedDeps.outputs.files
1035 commandLine d8CfCommandLine(
1036 r8NoManifestWithRelocatedDeps.outputs.files[0],
1037 r8DesugaredPath,
1038 ["--release"])
1039 workingDir = projectDir
1040 outputs.file r8DesugaredPath
1041}
1042
Mads Ager418d1ca2017-05-22 09:35:49 +02001043task sourceJar(type: Jar, dependsOn: classes) {
1044 classifier = 'src'
1045 from sourceSets.main.allSource
1046}
1047
1048task jctfCommonJar(type: Jar) {
1049 from sourceSets.jctfCommon.output
1050 baseName 'jctfCommon'
1051}
1052
1053artifacts {
1054 archives sourceJar
1055}
1056
1057task createArtTests(type: Exec) {
1058 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001059 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001060 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001061 outputs.dir outputDir
1062 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +02001063 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001064 workingDir = projectDir
1065}
1066
1067task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001068 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +02001069 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +02001070 inputs.file script
1071 outputs.dir outputDir
1072 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +02001073 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +02001074 workingDir = projectDir
1075}
1076
1077compileTestJava {
1078 dependsOn createArtTests
1079 dependsOn createJctfTests
1080}
1081
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001082task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1083 from sourceSets.cfSegments.output
1084 baseName 'cf_segments'
1085 destinationDir file('build/libs')
1086}
1087
Ian Zerny923a0c12018-01-03 10:59:18 +01001088task buildR8ApiUsageSample(type: Jar) {
1089 from sourceSets.apiUsageSample.output
1090 baseName 'r8_api_usage_sample'
1091 destinationDir file('tests')
1092}
1093
Yohann Roussel548ae942018-01-05 11:13:28 +01001094task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001095 dependsOn buildR8ApiUsageSample
1096}
1097
Mads Ager418d1ca2017-05-22 09:35:49 +02001098task buildDebugInfoExamplesDex {
1099 def examplesDir = file("src/test/java")
1100 def hostJar = "debuginfo_examples.jar"
1101 def hostDexJar = "debuginfo_examples_dex.jar"
1102 task "compile_debuginfo_examples"(type: JavaCompile) {
1103 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1104 destinationDir = file("build/test/debuginfo_examples/classes")
1105 classpath = sourceSets.main.compileClasspath
1106 sourceCompatibility = JavaVersion.VERSION_1_7
1107 targetCompatibility = JavaVersion.VERSION_1_7
1108 options.compilerArgs += ["-Xlint:-options"]
1109 }
1110 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1111 archiveName = hostJar
1112 destinationDir = file("build/test/")
1113 from "build/test/debuginfo_examples/classes"
1114 include "**/*.class"
1115 }
1116 task "dex_debuginfo_examples"(type: Exec,
1117 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001118 if (OperatingSystem.current().isWindows()) {
1119 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001120 } else if (OperatingSystem.current().isMacOsX()) {
1121 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001122 } else {
1123 executable file("tools/linux/dx/bin/dx");
1124 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001125 args "--dex"
1126 args "--output=build/test/${hostDexJar}"
1127 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001128 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001129 outputs.file file("build/test/${hostDexJar}")
1130 }
1131 dependsOn dex_debuginfo_examples
1132}
1133
1134task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001135 def resourcesDir = file("src/test/debugTestResources")
1136 def hostJar = "debug_test_resources.jar"
1137 task "compile_debugTestResources"(type: JavaCompile) {
1138 source = fileTree(dir: resourcesDir, include: '**/*.java')
1139 destinationDir = file("build/test/debugTestResources/classes")
1140 classpath = sourceSets.main.compileClasspath
1141 sourceCompatibility = JavaVersion.VERSION_1_7
1142 targetCompatibility = JavaVersion.VERSION_1_7
1143 options.compilerArgs += ["-g", "-Xlint:-options"]
1144 }
1145 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1146 archiveName = hostJar
1147 destinationDir = file("build/test/")
1148 from "build/test/debugTestResources/classes"
1149 include "**/*.class"
1150 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001151 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1152 def java8HostJar = "debug_test_resources_java8.jar"
1153 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1154 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1155 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1156 classpath = sourceSets.main.compileClasspath
1157 sourceCompatibility = JavaVersion.VERSION_1_8
1158 targetCompatibility = JavaVersion.VERSION_1_8
1159 options.compilerArgs += ["-g", "-Xlint:-options"]
1160 }
1161 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1162 archiveName = java8HostJar
1163 destinationDir = file("build/test/")
1164 from "build/test/debugTestResourcesJava8/classes"
1165 include "**/*.class"
1166 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001167 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001168 def kotlinHostJar = "debug_test_resources_kotlin.jar"
Morten Krogh-Jespersenb328dc62020-05-12 09:11:52 +02001169 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc, dependsOn: downloadDeps) {
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001170 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1171 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001172 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001173 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001174 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001175 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001176 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001177}
1178
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001179// Examples used by tests, where Android specific APIs are used.
1180task buildExampleAndroidApi(type: JavaCompile) {
1181 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1182 destinationDir = file("build/test/examplesAndroidApi/classes")
1183 classpath = files("third_party/android_jar/lib-v26/android.jar")
1184 sourceCompatibility = JavaVersion.VERSION_1_8
1185 targetCompatibility = JavaVersion.VERSION_1_8
1186}
1187
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001188task buildExampleKotlinJars {
1189 def kotlinSrcDir = file("src/test/examplesKotlin")
1190 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001191 def name = dir.getName();
1192 dependsOn "compile_example_kotlin_${name}"
1193 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1194 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1195 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001196 }
1197 }
1198}
1199
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001200task buildProtoGeneratedSources {
1201 def examplesProtoDir = file("src/test/examplesProto")
1202 examplesProtoDir.eachDir { dir ->
1203 def name = dir.getName()
1204 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1205 source = {
1206 file('third_party/proto').listFiles()
1207 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1208 .collect { zipTree(it) }
1209 }
1210 destinationDir = file("build/generated/test/proto/${name}_classes")
1211 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1212 sourceCompatibility = JavaVersion.VERSION_1_8
1213 targetCompatibility = JavaVersion.VERSION_1_8
1214 }
1215 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1216 archiveName = "${name}.jar"
1217 destinationDir = file("build/generated/test/proto")
1218 from "build/generated/test/proto/${name}_classes"
1219 include "/**/*.class"
1220 }
1221 dependsOn "jar_proto_generated_source_${name}"
1222 }
1223}
1224
1225task buildExamplesProto {
1226 def examplesProtoDir = file("src/test/examplesProto")
1227 def examplesProtoOutputDir = file("build/test/examplesProto");
1228 dependsOn buildProtoGeneratedSources
1229 task "compile_examples_proto"(type: JavaCompile) {
1230 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1231 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001232 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1233 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001234 sourceCompatibility = JavaVersion.VERSION_1_8
1235 targetCompatibility = JavaVersion.VERSION_1_8
1236 }
1237 examplesProtoDir.eachDir { dir ->
1238 def name = dir.getName()
1239 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1240 archiveName = "${name}.jar"
1241 destinationDir = examplesProtoOutputDir
1242 from "build/test/examplesProto/classes"
1243 include name + "/**/*.class"
1244 }
1245 dependsOn "jar_examples_proto_${name}"
1246 }
1247}
1248
Lars Bakc91e87e2017-08-18 08:53:10 +02001249// Proto lite generated code yields warnings when compiling with javac.
1250// We change the options passed to javac to ignore it.
1251compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1252
Søren Gjesse7320ce52018-05-07 15:45:22 +02001253
Mads Ager418d1ca2017-05-22 09:35:49 +02001254task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001255 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001256 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001257 def proguardScript
1258 if (OperatingSystem.current().isWindows()) {
1259 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1260 } else {
1261 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1262 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001263 task extractExamplesRuntime(type: Sync) {
1264 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001265 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001266 include "**/*.class"
1267 includeEmptyDirs false
1268 into "$buildDir/runtime/examples/"
1269 }
1270
Søren Gjesse7320ce52018-05-07 15:45:22 +02001271 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1272 from examplesDir
1273 exclude "**/*.java"
1274 exclude "**/keep-rules*.txt"
1275 into file("build/test/examples/classes")
1276 }
1277
1278 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001279 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001280 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001281 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001282 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001283 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001284 sourceCompatibility = JavaVersion.VERSION_1_7
1285 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001286 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1287 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001288 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1289 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001290 include "**/*.java"
1291 destinationDir = file("build/test/examples/classes_debuginfo_all")
1292 classpath = sourceSets.examples.compileClasspath
1293 sourceCompatibility = JavaVersion.VERSION_1_7
1294 targetCompatibility = JavaVersion.VERSION_1_7
1295 options.compilerArgs = ["-g", "-Xlint:none"]
1296 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001297 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1298 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001299 include "**/*.java"
1300 destinationDir = file("build/test/examples/classes_debuginfo_none")
1301 classpath = sourceSets.examples.compileClasspath
1302 sourceCompatibility = JavaVersion.VERSION_1_7
1303 targetCompatibility = JavaVersion.VERSION_1_7
1304 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001305 }
1306 examplesDir.eachDir { dir ->
1307 def name = dir.getName();
1308 def exampleOutputDir = file("build/test/examples");
1309 def jarName = "${name}.jar"
1310 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001311 dependsOn "jar_example_${name}_debuginfo_all"
1312 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001313 dependsOn "extractExamplesRuntime"
1314 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001315 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1316 def proguardConfigPath = "${dir}/proguard.cfg"
1317 if (new File(proguardConfigPath).exists()) {
1318 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1319 archiveName = "${name}_pre_proguard.jar"
1320 destinationDir = exampleOutputDir
1321 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001322 include name + "/**/*.class"
1323 with runtimeDependencies
1324 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001325 }
1326 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1327 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1328 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1329 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001330 inputs.files files(
1331 tasks.getByPath("pre_proguard_example_${name}"),
1332 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001333 // Enable these to get stdout and stderr redirected to files...
1334 // standardOutput = new FileOutputStream('proguard.stdout')
1335 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001336 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001337 " -outjars ${proguardJarPath}" +
1338 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001339 " -printmapping ${proguardMapPath}"
1340 if (OperatingSystem.current().isWindows()) {
1341 executable "${proguardScript}"
1342 args "${proguardArguments}"
1343 } else {
1344 executable "bash"
1345 args "-c", "${proguardScript} '${proguardArguments}'"
1346 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001347 outputs.file proguardJarPath
1348 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001349 // TODO: Consider performing distinct proguard compilations.
1350 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1351 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001352 into "${exampleOutputDir}"
1353 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001354 }
1355 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1356 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001357 into "${exampleOutputDir}"
1358 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001359 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001360 } else {
1361 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001362 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001363 destinationDir = exampleOutputDir
1364 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001365 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001366 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001367 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001368 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001369 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1370 archiveName = "${name}_debuginfo_all.jar"
1371 destinationDir = exampleOutputDir
1372 from "build/test/examples/classes_debuginfo_all"
1373 include name + "/**/*.class"
1374 with runtimeDependencies
1375 includeEmptyDirs false
1376 }
1377 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1378 archiveName = "${name}_debuginfo_none.jar"
1379 destinationDir = exampleOutputDir
1380 from "build/test/examples/classes_debuginfo_none"
1381 include name + "/**/*.class"
1382 with runtimeDependencies
1383 includeEmptyDirs false
1384 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001385 }
1386 }
1387}
1388
1389task buildExampleAndroidNJars {
1390 dependsOn downloadDeps
1391 def examplesDir = file("src/test/examplesAndroidN")
1392 task "compile_examplesAndroidN"(type: JavaCompile) {
1393 source = fileTree(dir: examplesDir, include: '**/*.java')
1394 destinationDir = file("build/test/examplesAndroidN/classes")
1395 classpath = sourceSets.main.compileClasspath
1396 sourceCompatibility = JavaVersion.VERSION_1_8
1397 targetCompatibility = JavaVersion.VERSION_1_8
1398 options.compilerArgs += ["-Xlint:-options"]
1399 }
1400 examplesDir.eachDir { dir ->
1401 def name = dir.getName();
1402 def exampleOutputDir = file("build/test/examplesAndroidN");
1403 def jarName = "${name}.jar"
1404 dependsOn "jar_examplesAndroidN_${name}"
1405 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1406 archiveName = jarName
1407 destinationDir = exampleOutputDir
1408 from "build/test/examplesAndroidN/classes"
1409 include "**/" + name + "/**/*.class"
1410 }
1411 }
1412}
1413
1414
1415task buildExampleAndroidOJars {
1416 dependsOn downloadDeps
1417 def examplesDir = file("src/test/examplesAndroidO")
1418 // NOTE: we want to enable a scenario when test needs to reference some
1419 // classes generated by legacy (1.6) Java compiler to test some specific
1420 // behaviour. To do so we compile all the java files located in sub-directory
1421 // called 'legacy' with Java 1.6, then compile the rest of the files with
1422 // Java 1.8 and a reference to previously generated 1.6 classes.
1423
1424 // Compiling all classes in dirs 'legacy' with old Java version.
1425 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1426 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1427 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1428 classpath = sourceSets.main.compileClasspath
1429 sourceCompatibility = JavaVersion.VERSION_1_6
1430 targetCompatibility = JavaVersion.VERSION_1_6
1431 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1432 }
1433 // Compiling the rest of the files as Java 1.8 code.
1434 task "compile_examplesAndroidO"(type: JavaCompile) {
1435 dependsOn "compile_examplesAndroidO_Legacy"
1436 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1437 destinationDir = file("build/test/examplesAndroidO/classes")
1438 classpath = sourceSets.main.compileClasspath
1439 classpath += files("build/test/examplesAndroidOLegacy/classes")
1440 sourceCompatibility = JavaVersion.VERSION_1_8
1441 targetCompatibility = JavaVersion.VERSION_1_8
1442 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1443 }
1444 examplesDir.eachDir { dir ->
1445 def name = dir.getName();
1446 def destinationDir = file("build/test/examplesAndroidO/classes");
1447 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1448 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1449 dependsOn: "compile_examplesAndroidO") {
1450 main = name + ".TestGenerator"
1451 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1452 args destinationDir
1453 }
1454 } else {
1455 task "generate_examplesAndroidO_${name}" () {}
1456 }
1457 }
1458 examplesDir.eachDir { dir ->
1459 def name = dir.getName();
1460 def exampleOutputDir = file("build/test/examplesAndroidO");
1461 def jarName = "${name}.jar"
1462 dependsOn "jar_examplesAndroidO_${name}"
1463 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1464 "generate_examplesAndroidO_${name}"]) {
1465 archiveName = jarName
1466 destinationDir = exampleOutputDir
1467 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1468 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1469 include "**/" + name + "/**/*.class"
1470 // Do not include generator into the test runtime jar, it is not useful.
1471 // Otherwise, shrinking will need ASM jars.
1472 exclude "**/TestGenerator*"
1473 }
1474 }
1475}
1476
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001477task buildExampleAndroidPJars {
1478 dependsOn downloadDeps
1479 def examplesDir = file("src/test/examplesAndroidP")
1480
1481 task "compile_examplesAndroidP"(type: JavaCompile) {
1482 source = fileTree(dir: examplesDir, include: '**/*.java')
1483 destinationDir = file("build/test/examplesAndroidP/classes")
1484 classpath = sourceSets.main.compileClasspath
1485 sourceCompatibility = JavaVersion.VERSION_1_8
1486 targetCompatibility = JavaVersion.VERSION_1_8
1487 options.compilerArgs += ["-Xlint:-options"]
1488 }
1489 examplesDir.eachDir { dir ->
1490 def name = dir.getName();
1491 def destinationDir = file("build/test/examplesAndroidP/classes");
1492 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1493 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1494 dependsOn: "compile_examplesAndroidP") {
1495 main = name + ".TestGenerator"
1496 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1497 args destinationDir
1498 }
1499 } else {
1500 task "generate_examplesAndroidP_${name}" () {}
1501 }
1502 }
1503 examplesDir.eachDir { dir ->
1504 def name = dir.getName();
1505 def exampleOutputDir = file("build/test/examplesAndroidP");
1506 def jarName = "${name}.jar"
1507 dependsOn "jar_examplesAndroidP_${name}"
1508 task "jar_examplesAndroidP_${name}"(type: Jar,
1509 dependsOn: ["compile_examplesAndroidP",
1510 "generate_examplesAndroidP_${name}"]) {
1511 archiveName = jarName
1512 destinationDir = exampleOutputDir
1513 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1514 include "**/" + name + "/**/*.class"
1515 // Do not include generator into the test runtime jar, it is not useful.
1516 // Otherwise, shrinking will need ASM jars.
1517 exclude "**/TestGenerator*"
1518 }
1519 }
1520}
1521
Mikaël Peltier61633d42017-10-13 16:51:06 +02001522task buildExampleJava9Jars {
1523 def examplesDir = file("src/test/examplesJava9")
1524 examplesDir.eachDir { dir ->
1525 def name = dir.getName();
1526 def exampleOutputDir = file("build/test/examplesJava9");
1527 def jarName = "${name}.jar"
1528 dependsOn "jar_examplesJava9_${name}"
1529 task "jar_examplesJava9_${name}"(type: Jar) {
1530 archiveName = jarName
1531 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001532 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001533 include "**/" + name + "/**/*.class"
1534 }
1535 }
1536}
1537
Jake Wharton2000b2f2019-12-11 20:37:49 -05001538task buildExampleJava10Jars {
1539 def examplesDir = file("src/test/examplesJava10")
1540 examplesDir.eachDir { dir ->
1541 def name = dir.getName();
1542 def exampleOutputDir = file("build/test/examplesJava10");
1543 def jarName = "${name}.jar"
1544 dependsOn "jar_examplesJava10_${name}"
1545 task "jar_examplesJava10_${name}"(type: Jar) {
1546 archiveName = jarName
1547 destinationDir = exampleOutputDir
1548 from sourceSets.examplesJava10.output
1549 include "**/" + name + "/**/*.class"
1550 }
1551 }
1552}
1553
clementberad7ab1dd2019-04-16 16:05:00 +02001554task buildExampleJava11Jars {
1555 def examplesDir = file("src/test/examplesJava11")
1556 examplesDir.eachDir { dir ->
1557 def name = dir.getName();
1558 def exampleOutputDir = file("build/test/examplesJava11");
1559 def jarName = "${name}.jar"
1560 dependsOn "jar_examplesJava11_${name}"
1561 task "jar_examplesJava11_${name}"(type: Jar) {
1562 archiveName = jarName
1563 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001564 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001565 include "**/" + name + "/**/*.class"
1566 }
1567 }
1568}
1569
clementberaa92e3cd2019-07-12 14:13:22 +02001570task provideArtFrameworksDependencies {
1571 cloudDependencies.tools.forEach({ art ->
1572 if (art.contains("art")) {
1573 def taskName = art.replace('/','_')
1574 dependsOn "patch_${taskName}"
1575 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1576 from "tools/${art}/framework"
1577 include "**.jar"
1578 into file("tools/${art}/out/host/linux-x86/framework")
1579 }
1580 }
1581 })
1582}
1583
clementbera4f9c2a92019-07-09 08:50:37 +02001584task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1585 from sourceSets.jdk11TimeTests.compileClasspath
1586 include "**/**.jar"
1587 into file("build/test/jdk11Tests")
1588}
1589
1590task buildJdk11TimeTestsJar {
1591 def exampleOutputDir = file("build/test/jdk11Tests");
1592 def jarName = "jdk11TimeTests.jar"
1593 dependsOn "jar_jdk11TimeTests"
1594 dependsOn provideJdk11TestsDependencies
1595 task "jar_jdk11TimeTests"(type: Jar) {
1596 archiveName = jarName
1597 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001598 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001599 include "**.class"
1600 from sourceSets.jdk11TimeTests.output
1601 include "**.class"
1602 include "**/**.class"
1603 }
1604}
1605
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001606task buildExamplesKotlin {
1607 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1608 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1609 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1610 } else if (!OperatingSystem.current().isLinux()) {
1611 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1612 "on your platform. It is fully supported on Linux and partially supported on " +
1613 "Mac OS and Windows")
1614 return;
1615 }
1616 def examplesDir = file("src/test/examplesKotlin")
1617 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001618 def name = dir.getName();
1619 dependsOn "dex_example_kotlin_${name}"
1620 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1621 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001622 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001623 dependsOn: "compile_example_kotlin_${name}") {
1624 doFirst {
1625 if (!dexPath.exists()) {
1626 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001627 }
1628 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001629 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1630 destination = dexPath
1631 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001632 }
1633 }
1634}
1635
Sebastien Hertzd3313772018-01-16 14:12:37 +01001636task buildKotlinR8TestResources {
1637 def examplesDir = file("src/test/kotlinR8TestResources")
1638 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001639 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1640 def name = dir.getName()
1641 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001642 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1643 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001644 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001645 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001646 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1647 source = fileTree(dir: file("${examplesDir}/${name}"),
1648 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001649 destination = file(outputFile)
1650 targetVersion = kotlinTargetVersion
1651 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001652 task "${taskName}Java"(type: JavaCompile) {
1653 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1654 destinationDir = file(javaOutput)
1655 classpath = sourceSets.main.compileClasspath
1656 sourceCompatibility = JavaVersion.VERSION_1_6
1657 targetCompatibility = JavaVersion.VERSION_1_6
1658 options.compilerArgs += ["-g", "-Xlint:-options"]
1659 }
1660 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1661 archiveName = javaOutputJarName
1662 destinationDir = file(javaOutputJarDir)
1663 from javaOutput
1664 include "**/*.class"
1665 }
1666 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001667 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001668 }
1669}
1670
Mads Ager418d1ca2017-05-22 09:35:49 +02001671task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001672 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1673 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1674 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001675 } else if (!OperatingSystem.current().isLinux()) {
1676 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001677 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001678 return;
1679 }
1680 dependsOn buildDebugTestResourcesJars
1681 dependsOn buildExampleJars
1682 dependsOn buildExampleAndroidNJars
1683 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001684 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001685 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001686 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001687 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001688 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001689 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001690 def noDexTests = [
1691 "multidex",
1692 "multidex002",
1693 "multidex004",
1694 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001695 examplesDir.eachDir { dir ->
1696 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001697 if (!(name in noDexTests)) {
1698 dependsOn "dex_example_${name}"
1699 def exampleOutputDir = file("build/test/examples/" + name);
1700 def dexPath = file("${exampleOutputDir}")
1701 def debug = (name == "throwing")
1702 if (!dexPath.exists()) {
1703 dexPath.mkdirs()
1704 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001705 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001706 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1707 destination = dexPath
1708 debug = debug
1709 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001710 }
1711 }
1712}
1713
1714task buildSmali {
1715 def smaliDir = file("src/test/smali")
1716 smaliDir.eachDirRecurse() { dir ->
1717 def name = dir.getName();
1718 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1719 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1720 smaliOutputDir.mkdirs()
1721 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001722 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001723 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1724 def javaFiles = fileTree(dir: dir, include: '*.java')
1725 def destDir = smaliOutputDir;
1726 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1727 def intermediateFileName = "${name}-intermediate.dex";
1728 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1729 if (javaFiles.empty) {
1730 if (!smaliFiles.empty) {
1731 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001732 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001733 source = smaliFiles
1734 destination = destFile
1735 }
1736 }
1737 } else {
1738 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001739 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001740 source = smaliFiles
1741 destination = intermediateFile
1742 }
1743 task "${taskName}_java"(type: JavaCompile) {
1744 source = javaFiles
1745 destinationDir destDir
1746 classpath = sourceSets.main.compileClasspath
1747 sourceCompatibility = JavaVersion.VERSION_1_7
1748 targetCompatibility = JavaVersion.VERSION_1_7
1749 options.compilerArgs += ["-Xlint:-options"]
1750 }
1751 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1752 archiveName = "Test.jar"
1753 destinationDir = destDir
1754 from fileTree(dir: destDir, include: 'Test.class')
1755 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001756 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001757 source = fileTree(dir: destDir, include: 'Test.jar')
1758 destination = destDir
1759 }
1760 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001761 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001762 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1763 destination = destFile
1764 }
1765 }
1766 }
1767}
1768
1769tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001770 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001771 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001772 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001773 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001774 if (userDefinedCoresPerFork) {
1775 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1776 } else {
1777 // On normal work machines this seems to give the best test execution time (without freezing)
1778 maxParallelForks = processors.intdiv(3) ?: 1
1779 }
Rico Windc56f21c2019-03-12 07:29:57 +01001780 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001781
Mads Ager418d1ca2017-05-22 09:35:49 +02001782 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001783 if (project.hasProperty('disable_assertions')) {
1784 enableAssertions = false
1785 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001786 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001787 if (project.hasProperty('test_xmx')) {
1788 maxHeapSize = project.property('test_xmx')
1789 } else {
1790 maxHeapSize = "4G"
1791 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001792}
1793
1794task buildPreNJdwpTestsJar(type: Jar) {
1795 baseName = 'jdwp-tests-preN'
1796 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1797 // Exclude the classes containing java8
1798 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1799 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1800 includeEmptyDirs = false
1801}
1802
Ian Zerny74143162017-11-24 13:46:35 +01001803task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1804 def inFile = buildPreNJdwpTestsJar.archivePath
1805 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001806 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001807 outputs.file outFile
1808 if (OperatingSystem.current().isWindows()) {
1809 executable file("tools/windows/dx/bin/dx.bat")
1810 } else if (OperatingSystem.current().isMacOsX()) {
1811 executable file("tools/mac/dx/bin/dx");
1812 } else {
1813 executable file("tools/linux/dx/bin/dx");
1814 }
1815 args "--dex"
1816 args "--output=${outFile}"
1817 args inFile
1818}
1819
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001820task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1821 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001822}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001823
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001824task generateR8TestKeepRules {
1825 def path = "build/generated/r8tests-keep.txt"
1826 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001827 dependsOn R8Lib
1828 doLast {
1829 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001830-dontshrink
1831-dontoptimize
1832-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001833-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001834"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001835 }
1836}
1837
1838task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001839 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1840 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001841 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001842 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001843 dependsOn generateR8TestKeepRules
1844 dependsOn testJar
1845 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1846 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1847 return pkg.toString().endsWith(".jar")
1848 } + ["${buildDir}/classes/java/test"]
1849 inputs.files testJar.outputs.files +
1850 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001851 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001852 commandLine = r8CfCommandLine(
1853 testJar.outputs.files[0],
1854 outputPath,
1855 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001856 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1857 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001858 workingDir = projectDir
1859 outputs.file outputPath
1860}
1861
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001862task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001863 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001864 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001865 dependsOn R8Lib
1866 delete r8LibTestPath
1867 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1868 def examplesDir = file("build/test")
1869 examplesDir.eachDir { dir ->
1870 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001871 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001872 from ("${buildDir}/runtime/examples")
1873 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001874 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001875}
1876
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001877def printStackTrace(TestResult result) {
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001878 filterStackTraces(result)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001879 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1880 def out = new StringBuffer()
1881 def err = new StringBuffer()
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001882 def command = "python tools/retrace.py --quiet"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001883 def header = "RETRACED STACKTRACE";
1884 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1885 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1886 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1887 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001888 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001889 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001890 out.append("--------------------------------------\n")
1891 Process process = command.execute()
1892 def processIn = new PrintStream(process.getOut())
1893 process.consumeProcessOutput(out, err)
1894 result.exception.printStackTrace(processIn)
1895 processIn.flush()
1896 processIn.close()
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001897 def errorDuringRetracing = process.waitFor() != 0
1898 if (errorDuringRetracing) {
Morten Krogh-Jespersenfe0d7e12020-01-31 08:50:17 +01001899 out.append("ERROR DURING RETRACING\n")
1900 out.append(err.toString())
1901 }
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001902 if (project.hasProperty('print_obfuscated_stacktraces') || errorDuringRetracing) {
1903 out.append("\n\n--------------------------------------\n")
1904 out.append("OBFUSCATED STACKTRACE\n")
1905 out.append("--------------------------------------\n")
1906 } else {
1907 result.exceptions.clear()
1908 }
1909 def exception = new Exception(out.toString())
1910 exception.setStackTrace([] as StackTraceElement[])
1911 result.exceptions.add(0, exception)
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001912 } else {
1913 result.exception.printStackTrace()
1914 }
1915}
1916
Christoffer Quist Adamsen7bf60342020-11-09 14:00:27 +01001917def filterStackTraces(TestResult result) {
1918 for (Throwable throwable : result.getExceptions()) {
1919 filterStackTrace(throwable)
1920 }
1921}
1922
1923def filterStackTrace(Throwable exception) {
1924 if (!project.hasProperty('print_full_stacktraces')) {
1925 def elements = []
1926 def skipped = []
1927 for (StackTraceElement element : exception.getStackTrace()) {
1928 if (element.toString().contains("com.android.tools.r8")) {
1929 elements.addAll(skipped)
1930 elements.add(element)
1931 skipped.clear()
1932 } else {
1933 skipped.add(element)
1934 }
1935 }
1936 exception.setStackTrace(elements as StackTraceElement[])
1937 }
1938}
1939
Mads Ager418d1ca2017-05-22 09:35:49 +02001940test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001941 if (project.hasProperty('generate_golden_files_to')) {
1942 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1943 assert project.hasProperty('HEAD_sha1')
1944 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1945 }
1946
1947 if (project.hasProperty('use_golden_files_in')) {
1948 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1949 assert project.hasProperty('HEAD_sha1')
1950 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1951 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001952
Ian Zerny64312222019-12-05 15:12:24 +01001953 dependsOn buildLibraryDesugarConversions
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001954 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001955 // R8.jar is required for running bootstrap tests.
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001956 dependsOn r8
Mads Ager418d1ca2017-05-22 09:35:49 +02001957 testLogging.exceptionFormat = 'full'
1958 if (project.hasProperty('print_test_stdout')) {
1959 testLogging.showStandardStreams = true
1960 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001961 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001962 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001963 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001964 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001965
Ian Zerny324d7612019-03-20 10:52:28 +01001966 // Forward runtime configurations for test parameters.
1967 if (project.hasProperty('runtimes')) {
1968 println "NOTE: Running with runtimes: " + project.property('runtimes')
1969 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001970 }
1971
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001972 if (project.hasProperty('slow_tests')) {
1973 systemProperty 'slow_tests', project.property('slow_tests')
1974 }
1975
Mads Ager418d1ca2017-05-22 09:35:49 +02001976 if (project.hasProperty('one_line_per_test')) {
1977 beforeTest { desc ->
1978 println "Start executing test ${desc.name} [${desc.className}]"
1979 }
1980 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001981 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001982 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001983 }
Rico Windda6836e2018-12-07 12:32:03 +01001984 if (project.hasProperty('update_test_timestamp')) {
1985 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1986 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001987 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1988 }
Rico Windf88b6be2018-12-11 15:14:05 +01001989 } else {
1990 afterTest { desc, result ->
1991 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001992 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001993 }
1994 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001995 }
1996 if (project.hasProperty('no_internal')) {
1997 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001998 } else {
1999 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02002000 }
2001 if (project.hasProperty('only_internal')) {
2002 include "com/android/tools/r8/internal/**"
2003 }
Rico Wind4e218292019-03-07 12:44:49 +01002004
Rico Windba151112020-10-01 08:16:33 +02002005 if (project.hasProperty('test_namespace')) {
2006 include "com/android/tools/r8/" + project.getProperty('test_namespace') + "/**"
2007 }
2008
Mads Ager418d1ca2017-05-22 09:35:49 +02002009 if (project.hasProperty('tool')) {
2010 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01002011 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02002012 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01002013 if (project.hasProperty('only_jctf')) {
2014 include "com/android/tools/r8/jctf/d8/**"
2015 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01002016 // Don't run anything, deprecated
2017 println "Running with deprecated tool d8, not running any tests"
2018 include ""
Rico Windf02167a2019-03-15 12:27:03 +01002019 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02002020 } else {
2021 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01002022 assert(project.hasProperty('only_jctf'))
2023 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002024 }
2025 }
2026 if (!project.hasProperty('all_tests')) {
2027 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002028 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002029 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02002030 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02002031 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01002032 if (project.hasProperty('shard_count') ) {
2033 assert project.hasProperty('shard_number')
2034 int shard_count = project.getProperty('shard_count') as Integer
2035 int shard_number = project.getProperty('shard_number') as Integer
2036 assert shard_count < 65536
2037 assert shard_number < shard_count
2038 exclude {
2039 entry ->
2040 // Don't leave out directories. Leaving out a directory means all entries below.
2041 if (entry.file.isDirectory()) {
2042 return false
2043 }
2044 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
2045 int hash = Integer.parseInt(first4, 16)
2046 return hash % shard_count != shard_number
2047 }
2048 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002049 if (project.hasProperty('jctf_compile_only')) {
2050 println "JCTF: compiling only"
2051 systemProperty 'jctf_compile_only', '1'
2052 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02002053 if (project.hasProperty('test_dir')) {
2054 systemProperty 'test_dir', project.property('test_dir')
2055 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002056 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002057 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02002058 // R8lib should be used instead of the main output and all the tests in
2059 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02002060 classpath = sourceSets.test.runtimeClasspath.filter {
2061 !it.getAbsolutePath().contains("/build/")
2062 }
2063 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01002064 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01002065 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002066 if (OperatingSystem.current().isLinux()
2067 || OperatingSystem.current().isMacOsX()
2068 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002069 if (OperatingSystem.current().isMacOsX()) {
2070 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
2071 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
2072 "See tools/docker/README.md for details.")
2073 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002074 if (OperatingSystem.current().isWindows()) {
2075 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
2076 "Art only runs on Linux and tests requiring Art will be skipped")
2077 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002078 dependsOn downloadDeps
2079 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01002080 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01002081 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002082 dependsOn buildSmali
2083 dependsOn jctfCommonJar
2084 dependsOn jctfTestsClasses
2085 dependsOn buildDebugInfoExamplesDex
2086 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002087 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02002088 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02002089 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002090 } else {
2091 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002092 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002093 }
2094}
2095
2096// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2097//
2098// To build and upload a new set of the Art tests for use with R8 follow these steps:
2099//
2100// First of all an Android checkout is required. Currently it must be located
2101// in $HOME/android/master.
2102//
2103// TODO(ricow): simplify this
2104//
2105// Before: update the checked in art, see scripts/update-host-art.sh
2106//
2107// 1. Get an android checkout in $HOME/android/master and apply the patch from
2108// https://android-review.googlesource.com/#/c/294187/
2109//
2110// 2. run the following commands in the Android checkout directory:
2111//
2112// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002113// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2114// m desugar
2115// m -j30 test-art-host
2116// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2117//
2118// Without running the test.py command the classes.jar file used by desugar in
2119// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2120// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002121//
2122// 3. In the R8 project root directory, make sure we have a clean state before starting:
2123// tools/gradle.py downloadDeps
2124// tools/gradle.py clean
2125// rm -rf tests/art
2126//
2127// 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 +02002128// Make sure you have smali on your path, please use the build binary in the
2129// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2130// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2131// 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 +02002132// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2133// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002134//
Søren Gjesse34b77732017-07-07 13:56:21 +02002135// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002136//
2137// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2138// skippedTests with an explanation. Rerun from step 3.
2139//
2140// 5. Run the tests:
2141// tools/gradle.py clean
2142// tools/test.py
2143//
Søren Gjesse34b77732017-07-07 13:56:21 +02002144// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2145// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2146// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002147//
Søren Gjesse34b77732017-07-07 13:56:21 +02002148// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002149// cd tests
2150// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002151//
2152// 7. Update the manifest file describing the Android repo used:
2153// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002154
Mads Ager418d1ca2017-05-22 09:35:49 +02002155def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002156
2157def artTestDir = file("${androidCheckoutDir}/art/test")
2158
2159if (project.hasProperty('android_source')) {
2160 task buildArtTests {
2161 outputs.upToDateWhen { false }
2162 def toBeTriaged = [
2163 "903-hello-tagging",
2164 "904-object-allocation",
2165 "905-object-free",
2166 "906-iterate-heap",
2167 "907-get-loaded-classes",
2168 "908-gc-start-finish",
2169 "954-invoke-polymorphic-verifier",
2170 "955-methodhandles-smali",
2171 "596-monitor-inflation",
2172 ]
2173 def skippedTests = toBeTriaged + [
2174 // This test produces no jar.
2175 "000-nop",
2176 // This does not build, as it tests the error when the application exceeds more
2177 // than 65536 methods
2178 "089-many-methods",
2179 // Requires some jack beta jar
2180 "956-methodhandles",
2181 ]
2182
2183 def skippedTestsDx = [
2184 // Tests with custom build scripts, where javac is not passed the options
2185 // -source 1.7 -target 1.7.
2186 "462-checker-inlining-across-dex-files",
2187 "556-invoke-super",
2188 "569-checker-pattern-replacement",
2189 // These tests use jack even when --build-with-javac-dx is specified.
2190 "004-JniTest",
2191 "048-reflect-v8",
2192 "146-bad-interface",
2193 "563-checker-invoke-super",
2194 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2195 "604-hot-static-interface",
2196 "957-methodhandle-transforms",
2197 "958-methodhandle-emulated-stackframe",
2198 "959-invoke-polymorphic-accessors",
2199 "961-default-iface-resolution-gen",
2200 "962-iface-static",
2201 "963-default-range-smali",
2202 "964-default-iface-init-gen",
2203 "965-default-verify",
2204 "966-default-conflict",
2205 "967-default-ame",
2206 "968-default-partial-compile-gen",
2207 "969-iface-super",
2208 "970-iface-super-resolution-gen",
2209 "971-iface-super",
2210 // These tests does not build with --build-with-javac-dx
2211 "004-NativeAllocations", // Javac error
2212 "031-class-attributes",
2213 "138-duplicate-classes-check",
2214 "157-void-class", // Javac error
2215 "580-checker-string-factory-intrinsics",
2216 "612-jit-dex-cache",
2217 "613-inlining-dex-cache",
2218 "900-hello-plugin", // --experimental agents
2219 "901-hello-ti-agent", // --experimental agents
2220 "902-hello-transformation", // --experimental agents
2221 "909-attach-agent", // --experimental agents
2222 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2223 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2224 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2225 "960-default-smali", // --experimental default-methods
2226 // These tests force the build to use jack
2227 "953-invoke-polymorphic-compiler",
2228 "958-methodhandle-stackframe",
2229 ]
2230
2231 def artTestBuildDir = file("${projectDir}/tests/art")
2232
2233 if (androidCheckoutDir.exists()) {
2234 dependsOn downloadDeps
2235 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002236 artTestDir.eachDir { dir ->
2237 def name = dir.getName();
2238 def markerFile = dir.toPath().resolve("info.txt").toFile();
2239 if (markerFile.exists() && !(name in skippedTests)) {
2240 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002241 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002242 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002243 }
2244 }
2245 }
2246 doFirst {
2247 if (!androidCheckoutDir.exists()) {
2248 throw new InvalidUserDataException(
2249 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002250 }
2251 }
2252 doLast {
2253 copy {
2254 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2255 into file("${artTestBuildDir}/lib64")
2256 include 'lib*.so'
2257 }
2258 copy {
2259 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2260 into file("${artTestBuildDir}/lib64")
2261 include 'libart.so'
2262 include 'libbacktrace.so'
2263 include 'libbase.so'
2264 include 'libc++.so'
2265 include 'libcutils.so'
2266 include 'liblz4.so'
2267 include 'liblzma.so'
2268 include 'libnativebridge.so'
2269 include 'libnativeloader.so'
2270 include 'libsigchain.so'
2271 include 'libunwind.so'
2272 include 'libziparchive.so'
2273 }
2274 copy {
2275 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2276 into file("${artTestBuildDir}/lib")
2277 include 'lib*.so'
2278 }
2279 copy {
2280 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2281 into file("${artTestBuildDir}/lib")
2282 include 'libart.so'
2283 include 'libbacktrace.so'
2284 include 'libbase.so'
2285 include 'libc++.so'
2286 include 'libcutils.so'
2287 include 'liblz4.so'
2288 include 'liblzma.so'
2289 include 'libnativebridge.so'
2290 include 'libnativeloader.so'
2291 include 'libsigchain.so'
2292 include 'libunwind.so'
2293 include 'libziparchive.so'
2294 }
2295 }
2296 }
2297}
2298
Rico Windde2af6c2019-03-26 15:21:08 +01002299def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002300 def artTestDir = file("${androidCheckoutDir}/art/test")
2301 def artRunTestScript = file("${artTestDir}/run-test")
2302 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002303 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002304
Søren Gjesse34b77732017-07-07 13:56:21 +02002305 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002306 def buildTask = "build_art_test_dx_${name}"
2307 def sanitizeTask = "sanitize_art_test_dx_${name}"
2308 def copyCheckTask = "copy_check_art_test_dx_${name}"
2309 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002310
2311 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002312 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002313 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2314 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002315 task "$buildTask"(type: Exec) {
2316 outputs.upToDateWhen { false }
2317 inputs.file buildInputs
2318 executable "${artRunTestScript}"
2319 args "--host"
2320 args "--build-only"
2321 args "--build-with-javac-dx"
2322 args "--output-path", "${testDir}"
2323 args "${name}"
2324 environment DX: "${dxExecutable.absolutePath}"
2325 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2326 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2327 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002328 }
2329 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2330 outputs.upToDateWhen { false }
2331 executable "/bin/bash"
2332 args "-c"
2333 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2334 " ${testDir}/classes-ex ${testDir}/check"
2335 }
2336
2337 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002338 // Directory that contains smali files is either smali, or smali/art
2339 def smali_dir = file("${dir}/smali/art")
2340 if (smali_dir.exists()) {
2341 workingDir "${testDir}/smali/art"
2342 } else {
2343 workingDir "${testDir}/smali"
2344 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002345 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002346 // This is the command line options for smali prior to 2.2.1, where smali got a new
2347 // command line interface.
2348 args "-c", "smali a *.smali"
2349 // This is the command line options for smali 2.2.1 and later.
2350 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002351 }
2352
2353 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2354 def smali_dir = file("${dir}/smali")
2355 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002356 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002357 dependsOn smaliToDexTask
2358 }
2359 from("${artTestDir}/${name}") {
2360 include 'check'
2361 }
2362 into testDir
2363 }
2364
2365 return copyCheckTask
2366}
2367
2368task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002369 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002370 classpath = sourceSets.main.compileClasspath
2371 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002372 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002373 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002374 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002375 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002376 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002377 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002378 include '**/com/android/tools/r8/CompilationMode.java'
2379 include '**/com/android/tools/r8/D8.java'
2380 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002381 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2382 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002383 include '**/com/android/tools/r8/Diagnostic.java'
2384 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002385 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2386 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002387 include '**/com/android/tools/r8/ProgramConsumer.java'
2388 include '**/com/android/tools/r8/ProgramResource.java'
2389 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002390 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002391 include '**/com/android/tools/r8/ResourceException.java'
2392 include '**/com/android/tools/r8/StringConsumer.java'
2393 include '**/com/android/tools/r8/StringResource.java'
2394 include '**/com/android/tools/r8/Version.java'
2395 include '**/com/android/tools/r8/origin/*.java'
2396}
2397
2398task javadocR8(type: Javadoc) {
2399 title "R8 API"
2400 classpath = sourceSets.main.compileClasspath
2401 source = sourceSets.main.allJava
2402 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2403 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2404 include '**/com/android/tools/r8/BaseCommand.java'
2405 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2406 include '**/com/android/tools/r8/ClassFileConsumer.java'
2407 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2408 include '**/com/android/tools/r8/CompilationFailedException.java'
2409 include '**/com/android/tools/r8/CompilationMode.java'
2410 include '**/com/android/tools/r8/R8.java'
2411 include '**/com/android/tools/r8/R8Command.java'
2412 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2413 include '**/com/android/tools/r8/Diagnostic.java'
2414 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002415 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2416 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002417 include '**/com/android/tools/r8/ProgramConsumer.java'
2418 include '**/com/android/tools/r8/ProgramResource.java'
2419 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2420 include '**/com/android/tools/r8/Resource.java'
2421 include '**/com/android/tools/r8/ResourceException.java'
2422 include '**/com/android/tools/r8/StringConsumer.java'
2423 include '**/com/android/tools/r8/StringResource.java'
2424 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002425 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002426}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002427
2428task copyMavenDeps(type: Copy) {
2429 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002430 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002431 from configurations.testCompile into "$buildDir/deps"
2432}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002433
Rico Wind23a05112019-03-27 08:00:44 +01002434task printMavenDeps {
2435 // Only actually print to stdout when we are updating.
2436 if (project.hasProperty('updatemavendeps')) {
2437 for (Configuration config : configurations) {
2438 if (!config.isCanBeResolved()) {
2439 continue
2440 }
2441 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2442 it.selected.id
2443 }
2444 def result = dependencies.createArtifactResolutionQuery()
2445 .forComponents(componentIds)
2446 .withArtifacts(MavenModule, MavenPomArtifact)
2447 .execute()
2448 for (component in result.resolvedComponents) {
2449 component.getArtifacts(MavenPomArtifact).each {
2450 println "POM: ${it.file} ${component.id}"
2451 }
2452 }
2453 config.each {
2454 println "JAR: ${it}"
2455 }
2456 }
2457 }
2458}
Ian Zerny9713c032020-01-23 11:41:58 +01002459
2460allprojects {
2461 tasks.withType(Exec) {
2462 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002463 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002464 }
2465 }
Søren Gjesse494609e2020-05-29 15:35:12 +02002466}