blob: c38343b6d768920b59833d51600482052c3604cb [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
Sebastien Hertz143ed112018-02-13 14:26:41 +010028ext {
29 androidSupportVersion = '25.4.0'
30 apacheCommonsVersion = '1.12'
31 asmVersion = '6.0'
32 autoValueVersion = '1.5'
33 espressoVersion = '3.0.0'
34 fastutilVersion = '7.2.0'
35 guavaVersion = '23.0'
36 joptSimpleVersion = '4.6'
37 jsonSimpleVersion = '1.1'
38 junitVersion = '4.12'
Sebastien Hertz6ebe39a2018-03-06 16:17:58 +010039 kotlinVersion = '1.2.30'
Sebastien Hertz143ed112018-02-13 14:26:41 +010040 protobufVersion = '3.0.0'
41 smaliVersion = '2.2b4'
42}
43
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020044def errorProneConfiguration = [
45 '-XepDisableAllChecks',
46 // D8 want to use reference equality, thus disable the checker explicitly
47 '-Xep:ReferenceEquality:OFF',
Stephan Herhute4d101c2017-11-22 12:18:02 +010048 '-Xep:ClassCanBeStatic:ERROR',
49 '-Xep:OperatorPrecedence:ERROR',
50 '-Xep:RemoveUnusedImports:ERROR',
51 '-Xep:MissingOverride:ERROR',
Stephan Herhute4d101c2017-11-22 12:18:02 +010052 '-Xep:IntLongMath:ERROR',
53 '-Xep:EqualsHashCode:ERROR',
54 '-Xep:InconsistentOverloads:ERROR',
55 '-Xep:ArrayHashCode:ERROR',
56 '-Xep:EqualsIncompatibleType:ERROR',
57 '-Xep:NonOverridingEquals:ERROR',
58 '-Xep:FallThrough:ERROR',
59 '-Xep:MissingCasesInEnumSwitch:ERROR',
60 '-Xep:MissingDefault:ERROR',
61 '-Xep:MultipleTopLevelClasses:ERROR',
62 '-Xep:NarrowingCompoundAssignment:ERROR',
63 '-Xep:BoxedPrimitiveConstructor:ERROR']
Mads Ager418d1ca2017-05-22 09:35:49 +020064
65apply from: 'copyAdditionalJctfCommonFiles.gradle'
66
Sebastien Hertze2687b62017-07-25 11:16:04 +020067
68if (project.hasProperty('with_code_coverage')) {
69 apply plugin: 'jacoco'
70}
71
Mads Ager418d1ca2017-05-22 09:35:49 +020072repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020073 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020074 mavenCentral()
75}
76
Stephan Herhut417a72a2017-07-18 10:38:30 +020077buildscript {
78 repositories {
79 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020080 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020081 maven {
82 url "https://plugins.gradle.org/m2/"
83 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020084 }
85 dependencies {
86 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'
Yohann Roussel7f47c032017-09-14 12:19:06 +020087 classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0'
Mads Ager247bdec2018-04-26 13:52:07 +020088 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.3'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020089 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020090 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Stephan Herhut417a72a2017-07-18 10:38:30 +020091 }
92}
93
Mads Ager418d1ca2017-05-22 09:35:49 +020094// Custom source set for example tests and generated tests.
95sourceSets {
96 test {
97 java {
98 srcDirs = [
99 'src/test/java',
100 'build/generated/test/java',
101 ]
102 }
103 }
Mads Ager22847672017-11-14 09:59:26 +0100104 bsPatch {
105 java {
106 srcDirs = [
107 'src/bspatch/java',
108 'src/main/java'
109 ]
110 }
111 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100112 apiUsageSample {
113 java {
114 srcDirs = ['src/test/apiUsageSample']
115 }
116 output.resourcesDir = 'build/classes/apiUsageSample'
117 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200118 debugTestResources {
119 java {
120 srcDirs = ['src/test/debugTestResources']
121 }
122 output.resourcesDir = 'build/classes/debugTestResources'
123 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200124 debugTestResourcesJava8 {
125 java {
126 srcDirs = ['src/test/debugTestResourcesJava8']
127 }
128 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
129 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200130 debugTestResourcesKotlin {
131 java {
132 srcDirs = ['src/test/debugTestResourcesKotlin']
133 }
134 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
135 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200136 examples {
137 java {
Stephan Herhut417a72a2017-07-18 10:38:30 +0200138 srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ]
139 }
140 proto {
141 srcDirs = [
142 'src/test/examples',
143 ]
Mads Ager418d1ca2017-05-22 09:35:49 +0200144 }
145 output.resourcesDir = 'build/classes/examples'
146 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100147 examplesKotlin {
148 java {
149 srcDirs = ['src/test/examplesKotlin']
150 }
151 output.resourcesDir = 'build/classes/examplesKotlin'
152 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200153 examplesAndroidN {
154 java {
155 srcDirs = ['src/test/examplesAndroidN']
156 }
157 output.resourcesDir = 'build/classes/examplesAndroidN'
158 }
159 examplesAndroidO {
160 java {
161 srcDirs = ['src/test/examplesAndroidO']
162 }
163 output.resourcesDir = 'build/classes/examplesAndroidO'
164 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200165 examplesAndroidP {
166 java {
167 srcDirs = ['src/test/examplesAndroidP']
168 }
169 output.resourcesDir = 'build/classes/examplesAndroidP'
170 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200171 jctfCommon {
172 java {
173 srcDirs = [
174 'third_party/jctf/Harness/src',
175 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
176 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
177 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
178 'third_party/jctf/LibTests/src/org',
179 'build/additionalJctfCommonFiles'
180 ]
181 }
182 resources {
183 srcDirs = ['third_party/jctf/LibTests/resources']
184 }
185 }
186 jctfTests {
187 java {
188 srcDirs = [
189 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
190 // 'third_party/jctf/VMTests/src',
191 ]
192 }
193 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100194 kotlinR8TestResources {
195 java {
196 srcDirs = ['src/test/kotlinR8TestResources']
197 }
198 output.resourcesDir = 'build/classes/kotlinR8TestResources'
199 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200200}
201
Yohann Roussel126f6872017-08-03 16:25:32 +0200202configurations {
203 supportLibs
204}
205
Mads Ager418d1ca2017-05-22 09:35:49 +0200206dependencies {
Sebastien Hertz143ed112018-02-13 14:26:41 +0100207 compile "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
208 compile "com.googlecode.json-simple:json-simple:$jsonSimpleVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200209 // Include all of guava when compiling the code, but exclude annotations that we don't
210 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100211 compileOnly("com.google.guava:guava:$guavaVersion")
212 compile("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200213 exclude group: 'com.google.errorprone'
214 exclude group: 'com.google.code.findbugs'
215 exclude group: 'com.google.j2objc'
216 exclude group: 'org.codehaus.mojo'
217 })
Sebastien Hertz143ed112018-02-13 14:26:41 +0100218 compile group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
219 compile group: 'org.ow2.asm', name: 'asm', version: asmVersion
220 compile group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
221 compile group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
222 compile group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
223 compile group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200224 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100225 testCompile "junit:junit:$junitVersion"
226 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200227 testCompile files('third_party/jasmin/jasmin-2.4.jar')
228 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200229 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100230 bsPatchCompile "org.apache.commons:commons-compress:$apacheCommonsVersion"
231 jctfCommonCompile "junit:junit:$junitVersion"
232 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200233 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100234 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
235 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200236 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100237 examplesCompile "com.google.guava:guava:$guavaVersion"
238 examplesCompile "com.google.protobuf:protobuf-lite:$protobufVersion"
239 examplesCompileOnly "com.google.auto.value:auto-value:$autoValueVersion"
240 examplesRuntime "com.google.protobuf:protobuf-lite:$protobufVersion"
241 supportLibs "com.android.support:support-v4:$androidSupportVersion"
242 supportLibs "junit:junit:$junitVersion"
243 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100244 apiUsageSampleCompile sourceSets.main.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100245 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
246 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
247 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
248 apt "com.google.auto.value:auto-value:$autoValueVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200249}
250
Mads Ager22847672017-11-14 09:59:26 +0100251configurations.bsPatchCompile.extendsFrom configurations.compile
252
Yohann Roussel7f47c032017-09-14 12:19:06 +0200253licenseTools {
254 licensesYaml = file('LIBRARY-LICENSE')
255}
256
Stephan Herhut417a72a2017-07-18 10:38:30 +0200257protobuf {
258 protoc {
259 // Download from repositories
Sebastien Hertz143ed112018-02-13 14:26:41 +0100260 artifact = "com.google.protobuf:protoc:$protobufVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200261 }
262 plugins {
263 javalite {
Sebastien Hertz143ed112018-02-13 14:26:41 +0100264 artifact = "com.google.protobuf:protoc-gen-javalite:$protobufVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200265 }
266 }
267 generateProtoTasks {
268 all().each { task ->
269 task.builtins {
270 // Disable the java code generator, as we want javalite only.
271 remove java
272 }
273 task.plugins {
274 javalite {}
275 }
276 }
277 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200278}
279
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200280def osString = OperatingSystem.current().isLinux() ? "linux" :
281 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200282
283def cloudDependencies = [
284 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200285 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200286 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200287 ],
288 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200289 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100290 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200291 "android_jar/lib-v19",
292 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100293 "android_jar/lib-v22",
294 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200295 "android_jar/lib-v24",
296 "android_jar/lib-v25",
297 "android_jar/lib-v26",
298 "proguard/proguard5.2.1",
Søren Gjessef631f482018-03-07 11:15:19 +0100299 "proguard/proguard6.0.1",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200300 "gradle/gradle",
301 "jdwp-tests",
302 "jasmin",
303 "jctf",
304 "kotlin",
305 "android_cts_baseline",
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200306 "ddmlib",
Søren Gjessec9b3fc72018-02-09 15:44:54 +0100307 "core-lambda-stubs",
Mathias Rav5285faf2018-03-20 14:16:32 +0100308 "openjdk/openjdk-rt-1.8",
Mathias Rav891831f2018-04-26 14:51:18 +0200309 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200310 ],
311 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
312 // container on other platforms where supported.
313 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200314 "linux/art",
315 "linux/art-5.1.1",
316 "linux/art-6.0.1",
317 "linux/art-7.0.0",
318 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100319 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200320 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200321 ]
322]
323
324cloudDependencies.each { entry ->
325 entry.value.each { entryFile ->
326 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200327 def outputDir = "${entry.key}/${entryFile}"
328 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200329 def sha1File = "${gzFile}.sha1"
330 inputs.file sha1File
331 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200332 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200333 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
334 if (OperatingSystem.current().isWindows()) {
335 executable "download_from_google_storage.bat"
336 args dlFromStorageArgs
337 } else {
338 executable "bash"
339 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
340 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200341 }
342 }
343}
344
345def x20Dependencies = [
346 "third_party": [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200347 "gmail/gmail_android_170604.16",
348 "gmscore/v4",
349 "gmscore/v5",
350 "gmscore/v6",
351 "gmscore/v7",
352 "gmscore/v8",
353 "gmscore/gmscore_v9",
354 "gmscore/gmscore_v10",
355 "gmscore/latest",
356 "photos/2017-06-06",
357 "youtube/youtube.android_12.10",
358 "youtube/youtube.android_12.17",
359 "youtube/youtube.android_12.22",
360 "proguardsettings",
361 "proguard/proguard_internal_159423826",
362 "framework",
363 "goyt",
Tamas Kenez80e4e392018-03-20 14:33:42 +0100364 "desugar/desugar_20180308"
Mads Ager418d1ca2017-05-22 09:35:49 +0200365 ],
366]
367
368x20Dependencies.each { entry ->
369 entry.value.each { entryFile ->
370 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200371 def outputDir = "${entry.key}/${entryFile}"
372 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200373 def sha1File = "${gzFile}.sha1"
374 inputs.file sha1File
375 outputs.file gzFile
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200376 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200377 executable "bash"
378 args "-c", "tools/download_from_x20.py ${sha1File}"
379 }
380 }
381}
382
Rico Wind897bb712017-05-23 10:44:29 +0200383task downloadProguard {
384 cloudDependencies.each { entry ->
385 entry.value.each { entryFile ->
386 if (entryFile.contains("proguard")) {
387 dependsOn "download_deps_${entry.key}/${entryFile}"
388 }
389 }
390 }
391}
392
Tamas Kenez427205b2017-06-29 15:57:09 +0200393task downloadDx {
394 cloudDependencies.each { entry ->
395 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200396 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200397 dependsOn "download_deps_${entry.key}/${entryFile}"
398 }
399 }
400 }
401}
402
Tamas Kenez0e10c562017-06-08 10:00:34 +0200403task downloadAndroidCts {
404 cloudDependencies.each { entry ->
405 entry.value.each { entryFile ->
406 if (entryFile.contains("android_cts_baseline")) {
407 dependsOn "download_deps_${entry.key}/${entryFile}"
408 }
409 }
410 }
411}
412
Mads Ager418d1ca2017-05-22 09:35:49 +0200413task downloadDeps {
414 cloudDependencies.each { entry ->
415 entry.value.each { entryFile ->
416 dependsOn "download_deps_${entry.key}/${entryFile}"
417 }
418 }
419 if (!project.hasProperty('no_internal')) {
420 x20Dependencies.each { entry ->
421 entry.value.each { entryFile ->
422 dependsOn "download_deps_${entry.key}/${entryFile}"
423 }
424 }
425 }
426}
427
428allprojects {
429 sourceCompatibility = JavaVersion.VERSION_1_8
430 targetCompatibility = JavaVersion.VERSION_1_8
431}
432
433tasks.withType(JavaCompile) {
434 options.compilerArgs << '-Xlint:unchecked'
435}
436
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200437if (!project.hasProperty('without_error_prone')) {
438 compileJava {
439 // Enable error prone for D8/R8 sources.
440 toolChain ErrorProneToolChain.create(project)
441 options.compilerArgs += errorProneConfiguration
442 }
443}
444
Mads Ager418d1ca2017-05-22 09:35:49 +0200445compileJctfCommonJava {
446 dependsOn 'copyAdditionalJctfCommonFiles'
447 options.compilerArgs = ['-Xlint:none']
448}
449
450compileJctfTestsJava {
451 dependsOn 'jctfCommonClasses'
452 options.compilerArgs = ['-Xlint:none']
453}
454
Yohann Roussel7f47c032017-09-14 12:19:06 +0200455task consolidatedLicense {
456 // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is
457 // corresponding to the effective list of embedded libraries.
458 dependsOn 'checkLicenses'
459 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
460 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
461 outputs.files license
462 doLast {
463 license.getParentFile().mkdirs()
464 license.createNewFile()
465 license.text = "This file lists all licenses for code distributed.\n"
466 license.text += "All non-library code has the following 3-Clause BSD license.\n"
467 license.text += "\n"
468 license.text += "\n"
469 license.text += file('LICENSE').text
470 license.text += "\n"
471 license.text += "\n"
472 license.text += "Summary of distributed libraries:\n"
473 license.text += "\n"
474 license.text += file('LIBRARY-LICENSE').text
475 license.text += "\n"
476 license.text += "\n"
477 license.text += "Licenses details:\n"
478 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
479 license.text += "\n"
480 license.text += "\n"
481 license.text += file.text
482 }
483 }
484}
485
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000486static configureRelocations(ShadowJar task) {
487 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
488 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
489 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
490 task.relocate('org.apache.commons', 'com.android.tools.r8.org.apache.commons')
491 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
492 task.relocate('org.json.simple', 'com.android.tools.r8.org.json.simple')
493 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
494}
495
496task repackageDeps(type: ShadowJar) {
497 configurations = [project.configurations.compile]
498 configureRelocations(it)
499 baseName 'deps'
500}
501
502task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200503 from sourceSets.main.output
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000504 configureRelocations(it)
505 baseName 'sources'
506}
507
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000508task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200509 from consolidatedLicense.outputs.files
510 exclude { path ->
511 path.getRelativePath().getPathString().startsWith("META-INF")
512 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200513 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200514 classifier = null
515 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200516 manifest {
517 attributes 'Main-Class': 'com.android.tools.r8.R8'
518 }
519 // In order to build without dependencies, pass the exclude_deps property using:
520 // gradle -Pexclude_deps R8
521 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800522 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000523 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800524 } else {
525 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200526 }
527}
528
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000529task D8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200530 from consolidatedLicense.outputs.files
531 exclude { path ->
532 path.getRelativePath().getPathString().startsWith("META-INF")
533 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200534 baseName 'd8'
mikaelpeltier80939312017-08-17 15:00:09 +0200535 classifier = null
536 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200537 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200538 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200539 }
540 // In order to build without dependencies, pass the exclude_deps property using:
541 // gradle -Pexclude_deps D8
542 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800543 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000544 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800545 } else {
546 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200547 }
548}
549
550task CompatDx(type: Jar) {
551 from sourceSets.main.output
552 baseName 'compatdx'
553 manifest {
554 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
555 }
556 // In order to build without dependencies, pass the exclude_deps property using:
557 // gradle -Pexclude_deps CompatDx
558 if (!project.hasProperty('exclude_deps')) {
559 // Also include dependencies
560 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
561 }
562}
563
Tamas Kenez73585922017-12-21 11:16:30 +0100564task DexFileMerger(type: Jar) {
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100565 from sourceSets.main.output
Tamas Kenez73585922017-12-21 11:16:30 +0100566 baseName 'dexfilemerger'
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100567 manifest {
Tamas Kenez73585922017-12-21 11:16:30 +0100568 attributes 'Main-Class': 'com.android.tools.r8.dexfilemerger.DexFileMerger'
Tamas Kenezeafa8c22017-12-14 09:53:44 +0100569 }
570 // In order to build without dependencies, pass the exclude_deps property using:
571 // gradle -Pexclude_deps CompatDx
572 if (!project.hasProperty('exclude_deps')) {
573 // Also include dependencies
574 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
575 }
576}
577
Rico Windb8580432018-02-05 15:12:41 +0100578task DexSplitter(type: Jar) {
579 from sourceSets.main.output
580 baseName 'dexsplitter'
581 manifest {
582 attributes 'Main-Class': 'com.android.tools.r8.dexsplitter.DexSplitter'
583 }
584 // In order to build without dependencies, pass the exclude_deps property using:
585 // gradle -Pexclude_deps CompatDx
586 if (!project.hasProperty('exclude_deps')) {
587 // Also include dependencies
588 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
589 }
590}
591
Søren Gjesse1d21da72017-09-01 12:05:38 +0200592task CompatProguard(type: Jar) {
593 from sourceSets.main.output
594 baseName 'compatproguard'
595 manifest {
596 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
597 }
598 // In order to build without dependencies, pass the exclude_deps property using:
599 // gradle -Pexclude_deps CompatProguard
600 if (!project.hasProperty('exclude_deps')) {
601 // Also include dependencies
602 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
603 }
604}
605
Tamas Kenez971eec62017-05-24 11:08:40 +0200606task D8Logger(type: Jar) {
607 from sourceSets.main.output
608 baseName 'd8logger'
609 manifest {
610 attributes 'Main-Class': 'com.android.tools.r8.D8Logger'
611 }
612 // In order to build without dependencies, pass the exclude_deps property using:
613 // gradle -Pexclude_deps D8Logger
614 if (!project.hasProperty('exclude_deps')) {
615 // Also include dependencies
616 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
617 }
618}
619
Mads Ager418d1ca2017-05-22 09:35:49 +0200620task disasm(type: Jar) {
621 from sourceSets.main.output
622 baseName 'disasm'
623 manifest {
624 attributes 'Main-Class': 'com.android.tools.r8.Disassemble'
625 }
626 // In order to build without dependencies, pass the exclude_deps property using:
627 // gradle -Pexclude_deps D8
628 if (!project.hasProperty('exclude_deps')) {
629 // Also include dependencies
630 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
631 }
632}
633
634task bisect(type: Jar) {
635 from sourceSets.main.output
636 baseName 'bisect'
637 manifest {
638 attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect'
639 }
640 // In order to build without dependencies, pass the exclude_deps property using:
641 // gradle -Pexclude_deps R8
642 if (!project.hasProperty('exclude_deps')) {
643 // Also include dependencies
644 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
645 }
646}
647
Lars Bak90c18042017-06-26 14:21:08 +0200648task DexSegments(type: Jar) {
649 from sourceSets.main.output
650 baseName 'dexsegments'
651 manifest {
652 attributes 'Main-Class': 'com.android.tools.r8.DexSegments'
653 }
654 // In order to build without dependencies, pass the exclude_deps property using:
655 // gradle -Pexclude_deps DexSegments
656 if (!project.hasProperty('exclude_deps')) {
657 // Also include dependencies
658 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
659 }
660}
661
Søren Gjessec4e5e932017-09-04 17:01:23 +0200662task maindex(type: Jar) {
663 from sourceSets.main.output
664 baseName 'maindex'
665 manifest {
666 attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList'
667 }
668 // In order to build without dependencies, pass the exclude_deps property using:
669 // gradle -Pexclude_deps maindex
670 if (!project.hasProperty('exclude_deps')) {
671 // Also include dependencies
672 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
673 }
674}
675
Lars Bak44cef522017-08-10 16:02:39 +0200676task ExtractMarker(type: Jar) {
677 from sourceSets.main.output
678 baseName 'extractmarker'
679 manifest {
680 attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker'
681 }
682 // In order to build without dependencies, pass the exclude_deps property using:
683 // gradle -Pexclude_deps ExtractMarker
684 if (!project.hasProperty('exclude_deps')) {
685 // Also include dependencies
686 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
687 }
688}
689
Mads Ager22847672017-11-14 09:59:26 +0100690task bspatch(type: Jar) {
691 from sourceSets.bsPatch.output
692 baseName 'bspatch'
693 manifest {
694 attributes 'Main-Class': 'com.android.tools.r8.dex.BSPatch'
695 }
696 // In order to build without dependencies, pass the exclude_deps property using:
697 // gradle -Pexclude_deps maindex
698 if (!project.hasProperty('exclude_deps')) {
699 // Also include dependencies
700 from {
701 configurations.bsPatchCompile.collect { it.isDirectory() ? it : zipTree(it) }
702 }
703 }
704}
705
Mads Ager418d1ca2017-05-22 09:35:49 +0200706task sourceJar(type: Jar, dependsOn: classes) {
707 classifier = 'src'
708 from sourceSets.main.allSource
709}
710
711task jctfCommonJar(type: Jar) {
712 from sourceSets.jctfCommon.output
713 baseName 'jctfCommon'
714}
715
716artifacts {
717 archives sourceJar
718}
719
720task createArtTests(type: Exec) {
721 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200722 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200723 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200724 inputs.file createArtTestsScript
725 outputs.dir outputDir
726 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200727 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200728 workingDir = projectDir
729}
730
731task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200732 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200733 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200734 inputs.file script
735 outputs.dir outputDir
736 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200737 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200738 workingDir = projectDir
739}
740
741compileTestJava {
742 dependsOn createArtTests
743 dependsOn createJctfTests
744}
745
Ian Zernyee23a172018-01-03 09:08:48 +0100746task buildD8ApiUsageSample(type: Jar) {
747 from sourceSets.apiUsageSample.output
748 baseName 'd8_api_usage_sample'
749 destinationDir file('tests')
750}
751
Ian Zerny923a0c12018-01-03 10:59:18 +0100752task buildR8ApiUsageSample(type: Jar) {
753 from sourceSets.apiUsageSample.output
754 baseName 'r8_api_usage_sample'
755 destinationDir file('tests')
756}
757
Yohann Roussel548ae942018-01-05 11:13:28 +0100758task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100759 dependsOn buildD8ApiUsageSample
760 dependsOn buildR8ApiUsageSample
761}
762
Mads Ager418d1ca2017-05-22 09:35:49 +0200763task buildDebugInfoExamplesDex {
764 def examplesDir = file("src/test/java")
765 def hostJar = "debuginfo_examples.jar"
766 def hostDexJar = "debuginfo_examples_dex.jar"
767 task "compile_debuginfo_examples"(type: JavaCompile) {
768 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
769 destinationDir = file("build/test/debuginfo_examples/classes")
770 classpath = sourceSets.main.compileClasspath
771 sourceCompatibility = JavaVersion.VERSION_1_7
772 targetCompatibility = JavaVersion.VERSION_1_7
773 options.compilerArgs += ["-Xlint:-options"]
774 }
775 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
776 archiveName = hostJar
777 destinationDir = file("build/test/")
778 from "build/test/debuginfo_examples/classes"
779 include "**/*.class"
780 }
781 task "dex_debuginfo_examples"(type: Exec,
782 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200783 if (OperatingSystem.current().isWindows()) {
784 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700785 } else if (OperatingSystem.current().isMacOsX()) {
786 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200787 } else {
788 executable file("tools/linux/dx/bin/dx");
789 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200790 args "--dex"
791 args "--output=build/test/${hostDexJar}"
792 args "build/test/${hostJar}"
793 inputs.file file("build/test/${hostJar}")
794 outputs.file file("build/test/${hostDexJar}")
795 }
796 dependsOn dex_debuginfo_examples
797}
798
799task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200800 def resourcesDir = file("src/test/debugTestResources")
801 def hostJar = "debug_test_resources.jar"
802 task "compile_debugTestResources"(type: JavaCompile) {
803 source = fileTree(dir: resourcesDir, include: '**/*.java')
804 destinationDir = file("build/test/debugTestResources/classes")
805 classpath = sourceSets.main.compileClasspath
806 sourceCompatibility = JavaVersion.VERSION_1_7
807 targetCompatibility = JavaVersion.VERSION_1_7
808 options.compilerArgs += ["-g", "-Xlint:-options"]
809 }
810 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
811 archiveName = hostJar
812 destinationDir = file("build/test/")
813 from "build/test/debugTestResources/classes"
814 include "**/*.class"
815 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200816 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
817 def java8HostJar = "debug_test_resources_java8.jar"
818 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
819 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
820 destinationDir = file("build/test/debugTestResourcesJava8/classes")
821 classpath = sourceSets.main.compileClasspath
822 sourceCompatibility = JavaVersion.VERSION_1_8
823 targetCompatibility = JavaVersion.VERSION_1_8
824 options.compilerArgs += ["-g", "-Xlint:-options"]
825 }
826 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
827 archiveName = java8HostJar
828 destinationDir = file("build/test/")
829 from "build/test/debugTestResourcesJava8/classes"
830 include "**/*.class"
831 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200832 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000833 def kotlinHostJar = "debug_test_resources_kotlin.jar"
834 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
835 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
836 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200837 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200838 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200839 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200840 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000841 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200842}
843
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100844// Examples used by tests, where Android specific APIs are used.
845task buildExampleAndroidApi(type: JavaCompile) {
846 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
847 destinationDir = file("build/test/examplesAndroidApi/classes")
848 classpath = files("third_party/android_jar/lib-v26/android.jar")
849 sourceCompatibility = JavaVersion.VERSION_1_8
850 targetCompatibility = JavaVersion.VERSION_1_8
851}
852
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100853task buildExampleKotlinJars {
854 def kotlinSrcDir = file("src/test/examplesKotlin")
855 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000856 def name = dir.getName();
857 dependsOn "compile_example_kotlin_${name}"
858 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
859 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
860 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100861 }
862 }
863}
864
Lars Bakc91e87e2017-08-18 08:53:10 +0200865// Proto lite generated code yields warnings when compiling with javac.
866// We change the options passed to javac to ignore it.
867compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
868
Mads Ager418d1ca2017-05-22 09:35:49 +0200869task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200870 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200871 def examplesDir = file("src/test/examples")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200872 def protoSourceDir = file("build/generated/source/proto/examples/javalite")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200873 def proguardScript
874 if (OperatingSystem.current().isWindows()) {
875 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
876 } else {
877 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
878 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200879 task extractExamplesRuntime(type: Sync) {
880 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000881 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200882 include "**/*.class"
883 includeEmptyDirs false
884 into "$buildDir/runtime/examples/"
885 }
886
887 task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") {
888 source examplesDir, protoSourceDir
889 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200890 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200891 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200892 sourceCompatibility = JavaVersion.VERSION_1_7
893 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200894 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
895 }
896 task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") {
897 source examplesDir, protoSourceDir
898 include "**/*.java"
899 destinationDir = file("build/test/examples/classes_debuginfo_all")
900 classpath = sourceSets.examples.compileClasspath
901 sourceCompatibility = JavaVersion.VERSION_1_7
902 targetCompatibility = JavaVersion.VERSION_1_7
903 options.compilerArgs = ["-g", "-Xlint:none"]
904 }
905 task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") {
906 source examplesDir, protoSourceDir
907 include "**/*.java"
908 destinationDir = file("build/test/examples/classes_debuginfo_none")
909 classpath = sourceSets.examples.compileClasspath
910 sourceCompatibility = JavaVersion.VERSION_1_7
911 targetCompatibility = JavaVersion.VERSION_1_7
912 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200913 }
914 examplesDir.eachDir { dir ->
915 def name = dir.getName();
916 def exampleOutputDir = file("build/test/examples");
917 def jarName = "${name}.jar"
918 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200919 dependsOn "jar_example_${name}_debuginfo_all"
920 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200921 dependsOn "extractExamplesRuntime"
922 def runtimeDependencies = copySpec { }
923 if (!fileTree(dir: dir, include: '**/*.proto').empty) {
924 // If we have any proto use, we have to include those classes and the runtime.
925 runtimeDependencies = copySpec {
926 from "$buildDir/runtime/examples/"
927 include "com/google/protobuf/**/*.class"
928 }
929 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200930 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
931 def proguardConfigPath = "${dir}/proguard.cfg"
932 if (new File(proguardConfigPath).exists()) {
933 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
934 archiveName = "${name}_pre_proguard.jar"
935 destinationDir = exampleOutputDir
936 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200937 include name + "/**/*.class"
938 with runtimeDependencies
939 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200940 }
941 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
942 def proguardJarPath = "${exampleOutputDir}/${jarName}"
943 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
944 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
945 inputs.files tasks.getByPath("pre_proguard_example_${name}")
946 inputs.file proguardConfigPath
947 // Enable these to get stdout and stderr redirected to files...
948 // standardOutput = new FileOutputStream('proguard.stdout')
949 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200950 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +0200951 " -outjars ${proguardJarPath}" +
952 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200953 " -printmapping ${proguardMapPath}"
954 if (OperatingSystem.current().isWindows()) {
955 executable "${proguardScript}"
956 args "${proguardArguments}"
957 } else {
958 executable "bash"
959 args "-c", "${proguardScript} '${proguardArguments}'"
960 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200961 outputs.file proguardJarPath
962 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200963 // TODO: Consider performing distinct proguard compilations.
964 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
965 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200966 into "${exampleOutputDir}"
967 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200968 }
969 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
970 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +0200971 into "${exampleOutputDir}"
972 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200973 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200974 } else {
975 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200976 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +0200977 destinationDir = exampleOutputDir
978 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200979 include name + "/**/*.class"
980 with runtimeDependencies
981 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200982 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200983 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
984 archiveName = "${name}_debuginfo_all.jar"
985 destinationDir = exampleOutputDir
986 from "build/test/examples/classes_debuginfo_all"
987 include name + "/**/*.class"
988 with runtimeDependencies
989 includeEmptyDirs false
990 }
991 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
992 archiveName = "${name}_debuginfo_none.jar"
993 destinationDir = exampleOutputDir
994 from "build/test/examples/classes_debuginfo_none"
995 include name + "/**/*.class"
996 with runtimeDependencies
997 includeEmptyDirs false
998 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200999 }
1000 }
1001}
1002
1003task buildExampleAndroidNJars {
1004 dependsOn downloadDeps
1005 def examplesDir = file("src/test/examplesAndroidN")
1006 task "compile_examplesAndroidN"(type: JavaCompile) {
1007 source = fileTree(dir: examplesDir, include: '**/*.java')
1008 destinationDir = file("build/test/examplesAndroidN/classes")
1009 classpath = sourceSets.main.compileClasspath
1010 sourceCompatibility = JavaVersion.VERSION_1_8
1011 targetCompatibility = JavaVersion.VERSION_1_8
1012 options.compilerArgs += ["-Xlint:-options"]
1013 }
1014 examplesDir.eachDir { dir ->
1015 def name = dir.getName();
1016 def exampleOutputDir = file("build/test/examplesAndroidN");
1017 def jarName = "${name}.jar"
1018 dependsOn "jar_examplesAndroidN_${name}"
1019 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1020 archiveName = jarName
1021 destinationDir = exampleOutputDir
1022 from "build/test/examplesAndroidN/classes"
1023 include "**/" + name + "/**/*.class"
1024 }
1025 }
1026}
1027
1028
1029task buildExampleAndroidOJars {
1030 dependsOn downloadDeps
1031 def examplesDir = file("src/test/examplesAndroidO")
1032 // NOTE: we want to enable a scenario when test needs to reference some
1033 // classes generated by legacy (1.6) Java compiler to test some specific
1034 // behaviour. To do so we compile all the java files located in sub-directory
1035 // called 'legacy' with Java 1.6, then compile the rest of the files with
1036 // Java 1.8 and a reference to previously generated 1.6 classes.
1037
1038 // Compiling all classes in dirs 'legacy' with old Java version.
1039 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1040 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1041 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1042 classpath = sourceSets.main.compileClasspath
1043 sourceCompatibility = JavaVersion.VERSION_1_6
1044 targetCompatibility = JavaVersion.VERSION_1_6
1045 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1046 }
1047 // Compiling the rest of the files as Java 1.8 code.
1048 task "compile_examplesAndroidO"(type: JavaCompile) {
1049 dependsOn "compile_examplesAndroidO_Legacy"
1050 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1051 destinationDir = file("build/test/examplesAndroidO/classes")
1052 classpath = sourceSets.main.compileClasspath
1053 classpath += files("build/test/examplesAndroidOLegacy/classes")
1054 sourceCompatibility = JavaVersion.VERSION_1_8
1055 targetCompatibility = JavaVersion.VERSION_1_8
1056 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1057 }
1058 examplesDir.eachDir { dir ->
1059 def name = dir.getName();
1060 def destinationDir = file("build/test/examplesAndroidO/classes");
1061 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1062 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1063 dependsOn: "compile_examplesAndroidO") {
1064 main = name + ".TestGenerator"
1065 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1066 args destinationDir
1067 }
1068 } else {
1069 task "generate_examplesAndroidO_${name}" () {}
1070 }
1071 }
1072 examplesDir.eachDir { dir ->
1073 def name = dir.getName();
1074 def exampleOutputDir = file("build/test/examplesAndroidO");
1075 def jarName = "${name}.jar"
1076 dependsOn "jar_examplesAndroidO_${name}"
1077 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1078 "generate_examplesAndroidO_${name}"]) {
1079 archiveName = jarName
1080 destinationDir = exampleOutputDir
1081 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1082 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1083 include "**/" + name + "/**/*.class"
1084 // Do not include generator into the test runtime jar, it is not useful.
1085 // Otherwise, shrinking will need ASM jars.
1086 exclude "**/TestGenerator*"
1087 }
1088 }
1089}
1090
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001091task buildExampleAndroidPJars {
1092 dependsOn downloadDeps
1093 def examplesDir = file("src/test/examplesAndroidP")
1094
1095 task "compile_examplesAndroidP"(type: JavaCompile) {
1096 source = fileTree(dir: examplesDir, include: '**/*.java')
1097 destinationDir = file("build/test/examplesAndroidP/classes")
1098 classpath = sourceSets.main.compileClasspath
1099 sourceCompatibility = JavaVersion.VERSION_1_8
1100 targetCompatibility = JavaVersion.VERSION_1_8
1101 options.compilerArgs += ["-Xlint:-options"]
1102 }
1103 examplesDir.eachDir { dir ->
1104 def name = dir.getName();
1105 def destinationDir = file("build/test/examplesAndroidP/classes");
1106 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1107 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1108 dependsOn: "compile_examplesAndroidP") {
1109 main = name + ".TestGenerator"
1110 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1111 args destinationDir
1112 }
1113 } else {
1114 task "generate_examplesAndroidP_${name}" () {}
1115 }
1116 }
1117 examplesDir.eachDir { dir ->
1118 def name = dir.getName();
1119 def exampleOutputDir = file("build/test/examplesAndroidP");
1120 def jarName = "${name}.jar"
1121 dependsOn "jar_examplesAndroidP_${name}"
1122 task "jar_examplesAndroidP_${name}"(type: Jar,
1123 dependsOn: ["compile_examplesAndroidP",
1124 "generate_examplesAndroidP_${name}"]) {
1125 archiveName = jarName
1126 destinationDir = exampleOutputDir
1127 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1128 include "**/" + name + "/**/*.class"
1129 // Do not include generator into the test runtime jar, it is not useful.
1130 // Otherwise, shrinking will need ASM jars.
1131 exclude "**/TestGenerator*"
1132 }
1133 }
1134}
1135
Mikaël Peltier61633d42017-10-13 16:51:06 +02001136task buildExampleJava9Jars {
1137 def examplesDir = file("src/test/examplesJava9")
1138 examplesDir.eachDir { dir ->
1139 def name = dir.getName();
1140 def exampleOutputDir = file("build/test/examplesJava9");
1141 def jarName = "${name}.jar"
1142 dependsOn "jar_examplesJava9_${name}"
1143 task "jar_examplesJava9_${name}"(type: Jar) {
1144 archiveName = jarName
1145 destinationDir = exampleOutputDir
1146 from "src/test/examplesJava9" // Java 1.9 classes
1147 include "**/" + name + "/**/*.class"
1148 }
1149 }
1150}
1151
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001152task buildExamplesKotlin {
1153 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1154 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1155 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1156 } else if (!OperatingSystem.current().isLinux()) {
1157 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1158 "on your platform. It is fully supported on Linux and partially supported on " +
1159 "Mac OS and Windows")
1160 return;
1161 }
1162 def examplesDir = file("src/test/examplesKotlin")
1163 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001164 def name = dir.getName();
1165 dependsOn "dex_example_kotlin_${name}"
1166 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1167 def dexPath = file("${exampleOutputDir}")
1168 task "dex_example_kotlin_${name}"(type: dx.Dx,
1169 dependsOn: "compile_example_kotlin_${name}") {
1170 doFirst {
1171 if (!dexPath.exists()) {
1172 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001173 }
1174 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001175 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1176 destination = dexPath
1177 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001178 }
1179 }
1180}
1181
Sebastien Hertzd3313772018-01-16 14:12:37 +01001182task buildKotlinR8TestResources {
1183 def examplesDir = file("src/test/kotlinR8TestResources")
1184 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001185 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1186 def name = dir.getName()
1187 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
1188 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
Denis Vnukovc22da842018-03-14 12:57:20 -07001189 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
1190 def javaOutputJarName = "${name}.java.jar"
1191 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
1192 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1193 source = fileTree(dir: file("${examplesDir}/${name}"),
1194 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001195 destination = file(outputFile)
1196 targetVersion = kotlinTargetVersion
1197 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001198 task "${taskName}Java"(type: JavaCompile) {
1199 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1200 destinationDir = file(javaOutput)
1201 classpath = sourceSets.main.compileClasspath
1202 sourceCompatibility = JavaVersion.VERSION_1_6
1203 targetCompatibility = JavaVersion.VERSION_1_6
1204 options.compilerArgs += ["-g", "-Xlint:-options"]
1205 }
1206 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1207 archiveName = javaOutputJarName
1208 destinationDir = file(javaOutputJarDir)
1209 from javaOutput
1210 include "**/*.class"
1211 }
1212 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001213 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001214 }
1215}
1216
Mads Ager418d1ca2017-05-22 09:35:49 +02001217task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001218 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1219 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1220 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001221 } else if (!OperatingSystem.current().isLinux()) {
1222 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001223 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001224 return;
1225 }
1226 dependsOn buildDebugTestResourcesJars
1227 dependsOn buildExampleJars
1228 dependsOn buildExampleAndroidNJars
1229 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001230 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001231 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001232 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001233 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001234 def noDexTests = [
1235 "multidex",
1236 "multidex002",
1237 "multidex004",
1238 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001239 examplesDir.eachDir { dir ->
1240 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001241 if (!(name in noDexTests)) {
1242 dependsOn "dex_example_${name}"
1243 def exampleOutputDir = file("build/test/examples/" + name);
1244 def dexPath = file("${exampleOutputDir}")
1245 def debug = (name == "throwing")
1246 if (!dexPath.exists()) {
1247 dexPath.mkdirs()
1248 }
1249 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1250 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1251 destination = dexPath
1252 debug = debug
1253 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001254 }
1255 }
1256}
1257
1258task buildSmali {
1259 def smaliDir = file("src/test/smali")
1260 smaliDir.eachDirRecurse() { dir ->
1261 def name = dir.getName();
1262 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1263 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1264 smaliOutputDir.mkdirs()
1265 outputs.dir smaliOutputDir
1266 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1267 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1268 def javaFiles = fileTree(dir: dir, include: '*.java')
1269 def destDir = smaliOutputDir;
1270 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1271 def intermediateFileName = "${name}-intermediate.dex";
1272 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1273 if (javaFiles.empty) {
1274 if (!smaliFiles.empty) {
1275 dependsOn "${taskName}_smali"
1276 task "${taskName}_smali"(type: smali.Smali) {
1277 source = smaliFiles
1278 destination = destFile
1279 }
1280 }
1281 } else {
1282 dependsOn "${taskName}_dexmerger"
1283 task "${taskName}_smali"(type: smali.Smali) {
1284 source = smaliFiles
1285 destination = intermediateFile
1286 }
1287 task "${taskName}_java"(type: JavaCompile) {
1288 source = javaFiles
1289 destinationDir destDir
1290 classpath = sourceSets.main.compileClasspath
1291 sourceCompatibility = JavaVersion.VERSION_1_7
1292 targetCompatibility = JavaVersion.VERSION_1_7
1293 options.compilerArgs += ["-Xlint:-options"]
1294 }
1295 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1296 archiveName = "Test.jar"
1297 destinationDir = destDir
1298 from fileTree(dir: destDir, include: 'Test.class')
1299 }
1300 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1301 source = fileTree(dir: destDir, include: 'Test.jar')
1302 destination = destDir
1303 }
1304 task "${taskName}_dexmerger"(
1305 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1306 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1307 destination = destFile
1308 }
1309 }
1310 }
1311}
1312
1313tasks.withType(Test) {
1314 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1315 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1316 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1317 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1318 forkEvery = 0
1319 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1320 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001321 if (project.hasProperty('disable_assertions')) {
1322 enableAssertions = false
1323 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001324}
1325
1326task buildPreNJdwpTestsJar(type: Jar) {
1327 baseName = 'jdwp-tests-preN'
1328 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1329 // Exclude the classes containing java8
1330 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1331 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1332 includeEmptyDirs = false
1333}
1334
Ian Zerny74143162017-11-24 13:46:35 +01001335task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1336 def inFile = buildPreNJdwpTestsJar.archivePath
1337 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
1338 inputs.file inFile
1339 outputs.file outFile
1340 if (OperatingSystem.current().isWindows()) {
1341 executable file("tools/windows/dx/bin/dx.bat")
1342 } else if (OperatingSystem.current().isMacOsX()) {
1343 executable file("tools/mac/dx/bin/dx");
1344 } else {
1345 executable file("tools/linux/dx/bin/dx");
1346 }
1347 args "--dex"
1348 args "--output=${outFile}"
1349 args inFile
1350}
1351
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001352task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1353 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001354}
1355
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001356task AospJarTest(type: Exec) {
1357 dependsOn CompatDx, downloadDeps
1358 def script = "tools/test_aosp_jar.py"
1359 inputs.file script
1360 commandLine "python", script, "--no-build"
1361 workingDir = projectDir
1362}
1363
Mads Ager418d1ca2017-05-22 09:35:49 +02001364test {
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001365 dependsOn getJarsFromSupportLibs
Mads Ager418d1ca2017-05-22 09:35:49 +02001366 testLogging.exceptionFormat = 'full'
1367 if (project.hasProperty('print_test_stdout')) {
1368 testLogging.showStandardStreams = true
1369 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001370 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001371 println "Running with non default vm: " + project.property('dex_vm')
1372 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001373 if (project.property('dex_vm').startsWith('4.4.4') ||
1374 project.property('dex_vm').startsWith('5.1.1') ||
1375 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001376 // R8 and D8 compute the dex file version number based on the input.
1377 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1378 // Therefore we skip the jack generated art tests with those art versions.
1379 exclude "com/android/tools/r8/art/jack/**"
1380 }
1381 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001382
Mads Ager418d1ca2017-05-22 09:35:49 +02001383 if (project.hasProperty('one_line_per_test')) {
1384 beforeTest { desc ->
1385 println "Start executing test ${desc.name} [${desc.className}]"
1386 }
1387 afterTest { desc, result ->
1388 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1389 }
1390 }
1391 if (project.hasProperty('no_internal')) {
1392 exclude "com/android/tools/r8/internal/**"
1393 }
1394 if (project.hasProperty('only_internal')) {
1395 include "com/android/tools/r8/internal/**"
1396 }
1397 if (project.hasProperty('tool')) {
1398 if (project.property('tool') == 'r8') {
1399 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001400 exclude "com/android/tools/r8/jctf/d8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001401 } else {
1402 assert(project.property('tool') == 'd8')
1403 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001404 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001405 }
1406 }
1407 if (!project.hasProperty('all_tests')) {
1408 exclude "com/android/tools/r8/art/dx/**"
1409 exclude "com/android/tools/r8/art/jack/**"
1410 }
1411 // TODO(tamaskenez) enable jctf on all_tests when consolidated
1412 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001413 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001414 }
1415 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001416 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001417 }
1418 if (project.hasProperty('jctf_compile_only')) {
1419 println "JCTF: compiling only"
1420 systemProperty 'jctf_compile_only', '1'
1421 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001422 if (project.hasProperty('test_dir')) {
1423 systemProperty 'test_dir', project.property('test_dir')
1424 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001425 if (project.hasProperty('aosp_jar')) {
1426 dependsOn AospJarTest
1427 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001428
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001429 if (OperatingSystem.current().isLinux()
1430 || OperatingSystem.current().isMacOsX()
1431 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001432 if (OperatingSystem.current().isMacOsX()) {
1433 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1434 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1435 "See tools/docker/README.md for details.")
1436 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001437 if (OperatingSystem.current().isWindows()) {
1438 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1439 "Art only runs on Linux and tests requiring Art will be skipped")
1440 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001441 dependsOn downloadDeps
1442 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001443 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001444 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001445 dependsOn buildSmali
1446 dependsOn jctfCommonJar
1447 dependsOn jctfTestsClasses
1448 dependsOn buildDebugInfoExamplesDex
1449 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001450 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001451 } else {
1452 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001453 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001454 }
1455}
1456
1457// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1458//
1459// To build and upload a new set of the Art tests for use with R8 follow these steps:
1460//
1461// First of all an Android checkout is required. Currently it must be located
1462// in $HOME/android/master.
1463//
1464// TODO(ricow): simplify this
1465//
1466// Before: update the checked in art, see scripts/update-host-art.sh
1467//
1468// 1. Get an android checkout in $HOME/android/master and apply the patch from
1469// https://android-review.googlesource.com/#/c/294187/
1470//
1471// 2. run the following commands in the Android checkout directory:
1472//
1473// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001474// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1475// m desugar
1476// m -j30 test-art-host
1477// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1478//
1479// Without running the test.py command the classes.jar file used by desugar in
1480// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1481// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001482//
1483// 3. In the R8 project root directory, make sure we have a clean state before starting:
1484// tools/gradle.py downloadDeps
1485// tools/gradle.py clean
1486// rm -rf tests/art
1487//
1488// 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 +02001489// Make sure you have smali on your path, please use the build binary in the
1490// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1491// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1492// 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 +02001493// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1494// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001495//
Søren Gjesse34b77732017-07-07 13:56:21 +02001496// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001497//
1498// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1499// skippedTests with an explanation. Rerun from step 3.
1500//
1501// 5. Run the tests:
1502// tools/gradle.py clean
1503// tools/test.py
1504//
Søren Gjesse34b77732017-07-07 13:56:21 +02001505// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1506// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1507// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001508//
Søren Gjesse34b77732017-07-07 13:56:21 +02001509// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001510// cd tests
1511// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001512//
1513// 7. Update the manifest file describing the Android repo used:
1514// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001515
1516enum DexTool {
1517 JACK,
1518 DX
1519}
1520
1521def androidCheckoutDir = file("${System.env.HOME}/android/master")
1522def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1523def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1524
1525def artTestDir = file("${androidCheckoutDir}/art/test")
1526
1527if (project.hasProperty('android_source')) {
1528 task buildArtTests {
1529 outputs.upToDateWhen { false }
1530 def toBeTriaged = [
1531 "903-hello-tagging",
1532 "904-object-allocation",
1533 "905-object-free",
1534 "906-iterate-heap",
1535 "907-get-loaded-classes",
1536 "908-gc-start-finish",
1537 "954-invoke-polymorphic-verifier",
1538 "955-methodhandles-smali",
1539 "596-monitor-inflation",
1540 ]
1541 def skippedTests = toBeTriaged + [
1542 // This test produces no jar.
1543 "000-nop",
1544 // This does not build, as it tests the error when the application exceeds more
1545 // than 65536 methods
1546 "089-many-methods",
1547 // Requires some jack beta jar
1548 "956-methodhandles",
1549 ]
1550
1551 def skippedTestsDx = [
1552 // Tests with custom build scripts, where javac is not passed the options
1553 // -source 1.7 -target 1.7.
1554 "462-checker-inlining-across-dex-files",
1555 "556-invoke-super",
1556 "569-checker-pattern-replacement",
1557 // These tests use jack even when --build-with-javac-dx is specified.
1558 "004-JniTest",
1559 "048-reflect-v8",
1560 "146-bad-interface",
1561 "563-checker-invoke-super",
1562 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1563 "604-hot-static-interface",
1564 "957-methodhandle-transforms",
1565 "958-methodhandle-emulated-stackframe",
1566 "959-invoke-polymorphic-accessors",
1567 "961-default-iface-resolution-gen",
1568 "962-iface-static",
1569 "963-default-range-smali",
1570 "964-default-iface-init-gen",
1571 "965-default-verify",
1572 "966-default-conflict",
1573 "967-default-ame",
1574 "968-default-partial-compile-gen",
1575 "969-iface-super",
1576 "970-iface-super-resolution-gen",
1577 "971-iface-super",
1578 // These tests does not build with --build-with-javac-dx
1579 "004-NativeAllocations", // Javac error
1580 "031-class-attributes",
1581 "138-duplicate-classes-check",
1582 "157-void-class", // Javac error
1583 "580-checker-string-factory-intrinsics",
1584 "612-jit-dex-cache",
1585 "613-inlining-dex-cache",
1586 "900-hello-plugin", // --experimental agents
1587 "901-hello-ti-agent", // --experimental agents
1588 "902-hello-transformation", // --experimental agents
1589 "909-attach-agent", // --experimental agents
1590 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1591 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1592 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1593 "960-default-smali", // --experimental default-methods
1594 // These tests force the build to use jack
1595 "953-invoke-polymorphic-compiler",
1596 "958-methodhandle-stackframe",
1597 ]
1598
1599 def artTestBuildDir = file("${projectDir}/tests/art")
1600
1601 if (androidCheckoutDir.exists()) {
1602 dependsOn downloadDeps
1603 artTestBuildDir.mkdirs()
1604 // Ensure Jack server is running.
1605 "${androidCheckoutJackServer} start-server".execute()
1606 artTestDir.eachDir { dir ->
1607 def name = dir.getName();
1608 def markerFile = dir.toPath().resolve("info.txt").toFile();
1609 if (markerFile.exists() && !(name in skippedTests)) {
1610 if (!(name in skippedTestsDx)) {
1611 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1612 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001613 // After Android O, Jack is no longer alive
1614 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001615 }
1616 }
1617 }
1618 doFirst {
1619 if (!androidCheckoutDir.exists()) {
1620 throw new InvalidUserDataException(
1621 "This task requires an Android checkout in ${androidCheckoutDir}");
1622 } else if (!androidCheckoutJack.exists() ||
1623 !androidCheckoutJackServer.exists()) {
1624 throw new InvalidUserDataException(
1625 "This task requires that tools for host testing have been build in the " +
1626 "Android checkout in ${androidCheckoutDir}");
1627 }
1628 }
1629 doLast {
1630 copy {
1631 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1632 into file("${artTestBuildDir}/lib64")
1633 include 'lib*.so'
1634 }
1635 copy {
1636 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1637 into file("${artTestBuildDir}/lib64")
1638 include 'libart.so'
1639 include 'libbacktrace.so'
1640 include 'libbase.so'
1641 include 'libc++.so'
1642 include 'libcutils.so'
1643 include 'liblz4.so'
1644 include 'liblzma.so'
1645 include 'libnativebridge.so'
1646 include 'libnativeloader.so'
1647 include 'libsigchain.so'
1648 include 'libunwind.so'
1649 include 'libziparchive.so'
1650 }
1651 copy {
1652 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1653 into file("${artTestBuildDir}/lib")
1654 include 'lib*.so'
1655 }
1656 copy {
1657 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1658 into file("${artTestBuildDir}/lib")
1659 include 'libart.so'
1660 include 'libbacktrace.so'
1661 include 'libbase.so'
1662 include 'libc++.so'
1663 include 'libcutils.so'
1664 include 'liblz4.so'
1665 include 'liblzma.so'
1666 include 'libnativebridge.so'
1667 include 'libnativeloader.so'
1668 include 'libsigchain.so'
1669 include 'libunwind.so'
1670 include 'libziparchive.so'
1671 }
1672 }
1673 }
1674}
1675
1676def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1677 def artTestDir = file("${androidCheckoutDir}/art/test")
1678 def artRunTestScript = file("${artTestDir}/run-test")
1679 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001680 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001681 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1682
Søren Gjesse34b77732017-07-07 13:56:21 +02001683 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001684 def buildTask = "build_art_test_${dexToolName}_${name}"
1685 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1686 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1687 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1688
1689 def buildInputs = fileTree(dir: dir, include: '**/*')
1690 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1691 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1692 testDir.mkdirs()
1693 if (dexTool == DexTool.DX) {
1694 task "$buildTask"(type: Exec) {
1695 outputs.upToDateWhen { false }
1696 inputs.file buildInputs
1697 executable "${artRunTestScript}"
1698 args "--host"
1699 args "--build-only"
1700 args "--build-with-javac-dx"
1701 args "--output-path", "${testDir}"
1702 args "${name}"
1703 environment DX: "${dxExecutable.absolutePath}"
1704 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001705 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001706 outputs.file outputJar
1707 }
1708 } else {
1709 assert dexTool == DexTool.JACK
1710 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1711 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1712 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1713 task "$buildTask"(type: Exec) {
1714 outputs.upToDateWhen { false }
1715 inputs.file buildInputs
1716 executable "${artRunTestScript}"
1717 args "--host"
1718 args "--build-only"
1719 args "--output-path", "${testDir}"
1720 args "${name}"
1721 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1722 environment JACK_CLASSPATH: jackClasspath
1723 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1724 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1725 outputs.file outputJar
1726 }
1727 }
1728 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1729 outputs.upToDateWhen { false }
1730 executable "/bin/bash"
1731 args "-c"
1732 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1733 " ${testDir}/classes-ex ${testDir}/check"
1734 }
1735
1736 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001737 // Directory that contains smali files is either smali, or smali/art
1738 def smali_dir = file("${dir}/smali/art")
1739 if (smali_dir.exists()) {
1740 workingDir "${testDir}/smali/art"
1741 } else {
1742 workingDir "${testDir}/smali"
1743 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001744 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001745 // This is the command line options for smali prior to 2.2.1, where smali got a new
1746 // command line interface.
1747 args "-c", "smali a *.smali"
1748 // This is the command line options for smali 2.2.1 and later.
1749 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001750 }
1751
1752 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1753 def smali_dir = file("${dir}/smali")
1754 outputs.upToDateWhen { false }
1755 if (smali_dir.exists() && dexTool == DexTool.DX) {
1756 dependsOn smaliToDexTask
1757 }
1758 from("${artTestDir}/${name}") {
1759 include 'check'
1760 }
1761 into testDir
1762 }
1763
1764 return copyCheckTask
1765}
1766
1767task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001768 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001769 classpath = sourceSets.main.compileClasspath
1770 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001771 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001772 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001773 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001774 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001775 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001776 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001777 include '**/com/android/tools/r8/CompilationMode.java'
1778 include '**/com/android/tools/r8/D8.java'
1779 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001780 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1781 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001782 include '**/com/android/tools/r8/Diagnostic.java'
1783 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001784 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1785 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001786 include '**/com/android/tools/r8/ProgramConsumer.java'
1787 include '**/com/android/tools/r8/ProgramResource.java'
1788 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001789 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001790 include '**/com/android/tools/r8/ResourceException.java'
1791 include '**/com/android/tools/r8/StringConsumer.java'
1792 include '**/com/android/tools/r8/StringResource.java'
1793 include '**/com/android/tools/r8/Version.java'
1794 include '**/com/android/tools/r8/origin/*.java'
1795}
1796
1797task javadocR8(type: Javadoc) {
1798 title "R8 API"
1799 classpath = sourceSets.main.compileClasspath
1800 source = sourceSets.main.allJava
1801 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
1802 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
1803 include '**/com/android/tools/r8/BaseCommand.java'
1804 include '**/com/android/tools/r8/BaseCompilerCommand.java'
1805 include '**/com/android/tools/r8/ClassFileConsumer.java'
1806 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
1807 include '**/com/android/tools/r8/CompilationFailedException.java'
1808 include '**/com/android/tools/r8/CompilationMode.java'
1809 include '**/com/android/tools/r8/R8.java'
1810 include '**/com/android/tools/r8/R8Command.java'
1811 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1812 include '**/com/android/tools/r8/Diagnostic.java'
1813 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001814 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1815 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001816 include '**/com/android/tools/r8/ProgramConsumer.java'
1817 include '**/com/android/tools/r8/ProgramResource.java'
1818 include '**/com/android/tools/r8/ProgramResourceProvider.java'
1819 include '**/com/android/tools/r8/Resource.java'
1820 include '**/com/android/tools/r8/ResourceException.java'
1821 include '**/com/android/tools/r8/StringConsumer.java'
1822 include '**/com/android/tools/r8/StringResource.java'
1823 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001824 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001825}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001826
1827task copyMavenDeps(type: Copy) {
1828 from configurations.compile into "$buildDir/deps"
1829 from configurations.testCompile into "$buildDir/deps"
1830}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001831
1832// This task allows to build class files from Java 9 source in order to use them as inputs of
1833// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1834// to the D8 repository because there is no way to generate them on all computers due to the need of
1835// Java 9.
1836// Use the following command to rebuild class files of tests:
1837// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1838task buildJava9Tests {
1839 def javacOutputFolder = getTemporaryDir();
1840 def examplesDir = file("src/test/examplesJava9")
1841
1842 task "compile_Java9examples"(type: JavaCompile) {
1843 doFirst {
1844 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1845 throw new GradleException("Set java9Home property.")
1846 }
1847 }
1848
1849 source = fileTree(dir: examplesDir, include: '**/*.java')
1850 destinationDir = javacOutputFolder
1851 classpath = sourceSets.main.compileClasspath
1852 options.compilerArgs += ["-Xlint:-options"]
1853 sourceCompatibility = JavaVersion.VERSION_1_9
1854 targetCompatibility = JavaVersion.VERSION_1_9
1855 options.fork = true
1856
1857 if (project.hasProperty('java9Home')) {
1858 options.forkOptions.javaHome = file(getProperty('java9Home'))
1859 }
1860
1861 doLast {
1862 def classfileFrom = copySpec {
1863 from javacOutputFolder
1864 include "**/*.class"
1865 }
1866 copy {
1867 into examplesDir
1868 with classfileFrom
1869 }
1870 delete javacOutputFolder
1871 }
1872 }
1873
1874 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02001875}