blob: 7672b729e83d153845dba22ffcca27e6d11c0f8e [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +00004import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +02005import net.ltgt.gradle.errorprone.ErrorProneToolChain
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02006import org.gradle.internal.os.OperatingSystem
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00007import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +02008import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +02009
10apply plugin: 'java'
11apply plugin: 'idea'
Stephan Herhut417a72a2017-07-18 10:38:30 +020012apply plugin: 'com.google.protobuf'
Yohann Roussel7f47c032017-09-14 12:19:06 +020013apply plugin: 'com.cookpad.android.licensetools'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020014apply plugin: 'net.ltgt.errorprone-base'
Stephan Herhut52cb1022017-10-24 15:10:41 +020015apply plugin: "net.ltgt.apt"
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020016
Søren Gjessed4bdd042017-11-23 11:44:50 +010017// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
18// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
19// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
20// for context.
21idea {
22 module {
23 outputDir file('build/classes/main')
24 testOutputDir file('build/classes/test')
25 }
26}
27
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020028def errorProneConfiguration = [
29 '-XepDisableAllChecks',
30 // D8 want to use reference equality, thus disable the checker explicitly
31 '-Xep:ReferenceEquality:OFF',
Stephan Herhute4d101c2017-11-22 12:18:02 +010032 '-Xep:ClassCanBeStatic:ERROR',
33 '-Xep:OperatorPrecedence:ERROR',
34 '-Xep:RemoveUnusedImports:ERROR',
35 '-Xep:MissingOverride:ERROR',
Stephan Herhute4d101c2017-11-22 12:18:02 +010036 '-Xep:IntLongMath:ERROR',
37 '-Xep:EqualsHashCode:ERROR',
38 '-Xep:InconsistentOverloads:ERROR',
39 '-Xep:ArrayHashCode:ERROR',
40 '-Xep:EqualsIncompatibleType:ERROR',
41 '-Xep:NonOverridingEquals:ERROR',
42 '-Xep:FallThrough:ERROR',
43 '-Xep:MissingCasesInEnumSwitch:ERROR',
44 '-Xep:MissingDefault:ERROR',
45 '-Xep:MultipleTopLevelClasses:ERROR',
46 '-Xep:NarrowingCompoundAssignment:ERROR',
47 '-Xep:BoxedPrimitiveConstructor:ERROR']
Mads Ager418d1ca2017-05-22 09:35:49 +020048
49apply from: 'copyAdditionalJctfCommonFiles.gradle'
50
Sebastien Hertze2687b62017-07-25 11:16:04 +020051
52if (project.hasProperty('with_code_coverage')) {
53 apply plugin: 'jacoco'
54}
55
Mads Ager418d1ca2017-05-22 09:35:49 +020056repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020057 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020058 mavenCentral()
59}
60
Stephan Herhut417a72a2017-07-18 10:38:30 +020061buildscript {
62 repositories {
63 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020064 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020065 maven {
66 url "https://plugins.gradle.org/m2/"
67 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020068 }
69 dependencies {
70 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020071 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Mads Ager1d5ae402017-09-22 12:30:56 +020072 // TODO(ager): shadow does not support java9 class files yet. Once it does,
73 // we should use the offial version instead of our fork using ASM 6.0 to
74 // support java9.
75 // classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
76 classpath files("third_party/shadow/shadow-2.0.1.jar")
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020077 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020078 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Stephan Herhut417a72a2017-07-18 10:38:30 +020079 }
80}
81
Mads Ager418d1ca2017-05-22 09:35:49 +020082// Custom source set for example tests and generated tests.
83sourceSets {
84 test {
85 java {
86 srcDirs = [
87 'src/test/java',
88 'build/generated/test/java',
89 ]
90 }
91 }
Mads Ager22847672017-11-14 09:59:26 +010092 bsPatch {
93 java {
94 srcDirs = [
95 'src/bspatch/java',
96 'src/main/java'
97 ]
98 }
99 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100100 apiUsageSample {
101 java {
102 srcDirs = ['src/test/apiUsageSample']
103 }
104 output.resourcesDir = 'build/classes/apiUsageSample'
105 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200106 debugTestResources {
107 java {
108 srcDirs = ['src/test/debugTestResources']
109 }
110 output.resourcesDir = 'build/classes/debugTestResources'
111 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200112 debugTestResourcesJava8 {
113 java {
114 srcDirs = ['src/test/debugTestResourcesJava8']
115 }
116 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
117 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200118 debugTestResourcesKotlin {
119 java {
120 srcDirs = ['src/test/debugTestResourcesKotlin']
121 }
122 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
123 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200124 examples {
125 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +0200126 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
127 }
128 proto {
129 srcDirs = [
130 'src/test/examples',
131 ]
Mads Ager418d1ca2017-05-22 09:35:49 +0200132 }
133 output.resourcesDir = 'build/classes/examples'
134 }
135 examplesAndroidN {
136 java {
137 srcDirs = ['src/test/examplesAndroidN']
138 }
139 output.resourcesDir = 'build/classes/examplesAndroidN'
140 }
141 examplesAndroidO {
142 java {
143 srcDirs = ['src/test/examplesAndroidO']
144 }
145 output.resourcesDir = 'build/classes/examplesAndroidO'
146 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200147 examplesAndroidP {
148 java {
149 srcDirs = ['src/test/examplesAndroidP']
150 }
151 output.resourcesDir = 'build/classes/examplesAndroidP'
152 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200153 jctfCommon {
154 java {
155 srcDirs = [
156 'third_party/jctf/Harness/src',
157 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
158 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
159 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
160 'third_party/jctf/LibTests/src/org',
161 'build/additionalJctfCommonFiles'
162 ]
163 }
164 resources {
165 srcDirs = ['third_party/jctf/LibTests/resources']
166 }
167 }
168 jctfTests {
169 java {
170 srcDirs = [
171 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
172 // 'third_party/jctf/VMTests/src',
173 ]
174 }
175 }
176}
177
Yohann Roussel126f6872017-08-03 16:25:32 +0200178configurations {
179 supportLibs
180}
181
Mads Ager418d1ca2017-05-22 09:35:49 +0200182dependencies {
183 compile 'net.sf.jopt-simple:jopt-simple:4.6'
Mads Agercd06c802017-08-22 13:44:34 +0200184 compile 'com.googlecode.json-simple:json-simple:1.1'
Mads Ager0aa48052017-09-15 12:39:15 +0200185 // Include all of guava when compiling the code, but exclude annotations that we don't
186 // need from the packaging.
187 compileOnly('com.google.guava:guava:23.0')
188 compile('com.google.guava:guava:23.0', {
189 exclude group: 'com.google.errorprone'
190 exclude group: 'com.google.code.findbugs'
191 exclude group: 'com.google.j2objc'
192 exclude group: 'org.codehaus.mojo'
193 })
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200194 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200195 compile group: 'org.ow2.asm', name: 'asm', version: '6.0'
196 compile group: 'org.ow2.asm', name: 'asm-commons', version: '6.0'
197 compile group: 'org.ow2.asm', name: 'asm-tree', version: '6.0'
Ian Zerny282ffa82017-10-30 12:19:02 +0100198 compile group: 'org.ow2.asm', name: 'asm-analysis', version: '6.0'
Mikaël Peltier7345e482017-10-17 17:57:48 +0200199 compile group: 'org.ow2.asm', name: 'asm-util', version: '6.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200200 testCompile sourceSets.examples.output
201 testCompile 'junit:junit:4.12'
202 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
203 testCompile files('third_party/jasmin/jasmin-2.4.jar')
204 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200205 testCompile files('third_party/ddmlib/ddmlib.jar')
Mads Ager22847672017-11-14 09:59:26 +0100206 bsPatchCompile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
Mads Ager418d1ca2017-05-22 09:35:49 +0200207 jctfCommonCompile 'junit:junit:4.12'
208 jctfTestsCompile 'junit:junit:4.12'
209 jctfTestsCompile sourceSets.jctfCommon.output
Mikaël Peltier7345e482017-10-17 17:57:48 +0200210 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
211 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: '6.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200212 // Import Guava for @Nullable annotation
213 examplesCompile 'com.google.guava:guava:23.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200214 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200215 examplesCompileOnly "com.google.auto.value:auto-value:1.5"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200216 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200217 supportLibs 'com.android.support:support-v4:25.4.0'
218 supportLibs 'junit:junit:4.12'
219 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Yohann Rousselbb571622017-11-09 10:47:36 +0100220 apiUsageSampleCompile sourceSets.main.output
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200221 debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3'
Stephan Herhut52cb1022017-10-24 15:10:41 +0200222 apt 'com.google.auto.value:auto-value:1.5'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200223}
224
Mads Ager22847672017-11-14 09:59:26 +0100225configurations.bsPatchCompile.extendsFrom configurations.compile
226
Yohann Roussel7f47c032017-09-14 12:19:06 +0200227licenseTools {
228 licensesYaml = file('LIBRARY-LICENSE')
229}
230
Stephan Herhut417a72a2017-07-18 10:38:30 +0200231protobuf {
232 protoc {
233 // Download from repositories
234 artifact = 'com.google.protobuf:protoc:3.0.0'
235 }
236 plugins {
237 javalite {
238 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
239 }
240 }
241 generateProtoTasks {
242 all().each { task ->
243 task.builtins {
244 // Disable the java code generator, as we want javalite only.
245 remove java
246 }
247 task.plugins {
248 javalite {}
249 }
250 }
251 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200252}
253
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200254def osString = OperatingSystem.current().isLinux() ? "linux" :
255 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200256
257def cloudDependencies = [
258 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200259 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200260 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200261 ],
262 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200263 "android_jar/lib-v14",
264 "android_jar/lib-v19",
265 "android_jar/lib-v21",
266 "android_jar/lib-v24",
267 "android_jar/lib-v25",
268 "android_jar/lib-v26",
269 "proguard/proguard5.2.1",
270 "gradle/gradle",
271 "jdwp-tests",
272 "jasmin",
273 "jctf",
274 "kotlin",
275 "android_cts_baseline",
276 "shadow",
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200277 "ddmlib",
Mads Ager418d1ca2017-05-22 09:35:49 +0200278 ],
279 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
280 // container on other platforms where supported.
281 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200282 "linux/art",
283 "linux/art-5.1.1",
284 "linux/art-6.0.1",
285 "linux/art-7.0.0",
286 "linux/dalvik",
287 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200288 ]
289]
290
291cloudDependencies.each { entry ->
292 entry.value.each { entryFile ->
293 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200294 def outputDir = "${entry.key}/${entryFile}"
295 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200296 def sha1File = "${gzFile}.sha1"
297 inputs.file sha1File
298 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200299 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200300 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
301 if (OperatingSystem.current().isWindows()) {
302 executable "download_from_google_storage.bat"
303 args dlFromStorageArgs
304 } else {
305 executable "bash"
306 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
307 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200308 }
309 }
310}
311
312def x20Dependencies = [
313 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200314 "gmail/gmail_android_170604.16",
315 "gmscore/v4",
316 "gmscore/v5",
317 "gmscore/v6",
318 "gmscore/v7",
319 "gmscore/v8",
320 "gmscore/gmscore_v9",
321 "gmscore/gmscore_v10",
322 "gmscore/latest",
323 "photos/2017-06-06",
324 "youtube/youtube.android_12.10",
325 "youtube/youtube.android_12.17",
326 "youtube/youtube.android_12.22",
327 "proguardsettings",
328 "proguard/proguard_internal_159423826",
329 "framework",
330 "goyt",
Mads Ager418d1ca2017-05-22 09:35:49 +0200331 ],
332]
333
334x20Dependencies.each { entry ->
335 entry.value.each { entryFile ->
336 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200337 def outputDir = "${entry.key}/${entryFile}"
338 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200339 def sha1File = "${gzFile}.sha1"
340 inputs.file sha1File
341 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200342 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200343 executable "bash"
344 args "-c", "tools/download_from_x20.py ${sha1File}"
345 }
346 }
347}
348
Rico Wind897bb712017-05-23 10:44:29 +0200349task downloadProguard {
350 cloudDependencies.each { entry ->
351 entry.value.each { entryFile ->
352 if (entryFile.contains("proguard")) {
353 dependsOn "download_deps_${entry.key}/${entryFile}"
354 }
355 }
356 }
357}
358
Tamas Kenez427205b2017-06-29 15:57:09 +0200359task downloadDx {
360 cloudDependencies.each { entry ->
361 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200362 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200363 dependsOn "download_deps_${entry.key}/${entryFile}"
364 }
365 }
366 }
367}
368
Tamas Kenez0e10c562017-06-08 10:00:34 +0200369task downloadAndroidCts {
370 cloudDependencies.each { entry ->
371 entry.value.each { entryFile ->
372 if (entryFile.contains("android_cts_baseline")) {
373 dependsOn "download_deps_${entry.key}/${entryFile}"
374 }
375 }
376 }
377}
378
Mads Ager418d1ca2017-05-22 09:35:49 +0200379task downloadDeps {
380 cloudDependencies.each { entry ->
381 entry.value.each { entryFile ->
382 dependsOn "download_deps_${entry.key}/${entryFile}"
383 }
384 }
385 if (!project.hasProperty('no_internal')) {
386 x20Dependencies.each { entry ->
387 entry.value.each { entryFile ->
388 dependsOn "download_deps_${entry.key}/${entryFile}"
389 }
390 }
391 }
392}
393
394allprojects {
395 sourceCompatibility = JavaVersion.VERSION_1_8
396 targetCompatibility = JavaVersion.VERSION_1_8
397}
398
399tasks.withType(JavaCompile) {
400 options.compilerArgs << '-Xlint:unchecked'
401}
402
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200403if (!project.hasProperty('without_error_prone')) {
404 compileJava {
405 // Enable error prone for D8/R8 sources.
406 toolChain ErrorProneToolChain.create(project)
407 options.compilerArgs += errorProneConfiguration
408 }
409}
410
Mads Ager418d1ca2017-05-22 09:35:49 +0200411compileJctfCommonJava {
412 dependsOn 'copyAdditionalJctfCommonFiles'
413 options.compilerArgs = ['-Xlint:none']
414}
415
416compileJctfTestsJava {
417 dependsOn 'jctfCommonClasses'
418 options.compilerArgs = ['-Xlint:none']
419}
420
Yohann Roussel7f47c032017-09-14 12:19:06 +0200421task consolidatedLicense {
422 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
423 // corresponding to the effective list of embedded libraries.
424 dependsOn 'checkLicenses'
425 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
426 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
427 outputs.files license
428 doLast {
429 license.getParentFile().mkdirs()
430 license.createNewFile()
431 license.text = "This file lists all licenses for code distributed.\n"
432 license.text += "All non-library code has the following 3-Clause BSD license.\n"
433 license.text += "\n"
434 license.text += "\n"
435 license.text += file('LICENSE').text
436 license.text += "\n"
437 license.text += "\n"
438 license.text += "Summary of distributed libraries:\n"
439 license.text += "\n"
440 license.text += file('LIBRARY-LICENSE').text
441 license.text += "\n"
442 license.text += "\n"
443 license.text += "Licenses details:\n"
444 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
445 license.text += "\n"
446 license.text += "\n"
447 license.text += file.text
448 }
449 }
450}
451
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000452static configureRelocations(ShadowJar task) {
453 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
454 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
455 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
456 task.relocate('org.apache.commons', 'com.android.tools.r8.org.apache.commons')
457 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
458 task.relocate('org.json.simple', 'com.android.tools.r8.org.json.simple')
459 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
460}
461
462task repackageDeps(type: ShadowJar) {
463 configurations = [project.configurations.compile]
464 configureRelocations(it)
465 baseName 'deps'
466}
467
468task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200469 from sourceSets.main.output
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000470 configureRelocations(it)
471 baseName 'sources'
472}
473
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000474task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200475 from consolidatedLicense.outputs.files
476 exclude { path ->
477 path.getRelativePath().getPathString().startsWith("META-INF")
478 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200479 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200480 classifier = null
481 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200482 manifest {
483 attributes 'Main-Class': 'com.android.tools.r8.R8'
484 }
485 // In order to build without dependencies, pass the exclude_deps property using:
486 // gradle -Pexclude_deps R8
487 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800488 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000489 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800490 } else {
491 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200492 }
493}
494
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000495task D8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200496 from consolidatedLicense.outputs.files
497 exclude { path ->
498 path.getRelativePath().getPathString().startsWith("META-INF")
499 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200500 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200501 classifier = null
502 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200503 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200504 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200505 }
506 // In order to build without dependencies, pass the exclude_deps property using:
507 // gradle -Pexclude_deps D8
508 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800509 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000510 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800511 } else {
512 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200513 }
514}
515
516task CompatDx(type: Jar) {
517 from sourceSets.main.output
518 baseName 'compatdx'
519 manifest {
520 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
521 }
522 // In order to build without dependencies, pass the exclude_deps property using:
523 // gradle -Pexclude_deps CompatDx
524 if (!project.hasProperty('exclude_deps')) {
525 // Also include dependencies
526 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
527 }
528}
529
Søren Gjesse1d21da72017-09-01 12:05:38 +0200530task CompatProguard(type: Jar) {
531 from sourceSets.main.output
532 baseName 'compatproguard'
533 manifest {
534 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
535 }
536 // In order to build without dependencies, pass the exclude_deps property using:
537 // gradle -Pexclude_deps CompatProguard
538 if (!project.hasProperty('exclude_deps')) {
539 // Also include dependencies
540 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
541 }
542}
543
Tamas Kenez971eec62017-05-24 11:08:40 +0200544task D8Logger(type: Jar) {
545 from sourceSets.main.output
546 baseName 'd8logger'
547 manifest {
548 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
549 }
550 // In order to build without dependencies, pass the exclude_deps property using:
551 // gradle -Pexclude_deps D8Logger
552 if (!project.hasProperty('exclude_deps')) {
553 // Also include dependencies
554 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
555 }
556}
557
Mads Ager418d1ca2017-05-22 09:35:49 +0200558task disasm(type: Jar) {
559 from sourceSets.main.output
560 baseName 'disasm'
561 manifest {
562 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
563 }
564 // In order to build without dependencies, pass the exclude_deps property using:
565 // gradle -Pexclude_deps D8
566 if (!project.hasProperty('exclude_deps')) {
567 // Also include dependencies
568 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
569 }
570}
571
572task bisect(type: Jar) {
573 from sourceSets.main.output
574 baseName 'bisect'
575 manifest {
576 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
577 }
578 // In order to build without dependencies, pass the exclude_deps property using:
579 // gradle -Pexclude_deps R8
580 if (!project.hasProperty('exclude_deps')) {
581 // Also include dependencies
582 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
583 }
584}
585
Lars Bak90c18042017-06-26 14:21:08 +0200586task DexSegments(type: Jar) {
587 from sourceSets.main.output
588 baseName 'dexsegments'
589 manifest {
590 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
591 }
592 // In order to build without dependencies, pass the exclude_deps property using:
593 // gradle -Pexclude_deps DexSegments
594 if (!project.hasProperty('exclude_deps')) {
595 // Also include dependencies
596 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
597 }
598}
599
Søren Gjessec4e5e932017-09-04 17:01:23 +0200600task maindex(type: Jar) {
601 from sourceSets.main.output
602 baseName 'maindex'
603 manifest {
604 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
605 }
606 // In order to build without dependencies, pass the exclude_deps property using:
607 // gradle -Pexclude_deps maindex
608 if (!project.hasProperty('exclude_deps')) {
609 // Also include dependencies
610 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
611 }
612}
613
Lars Bak44cef522017-08-10 16:02:39 +0200614task ExtractMarker(type: Jar) {
615 from sourceSets.main.output
616 baseName 'extractmarker'
617 manifest {
618 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
619 }
620 // In order to build without dependencies, pass the exclude_deps property using:
621 // gradle -Pexclude_deps ExtractMarker
622 if (!project.hasProperty('exclude_deps')) {
623 // Also include dependencies
624 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
625 }
626}
627
Mads Ager22847672017-11-14 09:59:26 +0100628task bspatch(type: Jar) {
629 from sourceSets.bsPatch.output
630 baseName 'bspatch'
631 manifest {
632 attributes 'Main-Class': 'com.android.tools.r8.dex.BSPatch'
633 }
634 // In order to build without dependencies, pass the exclude_deps property using:
635 // gradle -Pexclude_deps maindex
636 if (!project.hasProperty('exclude_deps')) {
637 // Also include dependencies
638 from {
639 configurations.bsPatchCompile.collect { it.isDirectory() ? it : zipTree(it) }
640 }
641 }
642}
643
Mads Ager418d1ca2017-05-22 09:35:49 +0200644task sourceJar(type: Jar, dependsOn: classes) {
645 classifier = 'src'
646 from sourceSets.main.allSource
647}
648
649task jctfCommonJar(type: Jar) {
650 from sourceSets.jctfCommon.output
651 baseName 'jctfCommon'
652}
653
654artifacts {
655 archives sourceJar
656}
657
658task createArtTests(type: Exec) {
659 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200660 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200661 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200662 inputs.file createArtTestsScript
663 outputs.dir outputDir
664 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200665 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200666 workingDir = projectDir
667}
668
669task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200670 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200671 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200672 inputs.file script
673 outputs.dir outputDir
674 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200675 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200676 workingDir = projectDir
677}
678
679compileTestJava {
680 dependsOn createArtTests
681 dependsOn createJctfTests
682}
683
Yohann Rousselbb571622017-11-09 10:47:36 +0100684task buildApiUsageSample(type: Jar) {
685 from sourceSets.apiUsageSample.output
686 baseName 'api_usage_sample'
687 destinationDir file('tests')
688}
689
Mads Ager418d1ca2017-05-22 09:35:49 +0200690task buildDebugInfoExamplesDex {
691 def examplesDir = file("src/test/java")
692 def hostJar = "debuginfo_examples.jar"
693 def hostDexJar = "debuginfo_examples_dex.jar"
694 task "compile_debuginfo_examples"(type: JavaCompile) {
695 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
696 destinationDir = file("build/test/debuginfo_examples/classes")
697 classpath = sourceSets.main.compileClasspath
698 sourceCompatibility = JavaVersion.VERSION_1_7
699 targetCompatibility = JavaVersion.VERSION_1_7
700 options.compilerArgs += ["-Xlint:-options"]
701 }
702 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
703 archiveName = hostJar
704 destinationDir = file("build/test/")
705 from "build/test/debuginfo_examples/classes"
706 include "**/*.class"
707 }
708 task "dex_debuginfo_examples"(type: Exec,
709 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200710 if (OperatingSystem.current().isWindows()) {
711 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700712 } else if (OperatingSystem.current().isMacOsX()) {
713 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200714 } else {
715 executable file("tools/linux/dx/bin/dx");
716 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200717 args "--dex"
718 args "--output=build/test/${hostDexJar}"
719 args "build/test/${hostJar}"
720 inputs.file file("build/test/${hostJar}")
721 outputs.file file("build/test/${hostDexJar}")
722 }
723 dependsOn dex_debuginfo_examples
724}
725
726task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200727 def resourcesDir = file("src/test/debugTestResources")
728 def hostJar = "debug_test_resources.jar"
729 task "compile_debugTestResources"(type: JavaCompile) {
730 source = fileTree(dir: resourcesDir, include: '**/*.java')
731 destinationDir = file("build/test/debugTestResources/classes")
732 classpath = sourceSets.main.compileClasspath
733 sourceCompatibility = JavaVersion.VERSION_1_7
734 targetCompatibility = JavaVersion.VERSION_1_7
735 options.compilerArgs += ["-g", "-Xlint:-options"]
736 }
737 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
738 archiveName = hostJar
739 destinationDir = file("build/test/")
740 from "build/test/debugTestResources/classes"
741 include "**/*.class"
742 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200743 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
744 def java8HostJar = "debug_test_resources_java8.jar"
745 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
746 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
747 destinationDir = file("build/test/debugTestResourcesJava8/classes")
748 classpath = sourceSets.main.compileClasspath
749 sourceCompatibility = JavaVersion.VERSION_1_8
750 targetCompatibility = JavaVersion.VERSION_1_8
751 options.compilerArgs += ["-g", "-Xlint:-options"]
752 }
753 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
754 archiveName = java8HostJar
755 destinationDir = file("build/test/")
756 from "build/test/debugTestResourcesJava8/classes"
757 include "**/*.class"
758 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200759 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
760 def kotlinHostJar = "debug_test_resources_kotlin.jar"
Sebastien Hertz9006e9c2017-09-11 11:03:26 +0200761 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
762 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
763 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200764 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200765 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200766 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200767 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200768 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200769}
770
Lars Bakc91e87e2017-08-18 08:53:10 +0200771// Proto lite generated code yields warnings when compiling with javac.
772// We change the options passed to javac to ignore it.
773compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
774
Mads Ager418d1ca2017-05-22 09:35:49 +0200775task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200776 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200777 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200778 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200779 def proguardScript
780 if (OperatingSystem.current().isWindows()) {
781 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
782 } else {
783 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
784 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200785 task extractExamplesRuntime(type: Sync) {
786 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000787 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200788 include "**/*.class"
789 includeEmptyDirs false
790 into "$buildDir/runtime/examples/"
791 }
792
793 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
794 source examplesDir, protoSourceDir
795 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200796 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200797 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200798 sourceCompatibility = JavaVersion.VERSION_1_7
799 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200800 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
801 }
802 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
803 source examplesDir, protoSourceDir
804 include "**/*.java"
805 destinationDir = file("build/test/examples/classes_debuginfo_all")
806 classpath = sourceSets.examples.compileClasspath
807 sourceCompatibility = JavaVersion.VERSION_1_7
808 targetCompatibility = JavaVersion.VERSION_1_7
809 options.compilerArgs = ["-g", "-Xlint:none"]
810 }
811 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
812 source examplesDir, protoSourceDir
813 include "**/*.java"
814 destinationDir = file("build/test/examples/classes_debuginfo_none")
815 classpath = sourceSets.examples.compileClasspath
816 sourceCompatibility = JavaVersion.VERSION_1_7
817 targetCompatibility = JavaVersion.VERSION_1_7
818 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200819 }
820 examplesDir.eachDir { dir ->
821 def name = dir.getName();
822 def exampleOutputDir = file("build/test/examples");
823 def jarName = "${name}.jar"
824 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200825 dependsOn "jar_example_${name}_debuginfo_all"
826 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200827 dependsOn "extractExamplesRuntime"
828 def runtimeDependencies = copySpec { }
829 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
830 // If we have any proto use, we have to include those classes and the runtime.
831 runtimeDependencies = copySpec {
832 from "$buildDir/runtime/examples/"
833 include "com/google/protobuf/**/*.class"
834 }
835 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200836 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
837 def proguardConfigPath = "${dir}/proguard.cfg"
838 if (new File(proguardConfigPath).exists()) {
839 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
840 archiveName = "${name}_pre_proguard.jar"
841 destinationDir = exampleOutputDir
842 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200843 include name + "/**/*.class"
844 with runtimeDependencies
845 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200846 }
847 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
848 def proguardJarPath = "${exampleOutputDir}/${jarName}"
849 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
850 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
851 inputs.files tasks.getByPath("pre_proguard_example_${name}")
852 inputs.file proguardConfigPath
853 // Enable these to get stdout and stderr redirected to files...
854 // standardOutput = new FileOutputStream('proguard.stdout')
855 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200856 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200857 " -outjars ${proguardJarPath}" +
858 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200859 " -printmapping ${proguardMapPath}"
860 if (OperatingSystem.current().isWindows()) {
861 executable "${proguardScript}"
862 args "${proguardArguments}"
863 } else {
864 executable "bash"
865 args "-c", "${proguardScript} '${proguardArguments}'"
866 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200867 outputs.file proguardJarPath
868 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200869 // TODO: Consider performing distinct proguard compilations.
870 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
871 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200872 into "${exampleOutputDir}"
873 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200874 }
875 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
876 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200877 into "${exampleOutputDir}"
878 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200879 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200880 } else {
881 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200882 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200883 destinationDir = exampleOutputDir
884 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200885 include name + "/**/*.class"
886 with runtimeDependencies
887 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200888 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200889 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
890 archiveName = "${name}_debuginfo_all.jar"
891 destinationDir = exampleOutputDir
892 from "build/test/examples/classes_debuginfo_all"
893 include name + "/**/*.class"
894 with runtimeDependencies
895 includeEmptyDirs false
896 }
897 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
898 archiveName = "${name}_debuginfo_none.jar"
899 destinationDir = exampleOutputDir
900 from "build/test/examples/classes_debuginfo_none"
901 include name + "/**/*.class"
902 with runtimeDependencies
903 includeEmptyDirs false
904 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200905 }
906 }
907}
908
909task buildExampleAndroidNJars {
910 dependsOn downloadDeps
911 def examplesDir = file("src/test/examplesAndroidN")
912 task "compile_examplesAndroidN"(type: JavaCompile) {
913 source = fileTree(dir: examplesDir, include: '**/*.java')
914 destinationDir = file("build/test/examplesAndroidN/classes")
915 classpath = sourceSets.main.compileClasspath
916 sourceCompatibility = JavaVersion.VERSION_1_8
917 targetCompatibility = JavaVersion.VERSION_1_8
918 options.compilerArgs += ["-Xlint:-options"]
919 }
920 examplesDir.eachDir { dir ->
921 def name = dir.getName();
922 def exampleOutputDir = file("build/test/examplesAndroidN");
923 def jarName = "${name}.jar"
924 dependsOn "jar_examplesAndroidN_${name}"
925 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
926 archiveName = jarName
927 destinationDir = exampleOutputDir
928 from "build/test/examplesAndroidN/classes"
929 include "**/" + name + "/**/*.class"
930 }
931 }
932}
933
934
935task buildExampleAndroidOJars {
936 dependsOn downloadDeps
937 def examplesDir = file("src/test/examplesAndroidO")
938 // NOTE: we want to enable a scenario when test needs to reference some
939 // classes generated by legacy (1.6) Java compiler to test some specific
940 // behaviour. To do so we compile all the java files located in sub-directory
941 // called 'legacy' with Java 1.6, then compile the rest of the files with
942 // Java 1.8 and a reference to previously generated 1.6 classes.
943
944 // Compiling all classes in dirs 'legacy' with old Java version.
945 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
946 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
947 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
948 classpath = sourceSets.main.compileClasspath
949 sourceCompatibility = JavaVersion.VERSION_1_6
950 targetCompatibility = JavaVersion.VERSION_1_6
951 options.compilerArgs += ["-Xlint:-options", "-parameters"]
952 }
953 // Compiling the rest of the files as Java 1.8 code.
954 task "compile_examplesAndroidO"(type: JavaCompile) {
955 dependsOn "compile_examplesAndroidO_Legacy"
956 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
957 destinationDir = file("build/test/examplesAndroidO/classes")
958 classpath = sourceSets.main.compileClasspath
959 classpath += files("build/test/examplesAndroidOLegacy/classes")
960 sourceCompatibility = JavaVersion.VERSION_1_8
961 targetCompatibility = JavaVersion.VERSION_1_8
962 options.compilerArgs += ["-Xlint:-options", "-parameters"]
963 }
964 examplesDir.eachDir { dir ->
965 def name = dir.getName();
966 def destinationDir = file("build/test/examplesAndroidO/classes");
967 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
968 task "generate_examplesAndroidO_${name}"(type: JavaExec,
969 dependsOn: "compile_examplesAndroidO") {
970 main = name + ".TestGenerator"
971 classpath = files(destinationDir, sourceSets.main.compileClasspath)
972 args destinationDir
973 }
974 } else {
975 task "generate_examplesAndroidO_${name}" () {}
976 }
977 }
978 examplesDir.eachDir { dir ->
979 def name = dir.getName();
980 def exampleOutputDir = file("build/test/examplesAndroidO");
981 def jarName = "${name}.jar"
982 dependsOn "jar_examplesAndroidO_${name}"
983 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
984 "generate_examplesAndroidO_${name}"]) {
985 archiveName = jarName
986 destinationDir = exampleOutputDir
987 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
988 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
989 include "**/" + name + "/**/*.class"
990 // Do not include generator into the test runtime jar, it is not useful.
991 // Otherwise, shrinking will need ASM jars.
992 exclude "**/TestGenerator*"
993 }
994 }
995}
996
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200997task buildExampleAndroidPJars {
998 dependsOn downloadDeps
999 def examplesDir = file("src/test/examplesAndroidP")
1000
1001 task "compile_examplesAndroidP"(type: JavaCompile) {
1002 source = fileTree(dir: examplesDir, include: '**/*.java')
1003 destinationDir = file("build/test/examplesAndroidP/classes")
1004 classpath = sourceSets.main.compileClasspath
1005 sourceCompatibility = JavaVersion.VERSION_1_8
1006 targetCompatibility = JavaVersion.VERSION_1_8
1007 options.compilerArgs += ["-Xlint:-options"]
1008 }
1009 examplesDir.eachDir { dir ->
1010 def name = dir.getName();
1011 def destinationDir = file("build/test/examplesAndroidP/classes");
1012 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1013 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1014 dependsOn: "compile_examplesAndroidP") {
1015 main = name + ".TestGenerator"
1016 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1017 args destinationDir
1018 }
1019 } else {
1020 task "generate_examplesAndroidP_${name}" () {}
1021 }
1022 }
1023 examplesDir.eachDir { dir ->
1024 def name = dir.getName();
1025 def exampleOutputDir = file("build/test/examplesAndroidP");
1026 def jarName = "${name}.jar"
1027 dependsOn "jar_examplesAndroidP_${name}"
1028 task "jar_examplesAndroidP_${name}"(type: Jar,
1029 dependsOn: ["compile_examplesAndroidP",
1030 "generate_examplesAndroidP_${name}"]) {
1031 archiveName = jarName
1032 destinationDir = exampleOutputDir
1033 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1034 include "**/" + name + "/**/*.class"
1035 // Do not include generator into the test runtime jar, it is not useful.
1036 // Otherwise, shrinking will need ASM jars.
1037 exclude "**/TestGenerator*"
1038 }
1039 }
1040}
1041
Mikaël Peltier61633d42017-10-13 16:51:06 +02001042task buildExampleJava9Jars {
1043 def examplesDir = file("src/test/examplesJava9")
1044 examplesDir.eachDir { dir ->
1045 def name = dir.getName();
1046 def exampleOutputDir = file("build/test/examplesJava9");
1047 def jarName = "${name}.jar"
1048 dependsOn "jar_examplesJava9_${name}"
1049 task "jar_examplesJava9_${name}"(type: Jar) {
1050 archiveName = jarName
1051 destinationDir = exampleOutputDir
1052 from "src/test/examplesJava9" // Java 1.9 classes
1053 include "**/" + name + "/**/*.class"
1054 }
1055 }
1056}
1057
Mads Ager418d1ca2017-05-22 09:35:49 +02001058task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001059 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1060 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1061 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001062 } else if (!OperatingSystem.current().isLinux()) {
1063 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001064 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001065 return;
1066 }
1067 dependsOn buildDebugTestResourcesJars
1068 dependsOn buildExampleJars
1069 dependsOn buildExampleAndroidNJars
1070 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001071 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001072 dependsOn buildExampleJava9Jars
Mads Ager418d1ca2017-05-22 09:35:49 +02001073 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001074 def noDexTests = [
1075 "multidex",
1076 "multidex002",
1077 "multidex004",
1078 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001079 examplesDir.eachDir { dir ->
1080 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001081 if (!(name in noDexTests)) {
1082 dependsOn "dex_example_${name}"
1083 def exampleOutputDir = file("build/test/examples/" + name);
1084 def dexPath = file("${exampleOutputDir}")
1085 def debug = (name == "throwing")
1086 if (!dexPath.exists()) {
1087 dexPath.mkdirs()
1088 }
1089 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1090 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1091 destination = dexPath
1092 debug = debug
1093 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001094 }
1095 }
1096}
1097
1098task buildSmali {
1099 def smaliDir = file("src/test/smali")
1100 smaliDir.eachDirRecurse() { dir ->
1101 def name = dir.getName();
1102 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1103 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1104 smaliOutputDir.mkdirs()
1105 outputs.dir smaliOutputDir
1106 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1107 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1108 def javaFiles = fileTree(dir: dir, include: '*.java')
1109 def destDir = smaliOutputDir;
1110 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1111 def intermediateFileName = "${name}-intermediate.dex";
1112 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1113 if (javaFiles.empty) {
1114 if (!smaliFiles.empty) {
1115 dependsOn "${taskName}_smali"
1116 task "${taskName}_smali"(type: smali.Smali) {
1117 source = smaliFiles
1118 destination = destFile
1119 }
1120 }
1121 } else {
1122 dependsOn "${taskName}_dexmerger"
1123 task "${taskName}_smali"(type: smali.Smali) {
1124 source = smaliFiles
1125 destination = intermediateFile
1126 }
1127 task "${taskName}_java"(type: JavaCompile) {
1128 source = javaFiles
1129 destinationDir destDir
1130 classpath = sourceSets.main.compileClasspath
1131 sourceCompatibility = JavaVersion.VERSION_1_7
1132 targetCompatibility = JavaVersion.VERSION_1_7
1133 options.compilerArgs += ["-Xlint:-options"]
1134 }
1135 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1136 archiveName = "Test.jar"
1137 destinationDir = destDir
1138 from fileTree(dir: destDir, include: 'Test.class')
1139 }
1140 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1141 source = fileTree(dir: destDir, include: 'Test.jar')
1142 destination = destDir
1143 }
1144 task "${taskName}_dexmerger"(
1145 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1146 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1147 destination = destFile
1148 }
1149 }
1150 }
1151}
1152
1153tasks.withType(Test) {
1154 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1155 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1156 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1157 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1158 forkEvery = 0
1159 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1160 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001161 if (project.hasProperty('disable_assertions')) {
1162 enableAssertions = false
1163 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001164}
1165
1166task buildPreNJdwpTestsJar(type: Jar) {
1167 baseName = 'jdwp-tests-preN'
1168 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1169 // Exclude the classes containing java8
1170 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1171 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1172 includeEmptyDirs = false
1173}
1174
Ian Zerny74143162017-11-24 13:46:35 +01001175task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1176 def inFile = buildPreNJdwpTestsJar.archivePath
1177 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
1178 inputs.file inFile
1179 outputs.file outFile
1180 if (OperatingSystem.current().isWindows()) {
1181 executable file("tools/windows/dx/bin/dx.bat")
1182 } else if (OperatingSystem.current().isMacOsX()) {
1183 executable file("tools/mac/dx/bin/dx");
1184 } else {
1185 executable file("tools/linux/dx/bin/dx");
1186 }
1187 args "--dex"
1188 args "--output=${outFile}"
1189 args inFile
1190}
1191
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001192task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1193 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001194}
1195
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001196task AospJarTest(type: Exec) {
1197 dependsOn CompatDx, downloadDeps
1198 def script = "tools/test_aosp_jar.py"
1199 inputs.file script
1200 commandLine "python", script, "--no-build"
1201 workingDir = projectDir
1202}
1203
Mads Ager418d1ca2017-05-22 09:35:49 +02001204test {
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001205 dependsOn getJarsFromSupportLibs
Mads Ager418d1ca2017-05-22 09:35:49 +02001206 testLogging.exceptionFormat = 'full'
1207 if (project.hasProperty('print_test_stdout')) {
1208 testLogging.showStandardStreams = true
1209 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001210 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001211 println "Running with non default vm: " + project.property('dex_vm')
1212 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001213 if (project.property('dex_vm').startsWith('4.4.4') ||
1214 project.property('dex_vm').startsWith('5.1.1') ||
1215 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001216 // R8 and D8 compute the dex file version number based on the input.
1217 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1218 // Therefore we skip the jack generated art tests with those art versions.
1219 exclude "com/android/tools/r8/art/jack/**"
1220 }
1221 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001222
Mads Ager418d1ca2017-05-22 09:35:49 +02001223 if (project.hasProperty('one_line_per_test')) {
1224 beforeTest { desc ->
1225 println "Start executing test ${desc.name} [${desc.className}]"
1226 }
1227 afterTest { desc, result ->
1228 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1229 }
1230 }
1231 if (project.hasProperty('no_internal')) {
1232 exclude "com/android/tools/r8/internal/**"
1233 }
1234 if (project.hasProperty('only_internal')) {
1235 include "com/android/tools/r8/internal/**"
1236 }
1237 if (project.hasProperty('tool')) {
1238 if (project.property('tool') == 'r8') {
1239 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001240 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001241 } else {
1242 assert(project.property('tool') == 'd8')
1243 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001244 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001245 }
1246 }
1247 if (!project.hasProperty('all_tests')) {
1248 exclude "com/android/tools/r8/art/dx/**"
1249 exclude "com/android/tools/r8/art/jack/**"
1250 }
1251 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1252 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001253 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001254 }
1255 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001256 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001257 }
1258 if (project.hasProperty('jctf_compile_only')) {
1259 println "JCTF: compiling only"
1260 systemProperty 'jctf_compile_only', '1'
1261 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001262 if (project.hasProperty('test_dir')) {
1263 systemProperty 'test_dir', project.property('test_dir')
1264 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001265 if (project.hasProperty('aosp_jar')) {
1266 dependsOn AospJarTest
1267 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001268
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001269 if (OperatingSystem.current().isLinux()
1270 || OperatingSystem.current().isMacOsX()
1271 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001272 if (OperatingSystem.current().isMacOsX()) {
1273 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1274 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1275 "See tools/docker/README.md for details.")
1276 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001277 if (OperatingSystem.current().isWindows()) {
1278 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1279 "Art only runs on Linux and tests requiring Art will be skipped")
1280 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001281 dependsOn downloadDeps
1282 dependsOn buildExamples
1283 dependsOn buildSmali
1284 dependsOn jctfCommonJar
1285 dependsOn jctfTestsClasses
1286 dependsOn buildDebugInfoExamplesDex
1287 dependsOn buildPreNJdwpTestsJar
1288 } else {
1289 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001290 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001291 }
1292}
1293
1294// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1295//
1296// To build and upload a new set of the Art tests for use with R8 follow these steps:
1297//
1298// First of all an Android checkout is required. Currently it must be located
1299// in $HOME/android/master.
1300//
1301// TODO(ricow): simplify this
1302//
1303// Before: update the checked in art, see scripts/update-host-art.sh
1304//
1305// 1. Get an android checkout in $HOME/android/master and apply the patch from
1306// https://android-review.googlesource.com/#/c/294187/
1307//
1308// 2. run the following commands in the Android checkout directory:
1309//
1310// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001311// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1312// m desugar
1313// m -j30 test-art-host
1314// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1315//
1316// Without running the test.py command the classes.jar file used by desugar in
1317// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1318// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001319//
1320// 3. In the R8 project root directory, make sure we have a clean state before starting:
1321// tools/gradle.py downloadDeps
1322// tools/gradle.py clean
1323// rm -rf tests/art
1324//
1325// 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 +02001326// Make sure you have smali on your path, please use the build binary in the
1327// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1328// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1329// 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 +02001330// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1331// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001332//
Søren Gjesse34b77732017-07-07 13:56:21 +02001333// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001334//
1335// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1336// skippedTests with an explanation. Rerun from step 3.
1337//
1338// 5. Run the tests:
1339// tools/gradle.py clean
1340// tools/test.py
1341//
Søren Gjesse34b77732017-07-07 13:56:21 +02001342// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1343// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1344// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001345//
Søren Gjesse34b77732017-07-07 13:56:21 +02001346// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001347// cd tests
1348// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001349//
1350// 7. Update the manifest file describing the Android repo used:
1351// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001352
1353enum DexTool {
1354 JACK,
1355 DX
1356}
1357
1358def androidCheckoutDir = file("${System.env.HOME}/android/master")
1359def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1360def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1361
1362def artTestDir = file("${androidCheckoutDir}/art/test")
1363
1364if (project.hasProperty('android_source')) {
1365 task buildArtTests {
1366 outputs.upToDateWhen { false }
1367 def toBeTriaged = [
1368 "903-hello-tagging",
1369 "904-object-allocation",
1370 "905-object-free",
1371 "906-iterate-heap",
1372 "907-get-loaded-classes",
1373 "908-gc-start-finish",
1374 "954-invoke-polymorphic-verifier",
1375 "955-methodhandles-smali",
1376 "596-monitor-inflation",
1377 ]
1378 def skippedTests = toBeTriaged + [
1379 // This test produces no jar.
1380 "000-nop",
1381 // This does not build, as it tests the error when the application exceeds more
1382 // than 65536 methods
1383 "089-many-methods",
1384 // Requires some jack beta jar
1385 "956-methodhandles",
1386 ]
1387
1388 def skippedTestsDx = [
1389 // Tests with custom build scripts, where javac is not passed the options
1390 // -source 1.7 -target 1.7.
1391 "462-checker-inlining-across-dex-files",
1392 "556-invoke-super",
1393 "569-checker-pattern-replacement",
1394 // These tests use jack even when --build-with-javac-dx is specified.
1395 "004-JniTest",
1396 "048-reflect-v8",
1397 "146-bad-interface",
1398 "563-checker-invoke-super",
1399 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1400 "604-hot-static-interface",
1401 "957-methodhandle-transforms",
1402 "958-methodhandle-emulated-stackframe",
1403 "959-invoke-polymorphic-accessors",
1404 "961-default-iface-resolution-gen",
1405 "962-iface-static",
1406 "963-default-range-smali",
1407 "964-default-iface-init-gen",
1408 "965-default-verify",
1409 "966-default-conflict",
1410 "967-default-ame",
1411 "968-default-partial-compile-gen",
1412 "969-iface-super",
1413 "970-iface-super-resolution-gen",
1414 "971-iface-super",
1415 // These tests does not build with --build-with-javac-dx
1416 "004-NativeAllocations", // Javac error
1417 "031-class-attributes",
1418 "138-duplicate-classes-check",
1419 "157-void-class", // Javac error
1420 "580-checker-string-factory-intrinsics",
1421 "612-jit-dex-cache",
1422 "613-inlining-dex-cache",
1423 "900-hello-plugin", // --experimental agents
1424 "901-hello-ti-agent", // --experimental agents
1425 "902-hello-transformation", // --experimental agents
1426 "909-attach-agent", // --experimental agents
1427 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1428 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1429 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1430 "960-default-smali", // --experimental default-methods
1431 // These tests force the build to use jack
1432 "953-invoke-polymorphic-compiler",
1433 "958-methodhandle-stackframe",
1434 ]
1435
1436 def artTestBuildDir = file("${projectDir}/tests/art")
1437
1438 if (androidCheckoutDir.exists()) {
1439 dependsOn downloadDeps
1440 artTestBuildDir.mkdirs()
1441 // Ensure Jack server is running.
1442 "${androidCheckoutJackServer} start-server".execute()
1443 artTestDir.eachDir { dir ->
1444 def name = dir.getName();
1445 def markerFile = dir.toPath().resolve("info.txt").toFile();
1446 if (markerFile.exists() && !(name in skippedTests)) {
1447 if (!(name in skippedTestsDx)) {
1448 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1449 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001450 // After Android O, Jack is no longer alive
1451 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001452 }
1453 }
1454 }
1455 doFirst {
1456 if (!androidCheckoutDir.exists()) {
1457 throw new InvalidUserDataException(
1458 "This task requires an Android checkout in ${androidCheckoutDir}");
1459 } else if (!androidCheckoutJack.exists() ||
1460 !androidCheckoutJackServer.exists()) {
1461 throw new InvalidUserDataException(
1462 "This task requires that tools for host testing have been build in the " +
1463 "Android checkout in ${androidCheckoutDir}");
1464 }
1465 }
1466 doLast {
1467 copy {
1468 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1469 into file("${artTestBuildDir}/lib64")
1470 include 'lib*.so'
1471 }
1472 copy {
1473 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1474 into file("${artTestBuildDir}/lib64")
1475 include 'libart.so'
1476 include 'libbacktrace.so'
1477 include 'libbase.so'
1478 include 'libc++.so'
1479 include 'libcutils.so'
1480 include 'liblz4.so'
1481 include 'liblzma.so'
1482 include 'libnativebridge.so'
1483 include 'libnativeloader.so'
1484 include 'libsigchain.so'
1485 include 'libunwind.so'
1486 include 'libziparchive.so'
1487 }
1488 copy {
1489 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1490 into file("${artTestBuildDir}/lib")
1491 include 'lib*.so'
1492 }
1493 copy {
1494 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1495 into file("${artTestBuildDir}/lib")
1496 include 'libart.so'
1497 include 'libbacktrace.so'
1498 include 'libbase.so'
1499 include 'libc++.so'
1500 include 'libcutils.so'
1501 include 'liblz4.so'
1502 include 'liblzma.so'
1503 include 'libnativebridge.so'
1504 include 'libnativeloader.so'
1505 include 'libsigchain.so'
1506 include 'libunwind.so'
1507 include 'libziparchive.so'
1508 }
1509 }
1510 }
1511}
1512
1513def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1514 def artTestDir = file("${androidCheckoutDir}/art/test")
1515 def artRunTestScript = file("${artTestDir}/run-test")
1516 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001517 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001518 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1519
Søren Gjesse34b77732017-07-07 13:56:21 +02001520 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001521 def buildTask = "build_art_test_${dexToolName}_${name}"
1522 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1523 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1524 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1525
1526 def buildInputs = fileTree(dir: dir, include: '**/*')
1527 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1528 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1529 testDir.mkdirs()
1530 if (dexTool == DexTool.DX) {
1531 task "$buildTask"(type: Exec) {
1532 outputs.upToDateWhen { false }
1533 inputs.file buildInputs
1534 executable "${artRunTestScript}"
1535 args "--host"
1536 args "--build-only"
1537 args "--build-with-javac-dx"
1538 args "--output-path", "${testDir}"
1539 args "${name}"
1540 environment DX: "${dxExecutable.absolutePath}"
1541 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001542 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001543 outputs.file outputJar
1544 }
1545 } else {
1546 assert dexTool == DexTool.JACK
1547 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1548 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1549 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1550 task "$buildTask"(type: Exec) {
1551 outputs.upToDateWhen { false }
1552 inputs.file buildInputs
1553 executable "${artRunTestScript}"
1554 args "--host"
1555 args "--build-only"
1556 args "--output-path", "${testDir}"
1557 args "${name}"
1558 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1559 environment JACK_CLASSPATH: jackClasspath
1560 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1561 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1562 outputs.file outputJar
1563 }
1564 }
1565 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1566 outputs.upToDateWhen { false }
1567 executable "/bin/bash"
1568 args "-c"
1569 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1570 " ${testDir}/classes-ex ${testDir}/check"
1571 }
1572
1573 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001574 // Directory that contains smali files is either smali, or smali/art
1575 def smali_dir = file("${dir}/smali/art")
1576 if (smali_dir.exists()) {
1577 workingDir "${testDir}/smali/art"
1578 } else {
1579 workingDir "${testDir}/smali"
1580 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001581 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001582 // This is the command line options for smali prior to 2.2.1, where smali got a new
1583 // command line interface.
1584 args "-c", "smali a *.smali"
1585 // This is the command line options for smali 2.2.1 and later.
1586 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001587 }
1588
1589 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1590 def smali_dir = file("${dir}/smali")
1591 outputs.upToDateWhen { false }
1592 if (smali_dir.exists() && dexTool == DexTool.DX) {
1593 dependsOn smaliToDexTask
1594 }
1595 from("${artTestDir}/${name}") {
1596 include 'check'
1597 }
1598 into testDir
1599 }
1600
1601 return copyCheckTask
1602}
1603
1604task javadocD8(type: Javadoc) {
1605 classpath = sourceSets.main.compileClasspath
1606 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001607 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001608 include '**/com/android/tools/r8/BaseCommand.java'
1609 include '**/com/android/tools/r8/BaseOutput.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001610 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001611 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001612 include '**/com/android/tools/r8/CompilationMode.java'
1613 include '**/com/android/tools/r8/D8.java'
1614 include '**/com/android/tools/r8/D8Command.java'
1615 include '**/com/android/tools/r8/D8Output.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001616 include '**/com/android/tools/r8/Diagnostic.java'
1617 include '**/com/android/tools/r8/DiagnosticsHandler.java'
1618 include '**/com/android/tools/r8/Location.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001619 include '**/com/android/tools/r8/Resource.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001620 include '**/com/android/tools/r8/TextRangeLocation.java'
1621 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001622}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001623
1624task copyMavenDeps(type: Copy) {
1625 from configurations.compile into "$buildDir/deps"
1626 from configurations.testCompile into "$buildDir/deps"
1627}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001628
1629// This task allows to build class files from Java 9 source in order to use them as inputs of
1630// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1631// to the D8 repository because there is no way to generate them on all computers due to the need of
1632// Java 9.
1633// Use the following command to rebuild class files of tests:
1634// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1635task buildJava9Tests {
1636 def javacOutputFolder = getTemporaryDir();
1637 def examplesDir = file("src/test/examplesJava9")
1638
1639 task "compile_Java9examples"(type: JavaCompile) {
1640 doFirst {
1641 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1642 throw new GradleException("Set java9Home property.")
1643 }
1644 }
1645
1646 source = fileTree(dir: examplesDir, include: '**/*.java')
1647 destinationDir = javacOutputFolder
1648 classpath = sourceSets.main.compileClasspath
1649 options.compilerArgs += ["-Xlint:-options"]
1650 sourceCompatibility = JavaVersion.VERSION_1_9
1651 targetCompatibility = JavaVersion.VERSION_1_9
1652 options.fork = true
1653
1654 if (project.hasProperty('java9Home')) {
1655 options.forkOptions.javaHome = file(getProperty('java9Home'))
1656 }
1657
1658 doLast {
1659 def classfileFrom = copySpec {
1660 from javacOutputFolder
1661 include "**/*.class"
1662 }
1663 copy {
1664 into examplesDir
1665 with classfileFrom
1666 }
1667 delete javacOutputFolder
1668 }
1669 }
1670
1671 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001672}