blob: e180938f1773cd94b6659ece29a77e03b4fd569a [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'
Gautam Korlam39d74202018-08-29 18:09:35 -070037 asmVersion = '6.2.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 = [
71 '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 }
92 classlib {
93 java {
94 srcDirs = [
95 'third_party/classlib/java',
96 ]
97 }
98 output.resourcesDir = 'build/classes/classlib'
99 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200100 debugTestResources {
101 java {
102 srcDirs = ['src/test/debugTestResources']
103 }
104 output.resourcesDir = 'build/classes/debugTestResources'
105 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200106 debugTestResourcesJava8 {
107 java {
108 srcDirs = ['src/test/debugTestResourcesJava8']
109 }
110 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
111 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200112 debugTestResourcesKotlin {
113 java {
114 srcDirs = ['src/test/debugTestResourcesKotlin']
115 }
116 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
117 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200118 examples {
119 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800120 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200121 }
122 output.resourcesDir = 'build/classes/examples'
123 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100124 examplesKotlin {
125 java {
126 srcDirs = ['src/test/examplesKotlin']
127 }
128 output.resourcesDir = 'build/classes/examplesKotlin'
129 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200130 examplesAndroidN {
131 java {
132 srcDirs = ['src/test/examplesAndroidN']
133 }
134 output.resourcesDir = 'build/classes/examplesAndroidN'
135 }
136 examplesAndroidO {
137 java {
138 srcDirs = ['src/test/examplesAndroidO']
139 }
140 output.resourcesDir = 'build/classes/examplesAndroidO'
141 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200142 examplesAndroidP {
143 java {
144 srcDirs = ['src/test/examplesAndroidP']
145 }
146 output.resourcesDir = 'build/classes/examplesAndroidP'
147 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200148 jctfCommon {
149 java {
150 srcDirs = [
151 'third_party/jctf/Harness/src',
152 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
153 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
154 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
155 'third_party/jctf/LibTests/src/org',
156 'build/additionalJctfCommonFiles'
157 ]
158 }
159 resources {
160 srcDirs = ['third_party/jctf/LibTests/resources']
161 }
162 }
163 jctfTests {
164 java {
165 srcDirs = [
166 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
167 // 'third_party/jctf/VMTests/src',
168 ]
169 }
170 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100171 kotlinR8TestResources {
172 java {
173 srcDirs = ['src/test/kotlinR8TestResources']
174 }
175 output.resourcesDir = 'build/classes/kotlinR8TestResources'
176 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200177}
178
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800179// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
180// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
181// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
182// for context.
183idea {
184 sourceSets.all { SourceSet sources ->
185 module {
186 if (sources.name == "main") {
187 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100188 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800189 } else {
190 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100191 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800192 }
193 }
194 }
195}
196
Yohann Roussel126f6872017-08-03 16:25:32 +0200197configurations {
198 supportLibs
199}
200
Mads Ager418d1ca2017-05-22 09:35:49 +0200201dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100202 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
203 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200204 // Include all of guava when compiling the code, but exclude annotations that we don't
205 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100206 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100207 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200208 exclude group: 'com.google.errorprone'
209 exclude group: 'com.google.code.findbugs'
210 exclude group: 'com.google.j2objc'
211 exclude group: 'org.codehaus.mojo'
212 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100213 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
214 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
215 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
216 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
217 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
218 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
219 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200220 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100221 testCompile "junit:junit:$junitVersion"
222 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200223 testCompile files('third_party/jasmin/jasmin-2.4.jar')
224 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200225 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100226 jctfCommonCompile "junit:junit:$junitVersion"
227 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200228 jctfTestsCompile sourceSets.jctfCommon.output
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100229 cfSegmentsCompile sourceSets.classlib.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100230 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
231 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200232 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100233 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800234 examplesCompile "junit:junit:$junitVersion"
235 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100236 supportLibs "com.android.support:support-v4:$androidSupportVersion"
237 supportLibs "junit:junit:$junitVersion"
238 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100239 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100240 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100241 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
242 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
243 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100244 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200245}
246
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100247def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100248def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100249def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100250def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100251def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100252
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200253def osString = OperatingSystem.current().isLinux() ? "linux" :
254 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200255
256def cloudDependencies = [
257 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200258 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100259 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200260 ],
261 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200262 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200263 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100264 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200265 "android_jar/lib-v19",
266 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100267 "android_jar/lib-v22",
268 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200269 "android_jar/lib-v24",
270 "android_jar/lib-v25",
271 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100272 "android_jar/lib-v27",
273 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200274 "core-lambda-stubs",
275 "dart-sdk",
276 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200277 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200278 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200279 "jasmin",
280 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100281 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200282 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200283 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100284 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200285 "proguard/proguard5.2.1",
286 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200287 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200288 ],
289 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
290 // container on other platforms where supported.
291 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "linux/art",
293 "linux/art-5.1.1",
294 "linux/art-6.0.1",
295 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100296 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100297 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200298 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100299 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200300 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200301 ]
302]
303
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100304def cloudSystemDependencies = [
305 linux: [
306 "third_party": ["openjdk/openjdk-9.0.4/linux"],
307 ],
308 osx: [
309 "third_party": ["openjdk/openjdk-9.0.4/osx"],
310 ],
311 windows: [
312 "third_party": ["openjdk/openjdk-9.0.4/windows"],
313 ],
314]
315
316if (OperatingSystem.current().isWindows()) {
317 cloudSystemDependencies.windows.each { entry ->
318 cloudDependencies.get(entry.key).addAll(entry.value)
319 }
320} else if (OperatingSystem.current().isLinux()) {
321 cloudSystemDependencies.linux.each { entry ->
322 cloudDependencies.get(entry.key).addAll(entry.value)
323 }
324} else if (OperatingSystem.current().isMacOsX()) {
325 cloudSystemDependencies.osx.each { entry ->
326 cloudDependencies.get(entry.key).addAll(entry.value)
327 }
328} else {
329 println "WARNING: Unsupported system: " + OperatingSystem.current()
330}
331
332def getDownloadDepsTaskName(entryKey, entryFile) {
333 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
334}
335
Ian Zernyb2d27c42019-02-20 09:09:41 +0100336def getFetchDepsTaskName(entryKey, entryFile) {
337 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
338}
339
Mads Ager418d1ca2017-05-22 09:35:49 +0200340cloudDependencies.each { entry ->
341 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100342 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
343 type DownloadDependency.Type.GOOGLE_STORAGE
344 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200345 }
346 }
347}
348
349def x20Dependencies = [
350 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200351 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200352 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100353 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100354 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200355 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100356 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200357 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200358 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200359 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200360 "gmscore/gmscore_v10",
361 "gmscore/gmscore_v9",
362 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200363 "gmscore/v4",
364 "gmscore/v5",
365 "gmscore/v6",
366 "gmscore/v7",
367 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200368 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200369 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200370 "proguard/proguard_internal_159423826",
371 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200372 "youtube/youtube.android_12.10",
373 "youtube/youtube.android_12.17",
374 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200375 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200376 ],
377]
378
379x20Dependencies.each { entry ->
380 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100381 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
382 type DownloadDependency.Type.X20
383 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200384 }
385 }
386}
387
Rico Wind897bb712017-05-23 10:44:29 +0200388task downloadProguard {
389 cloudDependencies.each { entry ->
390 entry.value.each { entryFile ->
391 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100392 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200393 }
394 }
395 }
396}
397
Rico Windf6c74ce2018-12-04 08:50:55 +0100398task downloadOpenJDKrt {
399 cloudDependencies.each { entry ->
400 entry.value.each { entryFile ->
401 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100402 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100403 }
404 }
405 }
406}
407
Tamas Kenez427205b2017-06-29 15:57:09 +0200408task downloadDx {
409 cloudDependencies.each { entry ->
410 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200411 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100412 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200413 }
414 }
415 }
416}
417
Tamas Kenez0e10c562017-06-08 10:00:34 +0200418task downloadAndroidCts {
419 cloudDependencies.each { entry ->
420 entry.value.each { entryFile ->
421 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100422 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200423 }
424 }
425 }
426}
427
Mads Ager418d1ca2017-05-22 09:35:49 +0200428task downloadDeps {
429 cloudDependencies.each { entry ->
430 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100431 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200432 }
433 }
434 if (!project.hasProperty('no_internal')) {
435 x20Dependencies.each { entry ->
436 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100437 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200438 }
439 }
440 }
441}
442
443allprojects {
444 sourceCompatibility = JavaVersion.VERSION_1_8
445 targetCompatibility = JavaVersion.VERSION_1_8
446}
447
Rico Wind266336c2019-02-25 10:11:38 +0100448// TODO(ricow): Remove debug prints
449println("NOTE: Current operating system: " + OperatingSystem.current())
450println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
451
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100452// Check if running with the JDK location from tools/jdk.py.
453if (OperatingSystem.current().isWindows()) {
454 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
455} else {
456 def javaHomeOut = new StringBuilder()
457 def javaHomeErr = new StringBuilder()
458 def javaHomeProc = './tools/jdk.py'.execute()
459 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
460 def jdkHome = new File(javaHomeOut.toString().trim())
461 if (!jdkHome.exists()) {
462 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
463 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
464 println("WARNING: Gradle is running in a non-pinned Java"
465 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
466 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100467 } else {
468 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100469 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200470}
471
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100472sourceSets.configureEach { sourceSet ->
473 tasks.named(sourceSet.compileJavaTaskName).configure {
474 // Default disable errorprone (enabled and setup below).
475 options.errorprone.enabled = false
476 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100477 // Run all compilation tasks in a forked subprocess.
478 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100479 // Javac often runs out of stack space when compiling the tests.
480 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100481 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100482 // Test compilation is sometimes hitting the default limit at 1g, increase it.
483 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100484 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
485 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
486 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200487}
488
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100489if (!project.hasProperty('without_error_prone') &&
490 // Don't enable error prone on Java 8 as the plugin setup does not support it.
491 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200492 compileJava {
493 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100494 options.errorprone.enabled = true
495 options.errorprone.disableAllChecks = true
496 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
497 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
498 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
499 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
500 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
501 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
502 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
503 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
504 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
505 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
506 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
507 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
508 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
509 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
510 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
511 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
512 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
513 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
514 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200515 }
516}
517
Mads Ager418d1ca2017-05-22 09:35:49 +0200518compileJctfCommonJava {
519 dependsOn 'copyAdditionalJctfCommonFiles'
520 options.compilerArgs = ['-Xlint:none']
521}
522
523compileJctfTestsJava {
524 dependsOn 'jctfCommonClasses'
525 options.compilerArgs = ['-Xlint:none']
526}
527
Yohann Roussel7f47c032017-09-14 12:19:06 +0200528task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200529 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100530
Yohann Roussel7f47c032017-09-14 12:19:06 +0200531 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100532 def runtimeClasspath = configurations.findByName("runtimeClasspath")
533 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
534
Yohann Roussel7f47c032017-09-14 12:19:06 +0200535 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100536
Yohann Roussel7f47c032017-09-14 12:19:06 +0200537 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100538 def dependencies = []
539 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
540 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
541 dependencies.add("${identifier.group}:${identifier.module}")
542 }
543 def libraryLicenses = file('LIBRARY-LICENSE').text
544 dependencies.each {
545 if (!libraryLicenses.contains("- artifact: $it")) {
546 throw new GradleException("No license for $it in LIBRARY_LICENSE")
547 }
548 }
549
Yohann Roussel7f47c032017-09-14 12:19:06 +0200550 license.getParentFile().mkdirs()
551 license.createNewFile()
552 license.text = "This file lists all licenses for code distributed.\n"
553 license.text += "All non-library code has the following 3-Clause BSD license.\n"
554 license.text += "\n"
555 license.text += "\n"
556 license.text += file('LICENSE').text
557 license.text += "\n"
558 license.text += "\n"
559 license.text += "Summary of distributed libraries:\n"
560 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100561 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200562 license.text += "\n"
563 license.text += "\n"
564 license.text += "Licenses details:\n"
565 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
566 license.text += "\n"
567 license.text += "\n"
568 license.text += file.text
569 }
570 }
571}
572
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200573static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700574 // Everything under META-INF is not included by default.
575 // Should include before 'relocate' so that the service file path and its content
576 // are properly relocated as well.
577 task.mergeServiceFiles {
578 include 'META-INF/services/*'
579 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200580}
581
582static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000583 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200584 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000585 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
586 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000587 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000588 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200589 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
590 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
591 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200592 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000593}
594
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100595task repackageDepsNoRelocate(type: ShadowJar) {
596 configurations = [project.configurations.runtimeClasspath]
597 mergeServiceFiles(it)
598 exclude { it.getRelativePath().getPathString() == "module-info.class" }
599 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100600 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100601}
602
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000603task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100604 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200605 mergeServiceFiles(it)
606 if (!project.hasProperty('lib_no_relocate')) {
607 configureRelocations(it)
608 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100609 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700610 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000611 baseName 'deps'
612}
613
614task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200615 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200616 mergeServiceFiles(it)
617 if (!project.hasProperty('lib_no_relocate')) {
618 configureRelocations(it)
619 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000620 baseName 'sources'
621}
622
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100623task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200624 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100625 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200626 classifier = null
627 version = null
628 manifest {
629 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
630 }
631 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100632 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100633 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100634 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200635}
636
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100637task r8WithoutDeps(type: ShadowJar) {
638 from consolidatedLicense.outputs.files
639 baseName 'r8_without_deps'
640 classifier = null
641 version = null
642 manifest {
643 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
644 }
645 from sourceSets.main.output
646}
647
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000648task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200649 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200650 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200651 classifier = null
652 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200653 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200654 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200655 }
656 // In order to build without dependencies, pass the exclude_deps property using:
657 // gradle -Pexclude_deps R8
658 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800659 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000660 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800661 } else {
662 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200663 }
Ian Zerny80533c92019-01-24 10:32:09 +0100664 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200665}
666
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100667task R8NoManifestNoDeps(type: ShadowJar) {
668 from consolidatedLicense.outputs.files
669 baseName 'r8nomanifest-exclude-deps'
670 classifier = null
671 version = null
672 from sourceSets.main.output
673}
674
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100675task R8NoManifest(type: ShadowJar) {
676 from consolidatedLicense.outputs.files
677 baseName 'r8nomanifest'
678 classifier = null
679 version = null
680 // In order to build without dependencies, pass the exclude_deps property using:
681 // gradle -Pexclude_deps R8
682 if (!project.hasProperty('exclude_deps')) {
683 from repackageSources.outputs.files
684 from repackageDeps.outputs.files
685 } else {
686 from sourceSets.main.output
687 }
Ian Zerny80533c92019-01-24 10:32:09 +0100688 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100689}
690
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000691task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200692 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200693 baseName 'd8'
694 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200695 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200696 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200697}
698
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200699task CompatDx(type: ShadowJar) {
700 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200701 baseName 'compatdx'
702 manifest {
703 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
704 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200705}
706
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200707task CompatProguard(type: ShadowJar) {
708 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200709 baseName 'compatproguard'
710 manifest {
711 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
712 }
Lars Bak44cef522017-08-10 16:02:39 +0200713}
714
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100715def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100716 // Execute r8 commands against a stable r8 with relocated dependencies.
Rico Windcfb65512019-02-27 12:57:34 +0100717 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
718 "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100719}
720
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100721def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100722 return baseR8CommandLine([
723 "--classfile", "--release",
724 input,
725 "--output", output,
726 "--pg-conf", pgconf,
727 "--pg-map-output", output + ".map",
728 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
729 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100730}
731
732def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
733 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100734 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100735 outputs.file output
736 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100737 dependsOn r8WithRelocatedDeps
738 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100739 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
740 workingDir = projectDir
741 }
742}
743
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100744task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100745 baseName = "r8tests"
746 from sourceSets.test.output
747}
748
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100749task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
750 baseName = "r8tests-exclude-deps"
751 from sourceSets.test.output
752}
753
754def generateR8LibKeepRules(name, r8Source, testSource, output) {
755 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
756 doFirst {
757 standardOutput new FileOutputStream(output)
758 }
759 dependsOn r8WithRelocatedDeps
760 dependsOn r8Source
761 dependsOn testSource
762 dependsOn downloadOpenJDKrt
763 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
764 outputs.file output
765 commandLine baseR8CommandLine([
766 "printuses",
767 "--keeprules",
768 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
769 r8Source.outputs.files[0],
770 testSource.outputs.files[0]])
771 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100772 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100773}
774
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100775task R8LibApiOnly {
776 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
777 outputs.file r8LibPath
778}
779
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100780task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100781 def genRulesTask = generateR8LibKeepRules(
782 "Main",
783 R8NoManifest,
784 testJar,
785 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100786 dependsOn r8LibCreateTask(
787 "Main",
788 "src/main/keep.txt",
789 R8NoManifest,
790 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100791 ["--pg-conf", genRulesTask.outputs.files[0]]
792 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100793 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100794}
795
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100796task R8LibNoDeps {
797 def genRulesTask = generateR8LibKeepRules(
798 "NoDeps",
799 R8NoManifestNoDeps,
800 testJarNoDeps,
801 r8LibGeneratedKeepRulesExcludeDepsPath
802 )
803 dependsOn r8LibCreateTask(
804 "NoDeps",
805 "src/main/keep.txt",
806 R8NoManifestNoDeps,
807 r8LibExludeDepsPath,
808 ["--pg-conf", genRulesTask.outputs.files[0]],
809 repackageDepsNoRelocate.outputs.files
810 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
811 outputs.file r8LibExludeDepsPath
812}
813
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100814task CompatDxLib {
815 dependsOn r8LibCreateTask(
816 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100817}
818
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100819task CompatProguardLib {
820 dependsOn r8LibCreateTask(
821 "CompatPg",
822 "src/main/keep-compatproguard.txt",
823 CompatProguard,
824 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100825}
826
Mads Ager418d1ca2017-05-22 09:35:49 +0200827task sourceJar(type: Jar, dependsOn: classes) {
828 classifier = 'src'
829 from sourceSets.main.allSource
830}
831
832task jctfCommonJar(type: Jar) {
833 from sourceSets.jctfCommon.output
834 baseName 'jctfCommon'
835}
836
837artifacts {
838 archives sourceJar
839}
840
841task createArtTests(type: Exec) {
842 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200843 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100844 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200845 outputs.dir outputDir
846 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200847 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200848 workingDir = projectDir
849}
850
851task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200852 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200853 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200854 inputs.file script
855 outputs.dir outputDir
856 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200857 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200858 workingDir = projectDir
859}
860
861compileTestJava {
862 dependsOn createArtTests
863 dependsOn createJctfTests
864}
865
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100866task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
867 from sourceSets.cfSegments.output
868 baseName 'cf_segments'
869 destinationDir file('build/libs')
870}
871
Ian Zernyee23a172018-01-03 09:08:48 +0100872task buildD8ApiUsageSample(type: Jar) {
873 from sourceSets.apiUsageSample.output
874 baseName 'd8_api_usage_sample'
875 destinationDir file('tests')
876}
877
Ian Zerny923a0c12018-01-03 10:59:18 +0100878task buildR8ApiUsageSample(type: Jar) {
879 from sourceSets.apiUsageSample.output
880 baseName 'r8_api_usage_sample'
881 destinationDir file('tests')
882}
883
Yohann Roussel548ae942018-01-05 11:13:28 +0100884task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100885 dependsOn buildD8ApiUsageSample
886 dependsOn buildR8ApiUsageSample
887}
888
Mads Ager418d1ca2017-05-22 09:35:49 +0200889task buildDebugInfoExamplesDex {
890 def examplesDir = file("src/test/java")
891 def hostJar = "debuginfo_examples.jar"
892 def hostDexJar = "debuginfo_examples_dex.jar"
893 task "compile_debuginfo_examples"(type: JavaCompile) {
894 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
895 destinationDir = file("build/test/debuginfo_examples/classes")
896 classpath = sourceSets.main.compileClasspath
897 sourceCompatibility = JavaVersion.VERSION_1_7
898 targetCompatibility = JavaVersion.VERSION_1_7
899 options.compilerArgs += ["-Xlint:-options"]
900 }
901 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
902 archiveName = hostJar
903 destinationDir = file("build/test/")
904 from "build/test/debuginfo_examples/classes"
905 include "**/*.class"
906 }
907 task "dex_debuginfo_examples"(type: Exec,
908 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200909 if (OperatingSystem.current().isWindows()) {
910 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700911 } else if (OperatingSystem.current().isMacOsX()) {
912 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200913 } else {
914 executable file("tools/linux/dx/bin/dx");
915 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200916 args "--dex"
917 args "--output=build/test/${hostDexJar}"
918 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100919 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200920 outputs.file file("build/test/${hostDexJar}")
921 }
922 dependsOn dex_debuginfo_examples
923}
924
925task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200926 def resourcesDir = file("src/test/debugTestResources")
927 def hostJar = "debug_test_resources.jar"
928 task "compile_debugTestResources"(type: JavaCompile) {
929 source = fileTree(dir: resourcesDir, include: '**/*.java')
930 destinationDir = file("build/test/debugTestResources/classes")
931 classpath = sourceSets.main.compileClasspath
932 sourceCompatibility = JavaVersion.VERSION_1_7
933 targetCompatibility = JavaVersion.VERSION_1_7
934 options.compilerArgs += ["-g", "-Xlint:-options"]
935 }
936 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
937 archiveName = hostJar
938 destinationDir = file("build/test/")
939 from "build/test/debugTestResources/classes"
940 include "**/*.class"
941 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200942 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
943 def java8HostJar = "debug_test_resources_java8.jar"
944 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
945 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
946 destinationDir = file("build/test/debugTestResourcesJava8/classes")
947 classpath = sourceSets.main.compileClasspath
948 sourceCompatibility = JavaVersion.VERSION_1_8
949 targetCompatibility = JavaVersion.VERSION_1_8
950 options.compilerArgs += ["-g", "-Xlint:-options"]
951 }
952 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
953 archiveName = java8HostJar
954 destinationDir = file("build/test/")
955 from "build/test/debugTestResourcesJava8/classes"
956 include "**/*.class"
957 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200958 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000959 def kotlinHostJar = "debug_test_resources_kotlin.jar"
960 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
961 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
962 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200963 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200964 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200965 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200966 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000967 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200968}
969
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100970// Examples used by tests, where Android specific APIs are used.
971task buildExampleAndroidApi(type: JavaCompile) {
972 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
973 destinationDir = file("build/test/examplesAndroidApi/classes")
974 classpath = files("third_party/android_jar/lib-v26/android.jar")
975 sourceCompatibility = JavaVersion.VERSION_1_8
976 targetCompatibility = JavaVersion.VERSION_1_8
977}
978
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100979task buildExampleKotlinJars {
980 def kotlinSrcDir = file("src/test/examplesKotlin")
981 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000982 def name = dir.getName();
983 dependsOn "compile_example_kotlin_${name}"
984 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
985 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
986 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100987 }
988 }
989}
990
Lars Bakc91e87e2017-08-18 08:53:10 +0200991// Proto lite generated code yields warnings when compiling with javac.
992// We change the options passed to javac to ignore it.
993compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
994
Søren Gjesse7320ce52018-05-07 15:45:22 +0200995
Mads Ager418d1ca2017-05-22 09:35:49 +0200996task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200997 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200998 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200999 def proguardScript
1000 if (OperatingSystem.current().isWindows()) {
1001 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1002 } else {
1003 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1004 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001005 task extractExamplesRuntime(type: Sync) {
1006 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001007 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001008 include "**/*.class"
1009 includeEmptyDirs false
1010 into "$buildDir/runtime/examples/"
1011 }
1012
Søren Gjesse7320ce52018-05-07 15:45:22 +02001013 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1014 from examplesDir
1015 exclude "**/*.java"
1016 exclude "**/keep-rules*.txt"
1017 into file("build/test/examples/classes")
1018 }
1019
1020 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001021 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001022 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001023 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001024 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001025 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001026 sourceCompatibility = JavaVersion.VERSION_1_7
1027 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001028 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1029 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001030 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1031 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001032 include "**/*.java"
1033 destinationDir = file("build/test/examples/classes_debuginfo_all")
1034 classpath = sourceSets.examples.compileClasspath
1035 sourceCompatibility = JavaVersion.VERSION_1_7
1036 targetCompatibility = JavaVersion.VERSION_1_7
1037 options.compilerArgs = ["-g", "-Xlint:none"]
1038 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001039 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1040 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001041 include "**/*.java"
1042 destinationDir = file("build/test/examples/classes_debuginfo_none")
1043 classpath = sourceSets.examples.compileClasspath
1044 sourceCompatibility = JavaVersion.VERSION_1_7
1045 targetCompatibility = JavaVersion.VERSION_1_7
1046 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001047 }
1048 examplesDir.eachDir { dir ->
1049 def name = dir.getName();
1050 def exampleOutputDir = file("build/test/examples");
1051 def jarName = "${name}.jar"
1052 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001053 dependsOn "jar_example_${name}_debuginfo_all"
1054 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001055 dependsOn "extractExamplesRuntime"
1056 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001057 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1058 def proguardConfigPath = "${dir}/proguard.cfg"
1059 if (new File(proguardConfigPath).exists()) {
1060 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1061 archiveName = "${name}_pre_proguard.jar"
1062 destinationDir = exampleOutputDir
1063 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001064 include name + "/**/*.class"
1065 with runtimeDependencies
1066 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001067 }
1068 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1069 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1070 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1071 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001072 inputs.files files(
1073 tasks.getByPath("pre_proguard_example_${name}"),
1074 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001075 // Enable these to get stdout and stderr redirected to files...
1076 // standardOutput = new FileOutputStream('proguard.stdout')
1077 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001078 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001079 " -outjars ${proguardJarPath}" +
1080 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001081 " -printmapping ${proguardMapPath}"
1082 if (OperatingSystem.current().isWindows()) {
1083 executable "${proguardScript}"
1084 args "${proguardArguments}"
1085 } else {
1086 executable "bash"
1087 args "-c", "${proguardScript} '${proguardArguments}'"
1088 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001089 outputs.file proguardJarPath
1090 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001091 // TODO: Consider performing distinct proguard compilations.
1092 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1093 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001094 into "${exampleOutputDir}"
1095 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001096 }
1097 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1098 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001099 into "${exampleOutputDir}"
1100 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001101 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001102 } else {
1103 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001104 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001105 destinationDir = exampleOutputDir
1106 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001107 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001108 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001109 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001110 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001111 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1112 archiveName = "${name}_debuginfo_all.jar"
1113 destinationDir = exampleOutputDir
1114 from "build/test/examples/classes_debuginfo_all"
1115 include name + "/**/*.class"
1116 with runtimeDependencies
1117 includeEmptyDirs false
1118 }
1119 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1120 archiveName = "${name}_debuginfo_none.jar"
1121 destinationDir = exampleOutputDir
1122 from "build/test/examples/classes_debuginfo_none"
1123 include name + "/**/*.class"
1124 with runtimeDependencies
1125 includeEmptyDirs false
1126 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001127 }
1128 }
1129}
1130
1131task buildExampleAndroidNJars {
1132 dependsOn downloadDeps
1133 def examplesDir = file("src/test/examplesAndroidN")
1134 task "compile_examplesAndroidN"(type: JavaCompile) {
1135 source = fileTree(dir: examplesDir, include: '**/*.java')
1136 destinationDir = file("build/test/examplesAndroidN/classes")
1137 classpath = sourceSets.main.compileClasspath
1138 sourceCompatibility = JavaVersion.VERSION_1_8
1139 targetCompatibility = JavaVersion.VERSION_1_8
1140 options.compilerArgs += ["-Xlint:-options"]
1141 }
1142 examplesDir.eachDir { dir ->
1143 def name = dir.getName();
1144 def exampleOutputDir = file("build/test/examplesAndroidN");
1145 def jarName = "${name}.jar"
1146 dependsOn "jar_examplesAndroidN_${name}"
1147 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1148 archiveName = jarName
1149 destinationDir = exampleOutputDir
1150 from "build/test/examplesAndroidN/classes"
1151 include "**/" + name + "/**/*.class"
1152 }
1153 }
1154}
1155
1156
1157task buildExampleAndroidOJars {
1158 dependsOn downloadDeps
1159 def examplesDir = file("src/test/examplesAndroidO")
1160 // NOTE: we want to enable a scenario when test needs to reference some
1161 // classes generated by legacy (1.6) Java compiler to test some specific
1162 // behaviour. To do so we compile all the java files located in sub-directory
1163 // called 'legacy' with Java 1.6, then compile the rest of the files with
1164 // Java 1.8 and a reference to previously generated 1.6 classes.
1165
1166 // Compiling all classes in dirs 'legacy' with old Java version.
1167 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1168 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1169 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1170 classpath = sourceSets.main.compileClasspath
1171 sourceCompatibility = JavaVersion.VERSION_1_6
1172 targetCompatibility = JavaVersion.VERSION_1_6
1173 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1174 }
1175 // Compiling the rest of the files as Java 1.8 code.
1176 task "compile_examplesAndroidO"(type: JavaCompile) {
1177 dependsOn "compile_examplesAndroidO_Legacy"
1178 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1179 destinationDir = file("build/test/examplesAndroidO/classes")
1180 classpath = sourceSets.main.compileClasspath
1181 classpath += files("build/test/examplesAndroidOLegacy/classes")
1182 sourceCompatibility = JavaVersion.VERSION_1_8
1183 targetCompatibility = JavaVersion.VERSION_1_8
1184 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1185 }
1186 examplesDir.eachDir { dir ->
1187 def name = dir.getName();
1188 def destinationDir = file("build/test/examplesAndroidO/classes");
1189 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1190 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1191 dependsOn: "compile_examplesAndroidO") {
1192 main = name + ".TestGenerator"
1193 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1194 args destinationDir
1195 }
1196 } else {
1197 task "generate_examplesAndroidO_${name}" () {}
1198 }
1199 }
1200 examplesDir.eachDir { dir ->
1201 def name = dir.getName();
1202 def exampleOutputDir = file("build/test/examplesAndroidO");
1203 def jarName = "${name}.jar"
1204 dependsOn "jar_examplesAndroidO_${name}"
1205 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1206 "generate_examplesAndroidO_${name}"]) {
1207 archiveName = jarName
1208 destinationDir = exampleOutputDir
1209 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1210 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1211 include "**/" + name + "/**/*.class"
1212 // Do not include generator into the test runtime jar, it is not useful.
1213 // Otherwise, shrinking will need ASM jars.
1214 exclude "**/TestGenerator*"
1215 }
1216 }
1217}
1218
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001219task buildExampleAndroidPJars {
1220 dependsOn downloadDeps
1221 def examplesDir = file("src/test/examplesAndroidP")
1222
1223 task "compile_examplesAndroidP"(type: JavaCompile) {
1224 source = fileTree(dir: examplesDir, include: '**/*.java')
1225 destinationDir = file("build/test/examplesAndroidP/classes")
1226 classpath = sourceSets.main.compileClasspath
1227 sourceCompatibility = JavaVersion.VERSION_1_8
1228 targetCompatibility = JavaVersion.VERSION_1_8
1229 options.compilerArgs += ["-Xlint:-options"]
1230 }
1231 examplesDir.eachDir { dir ->
1232 def name = dir.getName();
1233 def destinationDir = file("build/test/examplesAndroidP/classes");
1234 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1235 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1236 dependsOn: "compile_examplesAndroidP") {
1237 main = name + ".TestGenerator"
1238 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1239 args destinationDir
1240 }
1241 } else {
1242 task "generate_examplesAndroidP_${name}" () {}
1243 }
1244 }
1245 examplesDir.eachDir { dir ->
1246 def name = dir.getName();
1247 def exampleOutputDir = file("build/test/examplesAndroidP");
1248 def jarName = "${name}.jar"
1249 dependsOn "jar_examplesAndroidP_${name}"
1250 task "jar_examplesAndroidP_${name}"(type: Jar,
1251 dependsOn: ["compile_examplesAndroidP",
1252 "generate_examplesAndroidP_${name}"]) {
1253 archiveName = jarName
1254 destinationDir = exampleOutputDir
1255 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1256 include "**/" + name + "/**/*.class"
1257 // Do not include generator into the test runtime jar, it is not useful.
1258 // Otherwise, shrinking will need ASM jars.
1259 exclude "**/TestGenerator*"
1260 }
1261 }
1262}
1263
Mikaël Peltier61633d42017-10-13 16:51:06 +02001264task buildExampleJava9Jars {
1265 def examplesDir = file("src/test/examplesJava9")
1266 examplesDir.eachDir { dir ->
1267 def name = dir.getName();
1268 def exampleOutputDir = file("build/test/examplesJava9");
1269 def jarName = "${name}.jar"
1270 dependsOn "jar_examplesJava9_${name}"
1271 task "jar_examplesJava9_${name}"(type: Jar) {
1272 archiveName = jarName
1273 destinationDir = exampleOutputDir
1274 from "src/test/examplesJava9" // Java 1.9 classes
1275 include "**/" + name + "/**/*.class"
1276 }
1277 }
1278}
1279
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001280task buildExamplesKotlin {
1281 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1282 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1283 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1284 } else if (!OperatingSystem.current().isLinux()) {
1285 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1286 "on your platform. It is fully supported on Linux and partially supported on " +
1287 "Mac OS and Windows")
1288 return;
1289 }
1290 def examplesDir = file("src/test/examplesKotlin")
1291 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001292 def name = dir.getName();
1293 dependsOn "dex_example_kotlin_${name}"
1294 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1295 def dexPath = file("${exampleOutputDir}")
1296 task "dex_example_kotlin_${name}"(type: dx.Dx,
1297 dependsOn: "compile_example_kotlin_${name}") {
1298 doFirst {
1299 if (!dexPath.exists()) {
1300 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001301 }
1302 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001303 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1304 destination = dexPath
1305 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001306 }
1307 }
1308}
1309
Sebastien Hertzd3313772018-01-16 14:12:37 +01001310task buildKotlinR8TestResources {
1311 def examplesDir = file("src/test/kotlinR8TestResources")
1312 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001313 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1314 def name = dir.getName()
1315 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001316 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1317 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001318 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001319 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001320 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1321 source = fileTree(dir: file("${examplesDir}/${name}"),
1322 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001323 destination = file(outputFile)
1324 targetVersion = kotlinTargetVersion
1325 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001326 task "${taskName}Java"(type: JavaCompile) {
1327 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1328 destinationDir = file(javaOutput)
1329 classpath = sourceSets.main.compileClasspath
1330 sourceCompatibility = JavaVersion.VERSION_1_6
1331 targetCompatibility = JavaVersion.VERSION_1_6
1332 options.compilerArgs += ["-g", "-Xlint:-options"]
1333 }
1334 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1335 archiveName = javaOutputJarName
1336 destinationDir = file(javaOutputJarDir)
1337 from javaOutput
1338 include "**/*.class"
1339 }
1340 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001341 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001342 }
1343}
1344
Mads Ager418d1ca2017-05-22 09:35:49 +02001345task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001346 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1347 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1348 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001349 } else if (!OperatingSystem.current().isLinux()) {
1350 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001351 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001352 return;
1353 }
1354 dependsOn buildDebugTestResourcesJars
1355 dependsOn buildExampleJars
1356 dependsOn buildExampleAndroidNJars
1357 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001358 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001359 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001360 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001361 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001362 def noDexTests = [
1363 "multidex",
1364 "multidex002",
1365 "multidex004",
1366 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001367 examplesDir.eachDir { dir ->
1368 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001369 if (!(name in noDexTests)) {
1370 dependsOn "dex_example_${name}"
1371 def exampleOutputDir = file("build/test/examples/" + name);
1372 def dexPath = file("${exampleOutputDir}")
1373 def debug = (name == "throwing")
1374 if (!dexPath.exists()) {
1375 dexPath.mkdirs()
1376 }
1377 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1378 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1379 destination = dexPath
1380 debug = debug
1381 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001382 }
1383 }
1384}
1385
1386task buildSmali {
1387 def smaliDir = file("src/test/smali")
1388 smaliDir.eachDirRecurse() { dir ->
1389 def name = dir.getName();
1390 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1391 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1392 smaliOutputDir.mkdirs()
1393 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001394 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001395 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1396 def javaFiles = fileTree(dir: dir, include: '*.java')
1397 def destDir = smaliOutputDir;
1398 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1399 def intermediateFileName = "${name}-intermediate.dex";
1400 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1401 if (javaFiles.empty) {
1402 if (!smaliFiles.empty) {
1403 dependsOn "${taskName}_smali"
1404 task "${taskName}_smali"(type: smali.Smali) {
1405 source = smaliFiles
1406 destination = destFile
1407 }
1408 }
1409 } else {
1410 dependsOn "${taskName}_dexmerger"
1411 task "${taskName}_smali"(type: smali.Smali) {
1412 source = smaliFiles
1413 destination = intermediateFile
1414 }
1415 task "${taskName}_java"(type: JavaCompile) {
1416 source = javaFiles
1417 destinationDir destDir
1418 classpath = sourceSets.main.compileClasspath
1419 sourceCompatibility = JavaVersion.VERSION_1_7
1420 targetCompatibility = JavaVersion.VERSION_1_7
1421 options.compilerArgs += ["-Xlint:-options"]
1422 }
1423 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1424 archiveName = "Test.jar"
1425 destinationDir = destDir
1426 from fileTree(dir: destDir, include: 'Test.class')
1427 }
1428 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1429 source = fileTree(dir: destDir, include: 'Test.jar')
1430 destination = destDir
1431 }
1432 task "${taskName}_dexmerger"(
1433 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1434 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1435 destination = destFile
1436 }
1437 }
1438 }
1439}
1440
1441tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001442 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001443 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1444 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1445 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind54653a62019-03-26 18:19:11 +00001446 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
Rico Windc56f21c2019-03-12 07:29:57 +01001447 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001448 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001449 if (project.hasProperty('disable_assertions')) {
1450 enableAssertions = false
1451 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001452 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1453 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001454}
1455
1456task buildPreNJdwpTestsJar(type: Jar) {
1457 baseName = 'jdwp-tests-preN'
1458 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1459 // Exclude the classes containing java8
1460 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1461 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1462 includeEmptyDirs = false
1463}
1464
Ian Zerny74143162017-11-24 13:46:35 +01001465task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1466 def inFile = buildPreNJdwpTestsJar.archivePath
1467 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001468 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001469 outputs.file outFile
1470 if (OperatingSystem.current().isWindows()) {
1471 executable file("tools/windows/dx/bin/dx.bat")
1472 } else if (OperatingSystem.current().isMacOsX()) {
1473 executable file("tools/mac/dx/bin/dx");
1474 } else {
1475 executable file("tools/linux/dx/bin/dx");
1476 }
1477 args "--dex"
1478 args "--output=${outFile}"
1479 args inFile
1480}
1481
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001482task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1483 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001484}
1485
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001486def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001487 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001488 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001489 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001490 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001491 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001492 return null
1493}
1494
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001495task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001496 dependsOn testJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001497 inputs.files files("$buildDir/libs/r8tests.jar")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001498 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001499 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001500 delete r8LibTestPath
1501 from zipTree(testJar.outputs.files[0])
1502 into r8LibTestPath
1503 include "com/android/tools/r8/**"
1504 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001505 }
1506 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001507}
1508
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001509def printStackTrace(TestResult result) {
1510 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1511 def out = new StringBuffer()
1512 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001513 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001514 def header = "RETRACED STACKTRACE";
1515 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1516 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1517 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1518 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001519 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001520 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001521 out.append("--------------------------------------\n")
1522 Process process = command.execute()
1523 def processIn = new PrintStream(process.getOut())
1524 process.consumeProcessOutput(out, err)
1525 result.exception.printStackTrace(processIn)
1526 processIn.flush()
1527 processIn.close()
1528 process.waitFor()
1529 out.append("\n\n--------------------------------------\n")
1530 out.append("OBFUSCATED STACKTRACE\n")
1531 out.append("--------------------------------------\n")
1532 result.exceptions.add(0, new Exception(out.toString()))
1533 } else {
1534 result.exception.printStackTrace()
1535 }
1536}
1537
Mads Ager418d1ca2017-05-22 09:35:49 +02001538test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001539 if (project.hasProperty('generate_golden_files_to')) {
1540 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1541 assert project.hasProperty('HEAD_sha1')
1542 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1543 }
1544
1545 if (project.hasProperty('use_golden_files_in')) {
1546 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1547 assert project.hasProperty('HEAD_sha1')
1548 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1549 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001550 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001551 // R8.jar is required for running bootstrap tests.
1552 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001553 testLogging.exceptionFormat = 'full'
1554 if (project.hasProperty('print_test_stdout')) {
1555 testLogging.showStandardStreams = true
1556 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001557 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001558 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001559 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001560 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001561
Ian Zerny324d7612019-03-20 10:52:28 +01001562 // Forward runtime configurations for test parameters.
1563 if (project.hasProperty('runtimes')) {
1564 println "NOTE: Running with runtimes: " + project.property('runtimes')
1565 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001566 }
1567
Mads Ager418d1ca2017-05-22 09:35:49 +02001568 if (project.hasProperty('one_line_per_test')) {
1569 beforeTest { desc ->
1570 println "Start executing test ${desc.name} [${desc.className}]"
1571 }
1572 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001573 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001574 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001575 }
Rico Windda6836e2018-12-07 12:32:03 +01001576 if (project.hasProperty('update_test_timestamp')) {
1577 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1578 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001579 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1580 }
Rico Windf88b6be2018-12-11 15:14:05 +01001581 } else {
1582 afterTest { desc, result ->
1583 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001584 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001585 }
1586 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001587 }
1588 if (project.hasProperty('no_internal')) {
1589 exclude "com/android/tools/r8/internal/**"
1590 }
1591 if (project.hasProperty('only_internal')) {
1592 include "com/android/tools/r8/internal/**"
1593 }
Rico Wind4e218292019-03-07 12:44:49 +01001594
Mads Ager418d1ca2017-05-22 09:35:49 +02001595 if (project.hasProperty('tool')) {
1596 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001597 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001598 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001599 if (project.hasProperty('only_jctf')) {
1600 include "com/android/tools/r8/jctf/d8/**"
1601 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001602 // Don't run anything, deprecated
1603 println "Running with deprecated tool d8, not running any tests"
1604 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001605 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001606 } else {
1607 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001608 assert(project.hasProperty('only_jctf'))
1609 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001610 }
1611 }
1612 if (!project.hasProperty('all_tests')) {
1613 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001614 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001615 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001616 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001617 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001618 if (project.hasProperty('shard_count') ) {
1619 assert project.hasProperty('shard_number')
1620 int shard_count = project.getProperty('shard_count') as Integer
1621 int shard_number = project.getProperty('shard_number') as Integer
1622 assert shard_count < 65536
1623 assert shard_number < shard_count
1624 exclude {
1625 entry ->
1626 // Don't leave out directories. Leaving out a directory means all entries below.
1627 if (entry.file.isDirectory()) {
1628 return false
1629 }
1630 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1631 int hash = Integer.parseInt(first4, 16)
1632 return hash % shard_count != shard_number
1633 }
1634 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001635 if (project.hasProperty('jctf_compile_only')) {
1636 println "JCTF: compiling only"
1637 systemProperty 'jctf_compile_only', '1'
1638 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001639 if (project.hasProperty('test_dir')) {
1640 systemProperty 'test_dir', project.property('test_dir')
1641 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001642 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1643 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001644 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1645 // all needed tests in r8LibTestPath.
1646 classpath = files([r8LibPath, r8LibTestPath]) +
1647 sourceSets.test.runtimeClasspath -
1648 sourceSets.main.output -
1649 files(['build/classes/test'])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001650 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001651 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001652 if (OperatingSystem.current().isLinux()
1653 || OperatingSystem.current().isMacOsX()
1654 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001655 if (OperatingSystem.current().isMacOsX()) {
1656 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1657 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1658 "See tools/docker/README.md for details.")
1659 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001660 if (OperatingSystem.current().isWindows()) {
1661 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1662 "Art only runs on Linux and tests requiring Art will be skipped")
1663 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001664 dependsOn downloadDeps
1665 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001666 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001667 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001668 dependsOn buildSmali
1669 dependsOn jctfCommonJar
1670 dependsOn jctfTestsClasses
1671 dependsOn buildDebugInfoExamplesDex
1672 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001673 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001674 } else {
1675 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001676 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001677 }
1678}
1679
1680// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1681//
1682// To build and upload a new set of the Art tests for use with R8 follow these steps:
1683//
1684// First of all an Android checkout is required. Currently it must be located
1685// in $HOME/android/master.
1686//
1687// TODO(ricow): simplify this
1688//
1689// Before: update the checked in art, see scripts/update-host-art.sh
1690//
1691// 1. Get an android checkout in $HOME/android/master and apply the patch from
1692// https://android-review.googlesource.com/#/c/294187/
1693//
1694// 2. run the following commands in the Android checkout directory:
1695//
1696// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001697// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1698// m desugar
1699// m -j30 test-art-host
1700// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1701//
1702// Without running the test.py command the classes.jar file used by desugar in
1703// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1704// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001705//
1706// 3. In the R8 project root directory, make sure we have a clean state before starting:
1707// tools/gradle.py downloadDeps
1708// tools/gradle.py clean
1709// rm -rf tests/art
1710//
1711// 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 +02001712// Make sure you have smali on your path, please use the build binary in the
1713// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1714// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1715// 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 +02001716// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1717// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001718//
Søren Gjesse34b77732017-07-07 13:56:21 +02001719// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001720//
1721// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1722// skippedTests with an explanation. Rerun from step 3.
1723//
1724// 5. Run the tests:
1725// tools/gradle.py clean
1726// tools/test.py
1727//
Søren Gjesse34b77732017-07-07 13:56:21 +02001728// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1729// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1730// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001731//
Søren Gjesse34b77732017-07-07 13:56:21 +02001732// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001733// cd tests
1734// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001735//
1736// 7. Update the manifest file describing the Android repo used:
1737// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001738
Mads Ager418d1ca2017-05-22 09:35:49 +02001739def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02001740
1741def artTestDir = file("${androidCheckoutDir}/art/test")
1742
1743if (project.hasProperty('android_source')) {
1744 task buildArtTests {
1745 outputs.upToDateWhen { false }
1746 def toBeTriaged = [
1747 "903-hello-tagging",
1748 "904-object-allocation",
1749 "905-object-free",
1750 "906-iterate-heap",
1751 "907-get-loaded-classes",
1752 "908-gc-start-finish",
1753 "954-invoke-polymorphic-verifier",
1754 "955-methodhandles-smali",
1755 "596-monitor-inflation",
1756 ]
1757 def skippedTests = toBeTriaged + [
1758 // This test produces no jar.
1759 "000-nop",
1760 // This does not build, as it tests the error when the application exceeds more
1761 // than 65536 methods
1762 "089-many-methods",
1763 // Requires some jack beta jar
1764 "956-methodhandles",
1765 ]
1766
1767 def skippedTestsDx = [
1768 // Tests with custom build scripts, where javac is not passed the options
1769 // -source 1.7 -target 1.7.
1770 "462-checker-inlining-across-dex-files",
1771 "556-invoke-super",
1772 "569-checker-pattern-replacement",
1773 // These tests use jack even when --build-with-javac-dx is specified.
1774 "004-JniTest",
1775 "048-reflect-v8",
1776 "146-bad-interface",
1777 "563-checker-invoke-super",
1778 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1779 "604-hot-static-interface",
1780 "957-methodhandle-transforms",
1781 "958-methodhandle-emulated-stackframe",
1782 "959-invoke-polymorphic-accessors",
1783 "961-default-iface-resolution-gen",
1784 "962-iface-static",
1785 "963-default-range-smali",
1786 "964-default-iface-init-gen",
1787 "965-default-verify",
1788 "966-default-conflict",
1789 "967-default-ame",
1790 "968-default-partial-compile-gen",
1791 "969-iface-super",
1792 "970-iface-super-resolution-gen",
1793 "971-iface-super",
1794 // These tests does not build with --build-with-javac-dx
1795 "004-NativeAllocations", // Javac error
1796 "031-class-attributes",
1797 "138-duplicate-classes-check",
1798 "157-void-class", // Javac error
1799 "580-checker-string-factory-intrinsics",
1800 "612-jit-dex-cache",
1801 "613-inlining-dex-cache",
1802 "900-hello-plugin", // --experimental agents
1803 "901-hello-ti-agent", // --experimental agents
1804 "902-hello-transformation", // --experimental agents
1805 "909-attach-agent", // --experimental agents
1806 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1807 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1808 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1809 "960-default-smali", // --experimental default-methods
1810 // These tests force the build to use jack
1811 "953-invoke-polymorphic-compiler",
1812 "958-methodhandle-stackframe",
1813 ]
1814
1815 def artTestBuildDir = file("${projectDir}/tests/art")
1816
1817 if (androidCheckoutDir.exists()) {
1818 dependsOn downloadDeps
1819 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02001820 artTestDir.eachDir { dir ->
1821 def name = dir.getName();
1822 def markerFile = dir.toPath().resolve("info.txt").toFile();
1823 if (markerFile.exists() && !(name in skippedTests)) {
1824 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01001825 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02001826 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001827 }
1828 }
1829 }
1830 doFirst {
1831 if (!androidCheckoutDir.exists()) {
1832 throw new InvalidUserDataException(
1833 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02001834 }
1835 }
1836 doLast {
1837 copy {
1838 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1839 into file("${artTestBuildDir}/lib64")
1840 include 'lib*.so'
1841 }
1842 copy {
1843 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1844 into file("${artTestBuildDir}/lib64")
1845 include 'libart.so'
1846 include 'libbacktrace.so'
1847 include 'libbase.so'
1848 include 'libc++.so'
1849 include 'libcutils.so'
1850 include 'liblz4.so'
1851 include 'liblzma.so'
1852 include 'libnativebridge.so'
1853 include 'libnativeloader.so'
1854 include 'libsigchain.so'
1855 include 'libunwind.so'
1856 include 'libziparchive.so'
1857 }
1858 copy {
1859 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1860 into file("${artTestBuildDir}/lib")
1861 include 'lib*.so'
1862 }
1863 copy {
1864 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1865 into file("${artTestBuildDir}/lib")
1866 include 'libart.so'
1867 include 'libbacktrace.so'
1868 include 'libbase.so'
1869 include 'libc++.so'
1870 include 'libcutils.so'
1871 include 'liblz4.so'
1872 include 'liblzma.so'
1873 include 'libnativebridge.so'
1874 include 'libnativeloader.so'
1875 include 'libsigchain.so'
1876 include 'libunwind.so'
1877 include 'libziparchive.so'
1878 }
1879 }
1880 }
1881}
1882
Rico Windde2af6c2019-03-26 15:21:08 +01001883def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001884 def artTestDir = file("${androidCheckoutDir}/art/test")
1885 def artRunTestScript = file("${artTestDir}/run-test")
1886 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001887 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001888
Søren Gjesse34b77732017-07-07 13:56:21 +02001889 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01001890 def buildTask = "build_art_test_dx_${name}"
1891 def sanitizeTask = "sanitize_art_test_dx_${name}"
1892 def copyCheckTask = "copy_check_art_test_dx_${name}"
1893 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001894
1895 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01001896 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001897 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1898 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01001899 task "$buildTask"(type: Exec) {
1900 outputs.upToDateWhen { false }
1901 inputs.file buildInputs
1902 executable "${artRunTestScript}"
1903 args "--host"
1904 args "--build-only"
1905 args "--build-with-javac-dx"
1906 args "--output-path", "${testDir}"
1907 args "${name}"
1908 environment DX: "${dxExecutable.absolutePath}"
1909 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1910 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1911 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02001912 }
1913 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1914 outputs.upToDateWhen { false }
1915 executable "/bin/bash"
1916 args "-c"
1917 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1918 " ${testDir}/classes-ex ${testDir}/check"
1919 }
1920
1921 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001922 // Directory that contains smali files is either smali, or smali/art
1923 def smali_dir = file("${dir}/smali/art")
1924 if (smali_dir.exists()) {
1925 workingDir "${testDir}/smali/art"
1926 } else {
1927 workingDir "${testDir}/smali"
1928 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001929 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001930 // This is the command line options for smali prior to 2.2.1, where smali got a new
1931 // command line interface.
1932 args "-c", "smali a *.smali"
1933 // This is the command line options for smali 2.2.1 and later.
1934 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001935 }
1936
1937 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1938 def smali_dir = file("${dir}/smali")
1939 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01001940 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001941 dependsOn smaliToDexTask
1942 }
1943 from("${artTestDir}/${name}") {
1944 include 'check'
1945 }
1946 into testDir
1947 }
1948
1949 return copyCheckTask
1950}
1951
1952task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001953 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001954 classpath = sourceSets.main.compileClasspath
1955 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001956 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001957 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001958 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001959 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001960 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001961 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001962 include '**/com/android/tools/r8/CompilationMode.java'
1963 include '**/com/android/tools/r8/D8.java'
1964 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001965 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1966 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001967 include '**/com/android/tools/r8/Diagnostic.java'
1968 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001969 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1970 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001971 include '**/com/android/tools/r8/ProgramConsumer.java'
1972 include '**/com/android/tools/r8/ProgramResource.java'
1973 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001974 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001975 include '**/com/android/tools/r8/ResourceException.java'
1976 include '**/com/android/tools/r8/StringConsumer.java'
1977 include '**/com/android/tools/r8/StringResource.java'
1978 include '**/com/android/tools/r8/Version.java'
1979 include '**/com/android/tools/r8/origin/*.java'
1980}
1981
1982task javadocR8(type: Javadoc) {
1983 title "R8 API"
1984 classpath = sourceSets.main.compileClasspath
1985 source = sourceSets.main.allJava
1986 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
1987 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
1988 include '**/com/android/tools/r8/BaseCommand.java'
1989 include '**/com/android/tools/r8/BaseCompilerCommand.java'
1990 include '**/com/android/tools/r8/ClassFileConsumer.java'
1991 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
1992 include '**/com/android/tools/r8/CompilationFailedException.java'
1993 include '**/com/android/tools/r8/CompilationMode.java'
1994 include '**/com/android/tools/r8/R8.java'
1995 include '**/com/android/tools/r8/R8Command.java'
1996 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1997 include '**/com/android/tools/r8/Diagnostic.java'
1998 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001999 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2000 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002001 include '**/com/android/tools/r8/ProgramConsumer.java'
2002 include '**/com/android/tools/r8/ProgramResource.java'
2003 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2004 include '**/com/android/tools/r8/Resource.java'
2005 include '**/com/android/tools/r8/ResourceException.java'
2006 include '**/com/android/tools/r8/StringConsumer.java'
2007 include '**/com/android/tools/r8/StringResource.java'
2008 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002009 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002010}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002011
2012task copyMavenDeps(type: Copy) {
2013 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002014 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002015 from configurations.testCompile into "$buildDir/deps"
2016}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002017
Rico Wind23a05112019-03-27 08:00:44 +01002018task printMavenDeps {
2019 // Only actually print to stdout when we are updating.
2020 if (project.hasProperty('updatemavendeps')) {
2021 for (Configuration config : configurations) {
2022 if (!config.isCanBeResolved()) {
2023 continue
2024 }
2025 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2026 it.selected.id
2027 }
2028 def result = dependencies.createArtifactResolutionQuery()
2029 .forComponents(componentIds)
2030 .withArtifacts(MavenModule, MavenPomArtifact)
2031 .execute()
2032 for (component in result.resolvedComponents) {
2033 component.getArtifacts(MavenPomArtifact).each {
2034 println "POM: ${it.file} ${component.id}"
2035 }
2036 }
2037 config.each {
2038 println "JAR: ${it}"
2039 }
2040 }
2041 }
2042}
2043
2044
2045
2046
Mikaël Peltier61633d42017-10-13 16:51:06 +02002047// This task allows to build class files from Java 9 source in order to use them as inputs of
2048// D8/R8 tests. Class files are generated in the same place than source files and must be commited
2049// to the D8 repository because there is no way to generate them on all computers due to the need of
2050// Java 9.
2051// Use the following command to rebuild class files of tests:
2052// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
2053task buildJava9Tests {
2054 def javacOutputFolder = getTemporaryDir();
2055 def examplesDir = file("src/test/examplesJava9")
2056
2057 task "compile_Java9examples"(type: JavaCompile) {
2058 doFirst {
2059 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
2060 throw new GradleException("Set java9Home property.")
2061 }
2062 }
2063
2064 source = fileTree(dir: examplesDir, include: '**/*.java')
2065 destinationDir = javacOutputFolder
2066 classpath = sourceSets.main.compileClasspath
2067 options.compilerArgs += ["-Xlint:-options"]
2068 sourceCompatibility = JavaVersion.VERSION_1_9
2069 targetCompatibility = JavaVersion.VERSION_1_9
2070 options.fork = true
2071
2072 if (project.hasProperty('java9Home')) {
2073 options.forkOptions.javaHome = file(getProperty('java9Home'))
2074 }
2075
2076 doLast {
2077 def classfileFrom = copySpec {
2078 from javacOutputFolder
2079 include "**/*.class"
2080 }
2081 copy {
2082 into examplesDir
2083 with classfileFrom
2084 }
2085 delete javacOutputFolder
2086 }
2087 }
2088
2089 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02002090}