blob: c0a183bb4aaac30f3395dbea56ffdbf0f891a280 [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',
Stephan Herhut3d2cdde2017-10-24 15:56:12 +020024 '-Xep:IntLongMath:WARN',
Stephan Herhuteeae1e82017-10-25 13:59:55 +020025 '-Xep:EqualsHashCode:WARN',
Stephan Herhut6b06bfb2017-10-26 11:29:51 +020026 '-Xep:InconsistentOverloads:WARN',
Stephan Herhuteeae1e82017-10-25 13:59:55 +020027 '-Xep:ArrayHashCode:WARN',
28 '-Xep:EqualsIncompatibleType:WARN',
29 '-Xep:NonOverridingEquals:WARN',
30 '-Xep:FallThrough:WARN',
31 '-Xep:MissingCasesInEnumSwitch:WARN',
32 '-Xep:MissingDefault:WARN',
33 '-Xep:MultipleTopLevelClasses:WARN',
34 '-Xep:NarrowingCompoundAssignment:WARN',
35 '-Xep:BoxedPrimitiveConstructor:WARN']
Mads Ager418d1ca2017-05-22 09:35:49 +020036
37apply from: 'copyAdditionalJctfCommonFiles.gradle'
38
Sebastien Hertze2687b62017-07-25 11:16:04 +020039
40if (project.hasProperty('with_code_coverage')) {
41 apply plugin: 'jacoco'
42}
43
Mads Ager418d1ca2017-05-22 09:35:49 +020044repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020045 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020046 mavenCentral()
47}
48
Stephan Herhut417a72a2017-07-18 10:38:30 +020049buildscript {
50 repositories {
51 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020052 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020053 maven {
54 url "https://plugins.gradle.org/m2/"
55 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020056 }
57 dependencies {
58 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020059 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Mads Ager1d5ae402017-09-22 12:30:56 +020060 // TODO(ager): shadow does not support java9 class files yet. Once it does,
61 // we should use the offial version instead of our fork using ASM 6.0 to
62 // support java9.
63 // classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
64 classpath files("third_party/shadow/shadow-2.0.1.jar")
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020065 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020066 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Stephan Herhut417a72a2017-07-18 10:38:30 +020067 }
68}
69
Mads Ager418d1ca2017-05-22 09:35:49 +020070// Custom source set for example tests and generated tests.
71sourceSets {
72 test {
73 java {
74 srcDirs = [
75 'src/test/java',
76 'build/generated/test/java',
77 ]
78 }
79 }
Yohann Rousselbb571622017-11-09 10:47:36 +010080 apiUsageSample {
81 java {
82 srcDirs = ['src/test/apiUsageSample']
83 }
84 output.resourcesDir = 'build/classes/apiUsageSample'
85 }
Mads Ager418d1ca2017-05-22 09:35:49 +020086 debugTestResources {
87 java {
88 srcDirs = ['src/test/debugTestResources']
89 }
90 output.resourcesDir = 'build/classes/debugTestResources'
91 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020092 debugTestResourcesJava8 {
93 java {
94 srcDirs = ['src/test/debugTestResourcesJava8']
95 }
96 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
97 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +020098 debugTestResourcesKotlin {
99 java {
100 srcDirs = ['src/test/debugTestResourcesKotlin']
101 }
102 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
103 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200104 examples {
105 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +0200106 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
107 }
108 proto {
109 srcDirs = [
110 'src/test/examples',
111 ]
Mads Ager418d1ca2017-05-22 09:35:49 +0200112 }
113 output.resourcesDir = 'build/classes/examples'
114 }
115 examplesAndroidN {
116 java {
117 srcDirs = ['src/test/examplesAndroidN']
118 }
119 output.resourcesDir = 'build/classes/examplesAndroidN'
120 }
121 examplesAndroidO {
122 java {
123 srcDirs = ['src/test/examplesAndroidO']
124 }
125 output.resourcesDir = 'build/classes/examplesAndroidO'
126 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200127 examplesAndroidP {
128 java {
129 srcDirs = ['src/test/examplesAndroidP']
130 }
131 output.resourcesDir = 'build/classes/examplesAndroidP'
132 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200133 jctfCommon {
134 java {
135 srcDirs = [
136 'third_party/jctf/Harness/src',
137 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
138 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
139 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
140 'third_party/jctf/LibTests/src/org',
141 'build/additionalJctfCommonFiles'
142 ]
143 }
144 resources {
145 srcDirs = ['third_party/jctf/LibTests/resources']
146 }
147 }
148 jctfTests {
149 java {
150 srcDirs = [
151 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
152 // 'third_party/jctf/VMTests/src',
153 ]
154 }
155 }
156}
157
Yohann Roussel126f6872017-08-03 16:25:32 +0200158configurations {
159 supportLibs
160}
161
Mads Ager418d1ca2017-05-22 09:35:49 +0200162dependencies {
163 compile 'net.sf.jopt-simple:jopt-simple:4.6'
Mads Agercd06c802017-08-22 13:44:34 +0200164 compile 'com.googlecode.json-simple:json-simple:1.1'
Mads Ager0aa48052017-09-15 12:39:15 +0200165 // Include all of guava when compiling the code, but exclude annotations that we don't
166 // need from the packaging.
167 compileOnly('com.google.guava:guava:23.0')
168 compile('com.google.guava:guava:23.0', {
169 exclude group: 'com.google.errorprone'
170 exclude group: 'com.google.code.findbugs'
171 exclude group: 'com.google.j2objc'
172 exclude group: 'org.codehaus.mojo'
173 })
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200174 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200175 compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200176 compile group: 'org.ow2.asm', name: 'asm', version: '6.0'
177 compile group: 'org.ow2.asm', name: 'asm-commons', version: '6.0'
178 compile group: 'org.ow2.asm', name: 'asm-tree', version: '6.0'
Ian Zerny282ffa82017-10-30 12:19:02 +0100179 compile group: 'org.ow2.asm', name: 'asm-analysis', version: '6.0'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200180 compile group: 'org.ow2.asm', name: 'asm-util', version: '6.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200181 testCompile sourceSets.examples.output
182 testCompile 'junit:junit:4.12'
183 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
184 testCompile files('third_party/jasmin/jasmin-2.4.jar')
185 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200186 testCompile files('third_party/ddmlib/ddmlib.jar')
Mads Ager418d1ca2017-05-22 09:35:49 +0200187 jctfCommonCompile 'junit:junit:4.12'
188 jctfTestsCompile 'junit:junit:4.12'
189 jctfTestsCompile sourceSets.jctfCommon.output
Mikaël Peltier7345e482017-10-17 17:57:48 +0200190 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
191 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200192 // Import Guava for @Nullable annotation
193 examplesCompile 'com.google.guava:guava:23.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200194 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200195 examplesCompileOnly "com.google.auto.value:auto-value:1.5"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200196 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200197 supportLibs 'com.android.support:support-v4:25.4.0'
198 supportLibs 'junit:junit:4.12'
199 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Yohann Rousselbb571622017-11-09 10:47:36 +0100200 apiUsageSampleCompile sourceSets.main.output
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200201 debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200202 apt 'com.google.auto.value:auto-value:1.5'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200203}
204
Yohann Roussel7f47c032017-09-14 12:19:06 +0200205licenseTools {
206 licensesYaml = file('LIBRARY-LICENSE')
207}
208
Stephan Herhut417a72a2017-07-18 10:38:30 +0200209protobuf {
210 protoc {
211 // Download from repositories
212 artifact = 'com.google.protobuf:protoc:3.0.0'
213 }
214 plugins {
215 javalite {
216 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
217 }
218 }
219 generateProtoTasks {
220 all().each { task ->
221 task.builtins {
222 // Disable the java code generator, as we want javalite only.
223 remove java
224 }
225 task.plugins {
226 javalite {}
227 }
228 }
229 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200230}
231
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200232def osString = OperatingSystem.current().isLinux() ? "linux" :
233 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200234
235def cloudDependencies = [
236 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200237 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200238 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200239 ],
240 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200241 "android_jar/lib-v14",
242 "android_jar/lib-v19",
243 "android_jar/lib-v21",
244 "android_jar/lib-v24",
245 "android_jar/lib-v25",
246 "android_jar/lib-v26",
247 "proguard/proguard5.2.1",
248 "gradle/gradle",
249 "jdwp-tests",
250 "jasmin",
251 "jctf",
252 "kotlin",
253 "android_cts_baseline",
254 "shadow",
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200255 "ddmlib",
Mads Ager418d1ca2017-05-22 09:35:49 +0200256 ],
257 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
258 // container on other platforms where supported.
259 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200260 "linux/art",
261 "linux/art-5.1.1",
262 "linux/art-6.0.1",
263 "linux/art-7.0.0",
264 "linux/dalvik",
265 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200266 ]
267]
268
269cloudDependencies.each { entry ->
270 entry.value.each { entryFile ->
271 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200272 def outputDir = "${entry.key}/${entryFile}"
273 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200274 def sha1File = "${gzFile}.sha1"
275 inputs.file sha1File
276 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200277 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200278 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
279 if (OperatingSystem.current().isWindows()) {
280 executable "download_from_google_storage.bat"
281 args dlFromStorageArgs
282 } else {
283 executable "bash"
284 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
285 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200286 }
287 }
288}
289
290def x20Dependencies = [
291 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "gmail/gmail_android_170604.16",
293 "gmscore/v4",
294 "gmscore/v5",
295 "gmscore/v6",
296 "gmscore/v7",
297 "gmscore/v8",
298 "gmscore/gmscore_v9",
299 "gmscore/gmscore_v10",
300 "gmscore/latest",
301 "photos/2017-06-06",
302 "youtube/youtube.android_12.10",
303 "youtube/youtube.android_12.17",
304 "youtube/youtube.android_12.22",
305 "proguardsettings",
306 "proguard/proguard_internal_159423826",
307 "framework",
308 "goyt",
Mads Ager418d1ca2017-05-22 09:35:49 +0200309 ],
310]
311
312x20Dependencies.each { entry ->
313 entry.value.each { entryFile ->
314 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200315 def outputDir = "${entry.key}/${entryFile}"
316 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200317 def sha1File = "${gzFile}.sha1"
318 inputs.file sha1File
319 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200320 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200321 executable "bash"
322 args "-c", "tools/download_from_x20.py ${sha1File}"
323 }
324 }
325}
326
Rico Wind897bb712017-05-23 10:44:29 +0200327task downloadProguard {
328 cloudDependencies.each { entry ->
329 entry.value.each { entryFile ->
330 if (entryFile.contains("proguard")) {
331 dependsOn "download_deps_${entry.key}/${entryFile}"
332 }
333 }
334 }
335}
336
Tamas Kenez427205b2017-06-29 15:57:09 +0200337task downloadDx {
338 cloudDependencies.each { entry ->
339 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200340 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200341 dependsOn "download_deps_${entry.key}/${entryFile}"
342 }
343 }
344 }
345}
346
Tamas Kenez0e10c562017-06-08 10:00:34 +0200347task downloadAndroidCts {
348 cloudDependencies.each { entry ->
349 entry.value.each { entryFile ->
350 if (entryFile.contains("android_cts_baseline")) {
351 dependsOn "download_deps_${entry.key}/${entryFile}"
352 }
353 }
354 }
355}
356
Mads Ager418d1ca2017-05-22 09:35:49 +0200357task downloadDeps {
358 cloudDependencies.each { entry ->
359 entry.value.each { entryFile ->
360 dependsOn "download_deps_${entry.key}/${entryFile}"
361 }
362 }
363 if (!project.hasProperty('no_internal')) {
364 x20Dependencies.each { entry ->
365 entry.value.each { entryFile ->
366 dependsOn "download_deps_${entry.key}/${entryFile}"
367 }
368 }
369 }
370}
371
372allprojects {
373 sourceCompatibility = JavaVersion.VERSION_1_8
374 targetCompatibility = JavaVersion.VERSION_1_8
375}
376
377tasks.withType(JavaCompile) {
378 options.compilerArgs << '-Xlint:unchecked'
379}
380
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200381if (!project.hasProperty('without_error_prone')) {
382 compileJava {
383 // Enable error prone for D8/R8 sources.
384 toolChain ErrorProneToolChain.create(project)
385 options.compilerArgs += errorProneConfiguration
386 }
387}
388
Mads Ager418d1ca2017-05-22 09:35:49 +0200389compileJctfCommonJava {
390 dependsOn 'copyAdditionalJctfCommonFiles'
391 options.compilerArgs = ['-Xlint:none']
392}
393
394compileJctfTestsJava {
395 dependsOn 'jctfCommonClasses'
396 options.compilerArgs = ['-Xlint:none']
397}
398
Yohann Roussel7f47c032017-09-14 12:19:06 +0200399task consolidatedLicense {
400 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
401 // corresponding to the effective list of embedded libraries.
402 dependsOn 'checkLicenses'
403 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
404 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
405 outputs.files license
406 doLast {
407 license.getParentFile().mkdirs()
408 license.createNewFile()
409 license.text = "This file lists all licenses for code distributed.\n"
410 license.text += "All non-library code has the following 3-Clause BSD license.\n"
411 license.text += "\n"
412 license.text += "\n"
413 license.text += file('LICENSE').text
414 license.text += "\n"
415 license.text += "\n"
416 license.text += "Summary of distributed libraries:\n"
417 license.text += "\n"
418 license.text += file('LIBRARY-LICENSE').text
419 license.text += "\n"
420 license.text += "\n"
421 license.text += "Licenses details:\n"
422 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
423 license.text += "\n"
424 license.text += "\n"
425 license.text += file.text
426 }
427 }
428}
429
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200430task R8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200431 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200432 from consolidatedLicense.outputs.files
433 exclude { path ->
434 path.getRelativePath().getPathString().startsWith("META-INF")
435 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200436 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200437 classifier = null
438 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200439 manifest {
440 attributes 'Main-Class': 'com.android.tools.r8.R8'
441 }
442 // In order to build without dependencies, pass the exclude_deps property using:
443 // gradle -Pexclude_deps R8
444 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200445 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
446 // to avoid rewriting unrelated strings.
447 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
448 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200449 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200450 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
451 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200452 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200453 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200454 // Also include dependencies
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200455 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200456 }
457}
458
mikaelpeltier80939312017-08-17 15:00:09 +0200459task D8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200460 from sourceSets.main.output
Yohann Roussel7f47c032017-09-14 12:19:06 +0200461 from consolidatedLicense.outputs.files
462 exclude { path ->
463 path.getRelativePath().getPathString().startsWith("META-INF")
464 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200465 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200466 classifier = null
467 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200468 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200469 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200470 }
471 // In order to build without dependencies, pass the exclude_deps property using:
472 // gradle -Pexclude_deps D8
473 if (!project.hasProperty('exclude_deps')) {
Stephan Herhut93123ef2017-08-22 12:05:11 +0200474 // Relocating dependencies to avoid conflicts. Keep this as precise as possible
475 // to avoid rewriting unrelated strings.
476 relocate 'com.google.common', 'com.android.tools.r8.com.google.common'
477 relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty'
mikaelpeltier80939312017-08-17 15:00:09 +0200478 relocate 'joptsimple', 'com.android.tools.r8.joptsimple'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200479 relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons'
480 relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm'
Stephan Herhut93123ef2017-08-22 12:05:11 +0200481 relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple'
mikaelpeltier80939312017-08-17 15:00:09 +0200482 relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil'
Mads Ager418d1ca2017-05-22 09:35:49 +0200483 // Also include dependencies
mikaelpeltier80939312017-08-17 15:00:09 +0200484 configurations = [project.configurations.compile]
Mads Ager418d1ca2017-05-22 09:35:49 +0200485 }
486}
487
488task CompatDx(type: Jar) {
489 from sourceSets.main.output
490 baseName 'compatdx'
491 manifest {
492 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
493 }
494 // In order to build without dependencies, pass the exclude_deps property using:
495 // gradle -Pexclude_deps CompatDx
496 if (!project.hasProperty('exclude_deps')) {
497 // Also include dependencies
498 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
499 }
500}
501
Søren Gjesse1d21da72017-09-01 12:05:38 +0200502task CompatProguard(type: Jar) {
503 from sourceSets.main.output
504 baseName 'compatproguard'
505 manifest {
506 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
507 }
508 // In order to build without dependencies, pass the exclude_deps property using:
509 // gradle -Pexclude_deps CompatProguard
510 if (!project.hasProperty('exclude_deps')) {
511 // Also include dependencies
512 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
513 }
514}
515
Tamas Kenez971eec62017-05-24 11:08:40 +0200516task D8Logger(type: Jar) {
517 from sourceSets.main.output
518 baseName 'd8logger'
519 manifest {
520 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
521 }
522 // In order to build without dependencies, pass the exclude_deps property using:
523 // gradle -Pexclude_deps D8Logger
524 if (!project.hasProperty('exclude_deps')) {
525 // Also include dependencies
526 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
527 }
528}
529
Mads Ager418d1ca2017-05-22 09:35:49 +0200530task disasm(type: Jar) {
531 from sourceSets.main.output
532 baseName 'disasm'
533 manifest {
534 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
535 }
536 // In order to build without dependencies, pass the exclude_deps property using:
537 // gradle -Pexclude_deps D8
538 if (!project.hasProperty('exclude_deps')) {
539 // Also include dependencies
540 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
541 }
542}
543
544task bisect(type: Jar) {
545 from sourceSets.main.output
546 baseName 'bisect'
547 manifest {
548 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
549 }
550 // In order to build without dependencies, pass the exclude_deps property using:
551 // gradle -Pexclude_deps R8
552 if (!project.hasProperty('exclude_deps')) {
553 // Also include dependencies
554 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
555 }
556}
557
Lars Bak90c18042017-06-26 14:21:08 +0200558task DexSegments(type: Jar) {
559 from sourceSets.main.output
560 baseName 'dexsegments'
561 manifest {
562 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
563 }
564 // In order to build without dependencies, pass the exclude_deps property using:
565 // gradle -Pexclude_deps DexSegments
566 if (!project.hasProperty('exclude_deps')) {
567 // Also include dependencies
568 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
569 }
570}
571
Søren Gjessec4e5e932017-09-04 17:01:23 +0200572task maindex(type: Jar) {
573 from sourceSets.main.output
574 baseName 'maindex'
575 manifest {
576 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
577 }
578 // In order to build without dependencies, pass the exclude_deps property using:
579 // gradle -Pexclude_deps maindex
580 if (!project.hasProperty('exclude_deps')) {
581 // Also include dependencies
582 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
583 }
584}
585
Lars Bak44cef522017-08-10 16:02:39 +0200586task ExtractMarker(type: Jar) {
587 from sourceSets.main.output
588 baseName 'extractmarker'
589 manifest {
590 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
591 }
592 // In order to build without dependencies, pass the exclude_deps property using:
593 // gradle -Pexclude_deps ExtractMarker
594 if (!project.hasProperty('exclude_deps')) {
595 // Also include dependencies
596 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
597 }
598}
599
Mads Ager418d1ca2017-05-22 09:35:49 +0200600task sourceJar(type: Jar, dependsOn: classes) {
601 classifier = 'src'
602 from sourceSets.main.allSource
603}
604
605task jctfCommonJar(type: Jar) {
606 from sourceSets.jctfCommon.output
607 baseName 'jctfCommon'
608}
609
610artifacts {
611 archives sourceJar
612}
613
614task createArtTests(type: Exec) {
615 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200616 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200617 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200618 inputs.file createArtTestsScript
619 outputs.dir outputDir
620 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200621 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200622 workingDir = projectDir
623}
624
625task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200626 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200627 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200628 inputs.file script
629 outputs.dir outputDir
630 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200631 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200632 workingDir = projectDir
633}
634
635compileTestJava {
636 dependsOn createArtTests
637 dependsOn createJctfTests
638}
639
Yohann Rousselbb571622017-11-09 10:47:36 +0100640task buildApiUsageSample(type: Jar) {
641 from sourceSets.apiUsageSample.output
642 baseName 'api_usage_sample'
643 destinationDir file('tests')
644}
645
Mads Ager418d1ca2017-05-22 09:35:49 +0200646task buildDebugInfoExamplesDex {
647 def examplesDir = file("src/test/java")
648 def hostJar = "debuginfo_examples.jar"
649 def hostDexJar = "debuginfo_examples_dex.jar"
650 task "compile_debuginfo_examples"(type: JavaCompile) {
651 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
652 destinationDir = file("build/test/debuginfo_examples/classes")
653 classpath = sourceSets.main.compileClasspath
654 sourceCompatibility = JavaVersion.VERSION_1_7
655 targetCompatibility = JavaVersion.VERSION_1_7
656 options.compilerArgs += ["-Xlint:-options"]
657 }
658 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
659 archiveName = hostJar
660 destinationDir = file("build/test/")
661 from "build/test/debuginfo_examples/classes"
662 include "**/*.class"
663 }
664 task "dex_debuginfo_examples"(type: Exec,
665 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200666 if (OperatingSystem.current().isWindows()) {
667 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700668 } else if (OperatingSystem.current().isMacOsX()) {
669 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200670 } else {
671 executable file("tools/linux/dx/bin/dx");
672 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200673 args "--dex"
674 args "--output=build/test/${hostDexJar}"
675 args "build/test/${hostJar}"
676 inputs.file file("build/test/${hostJar}")
677 outputs.file file("build/test/${hostDexJar}")
678 }
679 dependsOn dex_debuginfo_examples
680}
681
682task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200683 def resourcesDir = file("src/test/debugTestResources")
684 def hostJar = "debug_test_resources.jar"
685 task "compile_debugTestResources"(type: JavaCompile) {
686 source = fileTree(dir: resourcesDir, include: '**/*.java')
687 destinationDir = file("build/test/debugTestResources/classes")
688 classpath = sourceSets.main.compileClasspath
689 sourceCompatibility = JavaVersion.VERSION_1_7
690 targetCompatibility = JavaVersion.VERSION_1_7
691 options.compilerArgs += ["-g", "-Xlint:-options"]
692 }
693 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
694 archiveName = hostJar
695 destinationDir = file("build/test/")
696 from "build/test/debugTestResources/classes"
697 include "**/*.class"
698 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200699 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
700 def java8HostJar = "debug_test_resources_java8.jar"
701 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
702 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
703 destinationDir = file("build/test/debugTestResourcesJava8/classes")
704 classpath = sourceSets.main.compileClasspath
705 sourceCompatibility = JavaVersion.VERSION_1_8
706 targetCompatibility = JavaVersion.VERSION_1_8
707 options.compilerArgs += ["-g", "-Xlint:-options"]
708 }
709 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
710 archiveName = java8HostJar
711 destinationDir = file("build/test/")
712 from "build/test/debugTestResourcesJava8/classes"
713 include "**/*.class"
714 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200715 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
716 def kotlinHostJar = "debug_test_resources_kotlin.jar"
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200717 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
718 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
719 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200720 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200721 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200722 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200723 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200724 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200725}
726
Lars Bakc91e87e2017-08-18 08:53:10 +0200727// Proto lite generated code yields warnings when compiling with javac.
728// We change the options passed to javac to ignore it.
729compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
730
Mads Ager418d1ca2017-05-22 09:35:49 +0200731task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200732 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200733 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200734 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200735 def proguardScript
736 if (OperatingSystem.current().isWindows()) {
737 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
738 } else {
739 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
740 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200741 task extractExamplesRuntime(type: Sync) {
742 dependsOn configurations.examplesRuntime
743 from configurations.examplesRuntime.collect { zipTree(it) }
744 include "**/*.class"
745 includeEmptyDirs false
746 into "$buildDir/runtime/examples/"
747 }
748
749 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
750 source examplesDir, protoSourceDir
751 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200752 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200753 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200754 sourceCompatibility = JavaVersion.VERSION_1_7
755 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200756 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
757 }
758 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
759 source examplesDir, protoSourceDir
760 include "**/*.java"
761 destinationDir = file("build/test/examples/classes_debuginfo_all")
762 classpath = sourceSets.examples.compileClasspath
763 sourceCompatibility = JavaVersion.VERSION_1_7
764 targetCompatibility = JavaVersion.VERSION_1_7
765 options.compilerArgs = ["-g", "-Xlint:none"]
766 }
767 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
768 source examplesDir, protoSourceDir
769 include "**/*.java"
770 destinationDir = file("build/test/examples/classes_debuginfo_none")
771 classpath = sourceSets.examples.compileClasspath
772 sourceCompatibility = JavaVersion.VERSION_1_7
773 targetCompatibility = JavaVersion.VERSION_1_7
774 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200775 }
776 examplesDir.eachDir { dir ->
777 def name = dir.getName();
778 def exampleOutputDir = file("build/test/examples");
779 def jarName = "${name}.jar"
780 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200781 dependsOn "jar_example_${name}_debuginfo_all"
782 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200783 dependsOn "extractExamplesRuntime"
784 def runtimeDependencies = copySpec { }
785 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
786 // If we have any proto use, we have to include those classes and the runtime.
787 runtimeDependencies = copySpec {
788 from "$buildDir/runtime/examples/"
789 include "com/google/protobuf/**/*.class"
790 }
791 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200792 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
793 def proguardConfigPath = "${dir}/proguard.cfg"
794 if (new File(proguardConfigPath).exists()) {
795 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
796 archiveName = "${name}_pre_proguard.jar"
797 destinationDir = exampleOutputDir
798 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200799 include name + "/**/*.class"
800 with runtimeDependencies
801 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200802 }
803 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
804 def proguardJarPath = "${exampleOutputDir}/${jarName}"
805 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
806 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
807 inputs.files tasks.getByPath("pre_proguard_example_${name}")
808 inputs.file proguardConfigPath
809 // Enable these to get stdout and stderr redirected to files...
810 // standardOutput = new FileOutputStream('proguard.stdout')
811 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200812 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200813 " -outjars ${proguardJarPath}" +
814 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200815 " -printmapping ${proguardMapPath}"
816 if (OperatingSystem.current().isWindows()) {
817 executable "${proguardScript}"
818 args "${proguardArguments}"
819 } else {
820 executable "bash"
821 args "-c", "${proguardScript} '${proguardArguments}'"
822 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200823 outputs.file proguardJarPath
824 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200825 // TODO: Consider performing distinct proguard compilations.
826 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
827 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200828 into "${exampleOutputDir}"
829 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200830 }
831 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
832 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200833 into "${exampleOutputDir}"
834 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200835 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200836 } else {
837 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200838 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200839 destinationDir = exampleOutputDir
840 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200841 include name + "/**/*.class"
842 with runtimeDependencies
843 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200844 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200845 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
846 archiveName = "${name}_debuginfo_all.jar"
847 destinationDir = exampleOutputDir
848 from "build/test/examples/classes_debuginfo_all"
849 include name + "/**/*.class"
850 with runtimeDependencies
851 includeEmptyDirs false
852 }
853 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
854 archiveName = "${name}_debuginfo_none.jar"
855 destinationDir = exampleOutputDir
856 from "build/test/examples/classes_debuginfo_none"
857 include name + "/**/*.class"
858 with runtimeDependencies
859 includeEmptyDirs false
860 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200861 }
862 }
863}
864
865task buildExampleAndroidNJars {
866 dependsOn downloadDeps
867 def examplesDir = file("src/test/examplesAndroidN")
868 task "compile_examplesAndroidN"(type: JavaCompile) {
869 source = fileTree(dir: examplesDir, include: '**/*.java')
870 destinationDir = file("build/test/examplesAndroidN/classes")
871 classpath = sourceSets.main.compileClasspath
872 sourceCompatibility = JavaVersion.VERSION_1_8
873 targetCompatibility = JavaVersion.VERSION_1_8
874 options.compilerArgs += ["-Xlint:-options"]
875 }
876 examplesDir.eachDir { dir ->
877 def name = dir.getName();
878 def exampleOutputDir = file("build/test/examplesAndroidN");
879 def jarName = "${name}.jar"
880 dependsOn "jar_examplesAndroidN_${name}"
881 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
882 archiveName = jarName
883 destinationDir = exampleOutputDir
884 from "build/test/examplesAndroidN/classes"
885 include "**/" + name + "/**/*.class"
886 }
887 }
888}
889
890
891task buildExampleAndroidOJars {
892 dependsOn downloadDeps
893 def examplesDir = file("src/test/examplesAndroidO")
894 // NOTE: we want to enable a scenario when test needs to reference some
895 // classes generated by legacy (1.6) Java compiler to test some specific
896 // behaviour. To do so we compile all the java files located in sub-directory
897 // called 'legacy' with Java 1.6, then compile the rest of the files with
898 // Java 1.8 and a reference to previously generated 1.6 classes.
899
900 // Compiling all classes in dirs 'legacy' with old Java version.
901 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
902 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
903 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
904 classpath = sourceSets.main.compileClasspath
905 sourceCompatibility = JavaVersion.VERSION_1_6
906 targetCompatibility = JavaVersion.VERSION_1_6
907 options.compilerArgs += ["-Xlint:-options", "-parameters"]
908 }
909 // Compiling the rest of the files as Java 1.8 code.
910 task "compile_examplesAndroidO"(type: JavaCompile) {
911 dependsOn "compile_examplesAndroidO_Legacy"
912 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
913 destinationDir = file("build/test/examplesAndroidO/classes")
914 classpath = sourceSets.main.compileClasspath
915 classpath += files("build/test/examplesAndroidOLegacy/classes")
916 sourceCompatibility = JavaVersion.VERSION_1_8
917 targetCompatibility = JavaVersion.VERSION_1_8
918 options.compilerArgs += ["-Xlint:-options", "-parameters"]
919 }
920 examplesDir.eachDir { dir ->
921 def name = dir.getName();
922 def destinationDir = file("build/test/examplesAndroidO/classes");
923 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
924 task "generate_examplesAndroidO_${name}"(type: JavaExec,
925 dependsOn: "compile_examplesAndroidO") {
926 main = name + ".TestGenerator"
927 classpath = files(destinationDir, sourceSets.main.compileClasspath)
928 args destinationDir
929 }
930 } else {
931 task "generate_examplesAndroidO_${name}" () {}
932 }
933 }
934 examplesDir.eachDir { dir ->
935 def name = dir.getName();
936 def exampleOutputDir = file("build/test/examplesAndroidO");
937 def jarName = "${name}.jar"
938 dependsOn "jar_examplesAndroidO_${name}"
939 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
940 "generate_examplesAndroidO_${name}"]) {
941 archiveName = jarName
942 destinationDir = exampleOutputDir
943 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
944 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
945 include "**/" + name + "/**/*.class"
946 // Do not include generator into the test runtime jar, it is not useful.
947 // Otherwise, shrinking will need ASM jars.
948 exclude "**/TestGenerator*"
949 }
950 }
951}
952
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200953task buildExampleAndroidPJars {
954 dependsOn downloadDeps
955 def examplesDir = file("src/test/examplesAndroidP")
956
957 task "compile_examplesAndroidP"(type: JavaCompile) {
958 source = fileTree(dir: examplesDir, include: '**/*.java')
959 destinationDir = file("build/test/examplesAndroidP/classes")
960 classpath = sourceSets.main.compileClasspath
961 sourceCompatibility = JavaVersion.VERSION_1_8
962 targetCompatibility = JavaVersion.VERSION_1_8
963 options.compilerArgs += ["-Xlint:-options"]
964 }
965 examplesDir.eachDir { dir ->
966 def name = dir.getName();
967 def destinationDir = file("build/test/examplesAndroidP/classes");
968 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
969 task "generate_examplesAndroidP_${name}"(type: JavaExec,
970 dependsOn: "compile_examplesAndroidP") {
971 main = name + ".TestGenerator"
972 classpath = files(destinationDir, sourceSets.main.compileClasspath)
973 args destinationDir
974 }
975 } else {
976 task "generate_examplesAndroidP_${name}" () {}
977 }
978 }
979 examplesDir.eachDir { dir ->
980 def name = dir.getName();
981 def exampleOutputDir = file("build/test/examplesAndroidP");
982 def jarName = "${name}.jar"
983 dependsOn "jar_examplesAndroidP_${name}"
984 task "jar_examplesAndroidP_${name}"(type: Jar,
985 dependsOn: ["compile_examplesAndroidP",
986 "generate_examplesAndroidP_${name}"]) {
987 archiveName = jarName
988 destinationDir = exampleOutputDir
989 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
990 include "**/" + name + "/**/*.class"
991 // Do not include generator into the test runtime jar, it is not useful.
992 // Otherwise, shrinking will need ASM jars.
993 exclude "**/TestGenerator*"
994 }
995 }
996}
997
Mikaël Peltier61633d42017-10-13 16:51:06 +0200998task buildExampleJava9Jars {
999 def examplesDir = file("src/test/examplesJava9")
1000 examplesDir.eachDir { dir ->
1001 def name = dir.getName();
1002 def exampleOutputDir = file("build/test/examplesJava9");
1003 def jarName = "${name}.jar"
1004 dependsOn "jar_examplesJava9_${name}"
1005 task "jar_examplesJava9_${name}"(type: Jar) {
1006 archiveName = jarName
1007 destinationDir = exampleOutputDir
1008 from "src/test/examplesJava9" // Java 1.9 classes
1009 include "**/" + name + "/**/*.class"
1010 }
1011 }
1012}
1013
Mads Ager418d1ca2017-05-22 09:35:49 +02001014task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001015 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1016 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1017 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001018 } else if (!OperatingSystem.current().isLinux()) {
1019 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001020 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001021 return;
1022 }
1023 dependsOn buildDebugTestResourcesJars
1024 dependsOn buildExampleJars
1025 dependsOn buildExampleAndroidNJars
1026 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001027 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001028 dependsOn buildExampleJava9Jars
Mads Ager418d1ca2017-05-22 09:35:49 +02001029 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001030 def noDexTests = [
1031 "multidex",
1032 "multidex002",
1033 "multidex004",
1034 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001035 examplesDir.eachDir { dir ->
1036 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001037 if (!(name in noDexTests)) {
1038 dependsOn "dex_example_${name}"
1039 def exampleOutputDir = file("build/test/examples/" + name);
1040 def dexPath = file("${exampleOutputDir}")
1041 def debug = (name == "throwing")
1042 if (!dexPath.exists()) {
1043 dexPath.mkdirs()
1044 }
1045 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1046 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1047 destination = dexPath
1048 debug = debug
1049 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001050 }
1051 }
1052}
1053
1054task buildSmali {
1055 def smaliDir = file("src/test/smali")
1056 smaliDir.eachDirRecurse() { dir ->
1057 def name = dir.getName();
1058 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1059 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1060 smaliOutputDir.mkdirs()
1061 outputs.dir smaliOutputDir
1062 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1063 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1064 def javaFiles = fileTree(dir: dir, include: '*.java')
1065 def destDir = smaliOutputDir;
1066 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1067 def intermediateFileName = "${name}-intermediate.dex";
1068 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1069 if (javaFiles.empty) {
1070 if (!smaliFiles.empty) {
1071 dependsOn "${taskName}_smali"
1072 task "${taskName}_smali"(type: smali.Smali) {
1073 source = smaliFiles
1074 destination = destFile
1075 }
1076 }
1077 } else {
1078 dependsOn "${taskName}_dexmerger"
1079 task "${taskName}_smali"(type: smali.Smali) {
1080 source = smaliFiles
1081 destination = intermediateFile
1082 }
1083 task "${taskName}_java"(type: JavaCompile) {
1084 source = javaFiles
1085 destinationDir destDir
1086 classpath = sourceSets.main.compileClasspath
1087 sourceCompatibility = JavaVersion.VERSION_1_7
1088 targetCompatibility = JavaVersion.VERSION_1_7
1089 options.compilerArgs += ["-Xlint:-options"]
1090 }
1091 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1092 archiveName = "Test.jar"
1093 destinationDir = destDir
1094 from fileTree(dir: destDir, include: 'Test.class')
1095 }
1096 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1097 source = fileTree(dir: destDir, include: 'Test.jar')
1098 destination = destDir
1099 }
1100 task "${taskName}_dexmerger"(
1101 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1102 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1103 destination = destFile
1104 }
1105 }
1106 }
1107}
1108
1109tasks.withType(Test) {
1110 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1111 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1112 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1113 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1114 forkEvery = 0
1115 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1116 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001117 if (project.hasProperty('disable_assertions')) {
1118 enableAssertions = false
1119 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001120}
1121
1122task buildPreNJdwpTestsJar(type: Jar) {
1123 baseName = 'jdwp-tests-preN'
1124 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1125 // Exclude the classes containing java8
1126 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1127 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1128 includeEmptyDirs = false
1129}
1130
Yohann Roussel126f6872017-08-03 16:25:32 +02001131task supportLibDir() {
1132 doLast {
1133 File dir = file("build/supportlibraries")
1134 dir.mkdir()
1135 }
1136}
1137
1138configurations.supportLibs.files.each { file ->
1139 if (file.getName().endsWith(".aar")) {
1140 def name = "extract_"+file.getName()
1141 task "${name}"(type: Copy) {
1142 dependsOn supportLibDir
1143 from zipTree(file)
1144 into "build/supportlibraries"
1145 eachFile { FileCopyDetails fcp ->
1146 if (fcp.relativePath.pathString.equals("classes.jar")) {
1147 // remap the file to the root with correct name
1148 fcp.relativePath = new RelativePath(true, file.getName().replace(".aar", ".jar"))
1149 } else {
1150 fcp.exclude()
1151 }
1152 }
1153 }
1154 }
1155}
1156
1157task supportLibList() {
1158 configurations.supportLibs.files.each {
1159 if (it.getName().endsWith(".aar")) {
1160 dependsOn "extract_"+it.getName()
1161 }
1162 }
1163 doLast {
Yohann Roussel630dfe12017-08-03 17:24:08 +02001164 file("build/generated").mkdir()
Yohann Roussel126f6872017-08-03 16:25:32 +02001165 def file = file("build/generated/supportlibraries.txt")
1166 file.createNewFile()
1167 file.text = ""
1168 configurations.supportLibs.files.each {
1169 if (it.getName().endsWith(".aar")) {
1170 def outName = it.getName().replace(".aar", ".jar")
1171 file.text += ("build/supportlibraries/"
1172 + outName + "\n")
1173 } else {
1174 file.text += (it.getPath() + "\n")
1175 }
1176 }
1177 }
1178}
1179
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001180task AospJarTest(type: Exec) {
1181 dependsOn CompatDx, downloadDeps
1182 def script = "tools/test_aosp_jar.py"
1183 inputs.file script
1184 commandLine "python", script, "--no-build"
1185 workingDir = projectDir
1186}
1187
Mads Ager418d1ca2017-05-22 09:35:49 +02001188test {
Yohann Roussel126f6872017-08-03 16:25:32 +02001189 dependsOn supportLibList
Mads Ager418d1ca2017-05-22 09:35:49 +02001190 testLogging.exceptionFormat = 'full'
1191 if (project.hasProperty('print_test_stdout')) {
1192 testLogging.showStandardStreams = true
1193 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001194 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001195 println "Running with non default vm: " + project.property('dex_vm')
1196 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001197 if (project.property('dex_vm').startsWith('4.4.4') ||
1198 project.property('dex_vm').startsWith('5.1.1') ||
1199 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001200 // R8 and D8 compute the dex file version number based on the input.
1201 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1202 // Therefore we skip the jack generated art tests with those art versions.
1203 exclude "com/android/tools/r8/art/jack/**"
1204 }
1205 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001206
Mads Ager418d1ca2017-05-22 09:35:49 +02001207 if (project.hasProperty('one_line_per_test')) {
1208 beforeTest { desc ->
1209 println "Start executing test ${desc.name} [${desc.className}]"
1210 }
1211 afterTest { desc, result ->
1212 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1213 }
1214 }
1215 if (project.hasProperty('no_internal')) {
1216 exclude "com/android/tools/r8/internal/**"
1217 }
1218 if (project.hasProperty('only_internal')) {
1219 include "com/android/tools/r8/internal/**"
1220 }
1221 if (project.hasProperty('tool')) {
1222 if (project.property('tool') == 'r8') {
1223 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001224 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001225 } else {
1226 assert(project.property('tool') == 'd8')
1227 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001228 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001229 }
1230 }
1231 if (!project.hasProperty('all_tests')) {
1232 exclude "com/android/tools/r8/art/dx/**"
1233 exclude "com/android/tools/r8/art/jack/**"
1234 }
1235 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1236 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001237 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001238 }
1239 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001240 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001241 }
1242 if (project.hasProperty('jctf_compile_only')) {
1243 println "JCTF: compiling only"
1244 systemProperty 'jctf_compile_only', '1'
1245 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001246 if (project.hasProperty('test_dir')) {
1247 systemProperty 'test_dir', project.property('test_dir')
1248 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001249 if (project.hasProperty('aosp_jar')) {
1250 dependsOn AospJarTest
1251 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001252
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001253 if (OperatingSystem.current().isLinux()
1254 || OperatingSystem.current().isMacOsX()
1255 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001256 if (OperatingSystem.current().isMacOsX()) {
1257 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1258 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1259 "See tools/docker/README.md for details.")
1260 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001261 if (OperatingSystem.current().isWindows()) {
1262 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1263 "Art only runs on Linux and tests requiring Art will be skipped")
1264 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001265 dependsOn downloadDeps
1266 dependsOn buildExamples
1267 dependsOn buildSmali
1268 dependsOn jctfCommonJar
1269 dependsOn jctfTestsClasses
1270 dependsOn buildDebugInfoExamplesDex
1271 dependsOn buildPreNJdwpTestsJar
1272 } else {
1273 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001274 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001275 }
1276}
1277
1278// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1279//
1280// To build and upload a new set of the Art tests for use with R8 follow these steps:
1281//
1282// First of all an Android checkout is required. Currently it must be located
1283// in $HOME/android/master.
1284//
1285// TODO(ricow): simplify this
1286//
1287// Before: update the checked in art, see scripts/update-host-art.sh
1288//
1289// 1. Get an android checkout in $HOME/android/master and apply the patch from
1290// https://android-review.googlesource.com/#/c/294187/
1291//
1292// 2. run the following commands in the Android checkout directory:
1293//
1294// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001295// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1296// m desugar
1297// m -j30 test-art-host
1298// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1299//
1300// Without running the test.py command the classes.jar file used by desugar in
1301// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1302// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001303//
1304// 3. In the R8 project root directory, make sure we have a clean state before starting:
1305// tools/gradle.py downloadDeps
1306// tools/gradle.py clean
1307// rm -rf tests/art
1308//
1309// 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 +02001310// Make sure you have smali on your path, please use the build binary in the
1311// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1312// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1313// 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 +02001314// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1315// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001316//
Søren Gjesse34b77732017-07-07 13:56:21 +02001317// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001318//
1319// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1320// skippedTests with an explanation. Rerun from step 3.
1321//
1322// 5. Run the tests:
1323// tools/gradle.py clean
1324// tools/test.py
1325//
Søren Gjesse34b77732017-07-07 13:56:21 +02001326// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1327// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1328// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001329//
Søren Gjesse34b77732017-07-07 13:56:21 +02001330// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001331// cd tests
1332// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001333//
1334// 7. Update the manifest file describing the Android repo used:
1335// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001336
1337enum DexTool {
1338 JACK,
1339 DX
1340}
1341
1342def androidCheckoutDir = file("${System.env.HOME}/android/master")
1343def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1344def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1345
1346def artTestDir = file("${androidCheckoutDir}/art/test")
1347
1348if (project.hasProperty('android_source')) {
1349 task buildArtTests {
1350 outputs.upToDateWhen { false }
1351 def toBeTriaged = [
1352 "903-hello-tagging",
1353 "904-object-allocation",
1354 "905-object-free",
1355 "906-iterate-heap",
1356 "907-get-loaded-classes",
1357 "908-gc-start-finish",
1358 "954-invoke-polymorphic-verifier",
1359 "955-methodhandles-smali",
1360 "596-monitor-inflation",
1361 ]
1362 def skippedTests = toBeTriaged + [
1363 // This test produces no jar.
1364 "000-nop",
1365 // This does not build, as it tests the error when the application exceeds more
1366 // than 65536 methods
1367 "089-many-methods",
1368 // Requires some jack beta jar
1369 "956-methodhandles",
1370 ]
1371
1372 def skippedTestsDx = [
1373 // Tests with custom build scripts, where javac is not passed the options
1374 // -source 1.7 -target 1.7.
1375 "462-checker-inlining-across-dex-files",
1376 "556-invoke-super",
1377 "569-checker-pattern-replacement",
1378 // These tests use jack even when --build-with-javac-dx is specified.
1379 "004-JniTest",
1380 "048-reflect-v8",
1381 "146-bad-interface",
1382 "563-checker-invoke-super",
1383 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1384 "604-hot-static-interface",
1385 "957-methodhandle-transforms",
1386 "958-methodhandle-emulated-stackframe",
1387 "959-invoke-polymorphic-accessors",
1388 "961-default-iface-resolution-gen",
1389 "962-iface-static",
1390 "963-default-range-smali",
1391 "964-default-iface-init-gen",
1392 "965-default-verify",
1393 "966-default-conflict",
1394 "967-default-ame",
1395 "968-default-partial-compile-gen",
1396 "969-iface-super",
1397 "970-iface-super-resolution-gen",
1398 "971-iface-super",
1399 // These tests does not build with --build-with-javac-dx
1400 "004-NativeAllocations", // Javac error
1401 "031-class-attributes",
1402 "138-duplicate-classes-check",
1403 "157-void-class", // Javac error
1404 "580-checker-string-factory-intrinsics",
1405 "612-jit-dex-cache",
1406 "613-inlining-dex-cache",
1407 "900-hello-plugin", // --experimental agents
1408 "901-hello-ti-agent", // --experimental agents
1409 "902-hello-transformation", // --experimental agents
1410 "909-attach-agent", // --experimental agents
1411 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1412 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1413 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1414 "960-default-smali", // --experimental default-methods
1415 // These tests force the build to use jack
1416 "953-invoke-polymorphic-compiler",
1417 "958-methodhandle-stackframe",
1418 ]
1419
1420 def artTestBuildDir = file("${projectDir}/tests/art")
1421
1422 if (androidCheckoutDir.exists()) {
1423 dependsOn downloadDeps
1424 artTestBuildDir.mkdirs()
1425 // Ensure Jack server is running.
1426 "${androidCheckoutJackServer} start-server".execute()
1427 artTestDir.eachDir { dir ->
1428 def name = dir.getName();
1429 def markerFile = dir.toPath().resolve("info.txt").toFile();
1430 if (markerFile.exists() && !(name in skippedTests)) {
1431 if (!(name in skippedTestsDx)) {
1432 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1433 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001434 // After Android O, Jack is no longer alive
1435 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001436 }
1437 }
1438 }
1439 doFirst {
1440 if (!androidCheckoutDir.exists()) {
1441 throw new InvalidUserDataException(
1442 "This task requires an Android checkout in ${androidCheckoutDir}");
1443 } else if (!androidCheckoutJack.exists() ||
1444 !androidCheckoutJackServer.exists()) {
1445 throw new InvalidUserDataException(
1446 "This task requires that tools for host testing have been build in the " +
1447 "Android checkout in ${androidCheckoutDir}");
1448 }
1449 }
1450 doLast {
1451 copy {
1452 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1453 into file("${artTestBuildDir}/lib64")
1454 include 'lib*.so'
1455 }
1456 copy {
1457 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1458 into file("${artTestBuildDir}/lib64")
1459 include 'libart.so'
1460 include 'libbacktrace.so'
1461 include 'libbase.so'
1462 include 'libc++.so'
1463 include 'libcutils.so'
1464 include 'liblz4.so'
1465 include 'liblzma.so'
1466 include 'libnativebridge.so'
1467 include 'libnativeloader.so'
1468 include 'libsigchain.so'
1469 include 'libunwind.so'
1470 include 'libziparchive.so'
1471 }
1472 copy {
1473 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1474 into file("${artTestBuildDir}/lib")
1475 include 'lib*.so'
1476 }
1477 copy {
1478 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1479 into file("${artTestBuildDir}/lib")
1480 include 'libart.so'
1481 include 'libbacktrace.so'
1482 include 'libbase.so'
1483 include 'libc++.so'
1484 include 'libcutils.so'
1485 include 'liblz4.so'
1486 include 'liblzma.so'
1487 include 'libnativebridge.so'
1488 include 'libnativeloader.so'
1489 include 'libsigchain.so'
1490 include 'libunwind.so'
1491 include 'libziparchive.so'
1492 }
1493 }
1494 }
1495}
1496
1497def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1498 def artTestDir = file("${androidCheckoutDir}/art/test")
1499 def artRunTestScript = file("${artTestDir}/run-test")
1500 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001501 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001502 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1503
Søren Gjesse34b77732017-07-07 13:56:21 +02001504 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001505 def buildTask = "build_art_test_${dexToolName}_${name}"
1506 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1507 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1508 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1509
1510 def buildInputs = fileTree(dir: dir, include: '**/*')
1511 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1512 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1513 testDir.mkdirs()
1514 if (dexTool == DexTool.DX) {
1515 task "$buildTask"(type: Exec) {
1516 outputs.upToDateWhen { false }
1517 inputs.file buildInputs
1518 executable "${artRunTestScript}"
1519 args "--host"
1520 args "--build-only"
1521 args "--build-with-javac-dx"
1522 args "--output-path", "${testDir}"
1523 args "${name}"
1524 environment DX: "${dxExecutable.absolutePath}"
1525 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001526 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001527 outputs.file outputJar
1528 }
1529 } else {
1530 assert dexTool == DexTool.JACK
1531 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1532 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1533 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1534 task "$buildTask"(type: Exec) {
1535 outputs.upToDateWhen { false }
1536 inputs.file buildInputs
1537 executable "${artRunTestScript}"
1538 args "--host"
1539 args "--build-only"
1540 args "--output-path", "${testDir}"
1541 args "${name}"
1542 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1543 environment JACK_CLASSPATH: jackClasspath
1544 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1545 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1546 outputs.file outputJar
1547 }
1548 }
1549 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1550 outputs.upToDateWhen { false }
1551 executable "/bin/bash"
1552 args "-c"
1553 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1554 " ${testDir}/classes-ex ${testDir}/check"
1555 }
1556
1557 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001558 // Directory that contains smali files is either smali, or smali/art
1559 def smali_dir = file("${dir}/smali/art")
1560 if (smali_dir.exists()) {
1561 workingDir "${testDir}/smali/art"
1562 } else {
1563 workingDir "${testDir}/smali"
1564 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001565 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001566 // This is the command line options for smali prior to 2.2.1, where smali got a new
1567 // command line interface.
1568 args "-c", "smali a *.smali"
1569 // This is the command line options for smali 2.2.1 and later.
1570 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001571 }
1572
1573 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1574 def smali_dir = file("${dir}/smali")
1575 outputs.upToDateWhen { false }
1576 if (smali_dir.exists() && dexTool == DexTool.DX) {
1577 dependsOn smaliToDexTask
1578 }
1579 from("${artTestDir}/${name}") {
1580 include 'check'
1581 }
1582 into testDir
1583 }
1584
1585 return copyCheckTask
1586}
1587
1588task javadocD8(type: Javadoc) {
1589 classpath = sourceSets.main.compileClasspath
1590 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001591 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001592 include '**/com/android/tools/r8/BaseCommand.java'
1593 include '**/com/android/tools/r8/BaseOutput.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001594 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001595 include '**/com/android/tools/r8/CompilationException.java'
1596 include '**/com/android/tools/r8/CompilationMode.java'
1597 include '**/com/android/tools/r8/D8.java'
1598 include '**/com/android/tools/r8/D8Command.java'
1599 include '**/com/android/tools/r8/D8Output.java'
1600 include '**/com/android/tools/r8/Resource.java'
1601}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001602
1603task copyMavenDeps(type: Copy) {
1604 from configurations.compile into "$buildDir/deps"
1605 from configurations.testCompile into "$buildDir/deps"
1606}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001607
1608// This task allows to build class files from Java 9 source in order to use them as inputs of
1609// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1610// to the D8 repository because there is no way to generate them on all computers due to the need of
1611// Java 9.
1612// Use the following command to rebuild class files of tests:
1613// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1614task buildJava9Tests {
1615 def javacOutputFolder = getTemporaryDir();
1616 def examplesDir = file("src/test/examplesJava9")
1617
1618 task "compile_Java9examples"(type: JavaCompile) {
1619 doFirst {
1620 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1621 throw new GradleException("Set java9Home property.")
1622 }
1623 }
1624
1625 source = fileTree(dir: examplesDir, include: '**/*.java')
1626 destinationDir = javacOutputFolder
1627 classpath = sourceSets.main.compileClasspath
1628 options.compilerArgs += ["-Xlint:-options"]
1629 sourceCompatibility = JavaVersion.VERSION_1_9
1630 targetCompatibility = JavaVersion.VERSION_1_9
1631 options.fork = true
1632
1633 if (project.hasProperty('java9Home')) {
1634 options.forkOptions.javaHome = file(getProperty('java9Home'))
1635 }
1636
1637 doLast {
1638 def classfileFrom = copySpec {
1639 from javacOutputFolder
1640 include "**/*.class"
1641 }
1642 copy {
1643 into examplesDir
1644 with classfileFrom
1645 }
1646 delete javacOutputFolder
1647 }
1648 }
1649
1650 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001651}