blob: 993e89402aeb1ac28d96497a5bef5abf9c309559 [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.
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02004import org.gradle.internal.os.OperatingSystem
Stephan Herhut417a72a2017-07-18 10:38:30 +02005import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +02006
7apply plugin: 'java'
8apply plugin: 'idea'
Stephan Herhut417a72a2017-07-18 10:38:30 +02009apply plugin: 'com.google.protobuf'
mikaelpeltier80939312017-08-17 15:00:09 +020010apply plugin: 'com.github.johnrengelman.shadow'
Yohann Roussel7f47c032017-09-14 12:19:06 +020011apply plugin: 'com.cookpad.android.licensetools'
Mads Ager418d1ca2017-05-22 09:35:49 +020012
13apply from: 'copyAdditionalJctfCommonFiles.gradle'
14
Sebastien Hertze2687b62017-07-25 11:16:04 +020015
16if (project.hasProperty('with_code_coverage')) {
17 apply plugin: 'jacoco'
18}
19
Mads Ager418d1ca2017-05-22 09:35:49 +020020repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020021 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020022 mavenCentral()
23}
24
Stephan Herhut417a72a2017-07-18 10:38:30 +020025buildscript {
26 repositories {
27 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020028 jcenter()
Stephan Herhut417a72a2017-07-18 10:38:30 +020029 }
30 dependencies {
31 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
mikaelpeltier80939312017-08-17 15:00:09 +020032 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020033 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +020034 }
35}
36
Mads Ager418d1ca2017-05-22 09:35:49 +020037// Custom source set for example tests and generated tests.
38sourceSets {
39 test {
40 java {
41 srcDirs = [
42 'src/test/java',
43 'build/generated/test/java',
44 ]
45 }
46 }
47 debugTestResources {
48 java {
49 srcDirs = ['src/test/debugTestResources']
50 }
51 output.resourcesDir = 'build/classes/debugTestResources'
52 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020053 debugTestResourcesJava8 {
54 java {
55 srcDirs = ['src/test/debugTestResourcesJava8']
56 }
57 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
58 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +020059 debugTestResourcesKotlin {
60 java {
61 srcDirs = ['src/test/debugTestResourcesKotlin']
62 }
63 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
64 }
Mads Ager418d1ca2017-05-22 09:35:49 +020065 examples {
66 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +020067 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
68 }
69 proto {
70 srcDirs = [
71 'src/test/examples',
72 ]
Mads Ager418d1ca2017-05-22 09:35:49 +020073 }
74 output.resourcesDir = 'build/classes/examples'
75 }
76 examplesAndroidN {
77 java {
78 srcDirs = ['src/test/examplesAndroidN']
79 }
80 output.resourcesDir = 'build/classes/examplesAndroidN'
81 }
82 examplesAndroidO {
83 java {
84 srcDirs = ['src/test/examplesAndroidO']
85 }
86 output.resourcesDir = 'build/classes/examplesAndroidO'
87 }
88 jctfCommon {
89 java {
90 srcDirs = [
91 'third_party/jctf/Harness/src',
92 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
93 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
94 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
95 'third_party/jctf/LibTests/src/org',
96 'build/additionalJctfCommonFiles'
97 ]
98 }
99 resources {
100 srcDirs = ['third_party/jctf/LibTests/resources']
101 }
102 }
103 jctfTests {
104 java {
105 srcDirs = [
106 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
107 // 'third_party/jctf/VMTests/src',
108 ]
109 }
110 }
111}
112
Yohann Roussel126f6872017-08-03 16:25:32 +0200113configurations {
114 supportLibs
115}
116
Mads Ager418d1ca2017-05-22 09:35:49 +0200117dependencies {
118 compile 'net.sf.jopt-simple:jopt-simple:4.6'
Mads Agercd06c802017-08-22 13:44:34 +0200119 compile 'com.googlecode.json-simple:json-simple:1.1'
Mads Ager0aa48052017-09-15 12:39:15 +0200120 // Include all of guava when compiling the code, but exclude annotations that we don't
121 // need from the packaging.
122 compileOnly('com.google.guava:guava:23.0')
123 compile('com.google.guava:guava:23.0', {
124 exclude group: 'com.google.errorprone'
125 exclude group: 'com.google.code.findbugs'
126 exclude group: 'com.google.j2objc'
127 exclude group: 'org.codehaus.mojo'
128 })
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200129 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200130 compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
131 compile group: 'org.ow2.asm', name: 'asm', version: '5.1'
132 compile group: 'org.ow2.asm', name: 'asm-commons', version: '5.1'
133 compile group: 'org.ow2.asm', name: 'asm-tree', version: '5.1'
134 compile group: 'org.ow2.asm', name: 'asm-util', version: '5.1'
135 testCompile sourceSets.examples.output
136 testCompile 'junit:junit:4.12'
137 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
138 testCompile files('third_party/jasmin/jasmin-2.4.jar')
139 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
140 jctfCommonCompile 'junit:junit:4.12'
141 jctfTestsCompile 'junit:junit:4.12'
142 jctfTestsCompile sourceSets.jctfCommon.output
143 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '5.1'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200144 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
145 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200146 supportLibs 'com.android.support:support-v4:25.4.0'
147 supportLibs 'junit:junit:4.12'
148 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200149 debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200150}
151
Yohann Roussel7f47c032017-09-14 12:19:06 +0200152licenseTools {
153 licensesYaml = file('LIBRARY-LICENSE')
154}
155
Stephan Herhut417a72a2017-07-18 10:38:30 +0200156protobuf {
157 protoc {
158 // Download from repositories
159 artifact = 'com.google.protobuf:protoc:3.0.0'
160 }
161 plugins {
162 javalite {
163 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
164 }
165 }
166 generateProtoTasks {
167 all().each { task ->
168 task.builtins {
169 // Disable the java code generator, as we want javalite only.
170 remove java
171 }
172 task.plugins {
173 javalite {}
174 }
175 }
176 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200177}
178
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200179def osString = OperatingSystem.current().isLinux() ? "linux" :
180 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200181
182def cloudDependencies = [
183 "tests" : [
mikaelpeltier962da332017-08-18 11:40:55 +0200184 "2017-07-27/art.tar.gz",
Søren Gjesse34b77732017-07-07 13:56:21 +0200185 "2016-12-19/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200186 ],
187 "third_party": [
188 "android_jar/lib-v14.tar.gz",
189 "android_jar/lib-v19.tar.gz",
Søren Gjesseab220772017-06-23 13:05:53 +0200190 "android_jar/lib-v21.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200191 "android_jar/lib-v24.tar.gz",
192 "android_jar/lib-v25.tar.gz",
193 "android_jar/lib-v26.tar.gz",
194 "proguard/proguard5.2.1.tar.gz",
195 "gradle/gradle.tar.gz",
196 "jdwp-tests.tar.gz",
197 "jasmin.tar.gz",
198 "jctf.tar.gz",
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200199 "kotlin.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200200 "android_cts_baseline.tar.gz",
201 ],
202 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
203 // container on other platforms where supported.
204 "tools" : [
205 "linux/art.tar.gz",
206 "linux/art-5.1.1.tar.gz",
207 "linux/art-6.0.1.tar.gz",
208 "linux/art-7.0.0.tar.gz",
209 "linux/dalvik.tar.gz",
210 "${osString}/dx.tar.gz",
211 ]
212]
213
214cloudDependencies.each { entry ->
215 entry.value.each { entryFile ->
216 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
217 def gzFile = "${entry.key}/${entryFile}"
218 def sha1File = "${gzFile}.sha1"
219 inputs.file sha1File
220 outputs.file gzFile
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200221 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
222 if (OperatingSystem.current().isWindows()) {
223 executable "download_from_google_storage.bat"
224 args dlFromStorageArgs
225 } else {
226 executable "bash"
227 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
228 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200229 }
230 }
231}
232
233def x20Dependencies = [
234 "third_party": [
Søren Gjesse5ecb04a2017-06-13 09:44:32 +0200235 "gmail/gmail_android_170604.16.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200236 "gmscore/v4.tar.gz",
237 "gmscore/v5.tar.gz",
238 "gmscore/v6.tar.gz",
239 "gmscore/v7.tar.gz",
240 "gmscore/v8.tar.gz",
241 "gmscore/gmscore_v9.tar.gz",
242 "gmscore/gmscore_v10.tar.gz",
Stephan Herhut4e743302017-06-09 13:09:03 +0200243 "gmscore/latest.tar.gz",
Mads Agerae646402017-06-07 13:32:43 +0200244 "photos/2017-06-06.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200245 "youtube/youtube.android_12.10.tar.gz",
Søren Gjessefeac2ef2017-05-22 17:09:29 +0200246 "youtube/youtube.android_12.17.tar.gz",
Søren Gjesse9be84982017-06-09 14:21:03 +0200247 "youtube/youtube.android_12.22.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200248 "proguardsettings.tar.gz",
Tamas Kenez5febf242017-06-20 16:00:44 +0200249 "proguard/proguard_internal_159423826.tar.gz",
Tamas Kenez67419712017-06-26 11:11:45 +0200250 "framework.tar.gz",
Tamas Kenez391fca82017-06-29 18:16:01 +0200251 "goyt.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200252 ],
253]
254
255x20Dependencies.each { entry ->
256 entry.value.each { entryFile ->
257 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
258 def gzFile = "${entry.key}/${entryFile}"
259 def sha1File = "${gzFile}.sha1"
260 inputs.file sha1File
261 outputs.file gzFile
262 executable "bash"
263 args "-c", "tools/download_from_x20.py ${sha1File}"
264 }
265 }
266}
267
Rico Wind897bb712017-05-23 10:44:29 +0200268task downloadProguard {
269 cloudDependencies.each { entry ->
270 entry.value.each { entryFile ->
271 if (entryFile.contains("proguard")) {
272 dependsOn "download_deps_${entry.key}/${entryFile}"
273 }
274 }
275 }
276}
277
Tamas Kenez427205b2017-06-29 15:57:09 +0200278task downloadDx {
279 cloudDependencies.each { entry ->
280 entry.value.each { entryFile ->
281 if (entryFile.contains("dx.tar")) {
282 dependsOn "download_deps_${entry.key}/${entryFile}"
283 }
284 }
285 }
286}
287
Tamas Kenez0e10c562017-06-08 10:00:34 +0200288task downloadAndroidCts {
289 cloudDependencies.each { entry ->
290 entry.value.each { entryFile ->
291 if (entryFile.contains("android_cts_baseline")) {
292 dependsOn "download_deps_${entry.key}/${entryFile}"
293 }
294 }
295 }
296}
297
Mads Ager418d1ca2017-05-22 09:35:49 +0200298task downloadDeps {
299 cloudDependencies.each { entry ->
300 entry.value.each { entryFile ->
301 dependsOn "download_deps_${entry.key}/${entryFile}"
302 }
303 }
304 if (!project.hasProperty('no_internal')) {
305 x20Dependencies.each { entry ->
306 entry.value.each { entryFile ->
307 dependsOn "download_deps_${entry.key}/${entryFile}"
308 }
309 }
310 }
311}
312
313allprojects {
314 sourceCompatibility = JavaVersion.VERSION_1_8
315 targetCompatibility = JavaVersion.VERSION_1_8
316}
317
318tasks.withType(JavaCompile) {
319 options.compilerArgs << '-Xlint:unchecked'
320}
321
322compileJctfCommonJava {
323 dependsOn 'copyAdditionalJctfCommonFiles'
324 options.compilerArgs = ['-Xlint:none']
325}
326
327compileJctfTestsJava {
328 dependsOn 'jctfCommonClasses'
329 options.compilerArgs = ['-Xlint:none']
330}
331
Yohann Roussel7f47c032017-09-14 12:19:06 +0200332task consolidatedLicense {
333 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
334 // corresponding to the effective list of embedded libraries.
335 dependsOn 'checkLicenses'
336 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
337 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
338 outputs.files license
339 doLast {
340 license.getParentFile().mkdirs()
341 license.createNewFile()
342 license.text = "This file lists all licenses for code distributed.\n"
343 license.text += "All non-library code has the following 3-Clause BSD license.\n"
344 license.text += "\n"
345 license.text += "\n"
346 license.text += file('LICENSE').text
347 license.text += "\n"
348 license.text += "\n"
349 license.text += "Summary of distributed libraries:\n"
350 license.text += "\n"
351 license.text += file('LIBRARY-LICENSE').text
352 license.text += "\n"
353 license.text += "\n"
354 license.text += "Licenses details:\n"
355 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
356 license.text += "\n"
357 license.text += "\n"
358 license.text += file.text
359 }
360 }
361}
362
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200363task R8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200364 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200365 from consolidatedLicense.outputs.files
366 exclude { path ->
367 path.getRelativePath().getPathString().startsWith("META-INF")
368 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200369 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200370 classifier = null
371 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200372 manifest {
373 attributes 'Main-Class': 'com.android.tools.r8.R8'
374 }
375 // In order to build without dependencies, pass the exclude_deps property using:
376 // gradle -Pexclude_deps R8
377 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200378 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
379 // to avoid rewriting unrelated strings.
380 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
381 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200382 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200383 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
384 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200385 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200386 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200387 // Also include dependencies
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200388 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200389 }
390}
391
mikaelpeltier80939312017-08-17 15:00:09 +0200392task D8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200393 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200394 from consolidatedLicense.outputs.files
395 exclude { path ->
396 path.getRelativePath().getPathString().startsWith("META-INF")
397 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200398 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200399 classifier = null
400 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200401 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200402 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200403 }
404 // In order to build without dependencies, pass the exclude_deps property using:
405 // gradle -Pexclude_deps D8
406 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200407 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
408 // to avoid rewriting unrelated strings.
409 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
410 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
mikaelpeltier80939312017-08-17 15:00:09 +0200411 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200412 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
413 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200414 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
mikaelpeltier80939312017-08-17 15:00:09 +0200415 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200416 // Also include dependencies
mikaelpeltier80939312017-08-17 15:00:09 +0200417 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200418 }
419}
420
421task CompatDx(type: Jar) {
422 from sourceSets.main.output
423 baseName 'compatdx'
424 manifest {
425 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
426 }
427 // In order to build without dependencies, pass the exclude_deps property using:
428 // gradle -Pexclude_deps CompatDx
429 if (!project.hasProperty('exclude_deps')) {
430 // Also include dependencies
431 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
432 }
433}
434
Søren Gjesse1d21da72017-09-01 12:05:38 +0200435task CompatProguard(type: Jar) {
436 from sourceSets.main.output
437 baseName 'compatproguard'
438 manifest {
439 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
440 }
441 // In order to build without dependencies, pass the exclude_deps property using:
442 // gradle -Pexclude_deps CompatProguard
443 if (!project.hasProperty('exclude_deps')) {
444 // Also include dependencies
445 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
446 }
447}
448
Tamas Kenez971eec62017-05-24 11:08:40 +0200449task D8Logger(type: Jar) {
450 from sourceSets.main.output
451 baseName 'd8logger'
452 manifest {
453 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
454 }
455 // In order to build without dependencies, pass the exclude_deps property using:
456 // gradle -Pexclude_deps D8Logger
457 if (!project.hasProperty('exclude_deps')) {
458 // Also include dependencies
459 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
460 }
461}
462
Mads Ager418d1ca2017-05-22 09:35:49 +0200463task disasm(type: Jar) {
464 from sourceSets.main.output
465 baseName 'disasm'
466 manifest {
467 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
468 }
469 // In order to build without dependencies, pass the exclude_deps property using:
470 // gradle -Pexclude_deps D8
471 if (!project.hasProperty('exclude_deps')) {
472 // Also include dependencies
473 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
474 }
475}
476
477task bisect(type: Jar) {
478 from sourceSets.main.output
479 baseName 'bisect'
480 manifest {
481 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
482 }
483 // In order to build without dependencies, pass the exclude_deps property using:
484 // gradle -Pexclude_deps R8
485 if (!project.hasProperty('exclude_deps')) {
486 // Also include dependencies
487 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
488 }
489}
490
Lars Bak90c18042017-06-26 14:21:08 +0200491task DexSegments(type: Jar) {
492 from sourceSets.main.output
493 baseName 'dexsegments'
494 manifest {
495 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
496 }
497 // In order to build without dependencies, pass the exclude_deps property using:
498 // gradle -Pexclude_deps DexSegments
499 if (!project.hasProperty('exclude_deps')) {
500 // Also include dependencies
501 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
502 }
503}
504
Søren Gjessec4e5e932017-09-04 17:01:23 +0200505task maindex(type: Jar) {
506 from sourceSets.main.output
507 baseName 'maindex'
508 manifest {
509 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
510 }
511 // In order to build without dependencies, pass the exclude_deps property using:
512 // gradle -Pexclude_deps maindex
513 if (!project.hasProperty('exclude_deps')) {
514 // Also include dependencies
515 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
516 }
517}
518
Lars Bak44cef522017-08-10 16:02:39 +0200519task ExtractMarker(type: Jar) {
520 from sourceSets.main.output
521 baseName 'extractmarker'
522 manifest {
523 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
524 }
525 // In order to build without dependencies, pass the exclude_deps property using:
526 // gradle -Pexclude_deps ExtractMarker
527 if (!project.hasProperty('exclude_deps')) {
528 // Also include dependencies
529 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
530 }
531}
532
Mads Ager418d1ca2017-05-22 09:35:49 +0200533task sourceJar(type: Jar, dependsOn: classes) {
534 classifier = 'src'
535 from sourceSets.main.allSource
536}
537
538task jctfCommonJar(type: Jar) {
539 from sourceSets.jctfCommon.output
540 baseName 'jctfCommon'
541}
542
543artifacts {
544 archives sourceJar
545}
546
547task createArtTests(type: Exec) {
548 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200549 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltier962da332017-08-18 11:40:55 +0200550 inputs.file "tests/2017-07-27/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200551 inputs.file createArtTestsScript
552 outputs.dir outputDir
553 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200554 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200555 workingDir = projectDir
556}
557
558task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200559 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200560 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200561 inputs.file script
562 outputs.dir outputDir
563 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200564 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200565 workingDir = projectDir
566}
567
568compileTestJava {
569 dependsOn createArtTests
570 dependsOn createJctfTests
571}
572
573task buildDebugInfoExamplesDex {
574 def examplesDir = file("src/test/java")
575 def hostJar = "debuginfo_examples.jar"
576 def hostDexJar = "debuginfo_examples_dex.jar"
577 task "compile_debuginfo_examples"(type: JavaCompile) {
578 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
579 destinationDir = file("build/test/debuginfo_examples/classes")
580 classpath = sourceSets.main.compileClasspath
581 sourceCompatibility = JavaVersion.VERSION_1_7
582 targetCompatibility = JavaVersion.VERSION_1_7
583 options.compilerArgs += ["-Xlint:-options"]
584 }
585 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
586 archiveName = hostJar
587 destinationDir = file("build/test/")
588 from "build/test/debuginfo_examples/classes"
589 include "**/*.class"
590 }
591 task "dex_debuginfo_examples"(type: Exec,
592 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200593 if (OperatingSystem.current().isWindows()) {
594 executable file("tools/windows/dx/bin/dx.bat")
595 } else {
596 executable file("tools/linux/dx/bin/dx");
597 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200598 args "--dex"
599 args "--output=build/test/${hostDexJar}"
600 args "build/test/${hostJar}"
601 inputs.file file("build/test/${hostJar}")
602 outputs.file file("build/test/${hostDexJar}")
603 }
604 dependsOn dex_debuginfo_examples
605}
606
607task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200608 def resourcesDir = file("src/test/debugTestResources")
609 def hostJar = "debug_test_resources.jar"
610 task "compile_debugTestResources"(type: JavaCompile) {
611 source = fileTree(dir: resourcesDir, include: '**/*.java')
612 destinationDir = file("build/test/debugTestResources/classes")
613 classpath = sourceSets.main.compileClasspath
614 sourceCompatibility = JavaVersion.VERSION_1_7
615 targetCompatibility = JavaVersion.VERSION_1_7
616 options.compilerArgs += ["-g", "-Xlint:-options"]
617 }
618 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
619 archiveName = hostJar
620 destinationDir = file("build/test/")
621 from "build/test/debugTestResources/classes"
622 include "**/*.class"
623 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200624 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
625 def java8HostJar = "debug_test_resources_java8.jar"
626 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
627 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
628 destinationDir = file("build/test/debugTestResourcesJava8/classes")
629 classpath = sourceSets.main.compileClasspath
630 sourceCompatibility = JavaVersion.VERSION_1_8
631 targetCompatibility = JavaVersion.VERSION_1_8
632 options.compilerArgs += ["-g", "-Xlint:-options"]
633 }
634 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
635 archiveName = java8HostJar
636 destinationDir = file("build/test/")
637 from "build/test/debugTestResourcesJava8/classes"
638 include "**/*.class"
639 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200640 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
641 def kotlinHostJar = "debug_test_resources_kotlin.jar"
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200642 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
643 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
644 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200645 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200646 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200647 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200648 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200649 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200650}
651
Lars Bakc91e87e2017-08-18 08:53:10 +0200652// Proto lite generated code yields warnings when compiling with javac.
653// We change the options passed to javac to ignore it.
654compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
655
Mads Ager418d1ca2017-05-22 09:35:49 +0200656task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200657 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200658 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200659 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200660 def proguardScript
661 if (OperatingSystem.current().isWindows()) {
662 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
663 } else {
664 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
665 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200666 task extractExamplesRuntime(type: Sync) {
667 dependsOn configurations.examplesRuntime
668 from configurations.examplesRuntime.collect { zipTree(it) }
669 include "**/*.class"
670 includeEmptyDirs false
671 into "$buildDir/runtime/examples/"
672 }
673
674 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
675 source examplesDir, protoSourceDir
676 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200677 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200678 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200679 sourceCompatibility = JavaVersion.VERSION_1_7
680 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200681 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
682 }
683 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
684 source examplesDir, protoSourceDir
685 include "**/*.java"
686 destinationDir = file("build/test/examples/classes_debuginfo_all")
687 classpath = sourceSets.examples.compileClasspath
688 sourceCompatibility = JavaVersion.VERSION_1_7
689 targetCompatibility = JavaVersion.VERSION_1_7
690 options.compilerArgs = ["-g", "-Xlint:none"]
691 }
692 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
693 source examplesDir, protoSourceDir
694 include "**/*.java"
695 destinationDir = file("build/test/examples/classes_debuginfo_none")
696 classpath = sourceSets.examples.compileClasspath
697 sourceCompatibility = JavaVersion.VERSION_1_7
698 targetCompatibility = JavaVersion.VERSION_1_7
699 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200700 }
701 examplesDir.eachDir { dir ->
702 def name = dir.getName();
703 def exampleOutputDir = file("build/test/examples");
704 def jarName = "${name}.jar"
705 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200706 dependsOn "jar_example_${name}_debuginfo_all"
707 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200708 dependsOn "extractExamplesRuntime"
709 def runtimeDependencies = copySpec { }
710 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
711 // If we have any proto use, we have to include those classes and the runtime.
712 runtimeDependencies = copySpec {
713 from "$buildDir/runtime/examples/"
714 include "com/google/protobuf/**/*.class"
715 }
716 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200717 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
718 def proguardConfigPath = "${dir}/proguard.cfg"
719 if (new File(proguardConfigPath).exists()) {
720 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
721 archiveName = "${name}_pre_proguard.jar"
722 destinationDir = exampleOutputDir
723 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200724 include name + "/**/*.class"
725 with runtimeDependencies
726 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200727 }
728 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
729 def proguardJarPath = "${exampleOutputDir}/${jarName}"
730 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
731 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
732 inputs.files tasks.getByPath("pre_proguard_example_${name}")
733 inputs.file proguardConfigPath
734 // Enable these to get stdout and stderr redirected to files...
735 // standardOutput = new FileOutputStream('proguard.stdout')
736 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200737 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200738 " -outjars ${proguardJarPath}" +
739 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200740 " -printmapping ${proguardMapPath}"
741 if (OperatingSystem.current().isWindows()) {
742 executable "${proguardScript}"
743 args "${proguardArguments}"
744 } else {
745 executable "bash"
746 args "-c", "${proguardScript} '${proguardArguments}'"
747 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200748 outputs.file proguardJarPath
749 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200750 // TODO: Consider performing distinct proguard compilations.
751 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
752 from "${exampleOutputDir}/${name}.jar"
753 into "${exampleOutputDir}/${name}_debuginfo_all.jar"
754 }
755 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
756 from "${exampleOutputDir}/${name}.jar"
757 into "${exampleOutputDir}/${name}_debuginfo_none.jar"
758 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200759 } else {
760 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200761 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200762 destinationDir = exampleOutputDir
763 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200764 include name + "/**/*.class"
765 with runtimeDependencies
766 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200767 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200768 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
769 archiveName = "${name}_debuginfo_all.jar"
770 destinationDir = exampleOutputDir
771 from "build/test/examples/classes_debuginfo_all"
772 include name + "/**/*.class"
773 with runtimeDependencies
774 includeEmptyDirs false
775 }
776 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
777 archiveName = "${name}_debuginfo_none.jar"
778 destinationDir = exampleOutputDir
779 from "build/test/examples/classes_debuginfo_none"
780 include name + "/**/*.class"
781 with runtimeDependencies
782 includeEmptyDirs false
783 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200784 }
785 }
786}
787
788task buildExampleAndroidNJars {
789 dependsOn downloadDeps
790 def examplesDir = file("src/test/examplesAndroidN")
791 task "compile_examplesAndroidN"(type: JavaCompile) {
792 source = fileTree(dir: examplesDir, include: '**/*.java')
793 destinationDir = file("build/test/examplesAndroidN/classes")
794 classpath = sourceSets.main.compileClasspath
795 sourceCompatibility = JavaVersion.VERSION_1_8
796 targetCompatibility = JavaVersion.VERSION_1_8
797 options.compilerArgs += ["-Xlint:-options"]
798 }
799 examplesDir.eachDir { dir ->
800 def name = dir.getName();
801 def exampleOutputDir = file("build/test/examplesAndroidN");
802 def jarName = "${name}.jar"
803 dependsOn "jar_examplesAndroidN_${name}"
804 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
805 archiveName = jarName
806 destinationDir = exampleOutputDir
807 from "build/test/examplesAndroidN/classes"
808 include "**/" + name + "/**/*.class"
809 }
810 }
811}
812
813
814task buildExampleAndroidOJars {
815 dependsOn downloadDeps
816 def examplesDir = file("src/test/examplesAndroidO")
817 // NOTE: we want to enable a scenario when test needs to reference some
818 // classes generated by legacy (1.6) Java compiler to test some specific
819 // behaviour. To do so we compile all the java files located in sub-directory
820 // called 'legacy' with Java 1.6, then compile the rest of the files with
821 // Java 1.8 and a reference to previously generated 1.6 classes.
822
823 // Compiling all classes in dirs 'legacy' with old Java version.
824 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
825 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
826 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
827 classpath = sourceSets.main.compileClasspath
828 sourceCompatibility = JavaVersion.VERSION_1_6
829 targetCompatibility = JavaVersion.VERSION_1_6
830 options.compilerArgs += ["-Xlint:-options", "-parameters"]
831 }
832 // Compiling the rest of the files as Java 1.8 code.
833 task "compile_examplesAndroidO"(type: JavaCompile) {
834 dependsOn "compile_examplesAndroidO_Legacy"
835 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
836 destinationDir = file("build/test/examplesAndroidO/classes")
837 classpath = sourceSets.main.compileClasspath
838 classpath += files("build/test/examplesAndroidOLegacy/classes")
839 sourceCompatibility = JavaVersion.VERSION_1_8
840 targetCompatibility = JavaVersion.VERSION_1_8
841 options.compilerArgs += ["-Xlint:-options", "-parameters"]
842 }
843 examplesDir.eachDir { dir ->
844 def name = dir.getName();
845 def destinationDir = file("build/test/examplesAndroidO/classes");
846 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
847 task "generate_examplesAndroidO_${name}"(type: JavaExec,
848 dependsOn: "compile_examplesAndroidO") {
849 main = name + ".TestGenerator"
850 classpath = files(destinationDir, sourceSets.main.compileClasspath)
851 args destinationDir
852 }
853 } else {
854 task "generate_examplesAndroidO_${name}" () {}
855 }
856 }
857 examplesDir.eachDir { dir ->
858 def name = dir.getName();
859 def exampleOutputDir = file("build/test/examplesAndroidO");
860 def jarName = "${name}.jar"
861 dependsOn "jar_examplesAndroidO_${name}"
862 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
863 "generate_examplesAndroidO_${name}"]) {
864 archiveName = jarName
865 destinationDir = exampleOutputDir
866 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
867 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
868 include "**/" + name + "/**/*.class"
869 // Do not include generator into the test runtime jar, it is not useful.
870 // Otherwise, shrinking will need ASM jars.
871 exclude "**/TestGenerator*"
872 }
873 }
874}
875
876task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200877 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
878 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
879 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +0200880 } else if (!OperatingSystem.current().isLinux()) {
881 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200882 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +0200883 return;
884 }
885 dependsOn buildDebugTestResourcesJars
886 dependsOn buildExampleJars
887 dependsOn buildExampleAndroidNJars
888 dependsOn buildExampleAndroidOJars
889 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +0200890 def noDexTests = [
891 "multidex",
892 "multidex002",
893 "multidex004",
894 ]
Mads Ager418d1ca2017-05-22 09:35:49 +0200895 examplesDir.eachDir { dir ->
896 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +0200897 if (!(name in noDexTests)) {
898 dependsOn "dex_example_${name}"
899 def exampleOutputDir = file("build/test/examples/" + name);
900 def dexPath = file("${exampleOutputDir}")
901 def debug = (name == "throwing")
902 if (!dexPath.exists()) {
903 dexPath.mkdirs()
904 }
905 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
906 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
907 destination = dexPath
908 debug = debug
909 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200910 }
911 }
912}
913
914task buildSmali {
915 def smaliDir = file("src/test/smali")
916 smaliDir.eachDirRecurse() { dir ->
917 def name = dir.getName();
918 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
919 def smaliOutputDir = file("build/test/smali/" + relativeDir);
920 smaliOutputDir.mkdirs()
921 outputs.dir smaliOutputDir
922 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
923 def smaliFiles = fileTree(dir: dir, include: '*.smali')
924 def javaFiles = fileTree(dir: dir, include: '*.java')
925 def destDir = smaliOutputDir;
926 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
927 def intermediateFileName = "${name}-intermediate.dex";
928 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
929 if (javaFiles.empty) {
930 if (!smaliFiles.empty) {
931 dependsOn "${taskName}_smali"
932 task "${taskName}_smali"(type: smali.Smali) {
933 source = smaliFiles
934 destination = destFile
935 }
936 }
937 } else {
938 dependsOn "${taskName}_dexmerger"
939 task "${taskName}_smali"(type: smali.Smali) {
940 source = smaliFiles
941 destination = intermediateFile
942 }
943 task "${taskName}_java"(type: JavaCompile) {
944 source = javaFiles
945 destinationDir destDir
946 classpath = sourceSets.main.compileClasspath
947 sourceCompatibility = JavaVersion.VERSION_1_7
948 targetCompatibility = JavaVersion.VERSION_1_7
949 options.compilerArgs += ["-Xlint:-options"]
950 }
951 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
952 archiveName = "Test.jar"
953 destinationDir = destDir
954 from fileTree(dir: destDir, include: 'Test.class')
955 }
956 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
957 source = fileTree(dir: destDir, include: 'Test.jar')
958 destination = destDir
959 }
960 task "${taskName}_dexmerger"(
961 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
962 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
963 destination = destFile
964 }
965 }
966 }
967}
968
969tasks.withType(Test) {
970 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
971 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
972 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
973 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
974 forkEvery = 0
975 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
976 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +0200977 if (project.hasProperty('disable_assertions')) {
978 enableAssertions = false
979 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200980}
981
982task buildPreNJdwpTestsJar(type: Jar) {
983 baseName = 'jdwp-tests-preN'
984 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
985 // Exclude the classes containing java8
986 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
987 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
988 includeEmptyDirs = false
989}
990
Yohann Roussel126f6872017-08-03 16:25:32 +0200991task supportLibDir() {
992 doLast {
993 File dir = file("build/supportlibraries")
994 dir.mkdir()
995 }
996}
997
998configurations.supportLibs.files.each { file ->
999 if (file.getName().endsWith(".aar")) {
1000 def name = "extract_"+file.getName()
1001 task "${name}"(type: Copy) {
1002 dependsOn supportLibDir
1003 from zipTree(file)
1004 into "build/supportlibraries"
1005 eachFile { FileCopyDetails fcp ->
1006 if (fcp.relativePath.pathString.equals("classes.jar")) {
1007 // remap the file to the root with correct name
1008 fcp.relativePath = new RelativePath(true, file.getName().replace(".aar", ".jar"))
1009 } else {
1010 fcp.exclude()
1011 }
1012 }
1013 }
1014 }
1015}
1016
1017task supportLibList() {
1018 configurations.supportLibs.files.each {
1019 if (it.getName().endsWith(".aar")) {
1020 dependsOn "extract_"+it.getName()
1021 }
1022 }
1023 doLast {
Yohann Roussel630dfe12017-08-03 17:24:08 +02001024 file("build/generated").mkdir()
Yohann Roussel126f6872017-08-03 16:25:32 +02001025 def file = file("build/generated/supportlibraries.txt")
1026 file.createNewFile()
1027 file.text = ""
1028 configurations.supportLibs.files.each {
1029 if (it.getName().endsWith(".aar")) {
1030 def outName = it.getName().replace(".aar", ".jar")
1031 file.text += ("build/supportlibraries/"
1032 + outName + "\n")
1033 } else {
1034 file.text += (it.getPath() + "\n")
1035 }
1036 }
1037 }
1038}
1039
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001040task AospJarTest(type: Exec) {
1041 dependsOn CompatDx, downloadDeps
1042 def script = "tools/test_aosp_jar.py"
1043 inputs.file script
1044 commandLine "python", script, "--no-build"
1045 workingDir = projectDir
1046}
1047
Mads Ager418d1ca2017-05-22 09:35:49 +02001048test {
Yohann Roussel126f6872017-08-03 16:25:32 +02001049 dependsOn supportLibList
Mads Ager418d1ca2017-05-22 09:35:49 +02001050 testLogging.exceptionFormat = 'full'
1051 if (project.hasProperty('print_test_stdout')) {
1052 testLogging.showStandardStreams = true
1053 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001054 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001055 println "Running with non default vm: " + project.property('dex_vm')
1056 systemProperty 'dex_vm', project.property('dex_vm')
1057 if (project.property('dex_vm') == '5.1.1' || project.property('dex_vm') == '6.0.1') {
1058 // R8 and D8 compute the dex file version number based on the input.
1059 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1060 // Therefore we skip the jack generated art tests with those art versions.
1061 exclude "com/android/tools/r8/art/jack/**"
1062 }
1063 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001064
Mads Ager418d1ca2017-05-22 09:35:49 +02001065 if (project.hasProperty('one_line_per_test')) {
1066 beforeTest { desc ->
1067 println "Start executing test ${desc.name} [${desc.className}]"
1068 }
1069 afterTest { desc, result ->
1070 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1071 }
1072 }
1073 if (project.hasProperty('no_internal')) {
1074 exclude "com/android/tools/r8/internal/**"
1075 }
1076 if (project.hasProperty('only_internal')) {
1077 include "com/android/tools/r8/internal/**"
1078 }
1079 if (project.hasProperty('tool')) {
1080 if (project.property('tool') == 'r8') {
1081 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001082 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001083 } else {
1084 assert(project.property('tool') == 'd8')
1085 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001086 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001087 }
1088 }
1089 if (!project.hasProperty('all_tests')) {
1090 exclude "com/android/tools/r8/art/dx/**"
1091 exclude "com/android/tools/r8/art/jack/**"
1092 }
1093 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1094 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001095 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001096 }
1097 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001098 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001099 }
1100 if (project.hasProperty('jctf_compile_only')) {
1101 println "JCTF: compiling only"
1102 systemProperty 'jctf_compile_only', '1'
1103 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001104 if (project.hasProperty('test_dir')) {
1105 systemProperty 'test_dir', project.property('test_dir')
1106 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001107 if (project.hasProperty('aosp_jar')) {
1108 dependsOn AospJarTest
1109 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001110
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001111 if (OperatingSystem.current().isLinux()
1112 || OperatingSystem.current().isMacOsX()
1113 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001114 if (OperatingSystem.current().isMacOsX()) {
1115 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1116 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1117 "See tools/docker/README.md for details.")
1118 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001119 if (OperatingSystem.current().isWindows()) {
1120 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1121 "Art only runs on Linux and tests requiring Art will be skipped")
1122 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001123 dependsOn downloadDeps
1124 dependsOn buildExamples
1125 dependsOn buildSmali
1126 dependsOn jctfCommonJar
1127 dependsOn jctfTestsClasses
1128 dependsOn buildDebugInfoExamplesDex
1129 dependsOn buildPreNJdwpTestsJar
1130 } else {
1131 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001132 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001133 }
1134}
1135
1136// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1137//
1138// To build and upload a new set of the Art tests for use with R8 follow these steps:
1139//
1140// First of all an Android checkout is required. Currently it must be located
1141// in $HOME/android/master.
1142//
1143// TODO(ricow): simplify this
1144//
1145// Before: update the checked in art, see scripts/update-host-art.sh
1146//
1147// 1. Get an android checkout in $HOME/android/master and apply the patch from
1148// https://android-review.googlesource.com/#/c/294187/
1149//
1150// 2. run the following commands in the Android checkout directory:
1151//
1152// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001153// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1154// m desugar
1155// m -j30 test-art-host
1156// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1157//
1158// Without running the test.py command the classes.jar file used by desugar in
1159// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1160// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001161//
1162// 3. In the R8 project root directory, make sure we have a clean state before starting:
1163// tools/gradle.py downloadDeps
1164// tools/gradle.py clean
1165// rm -rf tests/art
1166//
1167// 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 +02001168// Make sure you have smali on your path, please use the build binary in the
1169// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1170// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1171// need to change as smali got a completely new command line interface in version 2.2.1.
Mads Ager418d1ca2017-05-22 09:35:49 +02001172//
Søren Gjesse34b77732017-07-07 13:56:21 +02001173// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001174//
1175// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1176// skippedTests with an explanation. Rerun from step 3.
1177//
1178// 5. Run the tests:
1179// tools/gradle.py clean
1180// tools/test.py
1181//
Søren Gjesse34b77732017-07-07 13:56:21 +02001182// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1183// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1184// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001185//
Søren Gjesse34b77732017-07-07 13:56:21 +02001186// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001187// cd tests
1188// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001189//
1190// 7. Update the manifest file describing the Android repo used:
1191// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001192
1193enum DexTool {
1194 JACK,
1195 DX
1196}
1197
1198def androidCheckoutDir = file("${System.env.HOME}/android/master")
1199def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1200def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1201
1202def artTestDir = file("${androidCheckoutDir}/art/test")
1203
1204if (project.hasProperty('android_source')) {
1205 task buildArtTests {
1206 outputs.upToDateWhen { false }
1207 def toBeTriaged = [
1208 "903-hello-tagging",
1209 "904-object-allocation",
1210 "905-object-free",
1211 "906-iterate-heap",
1212 "907-get-loaded-classes",
1213 "908-gc-start-finish",
1214 "954-invoke-polymorphic-verifier",
1215 "955-methodhandles-smali",
1216 "596-monitor-inflation",
1217 ]
1218 def skippedTests = toBeTriaged + [
1219 // This test produces no jar.
1220 "000-nop",
1221 // This does not build, as it tests the error when the application exceeds more
1222 // than 65536 methods
1223 "089-many-methods",
1224 // Requires some jack beta jar
1225 "956-methodhandles",
1226 ]
1227
1228 def skippedTestsDx = [
1229 // Tests with custom build scripts, where javac is not passed the options
1230 // -source 1.7 -target 1.7.
1231 "462-checker-inlining-across-dex-files",
1232 "556-invoke-super",
1233 "569-checker-pattern-replacement",
1234 // These tests use jack even when --build-with-javac-dx is specified.
1235 "004-JniTest",
1236 "048-reflect-v8",
1237 "146-bad-interface",
1238 "563-checker-invoke-super",
1239 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1240 "604-hot-static-interface",
1241 "957-methodhandle-transforms",
1242 "958-methodhandle-emulated-stackframe",
1243 "959-invoke-polymorphic-accessors",
1244 "961-default-iface-resolution-gen",
1245 "962-iface-static",
1246 "963-default-range-smali",
1247 "964-default-iface-init-gen",
1248 "965-default-verify",
1249 "966-default-conflict",
1250 "967-default-ame",
1251 "968-default-partial-compile-gen",
1252 "969-iface-super",
1253 "970-iface-super-resolution-gen",
1254 "971-iface-super",
1255 // These tests does not build with --build-with-javac-dx
1256 "004-NativeAllocations", // Javac error
1257 "031-class-attributes",
1258 "138-duplicate-classes-check",
1259 "157-void-class", // Javac error
1260 "580-checker-string-factory-intrinsics",
1261 "612-jit-dex-cache",
1262 "613-inlining-dex-cache",
1263 "900-hello-plugin", // --experimental agents
1264 "901-hello-ti-agent", // --experimental agents
1265 "902-hello-transformation", // --experimental agents
1266 "909-attach-agent", // --experimental agents
1267 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1268 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1269 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1270 "960-default-smali", // --experimental default-methods
1271 // These tests force the build to use jack
1272 "953-invoke-polymorphic-compiler",
1273 "958-methodhandle-stackframe",
1274 ]
1275
1276 def artTestBuildDir = file("${projectDir}/tests/art")
1277
1278 if (androidCheckoutDir.exists()) {
1279 dependsOn downloadDeps
1280 artTestBuildDir.mkdirs()
1281 // Ensure Jack server is running.
1282 "${androidCheckoutJackServer} start-server".execute()
1283 artTestDir.eachDir { dir ->
1284 def name = dir.getName();
1285 def markerFile = dir.toPath().resolve("info.txt").toFile();
1286 if (markerFile.exists() && !(name in skippedTests)) {
1287 if (!(name in skippedTestsDx)) {
1288 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1289 }
1290 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
1291 }
1292 }
1293 }
1294 doFirst {
1295 if (!androidCheckoutDir.exists()) {
1296 throw new InvalidUserDataException(
1297 "This task requires an Android checkout in ${androidCheckoutDir}");
1298 } else if (!androidCheckoutJack.exists() ||
1299 !androidCheckoutJackServer.exists()) {
1300 throw new InvalidUserDataException(
1301 "This task requires that tools for host testing have been build in the " +
1302 "Android checkout in ${androidCheckoutDir}");
1303 }
1304 }
1305 doLast {
1306 copy {
1307 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1308 into file("${artTestBuildDir}/lib64")
1309 include 'lib*.so'
1310 }
1311 copy {
1312 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1313 into file("${artTestBuildDir}/lib64")
1314 include 'libart.so'
1315 include 'libbacktrace.so'
1316 include 'libbase.so'
1317 include 'libc++.so'
1318 include 'libcutils.so'
1319 include 'liblz4.so'
1320 include 'liblzma.so'
1321 include 'libnativebridge.so'
1322 include 'libnativeloader.so'
1323 include 'libsigchain.so'
1324 include 'libunwind.so'
1325 include 'libziparchive.so'
1326 }
1327 copy {
1328 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1329 into file("${artTestBuildDir}/lib")
1330 include 'lib*.so'
1331 }
1332 copy {
1333 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1334 into file("${artTestBuildDir}/lib")
1335 include 'libart.so'
1336 include 'libbacktrace.so'
1337 include 'libbase.so'
1338 include 'libc++.so'
1339 include 'libcutils.so'
1340 include 'liblz4.so'
1341 include 'liblzma.so'
1342 include 'libnativebridge.so'
1343 include 'libnativeloader.so'
1344 include 'libsigchain.so'
1345 include 'libunwind.so'
1346 include 'libziparchive.so'
1347 }
1348 }
1349 }
1350}
1351
1352def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1353 def artTestDir = file("${androidCheckoutDir}/art/test")
1354 def artRunTestScript = file("${artTestDir}/run-test")
1355 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001356 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001357 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1358
Søren Gjesse34b77732017-07-07 13:56:21 +02001359 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001360 def buildTask = "build_art_test_${dexToolName}_${name}"
1361 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1362 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1363 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1364
1365 def buildInputs = fileTree(dir: dir, include: '**/*')
1366 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1367 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1368 testDir.mkdirs()
1369 if (dexTool == DexTool.DX) {
1370 task "$buildTask"(type: Exec) {
1371 outputs.upToDateWhen { false }
1372 inputs.file buildInputs
1373 executable "${artRunTestScript}"
1374 args "--host"
1375 args "--build-only"
1376 args "--build-with-javac-dx"
1377 args "--output-path", "${testDir}"
1378 args "${name}"
1379 environment DX: "${dxExecutable.absolutePath}"
1380 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001381 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001382 outputs.file outputJar
1383 }
1384 } else {
1385 assert dexTool == DexTool.JACK
1386 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1387 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1388 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1389 task "$buildTask"(type: Exec) {
1390 outputs.upToDateWhen { false }
1391 inputs.file buildInputs
1392 executable "${artRunTestScript}"
1393 args "--host"
1394 args "--build-only"
1395 args "--output-path", "${testDir}"
1396 args "${name}"
1397 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1398 environment JACK_CLASSPATH: jackClasspath
1399 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1400 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1401 outputs.file outputJar
1402 }
1403 }
1404 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1405 outputs.upToDateWhen { false }
1406 executable "/bin/bash"
1407 args "-c"
1408 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1409 " ${testDir}/classes-ex ${testDir}/check"
1410 }
1411
1412 task "${smaliToDexTask}"(type: Exec) {
1413 workingDir "${testDir}/smali"
1414 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001415 // This is the command line options for smali prior to 2.2.1, where smali got a new
1416 // command line interface.
1417 args "-c", "smali a *.smali"
1418 // This is the command line options for smali 2.2.1 and later.
1419 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001420 }
1421
1422 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1423 def smali_dir = file("${dir}/smali")
1424 outputs.upToDateWhen { false }
1425 if (smali_dir.exists() && dexTool == DexTool.DX) {
1426 dependsOn smaliToDexTask
1427 }
1428 from("${artTestDir}/${name}") {
1429 include 'check'
1430 }
1431 into testDir
1432 }
1433
1434 return copyCheckTask
1435}
1436
1437task javadocD8(type: Javadoc) {
1438 classpath = sourceSets.main.compileClasspath
1439 source = sourceSets.main.allJava
1440 include '**/com/android/tools/r8/BaseCommand.java'
1441 include '**/com/android/tools/r8/BaseOutput.java'
1442 include '**/com/android/tools/r8/CompilationException.java'
1443 include '**/com/android/tools/r8/CompilationMode.java'
1444 include '**/com/android/tools/r8/D8.java'
1445 include '**/com/android/tools/r8/D8Command.java'
1446 include '**/com/android/tools/r8/D8Output.java'
1447 include '**/com/android/tools/r8/Resource.java'
1448}