blob: 2e644580efe853c31c995485cf43a473313cb45e [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.
Ian Zerny5fffb0a2019-02-11 13:54:22 +01004
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +00005import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Jake Wharton2d7aab82019-09-13 10:24:26 -04006import dx.DexMergerTask
7import dx.DxTask
Ian Zerny5fffb0a2019-02-11 13:54:22 +01008import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02009import org.gradle.internal.os.OperatingSystem
Jake Wharton2d7aab82019-09-13 10:24:26 -040010import smali.SmaliTask
Ian Zernyb2d27c42019-02-20 09:09:41 +010011import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +000012import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020013import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020014
Ian Zerny5fffb0a2019-02-11 13:54:22 +010015buildscript {
16 repositories {
Rico Wind23a05112019-03-27 08:00:44 +010017 maven {
18 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
19 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010020 mavenCentral()
Jake Wharton5e5b5232019-09-17 16:13:32 -040021 gradlePluginPortal()
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010022 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010023 }
24 dependencies {
clementbera0bca05e2019-05-29 14:11:18 +020025 classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010026 }
27}
28
29plugins {
30 id "net.ltgt.errorprone" version "0.7"
31}
32
33apply plugin: 'java'
34apply plugin: 'idea'
35
Sebastien Hertz143ed112018-02-13 14:26:41 +010036ext {
37 androidSupportVersion = '25.4.0'
clementbera45cea0a2019-04-09 09:26:57 +020038 asmVersion = '7.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010039 espressoVersion = '3.0.0'
40 fastutilVersion = '7.2.0'
41 guavaVersion = '23.0'
42 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020043 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010044 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080045 mockitoVersion = '2.10.0'
Jinseong Jeon87caee62019-08-16 00:17:26 -070046 kotlinVersion = '1.3.41'
Jinseong Jeon20124782019-08-06 22:52:17 -070047 kotlinExtMetadataJVMVersion = '0.1.0'
Sebastien Hertz143ed112018-02-13 14:26:41 +010048 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010049 errorproneVersion = '2.3.2'
clementbera4f9c2a92019-07-09 08:50:37 +020050 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010051}
52
Mads Ager418d1ca2017-05-22 09:35:49 +020053apply from: 'copyAdditionalJctfCommonFiles.gradle'
54
55repositories {
Rico Wind23a05112019-03-27 08:00:44 +010056 maven {
57 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
58 }
Jake Wharton5e5b5232019-09-17 16:13:32 -040059 google()
Mads Ager418d1ca2017-05-22 09:35:49 +020060 mavenCentral()
61}
62
Jinseong Jeon05064e12018-07-03 00:21:12 -070063if (project.hasProperty('with_code_coverage')) {
64 apply plugin: 'jacoco'
65}
66
Mads Ager418d1ca2017-05-22 09:35:49 +020067// Custom source set for example tests and generated tests.
68sourceSets {
69 test {
70 java {
71 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020072 'src/test/java',
73 'build/generated/test/java',
74 ]
75 }
76 }
Yohann Rousselbb571622017-11-09 10:47:36 +010077 apiUsageSample {
78 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020079 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
80 include 'com/android/tools/apiusagesample/*.java'
81 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
82 include 'com/android/tools/r8/D8CommandParser.java'
83 include 'com/android/tools/r8/R8CommandParser.java'
84 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010085 }
Yohann Rousselbb571622017-11-09 10:47:36 +010086 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010087 cfSegments {
88 java {
89 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
90 }
91 output.resourcesDir = 'build/classes/cfSegments'
92 }
Mads Ager418d1ca2017-05-22 09:35:49 +020093 debugTestResources {
94 java {
95 srcDirs = ['src/test/debugTestResources']
96 }
97 output.resourcesDir = 'build/classes/debugTestResources'
98 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020099 debugTestResourcesJava8 {
100 java {
101 srcDirs = ['src/test/debugTestResourcesJava8']
102 }
103 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
104 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200105 debugTestResourcesKotlin {
106 java {
107 srcDirs = ['src/test/debugTestResourcesKotlin']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
110 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200111 examples {
112 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800113 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200114 }
115 output.resourcesDir = 'build/classes/examples'
116 }
Ian Zernyd3020482019-04-25 07:05:04 +0200117 examplesJava9 {
118 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200119 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200120 }
121 }
122 examplesJava11 {
123 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200124 srcDirs = ['src/test/examplesJava11']
125 }
126 }
clementbera4f9c2a92019-07-09 08:50:37 +0200127 jdk11TimeTests {
128 java {
129 srcDirs = [
130 'third_party/openjdk/jdk-11-test/java/time/tck',
131 'third_party/openjdk/jdk-11-test/java/time/test'
132 ]
133 exclude '**/TestZoneTextPrinterParser.java'
134 }
135 }
clementberaefa10522019-07-11 11:20:46 +0200136 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200137 java {
138 srcDirs = ['src/test/testngrunner']
139 }
140 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100141 examplesKotlin {
142 java {
143 srcDirs = ['src/test/examplesKotlin']
144 }
145 output.resourcesDir = 'build/classes/examplesKotlin'
146 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200147 examplesAndroidN {
148 java {
149 srcDirs = ['src/test/examplesAndroidN']
150 }
151 output.resourcesDir = 'build/classes/examplesAndroidN'
152 }
153 examplesAndroidO {
154 java {
155 srcDirs = ['src/test/examplesAndroidO']
156 }
157 output.resourcesDir = 'build/classes/examplesAndroidO'
158 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200159 examplesAndroidP {
160 java {
161 srcDirs = ['src/test/examplesAndroidP']
162 }
163 output.resourcesDir = 'build/classes/examplesAndroidP'
164 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200165 examplesProto {
166 java {
167 srcDirs = ['src/test/examplesProto']
168 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200169 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
170 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200171 output.resourcesDir = 'build/classes/examplesProto'
172 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200173 jctfCommon {
174 java {
175 srcDirs = [
176 'third_party/jctf/Harness/src',
177 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
178 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
179 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
180 'third_party/jctf/LibTests/src/org',
181 'build/additionalJctfCommonFiles'
182 ]
183 }
184 resources {
185 srcDirs = ['third_party/jctf/LibTests/resources']
186 }
187 }
188 jctfTests {
189 java {
190 srcDirs = [
191 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
192 // 'third_party/jctf/VMTests/src',
193 ]
194 }
195 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100196 kotlinR8TestResources {
197 java {
198 srcDirs = ['src/test/kotlinR8TestResources']
199 }
200 output.resourcesDir = 'build/classes/kotlinR8TestResources'
201 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200202}
203
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800204// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
205// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
206// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
207// for context.
208idea {
209 sourceSets.all { SourceSet sources ->
210 module {
211 if (sources.name == "main") {
212 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100213 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800214 } else {
215 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100216 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800217 }
218 }
219 }
220}
221
Yohann Roussel126f6872017-08-03 16:25:32 +0200222configurations {
223 supportLibs
224}
225
Mads Ager418d1ca2017-05-22 09:35:49 +0200226dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100227 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
228 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200229 // Include all of guava when compiling the code, but exclude annotations that we don't
230 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100231 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100232 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200233 exclude group: 'com.google.errorprone'
234 exclude group: 'com.google.code.findbugs'
235 exclude group: 'com.google.j2objc'
236 exclude group: 'org.codehaus.mojo'
237 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100238 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
239 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
240 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
241 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
242 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
243 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
244 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
clementbera4f9c2a92019-07-09 08:50:37 +0200245 jdk11TimeTestsCompile group: 'org.testng', name: 'testng', version: testngVersion
clementberaefa10522019-07-11 11:20:46 +0200246 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200247 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100248 testCompile "junit:junit:$junitVersion"
249 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200250 testCompile files('third_party/jasmin/jasmin-2.4.jar')
251 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200252 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100253 jctfCommonCompile "junit:junit:$junitVersion"
254 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200255 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100256 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
257 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200258 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100259 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800260 examplesCompile "junit:junit:$junitVersion"
261 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100262 supportLibs "com.android.support:support-v4:$androidSupportVersion"
263 supportLibs "junit:junit:$junitVersion"
264 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100265 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100266 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100267 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
268 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
269 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100270 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200271}
272
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100273def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100274def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100275def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100276def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100277def r8LibTestPath = "$buildDir/classes/r8libtest"
clementbera0bca05e2019-05-29 14:11:18 +0200278def java11ClassFiles = "build/classes/java/mainJava11"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100279
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200280def osString = OperatingSystem.current().isLinux() ? "linux" :
281 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200282
283def cloudDependencies = [
284 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200285 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100286 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200287 ],
288 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200289 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200290 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100291 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "android_jar/lib-v19",
293 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100294 "android_jar/lib-v22",
295 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200296 "android_jar/lib-v24",
297 "android_jar/lib-v25",
298 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100299 "android_jar/lib-v27",
300 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200301 "android_jar/lib-v29",
Rico Windf72fa152018-10-22 15:41:03 +0200302 "core-lambda-stubs",
303 "dart-sdk",
304 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200305 "gradle/gradle",
Ian Zerny33c1c582019-09-17 12:43:45 +0200306 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200307 "iosched_2019",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200308 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200309 "jasmin",
310 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100311 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200312 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200313 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200314 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200315 "rhino-android-1.1.1",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200316 "kotlin",
Ian Zerny23942992019-07-10 14:33:52 +0200317 "kotlin-compiler-1.3.41",
Mathias Rav5285faf2018-03-20 14:16:32 +0100318 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200319 "openjdk/desugar_jdk_libs",
clementbera8dbfeda2019-07-03 11:24:13 +0200320 "openjdk/jdk-11-test",
Rico Windf72fa152018-10-22 15:41:03 +0200321 "proguard/proguard5.2.1",
322 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200323 "r8",
Morten Krogh-Jespersenbc0ffda2019-09-04 16:17:54 +0200324 "r8mappings"
Mads Ager418d1ca2017-05-22 09:35:49 +0200325 ],
326 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
327 // container on other platforms where supported.
328 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200329 "linux/art",
330 "linux/art-5.1.1",
331 "linux/art-6.0.1",
332 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100333 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100334 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200335 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100336 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200337 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200338 ]
339]
340
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100341def cloudSystemDependencies = [
342 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200343 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200344 "openjdk/jdk8/linux-x86",
345 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100346 ],
347 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200348 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200349 "openjdk/jdk8/darwin-x86",
350 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100351 ],
352 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200353 "third_party": ["openjdk/openjdk-9.0.4/windows",
354 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100355 ],
356]
357
358if (OperatingSystem.current().isWindows()) {
359 cloudSystemDependencies.windows.each { entry ->
360 cloudDependencies.get(entry.key).addAll(entry.value)
361 }
362} else if (OperatingSystem.current().isLinux()) {
363 cloudSystemDependencies.linux.each { entry ->
364 cloudDependencies.get(entry.key).addAll(entry.value)
365 }
366} else if (OperatingSystem.current().isMacOsX()) {
367 cloudSystemDependencies.osx.each { entry ->
368 cloudDependencies.get(entry.key).addAll(entry.value)
369 }
370} else {
371 println "WARNING: Unsupported system: " + OperatingSystem.current()
372}
373
374def getDownloadDepsTaskName(entryKey, entryFile) {
375 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
376}
377
Mads Ager418d1ca2017-05-22 09:35:49 +0200378cloudDependencies.each { entry ->
379 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100380 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
381 type DownloadDependency.Type.GOOGLE_STORAGE
382 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200383 }
384 }
385}
386
387def x20Dependencies = [
388 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200389 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700390 "chrome/chrome_180917_ffbaa8",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100391 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100392 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200393 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100394 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200395 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200396 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200397 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200398 "gmscore/gmscore_v10",
399 "gmscore/gmscore_v9",
400 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200401 "gmscore/v4",
402 "gmscore/v5",
403 "gmscore/v6",
404 "gmscore/v7",
405 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200406 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200407 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200408 "proguard/proguard_internal_159423826",
409 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200410 "proto",
411 "protobuf-lite",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200412 "youtube/youtube.android_12.10",
413 "youtube/youtube.android_12.17",
414 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200415 "youtube/youtube.android_13.37",
Søren Gjesse889e09d2019-11-07 16:33:51 +0100416 "youtube/youtube.android_14.19",
417 "youtube/youtube.android_14.44"
Mads Ager418d1ca2017-05-22 09:35:49 +0200418 ],
419]
420
421x20Dependencies.each { entry ->
422 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100423 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
424 type DownloadDependency.Type.X20
425 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200426 }
427 }
428}
429
Rico Wind897bb712017-05-23 10:44:29 +0200430task downloadProguard {
431 cloudDependencies.each { entry ->
432 entry.value.each { entryFile ->
433 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100434 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200435 }
436 }
437 }
438}
439
Rico Windf6c74ce2018-12-04 08:50:55 +0100440task downloadOpenJDKrt {
441 cloudDependencies.each { entry ->
442 entry.value.each { entryFile ->
443 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100444 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100445 }
446 }
447 }
448}
449
Tamas Kenez427205b2017-06-29 15:57:09 +0200450task downloadDx {
451 cloudDependencies.each { entry ->
452 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200453 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100454 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200455 }
456 }
457 }
458}
459
Tamas Kenez0e10c562017-06-08 10:00:34 +0200460task downloadAndroidCts {
461 cloudDependencies.each { entry ->
462 entry.value.each { entryFile ->
463 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100464 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200465 }
466 }
467 }
468}
469
Mads Ager418d1ca2017-05-22 09:35:49 +0200470task downloadDeps {
471 cloudDependencies.each { entry ->
472 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100473 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200474 }
475 }
476 if (!project.hasProperty('no_internal')) {
477 x20Dependencies.each { entry ->
478 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100479 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200480 }
481 }
482 }
483}
484
485allprojects {
486 sourceCompatibility = JavaVersion.VERSION_1_8
487 targetCompatibility = JavaVersion.VERSION_1_8
488}
489
Rico Wind266336c2019-02-25 10:11:38 +0100490// TODO(ricow): Remove debug prints
491println("NOTE: Current operating system: " + OperatingSystem.current())
492println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
493
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100494// Check if running with the JDK location from tools/jdk.py.
495if (OperatingSystem.current().isWindows()) {
496 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
497} else {
498 def javaHomeOut = new StringBuilder()
499 def javaHomeErr = new StringBuilder()
500 def javaHomeProc = './tools/jdk.py'.execute()
501 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
502 def jdkHome = new File(javaHomeOut.toString().trim())
503 if (!jdkHome.exists()) {
504 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
505 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
506 println("WARNING: Gradle is running in a non-pinned Java"
507 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
508 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100509 } else {
510 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100511 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200512}
513
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100514sourceSets.configureEach { sourceSet ->
515 tasks.named(sourceSet.compileJavaTaskName).configure {
516 // Default disable errorprone (enabled and setup below).
517 options.errorprone.enabled = false
518 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100519 // Run all compilation tasks in a forked subprocess.
520 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100521 // Javac often runs out of stack space when compiling the tests.
522 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200523 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100524 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200525 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100526 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
527 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
528 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200529}
530
Ian Zernyd3020482019-04-25 07:05:04 +0200531tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
532 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200533 options.fork = true
534 options.forkOptions.jvmArgs = []
535 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200536 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200537 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200538 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200539 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200540 options.forkOptions.javaHome = file(jdkDir + 'windows')
541 }
542 sourceCompatibility = JavaVersion.VERSION_1_9
543 targetCompatibility = JavaVersion.VERSION_1_9
544}
545
clementbera0bdd90f2019-07-06 11:15:23 +0200546def setJava11Compilation(sourceSet) {
547 tasks.named(sourceSet).get().configure {
548 def jdkDir = 'third_party/openjdk/jdk-11/'
549 options.fork = true
550 options.forkOptions.jvmArgs = []
551 if (OperatingSystem.current().isLinux()) {
552 options.forkOptions.javaHome = file(jdkDir + 'Linux')
553 } else if (OperatingSystem.current().isMacOsX()) {
554 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
555 } else {
556 options.forkOptions.javaHome = file(jdkDir + 'Windows')
557 }
558 sourceCompatibility = JavaVersion.VERSION_11
559 targetCompatibility = JavaVersion.VERSION_11
clementbera0fe940d2019-04-23 12:45:18 +0200560 }
clementbera0fe940d2019-04-23 12:45:18 +0200561}
562
clementbera0bdd90f2019-07-06 11:15:23 +0200563setJava11Compilation(sourceSets.examplesJava11.compileJavaTaskName)
clementberaefa10522019-07-11 11:20:46 +0200564setJava11Compilation(sourceSets.examplesTestNGRunner.compileJavaTaskName)
clementbera4f9c2a92019-07-09 08:50:37 +0200565setJava11Compilation(sourceSets.jdk11TimeTests.compileJavaTaskName)
clementbera0bdd90f2019-07-06 11:15:23 +0200566
clementbera0bca05e2019-05-29 14:11:18 +0200567task compileMainWithJava11 (type: JavaCompile) {
568 def jdkDir = 'third_party/openjdk/jdk-11/'
569 options.fork = true
570 options.forkOptions.jvmArgs = []
571 if (OperatingSystem.current().isLinux()) {
572 options.forkOptions.javaHome = file(jdkDir + 'Linux')
573 } else if (OperatingSystem.current().isMacOsX()) {
Jake Whartona5204f32019-06-26 08:29:21 -0400574 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
clementbera0bca05e2019-05-29 14:11:18 +0200575 } else {
576 options.forkOptions.javaHome = file(jdkDir + 'Windows')
577 }
578 source = sourceSets.main.allSource
579 destinationDir = file(java11ClassFiles)
580 sourceCompatibility = JavaVersion.VERSION_11
581 targetCompatibility = JavaVersion.VERSION_11
582 classpath = sourceSets.main.compileClasspath
583}
clementbera0fe940d2019-04-23 12:45:18 +0200584
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100585if (!project.hasProperty('without_error_prone') &&
586 // Don't enable error prone on Java 8 as the plugin setup does not support it.
587 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200588 compileJava {
589 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100590 options.errorprone.enabled = true
591 options.errorprone.disableAllChecks = true
592 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
593 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
594 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
595 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
596 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
597 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
598 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
599 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
600 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
601 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
602 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
603 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
604 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
605 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
606 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
607 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
608 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
609 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
610 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200611 }
612}
613
Mads Ager418d1ca2017-05-22 09:35:49 +0200614compileJctfCommonJava {
615 dependsOn 'copyAdditionalJctfCommonFiles'
616 options.compilerArgs = ['-Xlint:none']
617}
618
619compileJctfTestsJava {
620 dependsOn 'jctfCommonClasses'
621 options.compilerArgs = ['-Xlint:none']
622}
623
Yohann Roussel7f47c032017-09-14 12:19:06 +0200624task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200625 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100626
Yohann Roussel7f47c032017-09-14 12:19:06 +0200627 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100628 def runtimeClasspath = configurations.findByName("runtimeClasspath")
629 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
630
Yohann Roussel7f47c032017-09-14 12:19:06 +0200631 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100632
Yohann Roussel7f47c032017-09-14 12:19:06 +0200633 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100634 def dependencies = []
635 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
636 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
637 dependencies.add("${identifier.group}:${identifier.module}")
638 }
639 def libraryLicenses = file('LIBRARY-LICENSE').text
640 dependencies.each {
641 if (!libraryLicenses.contains("- artifact: $it")) {
642 throw new GradleException("No license for $it in LIBRARY_LICENSE")
643 }
644 }
645
Yohann Roussel7f47c032017-09-14 12:19:06 +0200646 license.getParentFile().mkdirs()
647 license.createNewFile()
648 license.text = "This file lists all licenses for code distributed.\n"
649 license.text += "All non-library code has the following 3-Clause BSD license.\n"
650 license.text += "\n"
651 license.text += "\n"
652 license.text += file('LICENSE').text
653 license.text += "\n"
654 license.text += "\n"
655 license.text += "Summary of distributed libraries:\n"
656 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100657 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200658 license.text += "\n"
659 license.text += "\n"
660 license.text += "Licenses details:\n"
661 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
662 license.text += "\n"
663 license.text += "\n"
664 license.text += file.text
665 }
666 }
667}
668
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200669static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700670 // Everything under META-INF is not included by default.
671 // Should include before 'relocate' so that the service file path and its content
672 // are properly relocated as well.
673 task.mergeServiceFiles {
674 include 'META-INF/services/*'
675 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200676}
677
678static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000679 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200680 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000681 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
682 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000683 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000684 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200685 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
686 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
687 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200688 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000689}
690
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100691task repackageDepsNoRelocate(type: ShadowJar) {
692 configurations = [project.configurations.runtimeClasspath]
693 mergeServiceFiles(it)
694 exclude { it.getRelativePath().getPathString() == "module-info.class" }
695 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100696 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100697}
698
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000699task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100700 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200701 mergeServiceFiles(it)
702 if (!project.hasProperty('lib_no_relocate')) {
703 configureRelocations(it)
704 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100705 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700706 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000707 baseName 'deps'
708}
709
710task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200711 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200712 mergeServiceFiles(it)
713 if (!project.hasProperty('lib_no_relocate')) {
714 configureRelocations(it)
715 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000716 baseName 'sources'
717}
718
clementbera0bca05e2019-05-29 14:11:18 +0200719task repackageSources11(type: ShadowJar) {
720 dependsOn compileMainWithJava11
721 from file(java11ClassFiles)
722 mergeServiceFiles(it)
723 if (!project.hasProperty('lib_no_relocate')) {
724 configureRelocations(it)
725 }
clementbera55e84822019-06-06 16:08:11 +0200726 baseName 'sources11'
clementbera0bca05e2019-05-29 14:11:18 +0200727}
728
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100729task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200730 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100731 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200732 classifier = null
733 version = null
734 manifest {
735 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
736 }
737 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100738 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100739 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100740 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200741 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200742}
743
clementbera0bca05e2019-05-29 14:11:18 +0200744task r8WithRelocatedDeps11(type: ShadowJar) {
745 from consolidatedLicense.outputs.files
746 baseName 'r8_with_relocated_deps_11'
747 classifier = null
748 version = null
749 manifest {
750 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
751 }
752 from repackageSources11.outputs.files
753 from repackageDeps.outputs.files
754 configureRelocations(it)
755 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200756 exclude "**/*.kotlin_metadata"
clementbera0bca05e2019-05-29 14:11:18 +0200757}
758
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100759task r8WithoutDeps(type: ShadowJar) {
760 from consolidatedLicense.outputs.files
761 baseName 'r8_without_deps'
762 classifier = null
763 version = null
764 manifest {
765 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
766 }
767 from sourceSets.main.output
768}
769
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000770task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200771 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200772 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200773 classifier = null
774 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200775 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200776 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200777 }
778 // In order to build without dependencies, pass the exclude_deps property using:
779 // gradle -Pexclude_deps R8
780 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800781 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000782 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800783 } else {
784 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200785 }
Ian Zerny80533c92019-01-24 10:32:09 +0100786 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200787 exclude "**/*.kotlin_metadata"
Mads Ager418d1ca2017-05-22 09:35:49 +0200788}
789
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100790task R8NoManifestNoDeps(type: ShadowJar) {
791 from consolidatedLicense.outputs.files
792 baseName 'r8nomanifest-exclude-deps'
793 classifier = null
794 version = null
795 from sourceSets.main.output
796}
797
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100798task R8NoManifest(type: ShadowJar) {
799 from consolidatedLicense.outputs.files
800 baseName 'r8nomanifest'
801 classifier = null
802 version = null
803 // In order to build without dependencies, pass the exclude_deps property using:
804 // gradle -Pexclude_deps R8
805 if (!project.hasProperty('exclude_deps')) {
806 from repackageSources.outputs.files
807 from repackageDeps.outputs.files
808 } else {
809 from sourceSets.main.output
810 }
Ian Zerny80533c92019-01-24 10:32:09 +0100811 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200812 exclude "**/*.kotlin_metadata"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100813}
814
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000815task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200816 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200817 baseName 'd8'
818 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200819 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200820 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200821}
822
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200823task CompatDx(type: ShadowJar) {
824 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200825 baseName 'compatdx'
826 manifest {
827 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
828 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200829}
830
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200831task CompatProguard(type: ShadowJar) {
832 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200833 baseName 'compatproguard'
834 manifest {
835 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
836 }
Lars Bak44cef522017-08-10 16:02:39 +0200837}
838
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100839def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100840 // Execute r8 commands against a stable r8 with relocated dependencies.
Morten Krogh-Jespersen4849e792019-08-20 13:27:13 +0200841 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx6g).
Rico Windcfb65512019-02-27 12:57:34 +0100842 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
Morten Krogh-Jespersen4849e792019-08-20 13:27:13 +0200843 "-Xmx6g", "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100844}
845
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200846def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
847 def allArgs = [
848 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100849 input,
850 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100851 "--pg-map-output", output + ".map",
852 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200853 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
854 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100855}
856
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200857def r8LibCreateTask(name, pgConfs = [], r8Task, output, args = ["--release"], libs = []) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100858 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200859 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs, libs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100860 outputs.file output
861 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100862 dependsOn r8WithRelocatedDeps
863 dependsOn r8Task
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200864 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConfs, args, libs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100865 workingDir = projectDir
866 }
867}
868
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100869task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100870 baseName = "r8tests"
871 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200872 // We only want to include tests that use R8 when generating keep rules for applymapping.
873 include "com/android/tools/r8/**"
874 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100875}
876
877def generateR8LibKeepRules(name, r8Source, testSource, output) {
878 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
879 doFirst {
880 standardOutput new FileOutputStream(output)
881 }
882 dependsOn r8WithRelocatedDeps
883 dependsOn r8Source
884 dependsOn testSource
885 dependsOn downloadOpenJDKrt
886 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
887 outputs.file output
888 commandLine baseR8CommandLine([
889 "printuses",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200890 "--keeprules-allowobfuscation",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100891 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
892 r8Source.outputs.files[0],
893 testSource.outputs.files[0]])
894 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100895 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100896}
897
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100898task R8LibApiOnly {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200899 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], R8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100900 outputs.file r8LibPath
901}
902
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100903task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100904 def genRulesTask = generateR8LibKeepRules(
905 "Main",
906 R8NoManifest,
907 testJar,
908 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100909 dependsOn r8LibCreateTask(
910 "Main",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200911 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100912 R8NoManifest,
913 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100914 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100915 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100916}
917
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100918task R8LibNoDeps {
919 def genRulesTask = generateR8LibKeepRules(
920 "NoDeps",
921 R8NoManifestNoDeps,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200922 testJar,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100923 r8LibGeneratedKeepRulesExcludeDepsPath
924 )
925 dependsOn r8LibCreateTask(
926 "NoDeps",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200927 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100928 R8NoManifestNoDeps,
929 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200930 "--release",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100931 repackageDepsNoRelocate.outputs.files
932 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
933 outputs.file r8LibExludeDepsPath
934}
935
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100936task CompatDxLib {
937 dependsOn r8LibCreateTask(
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200938 "CompatDx", ["src/main/keep-compatdx.txt"], CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100939}
940
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100941task CompatProguardLib {
942 dependsOn r8LibCreateTask(
943 "CompatPg",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200944 ["src/main/keep-compatproguard.txt"],
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100945 CompatProguard,
946 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100947}
948
Mads Ager418d1ca2017-05-22 09:35:49 +0200949task sourceJar(type: Jar, dependsOn: classes) {
950 classifier = 'src'
951 from sourceSets.main.allSource
952}
953
954task jctfCommonJar(type: Jar) {
955 from sourceSets.jctfCommon.output
956 baseName 'jctfCommon'
957}
958
959artifacts {
960 archives sourceJar
961}
962
963task createArtTests(type: Exec) {
964 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200965 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100966 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200967 outputs.dir outputDir
968 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200969 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200970 workingDir = projectDir
971}
972
973task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200974 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200975 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200976 inputs.file script
977 outputs.dir outputDir
978 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200979 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200980 workingDir = projectDir
981}
982
983compileTestJava {
984 dependsOn createArtTests
985 dependsOn createJctfTests
986}
987
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100988task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
989 from sourceSets.cfSegments.output
990 baseName 'cf_segments'
991 destinationDir file('build/libs')
992}
993
Ian Zernyee23a172018-01-03 09:08:48 +0100994task buildD8ApiUsageSample(type: Jar) {
995 from sourceSets.apiUsageSample.output
996 baseName 'd8_api_usage_sample'
997 destinationDir file('tests')
998}
999
Ian Zerny923a0c12018-01-03 10:59:18 +01001000task buildR8ApiUsageSample(type: Jar) {
1001 from sourceSets.apiUsageSample.output
1002 baseName 'r8_api_usage_sample'
1003 destinationDir file('tests')
1004}
1005
Yohann Roussel548ae942018-01-05 11:13:28 +01001006task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001007 dependsOn buildD8ApiUsageSample
1008 dependsOn buildR8ApiUsageSample
1009}
1010
Mads Ager418d1ca2017-05-22 09:35:49 +02001011task buildDebugInfoExamplesDex {
1012 def examplesDir = file("src/test/java")
1013 def hostJar = "debuginfo_examples.jar"
1014 def hostDexJar = "debuginfo_examples_dex.jar"
1015 task "compile_debuginfo_examples"(type: JavaCompile) {
1016 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1017 destinationDir = file("build/test/debuginfo_examples/classes")
1018 classpath = sourceSets.main.compileClasspath
1019 sourceCompatibility = JavaVersion.VERSION_1_7
1020 targetCompatibility = JavaVersion.VERSION_1_7
1021 options.compilerArgs += ["-Xlint:-options"]
1022 }
1023 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1024 archiveName = hostJar
1025 destinationDir = file("build/test/")
1026 from "build/test/debuginfo_examples/classes"
1027 include "**/*.class"
1028 }
1029 task "dex_debuginfo_examples"(type: Exec,
1030 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001031 if (OperatingSystem.current().isWindows()) {
1032 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001033 } else if (OperatingSystem.current().isMacOsX()) {
1034 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001035 } else {
1036 executable file("tools/linux/dx/bin/dx");
1037 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001038 args "--dex"
1039 args "--output=build/test/${hostDexJar}"
1040 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001041 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001042 outputs.file file("build/test/${hostDexJar}")
1043 }
1044 dependsOn dex_debuginfo_examples
1045}
1046
1047task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001048 def resourcesDir = file("src/test/debugTestResources")
1049 def hostJar = "debug_test_resources.jar"
1050 task "compile_debugTestResources"(type: JavaCompile) {
1051 source = fileTree(dir: resourcesDir, include: '**/*.java')
1052 destinationDir = file("build/test/debugTestResources/classes")
1053 classpath = sourceSets.main.compileClasspath
1054 sourceCompatibility = JavaVersion.VERSION_1_7
1055 targetCompatibility = JavaVersion.VERSION_1_7
1056 options.compilerArgs += ["-g", "-Xlint:-options"]
1057 }
1058 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1059 archiveName = hostJar
1060 destinationDir = file("build/test/")
1061 from "build/test/debugTestResources/classes"
1062 include "**/*.class"
1063 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001064 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1065 def java8HostJar = "debug_test_resources_java8.jar"
1066 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1067 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1068 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1069 classpath = sourceSets.main.compileClasspath
1070 sourceCompatibility = JavaVersion.VERSION_1_8
1071 targetCompatibility = JavaVersion.VERSION_1_8
1072 options.compilerArgs += ["-g", "-Xlint:-options"]
1073 }
1074 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1075 archiveName = java8HostJar
1076 destinationDir = file("build/test/")
1077 from "build/test/debugTestResourcesJava8/classes"
1078 include "**/*.class"
1079 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001080 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001081 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1082 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1083 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1084 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001085 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001086 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001087 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001088 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001089 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001090}
1091
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001092// Examples used by tests, where Android specific APIs are used.
1093task buildExampleAndroidApi(type: JavaCompile) {
1094 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1095 destinationDir = file("build/test/examplesAndroidApi/classes")
1096 classpath = files("third_party/android_jar/lib-v26/android.jar")
1097 sourceCompatibility = JavaVersion.VERSION_1_8
1098 targetCompatibility = JavaVersion.VERSION_1_8
1099}
1100
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001101task buildExampleKotlinJars {
1102 def kotlinSrcDir = file("src/test/examplesKotlin")
1103 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001104 def name = dir.getName();
1105 dependsOn "compile_example_kotlin_${name}"
1106 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1107 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1108 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001109 }
1110 }
1111}
1112
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001113task buildProtoGeneratedSources {
1114 def examplesProtoDir = file("src/test/examplesProto")
1115 examplesProtoDir.eachDir { dir ->
1116 def name = dir.getName()
1117 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1118 source = {
1119 file('third_party/proto').listFiles()
1120 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1121 .collect { zipTree(it) }
1122 }
1123 destinationDir = file("build/generated/test/proto/${name}_classes")
1124 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1125 sourceCompatibility = JavaVersion.VERSION_1_8
1126 targetCompatibility = JavaVersion.VERSION_1_8
1127 }
1128 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1129 archiveName = "${name}.jar"
1130 destinationDir = file("build/generated/test/proto")
1131 from "build/generated/test/proto/${name}_classes"
1132 include "/**/*.class"
1133 }
1134 dependsOn "jar_proto_generated_source_${name}"
1135 }
1136}
1137
1138task buildExamplesProto {
1139 def examplesProtoDir = file("src/test/examplesProto")
1140 def examplesProtoOutputDir = file("build/test/examplesProto");
1141 dependsOn buildProtoGeneratedSources
1142 task "compile_examples_proto"(type: JavaCompile) {
1143 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1144 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001145 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1146 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001147 sourceCompatibility = JavaVersion.VERSION_1_8
1148 targetCompatibility = JavaVersion.VERSION_1_8
1149 }
1150 examplesProtoDir.eachDir { dir ->
1151 def name = dir.getName()
1152 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1153 archiveName = "${name}.jar"
1154 destinationDir = examplesProtoOutputDir
1155 from "build/test/examplesProto/classes"
1156 include name + "/**/*.class"
1157 }
1158 dependsOn "jar_examples_proto_${name}"
1159 }
1160}
1161
Lars Bakc91e87e2017-08-18 08:53:10 +02001162// Proto lite generated code yields warnings when compiling with javac.
1163// We change the options passed to javac to ignore it.
1164compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1165
Søren Gjesse7320ce52018-05-07 15:45:22 +02001166
Mads Ager418d1ca2017-05-22 09:35:49 +02001167task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001168 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001169 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001170 def proguardScript
1171 if (OperatingSystem.current().isWindows()) {
1172 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1173 } else {
1174 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1175 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001176 task extractExamplesRuntime(type: Sync) {
1177 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001178 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001179 include "**/*.class"
1180 includeEmptyDirs false
1181 into "$buildDir/runtime/examples/"
1182 }
1183
Søren Gjesse7320ce52018-05-07 15:45:22 +02001184 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1185 from examplesDir
1186 exclude "**/*.java"
1187 exclude "**/keep-rules*.txt"
1188 into file("build/test/examples/classes")
1189 }
1190
1191 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001192 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001193 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001194 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001195 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001196 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001197 sourceCompatibility = JavaVersion.VERSION_1_7
1198 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001199 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1200 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001201 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1202 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001203 include "**/*.java"
1204 destinationDir = file("build/test/examples/classes_debuginfo_all")
1205 classpath = sourceSets.examples.compileClasspath
1206 sourceCompatibility = JavaVersion.VERSION_1_7
1207 targetCompatibility = JavaVersion.VERSION_1_7
1208 options.compilerArgs = ["-g", "-Xlint:none"]
1209 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001210 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1211 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001212 include "**/*.java"
1213 destinationDir = file("build/test/examples/classes_debuginfo_none")
1214 classpath = sourceSets.examples.compileClasspath
1215 sourceCompatibility = JavaVersion.VERSION_1_7
1216 targetCompatibility = JavaVersion.VERSION_1_7
1217 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001218 }
1219 examplesDir.eachDir { dir ->
1220 def name = dir.getName();
1221 def exampleOutputDir = file("build/test/examples");
1222 def jarName = "${name}.jar"
1223 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001224 dependsOn "jar_example_${name}_debuginfo_all"
1225 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001226 dependsOn "extractExamplesRuntime"
1227 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001228 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1229 def proguardConfigPath = "${dir}/proguard.cfg"
1230 if (new File(proguardConfigPath).exists()) {
1231 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1232 archiveName = "${name}_pre_proguard.jar"
1233 destinationDir = exampleOutputDir
1234 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001235 include name + "/**/*.class"
1236 with runtimeDependencies
1237 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001238 }
1239 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1240 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1241 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1242 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001243 inputs.files files(
1244 tasks.getByPath("pre_proguard_example_${name}"),
1245 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001246 // Enable these to get stdout and stderr redirected to files...
1247 // standardOutput = new FileOutputStream('proguard.stdout')
1248 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001249 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001250 " -outjars ${proguardJarPath}" +
1251 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001252 " -printmapping ${proguardMapPath}"
1253 if (OperatingSystem.current().isWindows()) {
1254 executable "${proguardScript}"
1255 args "${proguardArguments}"
1256 } else {
1257 executable "bash"
1258 args "-c", "${proguardScript} '${proguardArguments}'"
1259 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001260 outputs.file proguardJarPath
1261 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001262 // TODO: Consider performing distinct proguard compilations.
1263 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1264 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001265 into "${exampleOutputDir}"
1266 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001267 }
1268 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1269 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001270 into "${exampleOutputDir}"
1271 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001272 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001273 } else {
1274 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001275 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001276 destinationDir = exampleOutputDir
1277 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001278 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001279 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001280 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001281 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001282 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1283 archiveName = "${name}_debuginfo_all.jar"
1284 destinationDir = exampleOutputDir
1285 from "build/test/examples/classes_debuginfo_all"
1286 include name + "/**/*.class"
1287 with runtimeDependencies
1288 includeEmptyDirs false
1289 }
1290 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1291 archiveName = "${name}_debuginfo_none.jar"
1292 destinationDir = exampleOutputDir
1293 from "build/test/examples/classes_debuginfo_none"
1294 include name + "/**/*.class"
1295 with runtimeDependencies
1296 includeEmptyDirs false
1297 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001298 }
1299 }
1300}
1301
1302task buildExampleAndroidNJars {
1303 dependsOn downloadDeps
1304 def examplesDir = file("src/test/examplesAndroidN")
1305 task "compile_examplesAndroidN"(type: JavaCompile) {
1306 source = fileTree(dir: examplesDir, include: '**/*.java')
1307 destinationDir = file("build/test/examplesAndroidN/classes")
1308 classpath = sourceSets.main.compileClasspath
1309 sourceCompatibility = JavaVersion.VERSION_1_8
1310 targetCompatibility = JavaVersion.VERSION_1_8
1311 options.compilerArgs += ["-Xlint:-options"]
1312 }
1313 examplesDir.eachDir { dir ->
1314 def name = dir.getName();
1315 def exampleOutputDir = file("build/test/examplesAndroidN");
1316 def jarName = "${name}.jar"
1317 dependsOn "jar_examplesAndroidN_${name}"
1318 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1319 archiveName = jarName
1320 destinationDir = exampleOutputDir
1321 from "build/test/examplesAndroidN/classes"
1322 include "**/" + name + "/**/*.class"
1323 }
1324 }
1325}
1326
1327
1328task buildExampleAndroidOJars {
1329 dependsOn downloadDeps
1330 def examplesDir = file("src/test/examplesAndroidO")
1331 // NOTE: we want to enable a scenario when test needs to reference some
1332 // classes generated by legacy (1.6) Java compiler to test some specific
1333 // behaviour. To do so we compile all the java files located in sub-directory
1334 // called 'legacy' with Java 1.6, then compile the rest of the files with
1335 // Java 1.8 and a reference to previously generated 1.6 classes.
1336
1337 // Compiling all classes in dirs 'legacy' with old Java version.
1338 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1339 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1340 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1341 classpath = sourceSets.main.compileClasspath
1342 sourceCompatibility = JavaVersion.VERSION_1_6
1343 targetCompatibility = JavaVersion.VERSION_1_6
1344 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1345 }
1346 // Compiling the rest of the files as Java 1.8 code.
1347 task "compile_examplesAndroidO"(type: JavaCompile) {
1348 dependsOn "compile_examplesAndroidO_Legacy"
1349 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1350 destinationDir = file("build/test/examplesAndroidO/classes")
1351 classpath = sourceSets.main.compileClasspath
1352 classpath += files("build/test/examplesAndroidOLegacy/classes")
1353 sourceCompatibility = JavaVersion.VERSION_1_8
1354 targetCompatibility = JavaVersion.VERSION_1_8
1355 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1356 }
1357 examplesDir.eachDir { dir ->
1358 def name = dir.getName();
1359 def destinationDir = file("build/test/examplesAndroidO/classes");
1360 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1361 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1362 dependsOn: "compile_examplesAndroidO") {
1363 main = name + ".TestGenerator"
1364 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1365 args destinationDir
1366 }
1367 } else {
1368 task "generate_examplesAndroidO_${name}" () {}
1369 }
1370 }
1371 examplesDir.eachDir { dir ->
1372 def name = dir.getName();
1373 def exampleOutputDir = file("build/test/examplesAndroidO");
1374 def jarName = "${name}.jar"
1375 dependsOn "jar_examplesAndroidO_${name}"
1376 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1377 "generate_examplesAndroidO_${name}"]) {
1378 archiveName = jarName
1379 destinationDir = exampleOutputDir
1380 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1381 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1382 include "**/" + name + "/**/*.class"
1383 // Do not include generator into the test runtime jar, it is not useful.
1384 // Otherwise, shrinking will need ASM jars.
1385 exclude "**/TestGenerator*"
1386 }
1387 }
1388}
1389
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001390task buildExampleAndroidPJars {
1391 dependsOn downloadDeps
1392 def examplesDir = file("src/test/examplesAndroidP")
1393
1394 task "compile_examplesAndroidP"(type: JavaCompile) {
1395 source = fileTree(dir: examplesDir, include: '**/*.java')
1396 destinationDir = file("build/test/examplesAndroidP/classes")
1397 classpath = sourceSets.main.compileClasspath
1398 sourceCompatibility = JavaVersion.VERSION_1_8
1399 targetCompatibility = JavaVersion.VERSION_1_8
1400 options.compilerArgs += ["-Xlint:-options"]
1401 }
1402 examplesDir.eachDir { dir ->
1403 def name = dir.getName();
1404 def destinationDir = file("build/test/examplesAndroidP/classes");
1405 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1406 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1407 dependsOn: "compile_examplesAndroidP") {
1408 main = name + ".TestGenerator"
1409 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1410 args destinationDir
1411 }
1412 } else {
1413 task "generate_examplesAndroidP_${name}" () {}
1414 }
1415 }
1416 examplesDir.eachDir { dir ->
1417 def name = dir.getName();
1418 def exampleOutputDir = file("build/test/examplesAndroidP");
1419 def jarName = "${name}.jar"
1420 dependsOn "jar_examplesAndroidP_${name}"
1421 task "jar_examplesAndroidP_${name}"(type: Jar,
1422 dependsOn: ["compile_examplesAndroidP",
1423 "generate_examplesAndroidP_${name}"]) {
1424 archiveName = jarName
1425 destinationDir = exampleOutputDir
1426 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1427 include "**/" + name + "/**/*.class"
1428 // Do not include generator into the test runtime jar, it is not useful.
1429 // Otherwise, shrinking will need ASM jars.
1430 exclude "**/TestGenerator*"
1431 }
1432 }
1433}
1434
Mikaël Peltier61633d42017-10-13 16:51:06 +02001435task buildExampleJava9Jars {
1436 def examplesDir = file("src/test/examplesJava9")
1437 examplesDir.eachDir { dir ->
1438 def name = dir.getName();
1439 def exampleOutputDir = file("build/test/examplesJava9");
1440 def jarName = "${name}.jar"
1441 dependsOn "jar_examplesJava9_${name}"
1442 task "jar_examplesJava9_${name}"(type: Jar) {
1443 archiveName = jarName
1444 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001445 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001446 include "**/" + name + "/**/*.class"
1447 }
1448 }
1449}
1450
clementberad7ab1dd2019-04-16 16:05:00 +02001451task buildExampleJava11Jars {
1452 def examplesDir = file("src/test/examplesJava11")
1453 examplesDir.eachDir { dir ->
1454 def name = dir.getName();
1455 def exampleOutputDir = file("build/test/examplesJava11");
1456 def jarName = "${name}.jar"
1457 dependsOn "jar_examplesJava11_${name}"
1458 task "jar_examplesJava11_${name}"(type: Jar) {
1459 archiveName = jarName
1460 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001461 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001462 include "**/" + name + "/**/*.class"
1463 }
1464 }
1465}
1466
clementberaa92e3cd2019-07-12 14:13:22 +02001467task provideArtFrameworksDependencies {
1468 cloudDependencies.tools.forEach({ art ->
1469 if (art.contains("art")) {
1470 def taskName = art.replace('/','_')
1471 dependsOn "patch_${taskName}"
1472 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1473 from "tools/${art}/framework"
1474 include "**.jar"
1475 into file("tools/${art}/out/host/linux-x86/framework")
1476 }
1477 }
1478 })
1479}
1480
clementbera4f9c2a92019-07-09 08:50:37 +02001481task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1482 from sourceSets.jdk11TimeTests.compileClasspath
1483 include "**/**.jar"
1484 into file("build/test/jdk11Tests")
1485}
1486
1487task buildJdk11TimeTestsJar {
1488 def exampleOutputDir = file("build/test/jdk11Tests");
1489 def jarName = "jdk11TimeTests.jar"
1490 dependsOn "jar_jdk11TimeTests"
1491 dependsOn provideJdk11TestsDependencies
1492 task "jar_jdk11TimeTests"(type: Jar) {
1493 archiveName = jarName
1494 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001495 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001496 include "**.class"
1497 from sourceSets.jdk11TimeTests.output
1498 include "**.class"
1499 include "**/**.class"
1500 }
1501}
1502
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001503task buildExamplesKotlin {
1504 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1505 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1506 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1507 } else if (!OperatingSystem.current().isLinux()) {
1508 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1509 "on your platform. It is fully supported on Linux and partially supported on " +
1510 "Mac OS and Windows")
1511 return;
1512 }
1513 def examplesDir = file("src/test/examplesKotlin")
1514 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001515 def name = dir.getName();
1516 dependsOn "dex_example_kotlin_${name}"
1517 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1518 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001519 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001520 dependsOn: "compile_example_kotlin_${name}") {
1521 doFirst {
1522 if (!dexPath.exists()) {
1523 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001524 }
1525 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001526 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1527 destination = dexPath
1528 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001529 }
1530 }
1531}
1532
Sebastien Hertzd3313772018-01-16 14:12:37 +01001533task buildKotlinR8TestResources {
1534 def examplesDir = file("src/test/kotlinR8TestResources")
1535 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001536 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1537 def name = dir.getName()
1538 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001539 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1540 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001541 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001542 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001543 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1544 source = fileTree(dir: file("${examplesDir}/${name}"),
1545 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001546 destination = file(outputFile)
1547 targetVersion = kotlinTargetVersion
1548 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001549 task "${taskName}Java"(type: JavaCompile) {
1550 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1551 destinationDir = file(javaOutput)
1552 classpath = sourceSets.main.compileClasspath
1553 sourceCompatibility = JavaVersion.VERSION_1_6
1554 targetCompatibility = JavaVersion.VERSION_1_6
1555 options.compilerArgs += ["-g", "-Xlint:-options"]
1556 }
1557 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1558 archiveName = javaOutputJarName
1559 destinationDir = file(javaOutputJarDir)
1560 from javaOutput
1561 include "**/*.class"
1562 }
1563 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001564 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001565 }
1566}
1567
Mads Ager418d1ca2017-05-22 09:35:49 +02001568task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001569 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1570 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1571 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001572 } else if (!OperatingSystem.current().isLinux()) {
1573 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001574 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001575 return;
1576 }
1577 dependsOn buildDebugTestResourcesJars
1578 dependsOn buildExampleJars
1579 dependsOn buildExampleAndroidNJars
1580 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001581 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001582 dependsOn buildExampleJava9Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001583 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001584 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001585 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001586 def noDexTests = [
1587 "multidex",
1588 "multidex002",
1589 "multidex004",
1590 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001591 examplesDir.eachDir { dir ->
1592 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001593 if (!(name in noDexTests)) {
1594 dependsOn "dex_example_${name}"
1595 def exampleOutputDir = file("build/test/examples/" + name);
1596 def dexPath = file("${exampleOutputDir}")
1597 def debug = (name == "throwing")
1598 if (!dexPath.exists()) {
1599 dexPath.mkdirs()
1600 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001601 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001602 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1603 destination = dexPath
1604 debug = debug
1605 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001606 }
1607 }
1608}
1609
1610task buildSmali {
1611 def smaliDir = file("src/test/smali")
1612 smaliDir.eachDirRecurse() { dir ->
1613 def name = dir.getName();
1614 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1615 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1616 smaliOutputDir.mkdirs()
1617 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001618 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001619 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1620 def javaFiles = fileTree(dir: dir, include: '*.java')
1621 def destDir = smaliOutputDir;
1622 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1623 def intermediateFileName = "${name}-intermediate.dex";
1624 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1625 if (javaFiles.empty) {
1626 if (!smaliFiles.empty) {
1627 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001628 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001629 source = smaliFiles
1630 destination = destFile
1631 }
1632 }
1633 } else {
1634 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001635 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001636 source = smaliFiles
1637 destination = intermediateFile
1638 }
1639 task "${taskName}_java"(type: JavaCompile) {
1640 source = javaFiles
1641 destinationDir destDir
1642 classpath = sourceSets.main.compileClasspath
1643 sourceCompatibility = JavaVersion.VERSION_1_7
1644 targetCompatibility = JavaVersion.VERSION_1_7
1645 options.compilerArgs += ["-Xlint:-options"]
1646 }
1647 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1648 archiveName = "Test.jar"
1649 destinationDir = destDir
1650 from fileTree(dir: destDir, include: 'Test.class')
1651 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001652 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001653 source = fileTree(dir: destDir, include: 'Test.jar')
1654 destination = destDir
1655 }
1656 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001657 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001658 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1659 destination = destFile
1660 }
1661 }
1662 }
1663}
1664
1665tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001666 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001667 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001668 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001669 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001670 if (userDefinedCoresPerFork) {
1671 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1672 } else {
1673 // On normal work machines this seems to give the best test execution time (without freezing)
1674 maxParallelForks = processors.intdiv(3) ?: 1
1675 }
Rico Windc56f21c2019-03-12 07:29:57 +01001676 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001677
Mads Ager418d1ca2017-05-22 09:35:49 +02001678 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001679 if (project.hasProperty('disable_assertions')) {
1680 enableAssertions = false
1681 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001682 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001683 if (project.hasProperty('test_xmx')) {
1684 maxHeapSize = project.property('test_xmx')
1685 } else {
1686 maxHeapSize = "4G"
1687 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001688}
1689
1690task buildPreNJdwpTestsJar(type: Jar) {
1691 baseName = 'jdwp-tests-preN'
1692 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1693 // Exclude the classes containing java8
1694 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1695 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1696 includeEmptyDirs = false
1697}
1698
Ian Zerny74143162017-11-24 13:46:35 +01001699task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1700 def inFile = buildPreNJdwpTestsJar.archivePath
1701 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001702 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001703 outputs.file outFile
1704 if (OperatingSystem.current().isWindows()) {
1705 executable file("tools/windows/dx/bin/dx.bat")
1706 } else if (OperatingSystem.current().isMacOsX()) {
1707 executable file("tools/mac/dx/bin/dx");
1708 } else {
1709 executable file("tools/linux/dx/bin/dx");
1710 }
1711 args "--dex"
1712 args "--output=${outFile}"
1713 args inFile
1714}
1715
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001716task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1717 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001718}
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001719def getR8LibSourceTask() {
1720 if (project.hasProperty('r8lib')) {
1721 return R8NoManifest
1722 } else if (project.hasProperty('r8lib_no_deps')) {
1723 return R8NoManifestNoDeps
1724 }
1725 return null
1726}
Yohann Roussel126f6872017-08-03 16:25:32 +02001727
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001728def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001729 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001730 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001731 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001732 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001733 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001734 return null
1735}
1736
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001737task generateR8TestKeepRules {
1738 def path = "build/generated/r8tests-keep.txt"
1739 outputs.file path
1740 if (getR8LibTask() != null) {
1741 dependsOn getR8LibTask()
1742 doLast {
1743 file(path).write """-keep class ** { *; }
1744-dontshrink
1745-dontoptimize
1746-keepattributes *
1747-applymapping ${getR8LibTask().outputs.files[0]}.map
1748"""
1749 }
1750 }
1751}
1752
1753task buildR8LibCfTestDeps(type: Exec) {
1754 if (getR8LibTask() == null) {
1755 return
1756 }
1757 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1758 dependsOn downloadDeps
1759 dependsOn getR8LibTask()
1760 dependsOn getR8LibSourceTask()
1761 dependsOn generateR8TestKeepRules
1762 dependsOn testJar
1763 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1764 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1765 return pkg.toString().endsWith(".jar")
1766 } + ["${buildDir}/classes/java/test"]
1767 inputs.files testJar.outputs.files +
1768 generateR8TestKeepRules.outputs.files +
1769 getR8LibTask().outputs
1770 commandLine = r8CfCommandLine(
1771 testJar.outputs.files[0],
1772 outputPath,
1773 [generateR8TestKeepRules.outputs.files[0]],
1774 ["--debug", "--classpath", getR8LibSourceTask().outputs.files[0]],
1775 getR8LibSourceTask().outputs.files + addedLibraries)
1776 workingDir = projectDir
1777 outputs.file outputPath
1778}
1779
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001780task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001781 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001782 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001783 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001784 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001785 delete r8LibTestPath
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001786 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1787 def examplesDir = file("build/test")
1788 examplesDir.eachDir { dir ->
1789 from ("${buildDir}/test/${dir.getName()}/classes")
1790 }
1791 from ("${buildDir}/runtime/examples")
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001792 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001793 }
1794 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001795}
1796
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001797def printStackTrace(TestResult result) {
1798 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1799 def out = new StringBuffer()
1800 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001801 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001802 def header = "RETRACED STACKTRACE";
1803 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1804 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1805 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1806 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001807 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001808 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001809 out.append("--------------------------------------\n")
1810 Process process = command.execute()
1811 def processIn = new PrintStream(process.getOut())
1812 process.consumeProcessOutput(out, err)
1813 result.exception.printStackTrace(processIn)
1814 processIn.flush()
1815 processIn.close()
1816 process.waitFor()
1817 out.append("\n\n--------------------------------------\n")
1818 out.append("OBFUSCATED STACKTRACE\n")
1819 out.append("--------------------------------------\n")
1820 result.exceptions.add(0, new Exception(out.toString()))
1821 } else {
1822 result.exception.printStackTrace()
1823 }
1824}
1825
Mads Ager418d1ca2017-05-22 09:35:49 +02001826test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001827 if (project.hasProperty('generate_golden_files_to')) {
1828 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1829 assert project.hasProperty('HEAD_sha1')
1830 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1831 }
1832
1833 if (project.hasProperty('use_golden_files_in')) {
1834 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1835 assert project.hasProperty('HEAD_sha1')
1836 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1837 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001838
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001839 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001840 // R8.jar is required for running bootstrap tests.
1841 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001842 testLogging.exceptionFormat = 'full'
1843 if (project.hasProperty('print_test_stdout')) {
1844 testLogging.showStandardStreams = true
1845 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001846 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001847 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001848 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001849 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001850
Ian Zerny324d7612019-03-20 10:52:28 +01001851 // Forward runtime configurations for test parameters.
1852 if (project.hasProperty('runtimes')) {
1853 println "NOTE: Running with runtimes: " + project.property('runtimes')
1854 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001855 }
1856
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001857 if (project.hasProperty('slow_tests')) {
1858 systemProperty 'slow_tests', project.property('slow_tests')
1859 }
1860
Mads Ager418d1ca2017-05-22 09:35:49 +02001861 if (project.hasProperty('one_line_per_test')) {
1862 beforeTest { desc ->
1863 println "Start executing test ${desc.name} [${desc.className}]"
1864 }
1865 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001866 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001867 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001868 }
Rico Windda6836e2018-12-07 12:32:03 +01001869 if (project.hasProperty('update_test_timestamp')) {
1870 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1871 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001872 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1873 }
Rico Windf88b6be2018-12-11 15:14:05 +01001874 } else {
1875 afterTest { desc, result ->
1876 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001877 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001878 }
1879 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001880 }
1881 if (project.hasProperty('no_internal')) {
1882 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001883 } else {
1884 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001885 }
1886 if (project.hasProperty('only_internal')) {
1887 include "com/android/tools/r8/internal/**"
1888 }
Rico Wind4e218292019-03-07 12:44:49 +01001889
Mads Ager418d1ca2017-05-22 09:35:49 +02001890 if (project.hasProperty('tool')) {
1891 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001892 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001893 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001894 if (project.hasProperty('only_jctf')) {
1895 include "com/android/tools/r8/jctf/d8/**"
1896 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001897 // Don't run anything, deprecated
1898 println "Running with deprecated tool d8, not running any tests"
1899 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001900 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001901 } else {
1902 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001903 assert(project.hasProperty('only_jctf'))
1904 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001905 }
1906 }
1907 if (!project.hasProperty('all_tests')) {
1908 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001909 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001910 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001911 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001912 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001913 if (project.hasProperty('shard_count') ) {
1914 assert project.hasProperty('shard_number')
1915 int shard_count = project.getProperty('shard_count') as Integer
1916 int shard_number = project.getProperty('shard_number') as Integer
1917 assert shard_count < 65536
1918 assert shard_number < shard_count
1919 exclude {
1920 entry ->
1921 // Don't leave out directories. Leaving out a directory means all entries below.
1922 if (entry.file.isDirectory()) {
1923 return false
1924 }
1925 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1926 int hash = Integer.parseInt(first4, 16)
1927 return hash % shard_count != shard_number
1928 }
1929 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001930 if (project.hasProperty('jctf_compile_only')) {
1931 println "JCTF: compiling only"
1932 systemProperty 'jctf_compile_only', '1'
1933 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001934 if (project.hasProperty('test_dir')) {
1935 systemProperty 'test_dir', project.property('test_dir')
1936 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001937 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1938 dependsOn configureTestForR8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001939 // R8lib should be used instead of the main output and all the tests in r8 should be mapped
1940 // and exists in r8LibtestPath.
1941 classpath = sourceSets.test.runtimeClasspath.filter {
1942 !it.getAbsolutePath().contains("/build/")
1943 }
1944 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001945 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001946 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001947 if (OperatingSystem.current().isLinux()
1948 || OperatingSystem.current().isMacOsX()
1949 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001950 if (OperatingSystem.current().isMacOsX()) {
1951 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1952 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1953 "See tools/docker/README.md for details.")
1954 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001955 if (OperatingSystem.current().isWindows()) {
1956 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1957 "Art only runs on Linux and tests requiring Art will be skipped")
1958 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001959 dependsOn downloadDeps
1960 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001961 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001962 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001963 dependsOn buildSmali
1964 dependsOn jctfCommonJar
1965 dependsOn jctfTestsClasses
1966 dependsOn buildDebugInfoExamplesDex
1967 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001968 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02001969 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02001970 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02001971 } else {
1972 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001973 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001974 }
1975}
1976
1977// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1978//
1979// To build and upload a new set of the Art tests for use with R8 follow these steps:
1980//
1981// First of all an Android checkout is required. Currently it must be located
1982// in $HOME/android/master.
1983//
1984// TODO(ricow): simplify this
1985//
1986// Before: update the checked in art, see scripts/update-host-art.sh
1987//
1988// 1. Get an android checkout in $HOME/android/master and apply the patch from
1989// https://android-review.googlesource.com/#/c/294187/
1990//
1991// 2. run the following commands in the Android checkout directory:
1992//
1993// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001994// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1995// m desugar
1996// m -j30 test-art-host
1997// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1998//
1999// Without running the test.py command the classes.jar file used by desugar in
2000// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2001// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002002//
2003// 3. In the R8 project root directory, make sure we have a clean state before starting:
2004// tools/gradle.py downloadDeps
2005// tools/gradle.py clean
2006// rm -rf tests/art
2007//
2008// 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 +02002009// Make sure you have smali on your path, please use the build binary in the
2010// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2011// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2012// 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 +02002013// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2014// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002015//
Søren Gjesse34b77732017-07-07 13:56:21 +02002016// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002017//
2018// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2019// skippedTests with an explanation. Rerun from step 3.
2020//
2021// 5. Run the tests:
2022// tools/gradle.py clean
2023// tools/test.py
2024//
Søren Gjesse34b77732017-07-07 13:56:21 +02002025// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2026// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2027// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002028//
Søren Gjesse34b77732017-07-07 13:56:21 +02002029// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002030// cd tests
2031// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002032//
2033// 7. Update the manifest file describing the Android repo used:
2034// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002035
Mads Ager418d1ca2017-05-22 09:35:49 +02002036def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002037
2038def artTestDir = file("${androidCheckoutDir}/art/test")
2039
2040if (project.hasProperty('android_source')) {
2041 task buildArtTests {
2042 outputs.upToDateWhen { false }
2043 def toBeTriaged = [
2044 "903-hello-tagging",
2045 "904-object-allocation",
2046 "905-object-free",
2047 "906-iterate-heap",
2048 "907-get-loaded-classes",
2049 "908-gc-start-finish",
2050 "954-invoke-polymorphic-verifier",
2051 "955-methodhandles-smali",
2052 "596-monitor-inflation",
2053 ]
2054 def skippedTests = toBeTriaged + [
2055 // This test produces no jar.
2056 "000-nop",
2057 // This does not build, as it tests the error when the application exceeds more
2058 // than 65536 methods
2059 "089-many-methods",
2060 // Requires some jack beta jar
2061 "956-methodhandles",
2062 ]
2063
2064 def skippedTestsDx = [
2065 // Tests with custom build scripts, where javac is not passed the options
2066 // -source 1.7 -target 1.7.
2067 "462-checker-inlining-across-dex-files",
2068 "556-invoke-super",
2069 "569-checker-pattern-replacement",
2070 // These tests use jack even when --build-with-javac-dx is specified.
2071 "004-JniTest",
2072 "048-reflect-v8",
2073 "146-bad-interface",
2074 "563-checker-invoke-super",
2075 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2076 "604-hot-static-interface",
2077 "957-methodhandle-transforms",
2078 "958-methodhandle-emulated-stackframe",
2079 "959-invoke-polymorphic-accessors",
2080 "961-default-iface-resolution-gen",
2081 "962-iface-static",
2082 "963-default-range-smali",
2083 "964-default-iface-init-gen",
2084 "965-default-verify",
2085 "966-default-conflict",
2086 "967-default-ame",
2087 "968-default-partial-compile-gen",
2088 "969-iface-super",
2089 "970-iface-super-resolution-gen",
2090 "971-iface-super",
2091 // These tests does not build with --build-with-javac-dx
2092 "004-NativeAllocations", // Javac error
2093 "031-class-attributes",
2094 "138-duplicate-classes-check",
2095 "157-void-class", // Javac error
2096 "580-checker-string-factory-intrinsics",
2097 "612-jit-dex-cache",
2098 "613-inlining-dex-cache",
2099 "900-hello-plugin", // --experimental agents
2100 "901-hello-ti-agent", // --experimental agents
2101 "902-hello-transformation", // --experimental agents
2102 "909-attach-agent", // --experimental agents
2103 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2104 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2105 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2106 "960-default-smali", // --experimental default-methods
2107 // These tests force the build to use jack
2108 "953-invoke-polymorphic-compiler",
2109 "958-methodhandle-stackframe",
2110 ]
2111
2112 def artTestBuildDir = file("${projectDir}/tests/art")
2113
2114 if (androidCheckoutDir.exists()) {
2115 dependsOn downloadDeps
2116 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002117 artTestDir.eachDir { dir ->
2118 def name = dir.getName();
2119 def markerFile = dir.toPath().resolve("info.txt").toFile();
2120 if (markerFile.exists() && !(name in skippedTests)) {
2121 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002122 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002123 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002124 }
2125 }
2126 }
2127 doFirst {
2128 if (!androidCheckoutDir.exists()) {
2129 throw new InvalidUserDataException(
2130 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002131 }
2132 }
2133 doLast {
2134 copy {
2135 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2136 into file("${artTestBuildDir}/lib64")
2137 include 'lib*.so'
2138 }
2139 copy {
2140 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2141 into file("${artTestBuildDir}/lib64")
2142 include 'libart.so'
2143 include 'libbacktrace.so'
2144 include 'libbase.so'
2145 include 'libc++.so'
2146 include 'libcutils.so'
2147 include 'liblz4.so'
2148 include 'liblzma.so'
2149 include 'libnativebridge.so'
2150 include 'libnativeloader.so'
2151 include 'libsigchain.so'
2152 include 'libunwind.so'
2153 include 'libziparchive.so'
2154 }
2155 copy {
2156 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2157 into file("${artTestBuildDir}/lib")
2158 include 'lib*.so'
2159 }
2160 copy {
2161 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2162 into file("${artTestBuildDir}/lib")
2163 include 'libart.so'
2164 include 'libbacktrace.so'
2165 include 'libbase.so'
2166 include 'libc++.so'
2167 include 'libcutils.so'
2168 include 'liblz4.so'
2169 include 'liblzma.so'
2170 include 'libnativebridge.so'
2171 include 'libnativeloader.so'
2172 include 'libsigchain.so'
2173 include 'libunwind.so'
2174 include 'libziparchive.so'
2175 }
2176 }
2177 }
2178}
2179
Rico Windde2af6c2019-03-26 15:21:08 +01002180def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002181 def artTestDir = file("${androidCheckoutDir}/art/test")
2182 def artRunTestScript = file("${artTestDir}/run-test")
2183 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002184 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002185
Søren Gjesse34b77732017-07-07 13:56:21 +02002186 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002187 def buildTask = "build_art_test_dx_${name}"
2188 def sanitizeTask = "sanitize_art_test_dx_${name}"
2189 def copyCheckTask = "copy_check_art_test_dx_${name}"
2190 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002191
2192 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002193 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002194 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2195 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002196 task "$buildTask"(type: Exec) {
2197 outputs.upToDateWhen { false }
2198 inputs.file buildInputs
2199 executable "${artRunTestScript}"
2200 args "--host"
2201 args "--build-only"
2202 args "--build-with-javac-dx"
2203 args "--output-path", "${testDir}"
2204 args "${name}"
2205 environment DX: "${dxExecutable.absolutePath}"
2206 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2207 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2208 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002209 }
2210 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2211 outputs.upToDateWhen { false }
2212 executable "/bin/bash"
2213 args "-c"
2214 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2215 " ${testDir}/classes-ex ${testDir}/check"
2216 }
2217
2218 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002219 // Directory that contains smali files is either smali, or smali/art
2220 def smali_dir = file("${dir}/smali/art")
2221 if (smali_dir.exists()) {
2222 workingDir "${testDir}/smali/art"
2223 } else {
2224 workingDir "${testDir}/smali"
2225 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002226 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002227 // This is the command line options for smali prior to 2.2.1, where smali got a new
2228 // command line interface.
2229 args "-c", "smali a *.smali"
2230 // This is the command line options for smali 2.2.1 and later.
2231 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002232 }
2233
2234 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2235 def smali_dir = file("${dir}/smali")
2236 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002237 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002238 dependsOn smaliToDexTask
2239 }
2240 from("${artTestDir}/${name}") {
2241 include 'check'
2242 }
2243 into testDir
2244 }
2245
2246 return copyCheckTask
2247}
2248
2249task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002250 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002251 classpath = sourceSets.main.compileClasspath
2252 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002253 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002254 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002255 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002256 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002257 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002258 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002259 include '**/com/android/tools/r8/CompilationMode.java'
2260 include '**/com/android/tools/r8/D8.java'
2261 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002262 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2263 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002264 include '**/com/android/tools/r8/Diagnostic.java'
2265 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002266 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2267 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002268 include '**/com/android/tools/r8/ProgramConsumer.java'
2269 include '**/com/android/tools/r8/ProgramResource.java'
2270 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002271 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002272 include '**/com/android/tools/r8/ResourceException.java'
2273 include '**/com/android/tools/r8/StringConsumer.java'
2274 include '**/com/android/tools/r8/StringResource.java'
2275 include '**/com/android/tools/r8/Version.java'
2276 include '**/com/android/tools/r8/origin/*.java'
2277}
2278
2279task javadocR8(type: Javadoc) {
2280 title "R8 API"
2281 classpath = sourceSets.main.compileClasspath
2282 source = sourceSets.main.allJava
2283 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2284 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2285 include '**/com/android/tools/r8/BaseCommand.java'
2286 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2287 include '**/com/android/tools/r8/ClassFileConsumer.java'
2288 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2289 include '**/com/android/tools/r8/CompilationFailedException.java'
2290 include '**/com/android/tools/r8/CompilationMode.java'
2291 include '**/com/android/tools/r8/R8.java'
2292 include '**/com/android/tools/r8/R8Command.java'
2293 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2294 include '**/com/android/tools/r8/Diagnostic.java'
2295 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002296 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2297 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002298 include '**/com/android/tools/r8/ProgramConsumer.java'
2299 include '**/com/android/tools/r8/ProgramResource.java'
2300 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2301 include '**/com/android/tools/r8/Resource.java'
2302 include '**/com/android/tools/r8/ResourceException.java'
2303 include '**/com/android/tools/r8/StringConsumer.java'
2304 include '**/com/android/tools/r8/StringResource.java'
2305 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002306 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002307}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002308
2309task copyMavenDeps(type: Copy) {
2310 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002311 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002312 from configurations.testCompile into "$buildDir/deps"
2313}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002314
Rico Wind23a05112019-03-27 08:00:44 +01002315task printMavenDeps {
2316 // Only actually print to stdout when we are updating.
2317 if (project.hasProperty('updatemavendeps')) {
2318 for (Configuration config : configurations) {
2319 if (!config.isCanBeResolved()) {
2320 continue
2321 }
2322 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2323 it.selected.id
2324 }
2325 def result = dependencies.createArtifactResolutionQuery()
2326 .forComponents(componentIds)
2327 .withArtifacts(MavenModule, MavenPomArtifact)
2328 .execute()
2329 for (component in result.resolvedComponents) {
2330 component.getArtifacts(MavenPomArtifact).each {
2331 println "POM: ${it.file} ${component.id}"
2332 }
2333 }
2334 config.each {
2335 println "JAR: ${it}"
2336 }
2337 }
2338 }
2339}