blob: 1b9fc300f683e5ec4984c26efad289df8844ca31 [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
Ian Zerny5fffb0a2019-02-11 13:54:22 +01006import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02007import org.gradle.internal.os.OperatingSystem
Ian Zernyb2d27c42019-02-20 09:09:41 +01008import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00009import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020010import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020011
Ian Zerny5fffb0a2019-02-11 13:54:22 +010012buildscript {
13 repositories {
Rico Wind23a05112019-03-27 08:00:44 +010014 maven {
15 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
16 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010017 mavenCentral()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010018 maven {
19 url "https://plugins.gradle.org/m2/"
20 }
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010021 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010022 }
23 dependencies {
24 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
25 }
26}
27
28plugins {
29 id "net.ltgt.errorprone" version "0.7"
30}
31
32apply plugin: 'java'
33apply plugin: 'idea'
34
Sebastien Hertz143ed112018-02-13 14:26:41 +010035ext {
36 androidSupportVersion = '25.4.0'
clementbera45cea0a2019-04-09 09:26:57 +020037 asmVersion = '7.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010038 espressoVersion = '3.0.0'
39 fastutilVersion = '7.2.0'
40 guavaVersion = '23.0'
41 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020042 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010043 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080044 mockitoVersion = '2.10.0'
Jinseong Jeon46146f42018-12-16 23:26:14 -080045 kotlinVersion = '1.3.11'
Jinseong Jeonb6fe4fe2018-12-03 00:49:13 -080046 kotlinExtMetadataJVMVersion = '0.0.4'
Sebastien Hertz143ed112018-02-13 14:26:41 +010047 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010048 errorproneVersion = '2.3.2'
Sebastien Hertz143ed112018-02-13 14:26:41 +010049}
50
Mads Ager418d1ca2017-05-22 09:35:49 +020051apply from: 'copyAdditionalJctfCommonFiles.gradle'
52
53repositories {
Rico Wind23a05112019-03-27 08:00:44 +010054 maven {
55 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
56 }
Yohann Roussel126f6872017-08-03 16:25:32 +020057 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020058 mavenCentral()
Morten Krogh-Jespersene45b0f92019-03-21 09:56:19 +010059 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020060}
61
Jinseong Jeon05064e12018-07-03 00:21:12 -070062if (project.hasProperty('with_code_coverage')) {
63 apply plugin: 'jacoco'
64}
65
Mads Ager418d1ca2017-05-22 09:35:49 +020066// Custom source set for example tests and generated tests.
67sourceSets {
68 test {
69 java {
70 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020071 'src/test/java',
72 'build/generated/test/java',
73 ]
74 }
75 }
Yohann Rousselbb571622017-11-09 10:47:36 +010076 apiUsageSample {
77 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020078 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
79 include 'com/android/tools/apiusagesample/*.java'
80 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
81 include 'com/android/tools/r8/D8CommandParser.java'
82 include 'com/android/tools/r8/R8CommandParser.java'
83 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010084 }
Yohann Rousselbb571622017-11-09 10:47:36 +010085 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010086 cfSegments {
87 java {
88 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
89 }
90 output.resourcesDir = 'build/classes/cfSegments'
91 }
Mads Ager418d1ca2017-05-22 09:35:49 +020092 debugTestResources {
93 java {
94 srcDirs = ['src/test/debugTestResources']
95 }
96 output.resourcesDir = 'build/classes/debugTestResources'
97 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020098 debugTestResourcesJava8 {
99 java {
100 srcDirs = ['src/test/debugTestResourcesJava8']
101 }
102 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
103 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200104 debugTestResourcesKotlin {
105 java {
106 srcDirs = ['src/test/debugTestResourcesKotlin']
107 }
108 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
109 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200110 examples {
111 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800112 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200113 }
114 output.resourcesDir = 'build/classes/examples'
115 }
Ian Zernyd3020482019-04-25 07:05:04 +0200116 examplesJava9 {
117 java {
118 srcDirs = [
119 'src/test/examplesJava9'
120 ]
121 }
122 }
123 examplesJava11 {
124 java {
125 srcDirs = [
126 'src/test/examplesJava11'
127 ]
128 }
129 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100130 examplesKotlin {
131 java {
132 srcDirs = ['src/test/examplesKotlin']
133 }
134 output.resourcesDir = 'build/classes/examplesKotlin'
135 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200136 examplesAndroidN {
137 java {
138 srcDirs = ['src/test/examplesAndroidN']
139 }
140 output.resourcesDir = 'build/classes/examplesAndroidN'
141 }
142 examplesAndroidO {
143 java {
144 srcDirs = ['src/test/examplesAndroidO']
145 }
146 output.resourcesDir = 'build/classes/examplesAndroidO'
147 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200148 examplesAndroidP {
149 java {
150 srcDirs = ['src/test/examplesAndroidP']
151 }
152 output.resourcesDir = 'build/classes/examplesAndroidP'
153 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200154 jctfCommon {
155 java {
156 srcDirs = [
157 'third_party/jctf/Harness/src',
158 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
159 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
160 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
161 'third_party/jctf/LibTests/src/org',
162 'build/additionalJctfCommonFiles'
163 ]
164 }
165 resources {
166 srcDirs = ['third_party/jctf/LibTests/resources']
167 }
168 }
169 jctfTests {
170 java {
171 srcDirs = [
172 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
173 // 'third_party/jctf/VMTests/src',
174 ]
175 }
176 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100177 kotlinR8TestResources {
178 java {
179 srcDirs = ['src/test/kotlinR8TestResources']
180 }
181 output.resourcesDir = 'build/classes/kotlinR8TestResources'
182 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200183}
184
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800185// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
186// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
187// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
188// for context.
189idea {
190 sourceSets.all { SourceSet sources ->
191 module {
192 if (sources.name == "main") {
193 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100194 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800195 } else {
196 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100197 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800198 }
199 }
200 }
201}
202
Yohann Roussel126f6872017-08-03 16:25:32 +0200203configurations {
204 supportLibs
205}
206
Mads Ager418d1ca2017-05-22 09:35:49 +0200207dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100208 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
209 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200210 // Include all of guava when compiling the code, but exclude annotations that we don't
211 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100212 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100213 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200214 exclude group: 'com.google.errorprone'
215 exclude group: 'com.google.code.findbugs'
216 exclude group: 'com.google.j2objc'
217 exclude group: 'org.codehaus.mojo'
218 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100219 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
220 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
221 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
222 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
223 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
224 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
225 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200226 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100227 testCompile "junit:junit:$junitVersion"
228 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200229 testCompile files('third_party/jasmin/jasmin-2.4.jar')
230 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200231 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100232 jctfCommonCompile "junit:junit:$junitVersion"
233 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200234 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100235 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
236 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200237 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100238 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800239 examplesCompile "junit:junit:$junitVersion"
240 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100241 supportLibs "com.android.support:support-v4:$androidSupportVersion"
242 supportLibs "junit:junit:$junitVersion"
243 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100244 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100245 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100246 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
247 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
248 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100249 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200250}
251
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100252def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100253def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100254def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100255def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100256def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100257
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200258def osString = OperatingSystem.current().isLinux() ? "linux" :
259 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200260
261def cloudDependencies = [
262 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200263 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100264 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200265 ],
266 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200267 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200268 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100269 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200270 "android_jar/lib-v19",
271 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100272 "android_jar/lib-v22",
273 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200274 "android_jar/lib-v24",
275 "android_jar/lib-v25",
276 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100277 "android_jar/lib-v27",
278 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200279 "core-lambda-stubs",
280 "dart-sdk",
281 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200282 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200283 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200284 "jasmin",
285 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100286 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200287 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200288 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100289 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200290 "proguard/proguard5.2.1",
291 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200292 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200293 ],
294 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
295 // container on other platforms where supported.
296 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200297 "linux/art",
298 "linux/art-5.1.1",
299 "linux/art-6.0.1",
300 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100301 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100302 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200303 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100304 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200305 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200306 ]
307]
308
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100309def cloudSystemDependencies = [
310 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200311 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200312 "openjdk/jdk8/linux-x86",
313 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100314 ],
315 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200316 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200317 "openjdk/jdk8/darwin-x86",
318 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100319 ],
320 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200321 "third_party": ["openjdk/openjdk-9.0.4/windows",
322 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100323 ],
324]
325
326if (OperatingSystem.current().isWindows()) {
327 cloudSystemDependencies.windows.each { entry ->
328 cloudDependencies.get(entry.key).addAll(entry.value)
329 }
330} else if (OperatingSystem.current().isLinux()) {
331 cloudSystemDependencies.linux.each { entry ->
332 cloudDependencies.get(entry.key).addAll(entry.value)
333 }
334} else if (OperatingSystem.current().isMacOsX()) {
335 cloudSystemDependencies.osx.each { entry ->
336 cloudDependencies.get(entry.key).addAll(entry.value)
337 }
338} else {
339 println "WARNING: Unsupported system: " + OperatingSystem.current()
340}
341
342def getDownloadDepsTaskName(entryKey, entryFile) {
343 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
344}
345
Ian Zernyb2d27c42019-02-20 09:09:41 +0100346def getFetchDepsTaskName(entryKey, entryFile) {
347 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
348}
349
Mads Ager418d1ca2017-05-22 09:35:49 +0200350cloudDependencies.each { entry ->
351 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100352 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
353 type DownloadDependency.Type.GOOGLE_STORAGE
354 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200355 }
356 }
357}
358
359def x20Dependencies = [
360 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200361 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200362 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100363 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100364 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200365 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100366 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200367 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200368 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200369 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200370 "gmscore/gmscore_v10",
371 "gmscore/gmscore_v9",
372 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200373 "gmscore/v4",
374 "gmscore/v5",
375 "gmscore/v6",
376 "gmscore/v7",
377 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200378 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200379 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200380 "proguard/proguard_internal_159423826",
381 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200382 "youtube/youtube.android_12.10",
383 "youtube/youtube.android_12.17",
384 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200385 "youtube/youtube.android_13.37",
Rico Wind5acd2b62019-05-10 08:29:01 +0200386 "youtube/youtube.android_14.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200387 ],
388]
389
390x20Dependencies.each { entry ->
391 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100392 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
393 type DownloadDependency.Type.X20
394 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200395 }
396 }
397}
398
Rico Wind897bb712017-05-23 10:44:29 +0200399task downloadProguard {
400 cloudDependencies.each { entry ->
401 entry.value.each { entryFile ->
402 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100403 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200404 }
405 }
406 }
407}
408
Rico Windf6c74ce2018-12-04 08:50:55 +0100409task downloadOpenJDKrt {
410 cloudDependencies.each { entry ->
411 entry.value.each { entryFile ->
412 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100413 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100414 }
415 }
416 }
417}
418
Tamas Kenez427205b2017-06-29 15:57:09 +0200419task downloadDx {
420 cloudDependencies.each { entry ->
421 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200422 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100423 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200424 }
425 }
426 }
427}
428
Tamas Kenez0e10c562017-06-08 10:00:34 +0200429task downloadAndroidCts {
430 cloudDependencies.each { entry ->
431 entry.value.each { entryFile ->
432 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100433 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200434 }
435 }
436 }
437}
438
Mads Ager418d1ca2017-05-22 09:35:49 +0200439task downloadDeps {
440 cloudDependencies.each { entry ->
441 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100442 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200443 }
444 }
445 if (!project.hasProperty('no_internal')) {
446 x20Dependencies.each { entry ->
447 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100448 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200449 }
450 }
451 }
452}
453
454allprojects {
455 sourceCompatibility = JavaVersion.VERSION_1_8
456 targetCompatibility = JavaVersion.VERSION_1_8
457}
458
Rico Wind266336c2019-02-25 10:11:38 +0100459// TODO(ricow): Remove debug prints
460println("NOTE: Current operating system: " + OperatingSystem.current())
461println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
462
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100463// Check if running with the JDK location from tools/jdk.py.
464if (OperatingSystem.current().isWindows()) {
465 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
466} else {
467 def javaHomeOut = new StringBuilder()
468 def javaHomeErr = new StringBuilder()
469 def javaHomeProc = './tools/jdk.py'.execute()
470 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
471 def jdkHome = new File(javaHomeOut.toString().trim())
472 if (!jdkHome.exists()) {
473 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
474 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
475 println("WARNING: Gradle is running in a non-pinned Java"
476 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
477 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100478 } else {
479 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100480 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200481}
482
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100483sourceSets.configureEach { sourceSet ->
484 tasks.named(sourceSet.compileJavaTaskName).configure {
485 // Default disable errorprone (enabled and setup below).
486 options.errorprone.enabled = false
487 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100488 // Run all compilation tasks in a forked subprocess.
489 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100490 // Javac often runs out of stack space when compiling the tests.
491 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100492 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100493 // Test compilation is sometimes hitting the default limit at 1g, increase it.
494 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100495 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
496 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
497 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200498}
499
Ian Zernyd3020482019-04-25 07:05:04 +0200500tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
501 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200502 options.fork = true
503 options.forkOptions.jvmArgs = []
504 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200505 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200506 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200507 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200508 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200509 options.forkOptions.javaHome = file(jdkDir + 'windows')
510 }
511 sourceCompatibility = JavaVersion.VERSION_1_9
512 targetCompatibility = JavaVersion.VERSION_1_9
513}
514
515tasks.named(sourceSets.examplesJava11.compileJavaTaskName).get().configure {
516 def jdkDir = 'third_party/openjdk/jdk-11/'
517 options.fork = true
518 options.forkOptions.jvmArgs = []
519 if (OperatingSystem.current().isLinux()) {
520 options.forkOptions.javaHome = file(jdkDir + 'Linux')
521 } else if (OperatingSystem.current().isMacOsX()) {
522 options.forkOptions.javaHome = file(jdkDir + 'Mac')
523 } else {
524 options.forkOptions.javaHome = file(jdkDir + 'Windows')
clementbera0fe940d2019-04-23 12:45:18 +0200525 }
526 sourceCompatibility = JavaVersion.VERSION_11
527 targetCompatibility = JavaVersion.VERSION_11
528}
529
530
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100531if (!project.hasProperty('without_error_prone') &&
532 // Don't enable error prone on Java 8 as the plugin setup does not support it.
533 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200534 compileJava {
535 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100536 options.errorprone.enabled = true
537 options.errorprone.disableAllChecks = true
538 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
539 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
540 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
541 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
542 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
543 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
544 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
545 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
546 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
547 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
548 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
549 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
550 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
551 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
552 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
553 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
554 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
555 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
556 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200557 }
558}
559
Mads Ager418d1ca2017-05-22 09:35:49 +0200560compileJctfCommonJava {
561 dependsOn 'copyAdditionalJctfCommonFiles'
562 options.compilerArgs = ['-Xlint:none']
563}
564
565compileJctfTestsJava {
566 dependsOn 'jctfCommonClasses'
567 options.compilerArgs = ['-Xlint:none']
568}
569
Yohann Roussel7f47c032017-09-14 12:19:06 +0200570task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200571 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100572
Yohann Roussel7f47c032017-09-14 12:19:06 +0200573 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100574 def runtimeClasspath = configurations.findByName("runtimeClasspath")
575 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
576
Yohann Roussel7f47c032017-09-14 12:19:06 +0200577 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100578
Yohann Roussel7f47c032017-09-14 12:19:06 +0200579 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100580 def dependencies = []
581 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
582 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
583 dependencies.add("${identifier.group}:${identifier.module}")
584 }
585 def libraryLicenses = file('LIBRARY-LICENSE').text
586 dependencies.each {
587 if (!libraryLicenses.contains("- artifact: $it")) {
588 throw new GradleException("No license for $it in LIBRARY_LICENSE")
589 }
590 }
591
Yohann Roussel7f47c032017-09-14 12:19:06 +0200592 license.getParentFile().mkdirs()
593 license.createNewFile()
594 license.text = "This file lists all licenses for code distributed.\n"
595 license.text += "All non-library code has the following 3-Clause BSD license.\n"
596 license.text += "\n"
597 license.text += "\n"
598 license.text += file('LICENSE').text
599 license.text += "\n"
600 license.text += "\n"
601 license.text += "Summary of distributed libraries:\n"
602 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100603 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200604 license.text += "\n"
605 license.text += "\n"
606 license.text += "Licenses details:\n"
607 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
608 license.text += "\n"
609 license.text += "\n"
610 license.text += file.text
611 }
612 }
613}
614
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200615static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700616 // Everything under META-INF is not included by default.
617 // Should include before 'relocate' so that the service file path and its content
618 // are properly relocated as well.
619 task.mergeServiceFiles {
620 include 'META-INF/services/*'
621 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200622}
623
624static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000625 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200626 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000627 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
628 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000629 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000630 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200631 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
632 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
633 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200634 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000635}
636
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100637task repackageDepsNoRelocate(type: ShadowJar) {
638 configurations = [project.configurations.runtimeClasspath]
639 mergeServiceFiles(it)
640 exclude { it.getRelativePath().getPathString() == "module-info.class" }
641 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100642 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100643}
644
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000645task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100646 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200647 mergeServiceFiles(it)
648 if (!project.hasProperty('lib_no_relocate')) {
649 configureRelocations(it)
650 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100651 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700652 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000653 baseName 'deps'
654}
655
656task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200657 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200658 mergeServiceFiles(it)
659 if (!project.hasProperty('lib_no_relocate')) {
660 configureRelocations(it)
661 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000662 baseName 'sources'
663}
664
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100665task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200666 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100667 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200668 classifier = null
669 version = null
670 manifest {
671 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
672 }
673 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100674 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100675 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100676 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200677}
678
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100679task r8WithoutDeps(type: ShadowJar) {
680 from consolidatedLicense.outputs.files
681 baseName 'r8_without_deps'
682 classifier = null
683 version = null
684 manifest {
685 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
686 }
687 from sourceSets.main.output
688}
689
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000690task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200691 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200692 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200693 classifier = null
694 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200695 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200696 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200697 }
698 // In order to build without dependencies, pass the exclude_deps property using:
699 // gradle -Pexclude_deps R8
700 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800701 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000702 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800703 } else {
704 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200705 }
Ian Zerny80533c92019-01-24 10:32:09 +0100706 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200707}
708
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100709task R8NoManifestNoDeps(type: ShadowJar) {
710 from consolidatedLicense.outputs.files
711 baseName 'r8nomanifest-exclude-deps'
712 classifier = null
713 version = null
714 from sourceSets.main.output
715}
716
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100717task R8NoManifest(type: ShadowJar) {
718 from consolidatedLicense.outputs.files
719 baseName 'r8nomanifest'
720 classifier = null
721 version = null
722 // In order to build without dependencies, pass the exclude_deps property using:
723 // gradle -Pexclude_deps R8
724 if (!project.hasProperty('exclude_deps')) {
725 from repackageSources.outputs.files
726 from repackageDeps.outputs.files
727 } else {
728 from sourceSets.main.output
729 }
Ian Zerny80533c92019-01-24 10:32:09 +0100730 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100731}
732
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000733task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200734 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200735 baseName 'd8'
736 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200737 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200738 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200739}
740
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200741task CompatDx(type: ShadowJar) {
742 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200743 baseName 'compatdx'
744 manifest {
745 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
746 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200747}
748
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200749task CompatProguard(type: ShadowJar) {
750 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200751 baseName 'compatproguard'
752 manifest {
753 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
754 }
Lars Bak44cef522017-08-10 16:02:39 +0200755}
756
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100757def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100758 // Execute r8 commands against a stable r8 with relocated dependencies.
Rico Windcfb65512019-02-27 12:57:34 +0100759 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
760 "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100761}
762
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100763def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100764 return baseR8CommandLine([
765 "--classfile", "--release",
766 input,
767 "--output", output,
768 "--pg-conf", pgconf,
769 "--pg-map-output", output + ".map",
770 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
771 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100772}
773
774def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
775 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100776 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100777 outputs.file output
778 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100779 dependsOn r8WithRelocatedDeps
780 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100781 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
782 workingDir = projectDir
783 }
784}
785
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100786task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100787 baseName = "r8tests"
788 from sourceSets.test.output
789}
790
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100791task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
792 baseName = "r8tests-exclude-deps"
793 from sourceSets.test.output
794}
795
796def generateR8LibKeepRules(name, r8Source, testSource, output) {
797 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
798 doFirst {
799 standardOutput new FileOutputStream(output)
800 }
801 dependsOn r8WithRelocatedDeps
802 dependsOn r8Source
803 dependsOn testSource
804 dependsOn downloadOpenJDKrt
805 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
806 outputs.file output
807 commandLine baseR8CommandLine([
808 "printuses",
809 "--keeprules",
810 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
811 r8Source.outputs.files[0],
812 testSource.outputs.files[0]])
813 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100814 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100815}
816
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100817task R8LibApiOnly {
818 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
819 outputs.file r8LibPath
820}
821
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100822task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100823 def genRulesTask = generateR8LibKeepRules(
824 "Main",
825 R8NoManifest,
826 testJar,
827 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100828 dependsOn r8LibCreateTask(
829 "Main",
830 "src/main/keep.txt",
831 R8NoManifest,
832 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100833 ["--pg-conf", genRulesTask.outputs.files[0]]
834 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100835 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100836}
837
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100838task R8LibNoDeps {
839 def genRulesTask = generateR8LibKeepRules(
840 "NoDeps",
841 R8NoManifestNoDeps,
842 testJarNoDeps,
843 r8LibGeneratedKeepRulesExcludeDepsPath
844 )
845 dependsOn r8LibCreateTask(
846 "NoDeps",
847 "src/main/keep.txt",
848 R8NoManifestNoDeps,
849 r8LibExludeDepsPath,
850 ["--pg-conf", genRulesTask.outputs.files[0]],
851 repackageDepsNoRelocate.outputs.files
852 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
853 outputs.file r8LibExludeDepsPath
854}
855
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100856task CompatDxLib {
857 dependsOn r8LibCreateTask(
858 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100859}
860
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100861task CompatProguardLib {
862 dependsOn r8LibCreateTask(
863 "CompatPg",
864 "src/main/keep-compatproguard.txt",
865 CompatProguard,
866 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100867}
868
Mads Ager418d1ca2017-05-22 09:35:49 +0200869task sourceJar(type: Jar, dependsOn: classes) {
870 classifier = 'src'
871 from sourceSets.main.allSource
872}
873
874task jctfCommonJar(type: Jar) {
875 from sourceSets.jctfCommon.output
876 baseName 'jctfCommon'
877}
878
879artifacts {
880 archives sourceJar
881}
882
883task createArtTests(type: Exec) {
884 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200885 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100886 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200887 outputs.dir outputDir
888 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200889 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200890 workingDir = projectDir
891}
892
893task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200894 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200895 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200896 inputs.file script
897 outputs.dir outputDir
898 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200899 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200900 workingDir = projectDir
901}
902
903compileTestJava {
904 dependsOn createArtTests
905 dependsOn createJctfTests
906}
907
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100908task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
909 from sourceSets.cfSegments.output
910 baseName 'cf_segments'
911 destinationDir file('build/libs')
912}
913
Ian Zernyee23a172018-01-03 09:08:48 +0100914task buildD8ApiUsageSample(type: Jar) {
915 from sourceSets.apiUsageSample.output
916 baseName 'd8_api_usage_sample'
917 destinationDir file('tests')
918}
919
Ian Zerny923a0c12018-01-03 10:59:18 +0100920task buildR8ApiUsageSample(type: Jar) {
921 from sourceSets.apiUsageSample.output
922 baseName 'r8_api_usage_sample'
923 destinationDir file('tests')
924}
925
Yohann Roussel548ae942018-01-05 11:13:28 +0100926task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100927 dependsOn buildD8ApiUsageSample
928 dependsOn buildR8ApiUsageSample
929}
930
Mads Ager418d1ca2017-05-22 09:35:49 +0200931task buildDebugInfoExamplesDex {
932 def examplesDir = file("src/test/java")
933 def hostJar = "debuginfo_examples.jar"
934 def hostDexJar = "debuginfo_examples_dex.jar"
935 task "compile_debuginfo_examples"(type: JavaCompile) {
936 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
937 destinationDir = file("build/test/debuginfo_examples/classes")
938 classpath = sourceSets.main.compileClasspath
939 sourceCompatibility = JavaVersion.VERSION_1_7
940 targetCompatibility = JavaVersion.VERSION_1_7
941 options.compilerArgs += ["-Xlint:-options"]
942 }
943 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
944 archiveName = hostJar
945 destinationDir = file("build/test/")
946 from "build/test/debuginfo_examples/classes"
947 include "**/*.class"
948 }
949 task "dex_debuginfo_examples"(type: Exec,
950 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200951 if (OperatingSystem.current().isWindows()) {
952 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700953 } else if (OperatingSystem.current().isMacOsX()) {
954 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200955 } else {
956 executable file("tools/linux/dx/bin/dx");
957 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200958 args "--dex"
959 args "--output=build/test/${hostDexJar}"
960 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100961 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200962 outputs.file file("build/test/${hostDexJar}")
963 }
964 dependsOn dex_debuginfo_examples
965}
966
967task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200968 def resourcesDir = file("src/test/debugTestResources")
969 def hostJar = "debug_test_resources.jar"
970 task "compile_debugTestResources"(type: JavaCompile) {
971 source = fileTree(dir: resourcesDir, include: '**/*.java')
972 destinationDir = file("build/test/debugTestResources/classes")
973 classpath = sourceSets.main.compileClasspath
974 sourceCompatibility = JavaVersion.VERSION_1_7
975 targetCompatibility = JavaVersion.VERSION_1_7
976 options.compilerArgs += ["-g", "-Xlint:-options"]
977 }
978 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
979 archiveName = hostJar
980 destinationDir = file("build/test/")
981 from "build/test/debugTestResources/classes"
982 include "**/*.class"
983 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200984 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
985 def java8HostJar = "debug_test_resources_java8.jar"
986 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
987 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
988 destinationDir = file("build/test/debugTestResourcesJava8/classes")
989 classpath = sourceSets.main.compileClasspath
990 sourceCompatibility = JavaVersion.VERSION_1_8
991 targetCompatibility = JavaVersion.VERSION_1_8
992 options.compilerArgs += ["-g", "-Xlint:-options"]
993 }
994 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
995 archiveName = java8HostJar
996 destinationDir = file("build/test/")
997 from "build/test/debugTestResourcesJava8/classes"
998 include "**/*.class"
999 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001000 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001001 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1002 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1003 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1004 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001005 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001006 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001007 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001008 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001009 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001010}
1011
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001012// Examples used by tests, where Android specific APIs are used.
1013task buildExampleAndroidApi(type: JavaCompile) {
1014 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1015 destinationDir = file("build/test/examplesAndroidApi/classes")
1016 classpath = files("third_party/android_jar/lib-v26/android.jar")
1017 sourceCompatibility = JavaVersion.VERSION_1_8
1018 targetCompatibility = JavaVersion.VERSION_1_8
1019}
1020
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001021task buildExampleKotlinJars {
1022 def kotlinSrcDir = file("src/test/examplesKotlin")
1023 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001024 def name = dir.getName();
1025 dependsOn "compile_example_kotlin_${name}"
1026 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1027 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1028 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001029 }
1030 }
1031}
1032
Lars Bakc91e87e2017-08-18 08:53:10 +02001033// Proto lite generated code yields warnings when compiling with javac.
1034// We change the options passed to javac to ignore it.
1035compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1036
Søren Gjesse7320ce52018-05-07 15:45:22 +02001037
Mads Ager418d1ca2017-05-22 09:35:49 +02001038task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001039 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001040 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001041 def proguardScript
1042 if (OperatingSystem.current().isWindows()) {
1043 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1044 } else {
1045 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1046 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001047 task extractExamplesRuntime(type: Sync) {
1048 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001049 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001050 include "**/*.class"
1051 includeEmptyDirs false
1052 into "$buildDir/runtime/examples/"
1053 }
1054
Søren Gjesse7320ce52018-05-07 15:45:22 +02001055 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1056 from examplesDir
1057 exclude "**/*.java"
1058 exclude "**/keep-rules*.txt"
1059 into file("build/test/examples/classes")
1060 }
1061
1062 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001063 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001064 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001065 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001066 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001067 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001068 sourceCompatibility = JavaVersion.VERSION_1_7
1069 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001070 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1071 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001072 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1073 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001074 include "**/*.java"
1075 destinationDir = file("build/test/examples/classes_debuginfo_all")
1076 classpath = sourceSets.examples.compileClasspath
1077 sourceCompatibility = JavaVersion.VERSION_1_7
1078 targetCompatibility = JavaVersion.VERSION_1_7
1079 options.compilerArgs = ["-g", "-Xlint:none"]
1080 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001081 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1082 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001083 include "**/*.java"
1084 destinationDir = file("build/test/examples/classes_debuginfo_none")
1085 classpath = sourceSets.examples.compileClasspath
1086 sourceCompatibility = JavaVersion.VERSION_1_7
1087 targetCompatibility = JavaVersion.VERSION_1_7
1088 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001089 }
1090 examplesDir.eachDir { dir ->
1091 def name = dir.getName();
1092 def exampleOutputDir = file("build/test/examples");
1093 def jarName = "${name}.jar"
1094 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001095 dependsOn "jar_example_${name}_debuginfo_all"
1096 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001097 dependsOn "extractExamplesRuntime"
1098 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001099 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1100 def proguardConfigPath = "${dir}/proguard.cfg"
1101 if (new File(proguardConfigPath).exists()) {
1102 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1103 archiveName = "${name}_pre_proguard.jar"
1104 destinationDir = exampleOutputDir
1105 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001106 include name + "/**/*.class"
1107 with runtimeDependencies
1108 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001109 }
1110 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1111 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1112 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1113 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001114 inputs.files files(
1115 tasks.getByPath("pre_proguard_example_${name}"),
1116 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001117 // Enable these to get stdout and stderr redirected to files...
1118 // standardOutput = new FileOutputStream('proguard.stdout')
1119 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001120 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001121 " -outjars ${proguardJarPath}" +
1122 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001123 " -printmapping ${proguardMapPath}"
1124 if (OperatingSystem.current().isWindows()) {
1125 executable "${proguardScript}"
1126 args "${proguardArguments}"
1127 } else {
1128 executable "bash"
1129 args "-c", "${proguardScript} '${proguardArguments}'"
1130 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001131 outputs.file proguardJarPath
1132 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001133 // TODO: Consider performing distinct proguard compilations.
1134 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1135 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001136 into "${exampleOutputDir}"
1137 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001138 }
1139 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1140 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001141 into "${exampleOutputDir}"
1142 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001143 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001144 } else {
1145 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001146 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001147 destinationDir = exampleOutputDir
1148 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001149 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001150 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001151 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001152 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001153 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1154 archiveName = "${name}_debuginfo_all.jar"
1155 destinationDir = exampleOutputDir
1156 from "build/test/examples/classes_debuginfo_all"
1157 include name + "/**/*.class"
1158 with runtimeDependencies
1159 includeEmptyDirs false
1160 }
1161 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1162 archiveName = "${name}_debuginfo_none.jar"
1163 destinationDir = exampleOutputDir
1164 from "build/test/examples/classes_debuginfo_none"
1165 include name + "/**/*.class"
1166 with runtimeDependencies
1167 includeEmptyDirs false
1168 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001169 }
1170 }
1171}
1172
1173task buildExampleAndroidNJars {
1174 dependsOn downloadDeps
1175 def examplesDir = file("src/test/examplesAndroidN")
1176 task "compile_examplesAndroidN"(type: JavaCompile) {
1177 source = fileTree(dir: examplesDir, include: '**/*.java')
1178 destinationDir = file("build/test/examplesAndroidN/classes")
1179 classpath = sourceSets.main.compileClasspath
1180 sourceCompatibility = JavaVersion.VERSION_1_8
1181 targetCompatibility = JavaVersion.VERSION_1_8
1182 options.compilerArgs += ["-Xlint:-options"]
1183 }
1184 examplesDir.eachDir { dir ->
1185 def name = dir.getName();
1186 def exampleOutputDir = file("build/test/examplesAndroidN");
1187 def jarName = "${name}.jar"
1188 dependsOn "jar_examplesAndroidN_${name}"
1189 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1190 archiveName = jarName
1191 destinationDir = exampleOutputDir
1192 from "build/test/examplesAndroidN/classes"
1193 include "**/" + name + "/**/*.class"
1194 }
1195 }
1196}
1197
1198
1199task buildExampleAndroidOJars {
1200 dependsOn downloadDeps
1201 def examplesDir = file("src/test/examplesAndroidO")
1202 // NOTE: we want to enable a scenario when test needs to reference some
1203 // classes generated by legacy (1.6) Java compiler to test some specific
1204 // behaviour. To do so we compile all the java files located in sub-directory
1205 // called 'legacy' with Java 1.6, then compile the rest of the files with
1206 // Java 1.8 and a reference to previously generated 1.6 classes.
1207
1208 // Compiling all classes in dirs 'legacy' with old Java version.
1209 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1210 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1211 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1212 classpath = sourceSets.main.compileClasspath
1213 sourceCompatibility = JavaVersion.VERSION_1_6
1214 targetCompatibility = JavaVersion.VERSION_1_6
1215 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1216 }
1217 // Compiling the rest of the files as Java 1.8 code.
1218 task "compile_examplesAndroidO"(type: JavaCompile) {
1219 dependsOn "compile_examplesAndroidO_Legacy"
1220 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1221 destinationDir = file("build/test/examplesAndroidO/classes")
1222 classpath = sourceSets.main.compileClasspath
1223 classpath += files("build/test/examplesAndroidOLegacy/classes")
1224 sourceCompatibility = JavaVersion.VERSION_1_8
1225 targetCompatibility = JavaVersion.VERSION_1_8
1226 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1227 }
1228 examplesDir.eachDir { dir ->
1229 def name = dir.getName();
1230 def destinationDir = file("build/test/examplesAndroidO/classes");
1231 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1232 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1233 dependsOn: "compile_examplesAndroidO") {
1234 main = name + ".TestGenerator"
1235 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1236 args destinationDir
1237 }
1238 } else {
1239 task "generate_examplesAndroidO_${name}" () {}
1240 }
1241 }
1242 examplesDir.eachDir { dir ->
1243 def name = dir.getName();
1244 def exampleOutputDir = file("build/test/examplesAndroidO");
1245 def jarName = "${name}.jar"
1246 dependsOn "jar_examplesAndroidO_${name}"
1247 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1248 "generate_examplesAndroidO_${name}"]) {
1249 archiveName = jarName
1250 destinationDir = exampleOutputDir
1251 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1252 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1253 include "**/" + name + "/**/*.class"
1254 // Do not include generator into the test runtime jar, it is not useful.
1255 // Otherwise, shrinking will need ASM jars.
1256 exclude "**/TestGenerator*"
1257 }
1258 }
1259}
1260
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001261task buildExampleAndroidPJars {
1262 dependsOn downloadDeps
1263 def examplesDir = file("src/test/examplesAndroidP")
1264
1265 task "compile_examplesAndroidP"(type: JavaCompile) {
1266 source = fileTree(dir: examplesDir, include: '**/*.java')
1267 destinationDir = file("build/test/examplesAndroidP/classes")
1268 classpath = sourceSets.main.compileClasspath
1269 sourceCompatibility = JavaVersion.VERSION_1_8
1270 targetCompatibility = JavaVersion.VERSION_1_8
1271 options.compilerArgs += ["-Xlint:-options"]
1272 }
1273 examplesDir.eachDir { dir ->
1274 def name = dir.getName();
1275 def destinationDir = file("build/test/examplesAndroidP/classes");
1276 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1277 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1278 dependsOn: "compile_examplesAndroidP") {
1279 main = name + ".TestGenerator"
1280 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1281 args destinationDir
1282 }
1283 } else {
1284 task "generate_examplesAndroidP_${name}" () {}
1285 }
1286 }
1287 examplesDir.eachDir { dir ->
1288 def name = dir.getName();
1289 def exampleOutputDir = file("build/test/examplesAndroidP");
1290 def jarName = "${name}.jar"
1291 dependsOn "jar_examplesAndroidP_${name}"
1292 task "jar_examplesAndroidP_${name}"(type: Jar,
1293 dependsOn: ["compile_examplesAndroidP",
1294 "generate_examplesAndroidP_${name}"]) {
1295 archiveName = jarName
1296 destinationDir = exampleOutputDir
1297 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1298 include "**/" + name + "/**/*.class"
1299 // Do not include generator into the test runtime jar, it is not useful.
1300 // Otherwise, shrinking will need ASM jars.
1301 exclude "**/TestGenerator*"
1302 }
1303 }
1304}
1305
Mikaël Peltier61633d42017-10-13 16:51:06 +02001306task buildExampleJava9Jars {
1307 def examplesDir = file("src/test/examplesJava9")
1308 examplesDir.eachDir { dir ->
1309 def name = dir.getName();
1310 def exampleOutputDir = file("build/test/examplesJava9");
1311 def jarName = "${name}.jar"
1312 dependsOn "jar_examplesJava9_${name}"
1313 task "jar_examplesJava9_${name}"(type: Jar) {
1314 archiveName = jarName
1315 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001316 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001317 include "**/" + name + "/**/*.class"
1318 }
1319 }
1320}
1321
clementberad7ab1dd2019-04-16 16:05:00 +02001322task buildExampleJava11Jars {
1323 def examplesDir = file("src/test/examplesJava11")
1324 examplesDir.eachDir { dir ->
1325 def name = dir.getName();
1326 def exampleOutputDir = file("build/test/examplesJava11");
1327 def jarName = "${name}.jar"
1328 dependsOn "jar_examplesJava11_${name}"
1329 task "jar_examplesJava11_${name}"(type: Jar) {
1330 archiveName = jarName
1331 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001332 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001333 include "**/" + name + "/**/*.class"
1334 }
1335 }
1336}
1337
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001338task buildExamplesKotlin {
1339 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1340 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1341 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1342 } else if (!OperatingSystem.current().isLinux()) {
1343 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1344 "on your platform. It is fully supported on Linux and partially supported on " +
1345 "Mac OS and Windows")
1346 return;
1347 }
1348 def examplesDir = file("src/test/examplesKotlin")
1349 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001350 def name = dir.getName();
1351 dependsOn "dex_example_kotlin_${name}"
1352 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1353 def dexPath = file("${exampleOutputDir}")
1354 task "dex_example_kotlin_${name}"(type: dx.Dx,
1355 dependsOn: "compile_example_kotlin_${name}") {
1356 doFirst {
1357 if (!dexPath.exists()) {
1358 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001359 }
1360 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001361 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1362 destination = dexPath
1363 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001364 }
1365 }
1366}
1367
Sebastien Hertzd3313772018-01-16 14:12:37 +01001368task buildKotlinR8TestResources {
1369 def examplesDir = file("src/test/kotlinR8TestResources")
1370 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001371 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1372 def name = dir.getName()
1373 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001374 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1375 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001376 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001377 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001378 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1379 source = fileTree(dir: file("${examplesDir}/${name}"),
1380 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001381 destination = file(outputFile)
1382 targetVersion = kotlinTargetVersion
1383 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001384 task "${taskName}Java"(type: JavaCompile) {
1385 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1386 destinationDir = file(javaOutput)
1387 classpath = sourceSets.main.compileClasspath
1388 sourceCompatibility = JavaVersion.VERSION_1_6
1389 targetCompatibility = JavaVersion.VERSION_1_6
1390 options.compilerArgs += ["-g", "-Xlint:-options"]
1391 }
1392 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1393 archiveName = javaOutputJarName
1394 destinationDir = file(javaOutputJarDir)
1395 from javaOutput
1396 include "**/*.class"
1397 }
1398 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001399 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001400 }
1401}
1402
Mads Ager418d1ca2017-05-22 09:35:49 +02001403task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001404 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1405 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1406 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001407 } else if (!OperatingSystem.current().isLinux()) {
1408 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001409 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001410 return;
1411 }
1412 dependsOn buildDebugTestResourcesJars
1413 dependsOn buildExampleJars
1414 dependsOn buildExampleAndroidNJars
1415 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001416 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001417 dependsOn buildExampleJava9Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001418 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001419 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001420 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001421 def noDexTests = [
1422 "multidex",
1423 "multidex002",
1424 "multidex004",
1425 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001426 examplesDir.eachDir { dir ->
1427 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001428 if (!(name in noDexTests)) {
1429 dependsOn "dex_example_${name}"
1430 def exampleOutputDir = file("build/test/examples/" + name);
1431 def dexPath = file("${exampleOutputDir}")
1432 def debug = (name == "throwing")
1433 if (!dexPath.exists()) {
1434 dexPath.mkdirs()
1435 }
1436 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1437 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1438 destination = dexPath
1439 debug = debug
1440 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001441 }
1442 }
1443}
1444
1445task buildSmali {
1446 def smaliDir = file("src/test/smali")
1447 smaliDir.eachDirRecurse() { dir ->
1448 def name = dir.getName();
1449 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1450 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1451 smaliOutputDir.mkdirs()
1452 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001453 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001454 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1455 def javaFiles = fileTree(dir: dir, include: '*.java')
1456 def destDir = smaliOutputDir;
1457 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1458 def intermediateFileName = "${name}-intermediate.dex";
1459 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1460 if (javaFiles.empty) {
1461 if (!smaliFiles.empty) {
1462 dependsOn "${taskName}_smali"
1463 task "${taskName}_smali"(type: smali.Smali) {
1464 source = smaliFiles
1465 destination = destFile
1466 }
1467 }
1468 } else {
1469 dependsOn "${taskName}_dexmerger"
1470 task "${taskName}_smali"(type: smali.Smali) {
1471 source = smaliFiles
1472 destination = intermediateFile
1473 }
1474 task "${taskName}_java"(type: JavaCompile) {
1475 source = javaFiles
1476 destinationDir destDir
1477 classpath = sourceSets.main.compileClasspath
1478 sourceCompatibility = JavaVersion.VERSION_1_7
1479 targetCompatibility = JavaVersion.VERSION_1_7
1480 options.compilerArgs += ["-Xlint:-options"]
1481 }
1482 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1483 archiveName = "Test.jar"
1484 destinationDir = destDir
1485 from fileTree(dir: destDir, include: 'Test.class')
1486 }
1487 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1488 source = fileTree(dir: destDir, include: 'Test.jar')
1489 destination = destDir
1490 }
1491 task "${taskName}_dexmerger"(
1492 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1493 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1494 destination = destFile
1495 }
1496 }
1497 }
1498}
1499
1500tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001501 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001502 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1503 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1504 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind3defc8d2019-03-27 08:07:31 +01001505 maxParallelForks = (Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1) + 1
Rico Windc56f21c2019-03-12 07:29:57 +01001506 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001507 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001508 if (project.hasProperty('disable_assertions')) {
1509 enableAssertions = false
1510 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001511 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1512 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001513}
1514
1515task buildPreNJdwpTestsJar(type: Jar) {
1516 baseName = 'jdwp-tests-preN'
1517 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1518 // Exclude the classes containing java8
1519 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1520 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1521 includeEmptyDirs = false
1522}
1523
Ian Zerny74143162017-11-24 13:46:35 +01001524task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1525 def inFile = buildPreNJdwpTestsJar.archivePath
1526 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001527 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001528 outputs.file outFile
1529 if (OperatingSystem.current().isWindows()) {
1530 executable file("tools/windows/dx/bin/dx.bat")
1531 } else if (OperatingSystem.current().isMacOsX()) {
1532 executable file("tools/mac/dx/bin/dx");
1533 } else {
1534 executable file("tools/linux/dx/bin/dx");
1535 }
1536 args "--dex"
1537 args "--output=${outFile}"
1538 args inFile
1539}
1540
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001541task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1542 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001543}
1544
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001545def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001546 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001547 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001548 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001549 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001550 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001551 return null
1552}
1553
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001554task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001555 dependsOn testJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001556 inputs.files files("$buildDir/libs/r8tests.jar")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001557 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001558 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001559 delete r8LibTestPath
1560 from zipTree(testJar.outputs.files[0])
1561 into r8LibTestPath
1562 include "com/android/tools/r8/**"
1563 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001564 }
1565 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001566}
1567
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001568def printStackTrace(TestResult result) {
1569 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1570 def out = new StringBuffer()
1571 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001572 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001573 def header = "RETRACED STACKTRACE";
1574 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1575 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1576 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1577 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001578 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001579 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001580 out.append("--------------------------------------\n")
1581 Process process = command.execute()
1582 def processIn = new PrintStream(process.getOut())
1583 process.consumeProcessOutput(out, err)
1584 result.exception.printStackTrace(processIn)
1585 processIn.flush()
1586 processIn.close()
1587 process.waitFor()
1588 out.append("\n\n--------------------------------------\n")
1589 out.append("OBFUSCATED STACKTRACE\n")
1590 out.append("--------------------------------------\n")
1591 result.exceptions.add(0, new Exception(out.toString()))
1592 } else {
1593 result.exception.printStackTrace()
1594 }
1595}
1596
Mads Ager418d1ca2017-05-22 09:35:49 +02001597test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001598 if (project.hasProperty('generate_golden_files_to')) {
1599 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1600 assert project.hasProperty('HEAD_sha1')
1601 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1602 }
1603
1604 if (project.hasProperty('use_golden_files_in')) {
1605 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1606 assert project.hasProperty('HEAD_sha1')
1607 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1608 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001609 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001610 // R8.jar is required for running bootstrap tests.
1611 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001612 testLogging.exceptionFormat = 'full'
1613 if (project.hasProperty('print_test_stdout')) {
1614 testLogging.showStandardStreams = true
1615 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001616 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001617 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001618 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001619 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001620
Ian Zerny324d7612019-03-20 10:52:28 +01001621 // Forward runtime configurations for test parameters.
1622 if (project.hasProperty('runtimes')) {
1623 println "NOTE: Running with runtimes: " + project.property('runtimes')
1624 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001625 }
1626
Mads Ager418d1ca2017-05-22 09:35:49 +02001627 if (project.hasProperty('one_line_per_test')) {
1628 beforeTest { desc ->
1629 println "Start executing test ${desc.name} [${desc.className}]"
1630 }
1631 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001632 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001633 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001634 }
Rico Windda6836e2018-12-07 12:32:03 +01001635 if (project.hasProperty('update_test_timestamp')) {
1636 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1637 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001638 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1639 }
Rico Windf88b6be2018-12-11 15:14:05 +01001640 } else {
1641 afterTest { desc, result ->
1642 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001643 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001644 }
1645 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001646 }
1647 if (project.hasProperty('no_internal')) {
1648 exclude "com/android/tools/r8/internal/**"
1649 }
1650 if (project.hasProperty('only_internal')) {
1651 include "com/android/tools/r8/internal/**"
1652 }
Rico Wind4e218292019-03-07 12:44:49 +01001653
Mads Ager418d1ca2017-05-22 09:35:49 +02001654 if (project.hasProperty('tool')) {
1655 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001656 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001657 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001658 if (project.hasProperty('only_jctf')) {
1659 include "com/android/tools/r8/jctf/d8/**"
1660 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001661 // Don't run anything, deprecated
1662 println "Running with deprecated tool d8, not running any tests"
1663 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001664 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001665 } else {
1666 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001667 assert(project.hasProperty('only_jctf'))
1668 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001669 }
1670 }
1671 if (!project.hasProperty('all_tests')) {
1672 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001673 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001674 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001675 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001676 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001677 if (project.hasProperty('shard_count') ) {
1678 assert project.hasProperty('shard_number')
1679 int shard_count = project.getProperty('shard_count') as Integer
1680 int shard_number = project.getProperty('shard_number') as Integer
1681 assert shard_count < 65536
1682 assert shard_number < shard_count
1683 exclude {
1684 entry ->
1685 // Don't leave out directories. Leaving out a directory means all entries below.
1686 if (entry.file.isDirectory()) {
1687 return false
1688 }
1689 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1690 int hash = Integer.parseInt(first4, 16)
1691 return hash % shard_count != shard_number
1692 }
1693 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001694 if (project.hasProperty('jctf_compile_only')) {
1695 println "JCTF: compiling only"
1696 systemProperty 'jctf_compile_only', '1'
1697 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001698 if (project.hasProperty('test_dir')) {
1699 systemProperty 'test_dir', project.property('test_dir')
1700 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001701 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1702 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001703 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1704 // all needed tests in r8LibTestPath.
1705 classpath = files([r8LibPath, r8LibTestPath]) +
1706 sourceSets.test.runtimeClasspath -
1707 sourceSets.main.output -
1708 files(['build/classes/test'])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001709 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001710 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001711 if (OperatingSystem.current().isLinux()
1712 || OperatingSystem.current().isMacOsX()
1713 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001714 if (OperatingSystem.current().isMacOsX()) {
1715 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1716 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1717 "See tools/docker/README.md for details.")
1718 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001719 if (OperatingSystem.current().isWindows()) {
1720 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1721 "Art only runs on Linux and tests requiring Art will be skipped")
1722 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001723 dependsOn downloadDeps
1724 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001725 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001726 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001727 dependsOn buildSmali
1728 dependsOn jctfCommonJar
1729 dependsOn jctfTestsClasses
1730 dependsOn buildDebugInfoExamplesDex
1731 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001732 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001733 } else {
1734 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001735 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001736 }
1737}
1738
1739// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1740//
1741// To build and upload a new set of the Art tests for use with R8 follow these steps:
1742//
1743// First of all an Android checkout is required. Currently it must be located
1744// in $HOME/android/master.
1745//
1746// TODO(ricow): simplify this
1747//
1748// Before: update the checked in art, see scripts/update-host-art.sh
1749//
1750// 1. Get an android checkout in $HOME/android/master and apply the patch from
1751// https://android-review.googlesource.com/#/c/294187/
1752//
1753// 2. run the following commands in the Android checkout directory:
1754//
1755// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001756// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1757// m desugar
1758// m -j30 test-art-host
1759// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1760//
1761// Without running the test.py command the classes.jar file used by desugar in
1762// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1763// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001764//
1765// 3. In the R8 project root directory, make sure we have a clean state before starting:
1766// tools/gradle.py downloadDeps
1767// tools/gradle.py clean
1768// rm -rf tests/art
1769//
1770// 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 +02001771// Make sure you have smali on your path, please use the build binary in the
1772// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1773// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1774// 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 +02001775// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1776// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001777//
Søren Gjesse34b77732017-07-07 13:56:21 +02001778// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001779//
1780// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1781// skippedTests with an explanation. Rerun from step 3.
1782//
1783// 5. Run the tests:
1784// tools/gradle.py clean
1785// tools/test.py
1786//
Søren Gjesse34b77732017-07-07 13:56:21 +02001787// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1788// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1789// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001790//
Søren Gjesse34b77732017-07-07 13:56:21 +02001791// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001792// cd tests
1793// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001794//
1795// 7. Update the manifest file describing the Android repo used:
1796// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001797
Mads Ager418d1ca2017-05-22 09:35:49 +02001798def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02001799
1800def artTestDir = file("${androidCheckoutDir}/art/test")
1801
1802if (project.hasProperty('android_source')) {
1803 task buildArtTests {
1804 outputs.upToDateWhen { false }
1805 def toBeTriaged = [
1806 "903-hello-tagging",
1807 "904-object-allocation",
1808 "905-object-free",
1809 "906-iterate-heap",
1810 "907-get-loaded-classes",
1811 "908-gc-start-finish",
1812 "954-invoke-polymorphic-verifier",
1813 "955-methodhandles-smali",
1814 "596-monitor-inflation",
1815 ]
1816 def skippedTests = toBeTriaged + [
1817 // This test produces no jar.
1818 "000-nop",
1819 // This does not build, as it tests the error when the application exceeds more
1820 // than 65536 methods
1821 "089-many-methods",
1822 // Requires some jack beta jar
1823 "956-methodhandles",
1824 ]
1825
1826 def skippedTestsDx = [
1827 // Tests with custom build scripts, where javac is not passed the options
1828 // -source 1.7 -target 1.7.
1829 "462-checker-inlining-across-dex-files",
1830 "556-invoke-super",
1831 "569-checker-pattern-replacement",
1832 // These tests use jack even when --build-with-javac-dx is specified.
1833 "004-JniTest",
1834 "048-reflect-v8",
1835 "146-bad-interface",
1836 "563-checker-invoke-super",
1837 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1838 "604-hot-static-interface",
1839 "957-methodhandle-transforms",
1840 "958-methodhandle-emulated-stackframe",
1841 "959-invoke-polymorphic-accessors",
1842 "961-default-iface-resolution-gen",
1843 "962-iface-static",
1844 "963-default-range-smali",
1845 "964-default-iface-init-gen",
1846 "965-default-verify",
1847 "966-default-conflict",
1848 "967-default-ame",
1849 "968-default-partial-compile-gen",
1850 "969-iface-super",
1851 "970-iface-super-resolution-gen",
1852 "971-iface-super",
1853 // These tests does not build with --build-with-javac-dx
1854 "004-NativeAllocations", // Javac error
1855 "031-class-attributes",
1856 "138-duplicate-classes-check",
1857 "157-void-class", // Javac error
1858 "580-checker-string-factory-intrinsics",
1859 "612-jit-dex-cache",
1860 "613-inlining-dex-cache",
1861 "900-hello-plugin", // --experimental agents
1862 "901-hello-ti-agent", // --experimental agents
1863 "902-hello-transformation", // --experimental agents
1864 "909-attach-agent", // --experimental agents
1865 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1866 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1867 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1868 "960-default-smali", // --experimental default-methods
1869 // These tests force the build to use jack
1870 "953-invoke-polymorphic-compiler",
1871 "958-methodhandle-stackframe",
1872 ]
1873
1874 def artTestBuildDir = file("${projectDir}/tests/art")
1875
1876 if (androidCheckoutDir.exists()) {
1877 dependsOn downloadDeps
1878 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02001879 artTestDir.eachDir { dir ->
1880 def name = dir.getName();
1881 def markerFile = dir.toPath().resolve("info.txt").toFile();
1882 if (markerFile.exists() && !(name in skippedTests)) {
1883 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01001884 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02001885 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001886 }
1887 }
1888 }
1889 doFirst {
1890 if (!androidCheckoutDir.exists()) {
1891 throw new InvalidUserDataException(
1892 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02001893 }
1894 }
1895 doLast {
1896 copy {
1897 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1898 into file("${artTestBuildDir}/lib64")
1899 include 'lib*.so'
1900 }
1901 copy {
1902 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1903 into file("${artTestBuildDir}/lib64")
1904 include 'libart.so'
1905 include 'libbacktrace.so'
1906 include 'libbase.so'
1907 include 'libc++.so'
1908 include 'libcutils.so'
1909 include 'liblz4.so'
1910 include 'liblzma.so'
1911 include 'libnativebridge.so'
1912 include 'libnativeloader.so'
1913 include 'libsigchain.so'
1914 include 'libunwind.so'
1915 include 'libziparchive.so'
1916 }
1917 copy {
1918 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1919 into file("${artTestBuildDir}/lib")
1920 include 'lib*.so'
1921 }
1922 copy {
1923 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1924 into file("${artTestBuildDir}/lib")
1925 include 'libart.so'
1926 include 'libbacktrace.so'
1927 include 'libbase.so'
1928 include 'libc++.so'
1929 include 'libcutils.so'
1930 include 'liblz4.so'
1931 include 'liblzma.so'
1932 include 'libnativebridge.so'
1933 include 'libnativeloader.so'
1934 include 'libsigchain.so'
1935 include 'libunwind.so'
1936 include 'libziparchive.so'
1937 }
1938 }
1939 }
1940}
1941
Rico Windde2af6c2019-03-26 15:21:08 +01001942def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001943 def artTestDir = file("${androidCheckoutDir}/art/test")
1944 def artRunTestScript = file("${artTestDir}/run-test")
1945 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001946 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001947
Søren Gjesse34b77732017-07-07 13:56:21 +02001948 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01001949 def buildTask = "build_art_test_dx_${name}"
1950 def sanitizeTask = "sanitize_art_test_dx_${name}"
1951 def copyCheckTask = "copy_check_art_test_dx_${name}"
1952 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001953
1954 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01001955 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001956 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1957 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01001958 task "$buildTask"(type: Exec) {
1959 outputs.upToDateWhen { false }
1960 inputs.file buildInputs
1961 executable "${artRunTestScript}"
1962 args "--host"
1963 args "--build-only"
1964 args "--build-with-javac-dx"
1965 args "--output-path", "${testDir}"
1966 args "${name}"
1967 environment DX: "${dxExecutable.absolutePath}"
1968 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1969 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1970 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02001971 }
1972 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1973 outputs.upToDateWhen { false }
1974 executable "/bin/bash"
1975 args "-c"
1976 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1977 " ${testDir}/classes-ex ${testDir}/check"
1978 }
1979
1980 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001981 // Directory that contains smali files is either smali, or smali/art
1982 def smali_dir = file("${dir}/smali/art")
1983 if (smali_dir.exists()) {
1984 workingDir "${testDir}/smali/art"
1985 } else {
1986 workingDir "${testDir}/smali"
1987 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001988 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001989 // This is the command line options for smali prior to 2.2.1, where smali got a new
1990 // command line interface.
1991 args "-c", "smali a *.smali"
1992 // This is the command line options for smali 2.2.1 and later.
1993 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001994 }
1995
1996 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1997 def smali_dir = file("${dir}/smali")
1998 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01001999 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002000 dependsOn smaliToDexTask
2001 }
2002 from("${artTestDir}/${name}") {
2003 include 'check'
2004 }
2005 into testDir
2006 }
2007
2008 return copyCheckTask
2009}
2010
2011task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002012 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002013 classpath = sourceSets.main.compileClasspath
2014 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002015 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002016 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002017 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002018 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002019 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002020 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002021 include '**/com/android/tools/r8/CompilationMode.java'
2022 include '**/com/android/tools/r8/D8.java'
2023 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002024 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2025 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002026 include '**/com/android/tools/r8/Diagnostic.java'
2027 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002028 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2029 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002030 include '**/com/android/tools/r8/ProgramConsumer.java'
2031 include '**/com/android/tools/r8/ProgramResource.java'
2032 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002033 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002034 include '**/com/android/tools/r8/ResourceException.java'
2035 include '**/com/android/tools/r8/StringConsumer.java'
2036 include '**/com/android/tools/r8/StringResource.java'
2037 include '**/com/android/tools/r8/Version.java'
2038 include '**/com/android/tools/r8/origin/*.java'
2039}
2040
2041task javadocR8(type: Javadoc) {
2042 title "R8 API"
2043 classpath = sourceSets.main.compileClasspath
2044 source = sourceSets.main.allJava
2045 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2046 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2047 include '**/com/android/tools/r8/BaseCommand.java'
2048 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2049 include '**/com/android/tools/r8/ClassFileConsumer.java'
2050 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2051 include '**/com/android/tools/r8/CompilationFailedException.java'
2052 include '**/com/android/tools/r8/CompilationMode.java'
2053 include '**/com/android/tools/r8/R8.java'
2054 include '**/com/android/tools/r8/R8Command.java'
2055 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2056 include '**/com/android/tools/r8/Diagnostic.java'
2057 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002058 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2059 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002060 include '**/com/android/tools/r8/ProgramConsumer.java'
2061 include '**/com/android/tools/r8/ProgramResource.java'
2062 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2063 include '**/com/android/tools/r8/Resource.java'
2064 include '**/com/android/tools/r8/ResourceException.java'
2065 include '**/com/android/tools/r8/StringConsumer.java'
2066 include '**/com/android/tools/r8/StringResource.java'
2067 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002068 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002069}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002070
2071task copyMavenDeps(type: Copy) {
2072 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002073 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002074 from configurations.testCompile into "$buildDir/deps"
2075}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002076
Rico Wind23a05112019-03-27 08:00:44 +01002077task printMavenDeps {
2078 // Only actually print to stdout when we are updating.
2079 if (project.hasProperty('updatemavendeps')) {
2080 for (Configuration config : configurations) {
2081 if (!config.isCanBeResolved()) {
2082 continue
2083 }
2084 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2085 it.selected.id
2086 }
2087 def result = dependencies.createArtifactResolutionQuery()
2088 .forComponents(componentIds)
2089 .withArtifacts(MavenModule, MavenPomArtifact)
2090 .execute()
2091 for (component in result.resolvedComponents) {
2092 component.getArtifacts(MavenPomArtifact).each {
2093 println "POM: ${it.file} ${component.id}"
2094 }
2095 }
2096 config.each {
2097 println "JAR: ${it}"
2098 }
2099 }
2100 }
2101}