blob: 67d455ad5287cae2c4f3170b2866d1684cf0a238 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02004import org.gradle.internal.os.OperatingSystem
Stephan Herhut417a72a2017-07-18 10:38:30 +02005import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +02006
7apply plugin: 'java'
8apply plugin: 'idea'
9apply plugin: 'jacoco'
Stephan Herhut417a72a2017-07-18 10:38:30 +020010apply plugin: 'com.google.protobuf'
Mads Ager418d1ca2017-05-22 09:35:49 +020011
12apply from: 'copyAdditionalJctfCommonFiles.gradle'
13
14repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020015 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020016 mavenCentral()
17}
18
Stephan Herhut417a72a2017-07-18 10:38:30 +020019buildscript {
20 repositories {
21 mavenCentral()
22 }
23 dependencies {
24 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
25 }
26}
27
Mads Ager418d1ca2017-05-22 09:35:49 +020028// Custom source set for example tests and generated tests.
29sourceSets {
30 test {
31 java {
32 srcDirs = [
33 'src/test/java',
34 'build/generated/test/java',
35 ]
36 }
37 }
38 debugTestResources {
39 java {
40 srcDirs = ['src/test/debugTestResources']
41 }
42 output.resourcesDir = 'build/classes/debugTestResources'
43 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020044 debugTestResourcesJava8 {
45 java {
46 srcDirs = ['src/test/debugTestResourcesJava8']
47 }
48 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
49 }
Mads Ager418d1ca2017-05-22 09:35:49 +020050 examples {
51 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +020052 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
53 }
54 proto {
55 srcDirs = [
56 'src/test/examples',
57 ]
Mads Ager418d1ca2017-05-22 09:35:49 +020058 }
59 output.resourcesDir = 'build/classes/examples'
60 }
61 examplesAndroidN {
62 java {
63 srcDirs = ['src/test/examplesAndroidN']
64 }
65 output.resourcesDir = 'build/classes/examplesAndroidN'
66 }
67 examplesAndroidO {
68 java {
69 srcDirs = ['src/test/examplesAndroidO']
70 }
71 output.resourcesDir = 'build/classes/examplesAndroidO'
72 }
73 jctfCommon {
74 java {
75 srcDirs = [
76 'third_party/jctf/Harness/src',
77 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
78 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
79 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
80 'third_party/jctf/LibTests/src/org',
81 'build/additionalJctfCommonFiles'
82 ]
83 }
84 resources {
85 srcDirs = ['third_party/jctf/LibTests/resources']
86 }
87 }
88 jctfTests {
89 java {
90 srcDirs = [
91 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
92 // 'third_party/jctf/VMTests/src',
93 ]
94 }
95 }
96}
97
Yohann Roussel126f6872017-08-03 16:25:32 +020098configurations {
99 supportLibs
100}
101
Mads Ager418d1ca2017-05-22 09:35:49 +0200102dependencies {
103 compile 'net.sf.jopt-simple:jopt-simple:4.6'
104 compile group: 'com.google.guava', name: 'guava', version: '19.0'
Stephan Herhutb17bb8d2017-05-23 12:34:55 +0200105 compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0'
Mads Ager418d1ca2017-05-22 09:35:49 +0200106 compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12'
107 compile group: 'org.ow2.asm', name: 'asm', version: '5.1'
108 compile group: 'org.ow2.asm', name: 'asm-commons', version: '5.1'
109 compile group: 'org.ow2.asm', name: 'asm-tree', version: '5.1'
110 compile group: 'org.ow2.asm', name: 'asm-util', version: '5.1'
111 testCompile sourceSets.examples.output
112 testCompile 'junit:junit:4.12'
113 testCompile group: 'org.smali', name: 'smali', version: '2.2b4'
114 testCompile files('third_party/jasmin/jasmin-2.4.jar')
115 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
116 jctfCommonCompile 'junit:junit:4.12'
117 jctfTestsCompile 'junit:junit:4.12'
118 jctfTestsCompile sourceSets.jctfCommon.output
119 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '5.1'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200120 examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0'
121 examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0'
Yohann Roussel126f6872017-08-03 16:25:32 +0200122 supportLibs 'com.android.support:support-v4:25.4.0'
123 supportLibs 'junit:junit:4.12'
124 supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
Stephan Herhut417a72a2017-07-18 10:38:30 +0200125}
126
127protobuf {
128 protoc {
129 // Download from repositories
130 artifact = 'com.google.protobuf:protoc:3.0.0'
131 }
132 plugins {
133 javalite {
134 artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
135 }
136 }
137 generateProtoTasks {
138 all().each { task ->
139 task.builtins {
140 // Disable the java code generator, as we want javalite only.
141 remove java
142 }
143 task.plugins {
144 javalite {}
145 }
146 }
147 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200148}
149
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200150def osString = OperatingSystem.current().isLinux() ? "linux" :
151 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200152
153def cloudDependencies = [
154 "tests" : [
Søren Gjesse34b77732017-07-07 13:56:21 +0200155 "2017-07-07/art.tar.gz",
156 "2016-12-19/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200157 ],
158 "third_party": [
159 "android_jar/lib-v14.tar.gz",
160 "android_jar/lib-v19.tar.gz",
Søren Gjesseab220772017-06-23 13:05:53 +0200161 "android_jar/lib-v21.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200162 "android_jar/lib-v24.tar.gz",
163 "android_jar/lib-v25.tar.gz",
164 "android_jar/lib-v26.tar.gz",
165 "proguard/proguard5.2.1.tar.gz",
166 "gradle/gradle.tar.gz",
167 "jdwp-tests.tar.gz",
168 "jasmin.tar.gz",
169 "jctf.tar.gz",
170 "android_cts_baseline.tar.gz",
171 ],
172 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
173 // container on other platforms where supported.
174 "tools" : [
175 "linux/art.tar.gz",
176 "linux/art-5.1.1.tar.gz",
177 "linux/art-6.0.1.tar.gz",
178 "linux/art-7.0.0.tar.gz",
179 "linux/dalvik.tar.gz",
180 "${osString}/dx.tar.gz",
181 ]
182]
183
184cloudDependencies.each { entry ->
185 entry.value.each { entryFile ->
186 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
187 def gzFile = "${entry.key}/${entryFile}"
188 def sha1File = "${gzFile}.sha1"
189 inputs.file sha1File
190 outputs.file gzFile
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200191 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
192 if (OperatingSystem.current().isWindows()) {
193 executable "download_from_google_storage.bat"
194 args dlFromStorageArgs
195 } else {
196 executable "bash"
197 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
198 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200199 }
200 }
201}
202
203def x20Dependencies = [
204 "third_party": [
Søren Gjesse5ecb04a2017-06-13 09:44:32 +0200205 "gmail/gmail_android_170604.16.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200206 "gmscore/v4.tar.gz",
207 "gmscore/v5.tar.gz",
208 "gmscore/v6.tar.gz",
209 "gmscore/v7.tar.gz",
210 "gmscore/v8.tar.gz",
211 "gmscore/gmscore_v9.tar.gz",
212 "gmscore/gmscore_v10.tar.gz",
Stephan Herhut4e743302017-06-09 13:09:03 +0200213 "gmscore/latest.tar.gz",
Mads Agerae646402017-06-07 13:32:43 +0200214 "photos/2017-06-06.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200215 "youtube/youtube.android_12.10.tar.gz",
Søren Gjessefeac2ef2017-05-22 17:09:29 +0200216 "youtube/youtube.android_12.17.tar.gz",
Søren Gjesse9be84982017-06-09 14:21:03 +0200217 "youtube/youtube.android_12.22.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200218 "proguardsettings.tar.gz",
Tamas Kenez5febf242017-06-20 16:00:44 +0200219 "proguard/proguard_internal_159423826.tar.gz",
Tamas Kenez67419712017-06-26 11:11:45 +0200220 "framework.tar.gz",
Tamas Kenez391fca82017-06-29 18:16:01 +0200221 "goyt.tar.gz",
Mads Ager418d1ca2017-05-22 09:35:49 +0200222 ],
223]
224
225x20Dependencies.each { entry ->
226 entry.value.each { entryFile ->
227 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
228 def gzFile = "${entry.key}/${entryFile}"
229 def sha1File = "${gzFile}.sha1"
230 inputs.file sha1File
231 outputs.file gzFile
232 executable "bash"
233 args "-c", "tools/download_from_x20.py ${sha1File}"
234 }
235 }
236}
237
Rico Wind897bb712017-05-23 10:44:29 +0200238task downloadProguard {
239 cloudDependencies.each { entry ->
240 entry.value.each { entryFile ->
241 if (entryFile.contains("proguard")) {
242 dependsOn "download_deps_${entry.key}/${entryFile}"
243 }
244 }
245 }
246}
247
Tamas Kenez427205b2017-06-29 15:57:09 +0200248task downloadDx {
249 cloudDependencies.each { entry ->
250 entry.value.each { entryFile ->
251 if (entryFile.contains("dx.tar")) {
252 dependsOn "download_deps_${entry.key}/${entryFile}"
253 }
254 }
255 }
256}
257
Tamas Kenez0e10c562017-06-08 10:00:34 +0200258task downloadAndroidCts {
259 cloudDependencies.each { entry ->
260 entry.value.each { entryFile ->
261 if (entryFile.contains("android_cts_baseline")) {
262 dependsOn "download_deps_${entry.key}/${entryFile}"
263 }
264 }
265 }
266}
267
Mads Ager418d1ca2017-05-22 09:35:49 +0200268task downloadDeps {
269 cloudDependencies.each { entry ->
270 entry.value.each { entryFile ->
271 dependsOn "download_deps_${entry.key}/${entryFile}"
272 }
273 }
274 if (!project.hasProperty('no_internal')) {
275 x20Dependencies.each { entry ->
276 entry.value.each { entryFile ->
277 dependsOn "download_deps_${entry.key}/${entryFile}"
278 }
279 }
280 }
281}
282
283allprojects {
284 sourceCompatibility = JavaVersion.VERSION_1_8
285 targetCompatibility = JavaVersion.VERSION_1_8
286}
287
288tasks.withType(JavaCompile) {
289 options.compilerArgs << '-Xlint:unchecked'
290}
291
292compileJctfCommonJava {
293 dependsOn 'copyAdditionalJctfCommonFiles'
294 options.compilerArgs = ['-Xlint:none']
295}
296
297compileJctfTestsJava {
298 dependsOn 'jctfCommonClasses'
299 options.compilerArgs = ['-Xlint:none']
300}
301
302task R8(type: Jar) {
303 from sourceSets.main.output
304 baseName 'r8'
305 manifest {
306 attributes 'Main-Class': 'com.android.tools.r8.R8'
307 }
308 // In order to build without dependencies, pass the exclude_deps property using:
309 // gradle -Pexclude_deps R8
310 if (!project.hasProperty('exclude_deps')) {
311 // Also include dependencies
312 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
313 }
314}
315
316task D8(type: Jar) {
317 from sourceSets.main.output
318 baseName 'd8'
319 manifest {
320 attributes 'Main-Class': 'com.android.tools.r8.D8'
321 }
322 // In order to build without dependencies, pass the exclude_deps property using:
323 // gradle -Pexclude_deps D8
324 if (!project.hasProperty('exclude_deps')) {
325 // Also include dependencies
326 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
327 }
328}
329
330task CompatDx(type: Jar) {
331 from sourceSets.main.output
332 baseName 'compatdx'
333 manifest {
334 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
335 }
336 // In order to build without dependencies, pass the exclude_deps property using:
337 // gradle -Pexclude_deps CompatDx
338 if (!project.hasProperty('exclude_deps')) {
339 // Also include dependencies
340 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
341 }
342}
343
Tamas Kenez971eec62017-05-24 11:08:40 +0200344task D8Logger(type: Jar) {
345 from sourceSets.main.output
346 baseName 'd8logger'
347 manifest {
348 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
349 }
350 // In order to build without dependencies, pass the exclude_deps property using:
351 // gradle -Pexclude_deps D8Logger
352 if (!project.hasProperty('exclude_deps')) {
353 // Also include dependencies
354 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
355 }
356}
357
Mads Ager418d1ca2017-05-22 09:35:49 +0200358task disasm(type: Jar) {
359 from sourceSets.main.output
360 baseName 'disasm'
361 manifest {
362 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
363 }
364 // In order to build without dependencies, pass the exclude_deps property using:
365 // gradle -Pexclude_deps D8
366 if (!project.hasProperty('exclude_deps')) {
367 // Also include dependencies
368 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
369 }
370}
371
372task bisect(type: Jar) {
373 from sourceSets.main.output
374 baseName 'bisect'
375 manifest {
376 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
377 }
378 // In order to build without dependencies, pass the exclude_deps property using:
379 // gradle -Pexclude_deps R8
380 if (!project.hasProperty('exclude_deps')) {
381 // Also include dependencies
382 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
383 }
384}
385
Lars Bak90c18042017-06-26 14:21:08 +0200386task DexSegments(type: Jar) {
387 from sourceSets.main.output
388 baseName 'dexsegments'
389 manifest {
390 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
391 }
392 // In order to build without dependencies, pass the exclude_deps property using:
393 // gradle -Pexclude_deps DexSegments
394 if (!project.hasProperty('exclude_deps')) {
395 // Also include dependencies
396 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
397 }
398}
399
Mads Ager418d1ca2017-05-22 09:35:49 +0200400task sourceJar(type: Jar, dependsOn: classes) {
401 classifier = 'src'
402 from sourceSets.main.allSource
403}
404
405task jctfCommonJar(type: Jar) {
406 from sourceSets.jctfCommon.output
407 baseName 'jctfCommon'
408}
409
410artifacts {
411 archives sourceJar
412}
413
414task createArtTests(type: Exec) {
415 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200416 def createArtTestsScript = "tools/create_art_tests.py"
Søren Gjesse34b77732017-07-07 13:56:21 +0200417 inputs.file "tests/2017-07-07/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200418 inputs.file createArtTestsScript
419 outputs.dir outputDir
420 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200421 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200422 workingDir = projectDir
423}
424
425task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200426 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200427 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200428 inputs.file script
429 outputs.dir outputDir
430 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200431 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200432 workingDir = projectDir
433}
434
435compileTestJava {
436 dependsOn createArtTests
437 dependsOn createJctfTests
438}
439
440task buildDebugInfoExamplesDex {
441 def examplesDir = file("src/test/java")
442 def hostJar = "debuginfo_examples.jar"
443 def hostDexJar = "debuginfo_examples_dex.jar"
444 task "compile_debuginfo_examples"(type: JavaCompile) {
445 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
446 destinationDir = file("build/test/debuginfo_examples/classes")
447 classpath = sourceSets.main.compileClasspath
448 sourceCompatibility = JavaVersion.VERSION_1_7
449 targetCompatibility = JavaVersion.VERSION_1_7
450 options.compilerArgs += ["-Xlint:-options"]
451 }
452 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
453 archiveName = hostJar
454 destinationDir = file("build/test/")
455 from "build/test/debuginfo_examples/classes"
456 include "**/*.class"
457 }
458 task "dex_debuginfo_examples"(type: Exec,
459 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200460 if (OperatingSystem.current().isWindows()) {
461 executable file("tools/windows/dx/bin/dx.bat")
462 } else {
463 executable file("tools/linux/dx/bin/dx");
464 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200465 args "--dex"
466 args "--output=build/test/${hostDexJar}"
467 args "build/test/${hostJar}"
468 inputs.file file("build/test/${hostJar}")
469 outputs.file file("build/test/${hostDexJar}")
470 }
471 dependsOn dex_debuginfo_examples
472}
473
474task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200475 def resourcesDir = file("src/test/debugTestResources")
476 def hostJar = "debug_test_resources.jar"
477 task "compile_debugTestResources"(type: JavaCompile) {
478 source = fileTree(dir: resourcesDir, include: '**/*.java')
479 destinationDir = file("build/test/debugTestResources/classes")
480 classpath = sourceSets.main.compileClasspath
481 sourceCompatibility = JavaVersion.VERSION_1_7
482 targetCompatibility = JavaVersion.VERSION_1_7
483 options.compilerArgs += ["-g", "-Xlint:-options"]
484 }
485 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
486 archiveName = hostJar
487 destinationDir = file("build/test/")
488 from "build/test/debugTestResources/classes"
489 include "**/*.class"
490 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200491 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
492 def java8HostJar = "debug_test_resources_java8.jar"
493 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
494 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
495 destinationDir = file("build/test/debugTestResourcesJava8/classes")
496 classpath = sourceSets.main.compileClasspath
497 sourceCompatibility = JavaVersion.VERSION_1_8
498 targetCompatibility = JavaVersion.VERSION_1_8
499 options.compilerArgs += ["-g", "-Xlint:-options"]
500 }
501 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
502 archiveName = java8HostJar
503 destinationDir = file("build/test/")
504 from "build/test/debugTestResourcesJava8/classes"
505 include "**/*.class"
506 }
507 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200508 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200509 dependsOn jar_debugTestResourcesJava8
Mads Ager418d1ca2017-05-22 09:35:49 +0200510}
511
512task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200513 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200514 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200515 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200516 def proguardScript
517 if (OperatingSystem.current().isWindows()) {
518 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
519 } else {
520 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
521 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200522 task extractExamplesRuntime(type: Sync) {
523 dependsOn configurations.examplesRuntime
524 from configurations.examplesRuntime.collect { zipTree(it) }
525 include "**/*.class"
526 includeEmptyDirs false
527 into "$buildDir/runtime/examples/"
528 }
529
530 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
531 source examplesDir, protoSourceDir
532 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200533 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200534 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200535 sourceCompatibility = JavaVersion.VERSION_1_7
536 targetCompatibility = JavaVersion.VERSION_1_7
537 options.compilerArgs += ["-Xlint:-options"]
538 }
539 examplesDir.eachDir { dir ->
540 def name = dir.getName();
541 def exampleOutputDir = file("build/test/examples");
542 def jarName = "${name}.jar"
543 dependsOn "jar_example_${name}"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200544 dependsOn "extractExamplesRuntime"
545 def runtimeDependencies = copySpec { }
546 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
547 // If we have any proto use, we have to include those classes and the runtime.
548 runtimeDependencies = copySpec {
549 from "$buildDir/runtime/examples/"
550 include "com/google/protobuf/**/*.class"
551 }
552 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200553 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
554 def proguardConfigPath = "${dir}/proguard.cfg"
555 if (new File(proguardConfigPath).exists()) {
556 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
557 archiveName = "${name}_pre_proguard.jar"
558 destinationDir = exampleOutputDir
559 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200560 include name + "/**/*.class"
561 with runtimeDependencies
562 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200563 }
564 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
565 def proguardJarPath = "${exampleOutputDir}/${jarName}"
566 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
567 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
568 inputs.files tasks.getByPath("pre_proguard_example_${name}")
569 inputs.file proguardConfigPath
570 // Enable these to get stdout and stderr redirected to files...
571 // standardOutput = new FileOutputStream('proguard.stdout')
572 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200573 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200574 " -outjars ${proguardJarPath}" +
575 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200576 " -printmapping ${proguardMapPath}"
577 if (OperatingSystem.current().isWindows()) {
578 executable "${proguardScript}"
579 args "${proguardArguments}"
580 } else {
581 executable "bash"
582 args "-c", "${proguardScript} '${proguardArguments}'"
583 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200584 outputs.file proguardJarPath
585 }
586 } else {
587 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
588 archiveName = jarName
589 destinationDir = exampleOutputDir
590 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200591 include name + "/**/*.class"
592 with runtimeDependencies
593 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200594 }
595 }
596 }
597}
598
599task buildExampleAndroidNJars {
600 dependsOn downloadDeps
601 def examplesDir = file("src/test/examplesAndroidN")
602 task "compile_examplesAndroidN"(type: JavaCompile) {
603 source = fileTree(dir: examplesDir, include: '**/*.java')
604 destinationDir = file("build/test/examplesAndroidN/classes")
605 classpath = sourceSets.main.compileClasspath
606 sourceCompatibility = JavaVersion.VERSION_1_8
607 targetCompatibility = JavaVersion.VERSION_1_8
608 options.compilerArgs += ["-Xlint:-options"]
609 }
610 examplesDir.eachDir { dir ->
611 def name = dir.getName();
612 def exampleOutputDir = file("build/test/examplesAndroidN");
613 def jarName = "${name}.jar"
614 dependsOn "jar_examplesAndroidN_${name}"
615 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
616 archiveName = jarName
617 destinationDir = exampleOutputDir
618 from "build/test/examplesAndroidN/classes"
619 include "**/" + name + "/**/*.class"
620 }
621 }
622}
623
624
625task buildExampleAndroidOJars {
626 dependsOn downloadDeps
627 def examplesDir = file("src/test/examplesAndroidO")
628 // NOTE: we want to enable a scenario when test needs to reference some
629 // classes generated by legacy (1.6) Java compiler to test some specific
630 // behaviour. To do so we compile all the java files located in sub-directory
631 // called 'legacy' with Java 1.6, then compile the rest of the files with
632 // Java 1.8 and a reference to previously generated 1.6 classes.
633
634 // Compiling all classes in dirs 'legacy' with old Java version.
635 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
636 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
637 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
638 classpath = sourceSets.main.compileClasspath
639 sourceCompatibility = JavaVersion.VERSION_1_6
640 targetCompatibility = JavaVersion.VERSION_1_6
641 options.compilerArgs += ["-Xlint:-options", "-parameters"]
642 }
643 // Compiling the rest of the files as Java 1.8 code.
644 task "compile_examplesAndroidO"(type: JavaCompile) {
645 dependsOn "compile_examplesAndroidO_Legacy"
646 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
647 destinationDir = file("build/test/examplesAndroidO/classes")
648 classpath = sourceSets.main.compileClasspath
649 classpath += files("build/test/examplesAndroidOLegacy/classes")
650 sourceCompatibility = JavaVersion.VERSION_1_8
651 targetCompatibility = JavaVersion.VERSION_1_8
652 options.compilerArgs += ["-Xlint:-options", "-parameters"]
653 }
654 examplesDir.eachDir { dir ->
655 def name = dir.getName();
656 def destinationDir = file("build/test/examplesAndroidO/classes");
657 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
658 task "generate_examplesAndroidO_${name}"(type: JavaExec,
659 dependsOn: "compile_examplesAndroidO") {
660 main = name + ".TestGenerator"
661 classpath = files(destinationDir, sourceSets.main.compileClasspath)
662 args destinationDir
663 }
664 } else {
665 task "generate_examplesAndroidO_${name}" () {}
666 }
667 }
668 examplesDir.eachDir { dir ->
669 def name = dir.getName();
670 def exampleOutputDir = file("build/test/examplesAndroidO");
671 def jarName = "${name}.jar"
672 dependsOn "jar_examplesAndroidO_${name}"
673 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
674 "generate_examplesAndroidO_${name}"]) {
675 archiveName = jarName
676 destinationDir = exampleOutputDir
677 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
678 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
679 include "**/" + name + "/**/*.class"
680 // Do not include generator into the test runtime jar, it is not useful.
681 // Otherwise, shrinking will need ASM jars.
682 exclude "**/TestGenerator*"
683 }
684 }
685}
686
687task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200688 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
689 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
690 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +0200691 } else if (!OperatingSystem.current().isLinux()) {
692 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200693 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +0200694 return;
695 }
696 dependsOn buildDebugTestResourcesJars
697 dependsOn buildExampleJars
698 dependsOn buildExampleAndroidNJars
699 dependsOn buildExampleAndroidOJars
700 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +0200701 def noDexTests = [
702 "multidex",
703 "multidex002",
704 "multidex004",
705 ]
Mads Ager418d1ca2017-05-22 09:35:49 +0200706 examplesDir.eachDir { dir ->
707 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +0200708 if (!(name in noDexTests)) {
709 dependsOn "dex_example_${name}"
710 def exampleOutputDir = file("build/test/examples/" + name);
711 def dexPath = file("${exampleOutputDir}")
712 def debug = (name == "throwing")
713 if (!dexPath.exists()) {
714 dexPath.mkdirs()
715 }
716 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
717 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
718 destination = dexPath
719 debug = debug
720 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200721 }
722 }
723}
724
725task buildSmali {
726 def smaliDir = file("src/test/smali")
727 smaliDir.eachDirRecurse() { dir ->
728 def name = dir.getName();
729 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
730 def smaliOutputDir = file("build/test/smali/" + relativeDir);
731 smaliOutputDir.mkdirs()
732 outputs.dir smaliOutputDir
733 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
734 def smaliFiles = fileTree(dir: dir, include: '*.smali')
735 def javaFiles = fileTree(dir: dir, include: '*.java')
736 def destDir = smaliOutputDir;
737 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
738 def intermediateFileName = "${name}-intermediate.dex";
739 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
740 if (javaFiles.empty) {
741 if (!smaliFiles.empty) {
742 dependsOn "${taskName}_smali"
743 task "${taskName}_smali"(type: smali.Smali) {
744 source = smaliFiles
745 destination = destFile
746 }
747 }
748 } else {
749 dependsOn "${taskName}_dexmerger"
750 task "${taskName}_smali"(type: smali.Smali) {
751 source = smaliFiles
752 destination = intermediateFile
753 }
754 task "${taskName}_java"(type: JavaCompile) {
755 source = javaFiles
756 destinationDir destDir
757 classpath = sourceSets.main.compileClasspath
758 sourceCompatibility = JavaVersion.VERSION_1_7
759 targetCompatibility = JavaVersion.VERSION_1_7
760 options.compilerArgs += ["-Xlint:-options"]
761 }
762 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
763 archiveName = "Test.jar"
764 destinationDir = destDir
765 from fileTree(dir: destDir, include: 'Test.class')
766 }
767 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
768 source = fileTree(dir: destDir, include: 'Test.jar')
769 destination = destDir
770 }
771 task "${taskName}_dexmerger"(
772 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
773 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
774 destination = destFile
775 }
776 }
777 }
778}
779
780tasks.withType(Test) {
781 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
782 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
783 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
784 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
785 forkEvery = 0
786 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
787 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +0200788 if (project.hasProperty('disable_assertions')) {
789 enableAssertions = false
790 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200791}
792
793task buildPreNJdwpTestsJar(type: Jar) {
794 baseName = 'jdwp-tests-preN'
795 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
796 // Exclude the classes containing java8
797 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
798 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
799 includeEmptyDirs = false
800}
801
Yohann Roussel126f6872017-08-03 16:25:32 +0200802task supportLibDir() {
803 doLast {
804 File dir = file("build/supportlibraries")
805 dir.mkdir()
806 }
807}
808
809configurations.supportLibs.files.each { file ->
810 if (file.getName().endsWith(".aar")) {
811 def name = "extract_"+file.getName()
812 task "${name}"(type: Copy) {
813 dependsOn supportLibDir
814 from zipTree(file)
815 into "build/supportlibraries"
816 eachFile { FileCopyDetails fcp ->
817 if (fcp.relativePath.pathString.equals("classes.jar")) {
818 // remap the file to the root with correct name
819 fcp.relativePath = new RelativePath(true, file.getName().replace(".aar", ".jar"))
820 } else {
821 fcp.exclude()
822 }
823 }
824 }
825 }
826}
827
828task supportLibList() {
829 configurations.supportLibs.files.each {
830 if (it.getName().endsWith(".aar")) {
831 dependsOn "extract_"+it.getName()
832 }
833 }
834 doLast {
Yohann Roussel630dfe12017-08-03 17:24:08 +0200835 file("build/generated").mkdir()
Yohann Roussel126f6872017-08-03 16:25:32 +0200836 def file = file("build/generated/supportlibraries.txt")
837 file.createNewFile()
838 file.text = ""
839 configurations.supportLibs.files.each {
840 if (it.getName().endsWith(".aar")) {
841 def outName = it.getName().replace(".aar", ".jar")
842 file.text += ("build/supportlibraries/"
843 + outName + "\n")
844 } else {
845 file.text += (it.getPath() + "\n")
846 }
847 }
848 }
849}
850
Mads Ager418d1ca2017-05-22 09:35:49 +0200851test {
Yohann Roussel126f6872017-08-03 16:25:32 +0200852 dependsOn supportLibList
Mads Ager418d1ca2017-05-22 09:35:49 +0200853 testLogging.exceptionFormat = 'full'
854 if (project.hasProperty('print_test_stdout')) {
855 testLogging.showStandardStreams = true
856 }
857 if (project.hasProperty('dex_vm')) {
858 println "Running with non default vm: " + project.property('dex_vm')
859 systemProperty 'dex_vm', project.property('dex_vm')
860 if (project.property('dex_vm') == '5.1.1' || project.property('dex_vm') == '6.0.1') {
861 // R8 and D8 compute the dex file version number based on the input.
862 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
863 // Therefore we skip the jack generated art tests with those art versions.
864 exclude "com/android/tools/r8/art/jack/**"
865 }
866 }
867 if (project.hasProperty('one_line_per_test')) {
868 beforeTest { desc ->
869 println "Start executing test ${desc.name} [${desc.className}]"
870 }
871 afterTest { desc, result ->
872 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
873 }
874 }
875 if (project.hasProperty('no_internal')) {
876 exclude "com/android/tools/r8/internal/**"
877 }
878 if (project.hasProperty('only_internal')) {
879 include "com/android/tools/r8/internal/**"
880 }
881 if (project.hasProperty('tool')) {
882 if (project.property('tool') == 'r8') {
883 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +0200884 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +0200885 } else {
886 assert(project.property('tool') == 'd8')
887 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +0200888 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +0200889 }
890 }
891 if (!project.hasProperty('all_tests')) {
892 exclude "com/android/tools/r8/art/dx/**"
893 exclude "com/android/tools/r8/art/jack/**"
894 }
895 // TODO(tamaskenez) enable jctf on all_tests when consolidated
896 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200897 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +0200898 }
899 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200900 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +0200901 }
902 if (project.hasProperty('jctf_compile_only')) {
903 println "JCTF: compiling only"
904 systemProperty 'jctf_compile_only', '1'
905 }
906
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200907 if (OperatingSystem.current().isLinux()
908 || OperatingSystem.current().isMacOsX()
909 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200910 if (OperatingSystem.current().isMacOsX()) {
911 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
912 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
913 "See tools/docker/README.md for details.")
914 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200915 if (OperatingSystem.current().isWindows()) {
916 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
917 "Art only runs on Linux and tests requiring Art will be skipped")
918 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200919 dependsOn downloadDeps
920 dependsOn buildExamples
921 dependsOn buildSmali
922 dependsOn jctfCommonJar
923 dependsOn jctfTestsClasses
924 dependsOn buildDebugInfoExamplesDex
925 dependsOn buildPreNJdwpTestsJar
926 } else {
927 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200928 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +0200929 }
930}
931
932// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
933//
934// To build and upload a new set of the Art tests for use with R8 follow these steps:
935//
936// First of all an Android checkout is required. Currently it must be located
937// in $HOME/android/master.
938//
939// TODO(ricow): simplify this
940//
941// Before: update the checked in art, see scripts/update-host-art.sh
942//
943// 1. Get an android checkout in $HOME/android/master and apply the patch from
944// https://android-review.googlesource.com/#/c/294187/
945//
946// 2. run the following commands in the Android checkout directory:
947//
948// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +0200949// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
950// m desugar
951// m -j30 test-art-host
952// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
953//
954// Without running the test.py command the classes.jar file used by desugar in
955// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
956// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +0200957//
958// 3. In the R8 project root directory, make sure we have a clean state before starting:
959// tools/gradle.py downloadDeps
960// tools/gradle.py clean
961// rm -rf tests/art
962//
963// 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 +0200964// Make sure you have smali on your path, please use the build binary in the
965// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
966// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
967// need to change as smali got a completely new command line interface in version 2.2.1.
Mads Ager418d1ca2017-05-22 09:35:49 +0200968//
Søren Gjesse34b77732017-07-07 13:56:21 +0200969// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +0200970//
971// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
972// skippedTests with an explanation. Rerun from step 3.
973//
974// 5. Run the tests:
975// tools/gradle.py clean
976// tools/test.py
977//
Søren Gjesse34b77732017-07-07 13:56:21 +0200978// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
979// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
980// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +0200981//
Søren Gjesse34b77732017-07-07 13:56:21 +0200982// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +0200983// cd tests
984// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +0200985//
986// 7. Update the manifest file describing the Android repo used:
987// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +0200988
989enum DexTool {
990 JACK,
991 DX
992}
993
994def androidCheckoutDir = file("${System.env.HOME}/android/master")
995def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
996def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
997
998def artTestDir = file("${androidCheckoutDir}/art/test")
999
1000if (project.hasProperty('android_source')) {
1001 task buildArtTests {
1002 outputs.upToDateWhen { false }
1003 def toBeTriaged = [
1004 "903-hello-tagging",
1005 "904-object-allocation",
1006 "905-object-free",
1007 "906-iterate-heap",
1008 "907-get-loaded-classes",
1009 "908-gc-start-finish",
1010 "954-invoke-polymorphic-verifier",
1011 "955-methodhandles-smali",
1012 "596-monitor-inflation",
1013 ]
1014 def skippedTests = toBeTriaged + [
1015 // This test produces no jar.
1016 "000-nop",
1017 // This does not build, as it tests the error when the application exceeds more
1018 // than 65536 methods
1019 "089-many-methods",
1020 // Requires some jack beta jar
1021 "956-methodhandles",
1022 ]
1023
1024 def skippedTestsDx = [
1025 // Tests with custom build scripts, where javac is not passed the options
1026 // -source 1.7 -target 1.7.
1027 "462-checker-inlining-across-dex-files",
1028 "556-invoke-super",
1029 "569-checker-pattern-replacement",
1030 // These tests use jack even when --build-with-javac-dx is specified.
1031 "004-JniTest",
1032 "048-reflect-v8",
1033 "146-bad-interface",
1034 "563-checker-invoke-super",
1035 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1036 "604-hot-static-interface",
1037 "957-methodhandle-transforms",
1038 "958-methodhandle-emulated-stackframe",
1039 "959-invoke-polymorphic-accessors",
1040 "961-default-iface-resolution-gen",
1041 "962-iface-static",
1042 "963-default-range-smali",
1043 "964-default-iface-init-gen",
1044 "965-default-verify",
1045 "966-default-conflict",
1046 "967-default-ame",
1047 "968-default-partial-compile-gen",
1048 "969-iface-super",
1049 "970-iface-super-resolution-gen",
1050 "971-iface-super",
1051 // These tests does not build with --build-with-javac-dx
1052 "004-NativeAllocations", // Javac error
1053 "031-class-attributes",
1054 "138-duplicate-classes-check",
1055 "157-void-class", // Javac error
1056 "580-checker-string-factory-intrinsics",
1057 "612-jit-dex-cache",
1058 "613-inlining-dex-cache",
1059 "900-hello-plugin", // --experimental agents
1060 "901-hello-ti-agent", // --experimental agents
1061 "902-hello-transformation", // --experimental agents
1062 "909-attach-agent", // --experimental agents
1063 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1064 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1065 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1066 "960-default-smali", // --experimental default-methods
1067 // These tests force the build to use jack
1068 "953-invoke-polymorphic-compiler",
1069 "958-methodhandle-stackframe",
1070 ]
1071
1072 def artTestBuildDir = file("${projectDir}/tests/art")
1073
1074 if (androidCheckoutDir.exists()) {
1075 dependsOn downloadDeps
1076 artTestBuildDir.mkdirs()
1077 // Ensure Jack server is running.
1078 "${androidCheckoutJackServer} start-server".execute()
1079 artTestDir.eachDir { dir ->
1080 def name = dir.getName();
1081 def markerFile = dir.toPath().resolve("info.txt").toFile();
1082 if (markerFile.exists() && !(name in skippedTests)) {
1083 if (!(name in skippedTestsDx)) {
1084 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1085 }
1086 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
1087 }
1088 }
1089 }
1090 doFirst {
1091 if (!androidCheckoutDir.exists()) {
1092 throw new InvalidUserDataException(
1093 "This task requires an Android checkout in ${androidCheckoutDir}");
1094 } else if (!androidCheckoutJack.exists() ||
1095 !androidCheckoutJackServer.exists()) {
1096 throw new InvalidUserDataException(
1097 "This task requires that tools for host testing have been build in the " +
1098 "Android checkout in ${androidCheckoutDir}");
1099 }
1100 }
1101 doLast {
1102 copy {
1103 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1104 into file("${artTestBuildDir}/lib64")
1105 include 'lib*.so'
1106 }
1107 copy {
1108 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1109 into file("${artTestBuildDir}/lib64")
1110 include 'libart.so'
1111 include 'libbacktrace.so'
1112 include 'libbase.so'
1113 include 'libc++.so'
1114 include 'libcutils.so'
1115 include 'liblz4.so'
1116 include 'liblzma.so'
1117 include 'libnativebridge.so'
1118 include 'libnativeloader.so'
1119 include 'libsigchain.so'
1120 include 'libunwind.so'
1121 include 'libziparchive.so'
1122 }
1123 copy {
1124 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1125 into file("${artTestBuildDir}/lib")
1126 include 'lib*.so'
1127 }
1128 copy {
1129 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1130 into file("${artTestBuildDir}/lib")
1131 include 'libart.so'
1132 include 'libbacktrace.so'
1133 include 'libbase.so'
1134 include 'libc++.so'
1135 include 'libcutils.so'
1136 include 'liblz4.so'
1137 include 'liblzma.so'
1138 include 'libnativebridge.so'
1139 include 'libnativeloader.so'
1140 include 'libsigchain.so'
1141 include 'libunwind.so'
1142 include 'libziparchive.so'
1143 }
1144 }
1145 }
1146}
1147
1148def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1149 def artTestDir = file("${androidCheckoutDir}/art/test")
1150 def artRunTestScript = file("${artTestDir}/run-test")
1151 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001152 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001153 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1154
Søren Gjesse34b77732017-07-07 13:56:21 +02001155 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001156 def buildTask = "build_art_test_${dexToolName}_${name}"
1157 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1158 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1159 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1160
1161 def buildInputs = fileTree(dir: dir, include: '**/*')
1162 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1163 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1164 testDir.mkdirs()
1165 if (dexTool == DexTool.DX) {
1166 task "$buildTask"(type: Exec) {
1167 outputs.upToDateWhen { false }
1168 inputs.file buildInputs
1169 executable "${artRunTestScript}"
1170 args "--host"
1171 args "--build-only"
1172 args "--build-with-javac-dx"
1173 args "--output-path", "${testDir}"
1174 args "${name}"
1175 environment DX: "${dxExecutable.absolutePath}"
1176 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001177 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001178 outputs.file outputJar
1179 }
1180 } else {
1181 assert dexTool == DexTool.JACK
1182 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1183 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1184 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1185 task "$buildTask"(type: Exec) {
1186 outputs.upToDateWhen { false }
1187 inputs.file buildInputs
1188 executable "${artRunTestScript}"
1189 args "--host"
1190 args "--build-only"
1191 args "--output-path", "${testDir}"
1192 args "${name}"
1193 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1194 environment JACK_CLASSPATH: jackClasspath
1195 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1196 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1197 outputs.file outputJar
1198 }
1199 }
1200 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1201 outputs.upToDateWhen { false }
1202 executable "/bin/bash"
1203 args "-c"
1204 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1205 " ${testDir}/classes-ex ${testDir}/check"
1206 }
1207
1208 task "${smaliToDexTask}"(type: Exec) {
1209 workingDir "${testDir}/smali"
1210 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001211 // This is the command line options for smali prior to 2.2.1, where smali got a new
1212 // command line interface.
1213 args "-c", "smali a *.smali"
1214 // This is the command line options for smali 2.2.1 and later.
1215 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001216 }
1217
1218 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1219 def smali_dir = file("${dir}/smali")
1220 outputs.upToDateWhen { false }
1221 if (smali_dir.exists() && dexTool == DexTool.DX) {
1222 dependsOn smaliToDexTask
1223 }
1224 from("${artTestDir}/${name}") {
1225 include 'check'
1226 }
1227 into testDir
1228 }
1229
1230 return copyCheckTask
1231}
1232
1233task javadocD8(type: Javadoc) {
1234 classpath = sourceSets.main.compileClasspath
1235 source = sourceSets.main.allJava
1236 include '**/com/android/tools/r8/BaseCommand.java'
1237 include '**/com/android/tools/r8/BaseOutput.java'
1238 include '**/com/android/tools/r8/CompilationException.java'
1239 include '**/com/android/tools/r8/CompilationMode.java'
1240 include '**/com/android/tools/r8/D8.java'
1241 include '**/com/android/tools/r8/D8Command.java'
1242 include '**/com/android/tools/r8/D8Output.java'
1243 include '**/com/android/tools/r8/Resource.java'
1244}