blob: 59e6b9e1ec8066ba5861503e757405564107b4d0 [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.
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +00004import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +02005import net.ltgt.gradle.errorprone.ErrorProneToolChain
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02006import org.gradle.internal.os.OperatingSystem
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00007import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +02008import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +02009
Sebastien Hertz143ed112018-02-13 14:26:41 +010010ext {
11 androidSupportVersion = '25.4.0'
Gautam Korlam39d74202018-08-29 18:09:35 -070012 asmVersion = '6.2.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010013 autoValueVersion = '1.5'
14 espressoVersion = '3.0.0'
15 fastutilVersion = '7.2.0'
16 guavaVersion = '23.0'
17 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020018 gsonVersion = '2.7'
Sebastien Hertz143ed112018-02-13 14:26:41 +010019 junitVersion = '4.12'
Sebastien Hertz6ebe39a2018-03-06 16:17:58 +010020 kotlinVersion = '1.2.30'
Jinseong Jeon40ceab02018-07-09 14:25:31 -070021 kotlinExtMetadataJVMVersion = '0.0.3'
Sebastien Hertz143ed112018-02-13 14:26:41 +010022 smaliVersion = '2.2b4'
23}
24
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020025def errorProneConfiguration = [
26 '-XepDisableAllChecks',
27 // D8 want to use reference equality, thus disable the checker explicitly
28 '-Xep:ReferenceEquality:OFF',
Stephan Herhute4d101c2017-11-22 12:18:02 +010029 '-Xep:ClassCanBeStatic:ERROR',
30 '-Xep:OperatorPrecedence:ERROR',
31 '-Xep:RemoveUnusedImports:ERROR',
32 '-Xep:MissingOverride:ERROR',
Stephan Herhute4d101c2017-11-22 12:18:02 +010033 '-Xep:IntLongMath:ERROR',
34 '-Xep:EqualsHashCode:ERROR',
35 '-Xep:InconsistentOverloads:ERROR',
36 '-Xep:ArrayHashCode:ERROR',
37 '-Xep:EqualsIncompatibleType:ERROR',
38 '-Xep:NonOverridingEquals:ERROR',
39 '-Xep:FallThrough:ERROR',
40 '-Xep:MissingCasesInEnumSwitch:ERROR',
41 '-Xep:MissingDefault:ERROR',
42 '-Xep:MultipleTopLevelClasses:ERROR',
43 '-Xep:NarrowingCompoundAssignment:ERROR',
Mads Ager2ce4b372018-06-07 13:11:33 +020044 '-Xep:BoxedPrimitiveConstructor:ERROR',
45 '-Xep:LogicalAssignment:ERROR',
46 '-Xep:FloatCast:ERROR',
47 '-Xep:ReturnValueIgnored:ERROR']
Mads Ager418d1ca2017-05-22 09:35:49 +020048
49apply from: 'copyAdditionalJctfCommonFiles.gradle'
50
51repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020052 maven { url 'https://maven.google.com' }
Jinseong Jeon515e7582018-06-15 21:50:31 +000053 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020054 mavenCentral()
55}
56
Stephan Herhut417a72a2017-07-18 10:38:30 +020057buildscript {
58 repositories {
59 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020060 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020061 maven {
62 url "https://plugins.gradle.org/m2/"
63 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020064 }
65 dependencies {
Yohann Roussel7f47c032017-09-14 12:19:06 +020066 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Jinseong Jeon40ceab02018-07-09 14:25:31 -070067 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020068 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020069 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Jinseong Jeon05064e12018-07-03 00:21:12 -070070 classpath "com.gradle:build-scan-plugin:1.14"
Stephan Herhut417a72a2017-07-18 10:38:30 +020071 }
72}
73
Jinseong Jeon05064e12018-07-03 00:21:12 -070074apply plugin: "com.gradle.build-scan"
75
76buildScan {
77 licenseAgreementUrl = 'https://gradle.com/terms-of-service'
78 licenseAgree = 'yes'
79}
80
81apply plugin: 'java'
82apply plugin: 'idea'
Jinseong Jeon05064e12018-07-03 00:21:12 -070083apply plugin: 'com.cookpad.android.licensetools'
84apply plugin: 'net.ltgt.errorprone-base'
85apply plugin: "net.ltgt.apt"
86
Jinseong Jeon05064e12018-07-03 00:21:12 -070087if (project.hasProperty('with_code_coverage')) {
88 apply plugin: 'jacoco'
89}
90
Mads Ager418d1ca2017-05-22 09:35:49 +020091// Custom source set for example tests and generated tests.
92sourceSets {
93 test {
94 java {
95 srcDirs = [
96 'src/test/java',
97 'build/generated/test/java',
98 ]
99 }
100 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100101 apiUsageSample {
102 java {
Mathias Rave3f3c522018-05-30 08:22:17 +0200103 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
104 include 'com/android/tools/apiusagesample/*.java'
105 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
106 include 'com/android/tools/r8/D8CommandParser.java'
107 include 'com/android/tools/r8/R8CommandParser.java'
108 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +0100109 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100110 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200111 debugTestResources {
112 java {
113 srcDirs = ['src/test/debugTestResources']
114 }
115 output.resourcesDir = 'build/classes/debugTestResources'
116 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200117 debugTestResourcesJava8 {
118 java {
119 srcDirs = ['src/test/debugTestResourcesJava8']
120 }
121 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
122 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200123 debugTestResourcesKotlin {
124 java {
125 srcDirs = ['src/test/debugTestResourcesKotlin']
126 }
127 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
128 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200129 examples {
130 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800131 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200132 }
133 output.resourcesDir = 'build/classes/examples'
134 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100135 examplesKotlin {
136 java {
137 srcDirs = ['src/test/examplesKotlin']
138 }
139 output.resourcesDir = 'build/classes/examplesKotlin'
140 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200141 examplesAndroidN {
142 java {
143 srcDirs = ['src/test/examplesAndroidN']
144 }
145 output.resourcesDir = 'build/classes/examplesAndroidN'
146 }
147 examplesAndroidO {
148 java {
149 srcDirs = ['src/test/examplesAndroidO']
150 }
151 output.resourcesDir = 'build/classes/examplesAndroidO'
152 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200153 examplesAndroidP {
154 java {
155 srcDirs = ['src/test/examplesAndroidP']
156 }
157 output.resourcesDir = 'build/classes/examplesAndroidP'
158 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200159 jctfCommon {
160 java {
161 srcDirs = [
162 'third_party/jctf/Harness/src',
163 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
164 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
165 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
166 'third_party/jctf/LibTests/src/org',
167 'build/additionalJctfCommonFiles'
168 ]
169 }
170 resources {
171 srcDirs = ['third_party/jctf/LibTests/resources']
172 }
173 }
174 jctfTests {
175 java {
176 srcDirs = [
177 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
178 // 'third_party/jctf/VMTests/src',
179 ]
180 }
181 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100182 kotlinR8TestResources {
183 java {
184 srcDirs = ['src/test/kotlinR8TestResources']
185 }
186 output.resourcesDir = 'build/classes/kotlinR8TestResources'
187 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200188}
189
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800190// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
191// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
192// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
193// for context.
194idea {
195 sourceSets.all { SourceSet sources ->
196 module {
197 if (sources.name == "main") {
198 sourceDirs += sources.java.srcDirs
199 outputDir sources.output.classesDir
200 } else {
201 testSourceDirs += sources.java.srcDirs
202 testOutputDir sources.output.classesDir
203 }
204 }
205 }
206}
207
Yohann Roussel126f6872017-08-03 16:25:32 +0200208configurations {
209 supportLibs
210}
211
Mads Ager418d1ca2017-05-22 09:35:49 +0200212dependencies {
Sebastien Hertz143ed112018-02-13 14:26:41 +0100213 compile "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
Mads Ager48dd79e2018-05-15 09:13:55 +0200214 compile "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200215 // Include all of guava when compiling the code, but exclude annotations that we don't
216 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100217 compileOnly("com.google.guava:guava:$guavaVersion")
218 compile("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200219 exclude group: 'com.google.errorprone'
220 exclude group: 'com.google.code.findbugs'
221 exclude group: 'com.google.j2objc'
222 exclude group: 'org.codehaus.mojo'
223 })
Sebastien Hertz143ed112018-02-13 14:26:41 +0100224 compile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
Jinseong Jeon515e7582018-06-15 21:50:31 +0000225 compile "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100226 compile group: 'org.ow2.asm', name: 'asm', version: asmVersion
227 compile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
228 compile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
229 compile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
230 compile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200231 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100232 testCompile "junit:junit:$junitVersion"
233 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200234 testCompile files('third_party/jasmin/jasmin-2.4.jar')
235 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200236 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100237 jctfCommonCompile "junit:junit:$junitVersion"
238 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200239 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100240 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
241 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200242 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100243 examplesCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100244 examplesCompileOnly "com.google.auto.value:auto-value:$autoValueVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100245 supportLibs "com.android.support:support-v4:$androidSupportVersion"
246 supportLibs "junit:junit:$junitVersion"
247 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100248 apiUsageSampleCompile sourceSets.main.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100249 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
250 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
251 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
252 apt "com.google.auto.value:auto-value:$autoValueVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200253}
254
Yohann Roussel7f47c032017-09-14 12:19:06 +0200255licenseTools {
256 licensesYaml = file('LIBRARY-LICENSE')
257}
258
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200259def osString = OperatingSystem.current().isLinux() ? "linux" :
260 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200261
262def cloudDependencies = [
263 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200264 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200265 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200266 ],
267 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200268 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200269 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100270 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200271 "android_jar/lib-v19",
272 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100273 "android_jar/lib-v22",
274 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200275 "android_jar/lib-v24",
276 "android_jar/lib-v25",
277 "android_jar/lib-v26",
Rico Windf72fa152018-10-22 15:41:03 +0200278 "core-lambda-stubs",
279 "dart-sdk",
280 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200281 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200282 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200283 "jasmin",
284 "jctf",
Rico Windf72fa152018-10-22 15:41:03 +0200285 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200286 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100287 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200288 "proguard/proguard5.2.1",
289 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200290 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200291 ],
292 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
293 // container on other platforms where supported.
294 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200295 "linux/art",
296 "linux/art-5.1.1",
297 "linux/art-6.0.1",
298 "linux/art-7.0.0",
299 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100300 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200301 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200302 ]
303]
304
305cloudDependencies.each { entry ->
306 entry.value.each { entryFile ->
307 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200308 def outputDir = "${entry.key}/${entryFile}"
309 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200310 def sha1File = "${gzFile}.sha1"
311 inputs.file sha1File
312 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200313 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200314 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
315 if (OperatingSystem.current().isWindows()) {
316 executable "download_from_google_storage.bat"
317 args dlFromStorageArgs
318 } else {
319 executable "bash"
320 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
321 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200322 }
323 }
324}
325
326def x20Dependencies = [
327 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200328 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200329 "chrome",
330 "desugar/desugar_20180308",
331 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200332 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200333 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200334 "gmscore/gmscore_v10",
335 "gmscore/gmscore_v9",
336 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200337 "gmscore/v4",
338 "gmscore/v5",
339 "gmscore/v6",
340 "gmscore/v7",
341 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200342 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200343 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200344 "proguard/proguard_internal_159423826",
345 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200346 "youtube/youtube.android_12.10",
347 "youtube/youtube.android_12.17",
348 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200349 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200350 ],
351]
352
353x20Dependencies.each { entry ->
354 entry.value.each { entryFile ->
355 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200356 def outputDir = "${entry.key}/${entryFile}"
357 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200358 def sha1File = "${gzFile}.sha1"
359 inputs.file sha1File
360 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200361 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200362 executable "bash"
363 args "-c", "tools/download_from_x20.py ${sha1File}"
364 }
365 }
366}
367
Rico Wind897bb712017-05-23 10:44:29 +0200368task downloadProguard {
369 cloudDependencies.each { entry ->
370 entry.value.each { entryFile ->
371 if (entryFile.contains("proguard")) {
372 dependsOn "download_deps_${entry.key}/${entryFile}"
373 }
374 }
375 }
376}
377
Tamas Kenez427205b2017-06-29 15:57:09 +0200378task downloadDx {
379 cloudDependencies.each { entry ->
380 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200381 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200382 dependsOn "download_deps_${entry.key}/${entryFile}"
383 }
384 }
385 }
386}
387
Tamas Kenez0e10c562017-06-08 10:00:34 +0200388task downloadAndroidCts {
389 cloudDependencies.each { entry ->
390 entry.value.each { entryFile ->
391 if (entryFile.contains("android_cts_baseline")) {
392 dependsOn "download_deps_${entry.key}/${entryFile}"
393 }
394 }
395 }
396}
397
Mads Ager418d1ca2017-05-22 09:35:49 +0200398task downloadDeps {
399 cloudDependencies.each { entry ->
400 entry.value.each { entryFile ->
401 dependsOn "download_deps_${entry.key}/${entryFile}"
402 }
403 }
404 if (!project.hasProperty('no_internal')) {
405 x20Dependencies.each { entry ->
406 entry.value.each { entryFile ->
407 dependsOn "download_deps_${entry.key}/${entryFile}"
408 }
409 }
410 }
411}
412
413allprojects {
414 sourceCompatibility = JavaVersion.VERSION_1_8
415 targetCompatibility = JavaVersion.VERSION_1_8
416}
417
Mads Agerc7d14d32018-09-27 11:09:46 +0200418// Javac often runs out of stack space when compiling the tests.
419// Increase the stack size for the javac process.
420tasks.withType(JavaCompile) {
421 options.fork = true
422 options.forkOptions.jvmArgs = ["-Xss4m"]
423}
424
Mads Ager418d1ca2017-05-22 09:35:49 +0200425tasks.withType(JavaCompile) {
426 options.compilerArgs << '-Xlint:unchecked'
427}
428
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200429if (!project.hasProperty('without_error_prone')) {
430 compileJava {
431 // Enable error prone for D8/R8 sources.
432 toolChain ErrorProneToolChain.create(project)
433 options.compilerArgs += errorProneConfiguration
434 }
435}
436
Mads Ager418d1ca2017-05-22 09:35:49 +0200437compileJctfCommonJava {
438 dependsOn 'copyAdditionalJctfCommonFiles'
439 options.compilerArgs = ['-Xlint:none']
440}
441
442compileJctfTestsJava {
443 dependsOn 'jctfCommonClasses'
444 options.compilerArgs = ['-Xlint:none']
445}
446
Yohann Roussel7f47c032017-09-14 12:19:06 +0200447task consolidatedLicense {
448 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
449 // corresponding to the effective list of embedded libraries.
450 dependsOn 'checkLicenses'
451 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
452 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
453 outputs.files license
454 doLast {
455 license.getParentFile().mkdirs()
456 license.createNewFile()
457 license.text = "This file lists all licenses for code distributed.\n"
458 license.text += "All non-library code has the following 3-Clause BSD license.\n"
459 license.text += "\n"
460 license.text += "\n"
461 license.text += file('LICENSE').text
462 license.text += "\n"
463 license.text += "\n"
464 license.text += "Summary of distributed libraries:\n"
465 license.text += "\n"
466 license.text += file('LIBRARY-LICENSE').text
467 license.text += "\n"
468 license.text += "\n"
469 license.text += "Licenses details:\n"
470 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
471 license.text += "\n"
472 license.text += "\n"
473 license.text += file.text
474 }
475 }
476}
477
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200478static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700479 // Everything under META-INF is not included by default.
480 // Should include before 'relocate' so that the service file path and its content
481 // are properly relocated as well.
482 task.mergeServiceFiles {
483 include 'META-INF/services/*'
484 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200485}
486
487static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000488 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200489 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000490 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
491 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000492 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000493 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200494 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
495 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
496 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200497 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000498}
499
500task repackageDeps(type: ShadowJar) {
501 configurations = [project.configurations.compile]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200502 mergeServiceFiles(it)
503 if (!project.hasProperty('lib_no_relocate')) {
504 configureRelocations(it)
505 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100506 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700507 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000508 baseName 'deps'
509}
510
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200511task repackageDepsForLib(type: ShadowJar) {
512 configurations = [project.configurations.compile]
513 mergeServiceFiles(it)
514 configureRelocations(it)
515 exclude { it.getRelativePath().getPathString() == "module-info.class" }
516 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
517 baseName 'r8lib_deps'
518}
519
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000520task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200521 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200522 mergeServiceFiles(it)
523 if (!project.hasProperty('lib_no_relocate')) {
524 configureRelocations(it)
525 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000526 baseName 'sources'
527}
528
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200529task R8libWithDeps(type: ShadowJar) {
530 from consolidatedLicense.outputs.files
531 baseName 'r8lib_with_deps'
532 classifier = null
533 version = null
534 manifest {
535 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
536 }
537 from repackageSources.outputs.files
538 from repackageDepsForLib.outputs.files
539}
540
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000541task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200542 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200543 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200544 classifier = null
545 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200546 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200547 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200548 }
549 // In order to build without dependencies, pass the exclude_deps property using:
550 // gradle -Pexclude_deps R8
551 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800552 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000553 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800554 } else {
555 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200556 }
557}
558
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000559task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200560 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200561 baseName 'd8'
562 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200563 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200564 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200565}
566
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200567task CompatDx(type: ShadowJar) {
568 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200569 baseName 'compatdx'
570 manifest {
571 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
572 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200573}
574
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200575task CompatProguard(type: ShadowJar) {
576 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200577 baseName 'compatproguard'
578 manifest {
579 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
580 }
Lars Bak44cef522017-08-10 16:02:39 +0200581}
582
Mads Ager418d1ca2017-05-22 09:35:49 +0200583task sourceJar(type: Jar, dependsOn: classes) {
584 classifier = 'src'
585 from sourceSets.main.allSource
586}
587
588task jctfCommonJar(type: Jar) {
589 from sourceSets.jctfCommon.output
590 baseName 'jctfCommon'
591}
592
593artifacts {
594 archives sourceJar
595}
596
597task createArtTests(type: Exec) {
598 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200599 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200600 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200601 inputs.file createArtTestsScript
602 outputs.dir outputDir
603 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200604 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200605 workingDir = projectDir
606}
607
608task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200609 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200610 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200611 inputs.file script
612 outputs.dir outputDir
613 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200614 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200615 workingDir = projectDir
616}
617
618compileTestJava {
619 dependsOn createArtTests
620 dependsOn createJctfTests
621}
622
Ian Zernyee23a172018-01-03 09:08:48 +0100623task buildD8ApiUsageSample(type: Jar) {
624 from sourceSets.apiUsageSample.output
625 baseName 'd8_api_usage_sample'
626 destinationDir file('tests')
627}
628
Ian Zerny923a0c12018-01-03 10:59:18 +0100629task buildR8ApiUsageSample(type: Jar) {
630 from sourceSets.apiUsageSample.output
631 baseName 'r8_api_usage_sample'
632 destinationDir file('tests')
633}
634
Yohann Roussel548ae942018-01-05 11:13:28 +0100635task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100636 dependsOn buildD8ApiUsageSample
637 dependsOn buildR8ApiUsageSample
638}
639
Mads Ager418d1ca2017-05-22 09:35:49 +0200640task buildDebugInfoExamplesDex {
641 def examplesDir = file("src/test/java")
642 def hostJar = "debuginfo_examples.jar"
643 def hostDexJar = "debuginfo_examples_dex.jar"
644 task "compile_debuginfo_examples"(type: JavaCompile) {
645 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
646 destinationDir = file("build/test/debuginfo_examples/classes")
647 classpath = sourceSets.main.compileClasspath
648 sourceCompatibility = JavaVersion.VERSION_1_7
649 targetCompatibility = JavaVersion.VERSION_1_7
650 options.compilerArgs += ["-Xlint:-options"]
651 }
652 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
653 archiveName = hostJar
654 destinationDir = file("build/test/")
655 from "build/test/debuginfo_examples/classes"
656 include "**/*.class"
657 }
658 task "dex_debuginfo_examples"(type: Exec,
659 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200660 if (OperatingSystem.current().isWindows()) {
661 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700662 } else if (OperatingSystem.current().isMacOsX()) {
663 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200664 } else {
665 executable file("tools/linux/dx/bin/dx");
666 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200667 args "--dex"
668 args "--output=build/test/${hostDexJar}"
669 args "build/test/${hostJar}"
670 inputs.file file("build/test/${hostJar}")
671 outputs.file file("build/test/${hostDexJar}")
672 }
673 dependsOn dex_debuginfo_examples
674}
675
676task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200677 def resourcesDir = file("src/test/debugTestResources")
678 def hostJar = "debug_test_resources.jar"
679 task "compile_debugTestResources"(type: JavaCompile) {
680 source = fileTree(dir: resourcesDir, include: '**/*.java')
681 destinationDir = file("build/test/debugTestResources/classes")
682 classpath = sourceSets.main.compileClasspath
683 sourceCompatibility = JavaVersion.VERSION_1_7
684 targetCompatibility = JavaVersion.VERSION_1_7
685 options.compilerArgs += ["-g", "-Xlint:-options"]
686 }
687 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
688 archiveName = hostJar
689 destinationDir = file("build/test/")
690 from "build/test/debugTestResources/classes"
691 include "**/*.class"
692 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200693 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
694 def java8HostJar = "debug_test_resources_java8.jar"
695 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
696 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
697 destinationDir = file("build/test/debugTestResourcesJava8/classes")
698 classpath = sourceSets.main.compileClasspath
699 sourceCompatibility = JavaVersion.VERSION_1_8
700 targetCompatibility = JavaVersion.VERSION_1_8
701 options.compilerArgs += ["-g", "-Xlint:-options"]
702 }
703 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
704 archiveName = java8HostJar
705 destinationDir = file("build/test/")
706 from "build/test/debugTestResourcesJava8/classes"
707 include "**/*.class"
708 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200709 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000710 def kotlinHostJar = "debug_test_resources_kotlin.jar"
711 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
712 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
713 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200714 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200715 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200716 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200717 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000718 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200719}
720
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100721// Examples used by tests, where Android specific APIs are used.
722task buildExampleAndroidApi(type: JavaCompile) {
723 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
724 destinationDir = file("build/test/examplesAndroidApi/classes")
725 classpath = files("third_party/android_jar/lib-v26/android.jar")
726 sourceCompatibility = JavaVersion.VERSION_1_8
727 targetCompatibility = JavaVersion.VERSION_1_8
728}
729
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100730task buildExampleKotlinJars {
731 def kotlinSrcDir = file("src/test/examplesKotlin")
732 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000733 def name = dir.getName();
734 dependsOn "compile_example_kotlin_${name}"
735 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
736 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
737 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100738 }
739 }
740}
741
Lars Bakc91e87e2017-08-18 08:53:10 +0200742// Proto lite generated code yields warnings when compiling with javac.
743// We change the options passed to javac to ignore it.
744compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
745
Søren Gjesse7320ce52018-05-07 15:45:22 +0200746
Mads Ager418d1ca2017-05-22 09:35:49 +0200747task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200748 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200749 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200750 def proguardScript
751 if (OperatingSystem.current().isWindows()) {
752 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
753 } else {
754 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
755 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200756 task extractExamplesRuntime(type: Sync) {
757 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000758 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200759 include "**/*.class"
760 includeEmptyDirs false
761 into "$buildDir/runtime/examples/"
762 }
763
Søren Gjesse7320ce52018-05-07 15:45:22 +0200764 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
765 from examplesDir
766 exclude "**/*.java"
767 exclude "**/keep-rules*.txt"
768 into file("build/test/examples/classes")
769 }
770
771 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +0200772 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +0200773 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +0200774 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200775 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200776 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200777 sourceCompatibility = JavaVersion.VERSION_1_7
778 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200779 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
780 }
Rico Wind40fd2c12018-09-12 12:14:44 +0200781 task "compile_examples_debuginfo_all"(type: JavaCompile) {
782 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200783 include "**/*.java"
784 destinationDir = file("build/test/examples/classes_debuginfo_all")
785 classpath = sourceSets.examples.compileClasspath
786 sourceCompatibility = JavaVersion.VERSION_1_7
787 targetCompatibility = JavaVersion.VERSION_1_7
788 options.compilerArgs = ["-g", "-Xlint:none"]
789 }
Rico Wind40fd2c12018-09-12 12:14:44 +0200790 task "compile_examples_debuginfo_none"(type: JavaCompile) {
791 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200792 include "**/*.java"
793 destinationDir = file("build/test/examples/classes_debuginfo_none")
794 classpath = sourceSets.examples.compileClasspath
795 sourceCompatibility = JavaVersion.VERSION_1_7
796 targetCompatibility = JavaVersion.VERSION_1_7
797 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200798 }
799 examplesDir.eachDir { dir ->
800 def name = dir.getName();
801 def exampleOutputDir = file("build/test/examples");
802 def jarName = "${name}.jar"
803 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200804 dependsOn "jar_example_${name}_debuginfo_all"
805 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200806 dependsOn "extractExamplesRuntime"
807 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +0200808 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
809 def proguardConfigPath = "${dir}/proguard.cfg"
810 if (new File(proguardConfigPath).exists()) {
811 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
812 archiveName = "${name}_pre_proguard.jar"
813 destinationDir = exampleOutputDir
814 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200815 include name + "/**/*.class"
816 with runtimeDependencies
817 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200818 }
819 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
820 def proguardJarPath = "${exampleOutputDir}/${jarName}"
821 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
822 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
823 inputs.files tasks.getByPath("pre_proguard_example_${name}")
824 inputs.file proguardConfigPath
825 // Enable these to get stdout and stderr redirected to files...
826 // standardOutput = new FileOutputStream('proguard.stdout')
827 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200828 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200829 " -outjars ${proguardJarPath}" +
830 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200831 " -printmapping ${proguardMapPath}"
832 if (OperatingSystem.current().isWindows()) {
833 executable "${proguardScript}"
834 args "${proguardArguments}"
835 } else {
836 executable "bash"
837 args "-c", "${proguardScript} '${proguardArguments}'"
838 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200839 outputs.file proguardJarPath
840 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200841 // TODO: Consider performing distinct proguard compilations.
842 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
843 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200844 into "${exampleOutputDir}"
845 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200846 }
847 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
848 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200849 into "${exampleOutputDir}"
850 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200851 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200852 } else {
853 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200854 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200855 destinationDir = exampleOutputDir
856 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +0200857 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200858 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +0200859 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +0200860 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200861 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
862 archiveName = "${name}_debuginfo_all.jar"
863 destinationDir = exampleOutputDir
864 from "build/test/examples/classes_debuginfo_all"
865 include name + "/**/*.class"
866 with runtimeDependencies
867 includeEmptyDirs false
868 }
869 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
870 archiveName = "${name}_debuginfo_none.jar"
871 destinationDir = exampleOutputDir
872 from "build/test/examples/classes_debuginfo_none"
873 include name + "/**/*.class"
874 with runtimeDependencies
875 includeEmptyDirs false
876 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200877 }
878 }
879}
880
881task buildExampleAndroidNJars {
882 dependsOn downloadDeps
883 def examplesDir = file("src/test/examplesAndroidN")
884 task "compile_examplesAndroidN"(type: JavaCompile) {
885 source = fileTree(dir: examplesDir, include: '**/*.java')
886 destinationDir = file("build/test/examplesAndroidN/classes")
887 classpath = sourceSets.main.compileClasspath
888 sourceCompatibility = JavaVersion.VERSION_1_8
889 targetCompatibility = JavaVersion.VERSION_1_8
890 options.compilerArgs += ["-Xlint:-options"]
891 }
892 examplesDir.eachDir { dir ->
893 def name = dir.getName();
894 def exampleOutputDir = file("build/test/examplesAndroidN");
895 def jarName = "${name}.jar"
896 dependsOn "jar_examplesAndroidN_${name}"
897 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
898 archiveName = jarName
899 destinationDir = exampleOutputDir
900 from "build/test/examplesAndroidN/classes"
901 include "**/" + name + "/**/*.class"
902 }
903 }
904}
905
906
907task buildExampleAndroidOJars {
908 dependsOn downloadDeps
909 def examplesDir = file("src/test/examplesAndroidO")
910 // NOTE: we want to enable a scenario when test needs to reference some
911 // classes generated by legacy (1.6) Java compiler to test some specific
912 // behaviour. To do so we compile all the java files located in sub-directory
913 // called 'legacy' with Java 1.6, then compile the rest of the files with
914 // Java 1.8 and a reference to previously generated 1.6 classes.
915
916 // Compiling all classes in dirs 'legacy' with old Java version.
917 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
918 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
919 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
920 classpath = sourceSets.main.compileClasspath
921 sourceCompatibility = JavaVersion.VERSION_1_6
922 targetCompatibility = JavaVersion.VERSION_1_6
923 options.compilerArgs += ["-Xlint:-options", "-parameters"]
924 }
925 // Compiling the rest of the files as Java 1.8 code.
926 task "compile_examplesAndroidO"(type: JavaCompile) {
927 dependsOn "compile_examplesAndroidO_Legacy"
928 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
929 destinationDir = file("build/test/examplesAndroidO/classes")
930 classpath = sourceSets.main.compileClasspath
931 classpath += files("build/test/examplesAndroidOLegacy/classes")
932 sourceCompatibility = JavaVersion.VERSION_1_8
933 targetCompatibility = JavaVersion.VERSION_1_8
934 options.compilerArgs += ["-Xlint:-options", "-parameters"]
935 }
936 examplesDir.eachDir { dir ->
937 def name = dir.getName();
938 def destinationDir = file("build/test/examplesAndroidO/classes");
939 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
940 task "generate_examplesAndroidO_${name}"(type: JavaExec,
941 dependsOn: "compile_examplesAndroidO") {
942 main = name + ".TestGenerator"
943 classpath = files(destinationDir, sourceSets.main.compileClasspath)
944 args destinationDir
945 }
946 } else {
947 task "generate_examplesAndroidO_${name}" () {}
948 }
949 }
950 examplesDir.eachDir { dir ->
951 def name = dir.getName();
952 def exampleOutputDir = file("build/test/examplesAndroidO");
953 def jarName = "${name}.jar"
954 dependsOn "jar_examplesAndroidO_${name}"
955 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
956 "generate_examplesAndroidO_${name}"]) {
957 archiveName = jarName
958 destinationDir = exampleOutputDir
959 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
960 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
961 include "**/" + name + "/**/*.class"
962 // Do not include generator into the test runtime jar, it is not useful.
963 // Otherwise, shrinking will need ASM jars.
964 exclude "**/TestGenerator*"
965 }
966 }
967}
968
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200969task buildExampleAndroidPJars {
970 dependsOn downloadDeps
971 def examplesDir = file("src/test/examplesAndroidP")
972
973 task "compile_examplesAndroidP"(type: JavaCompile) {
974 source = fileTree(dir: examplesDir, include: '**/*.java')
975 destinationDir = file("build/test/examplesAndroidP/classes")
976 classpath = sourceSets.main.compileClasspath
977 sourceCompatibility = JavaVersion.VERSION_1_8
978 targetCompatibility = JavaVersion.VERSION_1_8
979 options.compilerArgs += ["-Xlint:-options"]
980 }
981 examplesDir.eachDir { dir ->
982 def name = dir.getName();
983 def destinationDir = file("build/test/examplesAndroidP/classes");
984 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
985 task "generate_examplesAndroidP_${name}"(type: JavaExec,
986 dependsOn: "compile_examplesAndroidP") {
987 main = name + ".TestGenerator"
988 classpath = files(destinationDir, sourceSets.main.compileClasspath)
989 args destinationDir
990 }
991 } else {
992 task "generate_examplesAndroidP_${name}" () {}
993 }
994 }
995 examplesDir.eachDir { dir ->
996 def name = dir.getName();
997 def exampleOutputDir = file("build/test/examplesAndroidP");
998 def jarName = "${name}.jar"
999 dependsOn "jar_examplesAndroidP_${name}"
1000 task "jar_examplesAndroidP_${name}"(type: Jar,
1001 dependsOn: ["compile_examplesAndroidP",
1002 "generate_examplesAndroidP_${name}"]) {
1003 archiveName = jarName
1004 destinationDir = exampleOutputDir
1005 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1006 include "**/" + name + "/**/*.class"
1007 // Do not include generator into the test runtime jar, it is not useful.
1008 // Otherwise, shrinking will need ASM jars.
1009 exclude "**/TestGenerator*"
1010 }
1011 }
1012}
1013
Mikaël Peltier61633d42017-10-13 16:51:06 +02001014task buildExampleJava9Jars {
1015 def examplesDir = file("src/test/examplesJava9")
1016 examplesDir.eachDir { dir ->
1017 def name = dir.getName();
1018 def exampleOutputDir = file("build/test/examplesJava9");
1019 def jarName = "${name}.jar"
1020 dependsOn "jar_examplesJava9_${name}"
1021 task "jar_examplesJava9_${name}"(type: Jar) {
1022 archiveName = jarName
1023 destinationDir = exampleOutputDir
1024 from "src/test/examplesJava9" // Java 1.9 classes
1025 include "**/" + name + "/**/*.class"
1026 }
1027 }
1028}
1029
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001030task buildExamplesKotlin {
1031 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1032 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1033 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1034 } else if (!OperatingSystem.current().isLinux()) {
1035 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1036 "on your platform. It is fully supported on Linux and partially supported on " +
1037 "Mac OS and Windows")
1038 return;
1039 }
1040 def examplesDir = file("src/test/examplesKotlin")
1041 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001042 def name = dir.getName();
1043 dependsOn "dex_example_kotlin_${name}"
1044 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1045 def dexPath = file("${exampleOutputDir}")
1046 task "dex_example_kotlin_${name}"(type: dx.Dx,
1047 dependsOn: "compile_example_kotlin_${name}") {
1048 doFirst {
1049 if (!dexPath.exists()) {
1050 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001051 }
1052 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001053 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1054 destination = dexPath
1055 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001056 }
1057 }
1058}
1059
Sebastien Hertzd3313772018-01-16 14:12:37 +01001060task buildKotlinR8TestResources {
1061 def examplesDir = file("src/test/kotlinR8TestResources")
1062 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001063 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1064 def name = dir.getName()
1065 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
1066 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
Denis Vnukovc22da842018-03-14 12:57:20 -07001067 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
1068 def javaOutputJarName = "${name}.java.jar"
1069 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
1070 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1071 source = fileTree(dir: file("${examplesDir}/${name}"),
1072 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001073 destination = file(outputFile)
1074 targetVersion = kotlinTargetVersion
1075 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001076 task "${taskName}Java"(type: JavaCompile) {
1077 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1078 destinationDir = file(javaOutput)
1079 classpath = sourceSets.main.compileClasspath
1080 sourceCompatibility = JavaVersion.VERSION_1_6
1081 targetCompatibility = JavaVersion.VERSION_1_6
1082 options.compilerArgs += ["-g", "-Xlint:-options"]
1083 }
1084 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1085 archiveName = javaOutputJarName
1086 destinationDir = file(javaOutputJarDir)
1087 from javaOutput
1088 include "**/*.class"
1089 }
1090 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001091 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001092 }
1093}
1094
Mads Ager418d1ca2017-05-22 09:35:49 +02001095task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001096 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1097 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1098 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001099 } else if (!OperatingSystem.current().isLinux()) {
1100 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001101 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001102 return;
1103 }
1104 dependsOn buildDebugTestResourcesJars
1105 dependsOn buildExampleJars
1106 dependsOn buildExampleAndroidNJars
1107 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001108 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001109 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001110 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001111 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001112 def noDexTests = [
1113 "multidex",
1114 "multidex002",
1115 "multidex004",
1116 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001117 examplesDir.eachDir { dir ->
1118 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001119 if (!(name in noDexTests)) {
1120 dependsOn "dex_example_${name}"
1121 def exampleOutputDir = file("build/test/examples/" + name);
1122 def dexPath = file("${exampleOutputDir}")
1123 def debug = (name == "throwing")
1124 if (!dexPath.exists()) {
1125 dexPath.mkdirs()
1126 }
1127 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1128 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1129 destination = dexPath
1130 debug = debug
1131 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001132 }
1133 }
1134}
1135
1136task buildSmali {
1137 def smaliDir = file("src/test/smali")
1138 smaliDir.eachDirRecurse() { dir ->
1139 def name = dir.getName();
1140 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1141 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1142 smaliOutputDir.mkdirs()
1143 outputs.dir smaliOutputDir
1144 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1145 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1146 def javaFiles = fileTree(dir: dir, include: '*.java')
1147 def destDir = smaliOutputDir;
1148 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1149 def intermediateFileName = "${name}-intermediate.dex";
1150 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1151 if (javaFiles.empty) {
1152 if (!smaliFiles.empty) {
1153 dependsOn "${taskName}_smali"
1154 task "${taskName}_smali"(type: smali.Smali) {
1155 source = smaliFiles
1156 destination = destFile
1157 }
1158 }
1159 } else {
1160 dependsOn "${taskName}_dexmerger"
1161 task "${taskName}_smali"(type: smali.Smali) {
1162 source = smaliFiles
1163 destination = intermediateFile
1164 }
1165 task "${taskName}_java"(type: JavaCompile) {
1166 source = javaFiles
1167 destinationDir destDir
1168 classpath = sourceSets.main.compileClasspath
1169 sourceCompatibility = JavaVersion.VERSION_1_7
1170 targetCompatibility = JavaVersion.VERSION_1_7
1171 options.compilerArgs += ["-Xlint:-options"]
1172 }
1173 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1174 archiveName = "Test.jar"
1175 destinationDir = destDir
1176 from fileTree(dir: destDir, include: 'Test.class')
1177 }
1178 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1179 source = fileTree(dir: destDir, include: 'Test.jar')
1180 destination = destDir
1181 }
1182 task "${taskName}_dexmerger"(
1183 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1184 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1185 destination = destFile
1186 }
1187 }
1188 }
1189}
1190
1191tasks.withType(Test) {
1192 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1193 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1194 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1195 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1196 forkEvery = 0
1197 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1198 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001199 if (project.hasProperty('disable_assertions')) {
1200 enableAssertions = false
1201 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001202}
1203
1204task buildPreNJdwpTestsJar(type: Jar) {
1205 baseName = 'jdwp-tests-preN'
1206 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1207 // Exclude the classes containing java8
1208 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1209 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1210 includeEmptyDirs = false
1211}
1212
Ian Zerny74143162017-11-24 13:46:35 +01001213task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1214 def inFile = buildPreNJdwpTestsJar.archivePath
1215 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
1216 inputs.file inFile
1217 outputs.file outFile
1218 if (OperatingSystem.current().isWindows()) {
1219 executable file("tools/windows/dx/bin/dx.bat")
1220 } else if (OperatingSystem.current().isMacOsX()) {
1221 executable file("tools/mac/dx/bin/dx");
1222 } else {
1223 executable file("tools/linux/dx/bin/dx");
1224 }
1225 args "--dex"
1226 args "--output=${outFile}"
1227 args inFile
1228}
1229
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001230task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1231 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001232}
1233
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001234task AospJarTest(type: Exec) {
1235 dependsOn CompatDx, downloadDeps
1236 def script = "tools/test_aosp_jar.py"
1237 inputs.file script
1238 commandLine "python", script, "--no-build"
1239 workingDir = projectDir
1240}
1241
Mads Ager418d1ca2017-05-22 09:35:49 +02001242test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001243 if (project.hasProperty('generate_golden_files_to')) {
1244 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1245 assert project.hasProperty('HEAD_sha1')
1246 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1247 }
1248
1249 if (project.hasProperty('use_golden_files_in')) {
1250 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1251 assert project.hasProperty('HEAD_sha1')
1252 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1253 }
1254
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001255 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001256 // R8.jar is required for running bootstrap tests.
1257 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001258 testLogging.exceptionFormat = 'full'
1259 if (project.hasProperty('print_test_stdout')) {
1260 testLogging.showStandardStreams = true
1261 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001262 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001263 println "Running with non default vm: " + project.property('dex_vm')
1264 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001265 if (project.property('dex_vm').startsWith('4.4.4') ||
1266 project.property('dex_vm').startsWith('5.1.1') ||
1267 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001268 // R8 and D8 compute the dex file version number based on the input.
1269 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1270 // Therefore we skip the jack generated art tests with those art versions.
1271 exclude "com/android/tools/r8/art/jack/**"
1272 }
1273 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001274
Mads Ager418d1ca2017-05-22 09:35:49 +02001275 if (project.hasProperty('one_line_per_test')) {
1276 beforeTest { desc ->
1277 println "Start executing test ${desc.name} [${desc.className}]"
1278 }
1279 afterTest { desc, result ->
1280 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1281 }
1282 }
1283 if (project.hasProperty('no_internal')) {
1284 exclude "com/android/tools/r8/internal/**"
1285 }
1286 if (project.hasProperty('only_internal')) {
1287 include "com/android/tools/r8/internal/**"
1288 }
1289 if (project.hasProperty('tool')) {
1290 if (project.property('tool') == 'r8') {
1291 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001292 exclude "com/android/tools/r8/jctf/d8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001293 exclude "com/android/tools/r8/jctf/r8cf/**"
1294 } else if (project.property('tool') == 'd8') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001295 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001296 exclude "com/android/tools/r8/jctf/r8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001297 exclude "com/android/tools/r8/jctf/r8cf/**"
1298 } else {
1299 assert(project.property('tool') == 'r8cf')
1300 exclude "com/android/tools/r8/art/*/d8/**"
1301 exclude "com/android/tools/r8/art/*/r8/**"
1302 exclude "com/android/tools/r8/jctf/d8/**"
1303 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001304 }
1305 }
1306 if (!project.hasProperty('all_tests')) {
1307 exclude "com/android/tools/r8/art/dx/**"
1308 exclude "com/android/tools/r8/art/jack/**"
1309 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001310 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001311 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001312 }
1313 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001314 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001315 }
1316 if (project.hasProperty('jctf_compile_only')) {
1317 println "JCTF: compiling only"
1318 systemProperty 'jctf_compile_only', '1'
1319 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001320 if (project.hasProperty('test_dir')) {
1321 systemProperty 'test_dir', project.property('test_dir')
1322 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001323 if (project.hasProperty('aosp_jar')) {
1324 dependsOn AospJarTest
1325 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001326
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001327 if (OperatingSystem.current().isLinux()
1328 || OperatingSystem.current().isMacOsX()
1329 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001330 if (OperatingSystem.current().isMacOsX()) {
1331 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1332 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1333 "See tools/docker/README.md for details.")
1334 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001335 if (OperatingSystem.current().isWindows()) {
1336 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1337 "Art only runs on Linux and tests requiring Art will be skipped")
1338 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001339 dependsOn downloadDeps
1340 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001341 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001342 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001343 dependsOn buildSmali
1344 dependsOn jctfCommonJar
1345 dependsOn jctfTestsClasses
1346 dependsOn buildDebugInfoExamplesDex
1347 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001348 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001349 } else {
1350 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001351 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001352 }
1353}
1354
1355// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1356//
1357// To build and upload a new set of the Art tests for use with R8 follow these steps:
1358//
1359// First of all an Android checkout is required. Currently it must be located
1360// in $HOME/android/master.
1361//
1362// TODO(ricow): simplify this
1363//
1364// Before: update the checked in art, see scripts/update-host-art.sh
1365//
1366// 1. Get an android checkout in $HOME/android/master and apply the patch from
1367// https://android-review.googlesource.com/#/c/294187/
1368//
1369// 2. run the following commands in the Android checkout directory:
1370//
1371// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001372// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1373// m desugar
1374// m -j30 test-art-host
1375// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1376//
1377// Without running the test.py command the classes.jar file used by desugar in
1378// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1379// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001380//
1381// 3. In the R8 project root directory, make sure we have a clean state before starting:
1382// tools/gradle.py downloadDeps
1383// tools/gradle.py clean
1384// rm -rf tests/art
1385//
1386// 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 +02001387// Make sure you have smali on your path, please use the build binary in the
1388// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1389// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1390// 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 +02001391// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1392// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001393//
Søren Gjesse34b77732017-07-07 13:56:21 +02001394// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001395//
1396// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1397// skippedTests with an explanation. Rerun from step 3.
1398//
1399// 5. Run the tests:
1400// tools/gradle.py clean
1401// tools/test.py
1402//
Søren Gjesse34b77732017-07-07 13:56:21 +02001403// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1404// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1405// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001406//
Søren Gjesse34b77732017-07-07 13:56:21 +02001407// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001408// cd tests
1409// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001410//
1411// 7. Update the manifest file describing the Android repo used:
1412// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001413
1414enum DexTool {
1415 JACK,
1416 DX
1417}
1418
1419def androidCheckoutDir = file("${System.env.HOME}/android/master")
1420def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1421def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1422
1423def artTestDir = file("${androidCheckoutDir}/art/test")
1424
1425if (project.hasProperty('android_source')) {
1426 task buildArtTests {
1427 outputs.upToDateWhen { false }
1428 def toBeTriaged = [
1429 "903-hello-tagging",
1430 "904-object-allocation",
1431 "905-object-free",
1432 "906-iterate-heap",
1433 "907-get-loaded-classes",
1434 "908-gc-start-finish",
1435 "954-invoke-polymorphic-verifier",
1436 "955-methodhandles-smali",
1437 "596-monitor-inflation",
1438 ]
1439 def skippedTests = toBeTriaged + [
1440 // This test produces no jar.
1441 "000-nop",
1442 // This does not build, as it tests the error when the application exceeds more
1443 // than 65536 methods
1444 "089-many-methods",
1445 // Requires some jack beta jar
1446 "956-methodhandles",
1447 ]
1448
1449 def skippedTestsDx = [
1450 // Tests with custom build scripts, where javac is not passed the options
1451 // -source 1.7 -target 1.7.
1452 "462-checker-inlining-across-dex-files",
1453 "556-invoke-super",
1454 "569-checker-pattern-replacement",
1455 // These tests use jack even when --build-with-javac-dx is specified.
1456 "004-JniTest",
1457 "048-reflect-v8",
1458 "146-bad-interface",
1459 "563-checker-invoke-super",
1460 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1461 "604-hot-static-interface",
1462 "957-methodhandle-transforms",
1463 "958-methodhandle-emulated-stackframe",
1464 "959-invoke-polymorphic-accessors",
1465 "961-default-iface-resolution-gen",
1466 "962-iface-static",
1467 "963-default-range-smali",
1468 "964-default-iface-init-gen",
1469 "965-default-verify",
1470 "966-default-conflict",
1471 "967-default-ame",
1472 "968-default-partial-compile-gen",
1473 "969-iface-super",
1474 "970-iface-super-resolution-gen",
1475 "971-iface-super",
1476 // These tests does not build with --build-with-javac-dx
1477 "004-NativeAllocations", // Javac error
1478 "031-class-attributes",
1479 "138-duplicate-classes-check",
1480 "157-void-class", // Javac error
1481 "580-checker-string-factory-intrinsics",
1482 "612-jit-dex-cache",
1483 "613-inlining-dex-cache",
1484 "900-hello-plugin", // --experimental agents
1485 "901-hello-ti-agent", // --experimental agents
1486 "902-hello-transformation", // --experimental agents
1487 "909-attach-agent", // --experimental agents
1488 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1489 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1490 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1491 "960-default-smali", // --experimental default-methods
1492 // These tests force the build to use jack
1493 "953-invoke-polymorphic-compiler",
1494 "958-methodhandle-stackframe",
1495 ]
1496
1497 def artTestBuildDir = file("${projectDir}/tests/art")
1498
1499 if (androidCheckoutDir.exists()) {
1500 dependsOn downloadDeps
1501 artTestBuildDir.mkdirs()
1502 // Ensure Jack server is running.
1503 "${androidCheckoutJackServer} start-server".execute()
1504 artTestDir.eachDir { dir ->
1505 def name = dir.getName();
1506 def markerFile = dir.toPath().resolve("info.txt").toFile();
1507 if (markerFile.exists() && !(name in skippedTests)) {
1508 if (!(name in skippedTestsDx)) {
1509 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1510 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001511 // After Android O, Jack is no longer alive
1512 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001513 }
1514 }
1515 }
1516 doFirst {
1517 if (!androidCheckoutDir.exists()) {
1518 throw new InvalidUserDataException(
1519 "This task requires an Android checkout in ${androidCheckoutDir}");
1520 } else if (!androidCheckoutJack.exists() ||
1521 !androidCheckoutJackServer.exists()) {
1522 throw new InvalidUserDataException(
1523 "This task requires that tools for host testing have been build in the " +
1524 "Android checkout in ${androidCheckoutDir}");
1525 }
1526 }
1527 doLast {
1528 copy {
1529 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1530 into file("${artTestBuildDir}/lib64")
1531 include 'lib*.so'
1532 }
1533 copy {
1534 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1535 into file("${artTestBuildDir}/lib64")
1536 include 'libart.so'
1537 include 'libbacktrace.so'
1538 include 'libbase.so'
1539 include 'libc++.so'
1540 include 'libcutils.so'
1541 include 'liblz4.so'
1542 include 'liblzma.so'
1543 include 'libnativebridge.so'
1544 include 'libnativeloader.so'
1545 include 'libsigchain.so'
1546 include 'libunwind.so'
1547 include 'libziparchive.so'
1548 }
1549 copy {
1550 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1551 into file("${artTestBuildDir}/lib")
1552 include 'lib*.so'
1553 }
1554 copy {
1555 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1556 into file("${artTestBuildDir}/lib")
1557 include 'libart.so'
1558 include 'libbacktrace.so'
1559 include 'libbase.so'
1560 include 'libc++.so'
1561 include 'libcutils.so'
1562 include 'liblz4.so'
1563 include 'liblzma.so'
1564 include 'libnativebridge.so'
1565 include 'libnativeloader.so'
1566 include 'libsigchain.so'
1567 include 'libunwind.so'
1568 include 'libziparchive.so'
1569 }
1570 }
1571 }
1572}
1573
1574def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1575 def artTestDir = file("${androidCheckoutDir}/art/test")
1576 def artRunTestScript = file("${artTestDir}/run-test")
1577 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001578 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001579 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1580
Søren Gjesse34b77732017-07-07 13:56:21 +02001581 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001582 def buildTask = "build_art_test_${dexToolName}_${name}"
1583 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1584 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1585 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1586
1587 def buildInputs = fileTree(dir: dir, include: '**/*')
1588 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1589 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1590 testDir.mkdirs()
1591 if (dexTool == DexTool.DX) {
1592 task "$buildTask"(type: Exec) {
1593 outputs.upToDateWhen { false }
1594 inputs.file buildInputs
1595 executable "${artRunTestScript}"
1596 args "--host"
1597 args "--build-only"
1598 args "--build-with-javac-dx"
1599 args "--output-path", "${testDir}"
1600 args "${name}"
1601 environment DX: "${dxExecutable.absolutePath}"
1602 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001603 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001604 outputs.file outputJar
1605 }
1606 } else {
1607 assert dexTool == DexTool.JACK
1608 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1609 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1610 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1611 task "$buildTask"(type: Exec) {
1612 outputs.upToDateWhen { false }
1613 inputs.file buildInputs
1614 executable "${artRunTestScript}"
1615 args "--host"
1616 args "--build-only"
1617 args "--output-path", "${testDir}"
1618 args "${name}"
1619 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1620 environment JACK_CLASSPATH: jackClasspath
1621 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1622 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1623 outputs.file outputJar
1624 }
1625 }
1626 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1627 outputs.upToDateWhen { false }
1628 executable "/bin/bash"
1629 args "-c"
1630 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1631 " ${testDir}/classes-ex ${testDir}/check"
1632 }
1633
1634 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001635 // Directory that contains smali files is either smali, or smali/art
1636 def smali_dir = file("${dir}/smali/art")
1637 if (smali_dir.exists()) {
1638 workingDir "${testDir}/smali/art"
1639 } else {
1640 workingDir "${testDir}/smali"
1641 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001642 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001643 // This is the command line options for smali prior to 2.2.1, where smali got a new
1644 // command line interface.
1645 args "-c", "smali a *.smali"
1646 // This is the command line options for smali 2.2.1 and later.
1647 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001648 }
1649
1650 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1651 def smali_dir = file("${dir}/smali")
1652 outputs.upToDateWhen { false }
1653 if (smali_dir.exists() && dexTool == DexTool.DX) {
1654 dependsOn smaliToDexTask
1655 }
1656 from("${artTestDir}/${name}") {
1657 include 'check'
1658 }
1659 into testDir
1660 }
1661
1662 return copyCheckTask
1663}
1664
1665task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001666 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001667 classpath = sourceSets.main.compileClasspath
1668 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001669 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001670 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001671 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001672 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001673 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001674 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001675 include '**/com/android/tools/r8/CompilationMode.java'
1676 include '**/com/android/tools/r8/D8.java'
1677 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001678 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1679 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001680 include '**/com/android/tools/r8/Diagnostic.java'
1681 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001682 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1683 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001684 include '**/com/android/tools/r8/ProgramConsumer.java'
1685 include '**/com/android/tools/r8/ProgramResource.java'
1686 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001687 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001688 include '**/com/android/tools/r8/ResourceException.java'
1689 include '**/com/android/tools/r8/StringConsumer.java'
1690 include '**/com/android/tools/r8/StringResource.java'
1691 include '**/com/android/tools/r8/Version.java'
1692 include '**/com/android/tools/r8/origin/*.java'
1693}
1694
1695task javadocR8(type: Javadoc) {
1696 title "R8 API"
1697 classpath = sourceSets.main.compileClasspath
1698 source = sourceSets.main.allJava
1699 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
1700 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
1701 include '**/com/android/tools/r8/BaseCommand.java'
1702 include '**/com/android/tools/r8/BaseCompilerCommand.java'
1703 include '**/com/android/tools/r8/ClassFileConsumer.java'
1704 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
1705 include '**/com/android/tools/r8/CompilationFailedException.java'
1706 include '**/com/android/tools/r8/CompilationMode.java'
1707 include '**/com/android/tools/r8/R8.java'
1708 include '**/com/android/tools/r8/R8Command.java'
1709 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1710 include '**/com/android/tools/r8/Diagnostic.java'
1711 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001712 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1713 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001714 include '**/com/android/tools/r8/ProgramConsumer.java'
1715 include '**/com/android/tools/r8/ProgramResource.java'
1716 include '**/com/android/tools/r8/ProgramResourceProvider.java'
1717 include '**/com/android/tools/r8/Resource.java'
1718 include '**/com/android/tools/r8/ResourceException.java'
1719 include '**/com/android/tools/r8/StringConsumer.java'
1720 include '**/com/android/tools/r8/StringResource.java'
1721 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001722 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001723}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001724
1725task copyMavenDeps(type: Copy) {
1726 from configurations.compile into "$buildDir/deps"
1727 from configurations.testCompile into "$buildDir/deps"
1728}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001729
1730// This task allows to build class files from Java 9 source in order to use them as inputs of
1731// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1732// to the D8 repository because there is no way to generate them on all computers due to the need of
1733// Java 9.
1734// Use the following command to rebuild class files of tests:
1735// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1736task buildJava9Tests {
1737 def javacOutputFolder = getTemporaryDir();
1738 def examplesDir = file("src/test/examplesJava9")
1739
1740 task "compile_Java9examples"(type: JavaCompile) {
1741 doFirst {
1742 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1743 throw new GradleException("Set java9Home property.")
1744 }
1745 }
1746
1747 source = fileTree(dir: examplesDir, include: '**/*.java')
1748 destinationDir = javacOutputFolder
1749 classpath = sourceSets.main.compileClasspath
1750 options.compilerArgs += ["-Xlint:-options"]
1751 sourceCompatibility = JavaVersion.VERSION_1_9
1752 targetCompatibility = JavaVersion.VERSION_1_9
1753 options.fork = true
1754
1755 if (project.hasProperty('java9Home')) {
1756 options.forkOptions.javaHome = file(getProperty('java9Home'))
1757 }
1758
1759 doLast {
1760 def classfileFrom = copySpec {
1761 from javacOutputFolder
1762 include "**/*.class"
1763 }
1764 copy {
1765 into examplesDir
1766 with classfileFrom
1767 }
1768 delete javacOutputFolder
1769 }
1770 }
1771
1772 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001773}