blob: 54a04a0f89276d9b20f543ad6d3f2f2725dddf6c [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
Ian Zerny5fffb0a2019-02-11 13:54:22 +01004
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +00005import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01006import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02007import org.gradle.internal.os.OperatingSystem
Ian Zernyb2d27c42019-02-20 09:09:41 +01008import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00009import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020010import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020011
Ian Zerny5fffb0a2019-02-11 13:54:22 +010012buildscript {
13 repositories {
14 mavenCentral()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010015 maven {
16 url "https://plugins.gradle.org/m2/"
17 }
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010018 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010019 }
20 dependencies {
21 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
22 }
23}
24
25plugins {
26 id "net.ltgt.errorprone" version "0.7"
27}
28
29apply plugin: 'java'
30apply plugin: 'idea'
31
Sebastien Hertz143ed112018-02-13 14:26:41 +010032ext {
33 androidSupportVersion = '25.4.0'
Gautam Korlam39d74202018-08-29 18:09:35 -070034 asmVersion = '6.2.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010035 espressoVersion = '3.0.0'
36 fastutilVersion = '7.2.0'
37 guavaVersion = '23.0'
38 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020039 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010040 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080041 mockitoVersion = '2.10.0'
Jinseong Jeon46146f42018-12-16 23:26:14 -080042 kotlinVersion = '1.3.11'
Jinseong Jeonb6fe4fe2018-12-03 00:49:13 -080043 kotlinExtMetadataJVMVersion = '0.0.4'
Sebastien Hertz143ed112018-02-13 14:26:41 +010044 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010045 errorproneVersion = '2.3.2'
Sebastien Hertz143ed112018-02-13 14:26:41 +010046}
47
Mads Ager418d1ca2017-05-22 09:35:49 +020048apply from: 'copyAdditionalJctfCommonFiles.gradle'
49
50repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020051 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020052 mavenCentral()
Morten Krogh-Jespersene45b0f92019-03-21 09:56:19 +010053 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020054}
55
Jinseong Jeon05064e12018-07-03 00:21:12 -070056if (project.hasProperty('with_code_coverage')) {
57 apply plugin: 'jacoco'
58}
59
Mads Ager418d1ca2017-05-22 09:35:49 +020060// Custom source set for example tests and generated tests.
61sourceSets {
62 test {
63 java {
64 srcDirs = [
65 'src/test/java',
66 'build/generated/test/java',
67 ]
68 }
69 }
Yohann Rousselbb571622017-11-09 10:47:36 +010070 apiUsageSample {
71 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020072 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
73 include 'com/android/tools/apiusagesample/*.java'
74 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
75 include 'com/android/tools/r8/D8CommandParser.java'
76 include 'com/android/tools/r8/R8CommandParser.java'
77 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010078 }
Yohann Rousselbb571622017-11-09 10:47:36 +010079 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010080 cfSegments {
81 java {
82 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
83 }
84 output.resourcesDir = 'build/classes/cfSegments'
85 }
86 classlib {
87 java {
88 srcDirs = [
89 'third_party/classlib/java',
90 ]
91 }
92 output.resourcesDir = 'build/classes/classlib'
93 }
Mads Ager418d1ca2017-05-22 09:35:49 +020094 debugTestResources {
95 java {
96 srcDirs = ['src/test/debugTestResources']
97 }
98 output.resourcesDir = 'build/classes/debugTestResources'
99 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200100 debugTestResourcesJava8 {
101 java {
102 srcDirs = ['src/test/debugTestResourcesJava8']
103 }
104 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
105 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200106 debugTestResourcesKotlin {
107 java {
108 srcDirs = ['src/test/debugTestResourcesKotlin']
109 }
110 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
111 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200112 examples {
113 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800114 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200115 }
116 output.resourcesDir = 'build/classes/examples'
117 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100118 examplesKotlin {
119 java {
120 srcDirs = ['src/test/examplesKotlin']
121 }
122 output.resourcesDir = 'build/classes/examplesKotlin'
123 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200124 examplesAndroidN {
125 java {
126 srcDirs = ['src/test/examplesAndroidN']
127 }
128 output.resourcesDir = 'build/classes/examplesAndroidN'
129 }
130 examplesAndroidO {
131 java {
132 srcDirs = ['src/test/examplesAndroidO']
133 }
134 output.resourcesDir = 'build/classes/examplesAndroidO'
135 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200136 examplesAndroidP {
137 java {
138 srcDirs = ['src/test/examplesAndroidP']
139 }
140 output.resourcesDir = 'build/classes/examplesAndroidP'
141 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200142 jctfCommon {
143 java {
144 srcDirs = [
145 'third_party/jctf/Harness/src',
146 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
147 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
148 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
149 'third_party/jctf/LibTests/src/org',
150 'build/additionalJctfCommonFiles'
151 ]
152 }
153 resources {
154 srcDirs = ['third_party/jctf/LibTests/resources']
155 }
156 }
157 jctfTests {
158 java {
159 srcDirs = [
160 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
161 // 'third_party/jctf/VMTests/src',
162 ]
163 }
164 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100165 kotlinR8TestResources {
166 java {
167 srcDirs = ['src/test/kotlinR8TestResources']
168 }
169 output.resourcesDir = 'build/classes/kotlinR8TestResources'
170 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200171}
172
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800173// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
174// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
175// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
176// for context.
177idea {
178 sourceSets.all { SourceSet sources ->
179 module {
180 if (sources.name == "main") {
181 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100182 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800183 } else {
184 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100185 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800186 }
187 }
188 }
189}
190
Yohann Roussel126f6872017-08-03 16:25:32 +0200191configurations {
192 supportLibs
193}
194
Mads Ager418d1ca2017-05-22 09:35:49 +0200195dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100196 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
197 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200198 // Include all of guava when compiling the code, but exclude annotations that we don't
199 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100200 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100201 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200202 exclude group: 'com.google.errorprone'
203 exclude group: 'com.google.code.findbugs'
204 exclude group: 'com.google.j2objc'
205 exclude group: 'org.codehaus.mojo'
206 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100207 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
208 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
209 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
210 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
211 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
212 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
213 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200214 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100215 testCompile "junit:junit:$junitVersion"
216 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200217 testCompile files('third_party/jasmin/jasmin-2.4.jar')
218 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200219 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100220 jctfCommonCompile "junit:junit:$junitVersion"
221 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200222 jctfTestsCompile sourceSets.jctfCommon.output
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100223 cfSegmentsCompile sourceSets.classlib.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100224 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
225 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200226 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100227 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800228 examplesCompile "junit:junit:$junitVersion"
229 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100230 supportLibs "com.android.support:support-v4:$androidSupportVersion"
231 supportLibs "junit:junit:$junitVersion"
232 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100233 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100234 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100235 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
236 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
237 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100238 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200239}
240
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100241def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100242def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100243def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100244def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100245def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100246
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200247def osString = OperatingSystem.current().isLinux() ? "linux" :
248 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200249
250def cloudDependencies = [
251 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200252 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100253 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200254 ],
255 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200256 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200257 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100258 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200259 "android_jar/lib-v19",
260 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100261 "android_jar/lib-v22",
262 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200263 "android_jar/lib-v24",
264 "android_jar/lib-v25",
265 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100266 "android_jar/lib-v27",
267 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200268 "core-lambda-stubs",
269 "dart-sdk",
270 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200271 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200272 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200273 "jasmin",
274 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100275 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200276 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200277 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100278 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200279 "proguard/proguard5.2.1",
280 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200281 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200282 ],
283 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
284 // container on other platforms where supported.
285 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200286 "linux/art",
287 "linux/art-5.1.1",
288 "linux/art-6.0.1",
289 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100290 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100291 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100293 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200294 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200295 ]
296]
297
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100298def cloudSystemDependencies = [
299 linux: [
300 "third_party": ["openjdk/openjdk-9.0.4/linux"],
301 ],
302 osx: [
303 "third_party": ["openjdk/openjdk-9.0.4/osx"],
304 ],
305 windows: [
306 "third_party": ["openjdk/openjdk-9.0.4/windows"],
307 ],
308]
309
310if (OperatingSystem.current().isWindows()) {
311 cloudSystemDependencies.windows.each { entry ->
312 cloudDependencies.get(entry.key).addAll(entry.value)
313 }
314} else if (OperatingSystem.current().isLinux()) {
315 cloudSystemDependencies.linux.each { entry ->
316 cloudDependencies.get(entry.key).addAll(entry.value)
317 }
318} else if (OperatingSystem.current().isMacOsX()) {
319 cloudSystemDependencies.osx.each { entry ->
320 cloudDependencies.get(entry.key).addAll(entry.value)
321 }
322} else {
323 println "WARNING: Unsupported system: " + OperatingSystem.current()
324}
325
326def getDownloadDepsTaskName(entryKey, entryFile) {
327 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
328}
329
Ian Zernyb2d27c42019-02-20 09:09:41 +0100330def getFetchDepsTaskName(entryKey, entryFile) {
331 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
332}
333
Mads Ager418d1ca2017-05-22 09:35:49 +0200334cloudDependencies.each { entry ->
335 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100336 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
337 type DownloadDependency.Type.GOOGLE_STORAGE
338 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200339 }
340 }
341}
342
343def x20Dependencies = [
344 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200345 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200346 "chrome",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100347 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100348 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200349 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100350 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200351 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200352 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200353 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200354 "gmscore/gmscore_v10",
355 "gmscore/gmscore_v9",
356 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200357 "gmscore/v4",
358 "gmscore/v5",
359 "gmscore/v6",
360 "gmscore/v7",
361 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200362 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200363 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200364 "proguard/proguard_internal_159423826",
365 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200366 "youtube/youtube.android_12.10",
367 "youtube/youtube.android_12.17",
368 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200369 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200370 ],
371]
372
373x20Dependencies.each { entry ->
374 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100375 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
376 type DownloadDependency.Type.X20
377 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200378 }
379 }
380}
381
Rico Wind897bb712017-05-23 10:44:29 +0200382task downloadProguard {
383 cloudDependencies.each { entry ->
384 entry.value.each { entryFile ->
385 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100386 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200387 }
388 }
389 }
390}
391
Rico Windf6c74ce2018-12-04 08:50:55 +0100392task downloadOpenJDKrt {
393 cloudDependencies.each { entry ->
394 entry.value.each { entryFile ->
395 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100396 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100397 }
398 }
399 }
400}
401
Tamas Kenez427205b2017-06-29 15:57:09 +0200402task downloadDx {
403 cloudDependencies.each { entry ->
404 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200405 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100406 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200407 }
408 }
409 }
410}
411
Tamas Kenez0e10c562017-06-08 10:00:34 +0200412task downloadAndroidCts {
413 cloudDependencies.each { entry ->
414 entry.value.each { entryFile ->
415 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100416 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200417 }
418 }
419 }
420}
421
Mads Ager418d1ca2017-05-22 09:35:49 +0200422task downloadDeps {
423 cloudDependencies.each { entry ->
424 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100425 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200426 }
427 }
428 if (!project.hasProperty('no_internal')) {
429 x20Dependencies.each { entry ->
430 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100431 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200432 }
433 }
434 }
435}
436
437allprojects {
438 sourceCompatibility = JavaVersion.VERSION_1_8
439 targetCompatibility = JavaVersion.VERSION_1_8
440}
441
Rico Wind266336c2019-02-25 10:11:38 +0100442// TODO(ricow): Remove debug prints
443println("NOTE: Current operating system: " + OperatingSystem.current())
444println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
445
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100446// Check if running with the JDK location from tools/jdk.py.
447if (OperatingSystem.current().isWindows()) {
448 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
449} else {
450 def javaHomeOut = new StringBuilder()
451 def javaHomeErr = new StringBuilder()
452 def javaHomeProc = './tools/jdk.py'.execute()
453 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
454 def jdkHome = new File(javaHomeOut.toString().trim())
455 if (!jdkHome.exists()) {
456 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
457 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
458 println("WARNING: Gradle is running in a non-pinned Java"
459 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
460 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100461 } else {
462 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100463 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200464}
465
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100466sourceSets.configureEach { sourceSet ->
467 tasks.named(sourceSet.compileJavaTaskName).configure {
468 // Default disable errorprone (enabled and setup below).
469 options.errorprone.enabled = false
470 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100471 // Run all compilation tasks in a forked subprocess.
472 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100473 // Javac often runs out of stack space when compiling the tests.
474 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100475 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100476 // Test compilation is sometimes hitting the default limit at 1g, increase it.
477 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100478 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
479 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
480 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200481}
482
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100483if (!project.hasProperty('without_error_prone') &&
484 // Don't enable error prone on Java 8 as the plugin setup does not support it.
485 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200486 compileJava {
487 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100488 options.errorprone.enabled = true
489 options.errorprone.disableAllChecks = true
490 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
491 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
492 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
493 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
494 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
495 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
496 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
497 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
498 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
499 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
500 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
501 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
502 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
503 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
504 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
505 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
506 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
507 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
508 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200509 }
510}
511
Mads Ager418d1ca2017-05-22 09:35:49 +0200512compileJctfCommonJava {
513 dependsOn 'copyAdditionalJctfCommonFiles'
514 options.compilerArgs = ['-Xlint:none']
515}
516
517compileJctfTestsJava {
518 dependsOn 'jctfCommonClasses'
519 options.compilerArgs = ['-Xlint:none']
520}
521
Yohann Roussel7f47c032017-09-14 12:19:06 +0200522task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200523 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100524
Yohann Roussel7f47c032017-09-14 12:19:06 +0200525 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100526 def runtimeClasspath = configurations.findByName("runtimeClasspath")
527 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
528
Yohann Roussel7f47c032017-09-14 12:19:06 +0200529 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100530
Yohann Roussel7f47c032017-09-14 12:19:06 +0200531 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100532 def dependencies = []
533 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
534 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
535 dependencies.add("${identifier.group}:${identifier.module}")
536 }
537 def libraryLicenses = file('LIBRARY-LICENSE').text
538 dependencies.each {
539 if (!libraryLicenses.contains("- artifact: $it")) {
540 throw new GradleException("No license for $it in LIBRARY_LICENSE")
541 }
542 }
543
Yohann Roussel7f47c032017-09-14 12:19:06 +0200544 license.getParentFile().mkdirs()
545 license.createNewFile()
546 license.text = "This file lists all licenses for code distributed.\n"
547 license.text += "All non-library code has the following 3-Clause BSD license.\n"
548 license.text += "\n"
549 license.text += "\n"
550 license.text += file('LICENSE').text
551 license.text += "\n"
552 license.text += "\n"
553 license.text += "Summary of distributed libraries:\n"
554 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100555 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200556 license.text += "\n"
557 license.text += "\n"
558 license.text += "Licenses details:\n"
559 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
560 license.text += "\n"
561 license.text += "\n"
562 license.text += file.text
563 }
564 }
565}
566
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200567static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700568 // Everything under META-INF is not included by default.
569 // Should include before 'relocate' so that the service file path and its content
570 // are properly relocated as well.
571 task.mergeServiceFiles {
572 include 'META-INF/services/*'
573 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200574}
575
576static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000577 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200578 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000579 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
580 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000581 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000582 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200583 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
584 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
585 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200586 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000587}
588
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100589task repackageDepsNoRelocate(type: ShadowJar) {
590 configurations = [project.configurations.runtimeClasspath]
591 mergeServiceFiles(it)
592 exclude { it.getRelativePath().getPathString() == "module-info.class" }
593 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100594 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100595}
596
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000597task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100598 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200599 mergeServiceFiles(it)
600 if (!project.hasProperty('lib_no_relocate')) {
601 configureRelocations(it)
602 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100603 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700604 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000605 baseName 'deps'
606}
607
608task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200609 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200610 mergeServiceFiles(it)
611 if (!project.hasProperty('lib_no_relocate')) {
612 configureRelocations(it)
613 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000614 baseName 'sources'
615}
616
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100617task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200618 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100619 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200620 classifier = null
621 version = null
622 manifest {
623 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
624 }
625 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100626 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100627 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100628 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200629}
630
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100631task r8WithoutDeps(type: ShadowJar) {
632 from consolidatedLicense.outputs.files
633 baseName 'r8_without_deps'
634 classifier = null
635 version = null
636 manifest {
637 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
638 }
639 from sourceSets.main.output
640}
641
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000642task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200643 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200644 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200645 classifier = null
646 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200647 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200648 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200649 }
650 // In order to build without dependencies, pass the exclude_deps property using:
651 // gradle -Pexclude_deps R8
652 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800653 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000654 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800655 } else {
656 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200657 }
Ian Zerny80533c92019-01-24 10:32:09 +0100658 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200659}
660
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100661task R8NoManifestNoDeps(type: ShadowJar) {
662 from consolidatedLicense.outputs.files
663 baseName 'r8nomanifest-exclude-deps'
664 classifier = null
665 version = null
666 from sourceSets.main.output
667}
668
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100669task R8NoManifest(type: ShadowJar) {
670 from consolidatedLicense.outputs.files
671 baseName 'r8nomanifest'
672 classifier = null
673 version = null
674 // In order to build without dependencies, pass the exclude_deps property using:
675 // gradle -Pexclude_deps R8
676 if (!project.hasProperty('exclude_deps')) {
677 from repackageSources.outputs.files
678 from repackageDeps.outputs.files
679 } else {
680 from sourceSets.main.output
681 }
Ian Zerny80533c92019-01-24 10:32:09 +0100682 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100683}
684
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000685task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200686 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200687 baseName 'd8'
688 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200689 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200690 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200691}
692
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200693task CompatDx(type: ShadowJar) {
694 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200695 baseName 'compatdx'
696 manifest {
697 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
698 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200699}
700
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200701task CompatProguard(type: ShadowJar) {
702 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200703 baseName 'compatproguard'
704 manifest {
705 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
706 }
Lars Bak44cef522017-08-10 16:02:39 +0200707}
708
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100709def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100710 // Execute r8 commands against a stable r8 with relocated dependencies.
Rico Windcfb65512019-02-27 12:57:34 +0100711 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
712 "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100713}
714
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100715def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100716 return baseR8CommandLine([
717 "--classfile", "--release",
718 input,
719 "--output", output,
720 "--pg-conf", pgconf,
721 "--pg-map-output", output + ".map",
722 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
723 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100724}
725
726def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
727 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100728 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100729 outputs.file output
730 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100731 dependsOn r8WithRelocatedDeps
732 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100733 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
734 workingDir = projectDir
735 }
736}
737
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100738task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100739 baseName = "r8tests"
740 from sourceSets.test.output
741}
742
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100743task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
744 baseName = "r8tests-exclude-deps"
745 from sourceSets.test.output
746}
747
748def generateR8LibKeepRules(name, r8Source, testSource, output) {
749 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
750 doFirst {
751 standardOutput new FileOutputStream(output)
752 }
753 dependsOn r8WithRelocatedDeps
754 dependsOn r8Source
755 dependsOn testSource
756 dependsOn downloadOpenJDKrt
757 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
758 outputs.file output
759 commandLine baseR8CommandLine([
760 "printuses",
761 "--keeprules",
762 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
763 r8Source.outputs.files[0],
764 testSource.outputs.files[0]])
765 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100766 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100767}
768
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100769task R8LibApiOnly {
770 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
771 outputs.file r8LibPath
772}
773
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100774task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100775 def genRulesTask = generateR8LibKeepRules(
776 "Main",
777 R8NoManifest,
778 testJar,
779 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100780 dependsOn r8LibCreateTask(
781 "Main",
782 "src/main/keep.txt",
783 R8NoManifest,
784 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100785 ["--pg-conf", genRulesTask.outputs.files[0]]
786 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100787 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100788}
789
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100790task R8LibNoDeps {
791 def genRulesTask = generateR8LibKeepRules(
792 "NoDeps",
793 R8NoManifestNoDeps,
794 testJarNoDeps,
795 r8LibGeneratedKeepRulesExcludeDepsPath
796 )
797 dependsOn r8LibCreateTask(
798 "NoDeps",
799 "src/main/keep.txt",
800 R8NoManifestNoDeps,
801 r8LibExludeDepsPath,
802 ["--pg-conf", genRulesTask.outputs.files[0]],
803 repackageDepsNoRelocate.outputs.files
804 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
805 outputs.file r8LibExludeDepsPath
806}
807
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100808task CompatDxLib {
809 dependsOn r8LibCreateTask(
810 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100811}
812
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100813task CompatProguardLib {
814 dependsOn r8LibCreateTask(
815 "CompatPg",
816 "src/main/keep-compatproguard.txt",
817 CompatProguard,
818 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100819}
820
Mads Ager418d1ca2017-05-22 09:35:49 +0200821task sourceJar(type: Jar, dependsOn: classes) {
822 classifier = 'src'
823 from sourceSets.main.allSource
824}
825
826task jctfCommonJar(type: Jar) {
827 from sourceSets.jctfCommon.output
828 baseName 'jctfCommon'
829}
830
831artifacts {
832 archives sourceJar
833}
834
835task createArtTests(type: Exec) {
836 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200837 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100838 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200839 outputs.dir outputDir
840 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200841 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200842 workingDir = projectDir
843}
844
845task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200846 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200847 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200848 inputs.file script
849 outputs.dir outputDir
850 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200851 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200852 workingDir = projectDir
853}
854
855compileTestJava {
856 dependsOn createArtTests
857 dependsOn createJctfTests
858}
859
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100860task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
861 from sourceSets.cfSegments.output
862 baseName 'cf_segments'
863 destinationDir file('build/libs')
864}
865
Ian Zernyee23a172018-01-03 09:08:48 +0100866task buildD8ApiUsageSample(type: Jar) {
867 from sourceSets.apiUsageSample.output
868 baseName 'd8_api_usage_sample'
869 destinationDir file('tests')
870}
871
Ian Zerny923a0c12018-01-03 10:59:18 +0100872task buildR8ApiUsageSample(type: Jar) {
873 from sourceSets.apiUsageSample.output
874 baseName 'r8_api_usage_sample'
875 destinationDir file('tests')
876}
877
Yohann Roussel548ae942018-01-05 11:13:28 +0100878task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100879 dependsOn buildD8ApiUsageSample
880 dependsOn buildR8ApiUsageSample
881}
882
Mads Ager418d1ca2017-05-22 09:35:49 +0200883task buildDebugInfoExamplesDex {
884 def examplesDir = file("src/test/java")
885 def hostJar = "debuginfo_examples.jar"
886 def hostDexJar = "debuginfo_examples_dex.jar"
887 task "compile_debuginfo_examples"(type: JavaCompile) {
888 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
889 destinationDir = file("build/test/debuginfo_examples/classes")
890 classpath = sourceSets.main.compileClasspath
891 sourceCompatibility = JavaVersion.VERSION_1_7
892 targetCompatibility = JavaVersion.VERSION_1_7
893 options.compilerArgs += ["-Xlint:-options"]
894 }
895 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
896 archiveName = hostJar
897 destinationDir = file("build/test/")
898 from "build/test/debuginfo_examples/classes"
899 include "**/*.class"
900 }
901 task "dex_debuginfo_examples"(type: Exec,
902 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200903 if (OperatingSystem.current().isWindows()) {
904 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700905 } else if (OperatingSystem.current().isMacOsX()) {
906 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200907 } else {
908 executable file("tools/linux/dx/bin/dx");
909 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200910 args "--dex"
911 args "--output=build/test/${hostDexJar}"
912 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100913 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +0200914 outputs.file file("build/test/${hostDexJar}")
915 }
916 dependsOn dex_debuginfo_examples
917}
918
919task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200920 def resourcesDir = file("src/test/debugTestResources")
921 def hostJar = "debug_test_resources.jar"
922 task "compile_debugTestResources"(type: JavaCompile) {
923 source = fileTree(dir: resourcesDir, include: '**/*.java')
924 destinationDir = file("build/test/debugTestResources/classes")
925 classpath = sourceSets.main.compileClasspath
926 sourceCompatibility = JavaVersion.VERSION_1_7
927 targetCompatibility = JavaVersion.VERSION_1_7
928 options.compilerArgs += ["-g", "-Xlint:-options"]
929 }
930 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
931 archiveName = hostJar
932 destinationDir = file("build/test/")
933 from "build/test/debugTestResources/classes"
934 include "**/*.class"
935 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200936 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
937 def java8HostJar = "debug_test_resources_java8.jar"
938 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
939 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
940 destinationDir = file("build/test/debugTestResourcesJava8/classes")
941 classpath = sourceSets.main.compileClasspath
942 sourceCompatibility = JavaVersion.VERSION_1_8
943 targetCompatibility = JavaVersion.VERSION_1_8
944 options.compilerArgs += ["-g", "-Xlint:-options"]
945 }
946 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
947 archiveName = java8HostJar
948 destinationDir = file("build/test/")
949 from "build/test/debugTestResourcesJava8/classes"
950 include "**/*.class"
951 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200952 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000953 def kotlinHostJar = "debug_test_resources_kotlin.jar"
954 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
955 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
956 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200957 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200958 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200959 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200960 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000961 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200962}
963
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100964// Examples used by tests, where Android specific APIs are used.
965task buildExampleAndroidApi(type: JavaCompile) {
966 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
967 destinationDir = file("build/test/examplesAndroidApi/classes")
968 classpath = files("third_party/android_jar/lib-v26/android.jar")
969 sourceCompatibility = JavaVersion.VERSION_1_8
970 targetCompatibility = JavaVersion.VERSION_1_8
971}
972
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100973task buildExampleKotlinJars {
974 def kotlinSrcDir = file("src/test/examplesKotlin")
975 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000976 def name = dir.getName();
977 dependsOn "compile_example_kotlin_${name}"
978 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
979 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
980 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100981 }
982 }
983}
984
Lars Bakc91e87e2017-08-18 08:53:10 +0200985// Proto lite generated code yields warnings when compiling with javac.
986// We change the options passed to javac to ignore it.
987compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
988
Søren Gjesse7320ce52018-05-07 15:45:22 +0200989
Mads Ager418d1ca2017-05-22 09:35:49 +0200990task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200991 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200992 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200993 def proguardScript
994 if (OperatingSystem.current().isWindows()) {
995 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
996 } else {
997 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
998 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200999 task extractExamplesRuntime(type: Sync) {
1000 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001001 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001002 include "**/*.class"
1003 includeEmptyDirs false
1004 into "$buildDir/runtime/examples/"
1005 }
1006
Søren Gjesse7320ce52018-05-07 15:45:22 +02001007 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1008 from examplesDir
1009 exclude "**/*.java"
1010 exclude "**/keep-rules*.txt"
1011 into file("build/test/examples/classes")
1012 }
1013
1014 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001015 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001016 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001017 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001018 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001019 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001020 sourceCompatibility = JavaVersion.VERSION_1_7
1021 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001022 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1023 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001024 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1025 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001026 include "**/*.java"
1027 destinationDir = file("build/test/examples/classes_debuginfo_all")
1028 classpath = sourceSets.examples.compileClasspath
1029 sourceCompatibility = JavaVersion.VERSION_1_7
1030 targetCompatibility = JavaVersion.VERSION_1_7
1031 options.compilerArgs = ["-g", "-Xlint:none"]
1032 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001033 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1034 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001035 include "**/*.java"
1036 destinationDir = file("build/test/examples/classes_debuginfo_none")
1037 classpath = sourceSets.examples.compileClasspath
1038 sourceCompatibility = JavaVersion.VERSION_1_7
1039 targetCompatibility = JavaVersion.VERSION_1_7
1040 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001041 }
1042 examplesDir.eachDir { dir ->
1043 def name = dir.getName();
1044 def exampleOutputDir = file("build/test/examples");
1045 def jarName = "${name}.jar"
1046 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001047 dependsOn "jar_example_${name}_debuginfo_all"
1048 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001049 dependsOn "extractExamplesRuntime"
1050 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001051 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1052 def proguardConfigPath = "${dir}/proguard.cfg"
1053 if (new File(proguardConfigPath).exists()) {
1054 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1055 archiveName = "${name}_pre_proguard.jar"
1056 destinationDir = exampleOutputDir
1057 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001058 include name + "/**/*.class"
1059 with runtimeDependencies
1060 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001061 }
1062 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1063 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1064 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1065 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001066 inputs.files files(
1067 tasks.getByPath("pre_proguard_example_${name}"),
1068 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001069 // Enable these to get stdout and stderr redirected to files...
1070 // standardOutput = new FileOutputStream('proguard.stdout')
1071 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001072 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001073 " -outjars ${proguardJarPath}" +
1074 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001075 " -printmapping ${proguardMapPath}"
1076 if (OperatingSystem.current().isWindows()) {
1077 executable "${proguardScript}"
1078 args "${proguardArguments}"
1079 } else {
1080 executable "bash"
1081 args "-c", "${proguardScript} '${proguardArguments}'"
1082 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001083 outputs.file proguardJarPath
1084 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001085 // TODO: Consider performing distinct proguard compilations.
1086 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1087 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001088 into "${exampleOutputDir}"
1089 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001090 }
1091 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1092 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001093 into "${exampleOutputDir}"
1094 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001095 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001096 } else {
1097 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001098 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001099 destinationDir = exampleOutputDir
1100 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001101 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001102 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001103 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001104 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001105 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1106 archiveName = "${name}_debuginfo_all.jar"
1107 destinationDir = exampleOutputDir
1108 from "build/test/examples/classes_debuginfo_all"
1109 include name + "/**/*.class"
1110 with runtimeDependencies
1111 includeEmptyDirs false
1112 }
1113 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1114 archiveName = "${name}_debuginfo_none.jar"
1115 destinationDir = exampleOutputDir
1116 from "build/test/examples/classes_debuginfo_none"
1117 include name + "/**/*.class"
1118 with runtimeDependencies
1119 includeEmptyDirs false
1120 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001121 }
1122 }
1123}
1124
1125task buildExampleAndroidNJars {
1126 dependsOn downloadDeps
1127 def examplesDir = file("src/test/examplesAndroidN")
1128 task "compile_examplesAndroidN"(type: JavaCompile) {
1129 source = fileTree(dir: examplesDir, include: '**/*.java')
1130 destinationDir = file("build/test/examplesAndroidN/classes")
1131 classpath = sourceSets.main.compileClasspath
1132 sourceCompatibility = JavaVersion.VERSION_1_8
1133 targetCompatibility = JavaVersion.VERSION_1_8
1134 options.compilerArgs += ["-Xlint:-options"]
1135 }
1136 examplesDir.eachDir { dir ->
1137 def name = dir.getName();
1138 def exampleOutputDir = file("build/test/examplesAndroidN");
1139 def jarName = "${name}.jar"
1140 dependsOn "jar_examplesAndroidN_${name}"
1141 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1142 archiveName = jarName
1143 destinationDir = exampleOutputDir
1144 from "build/test/examplesAndroidN/classes"
1145 include "**/" + name + "/**/*.class"
1146 }
1147 }
1148}
1149
1150
1151task buildExampleAndroidOJars {
1152 dependsOn downloadDeps
1153 def examplesDir = file("src/test/examplesAndroidO")
1154 // NOTE: we want to enable a scenario when test needs to reference some
1155 // classes generated by legacy (1.6) Java compiler to test some specific
1156 // behaviour. To do so we compile all the java files located in sub-directory
1157 // called 'legacy' with Java 1.6, then compile the rest of the files with
1158 // Java 1.8 and a reference to previously generated 1.6 classes.
1159
1160 // Compiling all classes in dirs 'legacy' with old Java version.
1161 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1162 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1163 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1164 classpath = sourceSets.main.compileClasspath
1165 sourceCompatibility = JavaVersion.VERSION_1_6
1166 targetCompatibility = JavaVersion.VERSION_1_6
1167 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1168 }
1169 // Compiling the rest of the files as Java 1.8 code.
1170 task "compile_examplesAndroidO"(type: JavaCompile) {
1171 dependsOn "compile_examplesAndroidO_Legacy"
1172 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1173 destinationDir = file("build/test/examplesAndroidO/classes")
1174 classpath = sourceSets.main.compileClasspath
1175 classpath += files("build/test/examplesAndroidOLegacy/classes")
1176 sourceCompatibility = JavaVersion.VERSION_1_8
1177 targetCompatibility = JavaVersion.VERSION_1_8
1178 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1179 }
1180 examplesDir.eachDir { dir ->
1181 def name = dir.getName();
1182 def destinationDir = file("build/test/examplesAndroidO/classes");
1183 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1184 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1185 dependsOn: "compile_examplesAndroidO") {
1186 main = name + ".TestGenerator"
1187 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1188 args destinationDir
1189 }
1190 } else {
1191 task "generate_examplesAndroidO_${name}" () {}
1192 }
1193 }
1194 examplesDir.eachDir { dir ->
1195 def name = dir.getName();
1196 def exampleOutputDir = file("build/test/examplesAndroidO");
1197 def jarName = "${name}.jar"
1198 dependsOn "jar_examplesAndroidO_${name}"
1199 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1200 "generate_examplesAndroidO_${name}"]) {
1201 archiveName = jarName
1202 destinationDir = exampleOutputDir
1203 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1204 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1205 include "**/" + name + "/**/*.class"
1206 // Do not include generator into the test runtime jar, it is not useful.
1207 // Otherwise, shrinking will need ASM jars.
1208 exclude "**/TestGenerator*"
1209 }
1210 }
1211}
1212
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001213task buildExampleAndroidPJars {
1214 dependsOn downloadDeps
1215 def examplesDir = file("src/test/examplesAndroidP")
1216
1217 task "compile_examplesAndroidP"(type: JavaCompile) {
1218 source = fileTree(dir: examplesDir, include: '**/*.java')
1219 destinationDir = file("build/test/examplesAndroidP/classes")
1220 classpath = sourceSets.main.compileClasspath
1221 sourceCompatibility = JavaVersion.VERSION_1_8
1222 targetCompatibility = JavaVersion.VERSION_1_8
1223 options.compilerArgs += ["-Xlint:-options"]
1224 }
1225 examplesDir.eachDir { dir ->
1226 def name = dir.getName();
1227 def destinationDir = file("build/test/examplesAndroidP/classes");
1228 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1229 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1230 dependsOn: "compile_examplesAndroidP") {
1231 main = name + ".TestGenerator"
1232 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1233 args destinationDir
1234 }
1235 } else {
1236 task "generate_examplesAndroidP_${name}" () {}
1237 }
1238 }
1239 examplesDir.eachDir { dir ->
1240 def name = dir.getName();
1241 def exampleOutputDir = file("build/test/examplesAndroidP");
1242 def jarName = "${name}.jar"
1243 dependsOn "jar_examplesAndroidP_${name}"
1244 task "jar_examplesAndroidP_${name}"(type: Jar,
1245 dependsOn: ["compile_examplesAndroidP",
1246 "generate_examplesAndroidP_${name}"]) {
1247 archiveName = jarName
1248 destinationDir = exampleOutputDir
1249 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1250 include "**/" + name + "/**/*.class"
1251 // Do not include generator into the test runtime jar, it is not useful.
1252 // Otherwise, shrinking will need ASM jars.
1253 exclude "**/TestGenerator*"
1254 }
1255 }
1256}
1257
Mikaël Peltier61633d42017-10-13 16:51:06 +02001258task buildExampleJava9Jars {
1259 def examplesDir = file("src/test/examplesJava9")
1260 examplesDir.eachDir { dir ->
1261 def name = dir.getName();
1262 def exampleOutputDir = file("build/test/examplesJava9");
1263 def jarName = "${name}.jar"
1264 dependsOn "jar_examplesJava9_${name}"
1265 task "jar_examplesJava9_${name}"(type: Jar) {
1266 archiveName = jarName
1267 destinationDir = exampleOutputDir
1268 from "src/test/examplesJava9" // Java 1.9 classes
1269 include "**/" + name + "/**/*.class"
1270 }
1271 }
1272}
1273
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001274task buildExamplesKotlin {
1275 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1276 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1277 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1278 } else if (!OperatingSystem.current().isLinux()) {
1279 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1280 "on your platform. It is fully supported on Linux and partially supported on " +
1281 "Mac OS and Windows")
1282 return;
1283 }
1284 def examplesDir = file("src/test/examplesKotlin")
1285 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001286 def name = dir.getName();
1287 dependsOn "dex_example_kotlin_${name}"
1288 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1289 def dexPath = file("${exampleOutputDir}")
1290 task "dex_example_kotlin_${name}"(type: dx.Dx,
1291 dependsOn: "compile_example_kotlin_${name}") {
1292 doFirst {
1293 if (!dexPath.exists()) {
1294 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001295 }
1296 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001297 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1298 destination = dexPath
1299 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001300 }
1301 }
1302}
1303
Sebastien Hertzd3313772018-01-16 14:12:37 +01001304task buildKotlinR8TestResources {
1305 def examplesDir = file("src/test/kotlinR8TestResources")
1306 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001307 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1308 def name = dir.getName()
1309 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001310 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1311 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001312 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001313 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001314 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1315 source = fileTree(dir: file("${examplesDir}/${name}"),
1316 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001317 destination = file(outputFile)
1318 targetVersion = kotlinTargetVersion
1319 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001320 task "${taskName}Java"(type: JavaCompile) {
1321 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1322 destinationDir = file(javaOutput)
1323 classpath = sourceSets.main.compileClasspath
1324 sourceCompatibility = JavaVersion.VERSION_1_6
1325 targetCompatibility = JavaVersion.VERSION_1_6
1326 options.compilerArgs += ["-g", "-Xlint:-options"]
1327 }
1328 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1329 archiveName = javaOutputJarName
1330 destinationDir = file(javaOutputJarDir)
1331 from javaOutput
1332 include "**/*.class"
1333 }
1334 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001335 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001336 }
1337}
1338
Mads Ager418d1ca2017-05-22 09:35:49 +02001339task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001340 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1341 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1342 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001343 } else if (!OperatingSystem.current().isLinux()) {
1344 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001345 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001346 return;
1347 }
1348 dependsOn buildDebugTestResourcesJars
1349 dependsOn buildExampleJars
1350 dependsOn buildExampleAndroidNJars
1351 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001352 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001353 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001354 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001355 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001356 def noDexTests = [
1357 "multidex",
1358 "multidex002",
1359 "multidex004",
1360 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001361 examplesDir.eachDir { dir ->
1362 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001363 if (!(name in noDexTests)) {
1364 dependsOn "dex_example_${name}"
1365 def exampleOutputDir = file("build/test/examples/" + name);
1366 def dexPath = file("${exampleOutputDir}")
1367 def debug = (name == "throwing")
1368 if (!dexPath.exists()) {
1369 dexPath.mkdirs()
1370 }
1371 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1372 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1373 destination = dexPath
1374 debug = debug
1375 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001376 }
1377 }
1378}
1379
1380task buildSmali {
1381 def smaliDir = file("src/test/smali")
1382 smaliDir.eachDirRecurse() { dir ->
1383 def name = dir.getName();
1384 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1385 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1386 smaliOutputDir.mkdirs()
1387 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001388 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001389 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1390 def javaFiles = fileTree(dir: dir, include: '*.java')
1391 def destDir = smaliOutputDir;
1392 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1393 def intermediateFileName = "${name}-intermediate.dex";
1394 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1395 if (javaFiles.empty) {
1396 if (!smaliFiles.empty) {
1397 dependsOn "${taskName}_smali"
1398 task "${taskName}_smali"(type: smali.Smali) {
1399 source = smaliFiles
1400 destination = destFile
1401 }
1402 }
1403 } else {
1404 dependsOn "${taskName}_dexmerger"
1405 task "${taskName}_smali"(type: smali.Smali) {
1406 source = smaliFiles
1407 destination = intermediateFile
1408 }
1409 task "${taskName}_java"(type: JavaCompile) {
1410 source = javaFiles
1411 destinationDir destDir
1412 classpath = sourceSets.main.compileClasspath
1413 sourceCompatibility = JavaVersion.VERSION_1_7
1414 targetCompatibility = JavaVersion.VERSION_1_7
1415 options.compilerArgs += ["-Xlint:-options"]
1416 }
1417 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1418 archiveName = "Test.jar"
1419 destinationDir = destDir
1420 from fileTree(dir: destDir, include: 'Test.class')
1421 }
1422 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1423 source = fileTree(dir: destDir, include: 'Test.jar')
1424 destination = destDir
1425 }
1426 task "${taskName}_dexmerger"(
1427 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1428 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1429 destination = destFile
1430 }
1431 }
1432 }
1433}
1434
1435tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001436 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001437 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.
Rico Windeaa66ad2019-03-25 08:41:15 +01001440 maxParallelForks = (Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1) + 1
Rico Windc56f21c2019-03-12 07:29:57 +01001441 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001442 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001443 if (project.hasProperty('disable_assertions')) {
1444 enableAssertions = false
1445 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001446 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
1447 maxHeapSize = "4g"
Mads Ager418d1ca2017-05-22 09:35:49 +02001448}
1449
1450task buildPreNJdwpTestsJar(type: Jar) {
1451 baseName = 'jdwp-tests-preN'
1452 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1453 // Exclude the classes containing java8
1454 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1455 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1456 includeEmptyDirs = false
1457}
1458
Ian Zerny74143162017-11-24 13:46:35 +01001459task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1460 def inFile = buildPreNJdwpTestsJar.archivePath
1461 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001462 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001463 outputs.file outFile
1464 if (OperatingSystem.current().isWindows()) {
1465 executable file("tools/windows/dx/bin/dx.bat")
1466 } else if (OperatingSystem.current().isMacOsX()) {
1467 executable file("tools/mac/dx/bin/dx");
1468 } else {
1469 executable file("tools/linux/dx/bin/dx");
1470 }
1471 args "--dex"
1472 args "--output=${outFile}"
1473 args inFile
1474}
1475
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001476task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1477 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001478}
1479
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001480def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001481 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001482 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001483 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001484 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001485 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001486 return null
1487}
1488
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001489task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001490 dependsOn testJar
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001491 inputs.files files("$buildDir/libs/r8tests.jar")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001492 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001493 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001494 delete r8LibTestPath
1495 from zipTree(testJar.outputs.files[0])
1496 into r8LibTestPath
1497 include "com/android/tools/r8/**"
1498 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001499 }
1500 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001501}
1502
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001503def printStackTrace(TestResult result) {
1504 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1505 def out = new StringBuffer()
1506 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001507 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001508 def header = "RETRACED STACKTRACE";
1509 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1510 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1511 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1512 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001513 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001514 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001515 out.append("--------------------------------------\n")
1516 Process process = command.execute()
1517 def processIn = new PrintStream(process.getOut())
1518 process.consumeProcessOutput(out, err)
1519 result.exception.printStackTrace(processIn)
1520 processIn.flush()
1521 processIn.close()
1522 process.waitFor()
1523 out.append("\n\n--------------------------------------\n")
1524 out.append("OBFUSCATED STACKTRACE\n")
1525 out.append("--------------------------------------\n")
1526 result.exceptions.add(0, new Exception(out.toString()))
1527 } else {
1528 result.exception.printStackTrace()
1529 }
1530}
1531
Mads Ager418d1ca2017-05-22 09:35:49 +02001532test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001533 if (project.hasProperty('generate_golden_files_to')) {
1534 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1535 assert project.hasProperty('HEAD_sha1')
1536 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1537 }
1538
1539 if (project.hasProperty('use_golden_files_in')) {
1540 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1541 assert project.hasProperty('HEAD_sha1')
1542 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1543 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001544 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001545 // R8.jar is required for running bootstrap tests.
1546 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001547 testLogging.exceptionFormat = 'full'
1548 if (project.hasProperty('print_test_stdout')) {
1549 testLogging.showStandardStreams = true
1550 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001551 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001552 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001553 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001554 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001555
Ian Zerny324d7612019-03-20 10:52:28 +01001556 // Forward runtime configurations for test parameters.
1557 if (project.hasProperty('runtimes')) {
1558 println "NOTE: Running with runtimes: " + project.property('runtimes')
1559 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001560 }
1561
Mads Ager418d1ca2017-05-22 09:35:49 +02001562 if (project.hasProperty('one_line_per_test')) {
1563 beforeTest { desc ->
1564 println "Start executing test ${desc.name} [${desc.className}]"
1565 }
1566 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001567 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001568 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001569 }
Rico Windda6836e2018-12-07 12:32:03 +01001570 if (project.hasProperty('update_test_timestamp')) {
1571 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1572 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001573 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1574 }
Rico Windf88b6be2018-12-11 15:14:05 +01001575 } else {
1576 afterTest { desc, result ->
1577 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001578 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001579 }
1580 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001581 }
1582 if (project.hasProperty('no_internal')) {
1583 exclude "com/android/tools/r8/internal/**"
1584 }
1585 if (project.hasProperty('only_internal')) {
1586 include "com/android/tools/r8/internal/**"
1587 }
Rico Wind4e218292019-03-07 12:44:49 +01001588
Mads Ager418d1ca2017-05-22 09:35:49 +02001589 if (project.hasProperty('tool')) {
1590 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001591 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001592 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001593 if (project.hasProperty('only_jctf')) {
1594 include "com/android/tools/r8/jctf/d8/**"
1595 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001596 // Don't run anything, deprecated
1597 println "Running with deprecated tool d8, not running any tests"
1598 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001599 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001600 } else {
1601 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001602 assert(project.hasProperty('only_jctf'))
1603 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001604 }
1605 }
1606 if (!project.hasProperty('all_tests')) {
1607 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001608 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001609 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001610 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001611 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001612 if (project.hasProperty('shard_count') ) {
1613 assert project.hasProperty('shard_number')
1614 int shard_count = project.getProperty('shard_count') as Integer
1615 int shard_number = project.getProperty('shard_number') as Integer
1616 assert shard_count < 65536
1617 assert shard_number < shard_count
1618 exclude {
1619 entry ->
1620 // Don't leave out directories. Leaving out a directory means all entries below.
1621 if (entry.file.isDirectory()) {
1622 return false
1623 }
1624 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1625 int hash = Integer.parseInt(first4, 16)
1626 return hash % shard_count != shard_number
1627 }
1628 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001629 if (project.hasProperty('jctf_compile_only')) {
1630 println "JCTF: compiling only"
1631 systemProperty 'jctf_compile_only', '1'
1632 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001633 if (project.hasProperty('test_dir')) {
1634 systemProperty 'test_dir', project.property('test_dir')
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}