blob: 7f6d5fab494af43ddfaeb3be0ccf5f1130b074f7 [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
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00008import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +02009import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020010
Ian Zerny5fffb0a2019-02-11 13:54:22 +010011buildscript {
12 repositories {
13 mavenCentral()
14 jcenter()
15 maven {
16 url "https://plugins.gradle.org/m2/"
17 }
18 }
19 dependencies {
20 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
21 }
22}
23
24plugins {
25 id "net.ltgt.errorprone" version "0.7"
26}
27
28apply plugin: 'java'
29apply plugin: 'idea'
30
Sebastien Hertz143ed112018-02-13 14:26:41 +010031ext {
32 androidSupportVersion = '25.4.0'
Gautam Korlam39d74202018-08-29 18:09:35 -070033 asmVersion = '6.2.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010034 espressoVersion = '3.0.0'
35 fastutilVersion = '7.2.0'
36 guavaVersion = '23.0'
37 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020038 gsonVersion = '2.7'
Sebastien Hertz143ed112018-02-13 14:26:41 +010039 junitVersion = '4.12'
Jinseong Jeone11145f2018-12-13 10:57:29 -080040 mockitoVersion = '2.10.0'
Jinseong Jeon46146f42018-12-16 23:26:14 -080041 kotlinVersion = '1.3.11'
Jinseong Jeonb6fe4fe2018-12-03 00:49:13 -080042 kotlinExtMetadataJVMVersion = '0.0.4'
Sebastien Hertz143ed112018-02-13 14:26:41 +010043 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010044 errorproneVersion = '2.3.2'
Sebastien Hertz143ed112018-02-13 14:26:41 +010045}
46
Mads Ager418d1ca2017-05-22 09:35:49 +020047apply from: 'copyAdditionalJctfCommonFiles.gradle'
48
49repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020050 maven { url 'https://maven.google.com' }
Jinseong Jeon515e7582018-06-15 21:50:31 +000051 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020052 mavenCentral()
53}
54
Jinseong Jeon05064e12018-07-03 00:21:12 -070055if (project.hasProperty('with_code_coverage')) {
56 apply plugin: 'jacoco'
57}
58
Mads Ager418d1ca2017-05-22 09:35:49 +020059// Custom source set for example tests and generated tests.
60sourceSets {
61 test {
62 java {
63 srcDirs = [
64 'src/test/java',
65 'build/generated/test/java',
66 ]
67 }
68 }
Yohann Rousselbb571622017-11-09 10:47:36 +010069 apiUsageSample {
70 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020071 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
72 include 'com/android/tools/apiusagesample/*.java'
73 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
74 include 'com/android/tools/r8/D8CommandParser.java'
75 include 'com/android/tools/r8/R8CommandParser.java'
76 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010077 }
Yohann Rousselbb571622017-11-09 10:47:36 +010078 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010079 cfSegments {
80 java {
81 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
82 }
83 output.resourcesDir = 'build/classes/cfSegments'
84 }
85 classlib {
86 java {
87 srcDirs = [
88 'third_party/classlib/java',
89 ]
90 }
91 output.resourcesDir = 'build/classes/classlib'
92 }
Mads Ager418d1ca2017-05-22 09:35:49 +020093 debugTestResources {
94 java {
95 srcDirs = ['src/test/debugTestResources']
96 }
97 output.resourcesDir = 'build/classes/debugTestResources'
98 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020099 debugTestResourcesJava8 {
100 java {
101 srcDirs = ['src/test/debugTestResourcesJava8']
102 }
103 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
104 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200105 debugTestResourcesKotlin {
106 java {
107 srcDirs = ['src/test/debugTestResourcesKotlin']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
110 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200111 examples {
112 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800113 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200114 }
115 output.resourcesDir = 'build/classes/examples'
116 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100117 examplesKotlin {
118 java {
119 srcDirs = ['src/test/examplesKotlin']
120 }
121 output.resourcesDir = 'build/classes/examplesKotlin'
122 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200123 examplesAndroidN {
124 java {
125 srcDirs = ['src/test/examplesAndroidN']
126 }
127 output.resourcesDir = 'build/classes/examplesAndroidN'
128 }
129 examplesAndroidO {
130 java {
131 srcDirs = ['src/test/examplesAndroidO']
132 }
133 output.resourcesDir = 'build/classes/examplesAndroidO'
134 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200135 examplesAndroidP {
136 java {
137 srcDirs = ['src/test/examplesAndroidP']
138 }
139 output.resourcesDir = 'build/classes/examplesAndroidP'
140 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200141 jctfCommon {
142 java {
143 srcDirs = [
144 'third_party/jctf/Harness/src',
145 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
146 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
147 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
148 'third_party/jctf/LibTests/src/org',
149 'build/additionalJctfCommonFiles'
150 ]
151 }
152 resources {
153 srcDirs = ['third_party/jctf/LibTests/resources']
154 }
155 }
156 jctfTests {
157 java {
158 srcDirs = [
159 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
160 // 'third_party/jctf/VMTests/src',
161 ]
162 }
163 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100164 kotlinR8TestResources {
165 java {
166 srcDirs = ['src/test/kotlinR8TestResources']
167 }
168 output.resourcesDir = 'build/classes/kotlinR8TestResources'
169 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200170}
171
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800172// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
173// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
174// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
175// for context.
176idea {
177 sourceSets.all { SourceSet sources ->
178 module {
179 if (sources.name == "main") {
180 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100181 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800182 } else {
183 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100184 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800185 }
186 }
187 }
188}
189
Yohann Roussel126f6872017-08-03 16:25:32 +0200190configurations {
191 supportLibs
192}
193
Mads Ager418d1ca2017-05-22 09:35:49 +0200194dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100195 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
196 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200197 // Include all of guava when compiling the code, but exclude annotations that we don't
198 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100199 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100200 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200201 exclude group: 'com.google.errorprone'
202 exclude group: 'com.google.code.findbugs'
203 exclude group: 'com.google.j2objc'
204 exclude group: 'org.codehaus.mojo'
205 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100206 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
207 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
208 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
209 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
210 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
211 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
212 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200213 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100214 testCompile "junit:junit:$junitVersion"
215 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200216 testCompile files('third_party/jasmin/jasmin-2.4.jar')
217 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200218 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100219 jctfCommonCompile "junit:junit:$junitVersion"
220 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200221 jctfTestsCompile sourceSets.jctfCommon.output
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100222 cfSegmentsCompile sourceSets.classlib.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100223 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
224 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200225 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100226 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800227 examplesCompile "junit:junit:$junitVersion"
228 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100229 supportLibs "com.android.support:support-v4:$androidSupportVersion"
230 supportLibs "junit:junit:$junitVersion"
231 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100232 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100233 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100234 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
235 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
236 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100237 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200238}
239
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100240def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100241def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100242def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100243def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100244def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100245
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200246def osString = OperatingSystem.current().isLinux() ? "linux" :
247 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200248
249def cloudDependencies = [
250 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200251 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200252 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200253 ],
254 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200255 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200256 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100257 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200258 "android_jar/lib-v19",
259 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100260 "android_jar/lib-v22",
261 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200262 "android_jar/lib-v24",
263 "android_jar/lib-v25",
264 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100265 "android_jar/lib-v27",
266 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200267 "core-lambda-stubs",
268 "dart-sdk",
269 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200270 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200271 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200272 "jasmin",
273 "jctf",
Rico Windf72fa152018-10-22 15:41:03 +0200274 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200275 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100276 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200277 "proguard/proguard5.2.1",
278 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200279 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200280 ],
281 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
282 // container on other platforms where supported.
283 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200284 "linux/art",
285 "linux/art-5.1.1",
286 "linux/art-6.0.1",
287 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100288 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100289 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200290 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100291 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200293 ]
294]
295
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100296def cloudSystemDependencies = [
297 linux: [
298 "third_party": ["openjdk/openjdk-9.0.4/linux"],
299 ],
300 osx: [
301 "third_party": ["openjdk/openjdk-9.0.4/osx"],
302 ],
303 windows: [
304 "third_party": ["openjdk/openjdk-9.0.4/windows"],
305 ],
306]
307
308if (OperatingSystem.current().isWindows()) {
309 cloudSystemDependencies.windows.each { entry ->
310 cloudDependencies.get(entry.key).addAll(entry.value)
311 }
312} else if (OperatingSystem.current().isLinux()) {
313 cloudSystemDependencies.linux.each { entry ->
314 cloudDependencies.get(entry.key).addAll(entry.value)
315 }
316} else if (OperatingSystem.current().isMacOsX()) {
317 cloudSystemDependencies.osx.each { entry ->
318 cloudDependencies.get(entry.key).addAll(entry.value)
319 }
320} else {
321 println "WARNING: Unsupported system: " + OperatingSystem.current()
322}
323
324def getDownloadDepsTaskName(entryKey, entryFile) {
325 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
326}
327
Mads Ager418d1ca2017-05-22 09:35:49 +0200328cloudDependencies.each { entry ->
329 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100330 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200331 def outputDir = "${entry.key}/${entryFile}"
332 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200333 def sha1File = "${gzFile}.sha1"
Ian Zerny61fcba92018-11-30 14:20:50 +0100334 // Make the output file part of the input dependencies explictly.
335 inputs.files files(sha1File, gzFile)
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200336 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200337 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
338 if (OperatingSystem.current().isWindows()) {
339 executable "download_from_google_storage.bat"
340 args dlFromStorageArgs
341 } else {
342 executable "bash"
343 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
344 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200345 }
346 }
347}
348
349def x20Dependencies = [
350 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200351 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200352 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100353 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100354 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200355 "desugar/desugar_20180308",
356 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200357 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200358 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200359 "gmscore/gmscore_v10",
360 "gmscore/gmscore_v9",
361 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200362 "gmscore/v4",
363 "gmscore/v5",
364 "gmscore/v6",
365 "gmscore/v7",
366 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200367 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200368 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200369 "proguard/proguard_internal_159423826",
370 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200371 "youtube/youtube.android_12.10",
372 "youtube/youtube.android_12.17",
373 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200374 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200375 ],
376]
377
378x20Dependencies.each { entry ->
379 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100380 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200381 def outputDir = "${entry.key}/${entryFile}"
382 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200383 def sha1File = "${gzFile}.sha1"
Morten Krogh-Jespersenef0d81a2019-01-11 11:43:14 +0100384 inputs.files files(sha1File, gzFile)
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200385 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200386 executable "bash"
387 args "-c", "tools/download_from_x20.py ${sha1File}"
388 }
389 }
390}
391
Rico Wind897bb712017-05-23 10:44:29 +0200392task downloadProguard {
393 cloudDependencies.each { entry ->
394 entry.value.each { entryFile ->
395 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100396 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200397 }
398 }
399 }
400}
401
Rico Windf6c74ce2018-12-04 08:50:55 +0100402task downloadOpenJDKrt {
403 cloudDependencies.each { entry ->
404 entry.value.each { entryFile ->
405 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100406 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100407 }
408 }
409 }
410}
411
Tamas Kenez427205b2017-06-29 15:57:09 +0200412task downloadDx {
413 cloudDependencies.each { entry ->
414 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200415 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100416 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200417 }
418 }
419 }
420}
421
Tamas Kenez0e10c562017-06-08 10:00:34 +0200422task downloadAndroidCts {
423 cloudDependencies.each { entry ->
424 entry.value.each { entryFile ->
425 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100426 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200427 }
428 }
429 }
430}
431
Mads Ager418d1ca2017-05-22 09:35:49 +0200432task downloadDeps {
433 cloudDependencies.each { entry ->
434 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100435 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200436 }
437 }
438 if (!project.hasProperty('no_internal')) {
439 x20Dependencies.each { entry ->
440 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100441 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200442 }
443 }
444 }
445}
446
447allprojects {
448 sourceCompatibility = JavaVersion.VERSION_1_8
449 targetCompatibility = JavaVersion.VERSION_1_8
450}
451
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100452// Check if running with the JDK location from tools/jdk.py.
453if (OperatingSystem.current().isWindows()) {
454 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
455} else {
456 def javaHomeOut = new StringBuilder()
457 def javaHomeErr = new StringBuilder()
458 def javaHomeProc = './tools/jdk.py'.execute()
459 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
460 def jdkHome = new File(javaHomeOut.toString().trim())
461 if (!jdkHome.exists()) {
462 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
463 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
464 println("WARNING: Gradle is running in a non-pinned Java"
465 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
466 + ". Expected: " + jdkHome)
467 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200468}
469
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100470sourceSets.configureEach { sourceSet ->
471 tasks.named(sourceSet.compileJavaTaskName).configure {
472 // Default disable errorprone (enabled and setup below).
473 options.errorprone.enabled = false
474 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100475 // Run all compilation tasks in a forked subprocess.
476 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100477 // Javac often runs out of stack space when compiling the tests.
478 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100479 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100480 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
481 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
482 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200483}
484
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100485if (!project.hasProperty('without_error_prone') &&
486 // Don't enable error prone on Java 8 as the plugin setup does not support it.
487 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200488 compileJava {
489 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100490 options.errorprone.enabled = true
491 options.errorprone.disableAllChecks = true
492 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
493 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
494 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
495 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
496 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
497 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
498 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
499 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
500 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
501 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
502 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
503 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
504 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
505 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
506 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
507 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
508 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
509 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
510 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200511 }
512}
513
Mads Ager418d1ca2017-05-22 09:35:49 +0200514compileJctfCommonJava {
515 dependsOn 'copyAdditionalJctfCommonFiles'
516 options.compilerArgs = ['-Xlint:none']
517}
518
519compileJctfTestsJava {
520 dependsOn 'jctfCommonClasses'
521 options.compilerArgs = ['-Xlint:none']
522}
523
Yohann Roussel7f47c032017-09-14 12:19:06 +0200524task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200525 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100526
Yohann Roussel7f47c032017-09-14 12:19:06 +0200527 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100528 def runtimeClasspath = configurations.findByName("runtimeClasspath")
529 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
530
Yohann Roussel7f47c032017-09-14 12:19:06 +0200531 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100532
Yohann Roussel7f47c032017-09-14 12:19:06 +0200533 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100534 def dependencies = []
535 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
536 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
537 dependencies.add("${identifier.group}:${identifier.module}")
538 }
539 def libraryLicenses = file('LIBRARY-LICENSE').text
540 dependencies.each {
541 if (!libraryLicenses.contains("- artifact: $it")) {
542 throw new GradleException("No license for $it in LIBRARY_LICENSE")
543 }
544 }
545
Yohann Roussel7f47c032017-09-14 12:19:06 +0200546 license.getParentFile().mkdirs()
547 license.createNewFile()
548 license.text = "This file lists all licenses for code distributed.\n"
549 license.text += "All non-library code has the following 3-Clause BSD license.\n"
550 license.text += "\n"
551 license.text += "\n"
552 license.text += file('LICENSE').text
553 license.text += "\n"
554 license.text += "\n"
555 license.text += "Summary of distributed libraries:\n"
556 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100557 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200558 license.text += "\n"
559 license.text += "\n"
560 license.text += "Licenses details:\n"
561 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
562 license.text += "\n"
563 license.text += "\n"
564 license.text += file.text
565 }
566 }
567}
568
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200569static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700570 // Everything under META-INF is not included by default.
571 // Should include before 'relocate' so that the service file path and its content
572 // are properly relocated as well.
573 task.mergeServiceFiles {
574 include 'META-INF/services/*'
575 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200576}
577
578static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000579 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200580 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000581 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
582 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000583 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000584 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200585 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
586 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
587 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200588 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000589}
590
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100591task repackageDepsNoRelocate(type: ShadowJar) {
592 configurations = [project.configurations.runtimeClasspath]
593 mergeServiceFiles(it)
594 exclude { it.getRelativePath().getPathString() == "module-info.class" }
595 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100596 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100597}
598
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000599task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100600 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200601 mergeServiceFiles(it)
602 if (!project.hasProperty('lib_no_relocate')) {
603 configureRelocations(it)
604 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100605 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700606 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000607 baseName 'deps'
608}
609
610task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200611 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200612 mergeServiceFiles(it)
613 if (!project.hasProperty('lib_no_relocate')) {
614 configureRelocations(it)
615 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000616 baseName 'sources'
617}
618
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100619task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200620 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100621 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200622 classifier = null
623 version = null
624 manifest {
625 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
626 }
627 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100628 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100629 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100630 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200631}
632
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100633task r8WithoutDeps(type: ShadowJar) {
634 from consolidatedLicense.outputs.files
635 baseName 'r8_without_deps'
636 classifier = null
637 version = null
638 manifest {
639 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
640 }
641 from sourceSets.main.output
642}
643
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000644task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200645 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200646 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200647 classifier = null
648 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200649 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200650 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200651 }
652 // In order to build without dependencies, pass the exclude_deps property using:
653 // gradle -Pexclude_deps R8
654 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800655 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000656 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800657 } else {
658 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200659 }
Ian Zerny80533c92019-01-24 10:32:09 +0100660 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200661}
662
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100663task R8NoManifestNoDeps(type: ShadowJar) {
664 from consolidatedLicense.outputs.files
665 baseName 'r8nomanifest-exclude-deps'
666 classifier = null
667 version = null
668 from sourceSets.main.output
669}
670
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100671task R8NoManifest(type: ShadowJar) {
672 from consolidatedLicense.outputs.files
673 baseName 'r8nomanifest'
674 classifier = null
675 version = null
676 // In order to build without dependencies, pass the exclude_deps property using:
677 // gradle -Pexclude_deps R8
678 if (!project.hasProperty('exclude_deps')) {
679 from repackageSources.outputs.files
680 from repackageDeps.outputs.files
681 } else {
682 from sourceSets.main.output
683 }
Ian Zerny80533c92019-01-24 10:32:09 +0100684 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100685}
686
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000687task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200688 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200689 baseName 'd8'
690 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200691 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200692 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200693}
694
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200695task CompatDx(type: ShadowJar) {
696 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200697 baseName 'compatdx'
698 manifest {
699 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
700 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200701}
702
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200703task CompatProguard(type: ShadowJar) {
704 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200705 baseName 'compatproguard'
706 manifest {
707 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
708 }
Lars Bak44cef522017-08-10 16:02:39 +0200709}
710
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100711def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100712 // Execute r8 commands against a stable r8 with relocated dependencies.
713 return ["java", "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100714}
715
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100716def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100717 return baseR8CommandLine([
718 "--classfile", "--release",
719 input,
720 "--output", output,
721 "--pg-conf", pgconf,
722 "--pg-map-output", output + ".map",
723 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
724 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100725}
726
727def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
728 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100729 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100730 outputs.file output
731 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100732 dependsOn r8WithRelocatedDeps
733 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100734 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
735 workingDir = projectDir
736 }
737}
738
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100739task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100740 baseName = "r8tests"
741 from sourceSets.test.output
742}
743
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100744task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
745 baseName = "r8tests-exclude-deps"
746 from sourceSets.test.output
747}
748
749def generateR8LibKeepRules(name, r8Source, testSource, output) {
750 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
751 doFirst {
752 standardOutput new FileOutputStream(output)
753 }
754 dependsOn r8WithRelocatedDeps
755 dependsOn r8Source
756 dependsOn testSource
757 dependsOn downloadOpenJDKrt
758 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
759 outputs.file output
760 commandLine baseR8CommandLine([
761 "printuses",
762 "--keeprules",
763 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
764 r8Source.outputs.files[0],
765 testSource.outputs.files[0]])
766 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100767 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100768}
769
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100770task R8LibApiOnly {
771 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
772 outputs.file r8LibPath
773}
774
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100775task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100776 def genRulesTask = generateR8LibKeepRules(
777 "Main",
778 R8NoManifest,
779 testJar,
780 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100781 dependsOn r8LibCreateTask(
782 "Main",
783 "src/main/keep.txt",
784 R8NoManifest,
785 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100786 ["--pg-conf", genRulesTask.outputs.files[0]]
787 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100788 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100789}
790
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100791task R8LibNoDeps {
792 def genRulesTask = generateR8LibKeepRules(
793 "NoDeps",
794 R8NoManifestNoDeps,
795 testJarNoDeps,
796 r8LibGeneratedKeepRulesExcludeDepsPath
797 )
798 dependsOn r8LibCreateTask(
799 "NoDeps",
800 "src/main/keep.txt",
801 R8NoManifestNoDeps,
802 r8LibExludeDepsPath,
803 ["--pg-conf", genRulesTask.outputs.files[0]],
804 repackageDepsNoRelocate.outputs.files
805 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
806 outputs.file r8LibExludeDepsPath
807}
808
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100809task CompatDxLib {
810 dependsOn r8LibCreateTask(
811 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100812}
813
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100814task CompatProguardLib {
815 dependsOn r8LibCreateTask(
816 "CompatPg",
817 "src/main/keep-compatproguard.txt",
818 CompatProguard,
819 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100820}
821
Mads Ager418d1ca2017-05-22 09:35:49 +0200822task sourceJar(type: Jar, dependsOn: classes) {
823 classifier = 'src'
824 from sourceSets.main.allSource
825}
826
827task jctfCommonJar(type: Jar) {
828 from sourceSets.jctfCommon.output
829 baseName 'jctfCommon'
830}
831
832artifacts {
833 archives sourceJar
834}
835
836task createArtTests(type: Exec) {
837 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200838 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100839 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200840 outputs.dir outputDir
841 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200842 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200843 workingDir = projectDir
844}
845
846task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200847 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200848 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200849 inputs.file script
850 outputs.dir outputDir
851 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200852 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200853 workingDir = projectDir
854}
855
856compileTestJava {
857 dependsOn createArtTests
858 dependsOn createJctfTests
859}
860
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100861task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
862 from sourceSets.cfSegments.output
863 baseName 'cf_segments'
864 destinationDir file('build/libs')
865}
866
Ian Zernyee23a172018-01-03 09:08:48 +0100867task buildD8ApiUsageSample(type: Jar) {
868 from sourceSets.apiUsageSample.output
869 baseName 'd8_api_usage_sample'
870 destinationDir file('tests')
871}
872
Ian Zerny923a0c12018-01-03 10:59:18 +0100873task buildR8ApiUsageSample(type: Jar) {
874 from sourceSets.apiUsageSample.output
875 baseName 'r8_api_usage_sample'
876 destinationDir file('tests')
877}
878
Yohann Roussel548ae942018-01-05 11:13:28 +0100879task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100880 dependsOn buildD8ApiUsageSample
881 dependsOn buildR8ApiUsageSample
882}
883
Mads Ager418d1ca2017-05-22 09:35:49 +0200884task buildDebugInfoExamplesDex {
885 def examplesDir = file("src/test/java")
886 def hostJar = "debuginfo_examples.jar"
887 def hostDexJar = "debuginfo_examples_dex.jar"
888 task "compile_debuginfo_examples"(type: JavaCompile) {
889 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
890 destinationDir = file("build/test/debuginfo_examples/classes")
891 classpath = sourceSets.main.compileClasspath
892 sourceCompatibility = JavaVersion.VERSION_1_7
893 targetCompatibility = JavaVersion.VERSION_1_7
894 options.compilerArgs += ["-Xlint:-options"]
895 }
896 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
897 archiveName = hostJar
898 destinationDir = file("build/test/")
899 from "build/test/debuginfo_examples/classes"
900 include "**/*.class"
901 }
902 task "dex_debuginfo_examples"(type: Exec,
903 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200904 if (OperatingSystem.current().isWindows()) {
905 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700906 } else if (OperatingSystem.current().isMacOsX()) {
907 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200908 } else {
909 executable file("tools/linux/dx/bin/dx");
910 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200911 args "--dex"
912 args "--output=build/test/${hostDexJar}"
913 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100914 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200915 outputs.file file("build/test/${hostDexJar}")
916 }
917 dependsOn dex_debuginfo_examples
918}
919
920task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200921 def resourcesDir = file("src/test/debugTestResources")
922 def hostJar = "debug_test_resources.jar"
923 task "compile_debugTestResources"(type: JavaCompile) {
924 source = fileTree(dir: resourcesDir, include: '**/*.java')
925 destinationDir = file("build/test/debugTestResources/classes")
926 classpath = sourceSets.main.compileClasspath
927 sourceCompatibility = JavaVersion.VERSION_1_7
928 targetCompatibility = JavaVersion.VERSION_1_7
929 options.compilerArgs += ["-g", "-Xlint:-options"]
930 }
931 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
932 archiveName = hostJar
933 destinationDir = file("build/test/")
934 from "build/test/debugTestResources/classes"
935 include "**/*.class"
936 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200937 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
938 def java8HostJar = "debug_test_resources_java8.jar"
939 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
940 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
941 destinationDir = file("build/test/debugTestResourcesJava8/classes")
942 classpath = sourceSets.main.compileClasspath
943 sourceCompatibility = JavaVersion.VERSION_1_8
944 targetCompatibility = JavaVersion.VERSION_1_8
945 options.compilerArgs += ["-g", "-Xlint:-options"]
946 }
947 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
948 archiveName = java8HostJar
949 destinationDir = file("build/test/")
950 from "build/test/debugTestResourcesJava8/classes"
951 include "**/*.class"
952 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200953 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000954 def kotlinHostJar = "debug_test_resources_kotlin.jar"
955 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
956 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
957 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200958 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200959 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200960 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200961 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000962 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200963}
964
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100965// Examples used by tests, where Android specific APIs are used.
966task buildExampleAndroidApi(type: JavaCompile) {
967 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
968 destinationDir = file("build/test/examplesAndroidApi/classes")
969 classpath = files("third_party/android_jar/lib-v26/android.jar")
970 sourceCompatibility = JavaVersion.VERSION_1_8
971 targetCompatibility = JavaVersion.VERSION_1_8
972}
973
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100974task buildExampleKotlinJars {
975 def kotlinSrcDir = file("src/test/examplesKotlin")
976 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000977 def name = dir.getName();
978 dependsOn "compile_example_kotlin_${name}"
979 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
980 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
981 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100982 }
983 }
984}
985
Lars Bakc91e87e2017-08-18 08:53:10 +0200986// Proto lite generated code yields warnings when compiling with javac.
987// We change the options passed to javac to ignore it.
988compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
989
Søren Gjesse7320ce52018-05-07 15:45:22 +0200990
Mads Ager418d1ca2017-05-22 09:35:49 +0200991task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200992 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200993 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200994 def proguardScript
995 if (OperatingSystem.current().isWindows()) {
996 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
997 } else {
998 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
999 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001000 task extractExamplesRuntime(type: Sync) {
1001 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001002 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001003 include "**/*.class"
1004 includeEmptyDirs false
1005 into "$buildDir/runtime/examples/"
1006 }
1007
Søren Gjesse7320ce52018-05-07 15:45:22 +02001008 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1009 from examplesDir
1010 exclude "**/*.java"
1011 exclude "**/keep-rules*.txt"
1012 into file("build/test/examples/classes")
1013 }
1014
1015 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001016 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001017 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001018 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001019 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001020 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001021 sourceCompatibility = JavaVersion.VERSION_1_7
1022 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001023 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1024 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001025 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1026 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001027 include "**/*.java"
1028 destinationDir = file("build/test/examples/classes_debuginfo_all")
1029 classpath = sourceSets.examples.compileClasspath
1030 sourceCompatibility = JavaVersion.VERSION_1_7
1031 targetCompatibility = JavaVersion.VERSION_1_7
1032 options.compilerArgs = ["-g", "-Xlint:none"]
1033 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001034 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1035 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001036 include "**/*.java"
1037 destinationDir = file("build/test/examples/classes_debuginfo_none")
1038 classpath = sourceSets.examples.compileClasspath
1039 sourceCompatibility = JavaVersion.VERSION_1_7
1040 targetCompatibility = JavaVersion.VERSION_1_7
1041 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001042 }
1043 examplesDir.eachDir { dir ->
1044 def name = dir.getName();
1045 def exampleOutputDir = file("build/test/examples");
1046 def jarName = "${name}.jar"
1047 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001048 dependsOn "jar_example_${name}_debuginfo_all"
1049 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001050 dependsOn "extractExamplesRuntime"
1051 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001052 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1053 def proguardConfigPath = "${dir}/proguard.cfg"
1054 if (new File(proguardConfigPath).exists()) {
1055 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1056 archiveName = "${name}_pre_proguard.jar"
1057 destinationDir = exampleOutputDir
1058 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001059 include name + "/**/*.class"
1060 with runtimeDependencies
1061 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001062 }
1063 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1064 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1065 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1066 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001067 inputs.files files(
1068 tasks.getByPath("pre_proguard_example_${name}"),
1069 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001070 // Enable these to get stdout and stderr redirected to files...
1071 // standardOutput = new FileOutputStream('proguard.stdout')
1072 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001073 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001074 " -outjars ${proguardJarPath}" +
1075 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001076 " -printmapping ${proguardMapPath}"
1077 if (OperatingSystem.current().isWindows()) {
1078 executable "${proguardScript}"
1079 args "${proguardArguments}"
1080 } else {
1081 executable "bash"
1082 args "-c", "${proguardScript} '${proguardArguments}'"
1083 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001084 outputs.file proguardJarPath
1085 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001086 // TODO: Consider performing distinct proguard compilations.
1087 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1088 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001089 into "${exampleOutputDir}"
1090 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001091 }
1092 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1093 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001094 into "${exampleOutputDir}"
1095 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001096 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001097 } else {
1098 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001099 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001100 destinationDir = exampleOutputDir
1101 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001102 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001103 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001104 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001105 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001106 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1107 archiveName = "${name}_debuginfo_all.jar"
1108 destinationDir = exampleOutputDir
1109 from "build/test/examples/classes_debuginfo_all"
1110 include name + "/**/*.class"
1111 with runtimeDependencies
1112 includeEmptyDirs false
1113 }
1114 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1115 archiveName = "${name}_debuginfo_none.jar"
1116 destinationDir = exampleOutputDir
1117 from "build/test/examples/classes_debuginfo_none"
1118 include name + "/**/*.class"
1119 with runtimeDependencies
1120 includeEmptyDirs false
1121 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001122 }
1123 }
1124}
1125
1126task buildExampleAndroidNJars {
1127 dependsOn downloadDeps
1128 def examplesDir = file("src/test/examplesAndroidN")
1129 task "compile_examplesAndroidN"(type: JavaCompile) {
1130 source = fileTree(dir: examplesDir, include: '**/*.java')
1131 destinationDir = file("build/test/examplesAndroidN/classes")
1132 classpath = sourceSets.main.compileClasspath
1133 sourceCompatibility = JavaVersion.VERSION_1_8
1134 targetCompatibility = JavaVersion.VERSION_1_8
1135 options.compilerArgs += ["-Xlint:-options"]
1136 }
1137 examplesDir.eachDir { dir ->
1138 def name = dir.getName();
1139 def exampleOutputDir = file("build/test/examplesAndroidN");
1140 def jarName = "${name}.jar"
1141 dependsOn "jar_examplesAndroidN_${name}"
1142 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1143 archiveName = jarName
1144 destinationDir = exampleOutputDir
1145 from "build/test/examplesAndroidN/classes"
1146 include "**/" + name + "/**/*.class"
1147 }
1148 }
1149}
1150
1151
1152task buildExampleAndroidOJars {
1153 dependsOn downloadDeps
1154 def examplesDir = file("src/test/examplesAndroidO")
1155 // NOTE: we want to enable a scenario when test needs to reference some
1156 // classes generated by legacy (1.6) Java compiler to test some specific
1157 // behaviour. To do so we compile all the java files located in sub-directory
1158 // called 'legacy' with Java 1.6, then compile the rest of the files with
1159 // Java 1.8 and a reference to previously generated 1.6 classes.
1160
1161 // Compiling all classes in dirs 'legacy' with old Java version.
1162 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1163 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1164 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1165 classpath = sourceSets.main.compileClasspath
1166 sourceCompatibility = JavaVersion.VERSION_1_6
1167 targetCompatibility = JavaVersion.VERSION_1_6
1168 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1169 }
1170 // Compiling the rest of the files as Java 1.8 code.
1171 task "compile_examplesAndroidO"(type: JavaCompile) {
1172 dependsOn "compile_examplesAndroidO_Legacy"
1173 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1174 destinationDir = file("build/test/examplesAndroidO/classes")
1175 classpath = sourceSets.main.compileClasspath
1176 classpath += files("build/test/examplesAndroidOLegacy/classes")
1177 sourceCompatibility = JavaVersion.VERSION_1_8
1178 targetCompatibility = JavaVersion.VERSION_1_8
1179 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1180 }
1181 examplesDir.eachDir { dir ->
1182 def name = dir.getName();
1183 def destinationDir = file("build/test/examplesAndroidO/classes");
1184 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1185 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1186 dependsOn: "compile_examplesAndroidO") {
1187 main = name + ".TestGenerator"
1188 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1189 args destinationDir
1190 }
1191 } else {
1192 task "generate_examplesAndroidO_${name}" () {}
1193 }
1194 }
1195 examplesDir.eachDir { dir ->
1196 def name = dir.getName();
1197 def exampleOutputDir = file("build/test/examplesAndroidO");
1198 def jarName = "${name}.jar"
1199 dependsOn "jar_examplesAndroidO_${name}"
1200 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1201 "generate_examplesAndroidO_${name}"]) {
1202 archiveName = jarName
1203 destinationDir = exampleOutputDir
1204 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1205 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1206 include "**/" + name + "/**/*.class"
1207 // Do not include generator into the test runtime jar, it is not useful.
1208 // Otherwise, shrinking will need ASM jars.
1209 exclude "**/TestGenerator*"
1210 }
1211 }
1212}
1213
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001214task buildExampleAndroidPJars {
1215 dependsOn downloadDeps
1216 def examplesDir = file("src/test/examplesAndroidP")
1217
1218 task "compile_examplesAndroidP"(type: JavaCompile) {
1219 source = fileTree(dir: examplesDir, include: '**/*.java')
1220 destinationDir = file("build/test/examplesAndroidP/classes")
1221 classpath = sourceSets.main.compileClasspath
1222 sourceCompatibility = JavaVersion.VERSION_1_8
1223 targetCompatibility = JavaVersion.VERSION_1_8
1224 options.compilerArgs += ["-Xlint:-options"]
1225 }
1226 examplesDir.eachDir { dir ->
1227 def name = dir.getName();
1228 def destinationDir = file("build/test/examplesAndroidP/classes");
1229 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1230 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1231 dependsOn: "compile_examplesAndroidP") {
1232 main = name + ".TestGenerator"
1233 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1234 args destinationDir
1235 }
1236 } else {
1237 task "generate_examplesAndroidP_${name}" () {}
1238 }
1239 }
1240 examplesDir.eachDir { dir ->
1241 def name = dir.getName();
1242 def exampleOutputDir = file("build/test/examplesAndroidP");
1243 def jarName = "${name}.jar"
1244 dependsOn "jar_examplesAndroidP_${name}"
1245 task "jar_examplesAndroidP_${name}"(type: Jar,
1246 dependsOn: ["compile_examplesAndroidP",
1247 "generate_examplesAndroidP_${name}"]) {
1248 archiveName = jarName
1249 destinationDir = exampleOutputDir
1250 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1251 include "**/" + name + "/**/*.class"
1252 // Do not include generator into the test runtime jar, it is not useful.
1253 // Otherwise, shrinking will need ASM jars.
1254 exclude "**/TestGenerator*"
1255 }
1256 }
1257}
1258
Mikaël Peltier61633d42017-10-13 16:51:06 +02001259task buildExampleJava9Jars {
1260 def examplesDir = file("src/test/examplesJava9")
1261 examplesDir.eachDir { dir ->
1262 def name = dir.getName();
1263 def exampleOutputDir = file("build/test/examplesJava9");
1264 def jarName = "${name}.jar"
1265 dependsOn "jar_examplesJava9_${name}"
1266 task "jar_examplesJava9_${name}"(type: Jar) {
1267 archiveName = jarName
1268 destinationDir = exampleOutputDir
1269 from "src/test/examplesJava9" // Java 1.9 classes
1270 include "**/" + name + "/**/*.class"
1271 }
1272 }
1273}
1274
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001275task buildExamplesKotlin {
1276 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1277 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1278 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1279 } else if (!OperatingSystem.current().isLinux()) {
1280 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1281 "on your platform. It is fully supported on Linux and partially supported on " +
1282 "Mac OS and Windows")
1283 return;
1284 }
1285 def examplesDir = file("src/test/examplesKotlin")
1286 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001287 def name = dir.getName();
1288 dependsOn "dex_example_kotlin_${name}"
1289 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1290 def dexPath = file("${exampleOutputDir}")
1291 task "dex_example_kotlin_${name}"(type: dx.Dx,
1292 dependsOn: "compile_example_kotlin_${name}") {
1293 doFirst {
1294 if (!dexPath.exists()) {
1295 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001296 }
1297 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001298 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1299 destination = dexPath
1300 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001301 }
1302 }
1303}
1304
Sebastien Hertzd3313772018-01-16 14:12:37 +01001305task buildKotlinR8TestResources {
1306 def examplesDir = file("src/test/kotlinR8TestResources")
1307 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001308 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1309 def name = dir.getName()
1310 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001311 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1312 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001313 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001314 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001315 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1316 source = fileTree(dir: file("${examplesDir}/${name}"),
1317 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001318 destination = file(outputFile)
1319 targetVersion = kotlinTargetVersion
1320 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001321 task "${taskName}Java"(type: JavaCompile) {
1322 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1323 destinationDir = file(javaOutput)
1324 classpath = sourceSets.main.compileClasspath
1325 sourceCompatibility = JavaVersion.VERSION_1_6
1326 targetCompatibility = JavaVersion.VERSION_1_6
1327 options.compilerArgs += ["-g", "-Xlint:-options"]
1328 }
1329 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1330 archiveName = javaOutputJarName
1331 destinationDir = file(javaOutputJarDir)
1332 from javaOutput
1333 include "**/*.class"
1334 }
1335 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001336 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001337 }
1338}
1339
Mads Ager418d1ca2017-05-22 09:35:49 +02001340task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001341 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1342 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1343 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001344 } else if (!OperatingSystem.current().isLinux()) {
1345 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001346 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001347 return;
1348 }
1349 dependsOn buildDebugTestResourcesJars
1350 dependsOn buildExampleJars
1351 dependsOn buildExampleAndroidNJars
1352 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001353 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001354 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001355 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001356 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001357 def noDexTests = [
1358 "multidex",
1359 "multidex002",
1360 "multidex004",
1361 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001362 examplesDir.eachDir { dir ->
1363 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001364 if (!(name in noDexTests)) {
1365 dependsOn "dex_example_${name}"
1366 def exampleOutputDir = file("build/test/examples/" + name);
1367 def dexPath = file("${exampleOutputDir}")
1368 def debug = (name == "throwing")
1369 if (!dexPath.exists()) {
1370 dexPath.mkdirs()
1371 }
1372 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1373 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1374 destination = dexPath
1375 debug = debug
1376 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001377 }
1378 }
1379}
1380
1381task buildSmali {
1382 def smaliDir = file("src/test/smali")
1383 smaliDir.eachDirRecurse() { dir ->
1384 def name = dir.getName();
1385 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1386 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1387 smaliOutputDir.mkdirs()
1388 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001389 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001390 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1391 def javaFiles = fileTree(dir: dir, include: '*.java')
1392 def destDir = smaliOutputDir;
1393 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1394 def intermediateFileName = "${name}-intermediate.dex";
1395 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1396 if (javaFiles.empty) {
1397 if (!smaliFiles.empty) {
1398 dependsOn "${taskName}_smali"
1399 task "${taskName}_smali"(type: smali.Smali) {
1400 source = smaliFiles
1401 destination = destFile
1402 }
1403 }
1404 } else {
1405 dependsOn "${taskName}_dexmerger"
1406 task "${taskName}_smali"(type: smali.Smali) {
1407 source = smaliFiles
1408 destination = intermediateFile
1409 }
1410 task "${taskName}_java"(type: JavaCompile) {
1411 source = javaFiles
1412 destinationDir destDir
1413 classpath = sourceSets.main.compileClasspath
1414 sourceCompatibility = JavaVersion.VERSION_1_7
1415 targetCompatibility = JavaVersion.VERSION_1_7
1416 options.compilerArgs += ["-Xlint:-options"]
1417 }
1418 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1419 archiveName = "Test.jar"
1420 destinationDir = destDir
1421 from fileTree(dir: destDir, include: 'Test.class')
1422 }
1423 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1424 source = fileTree(dir: destDir, include: 'Test.jar')
1425 destination = destDir
1426 }
1427 task "${taskName}_dexmerger"(
1428 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1429 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1430 destination = destFile
1431 }
1432 }
1433 }
1434}
1435
1436tasks.withType(Test) {
1437 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1438 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1439 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1440 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1441 forkEvery = 0
1442 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1443 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001444 if (project.hasProperty('disable_assertions')) {
1445 enableAssertions = false
1446 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001447 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1448 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001449}
1450
1451task buildPreNJdwpTestsJar(type: Jar) {
1452 baseName = 'jdwp-tests-preN'
1453 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1454 // Exclude the classes containing java8
1455 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1456 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1457 includeEmptyDirs = false
1458}
1459
Ian Zerny74143162017-11-24 13:46:35 +01001460task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1461 def inFile = buildPreNJdwpTestsJar.archivePath
1462 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001463 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001464 outputs.file outFile
1465 if (OperatingSystem.current().isWindows()) {
1466 executable file("tools/windows/dx/bin/dx.bat")
1467 } else if (OperatingSystem.current().isMacOsX()) {
1468 executable file("tools/mac/dx/bin/dx");
1469 } else {
1470 executable file("tools/linux/dx/bin/dx");
1471 }
1472 args "--dex"
1473 args "--output=${outFile}"
1474 args inFile
1475}
1476
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001477task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1478 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001479}
1480
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001481task AospJarTest(type: Exec) {
1482 dependsOn CompatDx, downloadDeps
1483 def script = "tools/test_aosp_jar.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001484 inputs.files files(script)
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001485 commandLine "python", script, "--no-build"
1486 workingDir = projectDir
1487}
1488
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001489def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001490 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001491 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001492 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001493 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001494 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001495 return null
1496}
1497
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001498task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001499 dependsOn testJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001500 inputs.files files("$buildDir/libs/r8tests.jar")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001501 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001502 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001503 delete r8LibTestPath
1504 from zipTree(testJar.outputs.files[0])
1505 into r8LibTestPath
1506 include "com/android/tools/r8/**"
1507 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001508 }
1509 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001510}
1511
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001512def printStackTrace(TestResult result) {
1513 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1514 def out = new StringBuffer()
1515 def err = new StringBuffer()
1516 def command = "tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001517 def header = "RETRACED STACKTRACE";
1518 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1519 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1520 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1521 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001522 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001523 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001524 out.append("--------------------------------------\n")
1525 Process process = command.execute()
1526 def processIn = new PrintStream(process.getOut())
1527 process.consumeProcessOutput(out, err)
1528 result.exception.printStackTrace(processIn)
1529 processIn.flush()
1530 processIn.close()
1531 process.waitFor()
1532 out.append("\n\n--------------------------------------\n")
1533 out.append("OBFUSCATED STACKTRACE\n")
1534 out.append("--------------------------------------\n")
1535 result.exceptions.add(0, new Exception(out.toString()))
1536 } else {
1537 result.exception.printStackTrace()
1538 }
1539}
1540
Mads Ager418d1ca2017-05-22 09:35:49 +02001541test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001542 if (project.hasProperty('generate_golden_files_to')) {
1543 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1544 assert project.hasProperty('HEAD_sha1')
1545 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1546 }
1547
1548 if (project.hasProperty('use_golden_files_in')) {
1549 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1550 assert project.hasProperty('HEAD_sha1')
1551 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1552 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001553 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001554 // R8.jar is required for running bootstrap tests.
1555 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001556 testLogging.exceptionFormat = 'full'
1557 if (project.hasProperty('print_test_stdout')) {
1558 testLogging.showStandardStreams = true
1559 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001560 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001561 println "Running with non default vm: " + project.property('dex_vm')
1562 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001563 if (project.property('dex_vm').startsWith('4.4.4') ||
1564 project.property('dex_vm').startsWith('5.1.1') ||
1565 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001566 // R8 and D8 compute the dex file version number based on the input.
1567 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1568 // Therefore we skip the jack generated art tests with those art versions.
1569 exclude "com/android/tools/r8/art/jack/**"
1570 }
1571 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001572
Mads Ager418d1ca2017-05-22 09:35:49 +02001573 if (project.hasProperty('one_line_per_test')) {
1574 beforeTest { desc ->
1575 println "Start executing test ${desc.name} [${desc.className}]"
1576 }
1577 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001578 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001579 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001580 }
Rico Windda6836e2018-12-07 12:32:03 +01001581 if (project.hasProperty('update_test_timestamp')) {
1582 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1583 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001584 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1585 }
Rico Windf88b6be2018-12-11 15:14:05 +01001586 } else {
1587 afterTest { desc, result ->
1588 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001589 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001590 }
1591 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001592 }
1593 if (project.hasProperty('no_internal')) {
1594 exclude "com/android/tools/r8/internal/**"
1595 }
1596 if (project.hasProperty('only_internal')) {
1597 include "com/android/tools/r8/internal/**"
1598 }
1599 if (project.hasProperty('tool')) {
1600 if (project.property('tool') == 'r8') {
1601 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001602 exclude "com/android/tools/r8/jctf/d8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001603 exclude "com/android/tools/r8/jctf/r8cf/**"
1604 } else if (project.property('tool') == 'd8') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001605 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001606 exclude "com/android/tools/r8/jctf/r8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001607 exclude "com/android/tools/r8/jctf/r8cf/**"
1608 } else {
1609 assert(project.property('tool') == 'r8cf')
1610 exclude "com/android/tools/r8/art/*/d8/**"
1611 exclude "com/android/tools/r8/art/*/r8/**"
1612 exclude "com/android/tools/r8/jctf/d8/**"
1613 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001614 }
1615 }
1616 if (!project.hasProperty('all_tests')) {
1617 exclude "com/android/tools/r8/art/dx/**"
1618 exclude "com/android/tools/r8/art/jack/**"
1619 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001620 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001621 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001622 }
1623 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001624 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001625 }
1626 if (project.hasProperty('jctf_compile_only')) {
1627 println "JCTF: compiling only"
1628 systemProperty 'jctf_compile_only', '1'
1629 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001630 if (project.hasProperty('test_dir')) {
1631 systemProperty 'test_dir', project.property('test_dir')
1632 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001633 if (project.hasProperty('aosp_jar')) {
1634 dependsOn AospJarTest
1635 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001636 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1637 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001638 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1639 // all needed tests in r8LibTestPath.
1640 classpath = files([r8LibPath, r8LibTestPath]) +
1641 sourceSets.test.runtimeClasspath -
1642 sourceSets.main.output -
1643 files(['build/classes/test'])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001644 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001645 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001646 if (OperatingSystem.current().isLinux()
1647 || OperatingSystem.current().isMacOsX()
1648 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001649 if (OperatingSystem.current().isMacOsX()) {
1650 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1651 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1652 "See tools/docker/README.md for details.")
1653 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001654 if (OperatingSystem.current().isWindows()) {
1655 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1656 "Art only runs on Linux and tests requiring Art will be skipped")
1657 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001658 dependsOn downloadDeps
1659 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001660 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001661 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001662 dependsOn buildSmali
1663 dependsOn jctfCommonJar
1664 dependsOn jctfTestsClasses
1665 dependsOn buildDebugInfoExamplesDex
1666 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001667 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001668 } else {
1669 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001670 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001671 }
1672}
1673
1674// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1675//
1676// To build and upload a new set of the Art tests for use with R8 follow these steps:
1677//
1678// First of all an Android checkout is required. Currently it must be located
1679// in $HOME/android/master.
1680//
1681// TODO(ricow): simplify this
1682//
1683// Before: update the checked in art, see scripts/update-host-art.sh
1684//
1685// 1. Get an android checkout in $HOME/android/master and apply the patch from
1686// https://android-review.googlesource.com/#/c/294187/
1687//
1688// 2. run the following commands in the Android checkout directory:
1689//
1690// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001691// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1692// m desugar
1693// m -j30 test-art-host
1694// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1695//
1696// Without running the test.py command the classes.jar file used by desugar in
1697// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1698// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001699//
1700// 3. In the R8 project root directory, make sure we have a clean state before starting:
1701// tools/gradle.py downloadDeps
1702// tools/gradle.py clean
1703// rm -rf tests/art
1704//
1705// 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 +02001706// Make sure you have smali on your path, please use the build binary in the
1707// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1708// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1709// 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 +02001710// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1711// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001712//
Søren Gjesse34b77732017-07-07 13:56:21 +02001713// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001714//
1715// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1716// skippedTests with an explanation. Rerun from step 3.
1717//
1718// 5. Run the tests:
1719// tools/gradle.py clean
1720// tools/test.py
1721//
Søren Gjesse34b77732017-07-07 13:56:21 +02001722// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1723// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1724// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001725//
Søren Gjesse34b77732017-07-07 13:56:21 +02001726// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001727// cd tests
1728// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001729//
1730// 7. Update the manifest file describing the Android repo used:
1731// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001732
1733enum DexTool {
1734 JACK,
1735 DX
1736}
1737
1738def androidCheckoutDir = file("${System.env.HOME}/android/master")
1739def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1740def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1741
1742def artTestDir = file("${androidCheckoutDir}/art/test")
1743
1744if (project.hasProperty('android_source')) {
1745 task buildArtTests {
1746 outputs.upToDateWhen { false }
1747 def toBeTriaged = [
1748 "903-hello-tagging",
1749 "904-object-allocation",
1750 "905-object-free",
1751 "906-iterate-heap",
1752 "907-get-loaded-classes",
1753 "908-gc-start-finish",
1754 "954-invoke-polymorphic-verifier",
1755 "955-methodhandles-smali",
1756 "596-monitor-inflation",
1757 ]
1758 def skippedTests = toBeTriaged + [
1759 // This test produces no jar.
1760 "000-nop",
1761 // This does not build, as it tests the error when the application exceeds more
1762 // than 65536 methods
1763 "089-many-methods",
1764 // Requires some jack beta jar
1765 "956-methodhandles",
1766 ]
1767
1768 def skippedTestsDx = [
1769 // Tests with custom build scripts, where javac is not passed the options
1770 // -source 1.7 -target 1.7.
1771 "462-checker-inlining-across-dex-files",
1772 "556-invoke-super",
1773 "569-checker-pattern-replacement",
1774 // These tests use jack even when --build-with-javac-dx is specified.
1775 "004-JniTest",
1776 "048-reflect-v8",
1777 "146-bad-interface",
1778 "563-checker-invoke-super",
1779 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1780 "604-hot-static-interface",
1781 "957-methodhandle-transforms",
1782 "958-methodhandle-emulated-stackframe",
1783 "959-invoke-polymorphic-accessors",
1784 "961-default-iface-resolution-gen",
1785 "962-iface-static",
1786 "963-default-range-smali",
1787 "964-default-iface-init-gen",
1788 "965-default-verify",
1789 "966-default-conflict",
1790 "967-default-ame",
1791 "968-default-partial-compile-gen",
1792 "969-iface-super",
1793 "970-iface-super-resolution-gen",
1794 "971-iface-super",
1795 // These tests does not build with --build-with-javac-dx
1796 "004-NativeAllocations", // Javac error
1797 "031-class-attributes",
1798 "138-duplicate-classes-check",
1799 "157-void-class", // Javac error
1800 "580-checker-string-factory-intrinsics",
1801 "612-jit-dex-cache",
1802 "613-inlining-dex-cache",
1803 "900-hello-plugin", // --experimental agents
1804 "901-hello-ti-agent", // --experimental agents
1805 "902-hello-transformation", // --experimental agents
1806 "909-attach-agent", // --experimental agents
1807 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1808 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1809 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1810 "960-default-smali", // --experimental default-methods
1811 // These tests force the build to use jack
1812 "953-invoke-polymorphic-compiler",
1813 "958-methodhandle-stackframe",
1814 ]
1815
1816 def artTestBuildDir = file("${projectDir}/tests/art")
1817
1818 if (androidCheckoutDir.exists()) {
1819 dependsOn downloadDeps
1820 artTestBuildDir.mkdirs()
1821 // Ensure Jack server is running.
1822 "${androidCheckoutJackServer} start-server".execute()
1823 artTestDir.eachDir { dir ->
1824 def name = dir.getName();
1825 def markerFile = dir.toPath().resolve("info.txt").toFile();
1826 if (markerFile.exists() && !(name in skippedTests)) {
1827 if (!(name in skippedTestsDx)) {
1828 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1829 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001830 // After Android O, Jack is no longer alive
1831 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001832 }
1833 }
1834 }
1835 doFirst {
1836 if (!androidCheckoutDir.exists()) {
1837 throw new InvalidUserDataException(
1838 "This task requires an Android checkout in ${androidCheckoutDir}");
1839 } else if (!androidCheckoutJack.exists() ||
1840 !androidCheckoutJackServer.exists()) {
1841 throw new InvalidUserDataException(
1842 "This task requires that tools for host testing have been build in the " +
1843 "Android checkout in ${androidCheckoutDir}");
1844 }
1845 }
1846 doLast {
1847 copy {
1848 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1849 into file("${artTestBuildDir}/lib64")
1850 include 'lib*.so'
1851 }
1852 copy {
1853 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1854 into file("${artTestBuildDir}/lib64")
1855 include 'libart.so'
1856 include 'libbacktrace.so'
1857 include 'libbase.so'
1858 include 'libc++.so'
1859 include 'libcutils.so'
1860 include 'liblz4.so'
1861 include 'liblzma.so'
1862 include 'libnativebridge.so'
1863 include 'libnativeloader.so'
1864 include 'libsigchain.so'
1865 include 'libunwind.so'
1866 include 'libziparchive.so'
1867 }
1868 copy {
1869 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1870 into file("${artTestBuildDir}/lib")
1871 include 'lib*.so'
1872 }
1873 copy {
1874 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1875 into file("${artTestBuildDir}/lib")
1876 include 'libart.so'
1877 include 'libbacktrace.so'
1878 include 'libbase.so'
1879 include 'libc++.so'
1880 include 'libcutils.so'
1881 include 'liblz4.so'
1882 include 'liblzma.so'
1883 include 'libnativebridge.so'
1884 include 'libnativeloader.so'
1885 include 'libsigchain.so'
1886 include 'libunwind.so'
1887 include 'libziparchive.so'
1888 }
1889 }
1890 }
1891}
1892
1893def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1894 def artTestDir = file("${androidCheckoutDir}/art/test")
1895 def artRunTestScript = file("${artTestDir}/run-test")
1896 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001897 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001898 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1899
Søren Gjesse34b77732017-07-07 13:56:21 +02001900 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001901 def buildTask = "build_art_test_${dexToolName}_${name}"
1902 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1903 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1904 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1905
1906 def buildInputs = fileTree(dir: dir, include: '**/*')
1907 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1908 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1909 testDir.mkdirs()
1910 if (dexTool == DexTool.DX) {
1911 task "$buildTask"(type: Exec) {
1912 outputs.upToDateWhen { false }
1913 inputs.file buildInputs
1914 executable "${artRunTestScript}"
1915 args "--host"
1916 args "--build-only"
1917 args "--build-with-javac-dx"
1918 args "--output-path", "${testDir}"
1919 args "${name}"
1920 environment DX: "${dxExecutable.absolutePath}"
1921 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001922 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001923 outputs.file outputJar
1924 }
1925 } else {
1926 assert dexTool == DexTool.JACK
1927 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1928 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1929 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1930 task "$buildTask"(type: Exec) {
1931 outputs.upToDateWhen { false }
1932 inputs.file buildInputs
1933 executable "${artRunTestScript}"
1934 args "--host"
1935 args "--build-only"
1936 args "--output-path", "${testDir}"
1937 args "${name}"
1938 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1939 environment JACK_CLASSPATH: jackClasspath
1940 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1941 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1942 outputs.file outputJar
1943 }
1944 }
1945 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1946 outputs.upToDateWhen { false }
1947 executable "/bin/bash"
1948 args "-c"
1949 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1950 " ${testDir}/classes-ex ${testDir}/check"
1951 }
1952
1953 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001954 // Directory that contains smali files is either smali, or smali/art
1955 def smali_dir = file("${dir}/smali/art")
1956 if (smali_dir.exists()) {
1957 workingDir "${testDir}/smali/art"
1958 } else {
1959 workingDir "${testDir}/smali"
1960 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001961 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001962 // This is the command line options for smali prior to 2.2.1, where smali got a new
1963 // command line interface.
1964 args "-c", "smali a *.smali"
1965 // This is the command line options for smali 2.2.1 and later.
1966 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001967 }
1968
1969 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1970 def smali_dir = file("${dir}/smali")
1971 outputs.upToDateWhen { false }
1972 if (smali_dir.exists() && dexTool == DexTool.DX) {
1973 dependsOn smaliToDexTask
1974 }
1975 from("${artTestDir}/${name}") {
1976 include 'check'
1977 }
1978 into testDir
1979 }
1980
1981 return copyCheckTask
1982}
1983
1984task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001985 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001986 classpath = sourceSets.main.compileClasspath
1987 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001988 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001989 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001990 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001991 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001992 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001993 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001994 include '**/com/android/tools/r8/CompilationMode.java'
1995 include '**/com/android/tools/r8/D8.java'
1996 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001997 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1998 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001999 include '**/com/android/tools/r8/Diagnostic.java'
2000 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002001 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2002 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002003 include '**/com/android/tools/r8/ProgramConsumer.java'
2004 include '**/com/android/tools/r8/ProgramResource.java'
2005 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002006 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002007 include '**/com/android/tools/r8/ResourceException.java'
2008 include '**/com/android/tools/r8/StringConsumer.java'
2009 include '**/com/android/tools/r8/StringResource.java'
2010 include '**/com/android/tools/r8/Version.java'
2011 include '**/com/android/tools/r8/origin/*.java'
2012}
2013
2014task javadocR8(type: Javadoc) {
2015 title "R8 API"
2016 classpath = sourceSets.main.compileClasspath
2017 source = sourceSets.main.allJava
2018 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2019 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2020 include '**/com/android/tools/r8/BaseCommand.java'
2021 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2022 include '**/com/android/tools/r8/ClassFileConsumer.java'
2023 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2024 include '**/com/android/tools/r8/CompilationFailedException.java'
2025 include '**/com/android/tools/r8/CompilationMode.java'
2026 include '**/com/android/tools/r8/R8.java'
2027 include '**/com/android/tools/r8/R8Command.java'
2028 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2029 include '**/com/android/tools/r8/Diagnostic.java'
2030 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002031 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2032 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002033 include '**/com/android/tools/r8/ProgramConsumer.java'
2034 include '**/com/android/tools/r8/ProgramResource.java'
2035 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2036 include '**/com/android/tools/r8/Resource.java'
2037 include '**/com/android/tools/r8/ResourceException.java'
2038 include '**/com/android/tools/r8/StringConsumer.java'
2039 include '**/com/android/tools/r8/StringResource.java'
2040 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002041 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002042}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002043
2044task copyMavenDeps(type: Copy) {
2045 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002046 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002047 from configurations.testCompile into "$buildDir/deps"
2048}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002049
2050// This task allows to build class files from Java 9 source in order to use them as inputs of
2051// D8/R8 tests. Class files are generated in the same place than source files and must be commited
2052// to the D8 repository because there is no way to generate them on all computers due to the need of
2053// Java 9.
2054// Use the following command to rebuild class files of tests:
2055// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
2056task buildJava9Tests {
2057 def javacOutputFolder = getTemporaryDir();
2058 def examplesDir = file("src/test/examplesJava9")
2059
2060 task "compile_Java9examples"(type: JavaCompile) {
2061 doFirst {
2062 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
2063 throw new GradleException("Set java9Home property.")
2064 }
2065 }
2066
2067 source = fileTree(dir: examplesDir, include: '**/*.java')
2068 destinationDir = javacOutputFolder
2069 classpath = sourceSets.main.compileClasspath
2070 options.compilerArgs += ["-Xlint:-options"]
2071 sourceCompatibility = JavaVersion.VERSION_1_9
2072 targetCompatibility = JavaVersion.VERSION_1_9
2073 options.fork = true
2074
2075 if (project.hasProperty('java9Home')) {
2076 options.forkOptions.javaHome = file(getProperty('java9Home'))
2077 }
2078
2079 doLast {
2080 def classfileFrom = copySpec {
2081 from javacOutputFolder
2082 include "**/*.class"
2083 }
2084 copy {
2085 into examplesDir
2086 with classfileFrom
2087 }
2088 delete javacOutputFolder
2089 }
2090 }
2091
2092 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02002093}