blob: f4923197413519571ed5d69d37d39943910bc91c [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 {
14 mavenCentral()
15 jcenter()
16 maven {
17 url "https://plugins.gradle.org/m2/"
18 }
19 }
20 dependencies {
21 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
22 }
23}
24
25plugins {
26 id "net.ltgt.errorprone" version "0.7"
27}
28
29apply plugin: 'java'
30apply plugin: 'idea'
31
Sebastien Hertz143ed112018-02-13 14:26:41 +010032ext {
33 androidSupportVersion = '25.4.0'
Gautam Korlam39d74202018-08-29 18:09:35 -070034 asmVersion = '6.2.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010035 espressoVersion = '3.0.0'
36 fastutilVersion = '7.2.0'
37 guavaVersion = '23.0'
38 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020039 gsonVersion = '2.7'
Sebastien Hertz143ed112018-02-13 14:26:41 +010040 junitVersion = '4.12'
Jinseong Jeone11145f2018-12-13 10:57:29 -080041 mockitoVersion = '2.10.0'
Jinseong Jeon46146f42018-12-16 23:26:14 -080042 kotlinVersion = '1.3.11'
Jinseong Jeonb6fe4fe2018-12-03 00:49:13 -080043 kotlinExtMetadataJVMVersion = '0.0.4'
Sebastien Hertz143ed112018-02-13 14:26:41 +010044 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010045 errorproneVersion = '2.3.2'
Sebastien Hertz143ed112018-02-13 14:26:41 +010046}
47
Mads Ager418d1ca2017-05-22 09:35:49 +020048apply from: 'copyAdditionalJctfCommonFiles.gradle'
49
50repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020051 maven { url 'https://maven.google.com' }
Jinseong Jeon515e7582018-06-15 21:50:31 +000052 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020053 mavenCentral()
54}
55
Jinseong Jeon05064e12018-07-03 00:21:12 -070056if (project.hasProperty('with_code_coverage')) {
57 apply plugin: 'jacoco'
58}
59
Mads Ager418d1ca2017-05-22 09:35:49 +020060// Custom source set for example tests and generated tests.
61sourceSets {
62 test {
63 java {
64 srcDirs = [
65 'src/test/java',
66 'build/generated/test/java',
67 ]
68 }
69 }
Yohann Rousselbb571622017-11-09 10:47:36 +010070 apiUsageSample {
71 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020072 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
73 include 'com/android/tools/apiusagesample/*.java'
74 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
75 include 'com/android/tools/r8/D8CommandParser.java'
76 include 'com/android/tools/r8/R8CommandParser.java'
77 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010078 }
Yohann Rousselbb571622017-11-09 10:47:36 +010079 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010080 cfSegments {
81 java {
82 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
83 }
84 output.resourcesDir = 'build/classes/cfSegments'
85 }
86 classlib {
87 java {
88 srcDirs = [
89 'third_party/classlib/java',
90 ]
91 }
92 output.resourcesDir = 'build/classes/classlib'
93 }
Mads Ager418d1ca2017-05-22 09:35:49 +020094 debugTestResources {
95 java {
96 srcDirs = ['src/test/debugTestResources']
97 }
98 output.resourcesDir = 'build/classes/debugTestResources'
99 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200100 debugTestResourcesJava8 {
101 java {
102 srcDirs = ['src/test/debugTestResourcesJava8']
103 }
104 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
105 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200106 debugTestResourcesKotlin {
107 java {
108 srcDirs = ['src/test/debugTestResourcesKotlin']
109 }
110 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
111 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200112 examples {
113 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800114 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200115 }
116 output.resourcesDir = 'build/classes/examples'
117 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100118 examplesKotlin {
119 java {
120 srcDirs = ['src/test/examplesKotlin']
121 }
122 output.resourcesDir = 'build/classes/examplesKotlin'
123 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200124 examplesAndroidN {
125 java {
126 srcDirs = ['src/test/examplesAndroidN']
127 }
128 output.resourcesDir = 'build/classes/examplesAndroidN'
129 }
130 examplesAndroidO {
131 java {
132 srcDirs = ['src/test/examplesAndroidO']
133 }
134 output.resourcesDir = 'build/classes/examplesAndroidO'
135 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200136 examplesAndroidP {
137 java {
138 srcDirs = ['src/test/examplesAndroidP']
139 }
140 output.resourcesDir = 'build/classes/examplesAndroidP'
141 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200142 jctfCommon {
143 java {
144 srcDirs = [
145 'third_party/jctf/Harness/src',
146 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
147 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
148 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
149 'third_party/jctf/LibTests/src/org',
150 'build/additionalJctfCommonFiles'
151 ]
152 }
153 resources {
154 srcDirs = ['third_party/jctf/LibTests/resources']
155 }
156 }
157 jctfTests {
158 java {
159 srcDirs = [
160 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
161 // 'third_party/jctf/VMTests/src',
162 ]
163 }
164 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100165 kotlinR8TestResources {
166 java {
167 srcDirs = ['src/test/kotlinR8TestResources']
168 }
169 output.resourcesDir = 'build/classes/kotlinR8TestResources'
170 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200171}
172
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800173// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
174// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
175// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
176// for context.
177idea {
178 sourceSets.all { SourceSet sources ->
179 module {
180 if (sources.name == "main") {
181 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100182 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800183 } else {
184 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100185 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800186 }
187 }
188 }
189}
190
Yohann Roussel126f6872017-08-03 16:25:32 +0200191configurations {
192 supportLibs
193}
194
Mads Ager418d1ca2017-05-22 09:35:49 +0200195dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100196 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
197 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200198 // Include all of guava when compiling the code, but exclude annotations that we don't
199 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100200 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100201 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200202 exclude group: 'com.google.errorprone'
203 exclude group: 'com.google.code.findbugs'
204 exclude group: 'com.google.j2objc'
205 exclude group: 'org.codehaus.mojo'
206 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100207 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
208 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
209 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
210 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
211 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
212 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
213 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200214 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100215 testCompile "junit:junit:$junitVersion"
216 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200217 testCompile files('third_party/jasmin/jasmin-2.4.jar')
218 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200219 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100220 jctfCommonCompile "junit:junit:$junitVersion"
221 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200222 jctfTestsCompile sourceSets.jctfCommon.output
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100223 cfSegmentsCompile sourceSets.classlib.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100224 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
225 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200226 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100227 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800228 examplesCompile "junit:junit:$junitVersion"
229 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100230 supportLibs "com.android.support:support-v4:$androidSupportVersion"
231 supportLibs "junit:junit:$junitVersion"
232 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100233 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100234 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100235 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
236 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
237 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100238 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200239}
240
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100241def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100242def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100243def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100244def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100245def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100246
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200247def osString = OperatingSystem.current().isLinux() ? "linux" :
248 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200249
250def cloudDependencies = [
251 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200252 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100253 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200254 ],
255 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200256 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200257 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100258 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200259 "android_jar/lib-v19",
260 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100261 "android_jar/lib-v22",
262 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200263 "android_jar/lib-v24",
264 "android_jar/lib-v25",
265 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100266 "android_jar/lib-v27",
267 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200268 "core-lambda-stubs",
269 "dart-sdk",
270 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200271 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200272 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200273 "jasmin",
274 "jctf",
Rico Windf72fa152018-10-22 15:41:03 +0200275 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200276 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100277 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200278 "proguard/proguard5.2.1",
279 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200280 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200281 ],
282 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
283 // container on other platforms where supported.
284 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200285 "linux/art",
286 "linux/art-5.1.1",
287 "linux/art-6.0.1",
288 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100289 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100290 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200291 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100292 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200293 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200294 ]
295]
296
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100297def cloudSystemDependencies = [
298 linux: [
299 "third_party": ["openjdk/openjdk-9.0.4/linux"],
300 ],
301 osx: [
302 "third_party": ["openjdk/openjdk-9.0.4/osx"],
303 ],
304 windows: [
305 "third_party": ["openjdk/openjdk-9.0.4/windows"],
306 ],
307]
308
309if (OperatingSystem.current().isWindows()) {
310 cloudSystemDependencies.windows.each { entry ->
311 cloudDependencies.get(entry.key).addAll(entry.value)
312 }
313} else if (OperatingSystem.current().isLinux()) {
314 cloudSystemDependencies.linux.each { entry ->
315 cloudDependencies.get(entry.key).addAll(entry.value)
316 }
317} else if (OperatingSystem.current().isMacOsX()) {
318 cloudSystemDependencies.osx.each { entry ->
319 cloudDependencies.get(entry.key).addAll(entry.value)
320 }
321} else {
322 println "WARNING: Unsupported system: " + OperatingSystem.current()
323}
324
325def getDownloadDepsTaskName(entryKey, entryFile) {
326 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
327}
328
Ian Zernyb2d27c42019-02-20 09:09:41 +0100329def getFetchDepsTaskName(entryKey, entryFile) {
330 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
331}
332
Mads Ager418d1ca2017-05-22 09:35:49 +0200333cloudDependencies.each { entry ->
334 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100335 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
336 type DownloadDependency.Type.GOOGLE_STORAGE
337 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200338 }
339 }
340}
341
342def x20Dependencies = [
343 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200344 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200345 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100346 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100347 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200348 "desugar/desugar_20180308",
349 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200350 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200351 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200352 "gmscore/gmscore_v10",
353 "gmscore/gmscore_v9",
354 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200355 "gmscore/v4",
356 "gmscore/v5",
357 "gmscore/v6",
358 "gmscore/v7",
359 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200360 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200361 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200362 "proguard/proguard_internal_159423826",
363 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200364 "youtube/youtube.android_12.10",
365 "youtube/youtube.android_12.17",
366 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200367 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200368 ],
369]
370
371x20Dependencies.each { entry ->
372 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100373 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
374 type DownloadDependency.Type.X20
375 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200376 }
377 }
378}
379
Rico Wind897bb712017-05-23 10:44:29 +0200380task downloadProguard {
381 cloudDependencies.each { entry ->
382 entry.value.each { entryFile ->
383 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100384 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200385 }
386 }
387 }
388}
389
Rico Windf6c74ce2018-12-04 08:50:55 +0100390task downloadOpenJDKrt {
391 cloudDependencies.each { entry ->
392 entry.value.each { entryFile ->
393 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100394 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100395 }
396 }
397 }
398}
399
Tamas Kenez427205b2017-06-29 15:57:09 +0200400task downloadDx {
401 cloudDependencies.each { entry ->
402 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200403 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100404 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200405 }
406 }
407 }
408}
409
Tamas Kenez0e10c562017-06-08 10:00:34 +0200410task downloadAndroidCts {
411 cloudDependencies.each { entry ->
412 entry.value.each { entryFile ->
413 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100414 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200415 }
416 }
417 }
418}
419
Mads Ager418d1ca2017-05-22 09:35:49 +0200420task downloadDeps {
421 cloudDependencies.each { entry ->
422 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100423 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200424 }
425 }
426 if (!project.hasProperty('no_internal')) {
427 x20Dependencies.each { entry ->
428 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100429 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200430 }
431 }
432 }
433}
434
435allprojects {
436 sourceCompatibility = JavaVersion.VERSION_1_8
437 targetCompatibility = JavaVersion.VERSION_1_8
438}
439
Rico Wind266336c2019-02-25 10:11:38 +0100440// TODO(ricow): Remove debug prints
441println("NOTE: Current operating system: " + OperatingSystem.current())
442println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
443
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100444// Check if running with the JDK location from tools/jdk.py.
445if (OperatingSystem.current().isWindows()) {
446 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
447} else {
448 def javaHomeOut = new StringBuilder()
449 def javaHomeErr = new StringBuilder()
450 def javaHomeProc = './tools/jdk.py'.execute()
451 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
452 def jdkHome = new File(javaHomeOut.toString().trim())
453 if (!jdkHome.exists()) {
454 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
455 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
456 println("WARNING: Gradle is running in a non-pinned Java"
457 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
458 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100459 } else {
460 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100461 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200462}
463
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100464sourceSets.configureEach { sourceSet ->
465 tasks.named(sourceSet.compileJavaTaskName).configure {
466 // Default disable errorprone (enabled and setup below).
467 options.errorprone.enabled = false
468 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100469 // Run all compilation tasks in a forked subprocess.
470 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100471 // Javac often runs out of stack space when compiling the tests.
472 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100473 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100474 // Test compilation is sometimes hitting the default limit at 1g, increase it.
475 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100476 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
477 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
478 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200479}
480
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100481if (!project.hasProperty('without_error_prone') &&
482 // Don't enable error prone on Java 8 as the plugin setup does not support it.
483 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200484 compileJava {
485 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100486 options.errorprone.enabled = true
487 options.errorprone.disableAllChecks = true
488 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
489 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
490 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
491 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
492 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
493 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
494 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
495 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
496 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
497 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
498 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
499 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
500 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
501 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
502 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
503 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
504 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
505 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
506 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200507 }
508}
509
Mads Ager418d1ca2017-05-22 09:35:49 +0200510compileJctfCommonJava {
511 dependsOn 'copyAdditionalJctfCommonFiles'
512 options.compilerArgs = ['-Xlint:none']
513}
514
515compileJctfTestsJava {
516 dependsOn 'jctfCommonClasses'
517 options.compilerArgs = ['-Xlint:none']
518}
519
Yohann Roussel7f47c032017-09-14 12:19:06 +0200520task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200521 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100522
Yohann Roussel7f47c032017-09-14 12:19:06 +0200523 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100524 def runtimeClasspath = configurations.findByName("runtimeClasspath")
525 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
526
Yohann Roussel7f47c032017-09-14 12:19:06 +0200527 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100528
Yohann Roussel7f47c032017-09-14 12:19:06 +0200529 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100530 def dependencies = []
531 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
532 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
533 dependencies.add("${identifier.group}:${identifier.module}")
534 }
535 def libraryLicenses = file('LIBRARY-LICENSE').text
536 dependencies.each {
537 if (!libraryLicenses.contains("- artifact: $it")) {
538 throw new GradleException("No license for $it in LIBRARY_LICENSE")
539 }
540 }
541
Yohann Roussel7f47c032017-09-14 12:19:06 +0200542 license.getParentFile().mkdirs()
543 license.createNewFile()
544 license.text = "This file lists all licenses for code distributed.\n"
545 license.text += "All non-library code has the following 3-Clause BSD license.\n"
546 license.text += "\n"
547 license.text += "\n"
548 license.text += file('LICENSE').text
549 license.text += "\n"
550 license.text += "\n"
551 license.text += "Summary of distributed libraries:\n"
552 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100553 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200554 license.text += "\n"
555 license.text += "\n"
556 license.text += "Licenses details:\n"
557 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
558 license.text += "\n"
559 license.text += "\n"
560 license.text += file.text
561 }
562 }
563}
564
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200565static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700566 // Everything under META-INF is not included by default.
567 // Should include before 'relocate' so that the service file path and its content
568 // are properly relocated as well.
569 task.mergeServiceFiles {
570 include 'META-INF/services/*'
571 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200572}
573
574static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000575 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200576 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000577 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
578 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000579 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000580 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200581 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
582 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
583 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200584 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000585}
586
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100587task repackageDepsNoRelocate(type: ShadowJar) {
588 configurations = [project.configurations.runtimeClasspath]
589 mergeServiceFiles(it)
590 exclude { it.getRelativePath().getPathString() == "module-info.class" }
591 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100592 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100593}
594
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000595task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100596 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200597 mergeServiceFiles(it)
598 if (!project.hasProperty('lib_no_relocate')) {
599 configureRelocations(it)
600 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100601 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700602 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000603 baseName 'deps'
604}
605
606task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200607 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200608 mergeServiceFiles(it)
609 if (!project.hasProperty('lib_no_relocate')) {
610 configureRelocations(it)
611 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000612 baseName 'sources'
613}
614
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100615task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200616 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100617 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200618 classifier = null
619 version = null
620 manifest {
621 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
622 }
623 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100624 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100625 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100626 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200627}
628
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100629task r8WithoutDeps(type: ShadowJar) {
630 from consolidatedLicense.outputs.files
631 baseName 'r8_without_deps'
632 classifier = null
633 version = null
634 manifest {
635 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
636 }
637 from sourceSets.main.output
638}
639
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000640task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200641 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200642 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200643 classifier = null
644 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200645 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200646 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200647 }
648 // In order to build without dependencies, pass the exclude_deps property using:
649 // gradle -Pexclude_deps R8
650 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800651 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000652 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800653 } else {
654 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200655 }
Ian Zerny80533c92019-01-24 10:32:09 +0100656 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200657}
658
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100659task R8NoManifestNoDeps(type: ShadowJar) {
660 from consolidatedLicense.outputs.files
661 baseName 'r8nomanifest-exclude-deps'
662 classifier = null
663 version = null
664 from sourceSets.main.output
665}
666
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100667task R8NoManifest(type: ShadowJar) {
668 from consolidatedLicense.outputs.files
669 baseName 'r8nomanifest'
670 classifier = null
671 version = null
672 // In order to build without dependencies, pass the exclude_deps property using:
673 // gradle -Pexclude_deps R8
674 if (!project.hasProperty('exclude_deps')) {
675 from repackageSources.outputs.files
676 from repackageDeps.outputs.files
677 } else {
678 from sourceSets.main.output
679 }
Ian Zerny80533c92019-01-24 10:32:09 +0100680 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100681}
682
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000683task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200684 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200685 baseName 'd8'
686 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200687 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200688 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200689}
690
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200691task CompatDx(type: ShadowJar) {
692 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200693 baseName 'compatdx'
694 manifest {
695 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
696 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200697}
698
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200699task CompatProguard(type: ShadowJar) {
700 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200701 baseName 'compatproguard'
702 manifest {
703 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
704 }
Lars Bak44cef522017-08-10 16:02:39 +0200705}
706
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100707def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100708 // Execute r8 commands against a stable r8 with relocated dependencies.
Rico Windcfb65512019-02-27 12:57:34 +0100709 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
710 "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100711}
712
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100713def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100714 return baseR8CommandLine([
715 "--classfile", "--release",
716 input,
717 "--output", output,
718 "--pg-conf", pgconf,
719 "--pg-map-output", output + ".map",
720 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
721 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100722}
723
724def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
725 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100726 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100727 outputs.file output
728 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100729 dependsOn r8WithRelocatedDeps
730 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100731 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
732 workingDir = projectDir
733 }
734}
735
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100736task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100737 baseName = "r8tests"
738 from sourceSets.test.output
739}
740
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100741task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
742 baseName = "r8tests-exclude-deps"
743 from sourceSets.test.output
744}
745
746def generateR8LibKeepRules(name, r8Source, testSource, output) {
747 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
748 doFirst {
749 standardOutput new FileOutputStream(output)
750 }
751 dependsOn r8WithRelocatedDeps
752 dependsOn r8Source
753 dependsOn testSource
754 dependsOn downloadOpenJDKrt
755 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
756 outputs.file output
757 commandLine baseR8CommandLine([
758 "printuses",
759 "--keeprules",
760 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
761 r8Source.outputs.files[0],
762 testSource.outputs.files[0]])
763 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100764 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100765}
766
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100767task R8LibApiOnly {
768 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
769 outputs.file r8LibPath
770}
771
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100772task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100773 def genRulesTask = generateR8LibKeepRules(
774 "Main",
775 R8NoManifest,
776 testJar,
777 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100778 dependsOn r8LibCreateTask(
779 "Main",
780 "src/main/keep.txt",
781 R8NoManifest,
782 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100783 ["--pg-conf", genRulesTask.outputs.files[0]]
784 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100785 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100786}
787
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100788task R8LibNoDeps {
789 def genRulesTask = generateR8LibKeepRules(
790 "NoDeps",
791 R8NoManifestNoDeps,
792 testJarNoDeps,
793 r8LibGeneratedKeepRulesExcludeDepsPath
794 )
795 dependsOn r8LibCreateTask(
796 "NoDeps",
797 "src/main/keep.txt",
798 R8NoManifestNoDeps,
799 r8LibExludeDepsPath,
800 ["--pg-conf", genRulesTask.outputs.files[0]],
801 repackageDepsNoRelocate.outputs.files
802 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
803 outputs.file r8LibExludeDepsPath
804}
805
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100806task CompatDxLib {
807 dependsOn r8LibCreateTask(
808 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100809}
810
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100811task CompatProguardLib {
812 dependsOn r8LibCreateTask(
813 "CompatPg",
814 "src/main/keep-compatproguard.txt",
815 CompatProguard,
816 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100817}
818
Mads Ager418d1ca2017-05-22 09:35:49 +0200819task sourceJar(type: Jar, dependsOn: classes) {
820 classifier = 'src'
821 from sourceSets.main.allSource
822}
823
824task jctfCommonJar(type: Jar) {
825 from sourceSets.jctfCommon.output
826 baseName 'jctfCommon'
827}
828
829artifacts {
830 archives sourceJar
831}
832
833task createArtTests(type: Exec) {
834 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200835 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100836 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200837 outputs.dir outputDir
838 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200839 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200840 workingDir = projectDir
841}
842
843task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200844 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200845 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200846 inputs.file script
847 outputs.dir outputDir
848 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200849 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200850 workingDir = projectDir
851}
852
853compileTestJava {
854 dependsOn createArtTests
855 dependsOn createJctfTests
856}
857
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100858task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
859 from sourceSets.cfSegments.output
860 baseName 'cf_segments'
861 destinationDir file('build/libs')
862}
863
Ian Zernyee23a172018-01-03 09:08:48 +0100864task buildD8ApiUsageSample(type: Jar) {
865 from sourceSets.apiUsageSample.output
866 baseName 'd8_api_usage_sample'
867 destinationDir file('tests')
868}
869
Ian Zerny923a0c12018-01-03 10:59:18 +0100870task buildR8ApiUsageSample(type: Jar) {
871 from sourceSets.apiUsageSample.output
872 baseName 'r8_api_usage_sample'
873 destinationDir file('tests')
874}
875
Yohann Roussel548ae942018-01-05 11:13:28 +0100876task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100877 dependsOn buildD8ApiUsageSample
878 dependsOn buildR8ApiUsageSample
879}
880
Mads Ager418d1ca2017-05-22 09:35:49 +0200881task buildDebugInfoExamplesDex {
882 def examplesDir = file("src/test/java")
883 def hostJar = "debuginfo_examples.jar"
884 def hostDexJar = "debuginfo_examples_dex.jar"
885 task "compile_debuginfo_examples"(type: JavaCompile) {
886 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
887 destinationDir = file("build/test/debuginfo_examples/classes")
888 classpath = sourceSets.main.compileClasspath
889 sourceCompatibility = JavaVersion.VERSION_1_7
890 targetCompatibility = JavaVersion.VERSION_1_7
891 options.compilerArgs += ["-Xlint:-options"]
892 }
893 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
894 archiveName = hostJar
895 destinationDir = file("build/test/")
896 from "build/test/debuginfo_examples/classes"
897 include "**/*.class"
898 }
899 task "dex_debuginfo_examples"(type: Exec,
900 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200901 if (OperatingSystem.current().isWindows()) {
902 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700903 } else if (OperatingSystem.current().isMacOsX()) {
904 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200905 } else {
906 executable file("tools/linux/dx/bin/dx");
907 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200908 args "--dex"
909 args "--output=build/test/${hostDexJar}"
910 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100911 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200912 outputs.file file("build/test/${hostDexJar}")
913 }
914 dependsOn dex_debuginfo_examples
915}
916
917task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200918 def resourcesDir = file("src/test/debugTestResources")
919 def hostJar = "debug_test_resources.jar"
920 task "compile_debugTestResources"(type: JavaCompile) {
921 source = fileTree(dir: resourcesDir, include: '**/*.java')
922 destinationDir = file("build/test/debugTestResources/classes")
923 classpath = sourceSets.main.compileClasspath
924 sourceCompatibility = JavaVersion.VERSION_1_7
925 targetCompatibility = JavaVersion.VERSION_1_7
926 options.compilerArgs += ["-g", "-Xlint:-options"]
927 }
928 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
929 archiveName = hostJar
930 destinationDir = file("build/test/")
931 from "build/test/debugTestResources/classes"
932 include "**/*.class"
933 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200934 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
935 def java8HostJar = "debug_test_resources_java8.jar"
936 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
937 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
938 destinationDir = file("build/test/debugTestResourcesJava8/classes")
939 classpath = sourceSets.main.compileClasspath
940 sourceCompatibility = JavaVersion.VERSION_1_8
941 targetCompatibility = JavaVersion.VERSION_1_8
942 options.compilerArgs += ["-g", "-Xlint:-options"]
943 }
944 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
945 archiveName = java8HostJar
946 destinationDir = file("build/test/")
947 from "build/test/debugTestResourcesJava8/classes"
948 include "**/*.class"
949 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200950 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000951 def kotlinHostJar = "debug_test_resources_kotlin.jar"
952 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
953 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
954 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200955 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200956 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200957 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200958 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000959 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200960}
961
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100962// Examples used by tests, where Android specific APIs are used.
963task buildExampleAndroidApi(type: JavaCompile) {
964 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
965 destinationDir = file("build/test/examplesAndroidApi/classes")
966 classpath = files("third_party/android_jar/lib-v26/android.jar")
967 sourceCompatibility = JavaVersion.VERSION_1_8
968 targetCompatibility = JavaVersion.VERSION_1_8
969}
970
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100971task buildExampleKotlinJars {
972 def kotlinSrcDir = file("src/test/examplesKotlin")
973 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000974 def name = dir.getName();
975 dependsOn "compile_example_kotlin_${name}"
976 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
977 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
978 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100979 }
980 }
981}
982
Lars Bakc91e87e2017-08-18 08:53:10 +0200983// Proto lite generated code yields warnings when compiling with javac.
984// We change the options passed to javac to ignore it.
985compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
986
Søren Gjesse7320ce52018-05-07 15:45:22 +0200987
Mads Ager418d1ca2017-05-22 09:35:49 +0200988task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200989 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200990 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200991 def proguardScript
992 if (OperatingSystem.current().isWindows()) {
993 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
994 } else {
995 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
996 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200997 task extractExamplesRuntime(type: Sync) {
998 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000999 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001000 include "**/*.class"
1001 includeEmptyDirs false
1002 into "$buildDir/runtime/examples/"
1003 }
1004
Søren Gjesse7320ce52018-05-07 15:45:22 +02001005 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1006 from examplesDir
1007 exclude "**/*.java"
1008 exclude "**/keep-rules*.txt"
1009 into file("build/test/examples/classes")
1010 }
1011
1012 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001013 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001014 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001015 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001016 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001017 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001018 sourceCompatibility = JavaVersion.VERSION_1_7
1019 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001020 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1021 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001022 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1023 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001024 include "**/*.java"
1025 destinationDir = file("build/test/examples/classes_debuginfo_all")
1026 classpath = sourceSets.examples.compileClasspath
1027 sourceCompatibility = JavaVersion.VERSION_1_7
1028 targetCompatibility = JavaVersion.VERSION_1_7
1029 options.compilerArgs = ["-g", "-Xlint:none"]
1030 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001031 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1032 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001033 include "**/*.java"
1034 destinationDir = file("build/test/examples/classes_debuginfo_none")
1035 classpath = sourceSets.examples.compileClasspath
1036 sourceCompatibility = JavaVersion.VERSION_1_7
1037 targetCompatibility = JavaVersion.VERSION_1_7
1038 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001039 }
1040 examplesDir.eachDir { dir ->
1041 def name = dir.getName();
1042 def exampleOutputDir = file("build/test/examples");
1043 def jarName = "${name}.jar"
1044 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001045 dependsOn "jar_example_${name}_debuginfo_all"
1046 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001047 dependsOn "extractExamplesRuntime"
1048 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001049 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1050 def proguardConfigPath = "${dir}/proguard.cfg"
1051 if (new File(proguardConfigPath).exists()) {
1052 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1053 archiveName = "${name}_pre_proguard.jar"
1054 destinationDir = exampleOutputDir
1055 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001056 include name + "/**/*.class"
1057 with runtimeDependencies
1058 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001059 }
1060 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1061 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1062 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1063 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001064 inputs.files files(
1065 tasks.getByPath("pre_proguard_example_${name}"),
1066 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001067 // Enable these to get stdout and stderr redirected to files...
1068 // standardOutput = new FileOutputStream('proguard.stdout')
1069 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001070 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001071 " -outjars ${proguardJarPath}" +
1072 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001073 " -printmapping ${proguardMapPath}"
1074 if (OperatingSystem.current().isWindows()) {
1075 executable "${proguardScript}"
1076 args "${proguardArguments}"
1077 } else {
1078 executable "bash"
1079 args "-c", "${proguardScript} '${proguardArguments}'"
1080 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001081 outputs.file proguardJarPath
1082 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001083 // TODO: Consider performing distinct proguard compilations.
1084 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1085 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001086 into "${exampleOutputDir}"
1087 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001088 }
1089 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1090 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001091 into "${exampleOutputDir}"
1092 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001093 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001094 } else {
1095 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001096 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001097 destinationDir = exampleOutputDir
1098 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001099 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001100 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001101 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001102 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001103 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1104 archiveName = "${name}_debuginfo_all.jar"
1105 destinationDir = exampleOutputDir
1106 from "build/test/examples/classes_debuginfo_all"
1107 include name + "/**/*.class"
1108 with runtimeDependencies
1109 includeEmptyDirs false
1110 }
1111 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1112 archiveName = "${name}_debuginfo_none.jar"
1113 destinationDir = exampleOutputDir
1114 from "build/test/examples/classes_debuginfo_none"
1115 include name + "/**/*.class"
1116 with runtimeDependencies
1117 includeEmptyDirs false
1118 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001119 }
1120 }
1121}
1122
1123task buildExampleAndroidNJars {
1124 dependsOn downloadDeps
1125 def examplesDir = file("src/test/examplesAndroidN")
1126 task "compile_examplesAndroidN"(type: JavaCompile) {
1127 source = fileTree(dir: examplesDir, include: '**/*.java')
1128 destinationDir = file("build/test/examplesAndroidN/classes")
1129 classpath = sourceSets.main.compileClasspath
1130 sourceCompatibility = JavaVersion.VERSION_1_8
1131 targetCompatibility = JavaVersion.VERSION_1_8
1132 options.compilerArgs += ["-Xlint:-options"]
1133 }
1134 examplesDir.eachDir { dir ->
1135 def name = dir.getName();
1136 def exampleOutputDir = file("build/test/examplesAndroidN");
1137 def jarName = "${name}.jar"
1138 dependsOn "jar_examplesAndroidN_${name}"
1139 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1140 archiveName = jarName
1141 destinationDir = exampleOutputDir
1142 from "build/test/examplesAndroidN/classes"
1143 include "**/" + name + "/**/*.class"
1144 }
1145 }
1146}
1147
1148
1149task buildExampleAndroidOJars {
1150 dependsOn downloadDeps
1151 def examplesDir = file("src/test/examplesAndroidO")
1152 // NOTE: we want to enable a scenario when test needs to reference some
1153 // classes generated by legacy (1.6) Java compiler to test some specific
1154 // behaviour. To do so we compile all the java files located in sub-directory
1155 // called 'legacy' with Java 1.6, then compile the rest of the files with
1156 // Java 1.8 and a reference to previously generated 1.6 classes.
1157
1158 // Compiling all classes in dirs 'legacy' with old Java version.
1159 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1160 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1161 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1162 classpath = sourceSets.main.compileClasspath
1163 sourceCompatibility = JavaVersion.VERSION_1_6
1164 targetCompatibility = JavaVersion.VERSION_1_6
1165 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1166 }
1167 // Compiling the rest of the files as Java 1.8 code.
1168 task "compile_examplesAndroidO"(type: JavaCompile) {
1169 dependsOn "compile_examplesAndroidO_Legacy"
1170 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1171 destinationDir = file("build/test/examplesAndroidO/classes")
1172 classpath = sourceSets.main.compileClasspath
1173 classpath += files("build/test/examplesAndroidOLegacy/classes")
1174 sourceCompatibility = JavaVersion.VERSION_1_8
1175 targetCompatibility = JavaVersion.VERSION_1_8
1176 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1177 }
1178 examplesDir.eachDir { dir ->
1179 def name = dir.getName();
1180 def destinationDir = file("build/test/examplesAndroidO/classes");
1181 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1182 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1183 dependsOn: "compile_examplesAndroidO") {
1184 main = name + ".TestGenerator"
1185 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1186 args destinationDir
1187 }
1188 } else {
1189 task "generate_examplesAndroidO_${name}" () {}
1190 }
1191 }
1192 examplesDir.eachDir { dir ->
1193 def name = dir.getName();
1194 def exampleOutputDir = file("build/test/examplesAndroidO");
1195 def jarName = "${name}.jar"
1196 dependsOn "jar_examplesAndroidO_${name}"
1197 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1198 "generate_examplesAndroidO_${name}"]) {
1199 archiveName = jarName
1200 destinationDir = exampleOutputDir
1201 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1202 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1203 include "**/" + name + "/**/*.class"
1204 // Do not include generator into the test runtime jar, it is not useful.
1205 // Otherwise, shrinking will need ASM jars.
1206 exclude "**/TestGenerator*"
1207 }
1208 }
1209}
1210
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001211task buildExampleAndroidPJars {
1212 dependsOn downloadDeps
1213 def examplesDir = file("src/test/examplesAndroidP")
1214
1215 task "compile_examplesAndroidP"(type: JavaCompile) {
1216 source = fileTree(dir: examplesDir, include: '**/*.java')
1217 destinationDir = file("build/test/examplesAndroidP/classes")
1218 classpath = sourceSets.main.compileClasspath
1219 sourceCompatibility = JavaVersion.VERSION_1_8
1220 targetCompatibility = JavaVersion.VERSION_1_8
1221 options.compilerArgs += ["-Xlint:-options"]
1222 }
1223 examplesDir.eachDir { dir ->
1224 def name = dir.getName();
1225 def destinationDir = file("build/test/examplesAndroidP/classes");
1226 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1227 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1228 dependsOn: "compile_examplesAndroidP") {
1229 main = name + ".TestGenerator"
1230 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1231 args destinationDir
1232 }
1233 } else {
1234 task "generate_examplesAndroidP_${name}" () {}
1235 }
1236 }
1237 examplesDir.eachDir { dir ->
1238 def name = dir.getName();
1239 def exampleOutputDir = file("build/test/examplesAndroidP");
1240 def jarName = "${name}.jar"
1241 dependsOn "jar_examplesAndroidP_${name}"
1242 task "jar_examplesAndroidP_${name}"(type: Jar,
1243 dependsOn: ["compile_examplesAndroidP",
1244 "generate_examplesAndroidP_${name}"]) {
1245 archiveName = jarName
1246 destinationDir = exampleOutputDir
1247 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1248 include "**/" + name + "/**/*.class"
1249 // Do not include generator into the test runtime jar, it is not useful.
1250 // Otherwise, shrinking will need ASM jars.
1251 exclude "**/TestGenerator*"
1252 }
1253 }
1254}
1255
Mikaël Peltier61633d42017-10-13 16:51:06 +02001256task buildExampleJava9Jars {
1257 def examplesDir = file("src/test/examplesJava9")
1258 examplesDir.eachDir { dir ->
1259 def name = dir.getName();
1260 def exampleOutputDir = file("build/test/examplesJava9");
1261 def jarName = "${name}.jar"
1262 dependsOn "jar_examplesJava9_${name}"
1263 task "jar_examplesJava9_${name}"(type: Jar) {
1264 archiveName = jarName
1265 destinationDir = exampleOutputDir
1266 from "src/test/examplesJava9" // Java 1.9 classes
1267 include "**/" + name + "/**/*.class"
1268 }
1269 }
1270}
1271
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001272task buildExamplesKotlin {
1273 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1274 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1275 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1276 } else if (!OperatingSystem.current().isLinux()) {
1277 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1278 "on your platform. It is fully supported on Linux and partially supported on " +
1279 "Mac OS and Windows")
1280 return;
1281 }
1282 def examplesDir = file("src/test/examplesKotlin")
1283 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001284 def name = dir.getName();
1285 dependsOn "dex_example_kotlin_${name}"
1286 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1287 def dexPath = file("${exampleOutputDir}")
1288 task "dex_example_kotlin_${name}"(type: dx.Dx,
1289 dependsOn: "compile_example_kotlin_${name}") {
1290 doFirst {
1291 if (!dexPath.exists()) {
1292 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001293 }
1294 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001295 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1296 destination = dexPath
1297 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001298 }
1299 }
1300}
1301
Sebastien Hertzd3313772018-01-16 14:12:37 +01001302task buildKotlinR8TestResources {
1303 def examplesDir = file("src/test/kotlinR8TestResources")
1304 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001305 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1306 def name = dir.getName()
1307 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001308 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1309 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001310 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001311 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001312 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1313 source = fileTree(dir: file("${examplesDir}/${name}"),
1314 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001315 destination = file(outputFile)
1316 targetVersion = kotlinTargetVersion
1317 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001318 task "${taskName}Java"(type: JavaCompile) {
1319 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1320 destinationDir = file(javaOutput)
1321 classpath = sourceSets.main.compileClasspath
1322 sourceCompatibility = JavaVersion.VERSION_1_6
1323 targetCompatibility = JavaVersion.VERSION_1_6
1324 options.compilerArgs += ["-g", "-Xlint:-options"]
1325 }
1326 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1327 archiveName = javaOutputJarName
1328 destinationDir = file(javaOutputJarDir)
1329 from javaOutput
1330 include "**/*.class"
1331 }
1332 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001333 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001334 }
1335}
1336
Mads Ager418d1ca2017-05-22 09:35:49 +02001337task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001338 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1339 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1340 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001341 } else if (!OperatingSystem.current().isLinux()) {
1342 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001343 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001344 return;
1345 }
1346 dependsOn buildDebugTestResourcesJars
1347 dependsOn buildExampleJars
1348 dependsOn buildExampleAndroidNJars
1349 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001350 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001351 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001352 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001353 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001354 def noDexTests = [
1355 "multidex",
1356 "multidex002",
1357 "multidex004",
1358 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001359 examplesDir.eachDir { dir ->
1360 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001361 if (!(name in noDexTests)) {
1362 dependsOn "dex_example_${name}"
1363 def exampleOutputDir = file("build/test/examples/" + name);
1364 def dexPath = file("${exampleOutputDir}")
1365 def debug = (name == "throwing")
1366 if (!dexPath.exists()) {
1367 dexPath.mkdirs()
1368 }
1369 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1370 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1371 destination = dexPath
1372 debug = debug
1373 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001374 }
1375 }
1376}
1377
1378task buildSmali {
1379 def smaliDir = file("src/test/smali")
1380 smaliDir.eachDirRecurse() { dir ->
1381 def name = dir.getName();
1382 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1383 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1384 smaliOutputDir.mkdirs()
1385 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001386 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001387 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1388 def javaFiles = fileTree(dir: dir, include: '*.java')
1389 def destDir = smaliOutputDir;
1390 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1391 def intermediateFileName = "${name}-intermediate.dex";
1392 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1393 if (javaFiles.empty) {
1394 if (!smaliFiles.empty) {
1395 dependsOn "${taskName}_smali"
1396 task "${taskName}_smali"(type: smali.Smali) {
1397 source = smaliFiles
1398 destination = destFile
1399 }
1400 }
1401 } else {
1402 dependsOn "${taskName}_dexmerger"
1403 task "${taskName}_smali"(type: smali.Smali) {
1404 source = smaliFiles
1405 destination = intermediateFile
1406 }
1407 task "${taskName}_java"(type: JavaCompile) {
1408 source = javaFiles
1409 destinationDir destDir
1410 classpath = sourceSets.main.compileClasspath
1411 sourceCompatibility = JavaVersion.VERSION_1_7
1412 targetCompatibility = JavaVersion.VERSION_1_7
1413 options.compilerArgs += ["-Xlint:-options"]
1414 }
1415 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1416 archiveName = "Test.jar"
1417 destinationDir = destDir
1418 from fileTree(dir: destDir, include: 'Test.class')
1419 }
1420 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1421 source = fileTree(dir: destDir, include: 'Test.jar')
1422 destination = destDir
1423 }
1424 task "${taskName}_dexmerger"(
1425 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1426 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1427 destination = destFile
1428 }
1429 }
1430 }
1431}
1432
1433tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001434 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001435 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1436 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1437 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1438 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
Rico Windc56f21c2019-03-12 07:29:57 +01001439 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001440 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001441 if (project.hasProperty('disable_assertions')) {
1442 enableAssertions = false
1443 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001444 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1445 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001446}
1447
1448task buildPreNJdwpTestsJar(type: Jar) {
1449 baseName = 'jdwp-tests-preN'
1450 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1451 // Exclude the classes containing java8
1452 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1453 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1454 includeEmptyDirs = false
1455}
1456
Ian Zerny74143162017-11-24 13:46:35 +01001457task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1458 def inFile = buildPreNJdwpTestsJar.archivePath
1459 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001460 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001461 outputs.file outFile
1462 if (OperatingSystem.current().isWindows()) {
1463 executable file("tools/windows/dx/bin/dx.bat")
1464 } else if (OperatingSystem.current().isMacOsX()) {
1465 executable file("tools/mac/dx/bin/dx");
1466 } else {
1467 executable file("tools/linux/dx/bin/dx");
1468 }
1469 args "--dex"
1470 args "--output=${outFile}"
1471 args inFile
1472}
1473
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001474task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1475 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001476}
1477
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001478task AospJarTest(type: Exec) {
1479 dependsOn CompatDx, downloadDeps
1480 def script = "tools/test_aosp_jar.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001481 inputs.files files(script)
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001482 commandLine "python", script, "--no-build"
1483 workingDir = projectDir
1484}
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') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001558 println "Running with non default vm: " + project.property('dex_vm')
1559 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001560 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001561
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001562 // Forward vm configurations for test parameters.
1563 if (project.hasProperty('dex_vms')) {
1564 systemProperty 'dex_vms', project.property('dex_vms')
1565 }
1566 if (project.hasProperty('cf_vms')) {
1567 systemProperty 'cf_vms', project.property('cf_vms')
1568 }
1569
Mads Ager418d1ca2017-05-22 09:35:49 +02001570 if (project.hasProperty('one_line_per_test')) {
1571 beforeTest { desc ->
1572 println "Start executing test ${desc.name} [${desc.className}]"
1573 }
1574 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001575 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001576 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001577 }
Rico Windda6836e2018-12-07 12:32:03 +01001578 if (project.hasProperty('update_test_timestamp')) {
1579 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1580 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001581 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1582 }
Rico Windf88b6be2018-12-11 15:14:05 +01001583 } else {
1584 afterTest { desc, result ->
1585 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001586 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001587 }
1588 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001589 }
1590 if (project.hasProperty('no_internal')) {
1591 exclude "com/android/tools/r8/internal/**"
1592 }
1593 if (project.hasProperty('only_internal')) {
1594 include "com/android/tools/r8/internal/**"
1595 }
Rico Wind4e218292019-03-07 12:44:49 +01001596
Mads Ager418d1ca2017-05-22 09:35:49 +02001597 if (project.hasProperty('tool')) {
1598 if (project.property('tool') == 'r8') {
1599 exclude "com/android/tools/r8/art/*/d8/**"
Rico Windf02167a2019-03-15 12:27:03 +01001600 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001601 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001602 if (project.hasProperty('only_jctf')) {
1603 include "com/android/tools/r8/jctf/d8/**"
1604 } else {
1605 include "com/android/tools/r8/art/*/d8/**"
1606 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001607 } else {
1608 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001609 assert(project.hasProperty('only_jctf'))
1610 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001611 }
1612 }
1613 if (!project.hasProperty('all_tests')) {
1614 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001615 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001616 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001617 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001618 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001619 if (project.hasProperty('shard_count') ) {
1620 assert project.hasProperty('shard_number')
1621 int shard_count = project.getProperty('shard_count') as Integer
1622 int shard_number = project.getProperty('shard_number') as Integer
1623 assert shard_count < 65536
1624 assert shard_number < shard_count
1625 exclude {
1626 entry ->
1627 // Don't leave out directories. Leaving out a directory means all entries below.
1628 if (entry.file.isDirectory()) {
1629 return false
1630 }
1631 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1632 int hash = Integer.parseInt(first4, 16)
1633 return hash % shard_count != shard_number
1634 }
1635 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001636 if (project.hasProperty('jctf_compile_only')) {
1637 println "JCTF: compiling only"
1638 systemProperty 'jctf_compile_only', '1'
1639 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001640 if (project.hasProperty('test_dir')) {
1641 systemProperty 'test_dir', project.property('test_dir')
1642 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001643 if (project.hasProperty('aosp_jar')) {
1644 dependsOn AospJarTest
1645 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001646 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1647 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001648 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1649 // all needed tests in r8LibTestPath.
1650 classpath = files([r8LibPath, r8LibTestPath]) +
1651 sourceSets.test.runtimeClasspath -
1652 sourceSets.main.output -
1653 files(['build/classes/test'])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001654 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001655 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001656 if (OperatingSystem.current().isLinux()
1657 || OperatingSystem.current().isMacOsX()
1658 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001659 if (OperatingSystem.current().isMacOsX()) {
1660 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1661 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1662 "See tools/docker/README.md for details.")
1663 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001664 if (OperatingSystem.current().isWindows()) {
1665 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1666 "Art only runs on Linux and tests requiring Art will be skipped")
1667 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001668 dependsOn downloadDeps
1669 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001670 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001671 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001672 dependsOn buildSmali
1673 dependsOn jctfCommonJar
1674 dependsOn jctfTestsClasses
1675 dependsOn buildDebugInfoExamplesDex
1676 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001677 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001678 } else {
1679 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001680 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001681 }
1682}
1683
1684// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1685//
1686// To build and upload a new set of the Art tests for use with R8 follow these steps:
1687//
1688// First of all an Android checkout is required. Currently it must be located
1689// in $HOME/android/master.
1690//
1691// TODO(ricow): simplify this
1692//
1693// Before: update the checked in art, see scripts/update-host-art.sh
1694//
1695// 1. Get an android checkout in $HOME/android/master and apply the patch from
1696// https://android-review.googlesource.com/#/c/294187/
1697//
1698// 2. run the following commands in the Android checkout directory:
1699//
1700// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001701// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1702// m desugar
1703// m -j30 test-art-host
1704// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1705//
1706// Without running the test.py command the classes.jar file used by desugar in
1707// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1708// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001709//
1710// 3. In the R8 project root directory, make sure we have a clean state before starting:
1711// tools/gradle.py downloadDeps
1712// tools/gradle.py clean
1713// rm -rf tests/art
1714//
1715// 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 +02001716// Make sure you have smali on your path, please use the build binary in the
1717// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1718// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1719// 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 +02001720// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1721// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001722//
Søren Gjesse34b77732017-07-07 13:56:21 +02001723// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001724//
1725// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1726// skippedTests with an explanation. Rerun from step 3.
1727//
1728// 5. Run the tests:
1729// tools/gradle.py clean
1730// tools/test.py
1731//
Søren Gjesse34b77732017-07-07 13:56:21 +02001732// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1733// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1734// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001735//
Søren Gjesse34b77732017-07-07 13:56:21 +02001736// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001737// cd tests
1738// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001739//
1740// 7. Update the manifest file describing the Android repo used:
1741// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001742
1743enum DexTool {
1744 JACK,
1745 DX
1746}
1747
1748def androidCheckoutDir = file("${System.env.HOME}/android/master")
1749def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1750def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1751
1752def artTestDir = file("${androidCheckoutDir}/art/test")
1753
1754if (project.hasProperty('android_source')) {
1755 task buildArtTests {
1756 outputs.upToDateWhen { false }
1757 def toBeTriaged = [
1758 "903-hello-tagging",
1759 "904-object-allocation",
1760 "905-object-free",
1761 "906-iterate-heap",
1762 "907-get-loaded-classes",
1763 "908-gc-start-finish",
1764 "954-invoke-polymorphic-verifier",
1765 "955-methodhandles-smali",
1766 "596-monitor-inflation",
1767 ]
1768 def skippedTests = toBeTriaged + [
1769 // This test produces no jar.
1770 "000-nop",
1771 // This does not build, as it tests the error when the application exceeds more
1772 // than 65536 methods
1773 "089-many-methods",
1774 // Requires some jack beta jar
1775 "956-methodhandles",
1776 ]
1777
1778 def skippedTestsDx = [
1779 // Tests with custom build scripts, where javac is not passed the options
1780 // -source 1.7 -target 1.7.
1781 "462-checker-inlining-across-dex-files",
1782 "556-invoke-super",
1783 "569-checker-pattern-replacement",
1784 // These tests use jack even when --build-with-javac-dx is specified.
1785 "004-JniTest",
1786 "048-reflect-v8",
1787 "146-bad-interface",
1788 "563-checker-invoke-super",
1789 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1790 "604-hot-static-interface",
1791 "957-methodhandle-transforms",
1792 "958-methodhandle-emulated-stackframe",
1793 "959-invoke-polymorphic-accessors",
1794 "961-default-iface-resolution-gen",
1795 "962-iface-static",
1796 "963-default-range-smali",
1797 "964-default-iface-init-gen",
1798 "965-default-verify",
1799 "966-default-conflict",
1800 "967-default-ame",
1801 "968-default-partial-compile-gen",
1802 "969-iface-super",
1803 "970-iface-super-resolution-gen",
1804 "971-iface-super",
1805 // These tests does not build with --build-with-javac-dx
1806 "004-NativeAllocations", // Javac error
1807 "031-class-attributes",
1808 "138-duplicate-classes-check",
1809 "157-void-class", // Javac error
1810 "580-checker-string-factory-intrinsics",
1811 "612-jit-dex-cache",
1812 "613-inlining-dex-cache",
1813 "900-hello-plugin", // --experimental agents
1814 "901-hello-ti-agent", // --experimental agents
1815 "902-hello-transformation", // --experimental agents
1816 "909-attach-agent", // --experimental agents
1817 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1818 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1819 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1820 "960-default-smali", // --experimental default-methods
1821 // These tests force the build to use jack
1822 "953-invoke-polymorphic-compiler",
1823 "958-methodhandle-stackframe",
1824 ]
1825
1826 def artTestBuildDir = file("${projectDir}/tests/art")
1827
1828 if (androidCheckoutDir.exists()) {
1829 dependsOn downloadDeps
1830 artTestBuildDir.mkdirs()
1831 // Ensure Jack server is running.
1832 "${androidCheckoutJackServer} start-server".execute()
1833 artTestDir.eachDir { dir ->
1834 def name = dir.getName();
1835 def markerFile = dir.toPath().resolve("info.txt").toFile();
1836 if (markerFile.exists() && !(name in skippedTests)) {
1837 if (!(name in skippedTestsDx)) {
1838 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1839 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001840 // After Android O, Jack is no longer alive
1841 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001842 }
1843 }
1844 }
1845 doFirst {
1846 if (!androidCheckoutDir.exists()) {
1847 throw new InvalidUserDataException(
1848 "This task requires an Android checkout in ${androidCheckoutDir}");
1849 } else if (!androidCheckoutJack.exists() ||
1850 !androidCheckoutJackServer.exists()) {
1851 throw new InvalidUserDataException(
1852 "This task requires that tools for host testing have been build in the " +
1853 "Android checkout in ${androidCheckoutDir}");
1854 }
1855 }
1856 doLast {
1857 copy {
1858 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1859 into file("${artTestBuildDir}/lib64")
1860 include 'lib*.so'
1861 }
1862 copy {
1863 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1864 into file("${artTestBuildDir}/lib64")
1865 include 'libart.so'
1866 include 'libbacktrace.so'
1867 include 'libbase.so'
1868 include 'libc++.so'
1869 include 'libcutils.so'
1870 include 'liblz4.so'
1871 include 'liblzma.so'
1872 include 'libnativebridge.so'
1873 include 'libnativeloader.so'
1874 include 'libsigchain.so'
1875 include 'libunwind.so'
1876 include 'libziparchive.so'
1877 }
1878 copy {
1879 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1880 into file("${artTestBuildDir}/lib")
1881 include 'lib*.so'
1882 }
1883 copy {
1884 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1885 into file("${artTestBuildDir}/lib")
1886 include 'libart.so'
1887 include 'libbacktrace.so'
1888 include 'libbase.so'
1889 include 'libc++.so'
1890 include 'libcutils.so'
1891 include 'liblz4.so'
1892 include 'liblzma.so'
1893 include 'libnativebridge.so'
1894 include 'libnativeloader.so'
1895 include 'libsigchain.so'
1896 include 'libunwind.so'
1897 include 'libziparchive.so'
1898 }
1899 }
1900 }
1901}
1902
1903def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1904 def artTestDir = file("${androidCheckoutDir}/art/test")
1905 def artRunTestScript = file("${artTestDir}/run-test")
1906 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001907 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001908 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1909
Søren Gjesse34b77732017-07-07 13:56:21 +02001910 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001911 def buildTask = "build_art_test_${dexToolName}_${name}"
1912 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1913 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1914 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1915
1916 def buildInputs = fileTree(dir: dir, include: '**/*')
1917 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1918 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1919 testDir.mkdirs()
1920 if (dexTool == DexTool.DX) {
1921 task "$buildTask"(type: Exec) {
1922 outputs.upToDateWhen { false }
1923 inputs.file buildInputs
1924 executable "${artRunTestScript}"
1925 args "--host"
1926 args "--build-only"
1927 args "--build-with-javac-dx"
1928 args "--output-path", "${testDir}"
1929 args "${name}"
1930 environment DX: "${dxExecutable.absolutePath}"
1931 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001932 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001933 outputs.file outputJar
1934 }
1935 } else {
1936 assert dexTool == DexTool.JACK
1937 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1938 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1939 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1940 task "$buildTask"(type: Exec) {
1941 outputs.upToDateWhen { false }
1942 inputs.file buildInputs
1943 executable "${artRunTestScript}"
1944 args "--host"
1945 args "--build-only"
1946 args "--output-path", "${testDir}"
1947 args "${name}"
1948 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1949 environment JACK_CLASSPATH: jackClasspath
1950 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1951 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1952 outputs.file outputJar
1953 }
1954 }
1955 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1956 outputs.upToDateWhen { false }
1957 executable "/bin/bash"
1958 args "-c"
1959 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1960 " ${testDir}/classes-ex ${testDir}/check"
1961 }
1962
1963 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001964 // Directory that contains smali files is either smali, or smali/art
1965 def smali_dir = file("${dir}/smali/art")
1966 if (smali_dir.exists()) {
1967 workingDir "${testDir}/smali/art"
1968 } else {
1969 workingDir "${testDir}/smali"
1970 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001971 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001972 // This is the command line options for smali prior to 2.2.1, where smali got a new
1973 // command line interface.
1974 args "-c", "smali a *.smali"
1975 // This is the command line options for smali 2.2.1 and later.
1976 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001977 }
1978
1979 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1980 def smali_dir = file("${dir}/smali")
1981 outputs.upToDateWhen { false }
1982 if (smali_dir.exists() && dexTool == DexTool.DX) {
1983 dependsOn smaliToDexTask
1984 }
1985 from("${artTestDir}/${name}") {
1986 include 'check'
1987 }
1988 into testDir
1989 }
1990
1991 return copyCheckTask
1992}
1993
1994task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001995 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001996 classpath = sourceSets.main.compileClasspath
1997 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001998 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001999 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002000 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002001 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002002 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002003 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002004 include '**/com/android/tools/r8/CompilationMode.java'
2005 include '**/com/android/tools/r8/D8.java'
2006 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002007 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2008 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002009 include '**/com/android/tools/r8/Diagnostic.java'
2010 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002011 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2012 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002013 include '**/com/android/tools/r8/ProgramConsumer.java'
2014 include '**/com/android/tools/r8/ProgramResource.java'
2015 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002016 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002017 include '**/com/android/tools/r8/ResourceException.java'
2018 include '**/com/android/tools/r8/StringConsumer.java'
2019 include '**/com/android/tools/r8/StringResource.java'
2020 include '**/com/android/tools/r8/Version.java'
2021 include '**/com/android/tools/r8/origin/*.java'
2022}
2023
2024task javadocR8(type: Javadoc) {
2025 title "R8 API"
2026 classpath = sourceSets.main.compileClasspath
2027 source = sourceSets.main.allJava
2028 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2029 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2030 include '**/com/android/tools/r8/BaseCommand.java'
2031 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2032 include '**/com/android/tools/r8/ClassFileConsumer.java'
2033 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2034 include '**/com/android/tools/r8/CompilationFailedException.java'
2035 include '**/com/android/tools/r8/CompilationMode.java'
2036 include '**/com/android/tools/r8/R8.java'
2037 include '**/com/android/tools/r8/R8Command.java'
2038 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2039 include '**/com/android/tools/r8/Diagnostic.java'
2040 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002041 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2042 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002043 include '**/com/android/tools/r8/ProgramConsumer.java'
2044 include '**/com/android/tools/r8/ProgramResource.java'
2045 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2046 include '**/com/android/tools/r8/Resource.java'
2047 include '**/com/android/tools/r8/ResourceException.java'
2048 include '**/com/android/tools/r8/StringConsumer.java'
2049 include '**/com/android/tools/r8/StringResource.java'
2050 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002051 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002052}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002053
2054task copyMavenDeps(type: Copy) {
2055 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002056 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002057 from configurations.testCompile into "$buildDir/deps"
2058}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002059
2060// This task allows to build class files from Java 9 source in order to use them as inputs of
2061// D8/R8 tests. Class files are generated in the same place than source files and must be commited
2062// to the D8 repository because there is no way to generate them on all computers due to the need of
2063// Java 9.
2064// Use the following command to rebuild class files of tests:
2065// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
2066task buildJava9Tests {
2067 def javacOutputFolder = getTemporaryDir();
2068 def examplesDir = file("src/test/examplesJava9")
2069
2070 task "compile_Java9examples"(type: JavaCompile) {
2071 doFirst {
2072 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
2073 throw new GradleException("Set java9Home property.")
2074 }
2075 }
2076
2077 source = fileTree(dir: examplesDir, include: '**/*.java')
2078 destinationDir = javacOutputFolder
2079 classpath = sourceSets.main.compileClasspath
2080 options.compilerArgs += ["-Xlint:-options"]
2081 sourceCompatibility = JavaVersion.VERSION_1_9
2082 targetCompatibility = JavaVersion.VERSION_1_9
2083 options.fork = true
2084
2085 if (project.hasProperty('java9Home')) {
2086 options.forkOptions.javaHome = file(getProperty('java9Home'))
2087 }
2088
2089 doLast {
2090 def classfileFrom = copySpec {
2091 from javacOutputFolder
2092 include "**/*.class"
2093 }
2094 copy {
2095 into examplesDir
2096 with classfileFrom
2097 }
2098 delete javacOutputFolder
2099 }
2100 }
2101
2102 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02002103}