blob: ef09f766e52a9f99b2288cd11d514de35fd3d796 [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.
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +02004import net.ltgt.gradle.errorprone.ErrorProneToolChain
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02005import org.gradle.internal.os.OperatingSystem
Stephan Herhut417a72a2017-07-18 10:38:30 +02006import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +02007
8apply plugin: 'java'
9apply plugin: 'idea'
Stephan Herhut417a72a2017-07-18 10:38:30 +020010apply plugin: 'com.google.protobuf'
Yohann Roussel7f47c032017-09-14 12:19:06 +020011apply plugin: 'com.cookpad.android.licensetools'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020012apply plugin: 'net.ltgt.errorprone-base'
Stephan Herhut52cb1022017-10-24 15:10:41 +020013apply plugin: "net.ltgt.apt"
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020014
15def errorProneConfiguration = [
16 '-XepDisableAllChecks',
17 // D8 want to use reference equality, thus disable the checker explicitly
18 '-Xep:ReferenceEquality:OFF',
19 '-Xep:ClassCanBeStatic:WARN',
20 '-Xep:OperatorPrecedence:WARN',
Benoit Lamarchec9996fd2017-10-17 17:21:36 +020021 '-Xep:RemoveUnusedImports:WARN',
Mikaël Peltier75b182e2017-10-19 11:58:34 +020022 '-Xep:MissingOverride:WARN',
Mikaël Peltiera12ad032017-10-23 09:03:14 +020023 '-Xep:OvershadowingSubclassFields:WARN',
24 '-Xep:IntLongMath:WARN']
Mads Ager418d1ca2017-05-22 09:35:49 +020025
26apply from: 'copyAdditionalJctfCommonFiles.gradle'
27
Sebastien Hertze2687b62017-07-25 11:16:04 +020028
29if (project.hasProperty('with_code_coverage')) {
30 apply plugin: 'jacoco'
31}
32
Mads Ager418d1ca2017-05-22 09:35:49 +020033repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020034 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020035 mavenCentral()
36}
37
Stephan Herhut417a72a2017-07-18 10:38:30 +020038buildscript {
39 repositories {
40 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020041 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020042 maven {
43 url "https://plugins.gradle.org/m2/"
44 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020045 }
46 dependencies {
47 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020048 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Mads Ager1d5ae402017-09-22 12:30:56 +020049 // TODO(ager): shadow does not support java9 class files yet. Once it does,
50 // we should use the offial version instead of our fork using ASM 6.0 to
51 // support java9.
52 // classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
53 classpath files("third_party/shadow/shadow-2.0.1.jar")
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020054 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020055 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Stephan Herhut417a72a2017-07-18 10:38:30 +020056 }
57}
58
Mads Ager418d1ca2017-05-22 09:35:49 +020059// Custom source set for example tests and generated tests.
60sourceSets {
61 test {
62 java {
63 srcDirs = [
64 'src/test/java',
65 'build/generated/test/java',
66 ]
67 }
68 }
69 debugTestResources {
70 java {
71 srcDirs = ['src/test/debugTestResources']
72 }
73 output.resourcesDir = 'build/classes/debugTestResources'
74 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020075 debugTestResourcesJava8 {
76 java {
77 srcDirs = ['src/test/debugTestResourcesJava8']
78 }
79 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
80 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +020081 debugTestResourcesKotlin {
82 java {
83 srcDirs = ['src/test/debugTestResourcesKotlin']
84 }
85 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
86 }
Mads Ager418d1ca2017-05-22 09:35:49 +020087 examples {
88 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +020089 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
90 }
91 proto {
92 srcDirs = [
93 'src/test/examples',
94 ]
Mads Ager418d1ca2017-05-22 09:35:49 +020095 }
96 output.resourcesDir = 'build/classes/examples'
97 }
98 examplesAndroidN {
99 java {
100 srcDirs = ['src/test/examplesAndroidN']
101 }
102 output.resourcesDir = 'build/classes/examplesAndroidN'
103 }
104 examplesAndroidO {
105 java {
106 srcDirs = ['src/test/examplesAndroidO']
107 }
108 output.resourcesDir = 'build/classes/examplesAndroidO'
109 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200110 examplesAndroidP {
111 java {
112 srcDirs = ['src/test/examplesAndroidP']
113 }
114 output.resourcesDir = 'build/classes/examplesAndroidP'
115 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200116 jctfCommon {
117 java {
118 srcDirs = [
119 'third_party/jctf/Harness/src',
120 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
121 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
122 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
123 'third_party/jctf/LibTests/src/org',
124 'build/additionalJctfCommonFiles'
125 ]
126 }
127 resources {
128 srcDirs = ['third_party/jctf/LibTests/resources']
129 }
130 }
131 jctfTests {
132 java {
133 srcDirs = [
134 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
135 // 'third_party/jctf/VMTests/src',
136 ]
137 }
138 }
139}
140
Yohann Roussel126f6872017-08-03 16:25:32 +0200141configurations {
142 supportLibs
143}
144
Mads Ager418d1ca2017-05-22 09:35:49 +0200145dependencies {
146 compile 'net.sf.jopt-simple:jopt-simple:4.6'
Mads Agercd06c802017-08-22 13:44:34 +0200147 compile 'com.googlecode.json-simple:json-simple:1.1'
Mads Ager0aa48052017-09-15 12:39:15 +0200148 // Include all of guava when compiling the code, but exclude annotations that we don't
149 // need from the packaging.
150 compileOnly('com.google.guava:guava:23.0')
151 compile('com.google.guava:guava:23.0', {
152 exclude group: 'com.google.errorprone'
153 exclude group: 'com.google.code.findbugs'
154 exclude group: 'com.google.j2objc'
155 exclude group: 'org.codehaus.mojo'
156 })
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200157 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200158 compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200159 compile group: 'org.ow2.asm', name: 'asm', version: '6.0'
160 compile group: 'org.ow2.asm', name: 'asm-commons', version: '6.0'
161 compile group: 'org.ow2.asm', name: 'asm-tree', version: '6.0'
162 compile group: 'org.ow2.asm', name: 'asm-util', version: '6.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200163 testCompile sourceSets.examples.output
164 testCompile 'junit:junit:4.12'
165 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
166 testCompile files('third_party/jasmin/jasmin-2.4.jar')
167 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200168 testCompile files('third_party/ddmlib/ddmlib.jar')
Mads Ager418d1ca2017-05-22 09:35:49 +0200169 jctfCommonCompile 'junit:junit:4.12'
170 jctfTestsCompile 'junit:junit:4.12'
171 jctfTestsCompile sourceSets.jctfCommon.output
Mikaël Peltier7345e482017-10-17 17:57:48 +0200172 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
173 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200174 // Import Guava for @Nullable annotation
175 examplesCompile 'com.google.guava:guava:23.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200176 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200177 examplesCompileOnly "com.google.auto.value:auto-value:1.5"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200178 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200179 supportLibs 'com.android.support:support-v4:25.4.0'
180 supportLibs 'junit:junit:4.12'
181 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200182 debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200183 apt 'com.google.auto.value:auto-value:1.5'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200184}
185
Yohann Roussel7f47c032017-09-14 12:19:06 +0200186licenseTools {
187 licensesYaml = file('LIBRARY-LICENSE')
188}
189
Stephan Herhut417a72a2017-07-18 10:38:30 +0200190protobuf {
191 protoc {
192 // Download from repositories
193 artifact = 'com.google.protobuf:protoc:3.0.0'
194 }
195 plugins {
196 javalite {
197 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
198 }
199 }
200 generateProtoTasks {
201 all().each { task ->
202 task.builtins {
203 // Disable the java code generator, as we want javalite only.
204 remove java
205 }
206 task.plugins {
207 javalite {}
208 }
209 }
210 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200211}
212
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200213def osString = OperatingSystem.current().isLinux() ? "linux" :
214 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200215
216def cloudDependencies = [
217 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200218 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200219 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200220 ],
221 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200222 "android_jar/lib-v14",
223 "android_jar/lib-v19",
224 "android_jar/lib-v21",
225 "android_jar/lib-v24",
226 "android_jar/lib-v25",
227 "android_jar/lib-v26",
228 "proguard/proguard5.2.1",
229 "gradle/gradle",
230 "jdwp-tests",
231 "jasmin",
232 "jctf",
233 "kotlin",
234 "android_cts_baseline",
235 "shadow",
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200236 "ddmlib",
Mads Ager418d1ca2017-05-22 09:35:49 +0200237 ],
238 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
239 // container on other platforms where supported.
240 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200241 "linux/art",
242 "linux/art-5.1.1",
243 "linux/art-6.0.1",
244 "linux/art-7.0.0",
245 "linux/dalvik",
246 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200247 ]
248]
249
250cloudDependencies.each { entry ->
251 entry.value.each { entryFile ->
252 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200253 def outputDir = "${entry.key}/${entryFile}"
254 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200255 def sha1File = "${gzFile}.sha1"
256 inputs.file sha1File
257 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200258 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200259 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
260 if (OperatingSystem.current().isWindows()) {
261 executable "download_from_google_storage.bat"
262 args dlFromStorageArgs
263 } else {
264 executable "bash"
265 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
266 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200267 }
268 }
269}
270
271def x20Dependencies = [
272 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200273 "gmail/gmail_android_170604.16",
274 "gmscore/v4",
275 "gmscore/v5",
276 "gmscore/v6",
277 "gmscore/v7",
278 "gmscore/v8",
279 "gmscore/gmscore_v9",
280 "gmscore/gmscore_v10",
281 "gmscore/latest",
282 "photos/2017-06-06",
283 "youtube/youtube.android_12.10",
284 "youtube/youtube.android_12.17",
285 "youtube/youtube.android_12.22",
286 "proguardsettings",
287 "proguard/proguard_internal_159423826",
288 "framework",
289 "goyt",
Mads Ager418d1ca2017-05-22 09:35:49 +0200290 ],
291]
292
293x20Dependencies.each { entry ->
294 entry.value.each { entryFile ->
295 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200296 def outputDir = "${entry.key}/${entryFile}"
297 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200298 def sha1File = "${gzFile}.sha1"
299 inputs.file sha1File
300 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200301 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200302 executable "bash"
303 args "-c", "tools/download_from_x20.py ${sha1File}"
304 }
305 }
306}
307
Rico Wind897bb712017-05-23 10:44:29 +0200308task downloadProguard {
309 cloudDependencies.each { entry ->
310 entry.value.each { entryFile ->
311 if (entryFile.contains("proguard")) {
312 dependsOn "download_deps_${entry.key}/${entryFile}"
313 }
314 }
315 }
316}
317
Tamas Kenez427205b2017-06-29 15:57:09 +0200318task downloadDx {
319 cloudDependencies.each { entry ->
320 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200321 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200322 dependsOn "download_deps_${entry.key}/${entryFile}"
323 }
324 }
325 }
326}
327
Tamas Kenez0e10c562017-06-08 10:00:34 +0200328task downloadAndroidCts {
329 cloudDependencies.each { entry ->
330 entry.value.each { entryFile ->
331 if (entryFile.contains("android_cts_baseline")) {
332 dependsOn "download_deps_${entry.key}/${entryFile}"
333 }
334 }
335 }
336}
337
Mads Ager418d1ca2017-05-22 09:35:49 +0200338task downloadDeps {
339 cloudDependencies.each { entry ->
340 entry.value.each { entryFile ->
341 dependsOn "download_deps_${entry.key}/${entryFile}"
342 }
343 }
344 if (!project.hasProperty('no_internal')) {
345 x20Dependencies.each { entry ->
346 entry.value.each { entryFile ->
347 dependsOn "download_deps_${entry.key}/${entryFile}"
348 }
349 }
350 }
351}
352
353allprojects {
354 sourceCompatibility = JavaVersion.VERSION_1_8
355 targetCompatibility = JavaVersion.VERSION_1_8
356}
357
358tasks.withType(JavaCompile) {
359 options.compilerArgs << '-Xlint:unchecked'
360}
361
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200362if (!project.hasProperty('without_error_prone')) {
363 compileJava {
364 // Enable error prone for D8/R8 sources.
365 toolChain ErrorProneToolChain.create(project)
366 options.compilerArgs += errorProneConfiguration
367 }
368}
369
Mads Ager418d1ca2017-05-22 09:35:49 +0200370compileJctfCommonJava {
371 dependsOn 'copyAdditionalJctfCommonFiles'
372 options.compilerArgs = ['-Xlint:none']
373}
374
375compileJctfTestsJava {
376 dependsOn 'jctfCommonClasses'
377 options.compilerArgs = ['-Xlint:none']
378}
379
Yohann Roussel7f47c032017-09-14 12:19:06 +0200380task consolidatedLicense {
381 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
382 // corresponding to the effective list of embedded libraries.
383 dependsOn 'checkLicenses'
384 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
385 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
386 outputs.files license
387 doLast {
388 license.getParentFile().mkdirs()
389 license.createNewFile()
390 license.text = "This file lists all licenses for code distributed.\n"
391 license.text += "All non-library code has the following 3-Clause BSD license.\n"
392 license.text += "\n"
393 license.text += "\n"
394 license.text += file('LICENSE').text
395 license.text += "\n"
396 license.text += "\n"
397 license.text += "Summary of distributed libraries:\n"
398 license.text += "\n"
399 license.text += file('LIBRARY-LICENSE').text
400 license.text += "\n"
401 license.text += "\n"
402 license.text += "Licenses details:\n"
403 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
404 license.text += "\n"
405 license.text += "\n"
406 license.text += file.text
407 }
408 }
409}
410
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200411task R8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200412 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200413 from consolidatedLicense.outputs.files
414 exclude { path ->
415 path.getRelativePath().getPathString().startsWith("META-INF")
416 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200417 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200418 classifier = null
419 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200420 manifest {
421 attributes 'Main-Class': 'com.android.tools.r8.R8'
422 }
423 // In order to build without dependencies, pass the exclude_deps property using:
424 // gradle -Pexclude_deps R8
425 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200426 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
427 // to avoid rewriting unrelated strings.
428 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
429 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200430 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200431 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
432 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200433 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200434 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200435 // Also include dependencies
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200436 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200437 }
438}
439
mikaelpeltier80939312017-08-17 15:00:09 +0200440task D8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200441 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200442 from consolidatedLicense.outputs.files
443 exclude { path ->
444 path.getRelativePath().getPathString().startsWith("META-INF")
445 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200446 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200447 classifier = null
448 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200449 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200450 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200451 }
452 // In order to build without dependencies, pass the exclude_deps property using:
453 // gradle -Pexclude_deps D8
454 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200455 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
456 // to avoid rewriting unrelated strings.
457 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
458 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
mikaelpeltier80939312017-08-17 15:00:09 +0200459 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200460 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
461 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200462 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
mikaelpeltier80939312017-08-17 15:00:09 +0200463 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200464 // Also include dependencies
mikaelpeltier80939312017-08-17 15:00:09 +0200465 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200466 }
467}
468
469task CompatDx(type: Jar) {
470 from sourceSets.main.output
471 baseName 'compatdx'
472 manifest {
473 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
474 }
475 // In order to build without dependencies, pass the exclude_deps property using:
476 // gradle -Pexclude_deps CompatDx
477 if (!project.hasProperty('exclude_deps')) {
478 // Also include dependencies
479 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
480 }
481}
482
Søren Gjesse1d21da72017-09-01 12:05:38 +0200483task CompatProguard(type: Jar) {
484 from sourceSets.main.output
485 baseName 'compatproguard'
486 manifest {
487 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
488 }
489 // In order to build without dependencies, pass the exclude_deps property using:
490 // gradle -Pexclude_deps CompatProguard
491 if (!project.hasProperty('exclude_deps')) {
492 // Also include dependencies
493 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
494 }
495}
496
Tamas Kenez971eec62017-05-24 11:08:40 +0200497task D8Logger(type: Jar) {
498 from sourceSets.main.output
499 baseName 'd8logger'
500 manifest {
501 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
502 }
503 // In order to build without dependencies, pass the exclude_deps property using:
504 // gradle -Pexclude_deps D8Logger
505 if (!project.hasProperty('exclude_deps')) {
506 // Also include dependencies
507 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
508 }
509}
510
Mads Ager418d1ca2017-05-22 09:35:49 +0200511task disasm(type: Jar) {
512 from sourceSets.main.output
513 baseName 'disasm'
514 manifest {
515 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
516 }
517 // In order to build without dependencies, pass the exclude_deps property using:
518 // gradle -Pexclude_deps D8
519 if (!project.hasProperty('exclude_deps')) {
520 // Also include dependencies
521 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
522 }
523}
524
525task bisect(type: Jar) {
526 from sourceSets.main.output
527 baseName 'bisect'
528 manifest {
529 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
530 }
531 // In order to build without dependencies, pass the exclude_deps property using:
532 // gradle -Pexclude_deps R8
533 if (!project.hasProperty('exclude_deps')) {
534 // Also include dependencies
535 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
536 }
537}
538
Lars Bak90c18042017-06-26 14:21:08 +0200539task DexSegments(type: Jar) {
540 from sourceSets.main.output
541 baseName 'dexsegments'
542 manifest {
543 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
544 }
545 // In order to build without dependencies, pass the exclude_deps property using:
546 // gradle -Pexclude_deps DexSegments
547 if (!project.hasProperty('exclude_deps')) {
548 // Also include dependencies
549 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
550 }
551}
552
Søren Gjessec4e5e932017-09-04 17:01:23 +0200553task maindex(type: Jar) {
554 from sourceSets.main.output
555 baseName 'maindex'
556 manifest {
557 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
558 }
559 // In order to build without dependencies, pass the exclude_deps property using:
560 // gradle -Pexclude_deps maindex
561 if (!project.hasProperty('exclude_deps')) {
562 // Also include dependencies
563 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
564 }
565}
566
Lars Bak44cef522017-08-10 16:02:39 +0200567task ExtractMarker(type: Jar) {
568 from sourceSets.main.output
569 baseName 'extractmarker'
570 manifest {
571 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
572 }
573 // In order to build without dependencies, pass the exclude_deps property using:
574 // gradle -Pexclude_deps ExtractMarker
575 if (!project.hasProperty('exclude_deps')) {
576 // Also include dependencies
577 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
578 }
579}
580
Mads Ager418d1ca2017-05-22 09:35:49 +0200581task sourceJar(type: Jar, dependsOn: classes) {
582 classifier = 'src'
583 from sourceSets.main.allSource
584}
585
586task jctfCommonJar(type: Jar) {
587 from sourceSets.jctfCommon.output
588 baseName 'jctfCommon'
589}
590
591artifacts {
592 archives sourceJar
593}
594
595task createArtTests(type: Exec) {
596 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200597 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200598 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200599 inputs.file createArtTestsScript
600 outputs.dir outputDir
601 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200602 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200603 workingDir = projectDir
604}
605
606task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200607 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200608 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200609 inputs.file script
610 outputs.dir outputDir
611 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200612 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200613 workingDir = projectDir
614}
615
616compileTestJava {
617 dependsOn createArtTests
618 dependsOn createJctfTests
619}
620
621task buildDebugInfoExamplesDex {
622 def examplesDir = file("src/test/java")
623 def hostJar = "debuginfo_examples.jar"
624 def hostDexJar = "debuginfo_examples_dex.jar"
625 task "compile_debuginfo_examples"(type: JavaCompile) {
626 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
627 destinationDir = file("build/test/debuginfo_examples/classes")
628 classpath = sourceSets.main.compileClasspath
629 sourceCompatibility = JavaVersion.VERSION_1_7
630 targetCompatibility = JavaVersion.VERSION_1_7
631 options.compilerArgs += ["-Xlint:-options"]
632 }
633 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
634 archiveName = hostJar
635 destinationDir = file("build/test/")
636 from "build/test/debuginfo_examples/classes"
637 include "**/*.class"
638 }
639 task "dex_debuginfo_examples"(type: Exec,
640 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200641 if (OperatingSystem.current().isWindows()) {
642 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700643 } else if (OperatingSystem.current().isMacOsX()) {
644 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200645 } else {
646 executable file("tools/linux/dx/bin/dx");
647 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200648 args "--dex"
649 args "--output=build/test/${hostDexJar}"
650 args "build/test/${hostJar}"
651 inputs.file file("build/test/${hostJar}")
652 outputs.file file("build/test/${hostDexJar}")
653 }
654 dependsOn dex_debuginfo_examples
655}
656
657task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200658 def resourcesDir = file("src/test/debugTestResources")
659 def hostJar = "debug_test_resources.jar"
660 task "compile_debugTestResources"(type: JavaCompile) {
661 source = fileTree(dir: resourcesDir, include: '**/*.java')
662 destinationDir = file("build/test/debugTestResources/classes")
663 classpath = sourceSets.main.compileClasspath
664 sourceCompatibility = JavaVersion.VERSION_1_7
665 targetCompatibility = JavaVersion.VERSION_1_7
666 options.compilerArgs += ["-g", "-Xlint:-options"]
667 }
668 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
669 archiveName = hostJar
670 destinationDir = file("build/test/")
671 from "build/test/debugTestResources/classes"
672 include "**/*.class"
673 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200674 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
675 def java8HostJar = "debug_test_resources_java8.jar"
676 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
677 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
678 destinationDir = file("build/test/debugTestResourcesJava8/classes")
679 classpath = sourceSets.main.compileClasspath
680 sourceCompatibility = JavaVersion.VERSION_1_8
681 targetCompatibility = JavaVersion.VERSION_1_8
682 options.compilerArgs += ["-g", "-Xlint:-options"]
683 }
684 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
685 archiveName = java8HostJar
686 destinationDir = file("build/test/")
687 from "build/test/debugTestResourcesJava8/classes"
688 include "**/*.class"
689 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200690 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
691 def kotlinHostJar = "debug_test_resources_kotlin.jar"
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200692 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
693 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
694 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200695 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200696 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200697 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200698 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200699 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200700}
701
Lars Bakc91e87e2017-08-18 08:53:10 +0200702// Proto lite generated code yields warnings when compiling with javac.
703// We change the options passed to javac to ignore it.
704compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
705
Mads Ager418d1ca2017-05-22 09:35:49 +0200706task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200707 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200708 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200709 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200710 def proguardScript
711 if (OperatingSystem.current().isWindows()) {
712 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
713 } else {
714 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
715 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200716 task extractExamplesRuntime(type: Sync) {
717 dependsOn configurations.examplesRuntime
718 from configurations.examplesRuntime.collect { zipTree(it) }
719 include "**/*.class"
720 includeEmptyDirs false
721 into "$buildDir/runtime/examples/"
722 }
723
724 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
725 source examplesDir, protoSourceDir
726 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200727 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200728 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200729 sourceCompatibility = JavaVersion.VERSION_1_7
730 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200731 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
732 }
733 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
734 source examplesDir, protoSourceDir
735 include "**/*.java"
736 destinationDir = file("build/test/examples/classes_debuginfo_all")
737 classpath = sourceSets.examples.compileClasspath
738 sourceCompatibility = JavaVersion.VERSION_1_7
739 targetCompatibility = JavaVersion.VERSION_1_7
740 options.compilerArgs = ["-g", "-Xlint:none"]
741 }
742 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
743 source examplesDir, protoSourceDir
744 include "**/*.java"
745 destinationDir = file("build/test/examples/classes_debuginfo_none")
746 classpath = sourceSets.examples.compileClasspath
747 sourceCompatibility = JavaVersion.VERSION_1_7
748 targetCompatibility = JavaVersion.VERSION_1_7
749 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200750 }
751 examplesDir.eachDir { dir ->
752 def name = dir.getName();
753 def exampleOutputDir = file("build/test/examples");
754 def jarName = "${name}.jar"
755 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200756 dependsOn "jar_example_${name}_debuginfo_all"
757 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200758 dependsOn "extractExamplesRuntime"
759 def runtimeDependencies = copySpec { }
760 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
761 // If we have any proto use, we have to include those classes and the runtime.
762 runtimeDependencies = copySpec {
763 from "$buildDir/runtime/examples/"
764 include "com/google/protobuf/**/*.class"
765 }
766 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200767 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
768 def proguardConfigPath = "${dir}/proguard.cfg"
769 if (new File(proguardConfigPath).exists()) {
770 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
771 archiveName = "${name}_pre_proguard.jar"
772 destinationDir = exampleOutputDir
773 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200774 include name + "/**/*.class"
775 with runtimeDependencies
776 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200777 }
778 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
779 def proguardJarPath = "${exampleOutputDir}/${jarName}"
780 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
781 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
782 inputs.files tasks.getByPath("pre_proguard_example_${name}")
783 inputs.file proguardConfigPath
784 // Enable these to get stdout and stderr redirected to files...
785 // standardOutput = new FileOutputStream('proguard.stdout')
786 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200787 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200788 " -outjars ${proguardJarPath}" +
789 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200790 " -printmapping ${proguardMapPath}"
791 if (OperatingSystem.current().isWindows()) {
792 executable "${proguardScript}"
793 args "${proguardArguments}"
794 } else {
795 executable "bash"
796 args "-c", "${proguardScript} '${proguardArguments}'"
797 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200798 outputs.file proguardJarPath
799 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200800 // TODO: Consider performing distinct proguard compilations.
801 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
802 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200803 into "${exampleOutputDir}"
804 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200805 }
806 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
807 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200808 into "${exampleOutputDir}"
809 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200810 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200811 } else {
812 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200813 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200814 destinationDir = exampleOutputDir
815 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200816 include name + "/**/*.class"
817 with runtimeDependencies
818 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200819 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200820 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
821 archiveName = "${name}_debuginfo_all.jar"
822 destinationDir = exampleOutputDir
823 from "build/test/examples/classes_debuginfo_all"
824 include name + "/**/*.class"
825 with runtimeDependencies
826 includeEmptyDirs false
827 }
828 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
829 archiveName = "${name}_debuginfo_none.jar"
830 destinationDir = exampleOutputDir
831 from "build/test/examples/classes_debuginfo_none"
832 include name + "/**/*.class"
833 with runtimeDependencies
834 includeEmptyDirs false
835 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200836 }
837 }
838}
839
840task buildExampleAndroidNJars {
841 dependsOn downloadDeps
842 def examplesDir = file("src/test/examplesAndroidN")
843 task "compile_examplesAndroidN"(type: JavaCompile) {
844 source = fileTree(dir: examplesDir, include: '**/*.java')
845 destinationDir = file("build/test/examplesAndroidN/classes")
846 classpath = sourceSets.main.compileClasspath
847 sourceCompatibility = JavaVersion.VERSION_1_8
848 targetCompatibility = JavaVersion.VERSION_1_8
849 options.compilerArgs += ["-Xlint:-options"]
850 }
851 examplesDir.eachDir { dir ->
852 def name = dir.getName();
853 def exampleOutputDir = file("build/test/examplesAndroidN");
854 def jarName = "${name}.jar"
855 dependsOn "jar_examplesAndroidN_${name}"
856 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
857 archiveName = jarName
858 destinationDir = exampleOutputDir
859 from "build/test/examplesAndroidN/classes"
860 include "**/" + name + "/**/*.class"
861 }
862 }
863}
864
865
866task buildExampleAndroidOJars {
867 dependsOn downloadDeps
868 def examplesDir = file("src/test/examplesAndroidO")
869 // NOTE: we want to enable a scenario when test needs to reference some
870 // classes generated by legacy (1.6) Java compiler to test some specific
871 // behaviour. To do so we compile all the java files located in sub-directory
872 // called 'legacy' with Java 1.6, then compile the rest of the files with
873 // Java 1.8 and a reference to previously generated 1.6 classes.
874
875 // Compiling all classes in dirs 'legacy' with old Java version.
876 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
877 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
878 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
879 classpath = sourceSets.main.compileClasspath
880 sourceCompatibility = JavaVersion.VERSION_1_6
881 targetCompatibility = JavaVersion.VERSION_1_6
882 options.compilerArgs += ["-Xlint:-options", "-parameters"]
883 }
884 // Compiling the rest of the files as Java 1.8 code.
885 task "compile_examplesAndroidO"(type: JavaCompile) {
886 dependsOn "compile_examplesAndroidO_Legacy"
887 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
888 destinationDir = file("build/test/examplesAndroidO/classes")
889 classpath = sourceSets.main.compileClasspath
890 classpath += files("build/test/examplesAndroidOLegacy/classes")
891 sourceCompatibility = JavaVersion.VERSION_1_8
892 targetCompatibility = JavaVersion.VERSION_1_8
893 options.compilerArgs += ["-Xlint:-options", "-parameters"]
894 }
895 examplesDir.eachDir { dir ->
896 def name = dir.getName();
897 def destinationDir = file("build/test/examplesAndroidO/classes");
898 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
899 task "generate_examplesAndroidO_${name}"(type: JavaExec,
900 dependsOn: "compile_examplesAndroidO") {
901 main = name + ".TestGenerator"
902 classpath = files(destinationDir, sourceSets.main.compileClasspath)
903 args destinationDir
904 }
905 } else {
906 task "generate_examplesAndroidO_${name}" () {}
907 }
908 }
909 examplesDir.eachDir { dir ->
910 def name = dir.getName();
911 def exampleOutputDir = file("build/test/examplesAndroidO");
912 def jarName = "${name}.jar"
913 dependsOn "jar_examplesAndroidO_${name}"
914 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
915 "generate_examplesAndroidO_${name}"]) {
916 archiveName = jarName
917 destinationDir = exampleOutputDir
918 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
919 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
920 include "**/" + name + "/**/*.class"
921 // Do not include generator into the test runtime jar, it is not useful.
922 // Otherwise, shrinking will need ASM jars.
923 exclude "**/TestGenerator*"
924 }
925 }
926}
927
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200928task buildExampleAndroidPJars {
929 dependsOn downloadDeps
930 def examplesDir = file("src/test/examplesAndroidP")
931
932 task "compile_examplesAndroidP"(type: JavaCompile) {
933 source = fileTree(dir: examplesDir, include: '**/*.java')
934 destinationDir = file("build/test/examplesAndroidP/classes")
935 classpath = sourceSets.main.compileClasspath
936 sourceCompatibility = JavaVersion.VERSION_1_8
937 targetCompatibility = JavaVersion.VERSION_1_8
938 options.compilerArgs += ["-Xlint:-options"]
939 }
940 examplesDir.eachDir { dir ->
941 def name = dir.getName();
942 def destinationDir = file("build/test/examplesAndroidP/classes");
943 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
944 task "generate_examplesAndroidP_${name}"(type: JavaExec,
945 dependsOn: "compile_examplesAndroidP") {
946 main = name + ".TestGenerator"
947 classpath = files(destinationDir, sourceSets.main.compileClasspath)
948 args destinationDir
949 }
950 } else {
951 task "generate_examplesAndroidP_${name}" () {}
952 }
953 }
954 examplesDir.eachDir { dir ->
955 def name = dir.getName();
956 def exampleOutputDir = file("build/test/examplesAndroidP");
957 def jarName = "${name}.jar"
958 dependsOn "jar_examplesAndroidP_${name}"
959 task "jar_examplesAndroidP_${name}"(type: Jar,
960 dependsOn: ["compile_examplesAndroidP",
961 "generate_examplesAndroidP_${name}"]) {
962 archiveName = jarName
963 destinationDir = exampleOutputDir
964 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
965 include "**/" + name + "/**/*.class"
966 // Do not include generator into the test runtime jar, it is not useful.
967 // Otherwise, shrinking will need ASM jars.
968 exclude "**/TestGenerator*"
969 }
970 }
971}
972
Mikaël Peltier61633d42017-10-13 16:51:06 +0200973task buildExampleJava9Jars {
974 def examplesDir = file("src/test/examplesJava9")
975 examplesDir.eachDir { dir ->
976 def name = dir.getName();
977 def exampleOutputDir = file("build/test/examplesJava9");
978 def jarName = "${name}.jar"
979 dependsOn "jar_examplesJava9_${name}"
980 task "jar_examplesJava9_${name}"(type: Jar) {
981 archiveName = jarName
982 destinationDir = exampleOutputDir
983 from "src/test/examplesJava9" // Java 1.9 classes
984 include "**/" + name + "/**/*.class"
985 }
986 }
987}
988
Mads Ager418d1ca2017-05-22 09:35:49 +0200989task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200990 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
991 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
992 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +0200993 } else if (!OperatingSystem.current().isLinux()) {
994 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200995 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +0200996 return;
997 }
998 dependsOn buildDebugTestResourcesJars
999 dependsOn buildExampleJars
1000 dependsOn buildExampleAndroidNJars
1001 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001002 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001003 dependsOn buildExampleJava9Jars
Mads Ager418d1ca2017-05-22 09:35:49 +02001004 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001005 def noDexTests = [
1006 "multidex",
1007 "multidex002",
1008 "multidex004",
1009 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001010 examplesDir.eachDir { dir ->
1011 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001012 if (!(name in noDexTests)) {
1013 dependsOn "dex_example_${name}"
1014 def exampleOutputDir = file("build/test/examples/" + name);
1015 def dexPath = file("${exampleOutputDir}")
1016 def debug = (name == "throwing")
1017 if (!dexPath.exists()) {
1018 dexPath.mkdirs()
1019 }
1020 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1021 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1022 destination = dexPath
1023 debug = debug
1024 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001025 }
1026 }
1027}
1028
1029task buildSmali {
1030 def smaliDir = file("src/test/smali")
1031 smaliDir.eachDirRecurse() { dir ->
1032 def name = dir.getName();
1033 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1034 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1035 smaliOutputDir.mkdirs()
1036 outputs.dir smaliOutputDir
1037 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1038 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1039 def javaFiles = fileTree(dir: dir, include: '*.java')
1040 def destDir = smaliOutputDir;
1041 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1042 def intermediateFileName = "${name}-intermediate.dex";
1043 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1044 if (javaFiles.empty) {
1045 if (!smaliFiles.empty) {
1046 dependsOn "${taskName}_smali"
1047 task "${taskName}_smali"(type: smali.Smali) {
1048 source = smaliFiles
1049 destination = destFile
1050 }
1051 }
1052 } else {
1053 dependsOn "${taskName}_dexmerger"
1054 task "${taskName}_smali"(type: smali.Smali) {
1055 source = smaliFiles
1056 destination = intermediateFile
1057 }
1058 task "${taskName}_java"(type: JavaCompile) {
1059 source = javaFiles
1060 destinationDir destDir
1061 classpath = sourceSets.main.compileClasspath
1062 sourceCompatibility = JavaVersion.VERSION_1_7
1063 targetCompatibility = JavaVersion.VERSION_1_7
1064 options.compilerArgs += ["-Xlint:-options"]
1065 }
1066 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1067 archiveName = "Test.jar"
1068 destinationDir = destDir
1069 from fileTree(dir: destDir, include: 'Test.class')
1070 }
1071 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1072 source = fileTree(dir: destDir, include: 'Test.jar')
1073 destination = destDir
1074 }
1075 task "${taskName}_dexmerger"(
1076 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1077 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1078 destination = destFile
1079 }
1080 }
1081 }
1082}
1083
1084tasks.withType(Test) {
1085 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1086 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1087 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1088 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1089 forkEvery = 0
1090 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1091 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001092 if (project.hasProperty('disable_assertions')) {
1093 enableAssertions = false
1094 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001095}
1096
1097task buildPreNJdwpTestsJar(type: Jar) {
1098 baseName = 'jdwp-tests-preN'
1099 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1100 // Exclude the classes containing java8
1101 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1102 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1103 includeEmptyDirs = false
1104}
1105
Yohann Roussel126f6872017-08-03 16:25:32 +02001106task supportLibDir() {
1107 doLast {
1108 File dir = file("build/supportlibraries")
1109 dir.mkdir()
1110 }
1111}
1112
1113configurations.supportLibs.files.each { file ->
1114 if (file.getName().endsWith(".aar")) {
1115 def name = "extract_"+file.getName()
1116 task "${name}"(type: Copy) {
1117 dependsOn supportLibDir
1118 from zipTree(file)
1119 into "build/supportlibraries"
1120 eachFile { FileCopyDetails fcp ->
1121 if (fcp.relativePath.pathString.equals("classes.jar")) {
1122 // remap the file to the root with correct name
1123 fcp.relativePath = new RelativePath(true, file.getName().replace(".aar", ".jar"))
1124 } else {
1125 fcp.exclude()
1126 }
1127 }
1128 }
1129 }
1130}
1131
1132task supportLibList() {
1133 configurations.supportLibs.files.each {
1134 if (it.getName().endsWith(".aar")) {
1135 dependsOn "extract_"+it.getName()
1136 }
1137 }
1138 doLast {
Yohann Roussel630dfe12017-08-03 17:24:08 +02001139 file("build/generated").mkdir()
Yohann Roussel126f6872017-08-03 16:25:32 +02001140 def file = file("build/generated/supportlibraries.txt")
1141 file.createNewFile()
1142 file.text = ""
1143 configurations.supportLibs.files.each {
1144 if (it.getName().endsWith(".aar")) {
1145 def outName = it.getName().replace(".aar", ".jar")
1146 file.text += ("build/supportlibraries/"
1147 + outName + "\n")
1148 } else {
1149 file.text += (it.getPath() + "\n")
1150 }
1151 }
1152 }
1153}
1154
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001155task AospJarTest(type: Exec) {
1156 dependsOn CompatDx, downloadDeps
1157 def script = "tools/test_aosp_jar.py"
1158 inputs.file script
1159 commandLine "python", script, "--no-build"
1160 workingDir = projectDir
1161}
1162
Mads Ager418d1ca2017-05-22 09:35:49 +02001163test {
Yohann Roussel126f6872017-08-03 16:25:32 +02001164 dependsOn supportLibList
Mads Ager418d1ca2017-05-22 09:35:49 +02001165 testLogging.exceptionFormat = 'full'
1166 if (project.hasProperty('print_test_stdout')) {
1167 testLogging.showStandardStreams = true
1168 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001169 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001170 println "Running with non default vm: " + project.property('dex_vm')
1171 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001172 if (project.property('dex_vm').startsWith('4.4.4') ||
1173 project.property('dex_vm').startsWith('5.1.1') ||
1174 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001175 // R8 and D8 compute the dex file version number based on the input.
1176 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1177 // Therefore we skip the jack generated art tests with those art versions.
1178 exclude "com/android/tools/r8/art/jack/**"
1179 }
1180 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001181
Mads Ager418d1ca2017-05-22 09:35:49 +02001182 if (project.hasProperty('one_line_per_test')) {
1183 beforeTest { desc ->
1184 println "Start executing test ${desc.name} [${desc.className}]"
1185 }
1186 afterTest { desc, result ->
1187 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1188 }
1189 }
1190 if (project.hasProperty('no_internal')) {
1191 exclude "com/android/tools/r8/internal/**"
1192 }
1193 if (project.hasProperty('only_internal')) {
1194 include "com/android/tools/r8/internal/**"
1195 }
1196 if (project.hasProperty('tool')) {
1197 if (project.property('tool') == 'r8') {
1198 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001199 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001200 } else {
1201 assert(project.property('tool') == 'd8')
1202 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001203 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001204 }
1205 }
1206 if (!project.hasProperty('all_tests')) {
1207 exclude "com/android/tools/r8/art/dx/**"
1208 exclude "com/android/tools/r8/art/jack/**"
1209 }
1210 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1211 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001212 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001213 }
1214 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001215 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001216 }
1217 if (project.hasProperty('jctf_compile_only')) {
1218 println "JCTF: compiling only"
1219 systemProperty 'jctf_compile_only', '1'
1220 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001221 if (project.hasProperty('test_dir')) {
1222 systemProperty 'test_dir', project.property('test_dir')
1223 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001224 if (project.hasProperty('aosp_jar')) {
1225 dependsOn AospJarTest
1226 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001227
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001228 if (OperatingSystem.current().isLinux()
1229 || OperatingSystem.current().isMacOsX()
1230 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001231 if (OperatingSystem.current().isMacOsX()) {
1232 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1233 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1234 "See tools/docker/README.md for details.")
1235 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001236 if (OperatingSystem.current().isWindows()) {
1237 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1238 "Art only runs on Linux and tests requiring Art will be skipped")
1239 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001240 dependsOn downloadDeps
1241 dependsOn buildExamples
1242 dependsOn buildSmali
1243 dependsOn jctfCommonJar
1244 dependsOn jctfTestsClasses
1245 dependsOn buildDebugInfoExamplesDex
1246 dependsOn buildPreNJdwpTestsJar
1247 } else {
1248 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001249 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001250 }
1251}
1252
1253// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1254//
1255// To build and upload a new set of the Art tests for use with R8 follow these steps:
1256//
1257// First of all an Android checkout is required. Currently it must be located
1258// in $HOME/android/master.
1259//
1260// TODO(ricow): simplify this
1261//
1262// Before: update the checked in art, see scripts/update-host-art.sh
1263//
1264// 1. Get an android checkout in $HOME/android/master and apply the patch from
1265// https://android-review.googlesource.com/#/c/294187/
1266//
1267// 2. run the following commands in the Android checkout directory:
1268//
1269// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001270// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1271// m desugar
1272// m -j30 test-art-host
1273// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1274//
1275// Without running the test.py command the classes.jar file used by desugar in
1276// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1277// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001278//
1279// 3. In the R8 project root directory, make sure we have a clean state before starting:
1280// tools/gradle.py downloadDeps
1281// tools/gradle.py clean
1282// rm -rf tests/art
1283//
1284// 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 +02001285// Make sure you have smali on your path, please use the build binary in the
1286// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1287// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1288// 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 +02001289// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1290// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001291//
Søren Gjesse34b77732017-07-07 13:56:21 +02001292// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001293//
1294// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1295// skippedTests with an explanation. Rerun from step 3.
1296//
1297// 5. Run the tests:
1298// tools/gradle.py clean
1299// tools/test.py
1300//
Søren Gjesse34b77732017-07-07 13:56:21 +02001301// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1302// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1303// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001304//
Søren Gjesse34b77732017-07-07 13:56:21 +02001305// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001306// cd tests
1307// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001308//
1309// 7. Update the manifest file describing the Android repo used:
1310// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001311
1312enum DexTool {
1313 JACK,
1314 DX
1315}
1316
1317def androidCheckoutDir = file("${System.env.HOME}/android/master")
1318def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1319def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1320
1321def artTestDir = file("${androidCheckoutDir}/art/test")
1322
1323if (project.hasProperty('android_source')) {
1324 task buildArtTests {
1325 outputs.upToDateWhen { false }
1326 def toBeTriaged = [
1327 "903-hello-tagging",
1328 "904-object-allocation",
1329 "905-object-free",
1330 "906-iterate-heap",
1331 "907-get-loaded-classes",
1332 "908-gc-start-finish",
1333 "954-invoke-polymorphic-verifier",
1334 "955-methodhandles-smali",
1335 "596-monitor-inflation",
1336 ]
1337 def skippedTests = toBeTriaged + [
1338 // This test produces no jar.
1339 "000-nop",
1340 // This does not build, as it tests the error when the application exceeds more
1341 // than 65536 methods
1342 "089-many-methods",
1343 // Requires some jack beta jar
1344 "956-methodhandles",
1345 ]
1346
1347 def skippedTestsDx = [
1348 // Tests with custom build scripts, where javac is not passed the options
1349 // -source 1.7 -target 1.7.
1350 "462-checker-inlining-across-dex-files",
1351 "556-invoke-super",
1352 "569-checker-pattern-replacement",
1353 // These tests use jack even when --build-with-javac-dx is specified.
1354 "004-JniTest",
1355 "048-reflect-v8",
1356 "146-bad-interface",
1357 "563-checker-invoke-super",
1358 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1359 "604-hot-static-interface",
1360 "957-methodhandle-transforms",
1361 "958-methodhandle-emulated-stackframe",
1362 "959-invoke-polymorphic-accessors",
1363 "961-default-iface-resolution-gen",
1364 "962-iface-static",
1365 "963-default-range-smali",
1366 "964-default-iface-init-gen",
1367 "965-default-verify",
1368 "966-default-conflict",
1369 "967-default-ame",
1370 "968-default-partial-compile-gen",
1371 "969-iface-super",
1372 "970-iface-super-resolution-gen",
1373 "971-iface-super",
1374 // These tests does not build with --build-with-javac-dx
1375 "004-NativeAllocations", // Javac error
1376 "031-class-attributes",
1377 "138-duplicate-classes-check",
1378 "157-void-class", // Javac error
1379 "580-checker-string-factory-intrinsics",
1380 "612-jit-dex-cache",
1381 "613-inlining-dex-cache",
1382 "900-hello-plugin", // --experimental agents
1383 "901-hello-ti-agent", // --experimental agents
1384 "902-hello-transformation", // --experimental agents
1385 "909-attach-agent", // --experimental agents
1386 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1387 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1388 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1389 "960-default-smali", // --experimental default-methods
1390 // These tests force the build to use jack
1391 "953-invoke-polymorphic-compiler",
1392 "958-methodhandle-stackframe",
1393 ]
1394
1395 def artTestBuildDir = file("${projectDir}/tests/art")
1396
1397 if (androidCheckoutDir.exists()) {
1398 dependsOn downloadDeps
1399 artTestBuildDir.mkdirs()
1400 // Ensure Jack server is running.
1401 "${androidCheckoutJackServer} start-server".execute()
1402 artTestDir.eachDir { dir ->
1403 def name = dir.getName();
1404 def markerFile = dir.toPath().resolve("info.txt").toFile();
1405 if (markerFile.exists() && !(name in skippedTests)) {
1406 if (!(name in skippedTestsDx)) {
1407 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1408 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001409 // After Android O, Jack is no longer alive
1410 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001411 }
1412 }
1413 }
1414 doFirst {
1415 if (!androidCheckoutDir.exists()) {
1416 throw new InvalidUserDataException(
1417 "This task requires an Android checkout in ${androidCheckoutDir}");
1418 } else if (!androidCheckoutJack.exists() ||
1419 !androidCheckoutJackServer.exists()) {
1420 throw new InvalidUserDataException(
1421 "This task requires that tools for host testing have been build in the " +
1422 "Android checkout in ${androidCheckoutDir}");
1423 }
1424 }
1425 doLast {
1426 copy {
1427 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1428 into file("${artTestBuildDir}/lib64")
1429 include 'lib*.so'
1430 }
1431 copy {
1432 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1433 into file("${artTestBuildDir}/lib64")
1434 include 'libart.so'
1435 include 'libbacktrace.so'
1436 include 'libbase.so'
1437 include 'libc++.so'
1438 include 'libcutils.so'
1439 include 'liblz4.so'
1440 include 'liblzma.so'
1441 include 'libnativebridge.so'
1442 include 'libnativeloader.so'
1443 include 'libsigchain.so'
1444 include 'libunwind.so'
1445 include 'libziparchive.so'
1446 }
1447 copy {
1448 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1449 into file("${artTestBuildDir}/lib")
1450 include 'lib*.so'
1451 }
1452 copy {
1453 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1454 into file("${artTestBuildDir}/lib")
1455 include 'libart.so'
1456 include 'libbacktrace.so'
1457 include 'libbase.so'
1458 include 'libc++.so'
1459 include 'libcutils.so'
1460 include 'liblz4.so'
1461 include 'liblzma.so'
1462 include 'libnativebridge.so'
1463 include 'libnativeloader.so'
1464 include 'libsigchain.so'
1465 include 'libunwind.so'
1466 include 'libziparchive.so'
1467 }
1468 }
1469 }
1470}
1471
1472def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1473 def artTestDir = file("${androidCheckoutDir}/art/test")
1474 def artRunTestScript = file("${artTestDir}/run-test")
1475 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001476 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001477 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1478
Søren Gjesse34b77732017-07-07 13:56:21 +02001479 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001480 def buildTask = "build_art_test_${dexToolName}_${name}"
1481 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1482 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1483 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1484
1485 def buildInputs = fileTree(dir: dir, include: '**/*')
1486 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1487 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1488 testDir.mkdirs()
1489 if (dexTool == DexTool.DX) {
1490 task "$buildTask"(type: Exec) {
1491 outputs.upToDateWhen { false }
1492 inputs.file buildInputs
1493 executable "${artRunTestScript}"
1494 args "--host"
1495 args "--build-only"
1496 args "--build-with-javac-dx"
1497 args "--output-path", "${testDir}"
1498 args "${name}"
1499 environment DX: "${dxExecutable.absolutePath}"
1500 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001501 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001502 outputs.file outputJar
1503 }
1504 } else {
1505 assert dexTool == DexTool.JACK
1506 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1507 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1508 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1509 task "$buildTask"(type: Exec) {
1510 outputs.upToDateWhen { false }
1511 inputs.file buildInputs
1512 executable "${artRunTestScript}"
1513 args "--host"
1514 args "--build-only"
1515 args "--output-path", "${testDir}"
1516 args "${name}"
1517 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1518 environment JACK_CLASSPATH: jackClasspath
1519 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1520 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1521 outputs.file outputJar
1522 }
1523 }
1524 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1525 outputs.upToDateWhen { false }
1526 executable "/bin/bash"
1527 args "-c"
1528 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1529 " ${testDir}/classes-ex ${testDir}/check"
1530 }
1531
1532 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001533 // Directory that contains smali files is either smali, or smali/art
1534 def smali_dir = file("${dir}/smali/art")
1535 if (smali_dir.exists()) {
1536 workingDir "${testDir}/smali/art"
1537 } else {
1538 workingDir "${testDir}/smali"
1539 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001540 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001541 // This is the command line options for smali prior to 2.2.1, where smali got a new
1542 // command line interface.
1543 args "-c", "smali a *.smali"
1544 // This is the command line options for smali 2.2.1 and later.
1545 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001546 }
1547
1548 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1549 def smali_dir = file("${dir}/smali")
1550 outputs.upToDateWhen { false }
1551 if (smali_dir.exists() && dexTool == DexTool.DX) {
1552 dependsOn smaliToDexTask
1553 }
1554 from("${artTestDir}/${name}") {
1555 include 'check'
1556 }
1557 into testDir
1558 }
1559
1560 return copyCheckTask
1561}
1562
1563task javadocD8(type: Javadoc) {
1564 classpath = sourceSets.main.compileClasspath
1565 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001566 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001567 include '**/com/android/tools/r8/BaseCommand.java'
1568 include '**/com/android/tools/r8/BaseOutput.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001569 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001570 include '**/com/android/tools/r8/CompilationException.java'
1571 include '**/com/android/tools/r8/CompilationMode.java'
1572 include '**/com/android/tools/r8/D8.java'
1573 include '**/com/android/tools/r8/D8Command.java'
1574 include '**/com/android/tools/r8/D8Output.java'
1575 include '**/com/android/tools/r8/Resource.java'
1576}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001577
1578task copyMavenDeps(type: Copy) {
1579 from configurations.compile into "$buildDir/deps"
1580 from configurations.testCompile into "$buildDir/deps"
1581}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001582
1583// This task allows to build class files from Java 9 source in order to use them as inputs of
1584// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1585// to the D8 repository because there is no way to generate them on all computers due to the need of
1586// Java 9.
1587// Use the following command to rebuild class files of tests:
1588// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1589task buildJava9Tests {
1590 def javacOutputFolder = getTemporaryDir();
1591 def examplesDir = file("src/test/examplesJava9")
1592
1593 task "compile_Java9examples"(type: JavaCompile) {
1594 doFirst {
1595 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1596 throw new GradleException("Set java9Home property.")
1597 }
1598 }
1599
1600 source = fileTree(dir: examplesDir, include: '**/*.java')
1601 destinationDir = javacOutputFolder
1602 classpath = sourceSets.main.compileClasspath
1603 options.compilerArgs += ["-Xlint:-options"]
1604 sourceCompatibility = JavaVersion.VERSION_1_9
1605 targetCompatibility = JavaVersion.VERSION_1_9
1606 options.fork = true
1607
1608 if (project.hasProperty('java9Home')) {
1609 options.forkOptions.javaHome = file(getProperty('java9Home'))
1610 }
1611
1612 doLast {
1613 def classfileFrom = copySpec {
1614 from javacOutputFolder
1615 include "**/*.class"
1616 }
1617 copy {
1618 into examplesDir
1619 with classfileFrom
1620 }
1621 delete javacOutputFolder
1622 }
1623 }
1624
1625 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001626}