blob: 171ede1cde93f1e89b498c2b3dd0513a10a525bb [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 {
Rico Wind70d614f2020-01-31 08:45:21 +010018 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010019 }
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 {
Rico Wind70d614f2020-01-31 08:45:21 +010057 url 'https://storage.googleapis.com/r8-deps/maven_mirror/'
Rico Wind23a05112019-03-27 08:00:44 +010058 }
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 }
Søren Gjesse17fc67d2019-12-04 14:50:17 +010093 libraryDesugarConversions {
94 java {
95 srcDirs = ['src/library_desugar/java']
96 }
97 output.resourcesDir = 'build/classes/library_desugar_conversions'
98 }
Mads Ager418d1ca2017-05-22 09:35:49 +020099 debugTestResources {
100 java {
101 srcDirs = ['src/test/debugTestResources']
102 }
103 output.resourcesDir = 'build/classes/debugTestResources'
104 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +0200105 debugTestResourcesJava8 {
106 java {
107 srcDirs = ['src/test/debugTestResourcesJava8']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
110 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200111 debugTestResourcesKotlin {
112 java {
113 srcDirs = ['src/test/debugTestResourcesKotlin']
114 }
115 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
116 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200117 examples {
118 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800119 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200120 }
121 output.resourcesDir = 'build/classes/examples'
122 }
Ian Zernyd3020482019-04-25 07:05:04 +0200123 examplesJava9 {
124 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200125 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200126 }
127 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500128 examplesJava10 {
129 java {
130 srcDirs = ['src/test/examplesJava10']
131 }
132 }
Ian Zernyd3020482019-04-25 07:05:04 +0200133 examplesJava11 {
134 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200135 srcDirs = ['src/test/examplesJava11']
136 }
137 }
clementbera4f9c2a92019-07-09 08:50:37 +0200138 jdk11TimeTests {
139 java {
140 srcDirs = [
141 'third_party/openjdk/jdk-11-test/java/time/tck',
142 'third_party/openjdk/jdk-11-test/java/time/test'
143 ]
144 exclude '**/TestZoneTextPrinterParser.java'
145 }
146 }
clementberaefa10522019-07-11 11:20:46 +0200147 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200148 java {
149 srcDirs = ['src/test/testngrunner']
150 }
151 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100152 examplesKotlin {
153 java {
154 srcDirs = ['src/test/examplesKotlin']
155 }
156 output.resourcesDir = 'build/classes/examplesKotlin'
157 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200158 examplesAndroidN {
159 java {
160 srcDirs = ['src/test/examplesAndroidN']
161 }
162 output.resourcesDir = 'build/classes/examplesAndroidN'
163 }
164 examplesAndroidO {
165 java {
166 srcDirs = ['src/test/examplesAndroidO']
167 }
168 output.resourcesDir = 'build/classes/examplesAndroidO'
169 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200170 examplesAndroidP {
171 java {
172 srcDirs = ['src/test/examplesAndroidP']
173 }
174 output.resourcesDir = 'build/classes/examplesAndroidP'
175 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200176 examplesProto {
177 java {
178 srcDirs = ['src/test/examplesProto']
179 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200180 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
181 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200182 output.resourcesDir = 'build/classes/examplesProto'
183 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200184 jctfCommon {
185 java {
186 srcDirs = [
187 'third_party/jctf/Harness/src',
188 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
189 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
190 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
191 'third_party/jctf/LibTests/src/org',
192 'build/additionalJctfCommonFiles'
193 ]
194 }
195 resources {
196 srcDirs = ['third_party/jctf/LibTests/resources']
197 }
198 }
199 jctfTests {
200 java {
201 srcDirs = [
202 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
203 // 'third_party/jctf/VMTests/src',
204 ]
205 }
206 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100207 kotlinR8TestResources {
208 java {
209 srcDirs = ['src/test/kotlinR8TestResources']
210 }
211 output.resourcesDir = 'build/classes/kotlinR8TestResources'
212 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200213}
214
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800215// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
216// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
217// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
218// for context.
219idea {
220 sourceSets.all { SourceSet sources ->
221 module {
222 if (sources.name == "main") {
223 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100224 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800225 } else {
226 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100227 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800228 }
229 }
230 }
231}
232
Yohann Roussel126f6872017-08-03 16:25:32 +0200233configurations {
234 supportLibs
235}
236
Mads Ager418d1ca2017-05-22 09:35:49 +0200237dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100238 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
239 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200240 // Include all of guava when compiling the code, but exclude annotations that we don't
241 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100242 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100243 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200244 exclude group: 'com.google.errorprone'
245 exclude group: 'com.google.code.findbugs'
246 exclude group: 'com.google.j2objc'
247 exclude group: 'org.codehaus.mojo'
248 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100249 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
250 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
251 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
252 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
253 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
254 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
255 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
clementbera4f9c2a92019-07-09 08:50:37 +0200256 jdk11TimeTestsCompile group: 'org.testng', name: 'testng', version: testngVersion
clementberaefa10522019-07-11 11:20:46 +0200257 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200258 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100259 testCompile "junit:junit:$junitVersion"
260 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200261 testCompile files('third_party/jasmin/jasmin-2.4.jar')
262 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200263 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100264 jctfCommonCompile "junit:junit:$junitVersion"
265 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200266 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100267 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
268 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200269 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100270 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800271 examplesCompile "junit:junit:$junitVersion"
272 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100273 supportLibs "com.android.support:support-v4:$androidSupportVersion"
274 supportLibs "junit:junit:$junitVersion"
275 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100276 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100277 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100278 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
279 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
280 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100281 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200282}
283
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100284def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100285def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100286def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100287def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100288def r8LibTestPath = "$buildDir/classes/r8libtest"
clementbera0bca05e2019-05-29 14:11:18 +0200289def java11ClassFiles = "build/classes/java/mainJava11"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100290
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200291def osString = OperatingSystem.current().isLinux() ? "linux" :
292 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200293
294def cloudDependencies = [
295 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200296 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100297 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200298 ],
299 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200300 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200301 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100302 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200303 "android_jar/lib-v19",
304 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100305 "android_jar/lib-v22",
306 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200307 "android_jar/lib-v24",
308 "android_jar/lib-v25",
309 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100310 "android_jar/lib-v27",
311 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200312 "android_jar/lib-v29",
Rico Windf72fa152018-10-22 15:41:03 +0200313 "core-lambda-stubs",
314 "dart-sdk",
315 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200316 "gradle/gradle",
Ian Zerny33c1c582019-09-17 12:43:45 +0200317 "google-java-format",
Morten Krogh-Jespersencd6712c2019-10-09 13:09:47 +0200318 "iosched_2019",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200319 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200320 "jasmin",
321 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100322 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200323 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200324 "jsr223-api-1.0",
Søren Gjesse8f0e0992019-09-06 09:28:14 +0200325 "rhino-1.7.10",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200326 "rhino-android-1.1.1",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200327 "kotlin",
Ian Zerny23942992019-07-10 14:33:52 +0200328 "kotlin-compiler-1.3.41",
Mathias Rav5285faf2018-03-20 14:16:32 +0100329 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200330 "openjdk/desugar_jdk_libs",
clementbera8dbfeda2019-07-03 11:24:13 +0200331 "openjdk/jdk-11-test",
Rico Windf72fa152018-10-22 15:41:03 +0200332 "proguard/proguard5.2.1",
333 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200334 "r8",
Morten Krogh-Jespersenbc0ffda2019-09-04 16:17:54 +0200335 "r8mappings"
Mads Ager418d1ca2017-05-22 09:35:49 +0200336 ],
337 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
338 // container on other platforms where supported.
339 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200340 "linux/art",
341 "linux/art-5.1.1",
342 "linux/art-6.0.1",
343 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100344 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100345 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100346 "linux/art-10.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200347 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100348 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200349 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200350 ]
351]
352
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100353def cloudSystemDependencies = [
354 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200355 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200356 "openjdk/jdk8/linux-x86",
357 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100358 ],
359 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200360 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200361 "openjdk/jdk8/darwin-x86",
362 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100363 ],
364 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200365 "third_party": ["openjdk/openjdk-9.0.4/windows",
366 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100367 ],
368]
369
370if (OperatingSystem.current().isWindows()) {
371 cloudSystemDependencies.windows.each { entry ->
372 cloudDependencies.get(entry.key).addAll(entry.value)
373 }
374} else if (OperatingSystem.current().isLinux()) {
375 cloudSystemDependencies.linux.each { entry ->
376 cloudDependencies.get(entry.key).addAll(entry.value)
377 }
378} else if (OperatingSystem.current().isMacOsX()) {
379 cloudSystemDependencies.osx.each { entry ->
380 cloudDependencies.get(entry.key).addAll(entry.value)
381 }
382} else {
383 println "WARNING: Unsupported system: " + OperatingSystem.current()
384}
385
386def getDownloadDepsTaskName(entryKey, entryFile) {
387 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
388}
389
Mads Ager418d1ca2017-05-22 09:35:49 +0200390cloudDependencies.each { entry ->
391 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100392 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
393 type DownloadDependency.Type.GOOGLE_STORAGE
394 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200395 }
396 }
397}
398
399def x20Dependencies = [
400 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200401 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700402 "chrome/chrome_180917_ffbaa8",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100403 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100404 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200405 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100406 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200407 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200408 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200409 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200410 "gmscore/gmscore_v10",
411 "gmscore/gmscore_v9",
412 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200413 "gmscore/v4",
414 "gmscore/v5",
415 "gmscore/v6",
416 "gmscore/v7",
417 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200418 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200419 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200420 "proguard/proguard_internal_159423826",
421 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200422 "proto",
423 "protobuf-lite",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200424 "youtube/youtube.android_12.10",
425 "youtube/youtube.android_12.17",
426 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200427 "youtube/youtube.android_13.37",
Søren Gjesse889e09d2019-11-07 16:33:51 +0100428 "youtube/youtube.android_14.19",
429 "youtube/youtube.android_14.44"
Mads Ager418d1ca2017-05-22 09:35:49 +0200430 ],
431]
432
433x20Dependencies.each { entry ->
434 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100435 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
436 type DownloadDependency.Type.X20
437 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200438 }
439 }
440}
441
Rico Wind897bb712017-05-23 10:44:29 +0200442task downloadProguard {
443 cloudDependencies.each { entry ->
444 entry.value.each { entryFile ->
445 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100446 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200447 }
448 }
449 }
450}
451
Rico Windf6c74ce2018-12-04 08:50:55 +0100452task downloadOpenJDKrt {
453 cloudDependencies.each { entry ->
454 entry.value.each { entryFile ->
455 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100456 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100457 }
458 }
459 }
460}
461
Tamas Kenez427205b2017-06-29 15:57:09 +0200462task downloadDx {
463 cloudDependencies.each { entry ->
464 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200465 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100466 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200467 }
468 }
469 }
470}
471
Tamas Kenez0e10c562017-06-08 10:00:34 +0200472task downloadAndroidCts {
473 cloudDependencies.each { entry ->
474 entry.value.each { entryFile ->
475 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100476 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200477 }
478 }
479 }
480}
481
Mads Ager418d1ca2017-05-22 09:35:49 +0200482task downloadDeps {
483 cloudDependencies.each { entry ->
484 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100485 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200486 }
487 }
488 if (!project.hasProperty('no_internal')) {
489 x20Dependencies.each { entry ->
490 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100491 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200492 }
493 }
494 }
495}
496
497allprojects {
498 sourceCompatibility = JavaVersion.VERSION_1_8
499 targetCompatibility = JavaVersion.VERSION_1_8
500}
501
Rico Wind266336c2019-02-25 10:11:38 +0100502// TODO(ricow): Remove debug prints
503println("NOTE: Current operating system: " + OperatingSystem.current())
504println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
505
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100506// Check if running with the JDK location from tools/jdk.py.
507if (OperatingSystem.current().isWindows()) {
508 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100509 compileJava.options.encoding = "UTF-8"
510 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100511} else {
512 def javaHomeOut = new StringBuilder()
513 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400514 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100515 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
516 def jdkHome = new File(javaHomeOut.toString().trim())
517 if (!jdkHome.exists()) {
518 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
519 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
520 println("WARNING: Gradle is running in a non-pinned Java"
521 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
522 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100523 } else {
524 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100525 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200526}
527
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100528sourceSets.configureEach { sourceSet ->
529 tasks.named(sourceSet.compileJavaTaskName).configure {
530 // Default disable errorprone (enabled and setup below).
531 options.errorprone.enabled = false
532 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100533 // Run all compilation tasks in a forked subprocess.
534 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100535 // Javac often runs out of stack space when compiling the tests.
536 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200537 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100538 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200539 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100540 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
541 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
542 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200543}
544
Ian Zernyd3020482019-04-25 07:05:04 +0200545tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
546 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200547 options.fork = true
548 options.forkOptions.jvmArgs = []
549 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200550 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200551 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200552 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200553 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200554 options.forkOptions.javaHome = file(jdkDir + 'windows')
555 }
556 sourceCompatibility = JavaVersion.VERSION_1_9
557 targetCompatibility = JavaVersion.VERSION_1_9
558}
559
Jake Wharton2000b2f2019-12-11 20:37:49 -0500560def setJdk11CompilationWithCompatibility(String sourceSet, JavaVersion compatibility) {
clementbera0bdd90f2019-07-06 11:15:23 +0200561 tasks.named(sourceSet).get().configure {
562 def jdkDir = 'third_party/openjdk/jdk-11/'
563 options.fork = true
564 options.forkOptions.jvmArgs = []
565 if (OperatingSystem.current().isLinux()) {
566 options.forkOptions.javaHome = file(jdkDir + 'Linux')
567 } else if (OperatingSystem.current().isMacOsX()) {
568 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
569 } else {
570 options.forkOptions.javaHome = file(jdkDir + 'Windows')
571 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500572 sourceCompatibility = compatibility
573 targetCompatibility = compatibility
clementbera0fe940d2019-04-23 12:45:18 +0200574 }
clementbera0fe940d2019-04-23 12:45:18 +0200575}
576
Jake Wharton2000b2f2019-12-11 20:37:49 -0500577setJdk11CompilationWithCompatibility(sourceSets.examplesJava10.compileJavaTaskName, JavaVersion.VERSION_1_10)
578setJdk11CompilationWithCompatibility(sourceSets.examplesJava11.compileJavaTaskName, JavaVersion.VERSION_11)
579setJdk11CompilationWithCompatibility(sourceSets.examplesTestNGRunner.compileJavaTaskName, JavaVersion.VERSION_11)
580setJdk11CompilationWithCompatibility(sourceSets.jdk11TimeTests.compileJavaTaskName, JavaVersion.VERSION_11)
clementbera0bdd90f2019-07-06 11:15:23 +0200581
clementbera0bca05e2019-05-29 14:11:18 +0200582task compileMainWithJava11 (type: JavaCompile) {
Ian Zernye0dd4c42019-12-02 10:12:15 +0100583 dependsOn downloadDeps
clementbera0bca05e2019-05-29 14:11:18 +0200584 def jdkDir = 'third_party/openjdk/jdk-11/'
585 options.fork = true
586 options.forkOptions.jvmArgs = []
587 if (OperatingSystem.current().isLinux()) {
588 options.forkOptions.javaHome = file(jdkDir + 'Linux')
589 } else if (OperatingSystem.current().isMacOsX()) {
Jake Whartona5204f32019-06-26 08:29:21 -0400590 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
clementbera0bca05e2019-05-29 14:11:18 +0200591 } else {
592 options.forkOptions.javaHome = file(jdkDir + 'Windows')
593 }
594 source = sourceSets.main.allSource
595 destinationDir = file(java11ClassFiles)
596 sourceCompatibility = JavaVersion.VERSION_11
597 targetCompatibility = JavaVersion.VERSION_11
598 classpath = sourceSets.main.compileClasspath
599}
clementbera0fe940d2019-04-23 12:45:18 +0200600
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100601if (!project.hasProperty('without_error_prone') &&
602 // Don't enable error prone on Java 8 as the plugin setup does not support it.
603 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200604 compileJava {
605 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100606 options.errorprone.enabled = true
607 options.errorprone.disableAllChecks = true
608 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
609 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
610 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
611 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
612 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
613 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
614 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
615 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
616 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
617 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
618 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
619 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
620 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
621 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
622 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
623 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
624 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
625 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
626 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200627 }
628}
629
Mads Ager418d1ca2017-05-22 09:35:49 +0200630compileJctfCommonJava {
631 dependsOn 'copyAdditionalJctfCommonFiles'
632 options.compilerArgs = ['-Xlint:none']
633}
634
635compileJctfTestsJava {
636 dependsOn 'jctfCommonClasses'
637 options.compilerArgs = ['-Xlint:none']
638}
639
Yohann Roussel7f47c032017-09-14 12:19:06 +0200640task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200641 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100642
Yohann Roussel7f47c032017-09-14 12:19:06 +0200643 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100644 def runtimeClasspath = configurations.findByName("runtimeClasspath")
645 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
646
Yohann Roussel7f47c032017-09-14 12:19:06 +0200647 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100648
Yohann Roussel7f47c032017-09-14 12:19:06 +0200649 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100650 def dependencies = []
651 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
652 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
653 dependencies.add("${identifier.group}:${identifier.module}")
654 }
655 def libraryLicenses = file('LIBRARY-LICENSE').text
656 dependencies.each {
657 if (!libraryLicenses.contains("- artifact: $it")) {
658 throw new GradleException("No license for $it in LIBRARY_LICENSE")
659 }
660 }
661
Yohann Roussel7f47c032017-09-14 12:19:06 +0200662 license.getParentFile().mkdirs()
663 license.createNewFile()
664 license.text = "This file lists all licenses for code distributed.\n"
665 license.text += "All non-library code has the following 3-Clause BSD license.\n"
666 license.text += "\n"
667 license.text += "\n"
668 license.text += file('LICENSE').text
669 license.text += "\n"
670 license.text += "\n"
671 license.text += "Summary of distributed libraries:\n"
672 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100673 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200674 license.text += "\n"
675 license.text += "\n"
676 license.text += "Licenses details:\n"
677 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
678 license.text += "\n"
679 license.text += "\n"
680 license.text += file.text
681 }
682 }
683}
684
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200685static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700686 // Everything under META-INF is not included by default.
687 // Should include before 'relocate' so that the service file path and its content
688 // are properly relocated as well.
689 task.mergeServiceFiles {
690 include 'META-INF/services/*'
691 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200692}
693
694static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000695 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200696 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000697 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
698 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000699 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000700 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200701 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
702 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
703 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200704 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000705}
706
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100707task repackageDepsNoRelocate(type: ShadowJar) {
708 configurations = [project.configurations.runtimeClasspath]
709 mergeServiceFiles(it)
710 exclude { it.getRelativePath().getPathString() == "module-info.class" }
711 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100712 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100713}
714
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000715task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100716 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200717 mergeServiceFiles(it)
718 if (!project.hasProperty('lib_no_relocate')) {
719 configureRelocations(it)
720 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100721 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700722 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000723 baseName 'deps'
724}
725
726task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200727 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200728 mergeServiceFiles(it)
729 if (!project.hasProperty('lib_no_relocate')) {
730 configureRelocations(it)
731 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000732 baseName 'sources'
733}
734
clementbera0bca05e2019-05-29 14:11:18 +0200735task repackageSources11(type: ShadowJar) {
736 dependsOn compileMainWithJava11
737 from file(java11ClassFiles)
738 mergeServiceFiles(it)
739 if (!project.hasProperty('lib_no_relocate')) {
740 configureRelocations(it)
741 }
clementbera55e84822019-06-06 16:08:11 +0200742 baseName 'sources11'
clementbera0bca05e2019-05-29 14:11:18 +0200743}
744
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100745task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200746 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100747 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200748 classifier = null
749 version = null
750 manifest {
751 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
752 }
753 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100754 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100755 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100756 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200757 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200758}
759
clementbera0bca05e2019-05-29 14:11:18 +0200760task r8WithRelocatedDeps11(type: ShadowJar) {
761 from consolidatedLicense.outputs.files
762 baseName 'r8_with_relocated_deps_11'
763 classifier = null
764 version = null
765 manifest {
766 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
767 }
768 from repackageSources11.outputs.files
769 from repackageDeps.outputs.files
770 configureRelocations(it)
771 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200772 exclude "**/*.kotlin_metadata"
clementbera0bca05e2019-05-29 14:11:18 +0200773}
774
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100775task r8WithoutDeps(type: ShadowJar) {
776 from consolidatedLicense.outputs.files
777 baseName 'r8_without_deps'
778 classifier = null
779 version = null
780 manifest {
781 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
782 }
783 from sourceSets.main.output
784}
785
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000786task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200787 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200788 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200789 classifier = null
790 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200791 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200792 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200793 }
794 // In order to build without dependencies, pass the exclude_deps property using:
795 // gradle -Pexclude_deps R8
796 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800797 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000798 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800799 } else {
800 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200801 }
Ian Zerny80533c92019-01-24 10:32:09 +0100802 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200803 exclude "**/*.kotlin_metadata"
Mads Ager418d1ca2017-05-22 09:35:49 +0200804}
805
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100806task R8NoManifestNoDeps(type: ShadowJar) {
807 from consolidatedLicense.outputs.files
808 baseName 'r8nomanifest-exclude-deps'
809 classifier = null
810 version = null
811 from sourceSets.main.output
812}
813
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100814task R8NoManifest(type: ShadowJar) {
815 from consolidatedLicense.outputs.files
816 baseName 'r8nomanifest'
817 classifier = null
818 version = null
819 // In order to build without dependencies, pass the exclude_deps property using:
820 // gradle -Pexclude_deps R8
821 if (!project.hasProperty('exclude_deps')) {
822 from repackageSources.outputs.files
823 from repackageDeps.outputs.files
824 } else {
825 from sourceSets.main.output
826 }
Ian Zerny80533c92019-01-24 10:32:09 +0100827 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200828 exclude "**/*.kotlin_metadata"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100829}
830
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000831task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200832 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200833 baseName 'd8'
834 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200835 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200836 }
Mads Ager418d1ca2017-05-22 09:35:49 +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-Jespersene36a23e2020-01-09 14:50:32 +0100843 "-Xmx8g", "-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
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100869task buildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
870 from sourceSets.libraryDesugarConversions.output
871 include "java/**/*.class"
872 baseName 'library_desugar_conversions'
873 destinationDir file('build/libs')
874}
875
876task testJar(type: ShadowJar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100877 baseName = "r8tests"
878 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200879 // We only want to include tests that use R8 when generating keep rules for applymapping.
880 include "com/android/tools/r8/**"
881 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100882}
883
884def generateR8LibKeepRules(name, r8Source, testSource, output) {
885 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
886 doFirst {
887 standardOutput new FileOutputStream(output)
888 }
889 dependsOn r8WithRelocatedDeps
890 dependsOn r8Source
891 dependsOn testSource
892 dependsOn downloadOpenJDKrt
893 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
894 outputs.file output
895 commandLine baseR8CommandLine([
896 "printuses",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200897 "--keeprules-allowobfuscation",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100898 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
899 r8Source.outputs.files[0],
900 testSource.outputs.files[0]])
901 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100902 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100903}
904
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100905task R8LibApiOnly {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200906 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], R8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100907 outputs.file r8LibPath
908}
909
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100910task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100911 def genRulesTask = generateR8LibKeepRules(
912 "Main",
913 R8NoManifest,
914 testJar,
915 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100916 dependsOn r8LibCreateTask(
917 "Main",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200918 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100919 R8NoManifest,
920 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100921 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100922 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100923}
924
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100925task R8LibNoDeps {
926 def genRulesTask = generateR8LibKeepRules(
927 "NoDeps",
928 R8NoManifestNoDeps,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200929 testJar,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100930 r8LibGeneratedKeepRulesExcludeDepsPath
931 )
932 dependsOn r8LibCreateTask(
933 "NoDeps",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200934 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100935 R8NoManifestNoDeps,
936 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200937 "--release",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100938 repackageDepsNoRelocate.outputs.files
939 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
940 outputs.file r8LibExludeDepsPath
941}
942
Mads Ager418d1ca2017-05-22 09:35:49 +0200943task sourceJar(type: Jar, dependsOn: classes) {
944 classifier = 'src'
945 from sourceSets.main.allSource
946}
947
948task jctfCommonJar(type: Jar) {
949 from sourceSets.jctfCommon.output
950 baseName 'jctfCommon'
951}
952
953artifacts {
954 archives sourceJar
955}
956
957task createArtTests(type: Exec) {
958 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200959 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100960 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200961 outputs.dir outputDir
962 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200963 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200964 workingDir = projectDir
965}
966
967task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200968 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200969 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200970 inputs.file script
971 outputs.dir outputDir
972 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200973 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200974 workingDir = projectDir
975}
976
977compileTestJava {
978 dependsOn createArtTests
979 dependsOn createJctfTests
980}
981
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100982task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
983 from sourceSets.cfSegments.output
984 baseName 'cf_segments'
985 destinationDir file('build/libs')
986}
987
Ian Zernyee23a172018-01-03 09:08:48 +0100988task buildD8ApiUsageSample(type: Jar) {
989 from sourceSets.apiUsageSample.output
990 baseName 'd8_api_usage_sample'
991 destinationDir file('tests')
992}
993
Ian Zerny923a0c12018-01-03 10:59:18 +0100994task buildR8ApiUsageSample(type: Jar) {
995 from sourceSets.apiUsageSample.output
996 baseName 'r8_api_usage_sample'
997 destinationDir file('tests')
998}
999
Yohann Roussel548ae942018-01-05 11:13:28 +01001000task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001001 dependsOn buildD8ApiUsageSample
1002 dependsOn buildR8ApiUsageSample
1003}
1004
Mads Ager418d1ca2017-05-22 09:35:49 +02001005task buildDebugInfoExamplesDex {
1006 def examplesDir = file("src/test/java")
1007 def hostJar = "debuginfo_examples.jar"
1008 def hostDexJar = "debuginfo_examples_dex.jar"
1009 task "compile_debuginfo_examples"(type: JavaCompile) {
1010 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1011 destinationDir = file("build/test/debuginfo_examples/classes")
1012 classpath = sourceSets.main.compileClasspath
1013 sourceCompatibility = JavaVersion.VERSION_1_7
1014 targetCompatibility = JavaVersion.VERSION_1_7
1015 options.compilerArgs += ["-Xlint:-options"]
1016 }
1017 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1018 archiveName = hostJar
1019 destinationDir = file("build/test/")
1020 from "build/test/debuginfo_examples/classes"
1021 include "**/*.class"
1022 }
1023 task "dex_debuginfo_examples"(type: Exec,
1024 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001025 if (OperatingSystem.current().isWindows()) {
1026 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001027 } else if (OperatingSystem.current().isMacOsX()) {
1028 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001029 } else {
1030 executable file("tools/linux/dx/bin/dx");
1031 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001032 args "--dex"
1033 args "--output=build/test/${hostDexJar}"
1034 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001035 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001036 outputs.file file("build/test/${hostDexJar}")
1037 }
1038 dependsOn dex_debuginfo_examples
1039}
1040
1041task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001042 def resourcesDir = file("src/test/debugTestResources")
1043 def hostJar = "debug_test_resources.jar"
1044 task "compile_debugTestResources"(type: JavaCompile) {
1045 source = fileTree(dir: resourcesDir, include: '**/*.java')
1046 destinationDir = file("build/test/debugTestResources/classes")
1047 classpath = sourceSets.main.compileClasspath
1048 sourceCompatibility = JavaVersion.VERSION_1_7
1049 targetCompatibility = JavaVersion.VERSION_1_7
1050 options.compilerArgs += ["-g", "-Xlint:-options"]
1051 }
1052 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1053 archiveName = hostJar
1054 destinationDir = file("build/test/")
1055 from "build/test/debugTestResources/classes"
1056 include "**/*.class"
1057 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001058 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1059 def java8HostJar = "debug_test_resources_java8.jar"
1060 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1061 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1062 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1063 classpath = sourceSets.main.compileClasspath
1064 sourceCompatibility = JavaVersion.VERSION_1_8
1065 targetCompatibility = JavaVersion.VERSION_1_8
1066 options.compilerArgs += ["-g", "-Xlint:-options"]
1067 }
1068 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1069 archiveName = java8HostJar
1070 destinationDir = file("build/test/")
1071 from "build/test/debugTestResourcesJava8/classes"
1072 include "**/*.class"
1073 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001074 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001075 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1076 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1077 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1078 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001079 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001080 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001081 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001082 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001083 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001084}
1085
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001086// Examples used by tests, where Android specific APIs are used.
1087task buildExampleAndroidApi(type: JavaCompile) {
1088 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1089 destinationDir = file("build/test/examplesAndroidApi/classes")
1090 classpath = files("third_party/android_jar/lib-v26/android.jar")
1091 sourceCompatibility = JavaVersion.VERSION_1_8
1092 targetCompatibility = JavaVersion.VERSION_1_8
1093}
1094
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001095task buildExampleKotlinJars {
1096 def kotlinSrcDir = file("src/test/examplesKotlin")
1097 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001098 def name = dir.getName();
1099 dependsOn "compile_example_kotlin_${name}"
1100 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1101 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1102 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001103 }
1104 }
1105}
1106
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001107task buildProtoGeneratedSources {
1108 def examplesProtoDir = file("src/test/examplesProto")
1109 examplesProtoDir.eachDir { dir ->
1110 def name = dir.getName()
1111 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1112 source = {
1113 file('third_party/proto').listFiles()
1114 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1115 .collect { zipTree(it) }
1116 }
1117 destinationDir = file("build/generated/test/proto/${name}_classes")
1118 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1119 sourceCompatibility = JavaVersion.VERSION_1_8
1120 targetCompatibility = JavaVersion.VERSION_1_8
1121 }
1122 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1123 archiveName = "${name}.jar"
1124 destinationDir = file("build/generated/test/proto")
1125 from "build/generated/test/proto/${name}_classes"
1126 include "/**/*.class"
1127 }
1128 dependsOn "jar_proto_generated_source_${name}"
1129 }
1130}
1131
1132task buildExamplesProto {
1133 def examplesProtoDir = file("src/test/examplesProto")
1134 def examplesProtoOutputDir = file("build/test/examplesProto");
1135 dependsOn buildProtoGeneratedSources
1136 task "compile_examples_proto"(type: JavaCompile) {
1137 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1138 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001139 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1140 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001141 sourceCompatibility = JavaVersion.VERSION_1_8
1142 targetCompatibility = JavaVersion.VERSION_1_8
1143 }
1144 examplesProtoDir.eachDir { dir ->
1145 def name = dir.getName()
1146 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1147 archiveName = "${name}.jar"
1148 destinationDir = examplesProtoOutputDir
1149 from "build/test/examplesProto/classes"
1150 include name + "/**/*.class"
1151 }
1152 dependsOn "jar_examples_proto_${name}"
1153 }
1154}
1155
Lars Bakc91e87e2017-08-18 08:53:10 +02001156// Proto lite generated code yields warnings when compiling with javac.
1157// We change the options passed to javac to ignore it.
1158compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1159
Søren Gjesse7320ce52018-05-07 15:45:22 +02001160
Mads Ager418d1ca2017-05-22 09:35:49 +02001161task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001162 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001163 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001164 def proguardScript
1165 if (OperatingSystem.current().isWindows()) {
1166 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1167 } else {
1168 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1169 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001170 task extractExamplesRuntime(type: Sync) {
1171 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001172 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001173 include "**/*.class"
1174 includeEmptyDirs false
1175 into "$buildDir/runtime/examples/"
1176 }
1177
Søren Gjesse7320ce52018-05-07 15:45:22 +02001178 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1179 from examplesDir
1180 exclude "**/*.java"
1181 exclude "**/keep-rules*.txt"
1182 into file("build/test/examples/classes")
1183 }
1184
1185 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001186 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001187 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001188 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001189 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001190 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001191 sourceCompatibility = JavaVersion.VERSION_1_7
1192 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001193 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1194 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001195 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1196 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001197 include "**/*.java"
1198 destinationDir = file("build/test/examples/classes_debuginfo_all")
1199 classpath = sourceSets.examples.compileClasspath
1200 sourceCompatibility = JavaVersion.VERSION_1_7
1201 targetCompatibility = JavaVersion.VERSION_1_7
1202 options.compilerArgs = ["-g", "-Xlint:none"]
1203 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001204 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1205 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001206 include "**/*.java"
1207 destinationDir = file("build/test/examples/classes_debuginfo_none")
1208 classpath = sourceSets.examples.compileClasspath
1209 sourceCompatibility = JavaVersion.VERSION_1_7
1210 targetCompatibility = JavaVersion.VERSION_1_7
1211 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001212 }
1213 examplesDir.eachDir { dir ->
1214 def name = dir.getName();
1215 def exampleOutputDir = file("build/test/examples");
1216 def jarName = "${name}.jar"
1217 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001218 dependsOn "jar_example_${name}_debuginfo_all"
1219 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001220 dependsOn "extractExamplesRuntime"
1221 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001222 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1223 def proguardConfigPath = "${dir}/proguard.cfg"
1224 if (new File(proguardConfigPath).exists()) {
1225 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1226 archiveName = "${name}_pre_proguard.jar"
1227 destinationDir = exampleOutputDir
1228 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001229 include name + "/**/*.class"
1230 with runtimeDependencies
1231 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001232 }
1233 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1234 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1235 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1236 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001237 inputs.files files(
1238 tasks.getByPath("pre_proguard_example_${name}"),
1239 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001240 // Enable these to get stdout and stderr redirected to files...
1241 // standardOutput = new FileOutputStream('proguard.stdout')
1242 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001243 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001244 " -outjars ${proguardJarPath}" +
1245 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001246 " -printmapping ${proguardMapPath}"
1247 if (OperatingSystem.current().isWindows()) {
1248 executable "${proguardScript}"
1249 args "${proguardArguments}"
1250 } else {
1251 executable "bash"
1252 args "-c", "${proguardScript} '${proguardArguments}'"
1253 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001254 outputs.file proguardJarPath
1255 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001256 // TODO: Consider performing distinct proguard compilations.
1257 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1258 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001259 into "${exampleOutputDir}"
1260 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001261 }
1262 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1263 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001264 into "${exampleOutputDir}"
1265 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001266 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001267 } else {
1268 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001269 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001270 destinationDir = exampleOutputDir
1271 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001272 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001273 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001274 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001275 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001276 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1277 archiveName = "${name}_debuginfo_all.jar"
1278 destinationDir = exampleOutputDir
1279 from "build/test/examples/classes_debuginfo_all"
1280 include name + "/**/*.class"
1281 with runtimeDependencies
1282 includeEmptyDirs false
1283 }
1284 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1285 archiveName = "${name}_debuginfo_none.jar"
1286 destinationDir = exampleOutputDir
1287 from "build/test/examples/classes_debuginfo_none"
1288 include name + "/**/*.class"
1289 with runtimeDependencies
1290 includeEmptyDirs false
1291 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001292 }
1293 }
1294}
1295
1296task buildExampleAndroidNJars {
1297 dependsOn downloadDeps
1298 def examplesDir = file("src/test/examplesAndroidN")
1299 task "compile_examplesAndroidN"(type: JavaCompile) {
1300 source = fileTree(dir: examplesDir, include: '**/*.java')
1301 destinationDir = file("build/test/examplesAndroidN/classes")
1302 classpath = sourceSets.main.compileClasspath
1303 sourceCompatibility = JavaVersion.VERSION_1_8
1304 targetCompatibility = JavaVersion.VERSION_1_8
1305 options.compilerArgs += ["-Xlint:-options"]
1306 }
1307 examplesDir.eachDir { dir ->
1308 def name = dir.getName();
1309 def exampleOutputDir = file("build/test/examplesAndroidN");
1310 def jarName = "${name}.jar"
1311 dependsOn "jar_examplesAndroidN_${name}"
1312 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1313 archiveName = jarName
1314 destinationDir = exampleOutputDir
1315 from "build/test/examplesAndroidN/classes"
1316 include "**/" + name + "/**/*.class"
1317 }
1318 }
1319}
1320
1321
1322task buildExampleAndroidOJars {
1323 dependsOn downloadDeps
1324 def examplesDir = file("src/test/examplesAndroidO")
1325 // NOTE: we want to enable a scenario when test needs to reference some
1326 // classes generated by legacy (1.6) Java compiler to test some specific
1327 // behaviour. To do so we compile all the java files located in sub-directory
1328 // called 'legacy' with Java 1.6, then compile the rest of the files with
1329 // Java 1.8 and a reference to previously generated 1.6 classes.
1330
1331 // Compiling all classes in dirs 'legacy' with old Java version.
1332 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1333 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1334 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1335 classpath = sourceSets.main.compileClasspath
1336 sourceCompatibility = JavaVersion.VERSION_1_6
1337 targetCompatibility = JavaVersion.VERSION_1_6
1338 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1339 }
1340 // Compiling the rest of the files as Java 1.8 code.
1341 task "compile_examplesAndroidO"(type: JavaCompile) {
1342 dependsOn "compile_examplesAndroidO_Legacy"
1343 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1344 destinationDir = file("build/test/examplesAndroidO/classes")
1345 classpath = sourceSets.main.compileClasspath
1346 classpath += files("build/test/examplesAndroidOLegacy/classes")
1347 sourceCompatibility = JavaVersion.VERSION_1_8
1348 targetCompatibility = JavaVersion.VERSION_1_8
1349 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1350 }
1351 examplesDir.eachDir { dir ->
1352 def name = dir.getName();
1353 def destinationDir = file("build/test/examplesAndroidO/classes");
1354 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1355 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1356 dependsOn: "compile_examplesAndroidO") {
1357 main = name + ".TestGenerator"
1358 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1359 args destinationDir
1360 }
1361 } else {
1362 task "generate_examplesAndroidO_${name}" () {}
1363 }
1364 }
1365 examplesDir.eachDir { dir ->
1366 def name = dir.getName();
1367 def exampleOutputDir = file("build/test/examplesAndroidO");
1368 def jarName = "${name}.jar"
1369 dependsOn "jar_examplesAndroidO_${name}"
1370 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1371 "generate_examplesAndroidO_${name}"]) {
1372 archiveName = jarName
1373 destinationDir = exampleOutputDir
1374 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1375 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1376 include "**/" + name + "/**/*.class"
1377 // Do not include generator into the test runtime jar, it is not useful.
1378 // Otherwise, shrinking will need ASM jars.
1379 exclude "**/TestGenerator*"
1380 }
1381 }
1382}
1383
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001384task buildExampleAndroidPJars {
1385 dependsOn downloadDeps
1386 def examplesDir = file("src/test/examplesAndroidP")
1387
1388 task "compile_examplesAndroidP"(type: JavaCompile) {
1389 source = fileTree(dir: examplesDir, include: '**/*.java')
1390 destinationDir = file("build/test/examplesAndroidP/classes")
1391 classpath = sourceSets.main.compileClasspath
1392 sourceCompatibility = JavaVersion.VERSION_1_8
1393 targetCompatibility = JavaVersion.VERSION_1_8
1394 options.compilerArgs += ["-Xlint:-options"]
1395 }
1396 examplesDir.eachDir { dir ->
1397 def name = dir.getName();
1398 def destinationDir = file("build/test/examplesAndroidP/classes");
1399 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1400 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1401 dependsOn: "compile_examplesAndroidP") {
1402 main = name + ".TestGenerator"
1403 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1404 args destinationDir
1405 }
1406 } else {
1407 task "generate_examplesAndroidP_${name}" () {}
1408 }
1409 }
1410 examplesDir.eachDir { dir ->
1411 def name = dir.getName();
1412 def exampleOutputDir = file("build/test/examplesAndroidP");
1413 def jarName = "${name}.jar"
1414 dependsOn "jar_examplesAndroidP_${name}"
1415 task "jar_examplesAndroidP_${name}"(type: Jar,
1416 dependsOn: ["compile_examplesAndroidP",
1417 "generate_examplesAndroidP_${name}"]) {
1418 archiveName = jarName
1419 destinationDir = exampleOutputDir
1420 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1421 include "**/" + name + "/**/*.class"
1422 // Do not include generator into the test runtime jar, it is not useful.
1423 // Otherwise, shrinking will need ASM jars.
1424 exclude "**/TestGenerator*"
1425 }
1426 }
1427}
1428
Mikaël Peltier61633d42017-10-13 16:51:06 +02001429task buildExampleJava9Jars {
1430 def examplesDir = file("src/test/examplesJava9")
1431 examplesDir.eachDir { dir ->
1432 def name = dir.getName();
1433 def exampleOutputDir = file("build/test/examplesJava9");
1434 def jarName = "${name}.jar"
1435 dependsOn "jar_examplesJava9_${name}"
1436 task "jar_examplesJava9_${name}"(type: Jar) {
1437 archiveName = jarName
1438 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001439 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001440 include "**/" + name + "/**/*.class"
1441 }
1442 }
1443}
1444
Jake Wharton2000b2f2019-12-11 20:37:49 -05001445task buildExampleJava10Jars {
1446 def examplesDir = file("src/test/examplesJava10")
1447 examplesDir.eachDir { dir ->
1448 def name = dir.getName();
1449 def exampleOutputDir = file("build/test/examplesJava10");
1450 def jarName = "${name}.jar"
1451 dependsOn "jar_examplesJava10_${name}"
1452 task "jar_examplesJava10_${name}"(type: Jar) {
1453 archiveName = jarName
1454 destinationDir = exampleOutputDir
1455 from sourceSets.examplesJava10.output
1456 include "**/" + name + "/**/*.class"
1457 }
1458 }
1459}
1460
clementberad7ab1dd2019-04-16 16:05:00 +02001461task buildExampleJava11Jars {
1462 def examplesDir = file("src/test/examplesJava11")
1463 examplesDir.eachDir { dir ->
1464 def name = dir.getName();
1465 def exampleOutputDir = file("build/test/examplesJava11");
1466 def jarName = "${name}.jar"
1467 dependsOn "jar_examplesJava11_${name}"
1468 task "jar_examplesJava11_${name}"(type: Jar) {
1469 archiveName = jarName
1470 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001471 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001472 include "**/" + name + "/**/*.class"
1473 }
1474 }
1475}
1476
clementberaa92e3cd2019-07-12 14:13:22 +02001477task provideArtFrameworksDependencies {
1478 cloudDependencies.tools.forEach({ art ->
1479 if (art.contains("art")) {
1480 def taskName = art.replace('/','_')
1481 dependsOn "patch_${taskName}"
1482 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1483 from "tools/${art}/framework"
1484 include "**.jar"
1485 into file("tools/${art}/out/host/linux-x86/framework")
1486 }
1487 }
1488 })
1489}
1490
clementbera4f9c2a92019-07-09 08:50:37 +02001491task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1492 from sourceSets.jdk11TimeTests.compileClasspath
1493 include "**/**.jar"
1494 into file("build/test/jdk11Tests")
1495}
1496
1497task buildJdk11TimeTestsJar {
1498 def exampleOutputDir = file("build/test/jdk11Tests");
1499 def jarName = "jdk11TimeTests.jar"
1500 dependsOn "jar_jdk11TimeTests"
1501 dependsOn provideJdk11TestsDependencies
1502 task "jar_jdk11TimeTests"(type: Jar) {
1503 archiveName = jarName
1504 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001505 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001506 include "**.class"
1507 from sourceSets.jdk11TimeTests.output
1508 include "**.class"
1509 include "**/**.class"
1510 }
1511}
1512
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001513task buildExamplesKotlin {
1514 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1515 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1516 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1517 } else if (!OperatingSystem.current().isLinux()) {
1518 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1519 "on your platform. It is fully supported on Linux and partially supported on " +
1520 "Mac OS and Windows")
1521 return;
1522 }
1523 def examplesDir = file("src/test/examplesKotlin")
1524 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001525 def name = dir.getName();
1526 dependsOn "dex_example_kotlin_${name}"
1527 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1528 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001529 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001530 dependsOn: "compile_example_kotlin_${name}") {
1531 doFirst {
1532 if (!dexPath.exists()) {
1533 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001534 }
1535 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001536 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1537 destination = dexPath
1538 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001539 }
1540 }
1541}
1542
Sebastien Hertzd3313772018-01-16 14:12:37 +01001543task buildKotlinR8TestResources {
1544 def examplesDir = file("src/test/kotlinR8TestResources")
1545 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001546 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1547 def name = dir.getName()
1548 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001549 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1550 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001551 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001552 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001553 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1554 source = fileTree(dir: file("${examplesDir}/${name}"),
1555 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001556 destination = file(outputFile)
1557 targetVersion = kotlinTargetVersion
1558 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001559 task "${taskName}Java"(type: JavaCompile) {
1560 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1561 destinationDir = file(javaOutput)
1562 classpath = sourceSets.main.compileClasspath
1563 sourceCompatibility = JavaVersion.VERSION_1_6
1564 targetCompatibility = JavaVersion.VERSION_1_6
1565 options.compilerArgs += ["-g", "-Xlint:-options"]
1566 }
1567 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1568 archiveName = javaOutputJarName
1569 destinationDir = file(javaOutputJarDir)
1570 from javaOutput
1571 include "**/*.class"
1572 }
1573 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001574 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001575 }
1576}
1577
Mads Ager418d1ca2017-05-22 09:35:49 +02001578task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001579 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1580 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1581 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001582 } else if (!OperatingSystem.current().isLinux()) {
1583 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001584 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001585 return;
1586 }
1587 dependsOn buildDebugTestResourcesJars
1588 dependsOn buildExampleJars
1589 dependsOn buildExampleAndroidNJars
1590 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001591 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001592 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001593 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001594 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001595 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001596 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001597 def noDexTests = [
1598 "multidex",
1599 "multidex002",
1600 "multidex004",
1601 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001602 examplesDir.eachDir { dir ->
1603 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001604 if (!(name in noDexTests)) {
1605 dependsOn "dex_example_${name}"
1606 def exampleOutputDir = file("build/test/examples/" + name);
1607 def dexPath = file("${exampleOutputDir}")
1608 def debug = (name == "throwing")
1609 if (!dexPath.exists()) {
1610 dexPath.mkdirs()
1611 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001612 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001613 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1614 destination = dexPath
1615 debug = debug
1616 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001617 }
1618 }
1619}
1620
1621task buildSmali {
1622 def smaliDir = file("src/test/smali")
1623 smaliDir.eachDirRecurse() { dir ->
1624 def name = dir.getName();
1625 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1626 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1627 smaliOutputDir.mkdirs()
1628 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001629 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001630 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1631 def javaFiles = fileTree(dir: dir, include: '*.java')
1632 def destDir = smaliOutputDir;
1633 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1634 def intermediateFileName = "${name}-intermediate.dex";
1635 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1636 if (javaFiles.empty) {
1637 if (!smaliFiles.empty) {
1638 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001639 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001640 source = smaliFiles
1641 destination = destFile
1642 }
1643 }
1644 } else {
1645 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001646 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001647 source = smaliFiles
1648 destination = intermediateFile
1649 }
1650 task "${taskName}_java"(type: JavaCompile) {
1651 source = javaFiles
1652 destinationDir destDir
1653 classpath = sourceSets.main.compileClasspath
1654 sourceCompatibility = JavaVersion.VERSION_1_7
1655 targetCompatibility = JavaVersion.VERSION_1_7
1656 options.compilerArgs += ["-Xlint:-options"]
1657 }
1658 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1659 archiveName = "Test.jar"
1660 destinationDir = destDir
1661 from fileTree(dir: destDir, include: 'Test.class')
1662 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001663 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001664 source = fileTree(dir: destDir, include: 'Test.jar')
1665 destination = destDir
1666 }
1667 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001668 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001669 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1670 destination = destFile
1671 }
1672 }
1673 }
1674}
1675
1676tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001677 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001678 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001679 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001680 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001681 if (userDefinedCoresPerFork) {
1682 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1683 } else {
1684 // On normal work machines this seems to give the best test execution time (without freezing)
1685 maxParallelForks = processors.intdiv(3) ?: 1
1686 }
Rico Windc56f21c2019-03-12 07:29:57 +01001687 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001688
Mads Ager418d1ca2017-05-22 09:35:49 +02001689 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001690 if (project.hasProperty('disable_assertions')) {
1691 enableAssertions = false
1692 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001693 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001694 if (project.hasProperty('test_xmx')) {
1695 maxHeapSize = project.property('test_xmx')
1696 } else {
1697 maxHeapSize = "4G"
1698 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001699}
1700
1701task buildPreNJdwpTestsJar(type: Jar) {
1702 baseName = 'jdwp-tests-preN'
1703 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1704 // Exclude the classes containing java8
1705 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1706 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1707 includeEmptyDirs = false
1708}
1709
Ian Zerny74143162017-11-24 13:46:35 +01001710task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1711 def inFile = buildPreNJdwpTestsJar.archivePath
1712 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001713 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001714 outputs.file outFile
1715 if (OperatingSystem.current().isWindows()) {
1716 executable file("tools/windows/dx/bin/dx.bat")
1717 } else if (OperatingSystem.current().isMacOsX()) {
1718 executable file("tools/mac/dx/bin/dx");
1719 } else {
1720 executable file("tools/linux/dx/bin/dx");
1721 }
1722 args "--dex"
1723 args "--output=${outFile}"
1724 args inFile
1725}
1726
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001727task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1728 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001729}
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001730def getR8LibSourceTask() {
1731 if (project.hasProperty('r8lib')) {
1732 return R8NoManifest
1733 } else if (project.hasProperty('r8lib_no_deps')) {
1734 return R8NoManifestNoDeps
1735 }
1736 return null
1737}
Yohann Roussel126f6872017-08-03 16:25:32 +02001738
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001739def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001740 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001741 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001742 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001743 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001744 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001745 return null
1746}
1747
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001748task generateR8TestKeepRules {
1749 def path = "build/generated/r8tests-keep.txt"
1750 outputs.file path
1751 if (getR8LibTask() != null) {
1752 dependsOn getR8LibTask()
1753 doLast {
1754 file(path).write """-keep class ** { *; }
1755-dontshrink
1756-dontoptimize
1757-keepattributes *
1758-applymapping ${getR8LibTask().outputs.files[0]}.map
1759"""
1760 }
1761 }
1762}
1763
1764task buildR8LibCfTestDeps(type: Exec) {
1765 if (getR8LibTask() == null) {
1766 return
1767 }
1768 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1769 dependsOn downloadDeps
1770 dependsOn getR8LibTask()
1771 dependsOn getR8LibSourceTask()
1772 dependsOn generateR8TestKeepRules
1773 dependsOn testJar
1774 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1775 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1776 return pkg.toString().endsWith(".jar")
1777 } + ["${buildDir}/classes/java/test"]
1778 inputs.files testJar.outputs.files +
1779 generateR8TestKeepRules.outputs.files +
1780 getR8LibTask().outputs
1781 commandLine = r8CfCommandLine(
1782 testJar.outputs.files[0],
1783 outputPath,
1784 [generateR8TestKeepRules.outputs.files[0]],
1785 ["--debug", "--classpath", getR8LibSourceTask().outputs.files[0]],
1786 getR8LibSourceTask().outputs.files + addedLibraries)
1787 workingDir = projectDir
1788 outputs.file outputPath
1789}
1790
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001791task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001792 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001793 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001794 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001795 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001796 delete r8LibTestPath
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001797 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1798 def examplesDir = file("build/test")
1799 examplesDir.eachDir { dir ->
1800 from ("${buildDir}/test/${dir.getName()}/classes")
1801 }
1802 from ("${buildDir}/runtime/examples")
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001803 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001804 }
1805 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001806}
1807
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001808def printStackTrace(TestResult result) {
1809 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1810 def out = new StringBuffer()
1811 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001812 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001813 def header = "RETRACED STACKTRACE";
1814 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1815 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1816 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1817 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001818 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001819 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001820 out.append("--------------------------------------\n")
1821 Process process = command.execute()
1822 def processIn = new PrintStream(process.getOut())
1823 process.consumeProcessOutput(out, err)
1824 result.exception.printStackTrace(processIn)
1825 processIn.flush()
1826 processIn.close()
Morten Krogh-Jespersenfe0d7e12020-01-31 08:50:17 +01001827 if (process.waitFor() != 0) {
1828 out.append("ERROR DURING RETRACING\n")
1829 out.append(err.toString())
1830 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001831 out.append("\n\n--------------------------------------\n")
1832 out.append("OBFUSCATED STACKTRACE\n")
1833 out.append("--------------------------------------\n")
1834 result.exceptions.add(0, new Exception(out.toString()))
1835 } else {
1836 result.exception.printStackTrace()
1837 }
1838}
1839
Mads Ager418d1ca2017-05-22 09:35:49 +02001840test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001841 if (project.hasProperty('generate_golden_files_to')) {
1842 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1843 assert project.hasProperty('HEAD_sha1')
1844 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1845 }
1846
1847 if (project.hasProperty('use_golden_files_in')) {
1848 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1849 assert project.hasProperty('HEAD_sha1')
1850 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1851 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001852
Ian Zerny64312222019-12-05 15:12:24 +01001853 dependsOn buildLibraryDesugarConversions
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001854 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001855 // R8.jar is required for running bootstrap tests.
1856 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001857 testLogging.exceptionFormat = 'full'
1858 if (project.hasProperty('print_test_stdout')) {
1859 testLogging.showStandardStreams = true
1860 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001861 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001862 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001863 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001864 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001865
Ian Zerny324d7612019-03-20 10:52:28 +01001866 // Forward runtime configurations for test parameters.
1867 if (project.hasProperty('runtimes')) {
1868 println "NOTE: Running with runtimes: " + project.property('runtimes')
1869 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001870 }
1871
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001872 if (project.hasProperty('slow_tests')) {
1873 systemProperty 'slow_tests', project.property('slow_tests')
1874 }
1875
Mads Ager418d1ca2017-05-22 09:35:49 +02001876 if (project.hasProperty('one_line_per_test')) {
1877 beforeTest { desc ->
1878 println "Start executing test ${desc.name} [${desc.className}]"
1879 }
1880 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001881 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001882 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001883 }
Rico Windda6836e2018-12-07 12:32:03 +01001884 if (project.hasProperty('update_test_timestamp')) {
1885 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1886 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001887 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1888 }
Rico Windf88b6be2018-12-11 15:14:05 +01001889 } else {
1890 afterTest { desc, result ->
1891 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001892 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001893 }
1894 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001895 }
1896 if (project.hasProperty('no_internal')) {
1897 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001898 } else {
1899 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001900 }
1901 if (project.hasProperty('only_internal')) {
1902 include "com/android/tools/r8/internal/**"
1903 }
Rico Wind4e218292019-03-07 12:44:49 +01001904
Mads Ager418d1ca2017-05-22 09:35:49 +02001905 if (project.hasProperty('tool')) {
1906 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001907 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001908 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001909 if (project.hasProperty('only_jctf')) {
1910 include "com/android/tools/r8/jctf/d8/**"
1911 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001912 // Don't run anything, deprecated
1913 println "Running with deprecated tool d8, not running any tests"
1914 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001915 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001916 } else {
1917 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001918 assert(project.hasProperty('only_jctf'))
1919 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001920 }
1921 }
1922 if (!project.hasProperty('all_tests')) {
1923 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001924 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001925 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001926 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001927 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001928 if (project.hasProperty('shard_count') ) {
1929 assert project.hasProperty('shard_number')
1930 int shard_count = project.getProperty('shard_count') as Integer
1931 int shard_number = project.getProperty('shard_number') as Integer
1932 assert shard_count < 65536
1933 assert shard_number < shard_count
1934 exclude {
1935 entry ->
1936 // Don't leave out directories. Leaving out a directory means all entries below.
1937 if (entry.file.isDirectory()) {
1938 return false
1939 }
1940 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1941 int hash = Integer.parseInt(first4, 16)
1942 return hash % shard_count != shard_number
1943 }
1944 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001945 if (project.hasProperty('jctf_compile_only')) {
1946 println "JCTF: compiling only"
1947 systemProperty 'jctf_compile_only', '1'
1948 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001949 if (project.hasProperty('test_dir')) {
1950 systemProperty 'test_dir', project.property('test_dir')
1951 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001952 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1953 dependsOn configureTestForR8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001954 // R8lib should be used instead of the main output and all the tests in r8 should be mapped
1955 // and exists in r8LibtestPath.
1956 classpath = sourceSets.test.runtimeClasspath.filter {
1957 !it.getAbsolutePath().contains("/build/")
1958 }
1959 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001960 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001961 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001962 if (OperatingSystem.current().isLinux()
1963 || OperatingSystem.current().isMacOsX()
1964 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001965 if (OperatingSystem.current().isMacOsX()) {
1966 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1967 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1968 "See tools/docker/README.md for details.")
1969 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001970 if (OperatingSystem.current().isWindows()) {
1971 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1972 "Art only runs on Linux and tests requiring Art will be skipped")
1973 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001974 dependsOn downloadDeps
1975 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001976 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001977 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001978 dependsOn buildSmali
1979 dependsOn jctfCommonJar
1980 dependsOn jctfTestsClasses
1981 dependsOn buildDebugInfoExamplesDex
1982 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001983 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02001984 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02001985 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02001986 } else {
1987 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001988 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001989 }
1990}
1991
1992// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1993//
1994// To build and upload a new set of the Art tests for use with R8 follow these steps:
1995//
1996// First of all an Android checkout is required. Currently it must be located
1997// in $HOME/android/master.
1998//
1999// TODO(ricow): simplify this
2000//
2001// Before: update the checked in art, see scripts/update-host-art.sh
2002//
2003// 1. Get an android checkout in $HOME/android/master and apply the patch from
2004// https://android-review.googlesource.com/#/c/294187/
2005//
2006// 2. run the following commands in the Android checkout directory:
2007//
2008// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002009// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2010// m desugar
2011// m -j30 test-art-host
2012// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2013//
2014// Without running the test.py command the classes.jar file used by desugar in
2015// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2016// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002017//
2018// 3. In the R8 project root directory, make sure we have a clean state before starting:
2019// tools/gradle.py downloadDeps
2020// tools/gradle.py clean
2021// rm -rf tests/art
2022//
2023// 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 +02002024// Make sure you have smali on your path, please use the build binary in the
2025// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2026// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2027// 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 +02002028// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2029// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002030//
Søren Gjesse34b77732017-07-07 13:56:21 +02002031// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002032//
2033// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2034// skippedTests with an explanation. Rerun from step 3.
2035//
2036// 5. Run the tests:
2037// tools/gradle.py clean
2038// tools/test.py
2039//
Søren Gjesse34b77732017-07-07 13:56:21 +02002040// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2041// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2042// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002043//
Søren Gjesse34b77732017-07-07 13:56:21 +02002044// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002045// cd tests
2046// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002047//
2048// 7. Update the manifest file describing the Android repo used:
2049// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002050
Mads Ager418d1ca2017-05-22 09:35:49 +02002051def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002052
2053def artTestDir = file("${androidCheckoutDir}/art/test")
2054
2055if (project.hasProperty('android_source')) {
2056 task buildArtTests {
2057 outputs.upToDateWhen { false }
2058 def toBeTriaged = [
2059 "903-hello-tagging",
2060 "904-object-allocation",
2061 "905-object-free",
2062 "906-iterate-heap",
2063 "907-get-loaded-classes",
2064 "908-gc-start-finish",
2065 "954-invoke-polymorphic-verifier",
2066 "955-methodhandles-smali",
2067 "596-monitor-inflation",
2068 ]
2069 def skippedTests = toBeTriaged + [
2070 // This test produces no jar.
2071 "000-nop",
2072 // This does not build, as it tests the error when the application exceeds more
2073 // than 65536 methods
2074 "089-many-methods",
2075 // Requires some jack beta jar
2076 "956-methodhandles",
2077 ]
2078
2079 def skippedTestsDx = [
2080 // Tests with custom build scripts, where javac is not passed the options
2081 // -source 1.7 -target 1.7.
2082 "462-checker-inlining-across-dex-files",
2083 "556-invoke-super",
2084 "569-checker-pattern-replacement",
2085 // These tests use jack even when --build-with-javac-dx is specified.
2086 "004-JniTest",
2087 "048-reflect-v8",
2088 "146-bad-interface",
2089 "563-checker-invoke-super",
2090 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2091 "604-hot-static-interface",
2092 "957-methodhandle-transforms",
2093 "958-methodhandle-emulated-stackframe",
2094 "959-invoke-polymorphic-accessors",
2095 "961-default-iface-resolution-gen",
2096 "962-iface-static",
2097 "963-default-range-smali",
2098 "964-default-iface-init-gen",
2099 "965-default-verify",
2100 "966-default-conflict",
2101 "967-default-ame",
2102 "968-default-partial-compile-gen",
2103 "969-iface-super",
2104 "970-iface-super-resolution-gen",
2105 "971-iface-super",
2106 // These tests does not build with --build-with-javac-dx
2107 "004-NativeAllocations", // Javac error
2108 "031-class-attributes",
2109 "138-duplicate-classes-check",
2110 "157-void-class", // Javac error
2111 "580-checker-string-factory-intrinsics",
2112 "612-jit-dex-cache",
2113 "613-inlining-dex-cache",
2114 "900-hello-plugin", // --experimental agents
2115 "901-hello-ti-agent", // --experimental agents
2116 "902-hello-transformation", // --experimental agents
2117 "909-attach-agent", // --experimental agents
2118 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2119 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2120 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2121 "960-default-smali", // --experimental default-methods
2122 // These tests force the build to use jack
2123 "953-invoke-polymorphic-compiler",
2124 "958-methodhandle-stackframe",
2125 ]
2126
2127 def artTestBuildDir = file("${projectDir}/tests/art")
2128
2129 if (androidCheckoutDir.exists()) {
2130 dependsOn downloadDeps
2131 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002132 artTestDir.eachDir { dir ->
2133 def name = dir.getName();
2134 def markerFile = dir.toPath().resolve("info.txt").toFile();
2135 if (markerFile.exists() && !(name in skippedTests)) {
2136 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002137 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002138 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002139 }
2140 }
2141 }
2142 doFirst {
2143 if (!androidCheckoutDir.exists()) {
2144 throw new InvalidUserDataException(
2145 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002146 }
2147 }
2148 doLast {
2149 copy {
2150 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2151 into file("${artTestBuildDir}/lib64")
2152 include 'lib*.so'
2153 }
2154 copy {
2155 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2156 into file("${artTestBuildDir}/lib64")
2157 include 'libart.so'
2158 include 'libbacktrace.so'
2159 include 'libbase.so'
2160 include 'libc++.so'
2161 include 'libcutils.so'
2162 include 'liblz4.so'
2163 include 'liblzma.so'
2164 include 'libnativebridge.so'
2165 include 'libnativeloader.so'
2166 include 'libsigchain.so'
2167 include 'libunwind.so'
2168 include 'libziparchive.so'
2169 }
2170 copy {
2171 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2172 into file("${artTestBuildDir}/lib")
2173 include 'lib*.so'
2174 }
2175 copy {
2176 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2177 into file("${artTestBuildDir}/lib")
2178 include 'libart.so'
2179 include 'libbacktrace.so'
2180 include 'libbase.so'
2181 include 'libc++.so'
2182 include 'libcutils.so'
2183 include 'liblz4.so'
2184 include 'liblzma.so'
2185 include 'libnativebridge.so'
2186 include 'libnativeloader.so'
2187 include 'libsigchain.so'
2188 include 'libunwind.so'
2189 include 'libziparchive.so'
2190 }
2191 }
2192 }
2193}
2194
Rico Windde2af6c2019-03-26 15:21:08 +01002195def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002196 def artTestDir = file("${androidCheckoutDir}/art/test")
2197 def artRunTestScript = file("${artTestDir}/run-test")
2198 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002199 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002200
Søren Gjesse34b77732017-07-07 13:56:21 +02002201 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002202 def buildTask = "build_art_test_dx_${name}"
2203 def sanitizeTask = "sanitize_art_test_dx_${name}"
2204 def copyCheckTask = "copy_check_art_test_dx_${name}"
2205 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002206
2207 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002208 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002209 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2210 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002211 task "$buildTask"(type: Exec) {
2212 outputs.upToDateWhen { false }
2213 inputs.file buildInputs
2214 executable "${artRunTestScript}"
2215 args "--host"
2216 args "--build-only"
2217 args "--build-with-javac-dx"
2218 args "--output-path", "${testDir}"
2219 args "${name}"
2220 environment DX: "${dxExecutable.absolutePath}"
2221 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2222 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2223 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002224 }
2225 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2226 outputs.upToDateWhen { false }
2227 executable "/bin/bash"
2228 args "-c"
2229 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2230 " ${testDir}/classes-ex ${testDir}/check"
2231 }
2232
2233 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002234 // Directory that contains smali files is either smali, or smali/art
2235 def smali_dir = file("${dir}/smali/art")
2236 if (smali_dir.exists()) {
2237 workingDir "${testDir}/smali/art"
2238 } else {
2239 workingDir "${testDir}/smali"
2240 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002241 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002242 // This is the command line options for smali prior to 2.2.1, where smali got a new
2243 // command line interface.
2244 args "-c", "smali a *.smali"
2245 // This is the command line options for smali 2.2.1 and later.
2246 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002247 }
2248
2249 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2250 def smali_dir = file("${dir}/smali")
2251 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002252 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002253 dependsOn smaliToDexTask
2254 }
2255 from("${artTestDir}/${name}") {
2256 include 'check'
2257 }
2258 into testDir
2259 }
2260
2261 return copyCheckTask
2262}
2263
2264task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002265 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002266 classpath = sourceSets.main.compileClasspath
2267 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002268 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002269 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002270 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002271 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002272 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002273 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002274 include '**/com/android/tools/r8/CompilationMode.java'
2275 include '**/com/android/tools/r8/D8.java'
2276 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002277 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2278 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002279 include '**/com/android/tools/r8/Diagnostic.java'
2280 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002281 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2282 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002283 include '**/com/android/tools/r8/ProgramConsumer.java'
2284 include '**/com/android/tools/r8/ProgramResource.java'
2285 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002286 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002287 include '**/com/android/tools/r8/ResourceException.java'
2288 include '**/com/android/tools/r8/StringConsumer.java'
2289 include '**/com/android/tools/r8/StringResource.java'
2290 include '**/com/android/tools/r8/Version.java'
2291 include '**/com/android/tools/r8/origin/*.java'
2292}
2293
2294task javadocR8(type: Javadoc) {
2295 title "R8 API"
2296 classpath = sourceSets.main.compileClasspath
2297 source = sourceSets.main.allJava
2298 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2299 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2300 include '**/com/android/tools/r8/BaseCommand.java'
2301 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2302 include '**/com/android/tools/r8/ClassFileConsumer.java'
2303 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2304 include '**/com/android/tools/r8/CompilationFailedException.java'
2305 include '**/com/android/tools/r8/CompilationMode.java'
2306 include '**/com/android/tools/r8/R8.java'
2307 include '**/com/android/tools/r8/R8Command.java'
2308 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2309 include '**/com/android/tools/r8/Diagnostic.java'
2310 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002311 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2312 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002313 include '**/com/android/tools/r8/ProgramConsumer.java'
2314 include '**/com/android/tools/r8/ProgramResource.java'
2315 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2316 include '**/com/android/tools/r8/Resource.java'
2317 include '**/com/android/tools/r8/ResourceException.java'
2318 include '**/com/android/tools/r8/StringConsumer.java'
2319 include '**/com/android/tools/r8/StringResource.java'
2320 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002321 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002322}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002323
2324task copyMavenDeps(type: Copy) {
2325 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002326 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002327 from configurations.testCompile into "$buildDir/deps"
2328}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002329
Rico Wind23a05112019-03-27 08:00:44 +01002330task printMavenDeps {
2331 // Only actually print to stdout when we are updating.
2332 if (project.hasProperty('updatemavendeps')) {
2333 for (Configuration config : configurations) {
2334 if (!config.isCanBeResolved()) {
2335 continue
2336 }
2337 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2338 it.selected.id
2339 }
2340 def result = dependencies.createArtifactResolutionQuery()
2341 .forComponents(componentIds)
2342 .withArtifacts(MavenModule, MavenPomArtifact)
2343 .execute()
2344 for (component in result.resolvedComponents) {
2345 component.getArtifacts(MavenPomArtifact).each {
2346 println "POM: ${it.file} ${component.id}"
2347 }
2348 }
2349 config.each {
2350 println "JAR: ${it}"
2351 }
2352 }
2353 }
2354}
Ian Zerny9713c032020-01-23 11:41:58 +01002355
2356allprojects {
2357 tasks.withType(Exec) {
2358 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002359 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002360 }
2361 }
2362}