blob: 12ef47aed7bbe8e0dadedada4f5bca4b2570d1f9 [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",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200290 "openjdk/desugar_jdk_libs",
Rico Windf72fa152018-10-22 15:41:03 +0200291 "proguard/proguard5.2.1",
292 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200293 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200294 ],
295 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
296 // container on other platforms where supported.
297 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200298 "linux/art",
299 "linux/art-5.1.1",
300 "linux/art-6.0.1",
301 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100302 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100303 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200304 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100305 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200306 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200307 ]
308]
309
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100310def cloudSystemDependencies = [
311 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200312 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200313 "openjdk/jdk8/linux-x86",
314 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100315 ],
316 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200317 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200318 "openjdk/jdk8/darwin-x86",
319 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100320 ],
321 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200322 "third_party": ["openjdk/openjdk-9.0.4/windows",
323 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100324 ],
325]
326
327if (OperatingSystem.current().isWindows()) {
328 cloudSystemDependencies.windows.each { entry ->
329 cloudDependencies.get(entry.key).addAll(entry.value)
330 }
331} else if (OperatingSystem.current().isLinux()) {
332 cloudSystemDependencies.linux.each { entry ->
333 cloudDependencies.get(entry.key).addAll(entry.value)
334 }
335} else if (OperatingSystem.current().isMacOsX()) {
336 cloudSystemDependencies.osx.each { entry ->
337 cloudDependencies.get(entry.key).addAll(entry.value)
338 }
339} else {
340 println "WARNING: Unsupported system: " + OperatingSystem.current()
341}
342
343def getDownloadDepsTaskName(entryKey, entryFile) {
344 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
345}
346
Ian Zernyb2d27c42019-02-20 09:09:41 +0100347def getFetchDepsTaskName(entryKey, entryFile) {
348 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
349}
350
Mads Ager418d1ca2017-05-22 09:35:49 +0200351cloudDependencies.each { entry ->
352 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100353 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
354 type DownloadDependency.Type.GOOGLE_STORAGE
355 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200356 }
357 }
358}
359
360def x20Dependencies = [
361 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200362 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200363 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100364 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100365 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200366 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100367 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200368 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200369 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200370 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200371 "gmscore/gmscore_v10",
372 "gmscore/gmscore_v9",
373 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200374 "gmscore/v4",
375 "gmscore/v5",
376 "gmscore/v6",
377 "gmscore/v7",
378 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200379 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200380 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200381 "proguard/proguard_internal_159423826",
382 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200383 "youtube/youtube.android_12.10",
384 "youtube/youtube.android_12.17",
385 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200386 "youtube/youtube.android_13.37",
Rico Wind5acd2b62019-05-10 08:29:01 +0200387 "youtube/youtube.android_14.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200388 ],
389]
390
391x20Dependencies.each { entry ->
392 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100393 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
394 type DownloadDependency.Type.X20
395 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200396 }
397 }
398}
399
Rico Wind897bb712017-05-23 10:44:29 +0200400task downloadProguard {
401 cloudDependencies.each { entry ->
402 entry.value.each { entryFile ->
403 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100404 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200405 }
406 }
407 }
408}
409
Rico Windf6c74ce2018-12-04 08:50:55 +0100410task downloadOpenJDKrt {
411 cloudDependencies.each { entry ->
412 entry.value.each { entryFile ->
413 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100414 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100415 }
416 }
417 }
418}
419
Tamas Kenez427205b2017-06-29 15:57:09 +0200420task downloadDx {
421 cloudDependencies.each { entry ->
422 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200423 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100424 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200425 }
426 }
427 }
428}
429
Tamas Kenez0e10c562017-06-08 10:00:34 +0200430task downloadAndroidCts {
431 cloudDependencies.each { entry ->
432 entry.value.each { entryFile ->
433 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100434 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200435 }
436 }
437 }
438}
439
Mads Ager418d1ca2017-05-22 09:35:49 +0200440task downloadDeps {
441 cloudDependencies.each { entry ->
442 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100443 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200444 }
445 }
446 if (!project.hasProperty('no_internal')) {
447 x20Dependencies.each { entry ->
448 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100449 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200450 }
451 }
452 }
453}
454
455allprojects {
456 sourceCompatibility = JavaVersion.VERSION_1_8
457 targetCompatibility = JavaVersion.VERSION_1_8
458}
459
Rico Wind266336c2019-02-25 10:11:38 +0100460// TODO(ricow): Remove debug prints
461println("NOTE: Current operating system: " + OperatingSystem.current())
462println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
463
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100464// Check if running with the JDK location from tools/jdk.py.
465if (OperatingSystem.current().isWindows()) {
466 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
467} else {
468 def javaHomeOut = new StringBuilder()
469 def javaHomeErr = new StringBuilder()
470 def javaHomeProc = './tools/jdk.py'.execute()
471 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
472 def jdkHome = new File(javaHomeOut.toString().trim())
473 if (!jdkHome.exists()) {
474 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
475 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
476 println("WARNING: Gradle is running in a non-pinned Java"
477 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
478 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100479 } else {
480 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100481 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200482}
483
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100484sourceSets.configureEach { sourceSet ->
485 tasks.named(sourceSet.compileJavaTaskName).configure {
486 // Default disable errorprone (enabled and setup below).
487 options.errorprone.enabled = false
488 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100489 // Run all compilation tasks in a forked subprocess.
490 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100491 // Javac often runs out of stack space when compiling the tests.
492 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100493 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100494 // Test compilation is sometimes hitting the default limit at 1g, increase it.
495 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100496 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
497 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
498 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200499}
500
Ian Zernyd3020482019-04-25 07:05:04 +0200501tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
502 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200503 options.fork = true
504 options.forkOptions.jvmArgs = []
505 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200506 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200507 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200508 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200509 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200510 options.forkOptions.javaHome = file(jdkDir + 'windows')
511 }
512 sourceCompatibility = JavaVersion.VERSION_1_9
513 targetCompatibility = JavaVersion.VERSION_1_9
514}
515
516tasks.named(sourceSets.examplesJava11.compileJavaTaskName).get().configure {
517 def jdkDir = 'third_party/openjdk/jdk-11/'
518 options.fork = true
519 options.forkOptions.jvmArgs = []
520 if (OperatingSystem.current().isLinux()) {
521 options.forkOptions.javaHome = file(jdkDir + 'Linux')
522 } else if (OperatingSystem.current().isMacOsX()) {
523 options.forkOptions.javaHome = file(jdkDir + 'Mac')
524 } else {
525 options.forkOptions.javaHome = file(jdkDir + 'Windows')
clementbera0fe940d2019-04-23 12:45:18 +0200526 }
527 sourceCompatibility = JavaVersion.VERSION_11
528 targetCompatibility = JavaVersion.VERSION_11
529}
530
531
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100532if (!project.hasProperty('without_error_prone') &&
533 // Don't enable error prone on Java 8 as the plugin setup does not support it.
534 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200535 compileJava {
536 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100537 options.errorprone.enabled = true
538 options.errorprone.disableAllChecks = true
539 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
540 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
541 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
542 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
543 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
544 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
545 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
546 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
547 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
548 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
549 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
550 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
551 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
552 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
553 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
554 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
555 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
556 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
557 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200558 }
559}
560
Mads Ager418d1ca2017-05-22 09:35:49 +0200561compileJctfCommonJava {
562 dependsOn 'copyAdditionalJctfCommonFiles'
563 options.compilerArgs = ['-Xlint:none']
564}
565
566compileJctfTestsJava {
567 dependsOn 'jctfCommonClasses'
568 options.compilerArgs = ['-Xlint:none']
569}
570
Yohann Roussel7f47c032017-09-14 12:19:06 +0200571task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200572 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100573
Yohann Roussel7f47c032017-09-14 12:19:06 +0200574 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100575 def runtimeClasspath = configurations.findByName("runtimeClasspath")
576 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
577
Yohann Roussel7f47c032017-09-14 12:19:06 +0200578 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100579
Yohann Roussel7f47c032017-09-14 12:19:06 +0200580 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100581 def dependencies = []
582 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
583 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
584 dependencies.add("${identifier.group}:${identifier.module}")
585 }
586 def libraryLicenses = file('LIBRARY-LICENSE').text
587 dependencies.each {
588 if (!libraryLicenses.contains("- artifact: $it")) {
589 throw new GradleException("No license for $it in LIBRARY_LICENSE")
590 }
591 }
592
Yohann Roussel7f47c032017-09-14 12:19:06 +0200593 license.getParentFile().mkdirs()
594 license.createNewFile()
595 license.text = "This file lists all licenses for code distributed.\n"
596 license.text += "All non-library code has the following 3-Clause BSD license.\n"
597 license.text += "\n"
598 license.text += "\n"
599 license.text += file('LICENSE').text
600 license.text += "\n"
601 license.text += "\n"
602 license.text += "Summary of distributed libraries:\n"
603 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100604 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200605 license.text += "\n"
606 license.text += "\n"
607 license.text += "Licenses details:\n"
608 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
609 license.text += "\n"
610 license.text += "\n"
611 license.text += file.text
612 }
613 }
614}
615
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200616static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700617 // Everything under META-INF is not included by default.
618 // Should include before 'relocate' so that the service file path and its content
619 // are properly relocated as well.
620 task.mergeServiceFiles {
621 include 'META-INF/services/*'
622 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200623}
624
625static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000626 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200627 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000628 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
629 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000630 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000631 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200632 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
633 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
634 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200635 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000636}
637
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100638task repackageDepsNoRelocate(type: ShadowJar) {
639 configurations = [project.configurations.runtimeClasspath]
640 mergeServiceFiles(it)
641 exclude { it.getRelativePath().getPathString() == "module-info.class" }
642 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100643 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100644}
645
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000646task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100647 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200648 mergeServiceFiles(it)
649 if (!project.hasProperty('lib_no_relocate')) {
650 configureRelocations(it)
651 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100652 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700653 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000654 baseName 'deps'
655}
656
657task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200658 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200659 mergeServiceFiles(it)
660 if (!project.hasProperty('lib_no_relocate')) {
661 configureRelocations(it)
662 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000663 baseName 'sources'
664}
665
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100666task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200667 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100668 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200669 classifier = null
670 version = null
671 manifest {
672 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
673 }
674 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100675 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100676 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100677 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200678}
679
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100680task r8WithoutDeps(type: ShadowJar) {
681 from consolidatedLicense.outputs.files
682 baseName 'r8_without_deps'
683 classifier = null
684 version = null
685 manifest {
686 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
687 }
688 from sourceSets.main.output
689}
690
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000691task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200692 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200693 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200694 classifier = null
695 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200696 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200697 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200698 }
699 // In order to build without dependencies, pass the exclude_deps property using:
700 // gradle -Pexclude_deps R8
701 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800702 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000703 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800704 } else {
705 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200706 }
Ian Zerny80533c92019-01-24 10:32:09 +0100707 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200708}
709
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100710task R8NoManifestNoDeps(type: ShadowJar) {
711 from consolidatedLicense.outputs.files
712 baseName 'r8nomanifest-exclude-deps'
713 classifier = null
714 version = null
715 from sourceSets.main.output
716}
717
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100718task R8NoManifest(type: ShadowJar) {
719 from consolidatedLicense.outputs.files
720 baseName 'r8nomanifest'
721 classifier = null
722 version = null
723 // In order to build without dependencies, pass the exclude_deps property using:
724 // gradle -Pexclude_deps R8
725 if (!project.hasProperty('exclude_deps')) {
726 from repackageSources.outputs.files
727 from repackageDeps.outputs.files
728 } else {
729 from sourceSets.main.output
730 }
Ian Zerny80533c92019-01-24 10:32:09 +0100731 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100732}
733
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000734task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200735 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200736 baseName 'd8'
737 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200738 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200739 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200740}
741
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200742task CompatDx(type: ShadowJar) {
743 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200744 baseName 'compatdx'
745 manifest {
746 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
747 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200748}
749
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200750task CompatProguard(type: ShadowJar) {
751 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200752 baseName 'compatproguard'
753 manifest {
754 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
755 }
Lars Bak44cef522017-08-10 16:02:39 +0200756}
757
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100758def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100759 // Execute r8 commands against a stable r8 with relocated dependencies.
Rico Windcfb65512019-02-27 12:57:34 +0100760 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
761 "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100762}
763
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100764def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100765 return baseR8CommandLine([
766 "--classfile", "--release",
767 input,
768 "--output", output,
769 "--pg-conf", pgconf,
770 "--pg-map-output", output + ".map",
771 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
772 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100773}
774
775def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
776 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100777 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100778 outputs.file output
779 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100780 dependsOn r8WithRelocatedDeps
781 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100782 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
783 workingDir = projectDir
784 }
785}
786
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100787task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100788 baseName = "r8tests"
789 from sourceSets.test.output
790}
791
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100792task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
793 baseName = "r8tests-exclude-deps"
794 from sourceSets.test.output
795}
796
797def generateR8LibKeepRules(name, r8Source, testSource, output) {
798 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
799 doFirst {
800 standardOutput new FileOutputStream(output)
801 }
802 dependsOn r8WithRelocatedDeps
803 dependsOn r8Source
804 dependsOn testSource
805 dependsOn downloadOpenJDKrt
806 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
807 outputs.file output
808 commandLine baseR8CommandLine([
809 "printuses",
810 "--keeprules",
811 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
812 r8Source.outputs.files[0],
813 testSource.outputs.files[0]])
814 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100815 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100816}
817
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100818task R8LibApiOnly {
819 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
820 outputs.file r8LibPath
821}
822
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100823task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100824 def genRulesTask = generateR8LibKeepRules(
825 "Main",
826 R8NoManifest,
827 testJar,
828 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100829 dependsOn r8LibCreateTask(
830 "Main",
831 "src/main/keep.txt",
832 R8NoManifest,
833 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100834 ["--pg-conf", genRulesTask.outputs.files[0]]
835 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100836 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100837}
838
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100839task R8LibNoDeps {
840 def genRulesTask = generateR8LibKeepRules(
841 "NoDeps",
842 R8NoManifestNoDeps,
843 testJarNoDeps,
844 r8LibGeneratedKeepRulesExcludeDepsPath
845 )
846 dependsOn r8LibCreateTask(
847 "NoDeps",
848 "src/main/keep.txt",
849 R8NoManifestNoDeps,
850 r8LibExludeDepsPath,
851 ["--pg-conf", genRulesTask.outputs.files[0]],
852 repackageDepsNoRelocate.outputs.files
853 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
854 outputs.file r8LibExludeDepsPath
855}
856
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100857task CompatDxLib {
858 dependsOn r8LibCreateTask(
859 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100860}
861
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100862task CompatProguardLib {
863 dependsOn r8LibCreateTask(
864 "CompatPg",
865 "src/main/keep-compatproguard.txt",
866 CompatProguard,
867 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100868}
869
Mads Ager418d1ca2017-05-22 09:35:49 +0200870task sourceJar(type: Jar, dependsOn: classes) {
871 classifier = 'src'
872 from sourceSets.main.allSource
873}
874
875task jctfCommonJar(type: Jar) {
876 from sourceSets.jctfCommon.output
877 baseName 'jctfCommon'
878}
879
880artifacts {
881 archives sourceJar
882}
883
884task createArtTests(type: Exec) {
885 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200886 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100887 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200888 outputs.dir outputDir
889 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200890 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200891 workingDir = projectDir
892}
893
894task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200895 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200896 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200897 inputs.file script
898 outputs.dir outputDir
899 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200900 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200901 workingDir = projectDir
902}
903
904compileTestJava {
905 dependsOn createArtTests
906 dependsOn createJctfTests
907}
908
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100909task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
910 from sourceSets.cfSegments.output
911 baseName 'cf_segments'
912 destinationDir file('build/libs')
913}
914
Ian Zernyee23a172018-01-03 09:08:48 +0100915task buildD8ApiUsageSample(type: Jar) {
916 from sourceSets.apiUsageSample.output
917 baseName 'd8_api_usage_sample'
918 destinationDir file('tests')
919}
920
Ian Zerny923a0c12018-01-03 10:59:18 +0100921task buildR8ApiUsageSample(type: Jar) {
922 from sourceSets.apiUsageSample.output
923 baseName 'r8_api_usage_sample'
924 destinationDir file('tests')
925}
926
Yohann Roussel548ae942018-01-05 11:13:28 +0100927task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100928 dependsOn buildD8ApiUsageSample
929 dependsOn buildR8ApiUsageSample
930}
931
Mads Ager418d1ca2017-05-22 09:35:49 +0200932task buildDebugInfoExamplesDex {
933 def examplesDir = file("src/test/java")
934 def hostJar = "debuginfo_examples.jar"
935 def hostDexJar = "debuginfo_examples_dex.jar"
936 task "compile_debuginfo_examples"(type: JavaCompile) {
937 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
938 destinationDir = file("build/test/debuginfo_examples/classes")
939 classpath = sourceSets.main.compileClasspath
940 sourceCompatibility = JavaVersion.VERSION_1_7
941 targetCompatibility = JavaVersion.VERSION_1_7
942 options.compilerArgs += ["-Xlint:-options"]
943 }
944 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
945 archiveName = hostJar
946 destinationDir = file("build/test/")
947 from "build/test/debuginfo_examples/classes"
948 include "**/*.class"
949 }
950 task "dex_debuginfo_examples"(type: Exec,
951 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200952 if (OperatingSystem.current().isWindows()) {
953 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700954 } else if (OperatingSystem.current().isMacOsX()) {
955 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200956 } else {
957 executable file("tools/linux/dx/bin/dx");
958 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200959 args "--dex"
960 args "--output=build/test/${hostDexJar}"
961 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100962 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200963 outputs.file file("build/test/${hostDexJar}")
964 }
965 dependsOn dex_debuginfo_examples
966}
967
968task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200969 def resourcesDir = file("src/test/debugTestResources")
970 def hostJar = "debug_test_resources.jar"
971 task "compile_debugTestResources"(type: JavaCompile) {
972 source = fileTree(dir: resourcesDir, include: '**/*.java')
973 destinationDir = file("build/test/debugTestResources/classes")
974 classpath = sourceSets.main.compileClasspath
975 sourceCompatibility = JavaVersion.VERSION_1_7
976 targetCompatibility = JavaVersion.VERSION_1_7
977 options.compilerArgs += ["-g", "-Xlint:-options"]
978 }
979 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
980 archiveName = hostJar
981 destinationDir = file("build/test/")
982 from "build/test/debugTestResources/classes"
983 include "**/*.class"
984 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200985 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
986 def java8HostJar = "debug_test_resources_java8.jar"
987 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
988 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
989 destinationDir = file("build/test/debugTestResourcesJava8/classes")
990 classpath = sourceSets.main.compileClasspath
991 sourceCompatibility = JavaVersion.VERSION_1_8
992 targetCompatibility = JavaVersion.VERSION_1_8
993 options.compilerArgs += ["-g", "-Xlint:-options"]
994 }
995 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
996 archiveName = java8HostJar
997 destinationDir = file("build/test/")
998 from "build/test/debugTestResourcesJava8/classes"
999 include "**/*.class"
1000 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001001 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001002 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1003 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1004 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1005 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001006 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001007 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001008 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001009 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001010 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001011}
1012
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001013// Examples used by tests, where Android specific APIs are used.
1014task buildExampleAndroidApi(type: JavaCompile) {
1015 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1016 destinationDir = file("build/test/examplesAndroidApi/classes")
1017 classpath = files("third_party/android_jar/lib-v26/android.jar")
1018 sourceCompatibility = JavaVersion.VERSION_1_8
1019 targetCompatibility = JavaVersion.VERSION_1_8
1020}
1021
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001022task buildExampleKotlinJars {
1023 def kotlinSrcDir = file("src/test/examplesKotlin")
1024 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001025 def name = dir.getName();
1026 dependsOn "compile_example_kotlin_${name}"
1027 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1028 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1029 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001030 }
1031 }
1032}
1033
Lars Bakc91e87e2017-08-18 08:53:10 +02001034// Proto lite generated code yields warnings when compiling with javac.
1035// We change the options passed to javac to ignore it.
1036compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1037
Søren Gjesse7320ce52018-05-07 15:45:22 +02001038
Mads Ager418d1ca2017-05-22 09:35:49 +02001039task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001040 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001041 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001042 def proguardScript
1043 if (OperatingSystem.current().isWindows()) {
1044 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1045 } else {
1046 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1047 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001048 task extractExamplesRuntime(type: Sync) {
1049 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001050 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001051 include "**/*.class"
1052 includeEmptyDirs false
1053 into "$buildDir/runtime/examples/"
1054 }
1055
Søren Gjesse7320ce52018-05-07 15:45:22 +02001056 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1057 from examplesDir
1058 exclude "**/*.java"
1059 exclude "**/keep-rules*.txt"
1060 into file("build/test/examples/classes")
1061 }
1062
1063 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001064 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001065 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001066 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001067 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001068 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001069 sourceCompatibility = JavaVersion.VERSION_1_7
1070 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001071 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1072 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001073 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1074 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001075 include "**/*.java"
1076 destinationDir = file("build/test/examples/classes_debuginfo_all")
1077 classpath = sourceSets.examples.compileClasspath
1078 sourceCompatibility = JavaVersion.VERSION_1_7
1079 targetCompatibility = JavaVersion.VERSION_1_7
1080 options.compilerArgs = ["-g", "-Xlint:none"]
1081 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001082 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1083 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001084 include "**/*.java"
1085 destinationDir = file("build/test/examples/classes_debuginfo_none")
1086 classpath = sourceSets.examples.compileClasspath
1087 sourceCompatibility = JavaVersion.VERSION_1_7
1088 targetCompatibility = JavaVersion.VERSION_1_7
1089 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001090 }
1091 examplesDir.eachDir { dir ->
1092 def name = dir.getName();
1093 def exampleOutputDir = file("build/test/examples");
1094 def jarName = "${name}.jar"
1095 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001096 dependsOn "jar_example_${name}_debuginfo_all"
1097 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001098 dependsOn "extractExamplesRuntime"
1099 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001100 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1101 def proguardConfigPath = "${dir}/proguard.cfg"
1102 if (new File(proguardConfigPath).exists()) {
1103 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1104 archiveName = "${name}_pre_proguard.jar"
1105 destinationDir = exampleOutputDir
1106 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001107 include name + "/**/*.class"
1108 with runtimeDependencies
1109 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001110 }
1111 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1112 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1113 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1114 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001115 inputs.files files(
1116 tasks.getByPath("pre_proguard_example_${name}"),
1117 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001118 // Enable these to get stdout and stderr redirected to files...
1119 // standardOutput = new FileOutputStream('proguard.stdout')
1120 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001121 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001122 " -outjars ${proguardJarPath}" +
1123 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001124 " -printmapping ${proguardMapPath}"
1125 if (OperatingSystem.current().isWindows()) {
1126 executable "${proguardScript}"
1127 args "${proguardArguments}"
1128 } else {
1129 executable "bash"
1130 args "-c", "${proguardScript} '${proguardArguments}'"
1131 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001132 outputs.file proguardJarPath
1133 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001134 // TODO: Consider performing distinct proguard compilations.
1135 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1136 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001137 into "${exampleOutputDir}"
1138 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001139 }
1140 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1141 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001142 into "${exampleOutputDir}"
1143 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001144 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001145 } else {
1146 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001147 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001148 destinationDir = exampleOutputDir
1149 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001150 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001151 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001152 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001153 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001154 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1155 archiveName = "${name}_debuginfo_all.jar"
1156 destinationDir = exampleOutputDir
1157 from "build/test/examples/classes_debuginfo_all"
1158 include name + "/**/*.class"
1159 with runtimeDependencies
1160 includeEmptyDirs false
1161 }
1162 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1163 archiveName = "${name}_debuginfo_none.jar"
1164 destinationDir = exampleOutputDir
1165 from "build/test/examples/classes_debuginfo_none"
1166 include name + "/**/*.class"
1167 with runtimeDependencies
1168 includeEmptyDirs false
1169 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001170 }
1171 }
1172}
1173
1174task buildExampleAndroidNJars {
1175 dependsOn downloadDeps
1176 def examplesDir = file("src/test/examplesAndroidN")
1177 task "compile_examplesAndroidN"(type: JavaCompile) {
1178 source = fileTree(dir: examplesDir, include: '**/*.java')
1179 destinationDir = file("build/test/examplesAndroidN/classes")
1180 classpath = sourceSets.main.compileClasspath
1181 sourceCompatibility = JavaVersion.VERSION_1_8
1182 targetCompatibility = JavaVersion.VERSION_1_8
1183 options.compilerArgs += ["-Xlint:-options"]
1184 }
1185 examplesDir.eachDir { dir ->
1186 def name = dir.getName();
1187 def exampleOutputDir = file("build/test/examplesAndroidN");
1188 def jarName = "${name}.jar"
1189 dependsOn "jar_examplesAndroidN_${name}"
1190 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1191 archiveName = jarName
1192 destinationDir = exampleOutputDir
1193 from "build/test/examplesAndroidN/classes"
1194 include "**/" + name + "/**/*.class"
1195 }
1196 }
1197}
1198
1199
1200task buildExampleAndroidOJars {
1201 dependsOn downloadDeps
1202 def examplesDir = file("src/test/examplesAndroidO")
1203 // NOTE: we want to enable a scenario when test needs to reference some
1204 // classes generated by legacy (1.6) Java compiler to test some specific
1205 // behaviour. To do so we compile all the java files located in sub-directory
1206 // called 'legacy' with Java 1.6, then compile the rest of the files with
1207 // Java 1.8 and a reference to previously generated 1.6 classes.
1208
1209 // Compiling all classes in dirs 'legacy' with old Java version.
1210 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1211 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1212 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1213 classpath = sourceSets.main.compileClasspath
1214 sourceCompatibility = JavaVersion.VERSION_1_6
1215 targetCompatibility = JavaVersion.VERSION_1_6
1216 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1217 }
1218 // Compiling the rest of the files as Java 1.8 code.
1219 task "compile_examplesAndroidO"(type: JavaCompile) {
1220 dependsOn "compile_examplesAndroidO_Legacy"
1221 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1222 destinationDir = file("build/test/examplesAndroidO/classes")
1223 classpath = sourceSets.main.compileClasspath
1224 classpath += files("build/test/examplesAndroidOLegacy/classes")
1225 sourceCompatibility = JavaVersion.VERSION_1_8
1226 targetCompatibility = JavaVersion.VERSION_1_8
1227 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1228 }
1229 examplesDir.eachDir { dir ->
1230 def name = dir.getName();
1231 def destinationDir = file("build/test/examplesAndroidO/classes");
1232 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1233 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1234 dependsOn: "compile_examplesAndroidO") {
1235 main = name + ".TestGenerator"
1236 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1237 args destinationDir
1238 }
1239 } else {
1240 task "generate_examplesAndroidO_${name}" () {}
1241 }
1242 }
1243 examplesDir.eachDir { dir ->
1244 def name = dir.getName();
1245 def exampleOutputDir = file("build/test/examplesAndroidO");
1246 def jarName = "${name}.jar"
1247 dependsOn "jar_examplesAndroidO_${name}"
1248 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1249 "generate_examplesAndroidO_${name}"]) {
1250 archiveName = jarName
1251 destinationDir = exampleOutputDir
1252 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1253 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1254 include "**/" + name + "/**/*.class"
1255 // Do not include generator into the test runtime jar, it is not useful.
1256 // Otherwise, shrinking will need ASM jars.
1257 exclude "**/TestGenerator*"
1258 }
1259 }
1260}
1261
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001262task buildExampleAndroidPJars {
1263 dependsOn downloadDeps
1264 def examplesDir = file("src/test/examplesAndroidP")
1265
1266 task "compile_examplesAndroidP"(type: JavaCompile) {
1267 source = fileTree(dir: examplesDir, include: '**/*.java')
1268 destinationDir = file("build/test/examplesAndroidP/classes")
1269 classpath = sourceSets.main.compileClasspath
1270 sourceCompatibility = JavaVersion.VERSION_1_8
1271 targetCompatibility = JavaVersion.VERSION_1_8
1272 options.compilerArgs += ["-Xlint:-options"]
1273 }
1274 examplesDir.eachDir { dir ->
1275 def name = dir.getName();
1276 def destinationDir = file("build/test/examplesAndroidP/classes");
1277 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1278 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1279 dependsOn: "compile_examplesAndroidP") {
1280 main = name + ".TestGenerator"
1281 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1282 args destinationDir
1283 }
1284 } else {
1285 task "generate_examplesAndroidP_${name}" () {}
1286 }
1287 }
1288 examplesDir.eachDir { dir ->
1289 def name = dir.getName();
1290 def exampleOutputDir = file("build/test/examplesAndroidP");
1291 def jarName = "${name}.jar"
1292 dependsOn "jar_examplesAndroidP_${name}"
1293 task "jar_examplesAndroidP_${name}"(type: Jar,
1294 dependsOn: ["compile_examplesAndroidP",
1295 "generate_examplesAndroidP_${name}"]) {
1296 archiveName = jarName
1297 destinationDir = exampleOutputDir
1298 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1299 include "**/" + name + "/**/*.class"
1300 // Do not include generator into the test runtime jar, it is not useful.
1301 // Otherwise, shrinking will need ASM jars.
1302 exclude "**/TestGenerator*"
1303 }
1304 }
1305}
1306
Mikaël Peltier61633d42017-10-13 16:51:06 +02001307task buildExampleJava9Jars {
1308 def examplesDir = file("src/test/examplesJava9")
1309 examplesDir.eachDir { dir ->
1310 def name = dir.getName();
1311 def exampleOutputDir = file("build/test/examplesJava9");
1312 def jarName = "${name}.jar"
1313 dependsOn "jar_examplesJava9_${name}"
1314 task "jar_examplesJava9_${name}"(type: Jar) {
1315 archiveName = jarName
1316 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001317 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001318 include "**/" + name + "/**/*.class"
1319 }
1320 }
1321}
1322
clementberad7ab1dd2019-04-16 16:05:00 +02001323task buildExampleJava11Jars {
1324 def examplesDir = file("src/test/examplesJava11")
1325 examplesDir.eachDir { dir ->
1326 def name = dir.getName();
1327 def exampleOutputDir = file("build/test/examplesJava11");
1328 def jarName = "${name}.jar"
1329 dependsOn "jar_examplesJava11_${name}"
1330 task "jar_examplesJava11_${name}"(type: Jar) {
1331 archiveName = jarName
1332 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001333 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001334 include "**/" + name + "/**/*.class"
1335 }
1336 }
1337}
1338
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001339task buildExamplesKotlin {
1340 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1341 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1342 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1343 } else if (!OperatingSystem.current().isLinux()) {
1344 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1345 "on your platform. It is fully supported on Linux and partially supported on " +
1346 "Mac OS and Windows")
1347 return;
1348 }
1349 def examplesDir = file("src/test/examplesKotlin")
1350 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001351 def name = dir.getName();
1352 dependsOn "dex_example_kotlin_${name}"
1353 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1354 def dexPath = file("${exampleOutputDir}")
1355 task "dex_example_kotlin_${name}"(type: dx.Dx,
1356 dependsOn: "compile_example_kotlin_${name}") {
1357 doFirst {
1358 if (!dexPath.exists()) {
1359 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001360 }
1361 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001362 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1363 destination = dexPath
1364 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001365 }
1366 }
1367}
1368
Sebastien Hertzd3313772018-01-16 14:12:37 +01001369task buildKotlinR8TestResources {
1370 def examplesDir = file("src/test/kotlinR8TestResources")
1371 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001372 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1373 def name = dir.getName()
1374 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001375 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1376 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001377 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001378 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001379 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1380 source = fileTree(dir: file("${examplesDir}/${name}"),
1381 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001382 destination = file(outputFile)
1383 targetVersion = kotlinTargetVersion
1384 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001385 task "${taskName}Java"(type: JavaCompile) {
1386 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1387 destinationDir = file(javaOutput)
1388 classpath = sourceSets.main.compileClasspath
1389 sourceCompatibility = JavaVersion.VERSION_1_6
1390 targetCompatibility = JavaVersion.VERSION_1_6
1391 options.compilerArgs += ["-g", "-Xlint:-options"]
1392 }
1393 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1394 archiveName = javaOutputJarName
1395 destinationDir = file(javaOutputJarDir)
1396 from javaOutput
1397 include "**/*.class"
1398 }
1399 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001400 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001401 }
1402}
1403
Mads Ager418d1ca2017-05-22 09:35:49 +02001404task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001405 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1406 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1407 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001408 } else if (!OperatingSystem.current().isLinux()) {
1409 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001410 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001411 return;
1412 }
1413 dependsOn buildDebugTestResourcesJars
1414 dependsOn buildExampleJars
1415 dependsOn buildExampleAndroidNJars
1416 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001417 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001418 dependsOn buildExampleJava9Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001419 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001420 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001421 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001422 def noDexTests = [
1423 "multidex",
1424 "multidex002",
1425 "multidex004",
1426 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001427 examplesDir.eachDir { dir ->
1428 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001429 if (!(name in noDexTests)) {
1430 dependsOn "dex_example_${name}"
1431 def exampleOutputDir = file("build/test/examples/" + name);
1432 def dexPath = file("${exampleOutputDir}")
1433 def debug = (name == "throwing")
1434 if (!dexPath.exists()) {
1435 dexPath.mkdirs()
1436 }
1437 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1438 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1439 destination = dexPath
1440 debug = debug
1441 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001442 }
1443 }
1444}
1445
1446task buildSmali {
1447 def smaliDir = file("src/test/smali")
1448 smaliDir.eachDirRecurse() { dir ->
1449 def name = dir.getName();
1450 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1451 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1452 smaliOutputDir.mkdirs()
1453 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001454 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001455 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1456 def javaFiles = fileTree(dir: dir, include: '*.java')
1457 def destDir = smaliOutputDir;
1458 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1459 def intermediateFileName = "${name}-intermediate.dex";
1460 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1461 if (javaFiles.empty) {
1462 if (!smaliFiles.empty) {
1463 dependsOn "${taskName}_smali"
1464 task "${taskName}_smali"(type: smali.Smali) {
1465 source = smaliFiles
1466 destination = destFile
1467 }
1468 }
1469 } else {
1470 dependsOn "${taskName}_dexmerger"
1471 task "${taskName}_smali"(type: smali.Smali) {
1472 source = smaliFiles
1473 destination = intermediateFile
1474 }
1475 task "${taskName}_java"(type: JavaCompile) {
1476 source = javaFiles
1477 destinationDir destDir
1478 classpath = sourceSets.main.compileClasspath
1479 sourceCompatibility = JavaVersion.VERSION_1_7
1480 targetCompatibility = JavaVersion.VERSION_1_7
1481 options.compilerArgs += ["-Xlint:-options"]
1482 }
1483 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1484 archiveName = "Test.jar"
1485 destinationDir = destDir
1486 from fileTree(dir: destDir, include: 'Test.class')
1487 }
1488 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1489 source = fileTree(dir: destDir, include: 'Test.jar')
1490 destination = destDir
1491 }
1492 task "${taskName}_dexmerger"(
1493 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1494 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1495 destination = destFile
1496 }
1497 }
1498 }
1499}
1500
1501tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001502 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001503 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1504 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1505 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind3defc8d2019-03-27 08:07:31 +01001506 maxParallelForks = (Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1) + 1
Rico Windc56f21c2019-03-12 07:29:57 +01001507 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001508 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001509 if (project.hasProperty('disable_assertions')) {
1510 enableAssertions = false
1511 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001512 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1513 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001514}
1515
1516task buildPreNJdwpTestsJar(type: Jar) {
1517 baseName = 'jdwp-tests-preN'
1518 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1519 // Exclude the classes containing java8
1520 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1521 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1522 includeEmptyDirs = false
1523}
1524
Ian Zerny74143162017-11-24 13:46:35 +01001525task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1526 def inFile = buildPreNJdwpTestsJar.archivePath
1527 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001528 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001529 outputs.file outFile
1530 if (OperatingSystem.current().isWindows()) {
1531 executable file("tools/windows/dx/bin/dx.bat")
1532 } else if (OperatingSystem.current().isMacOsX()) {
1533 executable file("tools/mac/dx/bin/dx");
1534 } else {
1535 executable file("tools/linux/dx/bin/dx");
1536 }
1537 args "--dex"
1538 args "--output=${outFile}"
1539 args inFile
1540}
1541
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001542task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1543 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001544}
1545
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001546def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001547 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001548 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001549 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001550 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001551 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001552 return null
1553}
1554
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001555task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001556 dependsOn testJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001557 inputs.files files("$buildDir/libs/r8tests.jar")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001558 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001559 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001560 delete r8LibTestPath
1561 from zipTree(testJar.outputs.files[0])
1562 into r8LibTestPath
1563 include "com/android/tools/r8/**"
1564 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001565 }
1566 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001567}
1568
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001569def printStackTrace(TestResult result) {
1570 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1571 def out = new StringBuffer()
1572 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001573 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001574 def header = "RETRACED STACKTRACE";
1575 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1576 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1577 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1578 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001579 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001580 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001581 out.append("--------------------------------------\n")
1582 Process process = command.execute()
1583 def processIn = new PrintStream(process.getOut())
1584 process.consumeProcessOutput(out, err)
1585 result.exception.printStackTrace(processIn)
1586 processIn.flush()
1587 processIn.close()
1588 process.waitFor()
1589 out.append("\n\n--------------------------------------\n")
1590 out.append("OBFUSCATED STACKTRACE\n")
1591 out.append("--------------------------------------\n")
1592 result.exceptions.add(0, new Exception(out.toString()))
1593 } else {
1594 result.exception.printStackTrace()
1595 }
1596}
1597
Mads Ager418d1ca2017-05-22 09:35:49 +02001598test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001599 if (project.hasProperty('generate_golden_files_to')) {
1600 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1601 assert project.hasProperty('HEAD_sha1')
1602 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1603 }
1604
1605 if (project.hasProperty('use_golden_files_in')) {
1606 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1607 assert project.hasProperty('HEAD_sha1')
1608 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1609 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001610 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001611 // R8.jar is required for running bootstrap tests.
1612 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001613 testLogging.exceptionFormat = 'full'
1614 if (project.hasProperty('print_test_stdout')) {
1615 testLogging.showStandardStreams = true
1616 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001617 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001618 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001619 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001620 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001621
Ian Zerny324d7612019-03-20 10:52:28 +01001622 // Forward runtime configurations for test parameters.
1623 if (project.hasProperty('runtimes')) {
1624 println "NOTE: Running with runtimes: " + project.property('runtimes')
1625 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001626 }
1627
Mads Ager418d1ca2017-05-22 09:35:49 +02001628 if (project.hasProperty('one_line_per_test')) {
1629 beforeTest { desc ->
1630 println "Start executing test ${desc.name} [${desc.className}]"
1631 }
1632 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001633 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001634 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001635 }
Rico Windda6836e2018-12-07 12:32:03 +01001636 if (project.hasProperty('update_test_timestamp')) {
1637 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1638 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001639 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1640 }
Rico Windf88b6be2018-12-11 15:14:05 +01001641 } else {
1642 afterTest { desc, result ->
1643 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001644 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001645 }
1646 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001647 }
1648 if (project.hasProperty('no_internal')) {
1649 exclude "com/android/tools/r8/internal/**"
1650 }
1651 if (project.hasProperty('only_internal')) {
1652 include "com/android/tools/r8/internal/**"
1653 }
Rico Wind4e218292019-03-07 12:44:49 +01001654
Mads Ager418d1ca2017-05-22 09:35:49 +02001655 if (project.hasProperty('tool')) {
1656 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001657 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001658 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001659 if (project.hasProperty('only_jctf')) {
1660 include "com/android/tools/r8/jctf/d8/**"
1661 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001662 // Don't run anything, deprecated
1663 println "Running with deprecated tool d8, not running any tests"
1664 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001665 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001666 } else {
1667 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001668 assert(project.hasProperty('only_jctf'))
1669 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001670 }
1671 }
1672 if (!project.hasProperty('all_tests')) {
1673 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001674 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001675 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001676 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001677 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001678 if (project.hasProperty('shard_count') ) {
1679 assert project.hasProperty('shard_number')
1680 int shard_count = project.getProperty('shard_count') as Integer
1681 int shard_number = project.getProperty('shard_number') as Integer
1682 assert shard_count < 65536
1683 assert shard_number < shard_count
1684 exclude {
1685 entry ->
1686 // Don't leave out directories. Leaving out a directory means all entries below.
1687 if (entry.file.isDirectory()) {
1688 return false
1689 }
1690 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1691 int hash = Integer.parseInt(first4, 16)
1692 return hash % shard_count != shard_number
1693 }
1694 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001695 if (project.hasProperty('jctf_compile_only')) {
1696 println "JCTF: compiling only"
1697 systemProperty 'jctf_compile_only', '1'
1698 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001699 if (project.hasProperty('test_dir')) {
1700 systemProperty 'test_dir', project.property('test_dir')
1701 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001702 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1703 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001704 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1705 // all needed tests in r8LibTestPath.
1706 classpath = files([r8LibPath, r8LibTestPath]) +
1707 sourceSets.test.runtimeClasspath -
1708 sourceSets.main.output -
1709 files(['build/classes/test'])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001710 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001711 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001712 if (OperatingSystem.current().isLinux()
1713 || OperatingSystem.current().isMacOsX()
1714 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001715 if (OperatingSystem.current().isMacOsX()) {
1716 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1717 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1718 "See tools/docker/README.md for details.")
1719 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001720 if (OperatingSystem.current().isWindows()) {
1721 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1722 "Art only runs on Linux and tests requiring Art will be skipped")
1723 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001724 dependsOn downloadDeps
1725 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001726 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001727 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001728 dependsOn buildSmali
1729 dependsOn jctfCommonJar
1730 dependsOn jctfTestsClasses
1731 dependsOn buildDebugInfoExamplesDex
1732 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001733 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001734 } else {
1735 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001736 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001737 }
1738}
1739
1740// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1741//
1742// To build and upload a new set of the Art tests for use with R8 follow these steps:
1743//
1744// First of all an Android checkout is required. Currently it must be located
1745// in $HOME/android/master.
1746//
1747// TODO(ricow): simplify this
1748//
1749// Before: update the checked in art, see scripts/update-host-art.sh
1750//
1751// 1. Get an android checkout in $HOME/android/master and apply the patch from
1752// https://android-review.googlesource.com/#/c/294187/
1753//
1754// 2. run the following commands in the Android checkout directory:
1755//
1756// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001757// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1758// m desugar
1759// m -j30 test-art-host
1760// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1761//
1762// Without running the test.py command the classes.jar file used by desugar in
1763// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1764// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001765//
1766// 3. In the R8 project root directory, make sure we have a clean state before starting:
1767// tools/gradle.py downloadDeps
1768// tools/gradle.py clean
1769// rm -rf tests/art
1770//
1771// 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 +02001772// Make sure you have smali on your path, please use the build binary in the
1773// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1774// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1775// 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 +02001776// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1777// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001778//
Søren Gjesse34b77732017-07-07 13:56:21 +02001779// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001780//
1781// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1782// skippedTests with an explanation. Rerun from step 3.
1783//
1784// 5. Run the tests:
1785// tools/gradle.py clean
1786// tools/test.py
1787//
Søren Gjesse34b77732017-07-07 13:56:21 +02001788// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1789// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1790// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001791//
Søren Gjesse34b77732017-07-07 13:56:21 +02001792// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001793// cd tests
1794// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001795//
1796// 7. Update the manifest file describing the Android repo used:
1797// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001798
Mads Ager418d1ca2017-05-22 09:35:49 +02001799def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02001800
1801def artTestDir = file("${androidCheckoutDir}/art/test")
1802
1803if (project.hasProperty('android_source')) {
1804 task buildArtTests {
1805 outputs.upToDateWhen { false }
1806 def toBeTriaged = [
1807 "903-hello-tagging",
1808 "904-object-allocation",
1809 "905-object-free",
1810 "906-iterate-heap",
1811 "907-get-loaded-classes",
1812 "908-gc-start-finish",
1813 "954-invoke-polymorphic-verifier",
1814 "955-methodhandles-smali",
1815 "596-monitor-inflation",
1816 ]
1817 def skippedTests = toBeTriaged + [
1818 // This test produces no jar.
1819 "000-nop",
1820 // This does not build, as it tests the error when the application exceeds more
1821 // than 65536 methods
1822 "089-many-methods",
1823 // Requires some jack beta jar
1824 "956-methodhandles",
1825 ]
1826
1827 def skippedTestsDx = [
1828 // Tests with custom build scripts, where javac is not passed the options
1829 // -source 1.7 -target 1.7.
1830 "462-checker-inlining-across-dex-files",
1831 "556-invoke-super",
1832 "569-checker-pattern-replacement",
1833 // These tests use jack even when --build-with-javac-dx is specified.
1834 "004-JniTest",
1835 "048-reflect-v8",
1836 "146-bad-interface",
1837 "563-checker-invoke-super",
1838 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1839 "604-hot-static-interface",
1840 "957-methodhandle-transforms",
1841 "958-methodhandle-emulated-stackframe",
1842 "959-invoke-polymorphic-accessors",
1843 "961-default-iface-resolution-gen",
1844 "962-iface-static",
1845 "963-default-range-smali",
1846 "964-default-iface-init-gen",
1847 "965-default-verify",
1848 "966-default-conflict",
1849 "967-default-ame",
1850 "968-default-partial-compile-gen",
1851 "969-iface-super",
1852 "970-iface-super-resolution-gen",
1853 "971-iface-super",
1854 // These tests does not build with --build-with-javac-dx
1855 "004-NativeAllocations", // Javac error
1856 "031-class-attributes",
1857 "138-duplicate-classes-check",
1858 "157-void-class", // Javac error
1859 "580-checker-string-factory-intrinsics",
1860 "612-jit-dex-cache",
1861 "613-inlining-dex-cache",
1862 "900-hello-plugin", // --experimental agents
1863 "901-hello-ti-agent", // --experimental agents
1864 "902-hello-transformation", // --experimental agents
1865 "909-attach-agent", // --experimental agents
1866 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1867 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1868 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1869 "960-default-smali", // --experimental default-methods
1870 // These tests force the build to use jack
1871 "953-invoke-polymorphic-compiler",
1872 "958-methodhandle-stackframe",
1873 ]
1874
1875 def artTestBuildDir = file("${projectDir}/tests/art")
1876
1877 if (androidCheckoutDir.exists()) {
1878 dependsOn downloadDeps
1879 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02001880 artTestDir.eachDir { dir ->
1881 def name = dir.getName();
1882 def markerFile = dir.toPath().resolve("info.txt").toFile();
1883 if (markerFile.exists() && !(name in skippedTests)) {
1884 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01001885 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02001886 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001887 }
1888 }
1889 }
1890 doFirst {
1891 if (!androidCheckoutDir.exists()) {
1892 throw new InvalidUserDataException(
1893 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02001894 }
1895 }
1896 doLast {
1897 copy {
1898 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1899 into file("${artTestBuildDir}/lib64")
1900 include 'lib*.so'
1901 }
1902 copy {
1903 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1904 into file("${artTestBuildDir}/lib64")
1905 include 'libart.so'
1906 include 'libbacktrace.so'
1907 include 'libbase.so'
1908 include 'libc++.so'
1909 include 'libcutils.so'
1910 include 'liblz4.so'
1911 include 'liblzma.so'
1912 include 'libnativebridge.so'
1913 include 'libnativeloader.so'
1914 include 'libsigchain.so'
1915 include 'libunwind.so'
1916 include 'libziparchive.so'
1917 }
1918 copy {
1919 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1920 into file("${artTestBuildDir}/lib")
1921 include 'lib*.so'
1922 }
1923 copy {
1924 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1925 into file("${artTestBuildDir}/lib")
1926 include 'libart.so'
1927 include 'libbacktrace.so'
1928 include 'libbase.so'
1929 include 'libc++.so'
1930 include 'libcutils.so'
1931 include 'liblz4.so'
1932 include 'liblzma.so'
1933 include 'libnativebridge.so'
1934 include 'libnativeloader.so'
1935 include 'libsigchain.so'
1936 include 'libunwind.so'
1937 include 'libziparchive.so'
1938 }
1939 }
1940 }
1941}
1942
Rico Windde2af6c2019-03-26 15:21:08 +01001943def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001944 def artTestDir = file("${androidCheckoutDir}/art/test")
1945 def artRunTestScript = file("${artTestDir}/run-test")
1946 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001947 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001948
Søren Gjesse34b77732017-07-07 13:56:21 +02001949 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01001950 def buildTask = "build_art_test_dx_${name}"
1951 def sanitizeTask = "sanitize_art_test_dx_${name}"
1952 def copyCheckTask = "copy_check_art_test_dx_${name}"
1953 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001954
1955 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01001956 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001957 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1958 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01001959 task "$buildTask"(type: Exec) {
1960 outputs.upToDateWhen { false }
1961 inputs.file buildInputs
1962 executable "${artRunTestScript}"
1963 args "--host"
1964 args "--build-only"
1965 args "--build-with-javac-dx"
1966 args "--output-path", "${testDir}"
1967 args "${name}"
1968 environment DX: "${dxExecutable.absolutePath}"
1969 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1970 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1971 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02001972 }
1973 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1974 outputs.upToDateWhen { false }
1975 executable "/bin/bash"
1976 args "-c"
1977 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1978 " ${testDir}/classes-ex ${testDir}/check"
1979 }
1980
1981 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001982 // Directory that contains smali files is either smali, or smali/art
1983 def smali_dir = file("${dir}/smali/art")
1984 if (smali_dir.exists()) {
1985 workingDir "${testDir}/smali/art"
1986 } else {
1987 workingDir "${testDir}/smali"
1988 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001989 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001990 // This is the command line options for smali prior to 2.2.1, where smali got a new
1991 // command line interface.
1992 args "-c", "smali a *.smali"
1993 // This is the command line options for smali 2.2.1 and later.
1994 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001995 }
1996
1997 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1998 def smali_dir = file("${dir}/smali")
1999 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002000 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002001 dependsOn smaliToDexTask
2002 }
2003 from("${artTestDir}/${name}") {
2004 include 'check'
2005 }
2006 into testDir
2007 }
2008
2009 return copyCheckTask
2010}
2011
2012task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002013 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002014 classpath = sourceSets.main.compileClasspath
2015 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002016 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002017 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002018 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002019 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002020 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002021 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002022 include '**/com/android/tools/r8/CompilationMode.java'
2023 include '**/com/android/tools/r8/D8.java'
2024 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002025 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2026 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002027 include '**/com/android/tools/r8/Diagnostic.java'
2028 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002029 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2030 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002031 include '**/com/android/tools/r8/ProgramConsumer.java'
2032 include '**/com/android/tools/r8/ProgramResource.java'
2033 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002034 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002035 include '**/com/android/tools/r8/ResourceException.java'
2036 include '**/com/android/tools/r8/StringConsumer.java'
2037 include '**/com/android/tools/r8/StringResource.java'
2038 include '**/com/android/tools/r8/Version.java'
2039 include '**/com/android/tools/r8/origin/*.java'
2040}
2041
2042task javadocR8(type: Javadoc) {
2043 title "R8 API"
2044 classpath = sourceSets.main.compileClasspath
2045 source = sourceSets.main.allJava
2046 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2047 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2048 include '**/com/android/tools/r8/BaseCommand.java'
2049 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2050 include '**/com/android/tools/r8/ClassFileConsumer.java'
2051 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2052 include '**/com/android/tools/r8/CompilationFailedException.java'
2053 include '**/com/android/tools/r8/CompilationMode.java'
2054 include '**/com/android/tools/r8/R8.java'
2055 include '**/com/android/tools/r8/R8Command.java'
2056 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2057 include '**/com/android/tools/r8/Diagnostic.java'
2058 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002059 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2060 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002061 include '**/com/android/tools/r8/ProgramConsumer.java'
2062 include '**/com/android/tools/r8/ProgramResource.java'
2063 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2064 include '**/com/android/tools/r8/Resource.java'
2065 include '**/com/android/tools/r8/ResourceException.java'
2066 include '**/com/android/tools/r8/StringConsumer.java'
2067 include '**/com/android/tools/r8/StringResource.java'
2068 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002069 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002070}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002071
2072task copyMavenDeps(type: Copy) {
2073 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002074 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002075 from configurations.testCompile into "$buildDir/deps"
2076}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002077
Rico Wind23a05112019-03-27 08:00:44 +01002078task printMavenDeps {
2079 // Only actually print to stdout when we are updating.
2080 if (project.hasProperty('updatemavendeps')) {
2081 for (Configuration config : configurations) {
2082 if (!config.isCanBeResolved()) {
2083 continue
2084 }
2085 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2086 it.selected.id
2087 }
2088 def result = dependencies.createArtifactResolutionQuery()
2089 .forComponents(componentIds)
2090 .withArtifacts(MavenModule, MavenPomArtifact)
2091 .execute()
2092 for (component in result.resolvedComponents) {
2093 component.getArtifacts(MavenPomArtifact).each {
2094 println "POM: ${it.file} ${component.id}"
2095 }
2096 }
2097 config.each {
2098 println "JAR: ${it}"
2099 }
2100 }
2101 }
2102}