blob: 5606a9ed6db28aa8eb539bce94206aa919824a89 [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
Sebastien Hertz143ed112018-02-13 14:26:41 +010010ext {
11 androidSupportVersion = '25.4.0'
Gautam Korlam39d74202018-08-29 18:09:35 -070012 asmVersion = '6.2.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010013 autoValueVersion = '1.5'
14 espressoVersion = '3.0.0'
15 fastutilVersion = '7.2.0'
16 guavaVersion = '23.0'
17 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020018 gsonVersion = '2.7'
Sebastien Hertz143ed112018-02-13 14:26:41 +010019 junitVersion = '4.12'
Jinseong Jeone11145f2018-12-13 10:57:29 -080020 mockitoVersion = '2.10.0'
Jinseong Jeon46146f42018-12-16 23:26:14 -080021 kotlinVersion = '1.3.11'
Jinseong Jeonb6fe4fe2018-12-03 00:49:13 -080022 kotlinExtMetadataJVMVersion = '0.0.4'
Sebastien Hertz143ed112018-02-13 14:26:41 +010023 smaliVersion = '2.2b4'
24}
25
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020026def errorProneConfiguration = [
27 '-XepDisableAllChecks',
28 // D8 want to use reference equality, thus disable the checker explicitly
29 '-Xep:ReferenceEquality:OFF',
Stephan Herhute4d101c2017-11-22 12:18:02 +010030 '-Xep:ClassCanBeStatic:ERROR',
31 '-Xep:OperatorPrecedence:ERROR',
32 '-Xep:RemoveUnusedImports:ERROR',
33 '-Xep:MissingOverride:ERROR',
Stephan Herhute4d101c2017-11-22 12:18:02 +010034 '-Xep:IntLongMath:ERROR',
35 '-Xep:EqualsHashCode:ERROR',
36 '-Xep:InconsistentOverloads:ERROR',
37 '-Xep:ArrayHashCode:ERROR',
38 '-Xep:EqualsIncompatibleType:ERROR',
39 '-Xep:NonOverridingEquals:ERROR',
40 '-Xep:FallThrough:ERROR',
41 '-Xep:MissingCasesInEnumSwitch:ERROR',
42 '-Xep:MissingDefault:ERROR',
43 '-Xep:MultipleTopLevelClasses:ERROR',
44 '-Xep:NarrowingCompoundAssignment:ERROR',
Mads Ager2ce4b372018-06-07 13:11:33 +020045 '-Xep:BoxedPrimitiveConstructor:ERROR',
46 '-Xep:LogicalAssignment:ERROR',
47 '-Xep:FloatCast:ERROR',
48 '-Xep:ReturnValueIgnored:ERROR']
Mads Ager418d1ca2017-05-22 09:35:49 +020049
50apply from: 'copyAdditionalJctfCommonFiles.gradle'
51
52repositories {
Yohann Roussel126f6872017-08-03 16:25:32 +020053 maven { url 'https://maven.google.com' }
Jinseong Jeon515e7582018-06-15 21:50:31 +000054 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020055 mavenCentral()
56}
57
Stephan Herhut417a72a2017-07-18 10:38:30 +020058buildscript {
59 repositories {
60 mavenCentral()
mikaelpeltier80939312017-08-17 15:00:09 +020061 jcenter()
Mikaël Peltiercf3e2362017-10-16 13:45:45 +020062 maven {
63 url "https://plugins.gradle.org/m2/"
64 }
Stephan Herhut417a72a2017-07-18 10:38:30 +020065 }
66 dependencies {
Jinseong Jeon40ceab02018-07-09 14:25:31 -070067 classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +020068 classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
Stephan Herhut52cb1022017-10-24 15:10:41 +020069 classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
Jinseong Jeon05064e12018-07-03 00:21:12 -070070 classpath "com.gradle:build-scan-plugin:1.14"
Stephan Herhut417a72a2017-07-18 10:38:30 +020071 }
72}
73
Jinseong Jeon05064e12018-07-03 00:21:12 -070074apply plugin: "com.gradle.build-scan"
75
76buildScan {
77 licenseAgreementUrl = 'https://gradle.com/terms-of-service'
78 licenseAgree = 'yes'
79}
80
81apply plugin: 'java'
82apply plugin: 'idea'
Jinseong Jeon05064e12018-07-03 00:21:12 -070083apply plugin: 'net.ltgt.errorprone-base'
84apply plugin: "net.ltgt.apt"
85
Jinseong Jeon05064e12018-07-03 00:21:12 -070086if (project.hasProperty('with_code_coverage')) {
87 apply plugin: 'jacoco'
88}
89
Mads Ager418d1ca2017-05-22 09:35:49 +020090// Custom source set for example tests and generated tests.
91sourceSets {
92 test {
93 java {
94 srcDirs = [
95 'src/test/java',
96 'build/generated/test/java',
97 ]
98 }
99 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100100 apiUsageSample {
101 java {
Mathias Rave3f3c522018-05-30 08:22:17 +0200102 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
103 include 'com/android/tools/apiusagesample/*.java'
104 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
105 include 'com/android/tools/r8/D8CommandParser.java'
106 include 'com/android/tools/r8/R8CommandParser.java'
107 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +0100108 }
Yohann Rousselbb571622017-11-09 10:47:36 +0100109 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200110 debugTestResources {
111 java {
112 srcDirs = ['src/test/debugTestResources']
113 }
114 output.resourcesDir = 'build/classes/debugTestResources'
115 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200116 debugTestResourcesJava8 {
117 java {
118 srcDirs = ['src/test/debugTestResourcesJava8']
119 }
120 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
121 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200122 debugTestResourcesKotlin {
123 java {
124 srcDirs = ['src/test/debugTestResourcesKotlin']
125 }
126 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
127 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200128 examples {
129 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800130 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200131 }
132 output.resourcesDir = 'build/classes/examples'
133 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100134 examplesKotlin {
135 java {
136 srcDirs = ['src/test/examplesKotlin']
137 }
138 output.resourcesDir = 'build/classes/examplesKotlin'
139 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200140 examplesAndroidN {
141 java {
142 srcDirs = ['src/test/examplesAndroidN']
143 }
144 output.resourcesDir = 'build/classes/examplesAndroidN'
145 }
146 examplesAndroidO {
147 java {
148 srcDirs = ['src/test/examplesAndroidO']
149 }
150 output.resourcesDir = 'build/classes/examplesAndroidO'
151 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200152 examplesAndroidP {
153 java {
154 srcDirs = ['src/test/examplesAndroidP']
155 }
156 output.resourcesDir = 'build/classes/examplesAndroidP'
157 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200158 jctfCommon {
159 java {
160 srcDirs = [
161 'third_party/jctf/Harness/src',
162 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
163 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
164 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
165 'third_party/jctf/LibTests/src/org',
166 'build/additionalJctfCommonFiles'
167 ]
168 }
169 resources {
170 srcDirs = ['third_party/jctf/LibTests/resources']
171 }
172 }
173 jctfTests {
174 java {
175 srcDirs = [
176 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
177 // 'third_party/jctf/VMTests/src',
178 ]
179 }
180 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100181 kotlinR8TestResources {
182 java {
183 srcDirs = ['src/test/kotlinR8TestResources']
184 }
185 output.resourcesDir = 'build/classes/kotlinR8TestResources'
186 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200187}
188
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800189// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
190// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
191// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
192// for context.
193idea {
194 sourceSets.all { SourceSet sources ->
195 module {
196 if (sources.name == "main") {
197 sourceDirs += sources.java.srcDirs
198 outputDir sources.output.classesDir
199 } else {
200 testSourceDirs += sources.java.srcDirs
201 testOutputDir sources.output.classesDir
202 }
203 }
204 }
205}
206
Yohann Roussel126f6872017-08-03 16:25:32 +0200207configurations {
208 supportLibs
209}
210
Mads Ager418d1ca2017-05-22 09:35:49 +0200211dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100212 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
213 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200214 // Include all of guava when compiling the code, but exclude annotations that we don't
215 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100216 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100217 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200218 exclude group: 'com.google.errorprone'
219 exclude group: 'com.google.code.findbugs'
220 exclude group: 'com.google.j2objc'
221 exclude group: 'org.codehaus.mojo'
222 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100223 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
224 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
225 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
226 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
227 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
228 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
229 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200230 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100231 testCompile "junit:junit:$junitVersion"
232 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200233 testCompile files('third_party/jasmin/jasmin-2.4.jar')
234 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200235 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100236 jctfCommonCompile "junit:junit:$junitVersion"
237 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200238 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100239 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
240 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200241 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100242 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800243 examplesCompile "junit:junit:$junitVersion"
244 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100245 examplesCompileOnly "com.google.auto.value:auto-value:$autoValueVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100246 supportLibs "com.android.support:support-v4:$androidSupportVersion"
247 supportLibs "junit:junit:$junitVersion"
248 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100249 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100250 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100251 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
252 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
253 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
254 apt "com.google.auto.value:auto-value:$autoValueVersion"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200255}
256
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100257def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100258def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100259def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100260def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100261def r8LibTestPath = "$buildDir/classes/r8libtest"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100262
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200263def osString = OperatingSystem.current().isLinux() ? "linux" :
264 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200265
266def cloudDependencies = [
267 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200268 "2017-10-04/art",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200269 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200270 ],
271 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200272 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200273 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100274 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200275 "android_jar/lib-v19",
276 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100277 "android_jar/lib-v22",
278 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200279 "android_jar/lib-v24",
280 "android_jar/lib-v25",
281 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100282 "android_jar/lib-v27",
283 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200284 "core-lambda-stubs",
285 "dart-sdk",
286 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200287 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200288 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200289 "jasmin",
290 "jctf",
Rico Windf72fa152018-10-22 15:41:03 +0200291 "jdwp-tests",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "kotlin",
Mathias Rav5285faf2018-03-20 14:16:32 +0100293 "openjdk/openjdk-rt-1.8",
Rico Windf72fa152018-10-22 15:41:03 +0200294 "proguard/proguard5.2.1",
295 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200296 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200297 ],
298 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
299 // container on other platforms where supported.
300 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200301 "linux/art",
302 "linux/art-5.1.1",
303 "linux/art-6.0.1",
304 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100305 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100306 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200307 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100308 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200309 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200310 ]
311]
312
313cloudDependencies.each { entry ->
314 entry.value.each { entryFile ->
315 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200316 def outputDir = "${entry.key}/${entryFile}"
317 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200318 def sha1File = "${gzFile}.sha1"
Ian Zerny61fcba92018-11-30 14:20:50 +0100319 // Make the output file part of the input dependencies explictly.
320 inputs.files files(sha1File, gzFile)
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200321 outputs.dir outputDir
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200322 List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"]
323 if (OperatingSystem.current().isWindows()) {
324 executable "download_from_google_storage.bat"
325 args dlFromStorageArgs
326 } else {
327 executable "bash"
328 args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs)
329 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200330 }
331 }
332}
333
334def x20Dependencies = [
335 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200336 "benchmarks/kotlin-benches",
Rico Windf72fa152018-10-22 15:41:03 +0200337 "chrome",
338 "desugar/desugar_20180308",
339 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200340 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200341 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200342 "gmscore/gmscore_v10",
343 "gmscore/gmscore_v9",
344 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200345 "gmscore/v4",
346 "gmscore/v5",
347 "gmscore/v6",
348 "gmscore/v7",
349 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200350 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200351 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200352 "proguard/proguard_internal_159423826",
353 "proguardsettings",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200354 "youtube/youtube.android_12.10",
355 "youtube/youtube.android_12.17",
356 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200357 "youtube/youtube.android_13.37",
Mads Ager418d1ca2017-05-22 09:35:49 +0200358 ],
359]
360
361x20Dependencies.each { entry ->
362 entry.value.each { entryFile ->
363 task "download_deps_${entry.key}/${entryFile}"(type: Exec) {
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200364 def outputDir = "${entry.key}/${entryFile}"
365 def gzFile = "${outputDir}.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200366 def sha1File = "${gzFile}.sha1"
Morten Krogh-Jespersenef0d81a2019-01-11 11:43:14 +0100367 inputs.files files(sha1File, gzFile)
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200368 outputs.dir outputDir
Mads Ager418d1ca2017-05-22 09:35:49 +0200369 executable "bash"
370 args "-c", "tools/download_from_x20.py ${sha1File}"
371 }
372 }
373}
374
Rico Wind897bb712017-05-23 10:44:29 +0200375task downloadProguard {
376 cloudDependencies.each { entry ->
377 entry.value.each { entryFile ->
378 if (entryFile.contains("proguard")) {
379 dependsOn "download_deps_${entry.key}/${entryFile}"
380 }
381 }
382 }
383}
384
Rico Windf6c74ce2018-12-04 08:50:55 +0100385task downloadOpenJDKrt {
386 cloudDependencies.each { entry ->
387 entry.value.each { entryFile ->
388 if (entryFile.contains("openjdk-rt")) {
389 dependsOn "download_deps_${entry.key}/${entryFile}"
390 }
391 }
392 }
393}
394
Tamas Kenez427205b2017-06-29 15:57:09 +0200395task downloadDx {
396 cloudDependencies.each { entry ->
397 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200398 if (entryFile.endsWith("/dx")) {
Tamas Kenez427205b2017-06-29 15:57:09 +0200399 dependsOn "download_deps_${entry.key}/${entryFile}"
400 }
401 }
402 }
403}
404
Tamas Kenez0e10c562017-06-08 10:00:34 +0200405task downloadAndroidCts {
406 cloudDependencies.each { entry ->
407 entry.value.each { entryFile ->
408 if (entryFile.contains("android_cts_baseline")) {
409 dependsOn "download_deps_${entry.key}/${entryFile}"
410 }
411 }
412 }
413}
414
Mads Ager418d1ca2017-05-22 09:35:49 +0200415task downloadDeps {
416 cloudDependencies.each { entry ->
417 entry.value.each { entryFile ->
418 dependsOn "download_deps_${entry.key}/${entryFile}"
419 }
420 }
421 if (!project.hasProperty('no_internal')) {
422 x20Dependencies.each { entry ->
423 entry.value.each { entryFile ->
424 dependsOn "download_deps_${entry.key}/${entryFile}"
425 }
426 }
427 }
428}
429
430allprojects {
431 sourceCompatibility = JavaVersion.VERSION_1_8
432 targetCompatibility = JavaVersion.VERSION_1_8
433}
434
Mads Agerc7d14d32018-09-27 11:09:46 +0200435// Javac often runs out of stack space when compiling the tests.
436// Increase the stack size for the javac process.
437tasks.withType(JavaCompile) {
438 options.fork = true
439 options.forkOptions.jvmArgs = ["-Xss4m"]
440}
441
Mads Ager418d1ca2017-05-22 09:35:49 +0200442tasks.withType(JavaCompile) {
443 options.compilerArgs << '-Xlint:unchecked'
444}
445
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200446if (!project.hasProperty('without_error_prone')) {
447 compileJava {
448 // Enable error prone for D8/R8 sources.
449 toolChain ErrorProneToolChain.create(project)
450 options.compilerArgs += errorProneConfiguration
451 }
452}
453
Mads Ager418d1ca2017-05-22 09:35:49 +0200454compileJctfCommonJava {
455 dependsOn 'copyAdditionalJctfCommonFiles'
456 options.compilerArgs = ['-Xlint:none']
457}
458
459compileJctfTestsJava {
460 dependsOn 'jctfCommonClasses'
461 options.compilerArgs = ['-Xlint:none']
462}
463
Yohann Roussel7f47c032017-09-14 12:19:06 +0200464task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200465 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100466
Yohann Roussel7f47c032017-09-14 12:19:06 +0200467 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100468 def runtimeClasspath = configurations.findByName("runtimeClasspath")
469 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
470
Yohann Roussel7f47c032017-09-14 12:19:06 +0200471 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100472
Yohann Roussel7f47c032017-09-14 12:19:06 +0200473 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100474 def dependencies = []
475 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
476 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
477 dependencies.add("${identifier.group}:${identifier.module}")
478 }
479 def libraryLicenses = file('LIBRARY-LICENSE').text
480 dependencies.each {
481 if (!libraryLicenses.contains("- artifact: $it")) {
482 throw new GradleException("No license for $it in LIBRARY_LICENSE")
483 }
484 }
485
Yohann Roussel7f47c032017-09-14 12:19:06 +0200486 license.getParentFile().mkdirs()
487 license.createNewFile()
488 license.text = "This file lists all licenses for code distributed.\n"
489 license.text += "All non-library code has the following 3-Clause BSD license.\n"
490 license.text += "\n"
491 license.text += "\n"
492 license.text += file('LICENSE').text
493 license.text += "\n"
494 license.text += "\n"
495 license.text += "Summary of distributed libraries:\n"
496 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100497 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200498 license.text += "\n"
499 license.text += "\n"
500 license.text += "Licenses details:\n"
501 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
502 license.text += "\n"
503 license.text += "\n"
504 license.text += file.text
505 }
506 }
507}
508
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200509static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700510 // Everything under META-INF is not included by default.
511 // Should include before 'relocate' so that the service file path and its content
512 // are properly relocated as well.
513 task.mergeServiceFiles {
514 include 'META-INF/services/*'
515 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200516}
517
518static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000519 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200520 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000521 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
522 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000523 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000524 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200525 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
526 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
527 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200528 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000529}
530
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100531task repackageDepsNoRelocate(type: ShadowJar) {
532 configurations = [project.configurations.runtimeClasspath]
533 mergeServiceFiles(it)
534 exclude { it.getRelativePath().getPathString() == "module-info.class" }
535 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100536 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100537}
538
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000539task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100540 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200541 mergeServiceFiles(it)
542 if (!project.hasProperty('lib_no_relocate')) {
543 configureRelocations(it)
544 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100545 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700546 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000547 baseName 'deps'
548}
549
550task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200551 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200552 mergeServiceFiles(it)
553 if (!project.hasProperty('lib_no_relocate')) {
554 configureRelocations(it)
555 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000556 baseName 'sources'
557}
558
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100559task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200560 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100561 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200562 classifier = null
563 version = null
564 manifest {
565 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
566 }
567 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100568 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100569 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100570 exclude "META-INF/*.kotlin_module"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200571}
572
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100573task r8WithoutDeps(type: ShadowJar) {
574 from consolidatedLicense.outputs.files
575 baseName 'r8_without_deps'
576 classifier = null
577 version = null
578 manifest {
579 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
580 }
581 from sourceSets.main.output
582}
583
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000584task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200585 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200586 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200587 classifier = null
588 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200589 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200590 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200591 }
592 // In order to build without dependencies, pass the exclude_deps property using:
593 // gradle -Pexclude_deps R8
594 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800595 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000596 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800597 } else {
598 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200599 }
Ian Zerny80533c92019-01-24 10:32:09 +0100600 exclude "META-INF/*.kotlin_module"
Mads Ager418d1ca2017-05-22 09:35:49 +0200601}
602
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100603task R8NoManifestNoDeps(type: ShadowJar) {
604 from consolidatedLicense.outputs.files
605 baseName 'r8nomanifest-exclude-deps'
606 classifier = null
607 version = null
608 from sourceSets.main.output
609}
610
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100611task R8NoManifest(type: ShadowJar) {
612 from consolidatedLicense.outputs.files
613 baseName 'r8nomanifest'
614 classifier = null
615 version = null
616 // In order to build without dependencies, pass the exclude_deps property using:
617 // gradle -Pexclude_deps R8
618 if (!project.hasProperty('exclude_deps')) {
619 from repackageSources.outputs.files
620 from repackageDeps.outputs.files
621 } else {
622 from sourceSets.main.output
623 }
Ian Zerny80533c92019-01-24 10:32:09 +0100624 exclude "META-INF/*.kotlin_module"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100625}
626
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000627task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200628 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200629 baseName 'd8'
630 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200631 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200632 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200633}
634
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200635task CompatDx(type: ShadowJar) {
636 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200637 baseName 'compatdx'
638 manifest {
639 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
640 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200641}
642
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200643task CompatProguard(type: ShadowJar) {
644 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200645 baseName 'compatproguard'
646 manifest {
647 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
648 }
Lars Bak44cef522017-08-10 16:02:39 +0200649}
650
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100651def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100652 // Execute r8 commands against a stable r8 with relocated dependencies.
653 return ["java", "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100654}
655
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100656def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100657 return baseR8CommandLine([
658 "--classfile", "--release",
659 input,
660 "--output", output,
661 "--pg-conf", pgconf,
662 "--pg-map-output", output + ".map",
663 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
664 ] + args + libs.collectMany { ["--lib", it] })
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100665}
666
667def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
668 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100669 inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100670 outputs.file output
671 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100672 dependsOn r8WithRelocatedDeps
673 dependsOn r8Task
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100674 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
675 workingDir = projectDir
676 }
677}
678
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100679task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100680 baseName = "r8tests"
681 from sourceSets.test.output
682}
683
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100684task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
685 baseName = "r8tests-exclude-deps"
686 from sourceSets.test.output
687}
688
689def generateR8LibKeepRules(name, r8Source, testSource, output) {
690 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
691 doFirst {
692 standardOutput new FileOutputStream(output)
693 }
694 dependsOn r8WithRelocatedDeps
695 dependsOn r8Source
696 dependsOn testSource
697 dependsOn downloadOpenJDKrt
698 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
699 outputs.file output
700 commandLine baseR8CommandLine([
701 "printuses",
702 "--keeprules",
703 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
704 r8Source.outputs.files[0],
705 testSource.outputs.files[0]])
706 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100707 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100708}
709
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100710task R8LibApiOnly {
711 dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
712 outputs.file r8LibPath
713}
714
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100715task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100716 def genRulesTask = generateR8LibKeepRules(
717 "Main",
718 R8NoManifest,
719 testJar,
720 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100721 dependsOn r8LibCreateTask(
722 "Main",
723 "src/main/keep.txt",
724 R8NoManifest,
725 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100726 ["--pg-conf", genRulesTask.outputs.files[0]]
727 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100728 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100729}
730
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100731task R8LibNoDeps {
732 def genRulesTask = generateR8LibKeepRules(
733 "NoDeps",
734 R8NoManifestNoDeps,
735 testJarNoDeps,
736 r8LibGeneratedKeepRulesExcludeDepsPath
737 )
738 dependsOn r8LibCreateTask(
739 "NoDeps",
740 "src/main/keep.txt",
741 R8NoManifestNoDeps,
742 r8LibExludeDepsPath,
743 ["--pg-conf", genRulesTask.outputs.files[0]],
744 repackageDepsNoRelocate.outputs.files
745 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
746 outputs.file r8LibExludeDepsPath
747}
748
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100749task CompatDxLib {
750 dependsOn r8LibCreateTask(
751 "CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100752}
753
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100754task CompatProguardLib {
755 dependsOn r8LibCreateTask(
756 "CompatPg",
757 "src/main/keep-compatproguard.txt",
758 CompatProguard,
759 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100760}
761
Mads Ager418d1ca2017-05-22 09:35:49 +0200762task sourceJar(type: Jar, dependsOn: classes) {
763 classifier = 'src'
764 from sourceSets.main.allSource
765}
766
767task jctfCommonJar(type: Jar) {
768 from sourceSets.jctfCommon.output
769 baseName 'jctfCommon'
770}
771
772artifacts {
773 archives sourceJar
774}
775
776task createArtTests(type: Exec) {
777 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200778 def createArtTestsScript = "tools/create_art_tests.py"
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200779 inputs.file "tests/2017-10-04/art.tar.gz"
Mads Ager418d1ca2017-05-22 09:35:49 +0200780 inputs.file createArtTestsScript
781 outputs.dir outputDir
782 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200783 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200784 workingDir = projectDir
785}
786
787task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200788 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200789 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200790 inputs.file script
791 outputs.dir outputDir
792 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200793 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200794 workingDir = projectDir
795}
796
797compileTestJava {
798 dependsOn createArtTests
799 dependsOn createJctfTests
800}
801
Ian Zernyee23a172018-01-03 09:08:48 +0100802task buildD8ApiUsageSample(type: Jar) {
803 from sourceSets.apiUsageSample.output
804 baseName 'd8_api_usage_sample'
805 destinationDir file('tests')
806}
807
Ian Zerny923a0c12018-01-03 10:59:18 +0100808task buildR8ApiUsageSample(type: Jar) {
809 from sourceSets.apiUsageSample.output
810 baseName 'r8_api_usage_sample'
811 destinationDir file('tests')
812}
813
Yohann Roussel548ae942018-01-05 11:13:28 +0100814task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +0100815 dependsOn buildD8ApiUsageSample
816 dependsOn buildR8ApiUsageSample
817}
818
Mads Ager418d1ca2017-05-22 09:35:49 +0200819task buildDebugInfoExamplesDex {
820 def examplesDir = file("src/test/java")
821 def hostJar = "debuginfo_examples.jar"
822 def hostDexJar = "debuginfo_examples_dex.jar"
823 task "compile_debuginfo_examples"(type: JavaCompile) {
824 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
825 destinationDir = file("build/test/debuginfo_examples/classes")
826 classpath = sourceSets.main.compileClasspath
827 sourceCompatibility = JavaVersion.VERSION_1_7
828 targetCompatibility = JavaVersion.VERSION_1_7
829 options.compilerArgs += ["-Xlint:-options"]
830 }
831 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
832 archiveName = hostJar
833 destinationDir = file("build/test/")
834 from "build/test/debuginfo_examples/classes"
835 include "**/*.class"
836 }
837 task "dex_debuginfo_examples"(type: Exec,
838 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200839 if (OperatingSystem.current().isWindows()) {
840 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -0700841 } else if (OperatingSystem.current().isMacOsX()) {
842 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200843 } else {
844 executable file("tools/linux/dx/bin/dx");
845 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200846 args "--dex"
847 args "--output=build/test/${hostDexJar}"
848 args "build/test/${hostJar}"
849 inputs.file file("build/test/${hostJar}")
850 outputs.file file("build/test/${hostDexJar}")
851 }
852 dependsOn dex_debuginfo_examples
853}
854
855task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +0200856 def resourcesDir = file("src/test/debugTestResources")
857 def hostJar = "debug_test_resources.jar"
858 task "compile_debugTestResources"(type: JavaCompile) {
859 source = fileTree(dir: resourcesDir, include: '**/*.java')
860 destinationDir = file("build/test/debugTestResources/classes")
861 classpath = sourceSets.main.compileClasspath
862 sourceCompatibility = JavaVersion.VERSION_1_7
863 targetCompatibility = JavaVersion.VERSION_1_7
864 options.compilerArgs += ["-g", "-Xlint:-options"]
865 }
866 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
867 archiveName = hostJar
868 destinationDir = file("build/test/")
869 from "build/test/debugTestResources/classes"
870 include "**/*.class"
871 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200872 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
873 def java8HostJar = "debug_test_resources_java8.jar"
874 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
875 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
876 destinationDir = file("build/test/debugTestResourcesJava8/classes")
877 classpath = sourceSets.main.compileClasspath
878 sourceCompatibility = JavaVersion.VERSION_1_8
879 targetCompatibility = JavaVersion.VERSION_1_8
880 options.compilerArgs += ["-g", "-Xlint:-options"]
881 }
882 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
883 archiveName = java8HostJar
884 destinationDir = file("build/test/")
885 from "build/test/debugTestResourcesJava8/classes"
886 include "**/*.class"
887 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200888 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000889 def kotlinHostJar = "debug_test_resources_kotlin.jar"
890 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
891 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
892 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200893 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200894 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +0200895 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200896 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000897 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +0200898}
899
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +0100900// Examples used by tests, where Android specific APIs are used.
901task buildExampleAndroidApi(type: JavaCompile) {
902 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
903 destinationDir = file("build/test/examplesAndroidApi/classes")
904 classpath = files("third_party/android_jar/lib-v26/android.jar")
905 sourceCompatibility = JavaVersion.VERSION_1_8
906 targetCompatibility = JavaVersion.VERSION_1_8
907}
908
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100909task buildExampleKotlinJars {
910 def kotlinSrcDir = file("src/test/examplesKotlin")
911 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +0000912 def name = dir.getName();
913 dependsOn "compile_example_kotlin_${name}"
914 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
915 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
916 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100917 }
918 }
919}
920
Lars Bakc91e87e2017-08-18 08:53:10 +0200921// Proto lite generated code yields warnings when compiling with javac.
922// We change the options passed to javac to ignore it.
923compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
924
Søren Gjesse7320ce52018-05-07 15:45:22 +0200925
Mads Ager418d1ca2017-05-22 09:35:49 +0200926task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +0200927 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +0200928 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +0200929 def proguardScript
930 if (OperatingSystem.current().isWindows()) {
931 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
932 } else {
933 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
934 }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200935 task extractExamplesRuntime(type: Sync) {
936 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +0000937 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +0200938 include "**/*.class"
939 includeEmptyDirs false
940 into "$buildDir/runtime/examples/"
941 }
942
Søren Gjesse7320ce52018-05-07 15:45:22 +0200943 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
944 from examplesDir
945 exclude "**/*.java"
946 exclude "**/keep-rules*.txt"
947 into file("build/test/examples/classes")
948 }
949
950 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +0200951 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +0200952 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +0200953 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +0200954 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200955 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +0200956 sourceCompatibility = JavaVersion.VERSION_1_7
957 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200958 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
959 }
Rico Wind40fd2c12018-09-12 12:14:44 +0200960 task "compile_examples_debuginfo_all"(type: JavaCompile) {
961 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200962 include "**/*.java"
963 destinationDir = file("build/test/examples/classes_debuginfo_all")
964 classpath = sourceSets.examples.compileClasspath
965 sourceCompatibility = JavaVersion.VERSION_1_7
966 targetCompatibility = JavaVersion.VERSION_1_7
967 options.compilerArgs = ["-g", "-Xlint:none"]
968 }
Rico Wind40fd2c12018-09-12 12:14:44 +0200969 task "compile_examples_debuginfo_none"(type: JavaCompile) {
970 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200971 include "**/*.java"
972 destinationDir = file("build/test/examples/classes_debuginfo_none")
973 classpath = sourceSets.examples.compileClasspath
974 sourceCompatibility = JavaVersion.VERSION_1_7
975 targetCompatibility = JavaVersion.VERSION_1_7
976 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +0200977 }
978 examplesDir.eachDir { dir ->
979 def name = dir.getName();
980 def exampleOutputDir = file("build/test/examples");
981 def jarName = "${name}.jar"
982 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +0200983 dependsOn "jar_example_${name}_debuginfo_all"
984 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200985 dependsOn "extractExamplesRuntime"
986 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +0200987 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
988 def proguardConfigPath = "${dir}/proguard.cfg"
989 if (new File(proguardConfigPath).exists()) {
990 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
991 archiveName = "${name}_pre_proguard.jar"
992 destinationDir = exampleOutputDir
993 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +0200994 include name + "/**/*.class"
995 with runtimeDependencies
996 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +0200997 }
998 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
999 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1000 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1001 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
1002 inputs.files tasks.getByPath("pre_proguard_example_${name}")
1003 inputs.file proguardConfigPath
1004 // Enable these to get stdout and stderr redirected to files...
1005 // standardOutput = new FileOutputStream('proguard.stdout')
1006 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001007 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001008 " -outjars ${proguardJarPath}" +
1009 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001010 " -printmapping ${proguardMapPath}"
1011 if (OperatingSystem.current().isWindows()) {
1012 executable "${proguardScript}"
1013 args "${proguardArguments}"
1014 } else {
1015 executable "bash"
1016 args "-c", "${proguardScript} '${proguardArguments}'"
1017 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001018 outputs.file proguardJarPath
1019 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001020 // TODO: Consider performing distinct proguard compilations.
1021 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1022 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001023 into "${exampleOutputDir}"
1024 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001025 }
1026 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1027 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001028 into "${exampleOutputDir}"
1029 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001030 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001031 } else {
1032 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001033 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001034 destinationDir = exampleOutputDir
1035 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001036 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001037 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001038 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001039 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001040 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1041 archiveName = "${name}_debuginfo_all.jar"
1042 destinationDir = exampleOutputDir
1043 from "build/test/examples/classes_debuginfo_all"
1044 include name + "/**/*.class"
1045 with runtimeDependencies
1046 includeEmptyDirs false
1047 }
1048 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1049 archiveName = "${name}_debuginfo_none.jar"
1050 destinationDir = exampleOutputDir
1051 from "build/test/examples/classes_debuginfo_none"
1052 include name + "/**/*.class"
1053 with runtimeDependencies
1054 includeEmptyDirs false
1055 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001056 }
1057 }
1058}
1059
1060task buildExampleAndroidNJars {
1061 dependsOn downloadDeps
1062 def examplesDir = file("src/test/examplesAndroidN")
1063 task "compile_examplesAndroidN"(type: JavaCompile) {
1064 source = fileTree(dir: examplesDir, include: '**/*.java')
1065 destinationDir = file("build/test/examplesAndroidN/classes")
1066 classpath = sourceSets.main.compileClasspath
1067 sourceCompatibility = JavaVersion.VERSION_1_8
1068 targetCompatibility = JavaVersion.VERSION_1_8
1069 options.compilerArgs += ["-Xlint:-options"]
1070 }
1071 examplesDir.eachDir { dir ->
1072 def name = dir.getName();
1073 def exampleOutputDir = file("build/test/examplesAndroidN");
1074 def jarName = "${name}.jar"
1075 dependsOn "jar_examplesAndroidN_${name}"
1076 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1077 archiveName = jarName
1078 destinationDir = exampleOutputDir
1079 from "build/test/examplesAndroidN/classes"
1080 include "**/" + name + "/**/*.class"
1081 }
1082 }
1083}
1084
1085
1086task buildExampleAndroidOJars {
1087 dependsOn downloadDeps
1088 def examplesDir = file("src/test/examplesAndroidO")
1089 // NOTE: we want to enable a scenario when test needs to reference some
1090 // classes generated by legacy (1.6) Java compiler to test some specific
1091 // behaviour. To do so we compile all the java files located in sub-directory
1092 // called 'legacy' with Java 1.6, then compile the rest of the files with
1093 // Java 1.8 and a reference to previously generated 1.6 classes.
1094
1095 // Compiling all classes in dirs 'legacy' with old Java version.
1096 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1097 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1098 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1099 classpath = sourceSets.main.compileClasspath
1100 sourceCompatibility = JavaVersion.VERSION_1_6
1101 targetCompatibility = JavaVersion.VERSION_1_6
1102 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1103 }
1104 // Compiling the rest of the files as Java 1.8 code.
1105 task "compile_examplesAndroidO"(type: JavaCompile) {
1106 dependsOn "compile_examplesAndroidO_Legacy"
1107 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1108 destinationDir = file("build/test/examplesAndroidO/classes")
1109 classpath = sourceSets.main.compileClasspath
1110 classpath += files("build/test/examplesAndroidOLegacy/classes")
1111 sourceCompatibility = JavaVersion.VERSION_1_8
1112 targetCompatibility = JavaVersion.VERSION_1_8
1113 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1114 }
1115 examplesDir.eachDir { dir ->
1116 def name = dir.getName();
1117 def destinationDir = file("build/test/examplesAndroidO/classes");
1118 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1119 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1120 dependsOn: "compile_examplesAndroidO") {
1121 main = name + ".TestGenerator"
1122 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1123 args destinationDir
1124 }
1125 } else {
1126 task "generate_examplesAndroidO_${name}" () {}
1127 }
1128 }
1129 examplesDir.eachDir { dir ->
1130 def name = dir.getName();
1131 def exampleOutputDir = file("build/test/examplesAndroidO");
1132 def jarName = "${name}.jar"
1133 dependsOn "jar_examplesAndroidO_${name}"
1134 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1135 "generate_examplesAndroidO_${name}"]) {
1136 archiveName = jarName
1137 destinationDir = exampleOutputDir
1138 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1139 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1140 include "**/" + name + "/**/*.class"
1141 // Do not include generator into the test runtime jar, it is not useful.
1142 // Otherwise, shrinking will need ASM jars.
1143 exclude "**/TestGenerator*"
1144 }
1145 }
1146}
1147
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001148task buildExampleAndroidPJars {
1149 dependsOn downloadDeps
1150 def examplesDir = file("src/test/examplesAndroidP")
1151
1152 task "compile_examplesAndroidP"(type: JavaCompile) {
1153 source = fileTree(dir: examplesDir, include: '**/*.java')
1154 destinationDir = file("build/test/examplesAndroidP/classes")
1155 classpath = sourceSets.main.compileClasspath
1156 sourceCompatibility = JavaVersion.VERSION_1_8
1157 targetCompatibility = JavaVersion.VERSION_1_8
1158 options.compilerArgs += ["-Xlint:-options"]
1159 }
1160 examplesDir.eachDir { dir ->
1161 def name = dir.getName();
1162 def destinationDir = file("build/test/examplesAndroidP/classes");
1163 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1164 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1165 dependsOn: "compile_examplesAndroidP") {
1166 main = name + ".TestGenerator"
1167 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1168 args destinationDir
1169 }
1170 } else {
1171 task "generate_examplesAndroidP_${name}" () {}
1172 }
1173 }
1174 examplesDir.eachDir { dir ->
1175 def name = dir.getName();
1176 def exampleOutputDir = file("build/test/examplesAndroidP");
1177 def jarName = "${name}.jar"
1178 dependsOn "jar_examplesAndroidP_${name}"
1179 task "jar_examplesAndroidP_${name}"(type: Jar,
1180 dependsOn: ["compile_examplesAndroidP",
1181 "generate_examplesAndroidP_${name}"]) {
1182 archiveName = jarName
1183 destinationDir = exampleOutputDir
1184 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1185 include "**/" + name + "/**/*.class"
1186 // Do not include generator into the test runtime jar, it is not useful.
1187 // Otherwise, shrinking will need ASM jars.
1188 exclude "**/TestGenerator*"
1189 }
1190 }
1191}
1192
Mikaël Peltier61633d42017-10-13 16:51:06 +02001193task buildExampleJava9Jars {
1194 def examplesDir = file("src/test/examplesJava9")
1195 examplesDir.eachDir { dir ->
1196 def name = dir.getName();
1197 def exampleOutputDir = file("build/test/examplesJava9");
1198 def jarName = "${name}.jar"
1199 dependsOn "jar_examplesJava9_${name}"
1200 task "jar_examplesJava9_${name}"(type: Jar) {
1201 archiveName = jarName
1202 destinationDir = exampleOutputDir
1203 from "src/test/examplesJava9" // Java 1.9 classes
1204 include "**/" + name + "/**/*.class"
1205 }
1206 }
1207}
1208
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001209task buildExamplesKotlin {
1210 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1211 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1212 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1213 } else if (!OperatingSystem.current().isLinux()) {
1214 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1215 "on your platform. It is fully supported on Linux and partially supported on " +
1216 "Mac OS and Windows")
1217 return;
1218 }
1219 def examplesDir = file("src/test/examplesKotlin")
1220 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001221 def name = dir.getName();
1222 dependsOn "dex_example_kotlin_${name}"
1223 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1224 def dexPath = file("${exampleOutputDir}")
1225 task "dex_example_kotlin_${name}"(type: dx.Dx,
1226 dependsOn: "compile_example_kotlin_${name}") {
1227 doFirst {
1228 if (!dexPath.exists()) {
1229 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001230 }
1231 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001232 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1233 destination = dexPath
1234 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001235 }
1236 }
1237}
1238
Sebastien Hertzd3313772018-01-16 14:12:37 +01001239task buildKotlinR8TestResources {
1240 def examplesDir = file("src/test/kotlinR8TestResources")
1241 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001242 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1243 def name = dir.getName()
1244 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001245 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1246 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001247 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001248 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001249 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1250 source = fileTree(dir: file("${examplesDir}/${name}"),
1251 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001252 destination = file(outputFile)
1253 targetVersion = kotlinTargetVersion
1254 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001255 task "${taskName}Java"(type: JavaCompile) {
1256 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1257 destinationDir = file(javaOutput)
1258 classpath = sourceSets.main.compileClasspath
1259 sourceCompatibility = JavaVersion.VERSION_1_6
1260 targetCompatibility = JavaVersion.VERSION_1_6
1261 options.compilerArgs += ["-g", "-Xlint:-options"]
1262 }
1263 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1264 archiveName = javaOutputJarName
1265 destinationDir = file(javaOutputJarDir)
1266 from javaOutput
1267 include "**/*.class"
1268 }
1269 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001270 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001271 }
1272}
1273
Mads Ager418d1ca2017-05-22 09:35:49 +02001274task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001275 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1276 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1277 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001278 } else if (!OperatingSystem.current().isLinux()) {
1279 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001280 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001281 return;
1282 }
1283 dependsOn buildDebugTestResourcesJars
1284 dependsOn buildExampleJars
1285 dependsOn buildExampleAndroidNJars
1286 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001287 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001288 dependsOn buildExampleJava9Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001289 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001290 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001291 def noDexTests = [
1292 "multidex",
1293 "multidex002",
1294 "multidex004",
1295 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001296 examplesDir.eachDir { dir ->
1297 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001298 if (!(name in noDexTests)) {
1299 dependsOn "dex_example_${name}"
1300 def exampleOutputDir = file("build/test/examples/" + name);
1301 def dexPath = file("${exampleOutputDir}")
1302 def debug = (name == "throwing")
1303 if (!dexPath.exists()) {
1304 dexPath.mkdirs()
1305 }
1306 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1307 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1308 destination = dexPath
1309 debug = debug
1310 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001311 }
1312 }
1313}
1314
1315task buildSmali {
1316 def smaliDir = file("src/test/smali")
1317 smaliDir.eachDirRecurse() { dir ->
1318 def name = dir.getName();
1319 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1320 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1321 smaliOutputDir.mkdirs()
1322 outputs.dir smaliOutputDir
1323 def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}"
1324 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1325 def javaFiles = fileTree(dir: dir, include: '*.java')
1326 def destDir = smaliOutputDir;
1327 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1328 def intermediateFileName = "${name}-intermediate.dex";
1329 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1330 if (javaFiles.empty) {
1331 if (!smaliFiles.empty) {
1332 dependsOn "${taskName}_smali"
1333 task "${taskName}_smali"(type: smali.Smali) {
1334 source = smaliFiles
1335 destination = destFile
1336 }
1337 }
1338 } else {
1339 dependsOn "${taskName}_dexmerger"
1340 task "${taskName}_smali"(type: smali.Smali) {
1341 source = smaliFiles
1342 destination = intermediateFile
1343 }
1344 task "${taskName}_java"(type: JavaCompile) {
1345 source = javaFiles
1346 destinationDir destDir
1347 classpath = sourceSets.main.compileClasspath
1348 sourceCompatibility = JavaVersion.VERSION_1_7
1349 targetCompatibility = JavaVersion.VERSION_1_7
1350 options.compilerArgs += ["-Xlint:-options"]
1351 }
1352 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1353 archiveName = "Test.jar"
1354 destinationDir = destDir
1355 from fileTree(dir: destDir, include: 'Test.class')
1356 }
1357 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1358 source = fileTree(dir: destDir, include: 'Test.jar')
1359 destination = destDir
1360 }
1361 task "${taskName}_dexmerger"(
1362 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1363 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1364 destination = destFile
1365 }
1366 }
1367 }
1368}
1369
1370tasks.withType(Test) {
1371 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1372 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1373 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
1374 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1
1375 forkEvery = 0
1376 // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level.
1377 jvmArgs = ["-XX:+UseConcMarkSweepGC"]
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001378 if (project.hasProperty('disable_assertions')) {
1379 enableAssertions = false
1380 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001381}
1382
1383task buildPreNJdwpTestsJar(type: Jar) {
1384 baseName = 'jdwp-tests-preN'
1385 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1386 // Exclude the classes containing java8
1387 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1388 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1389 includeEmptyDirs = false
1390}
1391
Ian Zerny74143162017-11-24 13:46:35 +01001392task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1393 def inFile = buildPreNJdwpTestsJar.archivePath
1394 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
1395 inputs.file inFile
1396 outputs.file outFile
1397 if (OperatingSystem.current().isWindows()) {
1398 executable file("tools/windows/dx/bin/dx.bat")
1399 } else if (OperatingSystem.current().isMacOsX()) {
1400 executable file("tools/mac/dx/bin/dx");
1401 } else {
1402 executable file("tools/linux/dx/bin/dx");
1403 }
1404 args "--dex"
1405 args "--output=${outFile}"
1406 args inFile
1407}
1408
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001409task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1410 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001411}
1412
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001413task AospJarTest(type: Exec) {
1414 dependsOn CompatDx, downloadDeps
1415 def script = "tools/test_aosp_jar.py"
1416 inputs.file script
1417 commandLine "python", script, "--no-build"
1418 workingDir = projectDir
1419}
1420
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001421def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001422 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001423 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001424 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001425 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001426 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001427 return null
1428}
1429
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001430task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001431 dependsOn testJar
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +01001432 inputs.file "$buildDir/libs/r8tests.jar"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001433 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001434 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001435 delete r8LibTestPath
1436 from zipTree(testJar.outputs.files[0])
1437 into r8LibTestPath
1438 include "com/android/tools/r8/**"
1439 include "dalvik/**"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001440 }
1441 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001442}
1443
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001444def printStackTrace(TestResult result) {
1445 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1446 def out = new StringBuffer()
1447 def err = new StringBuffer()
1448 def command = "tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001449 def header = "RETRACED STACKTRACE";
1450 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1451 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1452 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1453 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001454 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001455 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001456 out.append("--------------------------------------\n")
1457 Process process = command.execute()
1458 def processIn = new PrintStream(process.getOut())
1459 process.consumeProcessOutput(out, err)
1460 result.exception.printStackTrace(processIn)
1461 processIn.flush()
1462 processIn.close()
1463 process.waitFor()
1464 out.append("\n\n--------------------------------------\n")
1465 out.append("OBFUSCATED STACKTRACE\n")
1466 out.append("--------------------------------------\n")
1467 result.exceptions.add(0, new Exception(out.toString()))
1468 } else {
1469 result.exception.printStackTrace()
1470 }
1471}
1472
Mads Ager418d1ca2017-05-22 09:35:49 +02001473test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001474 if (project.hasProperty('generate_golden_files_to')) {
1475 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1476 assert project.hasProperty('HEAD_sha1')
1477 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1478 }
1479
1480 if (project.hasProperty('use_golden_files_in')) {
1481 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1482 assert project.hasProperty('HEAD_sha1')
1483 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1484 }
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001485 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001486 // R8.jar is required for running bootstrap tests.
1487 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001488 testLogging.exceptionFormat = 'full'
1489 if (project.hasProperty('print_test_stdout')) {
1490 testLogging.showStandardStreams = true
1491 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001492 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001493 println "Running with non default vm: " + project.property('dex_vm')
1494 systemProperty 'dex_vm', project.property('dex_vm')
Ian Zerny3f4ed602017-10-05 06:54:13 +02001495 if (project.property('dex_vm').startsWith('4.4.4') ||
1496 project.property('dex_vm').startsWith('5.1.1') ||
1497 project.property('dex_vm').startsWith('6.0.1')) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001498 // R8 and D8 compute the dex file version number based on the input.
1499 // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run.
1500 // Therefore we skip the jack generated art tests with those art versions.
1501 exclude "com/android/tools/r8/art/jack/**"
1502 }
1503 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001504
Mads Ager418d1ca2017-05-22 09:35:49 +02001505 if (project.hasProperty('one_line_per_test')) {
1506 beforeTest { desc ->
1507 println "Start executing test ${desc.name} [${desc.className}]"
1508 }
1509 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001510 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001511 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001512 }
Rico Windda6836e2018-12-07 12:32:03 +01001513 if (project.hasProperty('update_test_timestamp')) {
1514 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1515 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001516 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1517 }
Rico Windf88b6be2018-12-11 15:14:05 +01001518 } else {
1519 afterTest { desc, result ->
1520 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001521 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001522 }
1523 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001524 }
1525 if (project.hasProperty('no_internal')) {
1526 exclude "com/android/tools/r8/internal/**"
1527 }
1528 if (project.hasProperty('only_internal')) {
1529 include "com/android/tools/r8/internal/**"
1530 }
1531 if (project.hasProperty('tool')) {
1532 if (project.property('tool') == 'r8') {
1533 exclude "com/android/tools/r8/art/*/d8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001534 exclude "com/android/tools/r8/jctf/d8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001535 exclude "com/android/tools/r8/jctf/r8cf/**"
1536 } else if (project.property('tool') == 'd8') {
Mads Ager418d1ca2017-05-22 09:35:49 +02001537 exclude "com/android/tools/r8/art/*/r8/**"
Tamas Kenez69c2e8b2017-05-31 13:41:07 +02001538 exclude "com/android/tools/r8/jctf/r8/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001539 exclude "com/android/tools/r8/jctf/r8cf/**"
1540 } else {
1541 assert(project.property('tool') == 'r8cf')
1542 exclude "com/android/tools/r8/art/*/d8/**"
1543 exclude "com/android/tools/r8/art/*/r8/**"
1544 exclude "com/android/tools/r8/jctf/d8/**"
1545 exclude "com/android/tools/r8/jctf/r8/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001546 }
1547 }
1548 if (!project.hasProperty('all_tests')) {
1549 exclude "com/android/tools/r8/art/dx/**"
1550 exclude "com/android/tools/r8/art/jack/**"
1551 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001552 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001553 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001554 }
1555 if (project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001556 include "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001557 }
1558 if (project.hasProperty('jctf_compile_only')) {
1559 println "JCTF: compiling only"
1560 systemProperty 'jctf_compile_only', '1'
1561 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001562 if (project.hasProperty('test_dir')) {
1563 systemProperty 'test_dir', project.property('test_dir')
1564 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001565 if (project.hasProperty('aosp_jar')) {
1566 dependsOn AospJarTest
1567 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001568 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1569 dependsOn configureTestForR8Lib
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001570 // We remove build/classes/test from classpath and rely on configureTestForR8Lib to provide
1571 // all needed tests in r8LibTestPath.
1572 classpath = files([r8LibPath, r8LibTestPath]) +
1573 sourceSets.test.runtimeClasspath -
1574 sourceSets.main.output -
1575 files(['build/classes/test'])
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001576 testClassesDir = new File(r8LibTestPath)
1577 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001578 if (OperatingSystem.current().isLinux()
1579 || OperatingSystem.current().isMacOsX()
1580 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001581 if (OperatingSystem.current().isMacOsX()) {
1582 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1583 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1584 "See tools/docker/README.md for details.")
1585 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001586 if (OperatingSystem.current().isWindows()) {
1587 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1588 "Art only runs on Linux and tests requiring Art will be skipped")
1589 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001590 dependsOn downloadDeps
1591 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001592 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001593 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001594 dependsOn buildSmali
1595 dependsOn jctfCommonJar
1596 dependsOn jctfTestsClasses
1597 dependsOn buildDebugInfoExamplesDex
1598 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001599 dependsOn buildPreNJdwpTestsDex
Mads Ager418d1ca2017-05-22 09:35:49 +02001600 } else {
1601 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001602 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001603 }
1604}
1605
1606// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1607//
1608// To build and upload a new set of the Art tests for use with R8 follow these steps:
1609//
1610// First of all an Android checkout is required. Currently it must be located
1611// in $HOME/android/master.
1612//
1613// TODO(ricow): simplify this
1614//
1615// Before: update the checked in art, see scripts/update-host-art.sh
1616//
1617// 1. Get an android checkout in $HOME/android/master and apply the patch from
1618// https://android-review.googlesource.com/#/c/294187/
1619//
1620// 2. run the following commands in the Android checkout directory:
1621//
1622// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001623// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1624// m desugar
1625// m -j30 test-art-host
1626// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1627//
1628// Without running the test.py command the classes.jar file used by desugar in
1629// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1630// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001631//
1632// 3. In the R8 project root directory, make sure we have a clean state before starting:
1633// tools/gradle.py downloadDeps
1634// tools/gradle.py clean
1635// rm -rf tests/art
1636//
1637// 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 +02001638// Make sure you have smali on your path, please use the build binary in the
1639// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
1640// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
1641// 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 +02001642// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
1643// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02001644//
Søren Gjesse34b77732017-07-07 13:56:21 +02001645// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02001646//
1647// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
1648// skippedTests with an explanation. Rerun from step 3.
1649//
1650// 5. Run the tests:
1651// tools/gradle.py clean
1652// tools/test.py
1653//
Søren Gjesse34b77732017-07-07 13:56:21 +02001654// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
1655// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
1656// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02001657//
Søren Gjesse34b77732017-07-07 13:56:21 +02001658// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02001659// cd tests
1660// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02001661//
1662// 7. Update the manifest file describing the Android repo used:
1663// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02001664
1665enum DexTool {
1666 JACK,
1667 DX
1668}
1669
1670def androidCheckoutDir = file("${System.env.HOME}/android/master")
1671def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack");
1672def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin");
1673
1674def artTestDir = file("${androidCheckoutDir}/art/test")
1675
1676if (project.hasProperty('android_source')) {
1677 task buildArtTests {
1678 outputs.upToDateWhen { false }
1679 def toBeTriaged = [
1680 "903-hello-tagging",
1681 "904-object-allocation",
1682 "905-object-free",
1683 "906-iterate-heap",
1684 "907-get-loaded-classes",
1685 "908-gc-start-finish",
1686 "954-invoke-polymorphic-verifier",
1687 "955-methodhandles-smali",
1688 "596-monitor-inflation",
1689 ]
1690 def skippedTests = toBeTriaged + [
1691 // This test produces no jar.
1692 "000-nop",
1693 // This does not build, as it tests the error when the application exceeds more
1694 // than 65536 methods
1695 "089-many-methods",
1696 // Requires some jack beta jar
1697 "956-methodhandles",
1698 ]
1699
1700 def skippedTestsDx = [
1701 // Tests with custom build scripts, where javac is not passed the options
1702 // -source 1.7 -target 1.7.
1703 "462-checker-inlining-across-dex-files",
1704 "556-invoke-super",
1705 "569-checker-pattern-replacement",
1706 // These tests use jack even when --build-with-javac-dx is specified.
1707 "004-JniTest",
1708 "048-reflect-v8",
1709 "146-bad-interface",
1710 "563-checker-invoke-super",
1711 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
1712 "604-hot-static-interface",
1713 "957-methodhandle-transforms",
1714 "958-methodhandle-emulated-stackframe",
1715 "959-invoke-polymorphic-accessors",
1716 "961-default-iface-resolution-gen",
1717 "962-iface-static",
1718 "963-default-range-smali",
1719 "964-default-iface-init-gen",
1720 "965-default-verify",
1721 "966-default-conflict",
1722 "967-default-ame",
1723 "968-default-partial-compile-gen",
1724 "969-iface-super",
1725 "970-iface-super-resolution-gen",
1726 "971-iface-super",
1727 // These tests does not build with --build-with-javac-dx
1728 "004-NativeAllocations", // Javac error
1729 "031-class-attributes",
1730 "138-duplicate-classes-check",
1731 "157-void-class", // Javac error
1732 "580-checker-string-factory-intrinsics",
1733 "612-jit-dex-cache",
1734 "613-inlining-dex-cache",
1735 "900-hello-plugin", // --experimental agents
1736 "901-hello-ti-agent", // --experimental agents
1737 "902-hello-transformation", // --experimental agents
1738 "909-attach-agent", // --experimental agents
1739 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
1740 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
1741 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
1742 "960-default-smali", // --experimental default-methods
1743 // These tests force the build to use jack
1744 "953-invoke-polymorphic-compiler",
1745 "958-methodhandle-stackframe",
1746 ]
1747
1748 def artTestBuildDir = file("${projectDir}/tests/art")
1749
1750 if (androidCheckoutDir.exists()) {
1751 dependsOn downloadDeps
1752 artTestBuildDir.mkdirs()
1753 // Ensure Jack server is running.
1754 "${androidCheckoutJackServer} start-server".execute()
1755 artTestDir.eachDir { dir ->
1756 def name = dir.getName();
1757 def markerFile = dir.toPath().resolve("info.txt").toFile();
1758 if (markerFile.exists() && !(name in skippedTests)) {
1759 if (!(name in skippedTestsDx)) {
1760 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX);
1761 }
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001762 // After Android O, Jack is no longer alive
1763 //dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK);
Mads Ager418d1ca2017-05-22 09:35:49 +02001764 }
1765 }
1766 }
1767 doFirst {
1768 if (!androidCheckoutDir.exists()) {
1769 throw new InvalidUserDataException(
1770 "This task requires an Android checkout in ${androidCheckoutDir}");
1771 } else if (!androidCheckoutJack.exists() ||
1772 !androidCheckoutJackServer.exists()) {
1773 throw new InvalidUserDataException(
1774 "This task requires that tools for host testing have been build in the " +
1775 "Android checkout in ${androidCheckoutDir}");
1776 }
1777 }
1778 doLast {
1779 copy {
1780 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
1781 into file("${artTestBuildDir}/lib64")
1782 include 'lib*.so'
1783 }
1784 copy {
1785 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
1786 into file("${artTestBuildDir}/lib64")
1787 include 'libart.so'
1788 include 'libbacktrace.so'
1789 include 'libbase.so'
1790 include 'libc++.so'
1791 include 'libcutils.so'
1792 include 'liblz4.so'
1793 include 'liblzma.so'
1794 include 'libnativebridge.so'
1795 include 'libnativeloader.so'
1796 include 'libsigchain.so'
1797 include 'libunwind.so'
1798 include 'libziparchive.so'
1799 }
1800 copy {
1801 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
1802 into file("${artTestBuildDir}/lib")
1803 include 'lib*.so'
1804 }
1805 copy {
1806 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
1807 into file("${artTestBuildDir}/lib")
1808 include 'libart.so'
1809 include 'libbacktrace.so'
1810 include 'libbase.so'
1811 include 'libc++.so'
1812 include 'libcutils.so'
1813 include 'liblz4.so'
1814 include 'liblzma.so'
1815 include 'libnativebridge.so'
1816 include 'libnativeloader.so'
1817 include 'libsigchain.so'
1818 include 'libunwind.so'
1819 include 'libziparchive.so'
1820 }
1821 }
1822 }
1823}
1824
1825def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) {
1826 def artTestDir = file("${androidCheckoutDir}/art/test")
1827 def artRunTestScript = file("${artTestDir}/run-test")
1828 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02001829 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02001830 def dexToolName = dexTool == DexTool.DX ? "dx" : "jack"
1831
Søren Gjesse34b77732017-07-07 13:56:21 +02001832 def name = dir.getName()
Mads Ager418d1ca2017-05-22 09:35:49 +02001833 def buildTask = "build_art_test_${dexToolName}_${name}"
1834 def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}"
1835 def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}"
1836 def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}"
1837
1838 def buildInputs = fileTree(dir: dir, include: '**/*')
1839 def testDir = file("${artTestBuildDir}/${dexToolName}/${name}")
1840 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
1841 testDir.mkdirs()
1842 if (dexTool == DexTool.DX) {
1843 task "$buildTask"(type: Exec) {
1844 outputs.upToDateWhen { false }
1845 inputs.file buildInputs
1846 executable "${artRunTestScript}"
1847 args "--host"
1848 args "--build-only"
1849 args "--build-with-javac-dx"
1850 args "--output-path", "${testDir}"
1851 args "${name}"
1852 environment DX: "${dxExecutable.absolutePath}"
1853 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
Søren Gjesse34b77732017-07-07 13:56:21 +02001854 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001855 outputs.file outputJar
1856 }
1857 } else {
1858 assert dexTool == DexTool.JACK
1859 def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES"
1860 def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" +
1861 "${javaLibs}/core-oj-hostdex_intermediates/classes.jack"
1862 task "$buildTask"(type: Exec) {
1863 outputs.upToDateWhen { false }
1864 inputs.file buildInputs
1865 executable "${artRunTestScript}"
1866 args "--host"
1867 args "--build-only"
1868 args "--output-path", "${testDir}"
1869 args "${name}"
1870 environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack"
1871 environment JACK_CLASSPATH: jackClasspath
1872 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
1873 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
1874 outputs.file outputJar
1875 }
1876 }
1877 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
1878 outputs.upToDateWhen { false }
1879 executable "/bin/bash"
1880 args "-c"
1881 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
1882 " ${testDir}/classes-ex ${testDir}/check"
1883 }
1884
1885 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02001886 // Directory that contains smali files is either smali, or smali/art
1887 def smali_dir = file("${dir}/smali/art")
1888 if (smali_dir.exists()) {
1889 workingDir "${testDir}/smali/art"
1890 } else {
1891 workingDir "${testDir}/smali"
1892 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001893 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02001894 // This is the command line options for smali prior to 2.2.1, where smali got a new
1895 // command line interface.
1896 args "-c", "smali a *.smali"
1897 // This is the command line options for smali 2.2.1 and later.
1898 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02001899 }
1900
1901 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
1902 def smali_dir = file("${dir}/smali")
1903 outputs.upToDateWhen { false }
1904 if (smali_dir.exists() && dexTool == DexTool.DX) {
1905 dependsOn smaliToDexTask
1906 }
1907 from("${artTestDir}/${name}") {
1908 include 'check'
1909 }
1910 into testDir
1911 }
1912
1913 return copyCheckTask
1914}
1915
1916task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01001917 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02001918 classpath = sourceSets.main.compileClasspath
1919 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001920 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001921 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001922 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001923 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02001924 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001925 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001926 include '**/com/android/tools/r8/CompilationMode.java'
1927 include '**/com/android/tools/r8/D8.java'
1928 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001929 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1930 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001931 include '**/com/android/tools/r8/Diagnostic.java'
1932 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001933 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1934 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001935 include '**/com/android/tools/r8/ProgramConsumer.java'
1936 include '**/com/android/tools/r8/ProgramResource.java'
1937 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001938 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001939 include '**/com/android/tools/r8/ResourceException.java'
1940 include '**/com/android/tools/r8/StringConsumer.java'
1941 include '**/com/android/tools/r8/StringResource.java'
1942 include '**/com/android/tools/r8/Version.java'
1943 include '**/com/android/tools/r8/origin/*.java'
1944}
1945
1946task javadocR8(type: Javadoc) {
1947 title "R8 API"
1948 classpath = sourceSets.main.compileClasspath
1949 source = sourceSets.main.allJava
1950 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
1951 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
1952 include '**/com/android/tools/r8/BaseCommand.java'
1953 include '**/com/android/tools/r8/BaseCompilerCommand.java'
1954 include '**/com/android/tools/r8/ClassFileConsumer.java'
1955 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
1956 include '**/com/android/tools/r8/CompilationFailedException.java'
1957 include '**/com/android/tools/r8/CompilationMode.java'
1958 include '**/com/android/tools/r8/R8.java'
1959 include '**/com/android/tools/r8/R8Command.java'
1960 include '**/com/android/tools/r8/DexIndexedConsumer.java'
1961 include '**/com/android/tools/r8/Diagnostic.java'
1962 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01001963 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
1964 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01001965 include '**/com/android/tools/r8/ProgramConsumer.java'
1966 include '**/com/android/tools/r8/ProgramResource.java'
1967 include '**/com/android/tools/r8/ProgramResourceProvider.java'
1968 include '**/com/android/tools/r8/Resource.java'
1969 include '**/com/android/tools/r8/ResourceException.java'
1970 include '**/com/android/tools/r8/StringConsumer.java'
1971 include '**/com/android/tools/r8/StringResource.java'
1972 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01001973 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02001974}
Søren Gjesse39a909a2017-10-12 09:49:20 +02001975
1976task copyMavenDeps(type: Copy) {
1977 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01001978 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02001979 from configurations.testCompile into "$buildDir/deps"
1980}
Mikaël Peltier61633d42017-10-13 16:51:06 +02001981
1982// This task allows to build class files from Java 9 source in order to use them as inputs of
1983// D8/R8 tests. Class files are generated in the same place than source files and must be commited
1984// to the D8 repository because there is no way to generate them on all computers due to the need of
1985// Java 9.
1986// Use the following command to rebuild class files of tests:
1987// ./tools/gradle.py -Pjava9Home=<java 9 home> buildJava9Tests
1988task buildJava9Tests {
1989 def javacOutputFolder = getTemporaryDir();
1990 def examplesDir = file("src/test/examplesJava9")
1991
1992 task "compile_Java9examples"(type: JavaCompile) {
1993 doFirst {
1994 if (!project.hasProperty('java9Home') || project.property('java9Home').isEmpty()) {
1995 throw new GradleException("Set java9Home property.")
1996 }
1997 }
1998
1999 source = fileTree(dir: examplesDir, include: '**/*.java')
2000 destinationDir = javacOutputFolder
2001 classpath = sourceSets.main.compileClasspath
2002 options.compilerArgs += ["-Xlint:-options"]
2003 sourceCompatibility = JavaVersion.VERSION_1_9
2004 targetCompatibility = JavaVersion.VERSION_1_9
2005 options.fork = true
2006
2007 if (project.hasProperty('java9Home')) {
2008 options.forkOptions.javaHome = file(getProperty('java9Home'))
2009 }
2010
2011 doLast {
2012 def classfileFrom = copySpec {
2013 from javacOutputFolder
2014 include "**/*.class"
2015 }
2016 copy {
2017 into examplesDir
2018 with classfileFrom
2019 }
2020 delete javacOutputFolder
2021 }
2022 }
2023
2024 dependsOn compile_Java9examples
Benoit Lamarchea032e472017-10-17 10:52:59 +02002025}