blob: 889382078b6bb49a2575ff29c57ad6c83464cd48 [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
10apply plugin: 'java'
11apply plugin: 'idea'
Stephan Herhut417a72a2017-07-18 10:38:30 +020012apply plugin: 'com.google.protobuf'
Yohann Roussel7f47c032017-09-14 12:19:06 +020013apply plugin: 'com.cookpad.android.licensetools'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020014apply plugin: 'net.ltgt.errorprone-base'
Stephan Herhut52cb1022017-10-24 15:10:41 +020015apply plugin: "net.ltgt.apt"
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020016
Søren Gjessed4bdd042017-11-23 11:44:50 +010017// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
18// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
19// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
20// for context.
21idea {
22 module {
23 outputDir file('build/classes/main')
24 testOutputDir file('build/classes/test')
25 }
26}
27
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020028def errorProneConfiguration = [
29 '-XepDisableAllChecks',
30 // D8 want to use reference equality, thus disable the checker explicitly
31 '-Xep:ReferenceEquality:OFF',
Stephan Herhute4d101c2017-11-22 12:18:02 +010032 '-Xep:ClassCanBeStatic:ERROR',
33 '-Xep:OperatorPrecedence:ERROR',
34 '-Xep:RemoveUnusedImports:ERROR',
35 '-Xep:MissingOverride:ERROR',
Stephan Herhute4d101c2017-11-22 12:18:02 +010036 '-Xep:IntLongMath:ERROR',
37 '-Xep:EqualsHashCode:ERROR',
38 '-Xep:InconsistentOverloads:ERROR',
39 '-Xep:ArrayHashCode:ERROR',
40 '-Xep:EqualsIncompatibleType:ERROR',
41 '-Xep:NonOverridingEquals:ERROR',
42 '-Xep:FallThrough:ERROR',
43 '-Xep:MissingCasesInEnumSwitch:ERROR',
44 '-Xep:MissingDefault:ERROR',
45 '-Xep:MultipleTopLevelClasses:ERROR',
46 '-Xep:NarrowingCompoundAssignment:ERROR',
47 '-Xep:BoxedPrimitiveConstructor:ERROR']
Mads Ager418d1ca2017-05-22 09:35:49 +020048
49apply from: 'copyAdditionalJctfCommonFiles.gradle'
50
Sebastien Hertze2687b62017-07-25 11:16:04 +020051
52if (project.hasProperty('with_code_coverage')) {
53 apply plugin: 'jacoco'
54}
55
Mads Ager418d1ca2017-05-22 09:35:49 +020056repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020057 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020058 mavenCentral()
59}
60
Stephan Herhut417a72a2017-07-18 10:38:30 +020061buildscript {
62 repositories {
63 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020064 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020065 maven {
66 url "https://plugins.gradle.org/m2/"
67 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020068 }
69 dependencies {
70 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020071 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Mads Ager1d5ae402017-09-22 12:30:56 +020072 // TODO(ager): shadow does not support java9 class files yet. Once it does,
73 // we should use the offial version instead of our fork using ASM 6.0 to
74 // support java9.
75 // classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
76 classpath files("third_party/shadow/shadow-2.0.1.jar")
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020077 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020078 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Stephan Herhut417a72a2017-07-18 10:38:30 +020079 }
80}
81
Mads Ager418d1ca2017-05-22 09:35:49 +020082// Custom source set for example tests and generated tests.
83sourceSets {
84 test {
85 java {
86 srcDirs = [
87 'src/test/java',
88 'build/generated/test/java',
89 ]
90 }
91 }
Mads Ager22847672017-11-14 09:59:26 +010092 bsPatch {
93 java {
94 srcDirs = [
95 'src/bspatch/java',
96 'src/main/java'
97 ]
98 }
99 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100100 apiUsageSample {
101 java {
102 srcDirs = ['src/test/apiUsageSample']
103 }
104 output.resourcesDir = 'build/classes/apiUsageSample'
105 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200106 debugTestResources {
107 java {
108 srcDirs = ['src/test/debugTestResources']
109 }
110 output.resourcesDir = 'build/classes/debugTestResources'
111 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200112 debugTestResourcesJava8 {
113 java {
114 srcDirs = ['src/test/debugTestResourcesJava8']
115 }
116 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
117 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200118 debugTestResourcesKotlin {
119 java {
120 srcDirs = ['src/test/debugTestResourcesKotlin']
121 }
122 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
123 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200124 examples {
125 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +0200126 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
127 }
128 proto {
129 srcDirs = [
130 'src/test/examples',
131 ]
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
Yohann Roussel126f6872017-08-03 16:25:32 +0200190configurations {
191 supportLibs
192}
193
Mads Ager418d1ca2017-05-22 09:35:49 +0200194dependencies {
195 compile 'net.sf.jopt-simple:jopt-simple:4.6'
Mads Agercd06c802017-08-22 13:44:34 +0200196 compile 'com.googlecode.json-simple:json-simple:1.1'
Mads Ager0aa48052017-09-15 12:39:15 +0200197 // Include all of guava when compiling the code, but exclude annotations that we don't
198 // need from the packaging.
199 compileOnly('com.google.guava:guava:23.0')
200 compile('com.google.guava:guava:23.0', {
201 exclude group: 'com.google.errorprone'
202 exclude group: 'com.google.code.findbugs'
203 exclude group: 'com.google.j2objc'
204 exclude group: 'org.codehaus.mojo'
205 })
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200206 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200207 compile group: 'org.ow2.asm', name: 'asm', version: '6.0'
208 compile group: 'org.ow2.asm', name: 'asm-commons', version: '6.0'
209 compile group: 'org.ow2.asm', name: 'asm-tree', version: '6.0'
Ian Zerny282ffa82017-10-30 12:19:02 +0100210 compile group: 'org.ow2.asm', name: 'asm-analysis', version: '6.0'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200211 compile group: 'org.ow2.asm', name: 'asm-util', version: '6.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200212 testCompile sourceSets.examples.output
213 testCompile 'junit:junit:4.12'
214 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
215 testCompile files('third_party/jasmin/jasmin-2.4.jar')
216 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200217 testCompile files('third_party/ddmlib/ddmlib.jar')
Mads Ager22847672017-11-14 09:59:26 +0100218 bsPatchCompile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
Mads Ager418d1ca2017-05-22 09:35:49 +0200219 jctfCommonCompile 'junit:junit:4.12'
220 jctfTestsCompile 'junit:junit:4.12'
221 jctfTestsCompile sourceSets.jctfCommon.output
Mikaël Peltier7345e482017-10-17 17:57:48 +0200222 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
223 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200224 // Import Guava for @Nullable annotation
225 examplesCompile 'com.google.guava:guava:23.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200226 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200227 examplesCompileOnly "com.google.auto.value:auto-value:1.5"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200228 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200229 supportLibs 'com.android.support:support-v4:25.4.0'
230 supportLibs 'junit:junit:4.12'
231 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Yohann Rousselbb571622017-11-09 10:47:36 +0100232 apiUsageSampleCompile sourceSets.main.output
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100233 debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.2.0'
234 examplesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.2.0'
Sebastien Hertzd3313772018-01-16 14:12:37 +0100235 kotlinR8TestResourcesCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.2.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200236 apt 'com.google.auto.value:auto-value:1.5'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200237}
238
Mads Ager22847672017-11-14 09:59:26 +0100239configurations.bsPatchCompile.extendsFrom configurations.compile
240
Yohann Roussel7f47c032017-09-14 12:19:06 +0200241licenseTools {
242 licensesYaml = file('LIBRARY-LICENSE')
243}
244
Stephan Herhut417a72a2017-07-18 10:38:30 +0200245protobuf {
246 protoc {
247 // Download from repositories
248 artifact = 'com.google.protobuf:protoc:3.0.0'
249 }
250 plugins {
251 javalite {
252 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
253 }
254 }
255 generateProtoTasks {
256 all().each { task ->
257 task.builtins {
258 // Disable the java code generator, as we want javalite only.
259 remove java
260 }
261 task.plugins {
262 javalite {}
263 }
264 }
265 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200266}
267
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200268def osString = OperatingSystem.current().isLinux() ? "linux" :
269 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200270
271def cloudDependencies = [
272 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200273 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200274 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200275 ],
276 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200277 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100278 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200279 "android_jar/lib-v19",
280 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100281 "android_jar/lib-v22",
282 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200283 "android_jar/lib-v24",
284 "android_jar/lib-v25",
285 "android_jar/lib-v26",
286 "proguard/proguard5.2.1",
287 "gradle/gradle",
288 "jdwp-tests",
289 "jasmin",
290 "jctf",
291 "kotlin",
292 "android_cts_baseline",
293 "shadow",
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200294 "ddmlib",
Søren Gjessec9b3fc72018-02-09 15:44:54 +0100295 "core-lambda-stubs",
Mads Ager418d1ca2017-05-22 09:35:49 +0200296 ],
297 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
298 // container on other platforms where supported.
299 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200300 "linux/art",
301 "linux/art-5.1.1",
302 "linux/art-6.0.1",
303 "linux/art-7.0.0",
304 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100305 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200306 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200307 ]
308]
309
310cloudDependencies.each { entry ->
311 entry.value.each { entryFile ->
312 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200313 def outputDir = "${entry.key}/${entryFile}"
314 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200315 def sha1File = "${gzFile}.sha1"
316 inputs.file sha1File
317 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200318 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200319 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
320 if (OperatingSystem.current().isWindows()) {
321 executable "download_from_google_storage.bat"
322 args dlFromStorageArgs
323 } else {
324 executable "bash"
325 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
326 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200327 }
328 }
329}
330
331def x20Dependencies = [
332 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200333 "gmail/gmail_android_170604.16",
334 "gmscore/v4",
335 "gmscore/v5",
336 "gmscore/v6",
337 "gmscore/v7",
338 "gmscore/v8",
339 "gmscore/gmscore_v9",
340 "gmscore/gmscore_v10",
341 "gmscore/latest",
342 "photos/2017-06-06",
343 "youtube/youtube.android_12.10",
344 "youtube/youtube.android_12.17",
345 "youtube/youtube.android_12.22",
346 "proguardsettings",
347 "proguard/proguard_internal_159423826",
348 "framework",
349 "goyt",
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
418tasks.withType(JavaCompile) {
419 options.compilerArgs << '-Xlint:unchecked'
420}
421
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200422if (!project.hasProperty('without_error_prone')) {
423 compileJava {
424 // Enable error prone for D8/R8 sources.
425 toolChain ErrorProneToolChain.create(project)
426 options.compilerArgs += errorProneConfiguration
427 }
428}
429
Mads Ager418d1ca2017-05-22 09:35:49 +0200430compileJctfCommonJava {
431 dependsOn 'copyAdditionalJctfCommonFiles'
432 options.compilerArgs = ['-Xlint:none']
433}
434
435compileJctfTestsJava {
436 dependsOn 'jctfCommonClasses'
437 options.compilerArgs = ['-Xlint:none']
438}
439
Yohann Roussel7f47c032017-09-14 12:19:06 +0200440task consolidatedLicense {
441 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
442 // corresponding to the effective list of embedded libraries.
443 dependsOn 'checkLicenses'
444 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
445 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
446 outputs.files license
447 doLast {
448 license.getParentFile().mkdirs()
449 license.createNewFile()
450 license.text = "This file lists all licenses for code distributed.\n"
451 license.text += "All non-library code has the following 3-Clause BSD license.\n"
452 license.text += "\n"
453 license.text += "\n"
454 license.text += file('LICENSE').text
455 license.text += "\n"
456 license.text += "\n"
457 license.text += "Summary of distributed libraries:\n"
458 license.text += "\n"
459 license.text += file('LIBRARY-LICENSE').text
460 license.text += "\n"
461 license.text += "\n"
462 license.text += "Licenses details:\n"
463 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
464 license.text += "\n"
465 license.text += "\n"
466 license.text += file.text
467 }
468 }
469}
470
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000471static configureRelocations(ShadowJar task) {
472 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
473 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
474 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
475 task.relocate('org.apache.commons', 'com.android.tools.r8.org.apache.commons')
476 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
477 task.relocate('org.json.simple', 'com.android.tools.r8.org.json.simple')
478 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
479}
480
481task repackageDeps(type: ShadowJar) {
482 configurations = [project.configurations.compile]
483 configureRelocations(it)
484 baseName 'deps'
485}
486
487task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200488 from sourceSets.main.output
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000489 configureRelocations(it)
490 baseName 'sources'
491}
492
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000493task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200494 from consolidatedLicense.outputs.files
495 exclude { path ->
496 path.getRelativePath().getPathString().startsWith("META-INF")
497 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200498 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200499 classifier = null
500 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200501 manifest {
502 attributes 'Main-Class': 'com.android.tools.r8.R8'
503 }
504 // In order to build without dependencies, pass the exclude_deps property using:
505 // gradle -Pexclude_deps R8
506 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800507 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000508 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800509 } else {
510 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200511 }
512}
513
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000514task D8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200515 from consolidatedLicense.outputs.files
516 exclude { path ->
517 path.getRelativePath().getPathString().startsWith("META-INF")
518 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200519 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200520 classifier = null
521 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200522 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200523 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200524 }
525 // In order to build without dependencies, pass the exclude_deps property using:
526 // gradle -Pexclude_deps D8
527 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800528 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000529 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800530 } else {
531 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200532 }
533}
534
535task CompatDx(type: Jar) {
536 from sourceSets.main.output
537 baseName 'compatdx'
538 manifest {
539 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
540 }
541 // In order to build without dependencies, pass the exclude_deps property using:
542 // gradle -Pexclude_deps CompatDx
543 if (!project.hasProperty('exclude_deps')) {
544 // Also include dependencies
545 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
546 }
547}
548
Tamas Kenez73585922017-12-21 11:16:30 +0100549task DexFileMerger(type: Jar) {
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100550 from sourceSets.main.output
Tamas Kenez73585922017-12-21 11:16:30 +0100551 baseName 'dexfilemerger'
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100552 manifest {
Tamas Kenez73585922017-12-21 11:16:30 +0100553 attributes 'Main-Class': 'com.android.tools.r8.dexfilemerger.DexFileMerger'
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100554 }
555 // In order to build without dependencies, pass the exclude_deps property using:
556 // gradle -Pexclude_deps CompatDx
557 if (!project.hasProperty('exclude_deps')) {
558 // Also include dependencies
559 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
560 }
561}
562
Rico Windb8580432018-02-05 15:12:41 +0100563task DexSplitter(type: Jar) {
564 from sourceSets.main.output
565 baseName 'dexsplitter'
566 manifest {
567 attributes 'Main-Class': 'com.android.tools.r8.dexsplitter.DexSplitter'
568 }
569 // In order to build without dependencies, pass the exclude_deps property using:
570 // gradle -Pexclude_deps CompatDx
571 if (!project.hasProperty('exclude_deps')) {
572 // Also include dependencies
573 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
574 }
575}
576
Søren Gjesse1d21da72017-09-01 12:05:38 +0200577task CompatProguard(type: Jar) {
578 from sourceSets.main.output
579 baseName 'compatproguard'
580 manifest {
581 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
582 }
583 // In order to build without dependencies, pass the exclude_deps property using:
584 // gradle -Pexclude_deps CompatProguard
585 if (!project.hasProperty('exclude_deps')) {
586 // Also include dependencies
587 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
588 }
589}
590
Tamas Kenez971eec62017-05-24 11:08:40 +0200591task D8Logger(type: Jar) {
592 from sourceSets.main.output
593 baseName 'd8logger'
594 manifest {
595 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
596 }
597 // In order to build without dependencies, pass the exclude_deps property using:
598 // gradle -Pexclude_deps D8Logger
599 if (!project.hasProperty('exclude_deps')) {
600 // Also include dependencies
601 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
602 }
603}
604
Mads Ager418d1ca2017-05-22 09:35:49 +0200605task disasm(type: Jar) {
606 from sourceSets.main.output
607 baseName 'disasm'
608 manifest {
609 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
610 }
611 // In order to build without dependencies, pass the exclude_deps property using:
612 // gradle -Pexclude_deps D8
613 if (!project.hasProperty('exclude_deps')) {
614 // Also include dependencies
615 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
616 }
617}
618
619task bisect(type: Jar) {
620 from sourceSets.main.output
621 baseName 'bisect'
622 manifest {
623 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
624 }
625 // In order to build without dependencies, pass the exclude_deps property using:
626 // gradle -Pexclude_deps R8
627 if (!project.hasProperty('exclude_deps')) {
628 // Also include dependencies
629 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
630 }
631}
632
Lars Bak90c18042017-06-26 14:21:08 +0200633task DexSegments(type: Jar) {
634 from sourceSets.main.output
635 baseName 'dexsegments'
636 manifest {
637 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
638 }
639 // In order to build without dependencies, pass the exclude_deps property using:
640 // gradle -Pexclude_deps DexSegments
641 if (!project.hasProperty('exclude_deps')) {
642 // Also include dependencies
643 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
644 }
645}
646
Søren Gjessec4e5e932017-09-04 17:01:23 +0200647task maindex(type: Jar) {
648 from sourceSets.main.output
649 baseName 'maindex'
650 manifest {
651 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
652 }
653 // In order to build without dependencies, pass the exclude_deps property using:
654 // gradle -Pexclude_deps maindex
655 if (!project.hasProperty('exclude_deps')) {
656 // Also include dependencies
657 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
658 }
659}
660
Lars Bak44cef522017-08-10 16:02:39 +0200661task ExtractMarker(type: Jar) {
662 from sourceSets.main.output
663 baseName 'extractmarker'
664 manifest {
665 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
666 }
667 // In order to build without dependencies, pass the exclude_deps property using:
668 // gradle -Pexclude_deps ExtractMarker
669 if (!project.hasProperty('exclude_deps')) {
670 // Also include dependencies
671 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
672 }
673}
674
Mads Ager22847672017-11-14 09:59:26 +0100675task bspatch(type: Jar) {
676 from sourceSets.bsPatch.output
677 baseName 'bspatch'
678 manifest {
679 attributes 'Main-Class': 'com.android.tools.r8.dex.BSPatch'
680 }
681 // In order to build without dependencies, pass the exclude_deps property using:
682 // gradle -Pexclude_deps maindex
683 if (!project.hasProperty('exclude_deps')) {
684 // Also include dependencies
685 from {
686 configurations.bsPatchCompile.collect { it.isDirectory() ? it : zipTree(it) }
687 }
688 }
689}
690
Mads Ager418d1ca2017-05-22 09:35:49 +0200691task sourceJar(type: Jar, dependsOn: classes) {
692 classifier = 'src'
693 from sourceSets.main.allSource
694}
695
696task jctfCommonJar(type: Jar) {
697 from sourceSets.jctfCommon.output
698 baseName 'jctfCommon'
699}
700
701artifacts {
702 archives sourceJar
703}
704
705task createArtTests(type: Exec) {
706 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200707 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200708 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200709 inputs.file createArtTestsScript
710 outputs.dir outputDir
711 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200712 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200713 workingDir = projectDir
714}
715
716task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200717 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200718 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200719 inputs.file script
720 outputs.dir outputDir
721 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200722 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200723 workingDir = projectDir
724}
725
726compileTestJava {
727 dependsOn createArtTests
728 dependsOn createJctfTests
729}
730
Ian Zernyee23a172018-01-03 09:08:48 +0100731task buildD8ApiUsageSample(type: Jar) {
732 from sourceSets.apiUsageSample.output
733 baseName 'd8_api_usage_sample'
734 destinationDir file('tests')
735}
736
Ian Zerny923a0c12018-01-03 10:59:18 +0100737task buildR8ApiUsageSample(type: Jar) {
738 from sourceSets.apiUsageSample.output
739 baseName 'r8_api_usage_sample'
740 destinationDir file('tests')
741}
742
Yohann Roussel548ae942018-01-05 11:13:28 +0100743task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100744 dependsOn buildD8ApiUsageSample
745 dependsOn buildR8ApiUsageSample
746}
747
Mads Ager418d1ca2017-05-22 09:35:49 +0200748task buildDebugInfoExamplesDex {
749 def examplesDir = file("src/test/java")
750 def hostJar = "debuginfo_examples.jar"
751 def hostDexJar = "debuginfo_examples_dex.jar"
752 task "compile_debuginfo_examples"(type: JavaCompile) {
753 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
754 destinationDir = file("build/test/debuginfo_examples/classes")
755 classpath = sourceSets.main.compileClasspath
756 sourceCompatibility = JavaVersion.VERSION_1_7
757 targetCompatibility = JavaVersion.VERSION_1_7
758 options.compilerArgs += ["-Xlint:-options"]
759 }
760 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
761 archiveName = hostJar
762 destinationDir = file("build/test/")
763 from "build/test/debuginfo_examples/classes"
764 include "**/*.class"
765 }
766 task "dex_debuginfo_examples"(type: Exec,
767 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200768 if (OperatingSystem.current().isWindows()) {
769 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700770 } else if (OperatingSystem.current().isMacOsX()) {
771 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200772 } else {
773 executable file("tools/linux/dx/bin/dx");
774 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200775 args "--dex"
776 args "--output=build/test/${hostDexJar}"
777 args "build/test/${hostJar}"
778 inputs.file file("build/test/${hostJar}")
779 outputs.file file("build/test/${hostDexJar}")
780 }
781 dependsOn dex_debuginfo_examples
782}
783
784task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200785 def resourcesDir = file("src/test/debugTestResources")
786 def hostJar = "debug_test_resources.jar"
787 task "compile_debugTestResources"(type: JavaCompile) {
788 source = fileTree(dir: resourcesDir, include: '**/*.java')
789 destinationDir = file("build/test/debugTestResources/classes")
790 classpath = sourceSets.main.compileClasspath
791 sourceCompatibility = JavaVersion.VERSION_1_7
792 targetCompatibility = JavaVersion.VERSION_1_7
793 options.compilerArgs += ["-g", "-Xlint:-options"]
794 }
795 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
796 archiveName = hostJar
797 destinationDir = file("build/test/")
798 from "build/test/debugTestResources/classes"
799 include "**/*.class"
800 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200801 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
802 def java8HostJar = "debug_test_resources_java8.jar"
803 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
804 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
805 destinationDir = file("build/test/debugTestResourcesJava8/classes")
806 classpath = sourceSets.main.compileClasspath
807 sourceCompatibility = JavaVersion.VERSION_1_8
808 targetCompatibility = JavaVersion.VERSION_1_8
809 options.compilerArgs += ["-g", "-Xlint:-options"]
810 }
811 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
812 archiveName = java8HostJar
813 destinationDir = file("build/test/")
814 from "build/test/debugTestResourcesJava8/classes"
815 include "**/*.class"
816 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200817 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000818 def kotlinHostJar = "debug_test_resources_kotlin.jar"
819 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
820 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
821 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200822 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200823 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200824 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200825 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000826 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200827}
828
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100829// Examples used by tests, where Android specific APIs are used.
830task buildExampleAndroidApi(type: JavaCompile) {
831 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
832 destinationDir = file("build/test/examplesAndroidApi/classes")
833 classpath = files("third_party/android_jar/lib-v26/android.jar")
834 sourceCompatibility = JavaVersion.VERSION_1_8
835 targetCompatibility = JavaVersion.VERSION_1_8
836}
837
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100838task buildExampleKotlinJars {
839 def kotlinSrcDir = file("src/test/examplesKotlin")
840 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000841 def name = dir.getName();
842 dependsOn "compile_example_kotlin_${name}"
843 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
844 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
845 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100846 }
847 }
848}
849
Lars Bakc91e87e2017-08-18 08:53:10 +0200850// Proto lite generated code yields warnings when compiling with javac.
851// We change the options passed to javac to ignore it.
852compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
853
Mads Ager418d1ca2017-05-22 09:35:49 +0200854task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200855 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200856 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200857 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200858 def proguardScript
859 if (OperatingSystem.current().isWindows()) {
860 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
861 } else {
862 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
863 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200864 task extractExamplesRuntime(type: Sync) {
865 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000866 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200867 include "**/*.class"
868 includeEmptyDirs false
869 into "$buildDir/runtime/examples/"
870 }
871
872 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
873 source examplesDir, protoSourceDir
874 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200875 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200876 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200877 sourceCompatibility = JavaVersion.VERSION_1_7
878 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200879 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
880 }
881 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
882 source examplesDir, protoSourceDir
883 include "**/*.java"
884 destinationDir = file("build/test/examples/classes_debuginfo_all")
885 classpath = sourceSets.examples.compileClasspath
886 sourceCompatibility = JavaVersion.VERSION_1_7
887 targetCompatibility = JavaVersion.VERSION_1_7
888 options.compilerArgs = ["-g", "-Xlint:none"]
889 }
890 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
891 source examplesDir, protoSourceDir
892 include "**/*.java"
893 destinationDir = file("build/test/examples/classes_debuginfo_none")
894 classpath = sourceSets.examples.compileClasspath
895 sourceCompatibility = JavaVersion.VERSION_1_7
896 targetCompatibility = JavaVersion.VERSION_1_7
897 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200898 }
899 examplesDir.eachDir { dir ->
900 def name = dir.getName();
901 def exampleOutputDir = file("build/test/examples");
902 def jarName = "${name}.jar"
903 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200904 dependsOn "jar_example_${name}_debuginfo_all"
905 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200906 dependsOn "extractExamplesRuntime"
907 def runtimeDependencies = copySpec { }
908 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
909 // If we have any proto use, we have to include those classes and the runtime.
910 runtimeDependencies = copySpec {
911 from "$buildDir/runtime/examples/"
912 include "com/google/protobuf/**/*.class"
913 }
914 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200915 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
916 def proguardConfigPath = "${dir}/proguard.cfg"
917 if (new File(proguardConfigPath).exists()) {
918 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
919 archiveName = "${name}_pre_proguard.jar"
920 destinationDir = exampleOutputDir
921 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200922 include name + "/**/*.class"
923 with runtimeDependencies
924 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200925 }
926 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
927 def proguardJarPath = "${exampleOutputDir}/${jarName}"
928 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
929 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
930 inputs.files tasks.getByPath("pre_proguard_example_${name}")
931 inputs.file proguardConfigPath
932 // Enable these to get stdout and stderr redirected to files...
933 // standardOutput = new FileOutputStream('proguard.stdout')
934 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200935 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200936 " -outjars ${proguardJarPath}" +
937 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200938 " -printmapping ${proguardMapPath}"
939 if (OperatingSystem.current().isWindows()) {
940 executable "${proguardScript}"
941 args "${proguardArguments}"
942 } else {
943 executable "bash"
944 args "-c", "${proguardScript} '${proguardArguments}'"
945 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200946 outputs.file proguardJarPath
947 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200948 // TODO: Consider performing distinct proguard compilations.
949 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
950 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200951 into "${exampleOutputDir}"
952 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200953 }
954 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
955 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200956 into "${exampleOutputDir}"
957 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200958 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200959 } else {
960 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200961 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200962 destinationDir = exampleOutputDir
963 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200964 include name + "/**/*.class"
965 with runtimeDependencies
966 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200967 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200968 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
969 archiveName = "${name}_debuginfo_all.jar"
970 destinationDir = exampleOutputDir
971 from "build/test/examples/classes_debuginfo_all"
972 include name + "/**/*.class"
973 with runtimeDependencies
974 includeEmptyDirs false
975 }
976 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
977 archiveName = "${name}_debuginfo_none.jar"
978 destinationDir = exampleOutputDir
979 from "build/test/examples/classes_debuginfo_none"
980 include name + "/**/*.class"
981 with runtimeDependencies
982 includeEmptyDirs false
983 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200984 }
985 }
986}
987
988task buildExampleAndroidNJars {
989 dependsOn downloadDeps
990 def examplesDir = file("src/test/examplesAndroidN")
991 task "compile_examplesAndroidN"(type: JavaCompile) {
992 source = fileTree(dir: examplesDir, include: '**/*.java')
993 destinationDir = file("build/test/examplesAndroidN/classes")
994 classpath = sourceSets.main.compileClasspath
995 sourceCompatibility = JavaVersion.VERSION_1_8
996 targetCompatibility = JavaVersion.VERSION_1_8
997 options.compilerArgs += ["-Xlint:-options"]
998 }
999 examplesDir.eachDir { dir ->
1000 def name = dir.getName();
1001 def exampleOutputDir = file("build/test/examplesAndroidN");
1002 def jarName = "${name}.jar"
1003 dependsOn "jar_examplesAndroidN_${name}"
1004 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1005 archiveName = jarName
1006 destinationDir = exampleOutputDir
1007 from "build/test/examplesAndroidN/classes"
1008 include "**/" + name + "/**/*.class"
1009 }
1010 }
1011}
1012
1013
1014task buildExampleAndroidOJars {
1015 dependsOn downloadDeps
1016 def examplesDir = file("src/test/examplesAndroidO")
1017 // NOTE: we want to enable a scenario when test needs to reference some
1018 // classes generated by legacy (1.6) Java compiler to test some specific
1019 // behaviour. To do so we compile all the java files located in sub-directory
1020 // called 'legacy' with Java 1.6, then compile the rest of the files with
1021 // Java 1.8 and a reference to previously generated 1.6 classes.
1022
1023 // Compiling all classes in dirs 'legacy' with old Java version.
1024 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1025 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1026 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1027 classpath = sourceSets.main.compileClasspath
1028 sourceCompatibility = JavaVersion.VERSION_1_6
1029 targetCompatibility = JavaVersion.VERSION_1_6
1030 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1031 }
1032 // Compiling the rest of the files as Java 1.8 code.
1033 task "compile_examplesAndroidO"(type: JavaCompile) {
1034 dependsOn "compile_examplesAndroidO_Legacy"
1035 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1036 destinationDir = file("build/test/examplesAndroidO/classes")
1037 classpath = sourceSets.main.compileClasspath
1038 classpath += files("build/test/examplesAndroidOLegacy/classes")
1039 sourceCompatibility = JavaVersion.VERSION_1_8
1040 targetCompatibility = JavaVersion.VERSION_1_8
1041 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1042 }
1043 examplesDir.eachDir { dir ->
1044 def name = dir.getName();
1045 def destinationDir = file("build/test/examplesAndroidO/classes");
1046 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1047 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1048 dependsOn: "compile_examplesAndroidO") {
1049 main = name + ".TestGenerator"
1050 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1051 args destinationDir
1052 }
1053 } else {
1054 task "generate_examplesAndroidO_${name}" () {}
1055 }
1056 }
1057 examplesDir.eachDir { dir ->
1058 def name = dir.getName();
1059 def exampleOutputDir = file("build/test/examplesAndroidO");
1060 def jarName = "${name}.jar"
1061 dependsOn "jar_examplesAndroidO_${name}"
1062 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1063 "generate_examplesAndroidO_${name}"]) {
1064 archiveName = jarName
1065 destinationDir = exampleOutputDir
1066 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1067 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1068 include "**/" + name + "/**/*.class"
1069 // Do not include generator into the test runtime jar, it is not useful.
1070 // Otherwise, shrinking will need ASM jars.
1071 exclude "**/TestGenerator*"
1072 }
1073 }
1074}
1075
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001076task buildExampleAndroidPJars {
1077 dependsOn downloadDeps
1078 def examplesDir = file("src/test/examplesAndroidP")
1079
1080 task "compile_examplesAndroidP"(type: JavaCompile) {
1081 source = fileTree(dir: examplesDir, include: '**/*.java')
1082 destinationDir = file("build/test/examplesAndroidP/classes")
1083 classpath = sourceSets.main.compileClasspath
1084 sourceCompatibility = JavaVersion.VERSION_1_8
1085 targetCompatibility = JavaVersion.VERSION_1_8
1086 options.compilerArgs += ["-Xlint:-options"]
1087 }
1088 examplesDir.eachDir { dir ->
1089 def name = dir.getName();
1090 def destinationDir = file("build/test/examplesAndroidP/classes");
1091 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1092 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1093 dependsOn: "compile_examplesAndroidP") {
1094 main = name + ".TestGenerator"
1095 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1096 args destinationDir
1097 }
1098 } else {
1099 task "generate_examplesAndroidP_${name}" () {}
1100 }
1101 }
1102 examplesDir.eachDir { dir ->
1103 def name = dir.getName();
1104 def exampleOutputDir = file("build/test/examplesAndroidP");
1105 def jarName = "${name}.jar"
1106 dependsOn "jar_examplesAndroidP_${name}"
1107 task "jar_examplesAndroidP_${name}"(type: Jar,
1108 dependsOn: ["compile_examplesAndroidP",
1109 "generate_examplesAndroidP_${name}"]) {
1110 archiveName = jarName
1111 destinationDir = exampleOutputDir
1112 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1113 include "**/" + name + "/**/*.class"
1114 // Do not include generator into the test runtime jar, it is not useful.
1115 // Otherwise, shrinking will need ASM jars.
1116 exclude "**/TestGenerator*"
1117 }
1118 }
1119}
1120
Mikaël Peltier61633d42017-10-13 16:51:06 +02001121task buildExampleJava9Jars {
1122 def examplesDir = file("src/test/examplesJava9")
1123 examplesDir.eachDir { dir ->
1124 def name = dir.getName();
1125 def exampleOutputDir = file("build/test/examplesJava9");
1126 def jarName = "${name}.jar"
1127 dependsOn "jar_examplesJava9_${name}"
1128 task "jar_examplesJava9_${name}"(type: Jar) {
1129 archiveName = jarName
1130 destinationDir = exampleOutputDir
1131 from "src/test/examplesJava9" // Java 1.9 classes
1132 include "**/" + name + "/**/*.class"
1133 }
1134 }
1135}
1136
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001137task buildExamplesKotlin {
1138 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1139 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1140 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1141 } else if (!OperatingSystem.current().isLinux()) {
1142 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1143 "on your platform. It is fully supported on Linux and partially supported on " +
1144 "Mac OS and Windows")
1145 return;
1146 }
1147 def examplesDir = file("src/test/examplesKotlin")
1148 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001149 def name = dir.getName();
1150 dependsOn "dex_example_kotlin_${name}"
1151 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1152 def dexPath = file("${exampleOutputDir}")
1153 task "dex_example_kotlin_${name}"(type: dx.Dx,
1154 dependsOn: "compile_example_kotlin_${name}") {
1155 doFirst {
1156 if (!dexPath.exists()) {
1157 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001158 }
1159 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001160 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1161 destination = dexPath
1162 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001163 }
1164 }
1165}
1166
Sebastien Hertzd3313772018-01-16 14:12:37 +01001167task buildKotlinR8TestResources {
1168 def examplesDir = file("src/test/kotlinR8TestResources")
1169 examplesDir.eachDir { dir ->
1170 def name = dir.getName()
1171 def taskName = "jar_kotlinR8TestResources_${name}"
1172 task "${taskName}"(type: kotlin.Kotlinc) {
1173 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.kt')
1174 destination = file("build/test/kotlinR8TestResources/${name}.jar")
1175 }
1176 dependsOn taskName
1177 }
1178}
1179
Mads Ager418d1ca2017-05-22 09:35:49 +02001180task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001181 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1182 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1183 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001184 } else if (!OperatingSystem.current().isLinux()) {
1185 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001186 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001187 return;
1188 }
1189 dependsOn buildDebugTestResourcesJars
1190 dependsOn buildExampleJars
1191 dependsOn buildExampleAndroidNJars
1192 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001193 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001194 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001195 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001196 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001197 def noDexTests = [
1198 "multidex",
1199 "multidex002",
1200 "multidex004",
1201 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001202 examplesDir.eachDir { dir ->
1203 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001204 if (!(name in noDexTests)) {
1205 dependsOn "dex_example_${name}"
1206 def exampleOutputDir = file("build/test/examples/" + name);
1207 def dexPath = file("${exampleOutputDir}")
1208 def debug = (name == "throwing")
1209 if (!dexPath.exists()) {
1210 dexPath.mkdirs()
1211 }
1212 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1213 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1214 destination = dexPath
1215 debug = debug
1216 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001217 }
1218 }
1219}
1220
1221task buildSmali {
1222 def smaliDir = file("src/test/smali")
1223 smaliDir.eachDirRecurse() { dir ->
1224 def name = dir.getName();
1225 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1226 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1227 smaliOutputDir.mkdirs()
1228 outputs.dir smaliOutputDir
1229 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1230 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1231 def javaFiles = fileTree(dir: dir, include: '*.java')
1232 def destDir = smaliOutputDir;
1233 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1234 def intermediateFileName = "${name}-intermediate.dex";
1235 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1236 if (javaFiles.empty) {
1237 if (!smaliFiles.empty) {
1238 dependsOn "${taskName}_smali"
1239 task "${taskName}_smali"(type: smali.Smali) {
1240 source = smaliFiles
1241 destination = destFile
1242 }
1243 }
1244 } else {
1245 dependsOn "${taskName}_dexmerger"
1246 task "${taskName}_smali"(type: smali.Smali) {
1247 source = smaliFiles
1248 destination = intermediateFile
1249 }
1250 task "${taskName}_java"(type: JavaCompile) {
1251 source = javaFiles
1252 destinationDir destDir
1253 classpath = sourceSets.main.compileClasspath
1254 sourceCompatibility = JavaVersion.VERSION_1_7
1255 targetCompatibility = JavaVersion.VERSION_1_7
1256 options.compilerArgs += ["-Xlint:-options"]
1257 }
1258 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1259 archiveName = "Test.jar"
1260 destinationDir = destDir
1261 from fileTree(dir: destDir, include: 'Test.class')
1262 }
1263 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1264 source = fileTree(dir: destDir, include: 'Test.jar')
1265 destination = destDir
1266 }
1267 task "${taskName}_dexmerger"(
1268 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1269 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1270 destination = destFile
1271 }
1272 }
1273 }
1274}
1275
1276tasks.withType(Test) {
1277 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1278 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1279 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1280 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1281 forkEvery = 0
1282 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1283 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001284 if (project.hasProperty('disable_assertions')) {
1285 enableAssertions = false
1286 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001287}
1288
1289task buildPreNJdwpTestsJar(type: Jar) {
1290 baseName = 'jdwp-tests-preN'
1291 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1292 // Exclude the classes containing java8
1293 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1294 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1295 includeEmptyDirs = false
1296}
1297
Ian Zerny74143162017-11-24 13:46:35 +01001298task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1299 def inFile = buildPreNJdwpTestsJar.archivePath
1300 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
1301 inputs.file inFile
1302 outputs.file outFile
1303 if (OperatingSystem.current().isWindows()) {
1304 executable file("tools/windows/dx/bin/dx.bat")
1305 } else if (OperatingSystem.current().isMacOsX()) {
1306 executable file("tools/mac/dx/bin/dx");
1307 } else {
1308 executable file("tools/linux/dx/bin/dx");
1309 }
1310 args "--dex"
1311 args "--output=${outFile}"
1312 args inFile
1313}
1314
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001315task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1316 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001317}
1318
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001319task AospJarTest(type: Exec) {
1320 dependsOn CompatDx, downloadDeps
1321 def script = "tools/test_aosp_jar.py"
1322 inputs.file script
1323 commandLine "python", script, "--no-build"
1324 workingDir = projectDir
1325}
1326
Mads Ager418d1ca2017-05-22 09:35:49 +02001327test {
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001328 dependsOn getJarsFromSupportLibs
Mads Ager418d1ca2017-05-22 09:35:49 +02001329 testLogging.exceptionFormat = 'full'
1330 if (project.hasProperty('print_test_stdout')) {
1331 testLogging.showStandardStreams = true
1332 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001333 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001334 println "Running with non default vm: " + project.property('dex_vm')
1335 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001336 if (project.property('dex_vm').startsWith('4.4.4') ||
1337 project.property('dex_vm').startsWith('5.1.1') ||
1338 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001339 // R8 and D8 compute the dex file version number based on the input.
1340 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1341 // Therefore we skip the jack generated art tests with those art versions.
1342 exclude "com/android/tools/r8/art/jack/**"
1343 }
1344 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001345
Mads Ager418d1ca2017-05-22 09:35:49 +02001346 if (project.hasProperty('one_line_per_test')) {
1347 beforeTest { desc ->
1348 println "Start executing test ${desc.name} [${desc.className}]"
1349 }
1350 afterTest { desc, result ->
1351 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1352 }
1353 }
1354 if (project.hasProperty('no_internal')) {
1355 exclude "com/android/tools/r8/internal/**"
1356 }
1357 if (project.hasProperty('only_internal')) {
1358 include "com/android/tools/r8/internal/**"
1359 }
1360 if (project.hasProperty('tool')) {
1361 if (project.property('tool') == 'r8') {
1362 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001363 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001364 } else {
1365 assert(project.property('tool') == 'd8')
1366 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001367 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001368 }
1369 }
1370 if (!project.hasProperty('all_tests')) {
1371 exclude "com/android/tools/r8/art/dx/**"
1372 exclude "com/android/tools/r8/art/jack/**"
1373 }
1374 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1375 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001376 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001377 }
1378 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001379 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001380 }
1381 if (project.hasProperty('jctf_compile_only')) {
1382 println "JCTF: compiling only"
1383 systemProperty 'jctf_compile_only', '1'
1384 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001385 if (project.hasProperty('test_dir')) {
1386 systemProperty 'test_dir', project.property('test_dir')
1387 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001388 if (project.hasProperty('aosp_jar')) {
1389 dependsOn AospJarTest
1390 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001391
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001392 if (OperatingSystem.current().isLinux()
1393 || OperatingSystem.current().isMacOsX()
1394 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001395 if (OperatingSystem.current().isMacOsX()) {
1396 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1397 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1398 "See tools/docker/README.md for details.")
1399 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001400 if (OperatingSystem.current().isWindows()) {
1401 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1402 "Art only runs on Linux and tests requiring Art will be skipped")
1403 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001404 dependsOn downloadDeps
1405 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001406 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001407 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001408 dependsOn buildSmali
1409 dependsOn jctfCommonJar
1410 dependsOn jctfTestsClasses
1411 dependsOn buildDebugInfoExamplesDex
1412 dependsOn buildPreNJdwpTestsJar
1413 } else {
1414 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001415 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001416 }
1417}
1418
1419// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1420//
1421// To build and upload a new set of the Art tests for use with R8 follow these steps:
1422//
1423// First of all an Android checkout is required. Currently it must be located
1424// in $HOME/android/master.
1425//
1426// TODO(ricow): simplify this
1427//
1428// Before: update the checked in art, see scripts/update-host-art.sh
1429//
1430// 1. Get an android checkout in $HOME/android/master and apply the patch from
1431// https://android-review.googlesource.com/#/c/294187/
1432//
1433// 2. run the following commands in the Android checkout directory:
1434//
1435// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001436// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1437// m desugar
1438// m -j30 test-art-host
1439// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1440//
1441// Without running the test.py command the classes.jar file used by desugar in
1442// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1443// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001444//
1445// 3. In the R8 project root directory, make sure we have a clean state before starting:
1446// tools/gradle.py downloadDeps
1447// tools/gradle.py clean
1448// rm -rf tests/art
1449//
1450// 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 +02001451// Make sure you have smali on your path, please use the build binary in the
1452// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1453// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1454// 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 +02001455// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1456// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001457//
Søren Gjesse34b77732017-07-07 13:56:21 +02001458// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001459//
1460// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1461// skippedTests with an explanation. Rerun from step 3.
1462//
1463// 5. Run the tests:
1464// tools/gradle.py clean
1465// tools/test.py
1466//
Søren Gjesse34b77732017-07-07 13:56:21 +02001467// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1468// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1469// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001470//
Søren Gjesse34b77732017-07-07 13:56:21 +02001471// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001472// cd tests
1473// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001474//
1475// 7. Update the manifest file describing the Android repo used:
1476// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001477
1478enum DexTool {
1479 JACK,
1480 DX
1481}
1482
1483def androidCheckoutDir = file("${System.env.HOME}/android/master")
1484def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1485def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1486
1487def artTestDir = file("${androidCheckoutDir}/art/test")
1488
1489if (project.hasProperty('android_source')) {
1490 task buildArtTests {
1491 outputs.upToDateWhen { false }
1492 def toBeTriaged = [
1493 "903-hello-tagging",
1494 "904-object-allocation",
1495 "905-object-free",
1496 "906-iterate-heap",
1497 "907-get-loaded-classes",
1498 "908-gc-start-finish",
1499 "954-invoke-polymorphic-verifier",
1500 "955-methodhandles-smali",
1501 "596-monitor-inflation",
1502 ]
1503 def skippedTests = toBeTriaged + [
1504 // This test produces no jar.
1505 "000-nop",
1506 // This does not build, as it tests the error when the application exceeds more
1507 // than 65536 methods
1508 "089-many-methods",
1509 // Requires some jack beta jar
1510 "956-methodhandles",
1511 ]
1512
1513 def skippedTestsDx = [
1514 // Tests with custom build scripts, where javac is not passed the options
1515 // -source 1.7 -target 1.7.
1516 "462-checker-inlining-across-dex-files",
1517 "556-invoke-super",
1518 "569-checker-pattern-replacement",
1519 // These tests use jack even when --build-with-javac-dx is specified.
1520 "004-JniTest",
1521 "048-reflect-v8",
1522 "146-bad-interface",
1523 "563-checker-invoke-super",
1524 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1525 "604-hot-static-interface",
1526 "957-methodhandle-transforms",
1527 "958-methodhandle-emulated-stackframe",
1528 "959-invoke-polymorphic-accessors",
1529 "961-default-iface-resolution-gen",
1530 "962-iface-static",
1531 "963-default-range-smali",
1532 "964-default-iface-init-gen",
1533 "965-default-verify",
1534 "966-default-conflict",
1535 "967-default-ame",
1536 "968-default-partial-compile-gen",
1537 "969-iface-super",
1538 "970-iface-super-resolution-gen",
1539 "971-iface-super",
1540 // These tests does not build with --build-with-javac-dx
1541 "004-NativeAllocations", // Javac error
1542 "031-class-attributes",
1543 "138-duplicate-classes-check",
1544 "157-void-class", // Javac error
1545 "580-checker-string-factory-intrinsics",
1546 "612-jit-dex-cache",
1547 "613-inlining-dex-cache",
1548 "900-hello-plugin", // --experimental agents
1549 "901-hello-ti-agent", // --experimental agents
1550 "902-hello-transformation", // --experimental agents
1551 "909-attach-agent", // --experimental agents
1552 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1553 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1554 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1555 "960-default-smali", // --experimental default-methods
1556 // These tests force the build to use jack
1557 "953-invoke-polymorphic-compiler",
1558 "958-methodhandle-stackframe",
1559 ]
1560
1561 def artTestBuildDir = file("${projectDir}/tests/art")
1562
1563 if (androidCheckoutDir.exists()) {
1564 dependsOn downloadDeps
1565 artTestBuildDir.mkdirs()
1566 // Ensure Jack server is running.
1567 "${androidCheckoutJackServer} start-server".execute()
1568 artTestDir.eachDir { dir ->
1569 def name = dir.getName();
1570 def markerFile = dir.toPath().resolve("info.txt").toFile();
1571 if (markerFile.exists() && !(name in skippedTests)) {
1572 if (!(name in skippedTestsDx)) {
1573 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1574 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001575 // After Android O, Jack is no longer alive
1576 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001577 }
1578 }
1579 }
1580 doFirst {
1581 if (!androidCheckoutDir.exists()) {
1582 throw new InvalidUserDataException(
1583 "This task requires an Android checkout in ${androidCheckoutDir}");
1584 } else if (!androidCheckoutJack.exists() ||
1585 !androidCheckoutJackServer.exists()) {
1586 throw new InvalidUserDataException(
1587 "This task requires that tools for host testing have been build in the " +
1588 "Android checkout in ${androidCheckoutDir}");
1589 }
1590 }
1591 doLast {
1592 copy {
1593 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1594 into file("${artTestBuildDir}/lib64")
1595 include 'lib*.so'
1596 }
1597 copy {
1598 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1599 into file("${artTestBuildDir}/lib64")
1600 include 'libart.so'
1601 include 'libbacktrace.so'
1602 include 'libbase.so'
1603 include 'libc++.so'
1604 include 'libcutils.so'
1605 include 'liblz4.so'
1606 include 'liblzma.so'
1607 include 'libnativebridge.so'
1608 include 'libnativeloader.so'
1609 include 'libsigchain.so'
1610 include 'libunwind.so'
1611 include 'libziparchive.so'
1612 }
1613 copy {
1614 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1615 into file("${artTestBuildDir}/lib")
1616 include 'lib*.so'
1617 }
1618 copy {
1619 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1620 into file("${artTestBuildDir}/lib")
1621 include 'libart.so'
1622 include 'libbacktrace.so'
1623 include 'libbase.so'
1624 include 'libc++.so'
1625 include 'libcutils.so'
1626 include 'liblz4.so'
1627 include 'liblzma.so'
1628 include 'libnativebridge.so'
1629 include 'libnativeloader.so'
1630 include 'libsigchain.so'
1631 include 'libunwind.so'
1632 include 'libziparchive.so'
1633 }
1634 }
1635 }
1636}
1637
1638def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1639 def artTestDir = file("${androidCheckoutDir}/art/test")
1640 def artRunTestScript = file("${artTestDir}/run-test")
1641 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001642 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001643 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1644
Søren Gjesse34b77732017-07-07 13:56:21 +02001645 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001646 def buildTask = "build_art_test_${dexToolName}_${name}"
1647 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1648 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1649 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1650
1651 def buildInputs = fileTree(dir: dir, include: '**/*')
1652 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1653 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1654 testDir.mkdirs()
1655 if (dexTool == DexTool.DX) {
1656 task "$buildTask"(type: Exec) {
1657 outputs.upToDateWhen { false }
1658 inputs.file buildInputs
1659 executable "${artRunTestScript}"
1660 args "--host"
1661 args "--build-only"
1662 args "--build-with-javac-dx"
1663 args "--output-path", "${testDir}"
1664 args "${name}"
1665 environment DX: "${dxExecutable.absolutePath}"
1666 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001667 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001668 outputs.file outputJar
1669 }
1670 } else {
1671 assert dexTool == DexTool.JACK
1672 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1673 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1674 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1675 task "$buildTask"(type: Exec) {
1676 outputs.upToDateWhen { false }
1677 inputs.file buildInputs
1678 executable "${artRunTestScript}"
1679 args "--host"
1680 args "--build-only"
1681 args "--output-path", "${testDir}"
1682 args "${name}"
1683 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1684 environment JACK_CLASSPATH: jackClasspath
1685 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1686 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1687 outputs.file outputJar
1688 }
1689 }
1690 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1691 outputs.upToDateWhen { false }
1692 executable "/bin/bash"
1693 args "-c"
1694 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1695 " ${testDir}/classes-ex ${testDir}/check"
1696 }
1697
1698 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001699 // Directory that contains smali files is either smali, or smali/art
1700 def smali_dir = file("${dir}/smali/art")
1701 if (smali_dir.exists()) {
1702 workingDir "${testDir}/smali/art"
1703 } else {
1704 workingDir "${testDir}/smali"
1705 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001706 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001707 // This is the command line options for smali prior to 2.2.1, where smali got a new
1708 // command line interface.
1709 args "-c", "smali a *.smali"
1710 // This is the command line options for smali 2.2.1 and later.
1711 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001712 }
1713
1714 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1715 def smali_dir = file("${dir}/smali")
1716 outputs.upToDateWhen { false }
1717 if (smali_dir.exists() && dexTool == DexTool.DX) {
1718 dependsOn smaliToDexTask
1719 }
1720 from("${artTestDir}/${name}") {
1721 include 'check'
1722 }
1723 into testDir
1724 }
1725
1726 return copyCheckTask
1727}
1728
1729task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001730 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001731 classpath = sourceSets.main.compileClasspath
1732 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001733 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001734 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001735 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001736 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001737 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001738 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001739 include '**/com/android/tools/r8/CompilationMode.java'
1740 include '**/com/android/tools/r8/D8.java'
1741 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001742 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1743 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001744 include '**/com/android/tools/r8/Diagnostic.java'
1745 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001746 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1747 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001748 include '**/com/android/tools/r8/ProgramConsumer.java'
1749 include '**/com/android/tools/r8/ProgramResource.java'
1750 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001751 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001752 include '**/com/android/tools/r8/ResourceException.java'
1753 include '**/com/android/tools/r8/StringConsumer.java'
1754 include '**/com/android/tools/r8/StringResource.java'
1755 include '**/com/android/tools/r8/Version.java'
1756 include '**/com/android/tools/r8/origin/*.java'
1757}
1758
1759task javadocR8(type: Javadoc) {
1760 title "R8 API"
1761 classpath = sourceSets.main.compileClasspath
1762 source = sourceSets.main.allJava
1763 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
1764 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
1765 include '**/com/android/tools/r8/BaseCommand.java'
1766 include '**/com/android/tools/r8/BaseCompilerCommand.java'
1767 include '**/com/android/tools/r8/ClassFileConsumer.java'
1768 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
1769 include '**/com/android/tools/r8/CompilationFailedException.java'
1770 include '**/com/android/tools/r8/CompilationMode.java'
1771 include '**/com/android/tools/r8/R8.java'
1772 include '**/com/android/tools/r8/R8Command.java'
1773 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1774 include '**/com/android/tools/r8/Diagnostic.java'
1775 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001776 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1777 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001778 include '**/com/android/tools/r8/ProgramConsumer.java'
1779 include '**/com/android/tools/r8/ProgramResource.java'
1780 include '**/com/android/tools/r8/ProgramResourceProvider.java'
1781 include '**/com/android/tools/r8/Resource.java'
1782 include '**/com/android/tools/r8/ResourceException.java'
1783 include '**/com/android/tools/r8/StringConsumer.java'
1784 include '**/com/android/tools/r8/StringResource.java'
1785 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001786 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001787}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001788
1789task copyMavenDeps(type: Copy) {
1790 from configurations.compile into "$buildDir/deps"
1791 from configurations.testCompile into "$buildDir/deps"
1792}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001793
1794// This task allows to build class files from Java 9 source in order to use them as inputs of
1795// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1796// to the D8 repository because there is no way to generate them on all computers due to the need of
1797// Java 9.
1798// Use the following command to rebuild class files of tests:
1799// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1800task buildJava9Tests {
1801 def javacOutputFolder = getTemporaryDir();
1802 def examplesDir = file("src/test/examplesJava9")
1803
1804 task "compile_Java9examples"(type: JavaCompile) {
1805 doFirst {
1806 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1807 throw new GradleException("Set java9Home property.")
1808 }
1809 }
1810
1811 source = fileTree(dir: examplesDir, include: '**/*.java')
1812 destinationDir = javacOutputFolder
1813 classpath = sourceSets.main.compileClasspath
1814 options.compilerArgs += ["-Xlint:-options"]
1815 sourceCompatibility = JavaVersion.VERSION_1_9
1816 targetCompatibility = JavaVersion.VERSION_1_9
1817 options.fork = true
1818
1819 if (project.hasProperty('java9Home')) {
1820 options.forkOptions.javaHome = file(getProperty('java9Home'))
1821 }
1822
1823 doLast {
1824 def classfileFrom = copySpec {
1825 from javacOutputFolder
1826 include "**/*.class"
1827 }
1828 copy {
1829 into examplesDir
1830 with classfileFrom
1831 }
1832 delete javacOutputFolder
1833 }
1834 }
1835
1836 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001837}