blob: 39b8fc0dd3dcea0b753c69245db59d7af9a9e2a7 [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'
Søren Gjesse34e27f52020-03-26 12:03:23 +010038 asmVersion = '7.2'
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-Jespersen7df24322018-12-21 13:39:54 +0100287def r8LibTestPath = "$buildDir/classes/r8libtest"
clementbera0bca05e2019-05-29 14:11:18 +0200288def java11ClassFiles = "build/classes/java/mainJava11"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100289
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200290def osString = OperatingSystem.current().isLinux() ? "linux" :
291 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200292
293def cloudDependencies = [
294 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200295 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100296 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200297 ],
298 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200299 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200300 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100301 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200302 "android_jar/lib-v19",
303 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100304 "android_jar/lib-v22",
305 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200306 "android_jar/lib-v24",
307 "android_jar/lib-v25",
308 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100309 "android_jar/lib-v27",
310 "android_jar/lib-v28",
Søren Gjesse02f52852019-09-04 17:44:03 +0200311 "android_jar/lib-v29",
Søren Gjessefa3f8042020-04-20 12:56:11 +0200312 "android_jar/lib-v30",
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-Jespersen1ba55f52020-04-24 12:49:17 +0200335 "r8mappings",
336 "tachiyomi"
Mads Ager418d1ca2017-05-22 09:35:49 +0200337 ],
338 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
339 // container on other platforms where supported.
340 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200341 "linux/art",
342 "linux/art-5.1.1",
343 "linux/art-6.0.1",
344 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100345 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100346 "linux/art-9.0.0",
clementbera97d5cce2019-11-22 15:09:27 +0100347 "linux/art-10.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200348 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100349 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200350 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200351 ]
352]
353
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100354def cloudSystemDependencies = [
355 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200356 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200357 "openjdk/jdk8/linux-x86",
358 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100359 ],
360 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200361 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200362 "openjdk/jdk8/darwin-x86",
363 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100364 ],
365 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200366 "third_party": ["openjdk/openjdk-9.0.4/windows",
367 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100368 ],
369]
370
371if (OperatingSystem.current().isWindows()) {
372 cloudSystemDependencies.windows.each { entry ->
373 cloudDependencies.get(entry.key).addAll(entry.value)
374 }
375} else if (OperatingSystem.current().isLinux()) {
376 cloudSystemDependencies.linux.each { entry ->
377 cloudDependencies.get(entry.key).addAll(entry.value)
378 }
379} else if (OperatingSystem.current().isMacOsX()) {
380 cloudSystemDependencies.osx.each { entry ->
381 cloudDependencies.get(entry.key).addAll(entry.value)
382 }
383} else {
384 println "WARNING: Unsupported system: " + OperatingSystem.current()
385}
386
387def getDownloadDepsTaskName(entryKey, entryFile) {
388 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
389}
390
Mads Ager418d1ca2017-05-22 09:35:49 +0200391cloudDependencies.each { entry ->
392 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100393 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
394 type DownloadDependency.Type.GOOGLE_STORAGE
395 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200396 }
397 }
398}
399
400def x20Dependencies = [
401 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200402 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700403 "chrome/chrome_180917_ffbaa8",
Christoffer Quist Adamsence640052020-04-30 11:47:41 +0200404 "chrome/chrome_200430",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100405 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100406 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200407 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100408 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200409 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200410 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200411 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200412 "gmscore/gmscore_v10",
413 "gmscore/gmscore_v9",
414 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200415 "gmscore/v4",
416 "gmscore/v5",
417 "gmscore/v6",
418 "gmscore/v7",
419 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200420 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200421 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200422 "proguard/proguard_internal_159423826",
423 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200424 "proto",
425 "protobuf-lite",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200426 "youtube/youtube.android_12.10",
427 "youtube/youtube.android_12.17",
428 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200429 "youtube/youtube.android_13.37",
Søren Gjesse889e09d2019-11-07 16:33:51 +0100430 "youtube/youtube.android_14.19",
Søren Gjesse974707e2020-02-26 09:47:01 +0100431 "youtube/youtube.android_14.44",
Søren Gjesse04638962020-02-28 09:59:30 +0100432 "youtube/youtube.android_15.08",
433 "youtube/youtube.android_15.09"
Mads Ager418d1ca2017-05-22 09:35:49 +0200434 ],
435]
436
437x20Dependencies.each { entry ->
438 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100439 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
440 type DownloadDependency.Type.X20
441 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200442 }
443 }
444}
445
Rico Wind897bb712017-05-23 10:44:29 +0200446task downloadProguard {
447 cloudDependencies.each { entry ->
448 entry.value.each { entryFile ->
449 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100450 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200451 }
452 }
453 }
454}
455
Rico Windf6c74ce2018-12-04 08:50:55 +0100456task downloadOpenJDKrt {
457 cloudDependencies.each { entry ->
458 entry.value.each { entryFile ->
459 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100460 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100461 }
462 }
463 }
464}
465
Tamas Kenez427205b2017-06-29 15:57:09 +0200466task downloadDx {
467 cloudDependencies.each { entry ->
468 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200469 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100470 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200471 }
472 }
473 }
474}
475
Tamas Kenez0e10c562017-06-08 10:00:34 +0200476task downloadAndroidCts {
477 cloudDependencies.each { entry ->
478 entry.value.each { entryFile ->
479 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100480 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200481 }
482 }
483 }
484}
485
Mads Ager418d1ca2017-05-22 09:35:49 +0200486task downloadDeps {
487 cloudDependencies.each { entry ->
488 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100489 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200490 }
491 }
492 if (!project.hasProperty('no_internal')) {
493 x20Dependencies.each { entry ->
494 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100495 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200496 }
497 }
498 }
499}
500
501allprojects {
502 sourceCompatibility = JavaVersion.VERSION_1_8
503 targetCompatibility = JavaVersion.VERSION_1_8
504}
505
Rico Wind266336c2019-02-25 10:11:38 +0100506// TODO(ricow): Remove debug prints
507println("NOTE: Current operating system: " + OperatingSystem.current())
508println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
509
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100510// Check if running with the JDK location from tools/jdk.py.
511if (OperatingSystem.current().isWindows()) {
512 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
Morten Krogh-Jespersend9a88452020-01-31 14:13:54 +0100513 compileJava.options.encoding = "UTF-8"
514 compileTestJava.options.encoding = "UTF-8"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100515} else {
516 def javaHomeOut = new StringBuilder()
517 def javaHomeErr = new StringBuilder()
Jake Wharton7c14ce72019-09-17 13:49:18 -0400518 def javaHomeProc = './tools/jdk.py'.execute([], projectDir)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100519 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
520 def jdkHome = new File(javaHomeOut.toString().trim())
521 if (!jdkHome.exists()) {
522 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
523 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
524 println("WARNING: Gradle is running in a non-pinned Java"
525 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
Christoffer Quist Adamsen79b126a2020-03-27 17:23:08 +0000526 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100527 } else {
528 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100529 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200530}
531
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100532sourceSets.configureEach { sourceSet ->
533 tasks.named(sourceSet.compileJavaTaskName).configure {
534 // Default disable errorprone (enabled and setup below).
535 options.errorprone.enabled = false
536 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100537 // Run all compilation tasks in a forked subprocess.
538 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100539 // Javac often runs out of stack space when compiling the tests.
540 // Increase the stack size for the javac process.
Søren Gjesse1af374d2019-09-06 10:44:54 +0200541 options.forkOptions.jvmArgs << "-Xss256m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100542 // Test compilation is sometimes hitting the default limit at 1g, increase it.
Ian Zerny293b8152019-09-20 10:40:53 +0200543 options.forkOptions.jvmArgs << "-Xmx3g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100544 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
545 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
546 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200547}
548
Ian Zernyd3020482019-04-25 07:05:04 +0200549tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
550 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200551 options.fork = true
552 options.forkOptions.jvmArgs = []
553 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200554 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200555 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200556 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200557 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200558 options.forkOptions.javaHome = file(jdkDir + 'windows')
559 }
560 sourceCompatibility = JavaVersion.VERSION_1_9
561 targetCompatibility = JavaVersion.VERSION_1_9
562}
563
Jake Wharton2000b2f2019-12-11 20:37:49 -0500564def setJdk11CompilationWithCompatibility(String sourceSet, JavaVersion compatibility) {
clementbera0bdd90f2019-07-06 11:15:23 +0200565 tasks.named(sourceSet).get().configure {
566 def jdkDir = 'third_party/openjdk/jdk-11/'
567 options.fork = true
568 options.forkOptions.jvmArgs = []
569 if (OperatingSystem.current().isLinux()) {
570 options.forkOptions.javaHome = file(jdkDir + 'Linux')
571 } else if (OperatingSystem.current().isMacOsX()) {
572 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
573 } else {
574 options.forkOptions.javaHome = file(jdkDir + 'Windows')
575 }
Jake Wharton2000b2f2019-12-11 20:37:49 -0500576 sourceCompatibility = compatibility
577 targetCompatibility = compatibility
clementbera0fe940d2019-04-23 12:45:18 +0200578 }
clementbera0fe940d2019-04-23 12:45:18 +0200579}
580
Jake Wharton2000b2f2019-12-11 20:37:49 -0500581setJdk11CompilationWithCompatibility(sourceSets.examplesJava10.compileJavaTaskName, JavaVersion.VERSION_1_10)
582setJdk11CompilationWithCompatibility(sourceSets.examplesJava11.compileJavaTaskName, JavaVersion.VERSION_11)
583setJdk11CompilationWithCompatibility(sourceSets.examplesTestNGRunner.compileJavaTaskName, JavaVersion.VERSION_11)
584setJdk11CompilationWithCompatibility(sourceSets.jdk11TimeTests.compileJavaTaskName, JavaVersion.VERSION_11)
clementbera0bdd90f2019-07-06 11:15:23 +0200585
clementbera0bca05e2019-05-29 14:11:18 +0200586task compileMainWithJava11 (type: JavaCompile) {
Ian Zernye0dd4c42019-12-02 10:12:15 +0100587 dependsOn downloadDeps
clementbera0bca05e2019-05-29 14:11:18 +0200588 def jdkDir = 'third_party/openjdk/jdk-11/'
589 options.fork = true
590 options.forkOptions.jvmArgs = []
591 if (OperatingSystem.current().isLinux()) {
592 options.forkOptions.javaHome = file(jdkDir + 'Linux')
593 } else if (OperatingSystem.current().isMacOsX()) {
Jake Whartona5204f32019-06-26 08:29:21 -0400594 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
clementbera0bca05e2019-05-29 14:11:18 +0200595 } else {
596 options.forkOptions.javaHome = file(jdkDir + 'Windows')
597 }
598 source = sourceSets.main.allSource
599 destinationDir = file(java11ClassFiles)
600 sourceCompatibility = JavaVersion.VERSION_11
601 targetCompatibility = JavaVersion.VERSION_11
602 classpath = sourceSets.main.compileClasspath
603}
clementbera0fe940d2019-04-23 12:45:18 +0200604
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100605if (!project.hasProperty('without_error_prone') &&
606 // Don't enable error prone on Java 8 as the plugin setup does not support it.
607 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200608 compileJava {
609 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100610 options.errorprone.enabled = true
611 options.errorprone.disableAllChecks = true
612 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
613 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
614 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
615 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
616 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
617 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
618 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
619 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
620 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
621 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
622 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
623 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
624 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
625 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
626 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
627 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
628 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
629 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
630 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200631 }
632}
633
Mads Ager418d1ca2017-05-22 09:35:49 +0200634compileJctfCommonJava {
635 dependsOn 'copyAdditionalJctfCommonFiles'
636 options.compilerArgs = ['-Xlint:none']
637}
638
639compileJctfTestsJava {
640 dependsOn 'jctfCommonClasses'
641 options.compilerArgs = ['-Xlint:none']
642}
643
Yohann Roussel7f47c032017-09-14 12:19:06 +0200644task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200645 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100646
Yohann Roussel7f47c032017-09-14 12:19:06 +0200647 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100648 def runtimeClasspath = configurations.findByName("runtimeClasspath")
649 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
650
Yohann Roussel7f47c032017-09-14 12:19:06 +0200651 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100652
Yohann Roussel7f47c032017-09-14 12:19:06 +0200653 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100654 def dependencies = []
655 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
656 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
657 dependencies.add("${identifier.group}:${identifier.module}")
658 }
659 def libraryLicenses = file('LIBRARY-LICENSE').text
660 dependencies.each {
661 if (!libraryLicenses.contains("- artifact: $it")) {
662 throw new GradleException("No license for $it in LIBRARY_LICENSE")
663 }
664 }
665
Yohann Roussel7f47c032017-09-14 12:19:06 +0200666 license.getParentFile().mkdirs()
667 license.createNewFile()
668 license.text = "This file lists all licenses for code distributed.\n"
669 license.text += "All non-library code has the following 3-Clause BSD license.\n"
670 license.text += "\n"
671 license.text += "\n"
672 license.text += file('LICENSE').text
673 license.text += "\n"
674 license.text += "\n"
675 license.text += "Summary of distributed libraries:\n"
676 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100677 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200678 license.text += "\n"
679 license.text += "\n"
680 license.text += "Licenses details:\n"
681 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
682 license.text += "\n"
683 license.text += "\n"
684 license.text += file.text
685 }
686 }
687}
688
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200689static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700690 // Everything under META-INF is not included by default.
691 // Should include before 'relocate' so that the service file path and its content
692 // are properly relocated as well.
693 task.mergeServiceFiles {
694 include 'META-INF/services/*'
695 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200696}
697
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000698task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100699 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200700 mergeServiceFiles(it)
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100701 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700702 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000703 baseName 'deps'
704}
705
706task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200707 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200708 mergeServiceFiles(it)
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000709 baseName 'sources'
710}
711
clementbera0bca05e2019-05-29 14:11:18 +0200712task repackageSources11(type: ShadowJar) {
713 dependsOn compileMainWithJava11
714 from file(java11ClassFiles)
715 mergeServiceFiles(it)
clementbera55e84822019-06-06 16:08:11 +0200716 baseName 'sources11'
clementbera0bca05e2019-05-29 14:11:18 +0200717}
718
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200719def r8CreateTask(name, baseNameName, sources, includeSwissArmyKnife) {
720 return tasks.create("r8Create${name}", ShadowJar) {
721 from consolidatedLicense.outputs.files
722 from sources
723 baseName baseNameName
724 classifier = null
725 version = null
726 if (includeSwissArmyKnife) {
727 manifest {
728 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
729 }
730 }
731 exclude "META-INF/*.kotlin_module"
732 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200733 }
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200734}
735
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200736def r8RelocateTask(r8Task, output) {
737 return tasks.create("r8Relocate_${r8Task.name}", Exec) {
738 dependsOn r8WithDeps
739 dependsOn r8Task
740 outputs.file output
741 workingDir = projectDir
742 inputs.files r8Task.outputs.files + r8WithDeps.outputs.files
743 commandLine baseR8CommandLine([
744 "relocator",
745 "--input",
746 r8Task.outputs.files[0],
747 "--output",
748 output,
749 "--map",
750 "com.google.common->com.android.tools.r8.com.google.common",
751 "--map",
752 "com.google.gson->com.android.tools.r8.com.google.gson",
753 "--map",
754 "com.google.thirdparty->com.android.tools.r8.com.google.thirdparty",
755 "--map",
756 "joptsimple->com.android.tools.r8.joptsimple",
757 "--map",
758 "org.objectweb.asm->com.android.tools.r8.org.objectweb.asm",
759 "--map",
760 "it.unimi.dsi.fastutil->com.android.tools.r8.it.unimi.dsi.fastutil",
761 "--map",
762 "kotlin->com.android.tools.r8.jetbrains.kotlin",
763 "--map",
764 "kotlinx->com.android.tools.r8.jetbrains.kotlinx",
765 "--map",
766 "org.jetbrains->com.android.tools.r8.org.jetbrains",
767 "--map",
768 "org.intellij->com.android.tools.r8.org.intellij"
769 ])
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200770 }
771}
772
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200773task r8WithDeps {
774 dependsOn repackageSources
775 dependsOn repackageDeps
776 def r8Task = r8CreateTask(
777 'WithDeps',
778 'r8_with_deps',
779 repackageSources.outputs.files + repackageDeps.outputs.files,
780 true)
781 dependsOn r8Task
782 outputs.files r8Task.outputs.files
clementbera0bca05e2019-05-29 14:11:18 +0200783}
784
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200785task r8WithDeps11 {
786 dependsOn repackageSources11
787 dependsOn repackageDeps
788 def r8Task = r8CreateTask(
789 'WithDeps11',
790 'r8_with_deps_11',
791 repackageSources11.outputs.files + repackageDeps.outputs.files,
792 true)
793 dependsOn r8Task
794 outputs.files r8Task.outputs.files
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100795}
796
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200797task r8WithRelocatedDeps {
798 def output = "${buildDir}/libs/r8_with_relocated_deps.jar"
799 dependsOn r8RelocateTask(r8WithDeps, output)
800 outputs.file output
Morten Krogh-Jespersen8c812bd2020-04-29 15:50:24 +0200801}
802
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200803task r8WithRelocatedDeps11 {
804 def output = "${buildDir}/libs/r8_with_relocated_deps_11.jar"
805 dependsOn r8RelocateTask(r8WithDeps11, output)
806 outputs.file output
807}
808
809task r8WithoutDeps {
810 dependsOn repackageSources
811 def r8Task = r8CreateTask(
812 'WithoutDeps',
813 'r8_without_deps',
814 repackageSources.outputs.files,
815 true)
816 dependsOn r8Task
817 outputs.files r8Task.outputs.files
818}
819
820task r8(type: Copy) {
821 def r8Task = project.hasProperty("exclude_deps")
822 ? r8WithoutDeps : r8WithRelocatedDeps
823 dependsOn r8Task
824 from r8Task.outputs.files[0]
825 into file("${buildDir}/libs")
826 rename { String fileName -> "r8.jar" }
827 outputs.file "${buildDir}/libs/r8.jar"
828}
829
830task r8NoManifestWithoutDeps {
831 dependsOn repackageSources
832 def r8Task = r8CreateTask(
833 'NoManifestWithoutDeps',
834 'r8_no_manifest_without_deps',
835 repackageSources.outputs.files,
836 false)
837 dependsOn r8Task
838 outputs.files r8Task.outputs.files
839}
840
841task r8NoManifestWithDeps {
842 dependsOn repackageSources
843 def r8Task = r8CreateTask(
844 'NoManifestWithDeps',
845 'r8_no_manifest_with_deps',
846 repackageSources.outputs.files + repackageDeps.outputs.files,
847 false)
848 dependsOn r8Task
849 outputs.files r8Task.outputs.files
850}
851
852task r8NoManifestWithRelocatedDeps {
853 def output = "${buildDir}/libs/r8_no_manifest_with_relocated_deps.jar"
854 dependsOn r8RelocateTask(r8NoManifestWithDeps, output)
855 outputs.file output
856}
857
858task r8NoManifest(type: Copy) {
859 def r8Task = project.hasProperty("exclude_deps")
860 ? r8NoManifestWithoutDeps : r8NoManifestWithRelocatedDeps
861 dependsOn r8Task
862 from r8Task.outputs.files[0]
863 into file("${buildDir}/libs")
864 rename { String fileName -> "r8_no_manifest.jar" }
865 outputs.file "${buildDir}/libs/r8_no_manifest.jar"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100866}
867
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000868task D8(type: ShadowJar) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200869 dependsOn r8
870 from r8.outputs.files[0]
Mads Ager418d1ca2017-05-22 09:35:49 +0200871 baseName 'd8'
872 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200873 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200874 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200875}
876
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100877def baseR8CommandLine(args = []) {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200878 // Execute r8 commands against a stable r8 with dependencies.
Morten Krogh-Jespersen4849e792019-08-20 13:27:13 +0200879 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx6g).
Rico Windcfb65512019-02-27 12:57:34 +0100880 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200881 "-Xmx8g", "-ea", "-jar", r8WithDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100882}
883
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200884def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
885 def allArgs = [
886 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100887 input,
888 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100889 "--pg-map-output", output + ".map",
890 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200891 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
892 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100893}
894
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200895def r8LibCreateTask(name, pgConfs = [], r8Task, output, args = ["--release"], libs = []) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100896 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200897 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs, libs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100898 outputs.file output
899 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100900 dependsOn r8WithRelocatedDeps
901 dependsOn r8Task
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200902 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConfs, args, libs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100903 workingDir = projectDir
904 }
905}
906
Søren Gjesse17fc67d2019-12-04 14:50:17 +0100907task buildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
908 from sourceSets.libraryDesugarConversions.output
909 include "java/**/*.class"
910 baseName 'library_desugar_conversions'
911 destinationDir file('build/libs')
912}
913
914task testJar(type: ShadowJar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100915 baseName = "r8tests"
916 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200917 // We only want to include tests that use R8 when generating keep rules for applymapping.
918 include "com/android/tools/r8/**"
919 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100920}
921
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200922task generateR8LibKeepRules(type: Exec) {
923 doFirst {
924 // TODO(b/154785341): We should remove this.
925 standardOutput new FileOutputStream(r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100926 }
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200927 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200928 dependsOn r8WithRelocatedDeps
929 dependsOn testJar
930 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200931 inputs.files ([r8WithRelocatedDeps.outputs, r8NoManifest.outputs, testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200932 outputs.file r8LibGeneratedKeepRulesPath
933 commandLine baseR8CommandLine([
934 "printuses",
935 "--keeprules-allowobfuscation",
936 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200937 r8NoManifest.outputs.files[0],
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200938 testJar.outputs.files[0]])
939 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100940}
941
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100942task R8LibApiOnly {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200943 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], r8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100944 outputs.file r8LibPath
945}
946
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100947task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100948 dependsOn r8LibCreateTask(
949 "Main",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200950 ["src/main/keep.txt",
951 "src/main/keep-applymapping.txt",
952 generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200953 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100954 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200955 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100956 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100957}
958
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100959task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100960 dependsOn r8LibCreateTask(
961 "NoDeps",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200962 ["src/main/keep.txt", "src/main/keep-applymapping.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200963 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100964 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200965 "--release",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200966 repackageDeps.outputs.files
967 ).dependsOn(repackageDeps)
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100968 outputs.file r8LibExludeDepsPath
969}
970
Mads Ager418d1ca2017-05-22 09:35:49 +0200971task sourceJar(type: Jar, dependsOn: classes) {
972 classifier = 'src'
973 from sourceSets.main.allSource
974}
975
976task jctfCommonJar(type: Jar) {
977 from sourceSets.jctfCommon.output
978 baseName 'jctfCommon'
979}
980
981artifacts {
982 archives sourceJar
983}
984
985task createArtTests(type: Exec) {
986 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200987 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100988 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200989 outputs.dir outputDir
990 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200991 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200992 workingDir = projectDir
993}
994
995task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200996 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200997 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200998 inputs.file script
999 outputs.dir outputDir
1000 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +02001001 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +02001002 workingDir = projectDir
1003}
1004
1005compileTestJava {
1006 dependsOn createArtTests
1007 dependsOn createJctfTests
1008}
1009
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001010task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1011 from sourceSets.cfSegments.output
1012 baseName 'cf_segments'
1013 destinationDir file('build/libs')
1014}
1015
Ian Zernyee23a172018-01-03 09:08:48 +01001016task buildD8ApiUsageSample(type: Jar) {
1017 from sourceSets.apiUsageSample.output
1018 baseName 'd8_api_usage_sample'
1019 destinationDir file('tests')
1020}
1021
Ian Zerny923a0c12018-01-03 10:59:18 +01001022task buildR8ApiUsageSample(type: Jar) {
1023 from sourceSets.apiUsageSample.output
1024 baseName 'r8_api_usage_sample'
1025 destinationDir file('tests')
1026}
1027
Yohann Roussel548ae942018-01-05 11:13:28 +01001028task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001029 dependsOn buildD8ApiUsageSample
1030 dependsOn buildR8ApiUsageSample
1031}
1032
Mads Ager418d1ca2017-05-22 09:35:49 +02001033task buildDebugInfoExamplesDex {
1034 def examplesDir = file("src/test/java")
1035 def hostJar = "debuginfo_examples.jar"
1036 def hostDexJar = "debuginfo_examples_dex.jar"
1037 task "compile_debuginfo_examples"(type: JavaCompile) {
1038 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1039 destinationDir = file("build/test/debuginfo_examples/classes")
1040 classpath = sourceSets.main.compileClasspath
1041 sourceCompatibility = JavaVersion.VERSION_1_7
1042 targetCompatibility = JavaVersion.VERSION_1_7
1043 options.compilerArgs += ["-Xlint:-options"]
1044 }
1045 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1046 archiveName = hostJar
1047 destinationDir = file("build/test/")
1048 from "build/test/debuginfo_examples/classes"
1049 include "**/*.class"
1050 }
1051 task "dex_debuginfo_examples"(type: Exec,
1052 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001053 if (OperatingSystem.current().isWindows()) {
1054 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001055 } else if (OperatingSystem.current().isMacOsX()) {
1056 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001057 } else {
1058 executable file("tools/linux/dx/bin/dx");
1059 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001060 args "--dex"
1061 args "--output=build/test/${hostDexJar}"
1062 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001063 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001064 outputs.file file("build/test/${hostDexJar}")
1065 }
1066 dependsOn dex_debuginfo_examples
1067}
1068
1069task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001070 def resourcesDir = file("src/test/debugTestResources")
1071 def hostJar = "debug_test_resources.jar"
1072 task "compile_debugTestResources"(type: JavaCompile) {
1073 source = fileTree(dir: resourcesDir, include: '**/*.java')
1074 destinationDir = file("build/test/debugTestResources/classes")
1075 classpath = sourceSets.main.compileClasspath
1076 sourceCompatibility = JavaVersion.VERSION_1_7
1077 targetCompatibility = JavaVersion.VERSION_1_7
1078 options.compilerArgs += ["-g", "-Xlint:-options"]
1079 }
1080 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1081 archiveName = hostJar
1082 destinationDir = file("build/test/")
1083 from "build/test/debugTestResources/classes"
1084 include "**/*.class"
1085 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001086 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1087 def java8HostJar = "debug_test_resources_java8.jar"
1088 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1089 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1090 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1091 classpath = sourceSets.main.compileClasspath
1092 sourceCompatibility = JavaVersion.VERSION_1_8
1093 targetCompatibility = JavaVersion.VERSION_1_8
1094 options.compilerArgs += ["-g", "-Xlint:-options"]
1095 }
1096 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1097 archiveName = java8HostJar
1098 destinationDir = file("build/test/")
1099 from "build/test/debugTestResourcesJava8/classes"
1100 include "**/*.class"
1101 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001102 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001103 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1104 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1105 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1106 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001107 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001108 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001109 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001110 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001111 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001112}
1113
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001114// Examples used by tests, where Android specific APIs are used.
1115task buildExampleAndroidApi(type: JavaCompile) {
1116 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1117 destinationDir = file("build/test/examplesAndroidApi/classes")
1118 classpath = files("third_party/android_jar/lib-v26/android.jar")
1119 sourceCompatibility = JavaVersion.VERSION_1_8
1120 targetCompatibility = JavaVersion.VERSION_1_8
1121}
1122
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001123task buildExampleKotlinJars {
1124 def kotlinSrcDir = file("src/test/examplesKotlin")
1125 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001126 def name = dir.getName();
1127 dependsOn "compile_example_kotlin_${name}"
1128 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1129 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1130 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001131 }
1132 }
1133}
1134
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001135task buildProtoGeneratedSources {
1136 def examplesProtoDir = file("src/test/examplesProto")
1137 examplesProtoDir.eachDir { dir ->
1138 def name = dir.getName()
1139 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1140 source = {
1141 file('third_party/proto').listFiles()
1142 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1143 .collect { zipTree(it) }
1144 }
1145 destinationDir = file("build/generated/test/proto/${name}_classes")
1146 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1147 sourceCompatibility = JavaVersion.VERSION_1_8
1148 targetCompatibility = JavaVersion.VERSION_1_8
1149 }
1150 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1151 archiveName = "${name}.jar"
1152 destinationDir = file("build/generated/test/proto")
1153 from "build/generated/test/proto/${name}_classes"
1154 include "/**/*.class"
1155 }
1156 dependsOn "jar_proto_generated_source_${name}"
1157 }
1158}
1159
1160task buildExamplesProto {
1161 def examplesProtoDir = file("src/test/examplesProto")
1162 def examplesProtoOutputDir = file("build/test/examplesProto");
1163 dependsOn buildProtoGeneratedSources
1164 task "compile_examples_proto"(type: JavaCompile) {
1165 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1166 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001167 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1168 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001169 sourceCompatibility = JavaVersion.VERSION_1_8
1170 targetCompatibility = JavaVersion.VERSION_1_8
1171 }
1172 examplesProtoDir.eachDir { dir ->
1173 def name = dir.getName()
1174 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1175 archiveName = "${name}.jar"
1176 destinationDir = examplesProtoOutputDir
1177 from "build/test/examplesProto/classes"
1178 include name + "/**/*.class"
1179 }
1180 dependsOn "jar_examples_proto_${name}"
1181 }
1182}
1183
Lars Bakc91e87e2017-08-18 08:53:10 +02001184// Proto lite generated code yields warnings when compiling with javac.
1185// We change the options passed to javac to ignore it.
1186compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1187
Søren Gjesse7320ce52018-05-07 15:45:22 +02001188
Mads Ager418d1ca2017-05-22 09:35:49 +02001189task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001190 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001191 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001192 def proguardScript
1193 if (OperatingSystem.current().isWindows()) {
1194 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1195 } else {
1196 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1197 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001198 task extractExamplesRuntime(type: Sync) {
1199 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001200 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001201 include "**/*.class"
1202 includeEmptyDirs false
1203 into "$buildDir/runtime/examples/"
1204 }
1205
Søren Gjesse7320ce52018-05-07 15:45:22 +02001206 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1207 from examplesDir
1208 exclude "**/*.java"
1209 exclude "**/keep-rules*.txt"
1210 into file("build/test/examples/classes")
1211 }
1212
1213 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001214 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001215 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001216 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001217 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001218 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001219 sourceCompatibility = JavaVersion.VERSION_1_7
1220 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001221 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1222 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001223 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1224 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001225 include "**/*.java"
1226 destinationDir = file("build/test/examples/classes_debuginfo_all")
1227 classpath = sourceSets.examples.compileClasspath
1228 sourceCompatibility = JavaVersion.VERSION_1_7
1229 targetCompatibility = JavaVersion.VERSION_1_7
1230 options.compilerArgs = ["-g", "-Xlint:none"]
1231 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001232 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1233 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001234 include "**/*.java"
1235 destinationDir = file("build/test/examples/classes_debuginfo_none")
1236 classpath = sourceSets.examples.compileClasspath
1237 sourceCompatibility = JavaVersion.VERSION_1_7
1238 targetCompatibility = JavaVersion.VERSION_1_7
1239 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001240 }
1241 examplesDir.eachDir { dir ->
1242 def name = dir.getName();
1243 def exampleOutputDir = file("build/test/examples");
1244 def jarName = "${name}.jar"
1245 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001246 dependsOn "jar_example_${name}_debuginfo_all"
1247 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001248 dependsOn "extractExamplesRuntime"
1249 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001250 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1251 def proguardConfigPath = "${dir}/proguard.cfg"
1252 if (new File(proguardConfigPath).exists()) {
1253 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1254 archiveName = "${name}_pre_proguard.jar"
1255 destinationDir = exampleOutputDir
1256 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001257 include name + "/**/*.class"
1258 with runtimeDependencies
1259 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001260 }
1261 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1262 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1263 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1264 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001265 inputs.files files(
1266 tasks.getByPath("pre_proguard_example_${name}"),
1267 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001268 // Enable these to get stdout and stderr redirected to files...
1269 // standardOutput = new FileOutputStream('proguard.stdout')
1270 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001271 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001272 " -outjars ${proguardJarPath}" +
1273 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001274 " -printmapping ${proguardMapPath}"
1275 if (OperatingSystem.current().isWindows()) {
1276 executable "${proguardScript}"
1277 args "${proguardArguments}"
1278 } else {
1279 executable "bash"
1280 args "-c", "${proguardScript} '${proguardArguments}'"
1281 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001282 outputs.file proguardJarPath
1283 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001284 // TODO: Consider performing distinct proguard compilations.
1285 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1286 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001287 into "${exampleOutputDir}"
1288 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001289 }
1290 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1291 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001292 into "${exampleOutputDir}"
1293 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001294 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001295 } else {
1296 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001297 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001298 destinationDir = exampleOutputDir
1299 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001300 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001301 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001302 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001303 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001304 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1305 archiveName = "${name}_debuginfo_all.jar"
1306 destinationDir = exampleOutputDir
1307 from "build/test/examples/classes_debuginfo_all"
1308 include name + "/**/*.class"
1309 with runtimeDependencies
1310 includeEmptyDirs false
1311 }
1312 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1313 archiveName = "${name}_debuginfo_none.jar"
1314 destinationDir = exampleOutputDir
1315 from "build/test/examples/classes_debuginfo_none"
1316 include name + "/**/*.class"
1317 with runtimeDependencies
1318 includeEmptyDirs false
1319 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001320 }
1321 }
1322}
1323
1324task buildExampleAndroidNJars {
1325 dependsOn downloadDeps
1326 def examplesDir = file("src/test/examplesAndroidN")
1327 task "compile_examplesAndroidN"(type: JavaCompile) {
1328 source = fileTree(dir: examplesDir, include: '**/*.java')
1329 destinationDir = file("build/test/examplesAndroidN/classes")
1330 classpath = sourceSets.main.compileClasspath
1331 sourceCompatibility = JavaVersion.VERSION_1_8
1332 targetCompatibility = JavaVersion.VERSION_1_8
1333 options.compilerArgs += ["-Xlint:-options"]
1334 }
1335 examplesDir.eachDir { dir ->
1336 def name = dir.getName();
1337 def exampleOutputDir = file("build/test/examplesAndroidN");
1338 def jarName = "${name}.jar"
1339 dependsOn "jar_examplesAndroidN_${name}"
1340 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1341 archiveName = jarName
1342 destinationDir = exampleOutputDir
1343 from "build/test/examplesAndroidN/classes"
1344 include "**/" + name + "/**/*.class"
1345 }
1346 }
1347}
1348
1349
1350task buildExampleAndroidOJars {
1351 dependsOn downloadDeps
1352 def examplesDir = file("src/test/examplesAndroidO")
1353 // NOTE: we want to enable a scenario when test needs to reference some
1354 // classes generated by legacy (1.6) Java compiler to test some specific
1355 // behaviour. To do so we compile all the java files located in sub-directory
1356 // called 'legacy' with Java 1.6, then compile the rest of the files with
1357 // Java 1.8 and a reference to previously generated 1.6 classes.
1358
1359 // Compiling all classes in dirs 'legacy' with old Java version.
1360 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1361 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1362 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1363 classpath = sourceSets.main.compileClasspath
1364 sourceCompatibility = JavaVersion.VERSION_1_6
1365 targetCompatibility = JavaVersion.VERSION_1_6
1366 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1367 }
1368 // Compiling the rest of the files as Java 1.8 code.
1369 task "compile_examplesAndroidO"(type: JavaCompile) {
1370 dependsOn "compile_examplesAndroidO_Legacy"
1371 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1372 destinationDir = file("build/test/examplesAndroidO/classes")
1373 classpath = sourceSets.main.compileClasspath
1374 classpath += files("build/test/examplesAndroidOLegacy/classes")
1375 sourceCompatibility = JavaVersion.VERSION_1_8
1376 targetCompatibility = JavaVersion.VERSION_1_8
1377 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1378 }
1379 examplesDir.eachDir { dir ->
1380 def name = dir.getName();
1381 def destinationDir = file("build/test/examplesAndroidO/classes");
1382 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1383 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1384 dependsOn: "compile_examplesAndroidO") {
1385 main = name + ".TestGenerator"
1386 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1387 args destinationDir
1388 }
1389 } else {
1390 task "generate_examplesAndroidO_${name}" () {}
1391 }
1392 }
1393 examplesDir.eachDir { dir ->
1394 def name = dir.getName();
1395 def exampleOutputDir = file("build/test/examplesAndroidO");
1396 def jarName = "${name}.jar"
1397 dependsOn "jar_examplesAndroidO_${name}"
1398 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1399 "generate_examplesAndroidO_${name}"]) {
1400 archiveName = jarName
1401 destinationDir = exampleOutputDir
1402 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1403 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1404 include "**/" + name + "/**/*.class"
1405 // Do not include generator into the test runtime jar, it is not useful.
1406 // Otherwise, shrinking will need ASM jars.
1407 exclude "**/TestGenerator*"
1408 }
1409 }
1410}
1411
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001412task buildExampleAndroidPJars {
1413 dependsOn downloadDeps
1414 def examplesDir = file("src/test/examplesAndroidP")
1415
1416 task "compile_examplesAndroidP"(type: JavaCompile) {
1417 source = fileTree(dir: examplesDir, include: '**/*.java')
1418 destinationDir = file("build/test/examplesAndroidP/classes")
1419 classpath = sourceSets.main.compileClasspath
1420 sourceCompatibility = JavaVersion.VERSION_1_8
1421 targetCompatibility = JavaVersion.VERSION_1_8
1422 options.compilerArgs += ["-Xlint:-options"]
1423 }
1424 examplesDir.eachDir { dir ->
1425 def name = dir.getName();
1426 def destinationDir = file("build/test/examplesAndroidP/classes");
1427 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1428 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1429 dependsOn: "compile_examplesAndroidP") {
1430 main = name + ".TestGenerator"
1431 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1432 args destinationDir
1433 }
1434 } else {
1435 task "generate_examplesAndroidP_${name}" () {}
1436 }
1437 }
1438 examplesDir.eachDir { dir ->
1439 def name = dir.getName();
1440 def exampleOutputDir = file("build/test/examplesAndroidP");
1441 def jarName = "${name}.jar"
1442 dependsOn "jar_examplesAndroidP_${name}"
1443 task "jar_examplesAndroidP_${name}"(type: Jar,
1444 dependsOn: ["compile_examplesAndroidP",
1445 "generate_examplesAndroidP_${name}"]) {
1446 archiveName = jarName
1447 destinationDir = exampleOutputDir
1448 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1449 include "**/" + name + "/**/*.class"
1450 // Do not include generator into the test runtime jar, it is not useful.
1451 // Otherwise, shrinking will need ASM jars.
1452 exclude "**/TestGenerator*"
1453 }
1454 }
1455}
1456
Mikaël Peltier61633d42017-10-13 16:51:06 +02001457task buildExampleJava9Jars {
1458 def examplesDir = file("src/test/examplesJava9")
1459 examplesDir.eachDir { dir ->
1460 def name = dir.getName();
1461 def exampleOutputDir = file("build/test/examplesJava9");
1462 def jarName = "${name}.jar"
1463 dependsOn "jar_examplesJava9_${name}"
1464 task "jar_examplesJava9_${name}"(type: Jar) {
1465 archiveName = jarName
1466 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001467 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001468 include "**/" + name + "/**/*.class"
1469 }
1470 }
1471}
1472
Jake Wharton2000b2f2019-12-11 20:37:49 -05001473task buildExampleJava10Jars {
1474 def examplesDir = file("src/test/examplesJava10")
1475 examplesDir.eachDir { dir ->
1476 def name = dir.getName();
1477 def exampleOutputDir = file("build/test/examplesJava10");
1478 def jarName = "${name}.jar"
1479 dependsOn "jar_examplesJava10_${name}"
1480 task "jar_examplesJava10_${name}"(type: Jar) {
1481 archiveName = jarName
1482 destinationDir = exampleOutputDir
1483 from sourceSets.examplesJava10.output
1484 include "**/" + name + "/**/*.class"
1485 }
1486 }
1487}
1488
clementberad7ab1dd2019-04-16 16:05:00 +02001489task buildExampleJava11Jars {
1490 def examplesDir = file("src/test/examplesJava11")
1491 examplesDir.eachDir { dir ->
1492 def name = dir.getName();
1493 def exampleOutputDir = file("build/test/examplesJava11");
1494 def jarName = "${name}.jar"
1495 dependsOn "jar_examplesJava11_${name}"
1496 task "jar_examplesJava11_${name}"(type: Jar) {
1497 archiveName = jarName
1498 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001499 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001500 include "**/" + name + "/**/*.class"
1501 }
1502 }
1503}
1504
clementberaa92e3cd2019-07-12 14:13:22 +02001505task provideArtFrameworksDependencies {
1506 cloudDependencies.tools.forEach({ art ->
1507 if (art.contains("art")) {
1508 def taskName = art.replace('/','_')
1509 dependsOn "patch_${taskName}"
1510 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1511 from "tools/${art}/framework"
1512 include "**.jar"
1513 into file("tools/${art}/out/host/linux-x86/framework")
1514 }
1515 }
1516 })
1517}
1518
clementbera4f9c2a92019-07-09 08:50:37 +02001519task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1520 from sourceSets.jdk11TimeTests.compileClasspath
1521 include "**/**.jar"
1522 into file("build/test/jdk11Tests")
1523}
1524
1525task buildJdk11TimeTestsJar {
1526 def exampleOutputDir = file("build/test/jdk11Tests");
1527 def jarName = "jdk11TimeTests.jar"
1528 dependsOn "jar_jdk11TimeTests"
1529 dependsOn provideJdk11TestsDependencies
1530 task "jar_jdk11TimeTests"(type: Jar) {
1531 archiveName = jarName
1532 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001533 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001534 include "**.class"
1535 from sourceSets.jdk11TimeTests.output
1536 include "**.class"
1537 include "**/**.class"
1538 }
1539}
1540
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001541task buildExamplesKotlin {
1542 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1543 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1544 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1545 } else if (!OperatingSystem.current().isLinux()) {
1546 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1547 "on your platform. It is fully supported on Linux and partially supported on " +
1548 "Mac OS and Windows")
1549 return;
1550 }
1551 def examplesDir = file("src/test/examplesKotlin")
1552 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001553 def name = dir.getName();
1554 dependsOn "dex_example_kotlin_${name}"
1555 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1556 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001557 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001558 dependsOn: "compile_example_kotlin_${name}") {
1559 doFirst {
1560 if (!dexPath.exists()) {
1561 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001562 }
1563 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001564 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1565 destination = dexPath
1566 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001567 }
1568 }
1569}
1570
Sebastien Hertzd3313772018-01-16 14:12:37 +01001571task buildKotlinR8TestResources {
1572 def examplesDir = file("src/test/kotlinR8TestResources")
1573 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001574 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1575 def name = dir.getName()
1576 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001577 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1578 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001579 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001580 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001581 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1582 source = fileTree(dir: file("${examplesDir}/${name}"),
1583 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001584 destination = file(outputFile)
1585 targetVersion = kotlinTargetVersion
1586 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001587 task "${taskName}Java"(type: JavaCompile) {
1588 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1589 destinationDir = file(javaOutput)
1590 classpath = sourceSets.main.compileClasspath
1591 sourceCompatibility = JavaVersion.VERSION_1_6
1592 targetCompatibility = JavaVersion.VERSION_1_6
1593 options.compilerArgs += ["-g", "-Xlint:-options"]
1594 }
1595 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1596 archiveName = javaOutputJarName
1597 destinationDir = file(javaOutputJarDir)
1598 from javaOutput
1599 include "**/*.class"
1600 }
1601 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001602 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001603 }
1604}
1605
Mads Ager418d1ca2017-05-22 09:35:49 +02001606task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001607 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1608 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1609 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001610 } else if (!OperatingSystem.current().isLinux()) {
1611 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001612 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001613 return;
1614 }
1615 dependsOn buildDebugTestResourcesJars
1616 dependsOn buildExampleJars
1617 dependsOn buildExampleAndroidNJars
1618 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001619 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001620 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001621 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001622 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001623 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001624 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001625 def noDexTests = [
1626 "multidex",
1627 "multidex002",
1628 "multidex004",
1629 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001630 examplesDir.eachDir { dir ->
1631 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001632 if (!(name in noDexTests)) {
1633 dependsOn "dex_example_${name}"
1634 def exampleOutputDir = file("build/test/examples/" + name);
1635 def dexPath = file("${exampleOutputDir}")
1636 def debug = (name == "throwing")
1637 if (!dexPath.exists()) {
1638 dexPath.mkdirs()
1639 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001640 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001641 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1642 destination = dexPath
1643 debug = debug
1644 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001645 }
1646 }
1647}
1648
1649task buildSmali {
1650 def smaliDir = file("src/test/smali")
1651 smaliDir.eachDirRecurse() { dir ->
1652 def name = dir.getName();
1653 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1654 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1655 smaliOutputDir.mkdirs()
1656 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001657 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001658 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1659 def javaFiles = fileTree(dir: dir, include: '*.java')
1660 def destDir = smaliOutputDir;
1661 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1662 def intermediateFileName = "${name}-intermediate.dex";
1663 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1664 if (javaFiles.empty) {
1665 if (!smaliFiles.empty) {
1666 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001667 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001668 source = smaliFiles
1669 destination = destFile
1670 }
1671 }
1672 } else {
1673 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001674 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001675 source = smaliFiles
1676 destination = intermediateFile
1677 }
1678 task "${taskName}_java"(type: JavaCompile) {
1679 source = javaFiles
1680 destinationDir destDir
1681 classpath = sourceSets.main.compileClasspath
1682 sourceCompatibility = JavaVersion.VERSION_1_7
1683 targetCompatibility = JavaVersion.VERSION_1_7
1684 options.compilerArgs += ["-Xlint:-options"]
1685 }
1686 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1687 archiveName = "Test.jar"
1688 destinationDir = destDir
1689 from fileTree(dir: destDir, include: 'Test.class')
1690 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001691 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001692 source = fileTree(dir: destDir, include: 'Test.jar')
1693 destination = destDir
1694 }
1695 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001696 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001697 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1698 destination = destFile
1699 }
1700 }
1701 }
1702}
1703
1704tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001705 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001706 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001707 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001708 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001709 if (userDefinedCoresPerFork) {
1710 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1711 } else {
1712 // On normal work machines this seems to give the best test execution time (without freezing)
1713 maxParallelForks = processors.intdiv(3) ?: 1
1714 }
Rico Windc56f21c2019-03-12 07:29:57 +01001715 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001716
Mads Ager418d1ca2017-05-22 09:35:49 +02001717 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001718 if (project.hasProperty('disable_assertions')) {
1719 enableAssertions = false
1720 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001721 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001722 if (project.hasProperty('test_xmx')) {
1723 maxHeapSize = project.property('test_xmx')
1724 } else {
1725 maxHeapSize = "4G"
1726 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001727}
1728
1729task buildPreNJdwpTestsJar(type: Jar) {
1730 baseName = 'jdwp-tests-preN'
1731 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1732 // Exclude the classes containing java8
1733 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1734 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1735 includeEmptyDirs = false
1736}
1737
Ian Zerny74143162017-11-24 13:46:35 +01001738task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1739 def inFile = buildPreNJdwpTestsJar.archivePath
1740 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001741 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001742 outputs.file outFile
1743 if (OperatingSystem.current().isWindows()) {
1744 executable file("tools/windows/dx/bin/dx.bat")
1745 } else if (OperatingSystem.current().isMacOsX()) {
1746 executable file("tools/mac/dx/bin/dx");
1747 } else {
1748 executable file("tools/linux/dx/bin/dx");
1749 }
1750 args "--dex"
1751 args "--output=${outFile}"
1752 args inFile
1753}
1754
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001755task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1756 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001757}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001758
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001759task generateR8TestKeepRules {
1760 def path = "build/generated/r8tests-keep.txt"
1761 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001762 dependsOn R8Lib
1763 doLast {
1764 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001765-dontshrink
1766-dontoptimize
1767-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001768-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001769"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001770 }
1771}
1772
1773task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001774 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1775 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001776 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001777 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001778 dependsOn generateR8TestKeepRules
1779 dependsOn testJar
1780 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1781 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1782 return pkg.toString().endsWith(".jar")
1783 } + ["${buildDir}/classes/java/test"]
1784 inputs.files testJar.outputs.files +
1785 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001786 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001787 commandLine = r8CfCommandLine(
1788 testJar.outputs.files[0],
1789 outputPath,
1790 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001791 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1792 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001793 workingDir = projectDir
1794 outputs.file outputPath
1795}
1796
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001797task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001798 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001799 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001800 dependsOn R8Lib
1801 delete r8LibTestPath
1802 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1803 def examplesDir = file("build/test")
1804 examplesDir.eachDir { dir ->
1805 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001806 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001807 from ("${buildDir}/runtime/examples")
1808 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001809 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001810}
1811
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001812def printStackTrace(TestResult result) {
1813 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1814 def out = new StringBuffer()
1815 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001816 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001817 def header = "RETRACED STACKTRACE";
1818 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1819 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1820 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1821 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001822 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001823 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001824 out.append("--------------------------------------\n")
1825 Process process = command.execute()
1826 def processIn = new PrintStream(process.getOut())
1827 process.consumeProcessOutput(out, err)
1828 result.exception.printStackTrace(processIn)
1829 processIn.flush()
1830 processIn.close()
Morten Krogh-Jespersenfe0d7e12020-01-31 08:50:17 +01001831 if (process.waitFor() != 0) {
1832 out.append("ERROR DURING RETRACING\n")
1833 out.append(err.toString())
1834 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001835 out.append("\n\n--------------------------------------\n")
1836 out.append("OBFUSCATED STACKTRACE\n")
1837 out.append("--------------------------------------\n")
1838 result.exceptions.add(0, new Exception(out.toString()))
1839 } else {
1840 result.exception.printStackTrace()
1841 }
1842}
1843
Mads Ager418d1ca2017-05-22 09:35:49 +02001844test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001845 if (project.hasProperty('generate_golden_files_to')) {
1846 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1847 assert project.hasProperty('HEAD_sha1')
1848 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1849 }
1850
1851 if (project.hasProperty('use_golden_files_in')) {
1852 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1853 assert project.hasProperty('HEAD_sha1')
1854 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1855 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001856
Ian Zerny64312222019-12-05 15:12:24 +01001857 dependsOn buildLibraryDesugarConversions
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001858 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001859 // R8.jar is required for running bootstrap tests.
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001860 dependsOn r8
Mads Ager418d1ca2017-05-22 09:35:49 +02001861 testLogging.exceptionFormat = 'full'
1862 if (project.hasProperty('print_test_stdout')) {
1863 testLogging.showStandardStreams = true
1864 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001865 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001866 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001867 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001868 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001869
Ian Zerny324d7612019-03-20 10:52:28 +01001870 // Forward runtime configurations for test parameters.
1871 if (project.hasProperty('runtimes')) {
1872 println "NOTE: Running with runtimes: " + project.property('runtimes')
1873 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001874 }
1875
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001876 if (project.hasProperty('slow_tests')) {
1877 systemProperty 'slow_tests', project.property('slow_tests')
1878 }
1879
Mads Ager418d1ca2017-05-22 09:35:49 +02001880 if (project.hasProperty('one_line_per_test')) {
1881 beforeTest { desc ->
1882 println "Start executing test ${desc.name} [${desc.className}]"
1883 }
1884 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001885 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001886 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001887 }
Rico Windda6836e2018-12-07 12:32:03 +01001888 if (project.hasProperty('update_test_timestamp')) {
1889 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1890 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001891 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1892 }
Rico Windf88b6be2018-12-11 15:14:05 +01001893 } else {
1894 afterTest { desc, result ->
1895 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001896 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001897 }
1898 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001899 }
1900 if (project.hasProperty('no_internal')) {
1901 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001902 } else {
1903 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001904 }
1905 if (project.hasProperty('only_internal')) {
1906 include "com/android/tools/r8/internal/**"
1907 }
Rico Wind4e218292019-03-07 12:44:49 +01001908
Mads Ager418d1ca2017-05-22 09:35:49 +02001909 if (project.hasProperty('tool')) {
1910 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001911 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001912 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001913 if (project.hasProperty('only_jctf')) {
1914 include "com/android/tools/r8/jctf/d8/**"
1915 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001916 // Don't run anything, deprecated
1917 println "Running with deprecated tool d8, not running any tests"
1918 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001919 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001920 } else {
1921 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001922 assert(project.hasProperty('only_jctf'))
1923 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001924 }
1925 }
1926 if (!project.hasProperty('all_tests')) {
1927 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001928 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001929 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001930 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001931 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001932 if (project.hasProperty('shard_count') ) {
1933 assert project.hasProperty('shard_number')
1934 int shard_count = project.getProperty('shard_count') as Integer
1935 int shard_number = project.getProperty('shard_number') as Integer
1936 assert shard_count < 65536
1937 assert shard_number < shard_count
1938 exclude {
1939 entry ->
1940 // Don't leave out directories. Leaving out a directory means all entries below.
1941 if (entry.file.isDirectory()) {
1942 return false
1943 }
1944 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1945 int hash = Integer.parseInt(first4, 16)
1946 return hash % shard_count != shard_number
1947 }
1948 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001949 if (project.hasProperty('jctf_compile_only')) {
1950 println "JCTF: compiling only"
1951 systemProperty 'jctf_compile_only', '1'
1952 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001953 if (project.hasProperty('test_dir')) {
1954 systemProperty 'test_dir', project.property('test_dir')
1955 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001956 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001957 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001958 // R8lib should be used instead of the main output and all the tests in
1959 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001960 classpath = sourceSets.test.runtimeClasspath.filter {
1961 !it.getAbsolutePath().contains("/build/")
1962 }
1963 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001964 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001965 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001966 if (OperatingSystem.current().isLinux()
1967 || OperatingSystem.current().isMacOsX()
1968 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001969 if (OperatingSystem.current().isMacOsX()) {
1970 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1971 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1972 "See tools/docker/README.md for details.")
1973 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001974 if (OperatingSystem.current().isWindows()) {
1975 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1976 "Art only runs on Linux and tests requiring Art will be skipped")
1977 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001978 dependsOn downloadDeps
1979 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001980 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001981 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001982 dependsOn buildSmali
1983 dependsOn jctfCommonJar
1984 dependsOn jctfTestsClasses
1985 dependsOn buildDebugInfoExamplesDex
1986 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001987 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02001988 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02001989 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02001990 } else {
1991 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001992 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001993 }
1994}
1995
1996// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1997//
1998// To build and upload a new set of the Art tests for use with R8 follow these steps:
1999//
2000// First of all an Android checkout is required. Currently it must be located
2001// in $HOME/android/master.
2002//
2003// TODO(ricow): simplify this
2004//
2005// Before: update the checked in art, see scripts/update-host-art.sh
2006//
2007// 1. Get an android checkout in $HOME/android/master and apply the patch from
2008// https://android-review.googlesource.com/#/c/294187/
2009//
2010// 2. run the following commands in the Android checkout directory:
2011//
2012// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002013// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2014// m desugar
2015// m -j30 test-art-host
2016// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2017//
2018// Without running the test.py command the classes.jar file used by desugar in
2019// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2020// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002021//
2022// 3. In the R8 project root directory, make sure we have a clean state before starting:
2023// tools/gradle.py downloadDeps
2024// tools/gradle.py clean
2025// rm -rf tests/art
2026//
2027// 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 +02002028// Make sure you have smali on your path, please use the build binary in the
2029// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2030// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2031// 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 +02002032// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2033// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002034//
Søren Gjesse34b77732017-07-07 13:56:21 +02002035// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002036//
2037// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2038// skippedTests with an explanation. Rerun from step 3.
2039//
2040// 5. Run the tests:
2041// tools/gradle.py clean
2042// tools/test.py
2043//
Søren Gjesse34b77732017-07-07 13:56:21 +02002044// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2045// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2046// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002047//
Søren Gjesse34b77732017-07-07 13:56:21 +02002048// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002049// cd tests
2050// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002051//
2052// 7. Update the manifest file describing the Android repo used:
2053// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002054
Mads Ager418d1ca2017-05-22 09:35:49 +02002055def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002056
2057def artTestDir = file("${androidCheckoutDir}/art/test")
2058
2059if (project.hasProperty('android_source')) {
2060 task buildArtTests {
2061 outputs.upToDateWhen { false }
2062 def toBeTriaged = [
2063 "903-hello-tagging",
2064 "904-object-allocation",
2065 "905-object-free",
2066 "906-iterate-heap",
2067 "907-get-loaded-classes",
2068 "908-gc-start-finish",
2069 "954-invoke-polymorphic-verifier",
2070 "955-methodhandles-smali",
2071 "596-monitor-inflation",
2072 ]
2073 def skippedTests = toBeTriaged + [
2074 // This test produces no jar.
2075 "000-nop",
2076 // This does not build, as it tests the error when the application exceeds more
2077 // than 65536 methods
2078 "089-many-methods",
2079 // Requires some jack beta jar
2080 "956-methodhandles",
2081 ]
2082
2083 def skippedTestsDx = [
2084 // Tests with custom build scripts, where javac is not passed the options
2085 // -source 1.7 -target 1.7.
2086 "462-checker-inlining-across-dex-files",
2087 "556-invoke-super",
2088 "569-checker-pattern-replacement",
2089 // These tests use jack even when --build-with-javac-dx is specified.
2090 "004-JniTest",
2091 "048-reflect-v8",
2092 "146-bad-interface",
2093 "563-checker-invoke-super",
2094 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2095 "604-hot-static-interface",
2096 "957-methodhandle-transforms",
2097 "958-methodhandle-emulated-stackframe",
2098 "959-invoke-polymorphic-accessors",
2099 "961-default-iface-resolution-gen",
2100 "962-iface-static",
2101 "963-default-range-smali",
2102 "964-default-iface-init-gen",
2103 "965-default-verify",
2104 "966-default-conflict",
2105 "967-default-ame",
2106 "968-default-partial-compile-gen",
2107 "969-iface-super",
2108 "970-iface-super-resolution-gen",
2109 "971-iface-super",
2110 // These tests does not build with --build-with-javac-dx
2111 "004-NativeAllocations", // Javac error
2112 "031-class-attributes",
2113 "138-duplicate-classes-check",
2114 "157-void-class", // Javac error
2115 "580-checker-string-factory-intrinsics",
2116 "612-jit-dex-cache",
2117 "613-inlining-dex-cache",
2118 "900-hello-plugin", // --experimental agents
2119 "901-hello-ti-agent", // --experimental agents
2120 "902-hello-transformation", // --experimental agents
2121 "909-attach-agent", // --experimental agents
2122 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2123 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2124 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2125 "960-default-smali", // --experimental default-methods
2126 // These tests force the build to use jack
2127 "953-invoke-polymorphic-compiler",
2128 "958-methodhandle-stackframe",
2129 ]
2130
2131 def artTestBuildDir = file("${projectDir}/tests/art")
2132
2133 if (androidCheckoutDir.exists()) {
2134 dependsOn downloadDeps
2135 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002136 artTestDir.eachDir { dir ->
2137 def name = dir.getName();
2138 def markerFile = dir.toPath().resolve("info.txt").toFile();
2139 if (markerFile.exists() && !(name in skippedTests)) {
2140 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002141 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002142 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002143 }
2144 }
2145 }
2146 doFirst {
2147 if (!androidCheckoutDir.exists()) {
2148 throw new InvalidUserDataException(
2149 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002150 }
2151 }
2152 doLast {
2153 copy {
2154 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2155 into file("${artTestBuildDir}/lib64")
2156 include 'lib*.so'
2157 }
2158 copy {
2159 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2160 into file("${artTestBuildDir}/lib64")
2161 include 'libart.so'
2162 include 'libbacktrace.so'
2163 include 'libbase.so'
2164 include 'libc++.so'
2165 include 'libcutils.so'
2166 include 'liblz4.so'
2167 include 'liblzma.so'
2168 include 'libnativebridge.so'
2169 include 'libnativeloader.so'
2170 include 'libsigchain.so'
2171 include 'libunwind.so'
2172 include 'libziparchive.so'
2173 }
2174 copy {
2175 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2176 into file("${artTestBuildDir}/lib")
2177 include 'lib*.so'
2178 }
2179 copy {
2180 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2181 into file("${artTestBuildDir}/lib")
2182 include 'libart.so'
2183 include 'libbacktrace.so'
2184 include 'libbase.so'
2185 include 'libc++.so'
2186 include 'libcutils.so'
2187 include 'liblz4.so'
2188 include 'liblzma.so'
2189 include 'libnativebridge.so'
2190 include 'libnativeloader.so'
2191 include 'libsigchain.so'
2192 include 'libunwind.so'
2193 include 'libziparchive.so'
2194 }
2195 }
2196 }
2197}
2198
Rico Windde2af6c2019-03-26 15:21:08 +01002199def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002200 def artTestDir = file("${androidCheckoutDir}/art/test")
2201 def artRunTestScript = file("${artTestDir}/run-test")
2202 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002203 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002204
Søren Gjesse34b77732017-07-07 13:56:21 +02002205 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002206 def buildTask = "build_art_test_dx_${name}"
2207 def sanitizeTask = "sanitize_art_test_dx_${name}"
2208 def copyCheckTask = "copy_check_art_test_dx_${name}"
2209 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002210
2211 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002212 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002213 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2214 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002215 task "$buildTask"(type: Exec) {
2216 outputs.upToDateWhen { false }
2217 inputs.file buildInputs
2218 executable "${artRunTestScript}"
2219 args "--host"
2220 args "--build-only"
2221 args "--build-with-javac-dx"
2222 args "--output-path", "${testDir}"
2223 args "${name}"
2224 environment DX: "${dxExecutable.absolutePath}"
2225 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2226 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2227 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002228 }
2229 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2230 outputs.upToDateWhen { false }
2231 executable "/bin/bash"
2232 args "-c"
2233 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2234 " ${testDir}/classes-ex ${testDir}/check"
2235 }
2236
2237 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002238 // Directory that contains smali files is either smali, or smali/art
2239 def smali_dir = file("${dir}/smali/art")
2240 if (smali_dir.exists()) {
2241 workingDir "${testDir}/smali/art"
2242 } else {
2243 workingDir "${testDir}/smali"
2244 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002245 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002246 // This is the command line options for smali prior to 2.2.1, where smali got a new
2247 // command line interface.
2248 args "-c", "smali a *.smali"
2249 // This is the command line options for smali 2.2.1 and later.
2250 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002251 }
2252
2253 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2254 def smali_dir = file("${dir}/smali")
2255 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002256 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002257 dependsOn smaliToDexTask
2258 }
2259 from("${artTestDir}/${name}") {
2260 include 'check'
2261 }
2262 into testDir
2263 }
2264
2265 return copyCheckTask
2266}
2267
2268task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002269 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002270 classpath = sourceSets.main.compileClasspath
2271 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002272 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002273 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002274 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002275 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002276 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002277 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002278 include '**/com/android/tools/r8/CompilationMode.java'
2279 include '**/com/android/tools/r8/D8.java'
2280 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002281 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2282 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002283 include '**/com/android/tools/r8/Diagnostic.java'
2284 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002285 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2286 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002287 include '**/com/android/tools/r8/ProgramConsumer.java'
2288 include '**/com/android/tools/r8/ProgramResource.java'
2289 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002290 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002291 include '**/com/android/tools/r8/ResourceException.java'
2292 include '**/com/android/tools/r8/StringConsumer.java'
2293 include '**/com/android/tools/r8/StringResource.java'
2294 include '**/com/android/tools/r8/Version.java'
2295 include '**/com/android/tools/r8/origin/*.java'
2296}
2297
2298task javadocR8(type: Javadoc) {
2299 title "R8 API"
2300 classpath = sourceSets.main.compileClasspath
2301 source = sourceSets.main.allJava
2302 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2303 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2304 include '**/com/android/tools/r8/BaseCommand.java'
2305 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2306 include '**/com/android/tools/r8/ClassFileConsumer.java'
2307 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2308 include '**/com/android/tools/r8/CompilationFailedException.java'
2309 include '**/com/android/tools/r8/CompilationMode.java'
2310 include '**/com/android/tools/r8/R8.java'
2311 include '**/com/android/tools/r8/R8Command.java'
2312 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2313 include '**/com/android/tools/r8/Diagnostic.java'
2314 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002315 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2316 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002317 include '**/com/android/tools/r8/ProgramConsumer.java'
2318 include '**/com/android/tools/r8/ProgramResource.java'
2319 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2320 include '**/com/android/tools/r8/Resource.java'
2321 include '**/com/android/tools/r8/ResourceException.java'
2322 include '**/com/android/tools/r8/StringConsumer.java'
2323 include '**/com/android/tools/r8/StringResource.java'
2324 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002325 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002326}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002327
2328task copyMavenDeps(type: Copy) {
2329 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002330 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002331 from configurations.testCompile into "$buildDir/deps"
2332}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002333
Rico Wind23a05112019-03-27 08:00:44 +01002334task printMavenDeps {
2335 // Only actually print to stdout when we are updating.
2336 if (project.hasProperty('updatemavendeps')) {
2337 for (Configuration config : configurations) {
2338 if (!config.isCanBeResolved()) {
2339 continue
2340 }
2341 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2342 it.selected.id
2343 }
2344 def result = dependencies.createArtifactResolutionQuery()
2345 .forComponents(componentIds)
2346 .withArtifacts(MavenModule, MavenPomArtifact)
2347 .execute()
2348 for (component in result.resolvedComponents) {
2349 component.getArtifacts(MavenPomArtifact).each {
2350 println "POM: ${it.file} ${component.id}"
2351 }
2352 }
2353 config.each {
2354 println "JAR: ${it}"
2355 }
2356 }
2357 }
2358}
Ian Zerny9713c032020-01-23 11:41:58 +01002359
2360allprojects {
2361 tasks.withType(Exec) {
2362 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002363 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002364 }
2365 }
2366}