blob: 23f55dc0dcad1a2709bc2bff990c66b122a5b5ac [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
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200914task testJarSources(type: ShadowJar, dependsOn: [testClasses, buildLibraryDesugarConversions]) {
915 baseName = "r8testsbase"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100916 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-Jespersen4a5b1012020-05-02 21:54:11 +0200922task testJar(type: Exec) {
923 def output = "$buildDir/libs/r8tests.jar"
924 outputs.file output
925 workingDir = projectDir
926 inputs.files (testJarSources.outputs)
927 commandLine baseR8CommandLine([
928 "relocator",
929 "--input",
930 testJarSources.outputs.files[0],
931 "--output",
932 output,
933 "--map",
934 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
935 ])
936}
937
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200938task generateR8LibKeepRules(type: Exec) {
939 doFirst {
940 // TODO(b/154785341): We should remove this.
941 standardOutput new FileOutputStream(r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100942 }
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200943 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200944 dependsOn r8WithRelocatedDeps
945 dependsOn testJar
946 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200947 inputs.files ([r8WithRelocatedDeps.outputs, r8NoManifest.outputs, testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200948 outputs.file r8LibGeneratedKeepRulesPath
949 commandLine baseR8CommandLine([
950 "printuses",
951 "--keeprules-allowobfuscation",
952 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200953 r8NoManifest.outputs.files[0],
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200954 testJar.outputs.files[0]])
955 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100956}
957
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100958task R8LibApiOnly {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200959 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], r8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100960 outputs.file r8LibPath
961}
962
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100963task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100964 dependsOn r8LibCreateTask(
965 "Main",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200966 ["src/main/keep.txt",
967 "src/main/keep-applymapping.txt",
968 generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200969 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100970 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200971 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100972 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100973}
974
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100975task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100976 dependsOn r8LibCreateTask(
977 "NoDeps",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200978 ["src/main/keep.txt", "src/main/keep-applymapping.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200979 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100980 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200981 "--release",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200982 repackageDeps.outputs.files
983 ).dependsOn(repackageDeps)
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100984 outputs.file r8LibExludeDepsPath
985}
986
Mads Ager418d1ca2017-05-22 09:35:49 +0200987task sourceJar(type: Jar, dependsOn: classes) {
988 classifier = 'src'
989 from sourceSets.main.allSource
990}
991
992task jctfCommonJar(type: Jar) {
993 from sourceSets.jctfCommon.output
994 baseName 'jctfCommon'
995}
996
997artifacts {
998 archives sourceJar
999}
1000
1001task createArtTests(type: Exec) {
1002 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001003 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001004 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001005 outputs.dir outputDir
1006 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +02001007 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001008 workingDir = projectDir
1009}
1010
1011task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001012 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +02001013 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +02001014 inputs.file script
1015 outputs.dir outputDir
1016 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +02001017 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +02001018 workingDir = projectDir
1019}
1020
1021compileTestJava {
1022 dependsOn createArtTests
1023 dependsOn createJctfTests
1024}
1025
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001026task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1027 from sourceSets.cfSegments.output
1028 baseName 'cf_segments'
1029 destinationDir file('build/libs')
1030}
1031
Ian Zernyee23a172018-01-03 09:08:48 +01001032task buildD8ApiUsageSample(type: Jar) {
1033 from sourceSets.apiUsageSample.output
1034 baseName 'd8_api_usage_sample'
1035 destinationDir file('tests')
1036}
1037
Ian Zerny923a0c12018-01-03 10:59:18 +01001038task buildR8ApiUsageSample(type: Jar) {
1039 from sourceSets.apiUsageSample.output
1040 baseName 'r8_api_usage_sample'
1041 destinationDir file('tests')
1042}
1043
Yohann Roussel548ae942018-01-05 11:13:28 +01001044task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001045 dependsOn buildD8ApiUsageSample
1046 dependsOn buildR8ApiUsageSample
1047}
1048
Mads Ager418d1ca2017-05-22 09:35:49 +02001049task buildDebugInfoExamplesDex {
1050 def examplesDir = file("src/test/java")
1051 def hostJar = "debuginfo_examples.jar"
1052 def hostDexJar = "debuginfo_examples_dex.jar"
1053 task "compile_debuginfo_examples"(type: JavaCompile) {
1054 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1055 destinationDir = file("build/test/debuginfo_examples/classes")
1056 classpath = sourceSets.main.compileClasspath
1057 sourceCompatibility = JavaVersion.VERSION_1_7
1058 targetCompatibility = JavaVersion.VERSION_1_7
1059 options.compilerArgs += ["-Xlint:-options"]
1060 }
1061 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1062 archiveName = hostJar
1063 destinationDir = file("build/test/")
1064 from "build/test/debuginfo_examples/classes"
1065 include "**/*.class"
1066 }
1067 task "dex_debuginfo_examples"(type: Exec,
1068 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001069 if (OperatingSystem.current().isWindows()) {
1070 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001071 } else if (OperatingSystem.current().isMacOsX()) {
1072 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001073 } else {
1074 executable file("tools/linux/dx/bin/dx");
1075 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001076 args "--dex"
1077 args "--output=build/test/${hostDexJar}"
1078 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001079 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001080 outputs.file file("build/test/${hostDexJar}")
1081 }
1082 dependsOn dex_debuginfo_examples
1083}
1084
1085task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001086 def resourcesDir = file("src/test/debugTestResources")
1087 def hostJar = "debug_test_resources.jar"
1088 task "compile_debugTestResources"(type: JavaCompile) {
1089 source = fileTree(dir: resourcesDir, include: '**/*.java')
1090 destinationDir = file("build/test/debugTestResources/classes")
1091 classpath = sourceSets.main.compileClasspath
1092 sourceCompatibility = JavaVersion.VERSION_1_7
1093 targetCompatibility = JavaVersion.VERSION_1_7
1094 options.compilerArgs += ["-g", "-Xlint:-options"]
1095 }
1096 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1097 archiveName = hostJar
1098 destinationDir = file("build/test/")
1099 from "build/test/debugTestResources/classes"
1100 include "**/*.class"
1101 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001102 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1103 def java8HostJar = "debug_test_resources_java8.jar"
1104 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1105 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1106 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1107 classpath = sourceSets.main.compileClasspath
1108 sourceCompatibility = JavaVersion.VERSION_1_8
1109 targetCompatibility = JavaVersion.VERSION_1_8
1110 options.compilerArgs += ["-g", "-Xlint:-options"]
1111 }
1112 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1113 archiveName = java8HostJar
1114 destinationDir = file("build/test/")
1115 from "build/test/debugTestResourcesJava8/classes"
1116 include "**/*.class"
1117 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001118 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001119 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1120 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1121 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1122 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001123 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001124 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001125 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001126 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001127 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001128}
1129
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001130// Examples used by tests, where Android specific APIs are used.
1131task buildExampleAndroidApi(type: JavaCompile) {
1132 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1133 destinationDir = file("build/test/examplesAndroidApi/classes")
1134 classpath = files("third_party/android_jar/lib-v26/android.jar")
1135 sourceCompatibility = JavaVersion.VERSION_1_8
1136 targetCompatibility = JavaVersion.VERSION_1_8
1137}
1138
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001139task buildExampleKotlinJars {
1140 def kotlinSrcDir = file("src/test/examplesKotlin")
1141 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001142 def name = dir.getName();
1143 dependsOn "compile_example_kotlin_${name}"
1144 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1145 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1146 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001147 }
1148 }
1149}
1150
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001151task buildProtoGeneratedSources {
1152 def examplesProtoDir = file("src/test/examplesProto")
1153 examplesProtoDir.eachDir { dir ->
1154 def name = dir.getName()
1155 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1156 source = {
1157 file('third_party/proto').listFiles()
1158 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1159 .collect { zipTree(it) }
1160 }
1161 destinationDir = file("build/generated/test/proto/${name}_classes")
1162 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1163 sourceCompatibility = JavaVersion.VERSION_1_8
1164 targetCompatibility = JavaVersion.VERSION_1_8
1165 }
1166 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1167 archiveName = "${name}.jar"
1168 destinationDir = file("build/generated/test/proto")
1169 from "build/generated/test/proto/${name}_classes"
1170 include "/**/*.class"
1171 }
1172 dependsOn "jar_proto_generated_source_${name}"
1173 }
1174}
1175
1176task buildExamplesProto {
1177 def examplesProtoDir = file("src/test/examplesProto")
1178 def examplesProtoOutputDir = file("build/test/examplesProto");
1179 dependsOn buildProtoGeneratedSources
1180 task "compile_examples_proto"(type: JavaCompile) {
1181 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1182 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001183 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1184 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001185 sourceCompatibility = JavaVersion.VERSION_1_8
1186 targetCompatibility = JavaVersion.VERSION_1_8
1187 }
1188 examplesProtoDir.eachDir { dir ->
1189 def name = dir.getName()
1190 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1191 archiveName = "${name}.jar"
1192 destinationDir = examplesProtoOutputDir
1193 from "build/test/examplesProto/classes"
1194 include name + "/**/*.class"
1195 }
1196 dependsOn "jar_examples_proto_${name}"
1197 }
1198}
1199
Lars Bakc91e87e2017-08-18 08:53:10 +02001200// Proto lite generated code yields warnings when compiling with javac.
1201// We change the options passed to javac to ignore it.
1202compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1203
Søren Gjesse7320ce52018-05-07 15:45:22 +02001204
Mads Ager418d1ca2017-05-22 09:35:49 +02001205task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001206 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001207 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001208 def proguardScript
1209 if (OperatingSystem.current().isWindows()) {
1210 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1211 } else {
1212 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1213 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001214 task extractExamplesRuntime(type: Sync) {
1215 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001216 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001217 include "**/*.class"
1218 includeEmptyDirs false
1219 into "$buildDir/runtime/examples/"
1220 }
1221
Søren Gjesse7320ce52018-05-07 15:45:22 +02001222 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1223 from examplesDir
1224 exclude "**/*.java"
1225 exclude "**/keep-rules*.txt"
1226 into file("build/test/examples/classes")
1227 }
1228
1229 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001230 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001231 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001232 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001233 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001234 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001235 sourceCompatibility = JavaVersion.VERSION_1_7
1236 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001237 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1238 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001239 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1240 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001241 include "**/*.java"
1242 destinationDir = file("build/test/examples/classes_debuginfo_all")
1243 classpath = sourceSets.examples.compileClasspath
1244 sourceCompatibility = JavaVersion.VERSION_1_7
1245 targetCompatibility = JavaVersion.VERSION_1_7
1246 options.compilerArgs = ["-g", "-Xlint:none"]
1247 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001248 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1249 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001250 include "**/*.java"
1251 destinationDir = file("build/test/examples/classes_debuginfo_none")
1252 classpath = sourceSets.examples.compileClasspath
1253 sourceCompatibility = JavaVersion.VERSION_1_7
1254 targetCompatibility = JavaVersion.VERSION_1_7
1255 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001256 }
1257 examplesDir.eachDir { dir ->
1258 def name = dir.getName();
1259 def exampleOutputDir = file("build/test/examples");
1260 def jarName = "${name}.jar"
1261 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001262 dependsOn "jar_example_${name}_debuginfo_all"
1263 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001264 dependsOn "extractExamplesRuntime"
1265 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001266 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1267 def proguardConfigPath = "${dir}/proguard.cfg"
1268 if (new File(proguardConfigPath).exists()) {
1269 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1270 archiveName = "${name}_pre_proguard.jar"
1271 destinationDir = exampleOutputDir
1272 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001273 include name + "/**/*.class"
1274 with runtimeDependencies
1275 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001276 }
1277 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1278 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1279 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1280 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001281 inputs.files files(
1282 tasks.getByPath("pre_proguard_example_${name}"),
1283 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001284 // Enable these to get stdout and stderr redirected to files...
1285 // standardOutput = new FileOutputStream('proguard.stdout')
1286 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001287 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001288 " -outjars ${proguardJarPath}" +
1289 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001290 " -printmapping ${proguardMapPath}"
1291 if (OperatingSystem.current().isWindows()) {
1292 executable "${proguardScript}"
1293 args "${proguardArguments}"
1294 } else {
1295 executable "bash"
1296 args "-c", "${proguardScript} '${proguardArguments}'"
1297 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001298 outputs.file proguardJarPath
1299 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001300 // TODO: Consider performing distinct proguard compilations.
1301 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1302 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001303 into "${exampleOutputDir}"
1304 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001305 }
1306 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1307 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001308 into "${exampleOutputDir}"
1309 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001310 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001311 } else {
1312 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001313 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001314 destinationDir = exampleOutputDir
1315 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001316 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001317 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001318 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001319 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001320 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1321 archiveName = "${name}_debuginfo_all.jar"
1322 destinationDir = exampleOutputDir
1323 from "build/test/examples/classes_debuginfo_all"
1324 include name + "/**/*.class"
1325 with runtimeDependencies
1326 includeEmptyDirs false
1327 }
1328 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1329 archiveName = "${name}_debuginfo_none.jar"
1330 destinationDir = exampleOutputDir
1331 from "build/test/examples/classes_debuginfo_none"
1332 include name + "/**/*.class"
1333 with runtimeDependencies
1334 includeEmptyDirs false
1335 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001336 }
1337 }
1338}
1339
1340task buildExampleAndroidNJars {
1341 dependsOn downloadDeps
1342 def examplesDir = file("src/test/examplesAndroidN")
1343 task "compile_examplesAndroidN"(type: JavaCompile) {
1344 source = fileTree(dir: examplesDir, include: '**/*.java')
1345 destinationDir = file("build/test/examplesAndroidN/classes")
1346 classpath = sourceSets.main.compileClasspath
1347 sourceCompatibility = JavaVersion.VERSION_1_8
1348 targetCompatibility = JavaVersion.VERSION_1_8
1349 options.compilerArgs += ["-Xlint:-options"]
1350 }
1351 examplesDir.eachDir { dir ->
1352 def name = dir.getName();
1353 def exampleOutputDir = file("build/test/examplesAndroidN");
1354 def jarName = "${name}.jar"
1355 dependsOn "jar_examplesAndroidN_${name}"
1356 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1357 archiveName = jarName
1358 destinationDir = exampleOutputDir
1359 from "build/test/examplesAndroidN/classes"
1360 include "**/" + name + "/**/*.class"
1361 }
1362 }
1363}
1364
1365
1366task buildExampleAndroidOJars {
1367 dependsOn downloadDeps
1368 def examplesDir = file("src/test/examplesAndroidO")
1369 // NOTE: we want to enable a scenario when test needs to reference some
1370 // classes generated by legacy (1.6) Java compiler to test some specific
1371 // behaviour. To do so we compile all the java files located in sub-directory
1372 // called 'legacy' with Java 1.6, then compile the rest of the files with
1373 // Java 1.8 and a reference to previously generated 1.6 classes.
1374
1375 // Compiling all classes in dirs 'legacy' with old Java version.
1376 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1377 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1378 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1379 classpath = sourceSets.main.compileClasspath
1380 sourceCompatibility = JavaVersion.VERSION_1_6
1381 targetCompatibility = JavaVersion.VERSION_1_6
1382 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1383 }
1384 // Compiling the rest of the files as Java 1.8 code.
1385 task "compile_examplesAndroidO"(type: JavaCompile) {
1386 dependsOn "compile_examplesAndroidO_Legacy"
1387 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1388 destinationDir = file("build/test/examplesAndroidO/classes")
1389 classpath = sourceSets.main.compileClasspath
1390 classpath += files("build/test/examplesAndroidOLegacy/classes")
1391 sourceCompatibility = JavaVersion.VERSION_1_8
1392 targetCompatibility = JavaVersion.VERSION_1_8
1393 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1394 }
1395 examplesDir.eachDir { dir ->
1396 def name = dir.getName();
1397 def destinationDir = file("build/test/examplesAndroidO/classes");
1398 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1399 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1400 dependsOn: "compile_examplesAndroidO") {
1401 main = name + ".TestGenerator"
1402 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1403 args destinationDir
1404 }
1405 } else {
1406 task "generate_examplesAndroidO_${name}" () {}
1407 }
1408 }
1409 examplesDir.eachDir { dir ->
1410 def name = dir.getName();
1411 def exampleOutputDir = file("build/test/examplesAndroidO");
1412 def jarName = "${name}.jar"
1413 dependsOn "jar_examplesAndroidO_${name}"
1414 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1415 "generate_examplesAndroidO_${name}"]) {
1416 archiveName = jarName
1417 destinationDir = exampleOutputDir
1418 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1419 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1420 include "**/" + name + "/**/*.class"
1421 // Do not include generator into the test runtime jar, it is not useful.
1422 // Otherwise, shrinking will need ASM jars.
1423 exclude "**/TestGenerator*"
1424 }
1425 }
1426}
1427
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001428task buildExampleAndroidPJars {
1429 dependsOn downloadDeps
1430 def examplesDir = file("src/test/examplesAndroidP")
1431
1432 task "compile_examplesAndroidP"(type: JavaCompile) {
1433 source = fileTree(dir: examplesDir, include: '**/*.java')
1434 destinationDir = file("build/test/examplesAndroidP/classes")
1435 classpath = sourceSets.main.compileClasspath
1436 sourceCompatibility = JavaVersion.VERSION_1_8
1437 targetCompatibility = JavaVersion.VERSION_1_8
1438 options.compilerArgs += ["-Xlint:-options"]
1439 }
1440 examplesDir.eachDir { dir ->
1441 def name = dir.getName();
1442 def destinationDir = file("build/test/examplesAndroidP/classes");
1443 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1444 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1445 dependsOn: "compile_examplesAndroidP") {
1446 main = name + ".TestGenerator"
1447 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1448 args destinationDir
1449 }
1450 } else {
1451 task "generate_examplesAndroidP_${name}" () {}
1452 }
1453 }
1454 examplesDir.eachDir { dir ->
1455 def name = dir.getName();
1456 def exampleOutputDir = file("build/test/examplesAndroidP");
1457 def jarName = "${name}.jar"
1458 dependsOn "jar_examplesAndroidP_${name}"
1459 task "jar_examplesAndroidP_${name}"(type: Jar,
1460 dependsOn: ["compile_examplesAndroidP",
1461 "generate_examplesAndroidP_${name}"]) {
1462 archiveName = jarName
1463 destinationDir = exampleOutputDir
1464 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1465 include "**/" + name + "/**/*.class"
1466 // Do not include generator into the test runtime jar, it is not useful.
1467 // Otherwise, shrinking will need ASM jars.
1468 exclude "**/TestGenerator*"
1469 }
1470 }
1471}
1472
Mikaël Peltier61633d42017-10-13 16:51:06 +02001473task buildExampleJava9Jars {
1474 def examplesDir = file("src/test/examplesJava9")
1475 examplesDir.eachDir { dir ->
1476 def name = dir.getName();
1477 def exampleOutputDir = file("build/test/examplesJava9");
1478 def jarName = "${name}.jar"
1479 dependsOn "jar_examplesJava9_${name}"
1480 task "jar_examplesJava9_${name}"(type: Jar) {
1481 archiveName = jarName
1482 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001483 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001484 include "**/" + name + "/**/*.class"
1485 }
1486 }
1487}
1488
Jake Wharton2000b2f2019-12-11 20:37:49 -05001489task buildExampleJava10Jars {
1490 def examplesDir = file("src/test/examplesJava10")
1491 examplesDir.eachDir { dir ->
1492 def name = dir.getName();
1493 def exampleOutputDir = file("build/test/examplesJava10");
1494 def jarName = "${name}.jar"
1495 dependsOn "jar_examplesJava10_${name}"
1496 task "jar_examplesJava10_${name}"(type: Jar) {
1497 archiveName = jarName
1498 destinationDir = exampleOutputDir
1499 from sourceSets.examplesJava10.output
1500 include "**/" + name + "/**/*.class"
1501 }
1502 }
1503}
1504
clementberad7ab1dd2019-04-16 16:05:00 +02001505task buildExampleJava11Jars {
1506 def examplesDir = file("src/test/examplesJava11")
1507 examplesDir.eachDir { dir ->
1508 def name = dir.getName();
1509 def exampleOutputDir = file("build/test/examplesJava11");
1510 def jarName = "${name}.jar"
1511 dependsOn "jar_examplesJava11_${name}"
1512 task "jar_examplesJava11_${name}"(type: Jar) {
1513 archiveName = jarName
1514 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001515 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001516 include "**/" + name + "/**/*.class"
1517 }
1518 }
1519}
1520
clementberaa92e3cd2019-07-12 14:13:22 +02001521task provideArtFrameworksDependencies {
1522 cloudDependencies.tools.forEach({ art ->
1523 if (art.contains("art")) {
1524 def taskName = art.replace('/','_')
1525 dependsOn "patch_${taskName}"
1526 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1527 from "tools/${art}/framework"
1528 include "**.jar"
1529 into file("tools/${art}/out/host/linux-x86/framework")
1530 }
1531 }
1532 })
1533}
1534
clementbera4f9c2a92019-07-09 08:50:37 +02001535task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1536 from sourceSets.jdk11TimeTests.compileClasspath
1537 include "**/**.jar"
1538 into file("build/test/jdk11Tests")
1539}
1540
1541task buildJdk11TimeTestsJar {
1542 def exampleOutputDir = file("build/test/jdk11Tests");
1543 def jarName = "jdk11TimeTests.jar"
1544 dependsOn "jar_jdk11TimeTests"
1545 dependsOn provideJdk11TestsDependencies
1546 task "jar_jdk11TimeTests"(type: Jar) {
1547 archiveName = jarName
1548 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001549 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001550 include "**.class"
1551 from sourceSets.jdk11TimeTests.output
1552 include "**.class"
1553 include "**/**.class"
1554 }
1555}
1556
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001557task buildExamplesKotlin {
1558 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1559 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1560 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1561 } else if (!OperatingSystem.current().isLinux()) {
1562 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1563 "on your platform. It is fully supported on Linux and partially supported on " +
1564 "Mac OS and Windows")
1565 return;
1566 }
1567 def examplesDir = file("src/test/examplesKotlin")
1568 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001569 def name = dir.getName();
1570 dependsOn "dex_example_kotlin_${name}"
1571 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1572 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001573 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001574 dependsOn: "compile_example_kotlin_${name}") {
1575 doFirst {
1576 if (!dexPath.exists()) {
1577 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001578 }
1579 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001580 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1581 destination = dexPath
1582 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001583 }
1584 }
1585}
1586
Sebastien Hertzd3313772018-01-16 14:12:37 +01001587task buildKotlinR8TestResources {
1588 def examplesDir = file("src/test/kotlinR8TestResources")
1589 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001590 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1591 def name = dir.getName()
1592 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001593 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1594 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001595 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001596 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001597 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1598 source = fileTree(dir: file("${examplesDir}/${name}"),
1599 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001600 destination = file(outputFile)
1601 targetVersion = kotlinTargetVersion
1602 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001603 task "${taskName}Java"(type: JavaCompile) {
1604 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1605 destinationDir = file(javaOutput)
1606 classpath = sourceSets.main.compileClasspath
1607 sourceCompatibility = JavaVersion.VERSION_1_6
1608 targetCompatibility = JavaVersion.VERSION_1_6
1609 options.compilerArgs += ["-g", "-Xlint:-options"]
1610 }
1611 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1612 archiveName = javaOutputJarName
1613 destinationDir = file(javaOutputJarDir)
1614 from javaOutput
1615 include "**/*.class"
1616 }
1617 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001618 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001619 }
1620}
1621
Mads Ager418d1ca2017-05-22 09:35:49 +02001622task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001623 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1624 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1625 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001626 } else if (!OperatingSystem.current().isLinux()) {
1627 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001628 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001629 return;
1630 }
1631 dependsOn buildDebugTestResourcesJars
1632 dependsOn buildExampleJars
1633 dependsOn buildExampleAndroidNJars
1634 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001635 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001636 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001637 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001638 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001639 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001640 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001641 def noDexTests = [
1642 "multidex",
1643 "multidex002",
1644 "multidex004",
1645 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001646 examplesDir.eachDir { dir ->
1647 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001648 if (!(name in noDexTests)) {
1649 dependsOn "dex_example_${name}"
1650 def exampleOutputDir = file("build/test/examples/" + name);
1651 def dexPath = file("${exampleOutputDir}")
1652 def debug = (name == "throwing")
1653 if (!dexPath.exists()) {
1654 dexPath.mkdirs()
1655 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001656 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001657 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1658 destination = dexPath
1659 debug = debug
1660 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001661 }
1662 }
1663}
1664
1665task buildSmali {
1666 def smaliDir = file("src/test/smali")
1667 smaliDir.eachDirRecurse() { dir ->
1668 def name = dir.getName();
1669 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1670 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1671 smaliOutputDir.mkdirs()
1672 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001673 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001674 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1675 def javaFiles = fileTree(dir: dir, include: '*.java')
1676 def destDir = smaliOutputDir;
1677 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1678 def intermediateFileName = "${name}-intermediate.dex";
1679 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1680 if (javaFiles.empty) {
1681 if (!smaliFiles.empty) {
1682 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001683 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001684 source = smaliFiles
1685 destination = destFile
1686 }
1687 }
1688 } else {
1689 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001690 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001691 source = smaliFiles
1692 destination = intermediateFile
1693 }
1694 task "${taskName}_java"(type: JavaCompile) {
1695 source = javaFiles
1696 destinationDir destDir
1697 classpath = sourceSets.main.compileClasspath
1698 sourceCompatibility = JavaVersion.VERSION_1_7
1699 targetCompatibility = JavaVersion.VERSION_1_7
1700 options.compilerArgs += ["-Xlint:-options"]
1701 }
1702 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1703 archiveName = "Test.jar"
1704 destinationDir = destDir
1705 from fileTree(dir: destDir, include: 'Test.class')
1706 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001707 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001708 source = fileTree(dir: destDir, include: 'Test.jar')
1709 destination = destDir
1710 }
1711 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001712 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001713 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1714 destination = destFile
1715 }
1716 }
1717 }
1718}
1719
1720tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001721 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001722 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001723 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001724 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001725 if (userDefinedCoresPerFork) {
1726 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1727 } else {
1728 // On normal work machines this seems to give the best test execution time (without freezing)
1729 maxParallelForks = processors.intdiv(3) ?: 1
1730 }
Rico Windc56f21c2019-03-12 07:29:57 +01001731 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001732
Mads Ager418d1ca2017-05-22 09:35:49 +02001733 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001734 if (project.hasProperty('disable_assertions')) {
1735 enableAssertions = false
1736 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001737 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001738 if (project.hasProperty('test_xmx')) {
1739 maxHeapSize = project.property('test_xmx')
1740 } else {
1741 maxHeapSize = "4G"
1742 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001743}
1744
1745task buildPreNJdwpTestsJar(type: Jar) {
1746 baseName = 'jdwp-tests-preN'
1747 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1748 // Exclude the classes containing java8
1749 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1750 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1751 includeEmptyDirs = false
1752}
1753
Ian Zerny74143162017-11-24 13:46:35 +01001754task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1755 def inFile = buildPreNJdwpTestsJar.archivePath
1756 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001757 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001758 outputs.file outFile
1759 if (OperatingSystem.current().isWindows()) {
1760 executable file("tools/windows/dx/bin/dx.bat")
1761 } else if (OperatingSystem.current().isMacOsX()) {
1762 executable file("tools/mac/dx/bin/dx");
1763 } else {
1764 executable file("tools/linux/dx/bin/dx");
1765 }
1766 args "--dex"
1767 args "--output=${outFile}"
1768 args inFile
1769}
1770
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001771task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1772 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001773}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001774
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001775task generateR8TestKeepRules {
1776 def path = "build/generated/r8tests-keep.txt"
1777 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001778 dependsOn R8Lib
1779 doLast {
1780 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001781-dontshrink
1782-dontoptimize
1783-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001784-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001785"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001786 }
1787}
1788
1789task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001790 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1791 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001792 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001793 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001794 dependsOn generateR8TestKeepRules
1795 dependsOn testJar
1796 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1797 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1798 return pkg.toString().endsWith(".jar")
1799 } + ["${buildDir}/classes/java/test"]
1800 inputs.files testJar.outputs.files +
1801 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001802 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001803 commandLine = r8CfCommandLine(
1804 testJar.outputs.files[0],
1805 outputPath,
1806 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001807 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1808 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001809 workingDir = projectDir
1810 outputs.file outputPath
1811}
1812
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001813task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001814 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001815 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001816 dependsOn R8Lib
1817 delete r8LibTestPath
1818 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1819 def examplesDir = file("build/test")
1820 examplesDir.eachDir { dir ->
1821 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001822 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001823 from ("${buildDir}/runtime/examples")
1824 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001825 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001826}
1827
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001828def printStackTrace(TestResult result) {
1829 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1830 def out = new StringBuffer()
1831 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001832 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001833 def header = "RETRACED STACKTRACE";
1834 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1835 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1836 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1837 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001838 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001839 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001840 out.append("--------------------------------------\n")
1841 Process process = command.execute()
1842 def processIn = new PrintStream(process.getOut())
1843 process.consumeProcessOutput(out, err)
1844 result.exception.printStackTrace(processIn)
1845 processIn.flush()
1846 processIn.close()
Morten Krogh-Jespersenfe0d7e12020-01-31 08:50:17 +01001847 if (process.waitFor() != 0) {
1848 out.append("ERROR DURING RETRACING\n")
1849 out.append(err.toString())
1850 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001851 out.append("\n\n--------------------------------------\n")
1852 out.append("OBFUSCATED STACKTRACE\n")
1853 out.append("--------------------------------------\n")
1854 result.exceptions.add(0, new Exception(out.toString()))
1855 } else {
1856 result.exception.printStackTrace()
1857 }
1858}
1859
Mads Ager418d1ca2017-05-22 09:35:49 +02001860test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001861 if (project.hasProperty('generate_golden_files_to')) {
1862 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1863 assert project.hasProperty('HEAD_sha1')
1864 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1865 }
1866
1867 if (project.hasProperty('use_golden_files_in')) {
1868 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1869 assert project.hasProperty('HEAD_sha1')
1870 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1871 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001872
Ian Zerny64312222019-12-05 15:12:24 +01001873 dependsOn buildLibraryDesugarConversions
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001874 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001875 // R8.jar is required for running bootstrap tests.
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001876 dependsOn r8
Mads Ager418d1ca2017-05-22 09:35:49 +02001877 testLogging.exceptionFormat = 'full'
1878 if (project.hasProperty('print_test_stdout')) {
1879 testLogging.showStandardStreams = true
1880 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001881 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001882 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001883 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001884 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001885
Ian Zerny324d7612019-03-20 10:52:28 +01001886 // Forward runtime configurations for test parameters.
1887 if (project.hasProperty('runtimes')) {
1888 println "NOTE: Running with runtimes: " + project.property('runtimes')
1889 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001890 }
1891
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001892 if (project.hasProperty('slow_tests')) {
1893 systemProperty 'slow_tests', project.property('slow_tests')
1894 }
1895
Mads Ager418d1ca2017-05-22 09:35:49 +02001896 if (project.hasProperty('one_line_per_test')) {
1897 beforeTest { desc ->
1898 println "Start executing test ${desc.name} [${desc.className}]"
1899 }
1900 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001901 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001902 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001903 }
Rico Windda6836e2018-12-07 12:32:03 +01001904 if (project.hasProperty('update_test_timestamp')) {
1905 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1906 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001907 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1908 }
Rico Windf88b6be2018-12-11 15:14:05 +01001909 } else {
1910 afterTest { desc, result ->
1911 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001912 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001913 }
1914 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001915 }
1916 if (project.hasProperty('no_internal')) {
1917 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001918 } else {
1919 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001920 }
1921 if (project.hasProperty('only_internal')) {
1922 include "com/android/tools/r8/internal/**"
1923 }
Rico Wind4e218292019-03-07 12:44:49 +01001924
Mads Ager418d1ca2017-05-22 09:35:49 +02001925 if (project.hasProperty('tool')) {
1926 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001927 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001928 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001929 if (project.hasProperty('only_jctf')) {
1930 include "com/android/tools/r8/jctf/d8/**"
1931 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001932 // Don't run anything, deprecated
1933 println "Running with deprecated tool d8, not running any tests"
1934 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001935 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001936 } else {
1937 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001938 assert(project.hasProperty('only_jctf'))
1939 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001940 }
1941 }
1942 if (!project.hasProperty('all_tests')) {
1943 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001944 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001945 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001946 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001947 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001948 if (project.hasProperty('shard_count') ) {
1949 assert project.hasProperty('shard_number')
1950 int shard_count = project.getProperty('shard_count') as Integer
1951 int shard_number = project.getProperty('shard_number') as Integer
1952 assert shard_count < 65536
1953 assert shard_number < shard_count
1954 exclude {
1955 entry ->
1956 // Don't leave out directories. Leaving out a directory means all entries below.
1957 if (entry.file.isDirectory()) {
1958 return false
1959 }
1960 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1961 int hash = Integer.parseInt(first4, 16)
1962 return hash % shard_count != shard_number
1963 }
1964 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001965 if (project.hasProperty('jctf_compile_only')) {
1966 println "JCTF: compiling only"
1967 systemProperty 'jctf_compile_only', '1'
1968 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001969 if (project.hasProperty('test_dir')) {
1970 systemProperty 'test_dir', project.property('test_dir')
1971 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001972 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001973 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001974 // R8lib should be used instead of the main output and all the tests in
1975 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001976 classpath = sourceSets.test.runtimeClasspath.filter {
1977 !it.getAbsolutePath().contains("/build/")
1978 }
1979 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001980 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001981 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001982 if (OperatingSystem.current().isLinux()
1983 || OperatingSystem.current().isMacOsX()
1984 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001985 if (OperatingSystem.current().isMacOsX()) {
1986 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1987 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1988 "See tools/docker/README.md for details.")
1989 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001990 if (OperatingSystem.current().isWindows()) {
1991 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1992 "Art only runs on Linux and tests requiring Art will be skipped")
1993 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001994 dependsOn downloadDeps
1995 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001996 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001997 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001998 dependsOn buildSmali
1999 dependsOn jctfCommonJar
2000 dependsOn jctfTestsClasses
2001 dependsOn buildDebugInfoExamplesDex
2002 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002003 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02002004 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02002005 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002006 } else {
2007 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002008 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002009 }
2010}
2011
2012// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2013//
2014// To build and upload a new set of the Art tests for use with R8 follow these steps:
2015//
2016// First of all an Android checkout is required. Currently it must be located
2017// in $HOME/android/master.
2018//
2019// TODO(ricow): simplify this
2020//
2021// Before: update the checked in art, see scripts/update-host-art.sh
2022//
2023// 1. Get an android checkout in $HOME/android/master and apply the patch from
2024// https://android-review.googlesource.com/#/c/294187/
2025//
2026// 2. run the following commands in the Android checkout directory:
2027//
2028// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002029// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2030// m desugar
2031// m -j30 test-art-host
2032// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2033//
2034// Without running the test.py command the classes.jar file used by desugar in
2035// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2036// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002037//
2038// 3. In the R8 project root directory, make sure we have a clean state before starting:
2039// tools/gradle.py downloadDeps
2040// tools/gradle.py clean
2041// rm -rf tests/art
2042//
2043// 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 +02002044// Make sure you have smali on your path, please use the build binary in the
2045// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2046// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2047// 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 +02002048// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2049// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002050//
Søren Gjesse34b77732017-07-07 13:56:21 +02002051// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002052//
2053// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2054// skippedTests with an explanation. Rerun from step 3.
2055//
2056// 5. Run the tests:
2057// tools/gradle.py clean
2058// tools/test.py
2059//
Søren Gjesse34b77732017-07-07 13:56:21 +02002060// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2061// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2062// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002063//
Søren Gjesse34b77732017-07-07 13:56:21 +02002064// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002065// cd tests
2066// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002067//
2068// 7. Update the manifest file describing the Android repo used:
2069// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002070
Mads Ager418d1ca2017-05-22 09:35:49 +02002071def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002072
2073def artTestDir = file("${androidCheckoutDir}/art/test")
2074
2075if (project.hasProperty('android_source')) {
2076 task buildArtTests {
2077 outputs.upToDateWhen { false }
2078 def toBeTriaged = [
2079 "903-hello-tagging",
2080 "904-object-allocation",
2081 "905-object-free",
2082 "906-iterate-heap",
2083 "907-get-loaded-classes",
2084 "908-gc-start-finish",
2085 "954-invoke-polymorphic-verifier",
2086 "955-methodhandles-smali",
2087 "596-monitor-inflation",
2088 ]
2089 def skippedTests = toBeTriaged + [
2090 // This test produces no jar.
2091 "000-nop",
2092 // This does not build, as it tests the error when the application exceeds more
2093 // than 65536 methods
2094 "089-many-methods",
2095 // Requires some jack beta jar
2096 "956-methodhandles",
2097 ]
2098
2099 def skippedTestsDx = [
2100 // Tests with custom build scripts, where javac is not passed the options
2101 // -source 1.7 -target 1.7.
2102 "462-checker-inlining-across-dex-files",
2103 "556-invoke-super",
2104 "569-checker-pattern-replacement",
2105 // These tests use jack even when --build-with-javac-dx is specified.
2106 "004-JniTest",
2107 "048-reflect-v8",
2108 "146-bad-interface",
2109 "563-checker-invoke-super",
2110 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2111 "604-hot-static-interface",
2112 "957-methodhandle-transforms",
2113 "958-methodhandle-emulated-stackframe",
2114 "959-invoke-polymorphic-accessors",
2115 "961-default-iface-resolution-gen",
2116 "962-iface-static",
2117 "963-default-range-smali",
2118 "964-default-iface-init-gen",
2119 "965-default-verify",
2120 "966-default-conflict",
2121 "967-default-ame",
2122 "968-default-partial-compile-gen",
2123 "969-iface-super",
2124 "970-iface-super-resolution-gen",
2125 "971-iface-super",
2126 // These tests does not build with --build-with-javac-dx
2127 "004-NativeAllocations", // Javac error
2128 "031-class-attributes",
2129 "138-duplicate-classes-check",
2130 "157-void-class", // Javac error
2131 "580-checker-string-factory-intrinsics",
2132 "612-jit-dex-cache",
2133 "613-inlining-dex-cache",
2134 "900-hello-plugin", // --experimental agents
2135 "901-hello-ti-agent", // --experimental agents
2136 "902-hello-transformation", // --experimental agents
2137 "909-attach-agent", // --experimental agents
2138 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2139 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2140 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2141 "960-default-smali", // --experimental default-methods
2142 // These tests force the build to use jack
2143 "953-invoke-polymorphic-compiler",
2144 "958-methodhandle-stackframe",
2145 ]
2146
2147 def artTestBuildDir = file("${projectDir}/tests/art")
2148
2149 if (androidCheckoutDir.exists()) {
2150 dependsOn downloadDeps
2151 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002152 artTestDir.eachDir { dir ->
2153 def name = dir.getName();
2154 def markerFile = dir.toPath().resolve("info.txt").toFile();
2155 if (markerFile.exists() && !(name in skippedTests)) {
2156 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002157 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002158 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002159 }
2160 }
2161 }
2162 doFirst {
2163 if (!androidCheckoutDir.exists()) {
2164 throw new InvalidUserDataException(
2165 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002166 }
2167 }
2168 doLast {
2169 copy {
2170 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2171 into file("${artTestBuildDir}/lib64")
2172 include 'lib*.so'
2173 }
2174 copy {
2175 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2176 into file("${artTestBuildDir}/lib64")
2177 include 'libart.so'
2178 include 'libbacktrace.so'
2179 include 'libbase.so'
2180 include 'libc++.so'
2181 include 'libcutils.so'
2182 include 'liblz4.so'
2183 include 'liblzma.so'
2184 include 'libnativebridge.so'
2185 include 'libnativeloader.so'
2186 include 'libsigchain.so'
2187 include 'libunwind.so'
2188 include 'libziparchive.so'
2189 }
2190 copy {
2191 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2192 into file("${artTestBuildDir}/lib")
2193 include 'lib*.so'
2194 }
2195 copy {
2196 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2197 into file("${artTestBuildDir}/lib")
2198 include 'libart.so'
2199 include 'libbacktrace.so'
2200 include 'libbase.so'
2201 include 'libc++.so'
2202 include 'libcutils.so'
2203 include 'liblz4.so'
2204 include 'liblzma.so'
2205 include 'libnativebridge.so'
2206 include 'libnativeloader.so'
2207 include 'libsigchain.so'
2208 include 'libunwind.so'
2209 include 'libziparchive.so'
2210 }
2211 }
2212 }
2213}
2214
Rico Windde2af6c2019-03-26 15:21:08 +01002215def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002216 def artTestDir = file("${androidCheckoutDir}/art/test")
2217 def artRunTestScript = file("${artTestDir}/run-test")
2218 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002219 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002220
Søren Gjesse34b77732017-07-07 13:56:21 +02002221 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002222 def buildTask = "build_art_test_dx_${name}"
2223 def sanitizeTask = "sanitize_art_test_dx_${name}"
2224 def copyCheckTask = "copy_check_art_test_dx_${name}"
2225 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002226
2227 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002228 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002229 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2230 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002231 task "$buildTask"(type: Exec) {
2232 outputs.upToDateWhen { false }
2233 inputs.file buildInputs
2234 executable "${artRunTestScript}"
2235 args "--host"
2236 args "--build-only"
2237 args "--build-with-javac-dx"
2238 args "--output-path", "${testDir}"
2239 args "${name}"
2240 environment DX: "${dxExecutable.absolutePath}"
2241 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2242 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2243 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002244 }
2245 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2246 outputs.upToDateWhen { false }
2247 executable "/bin/bash"
2248 args "-c"
2249 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2250 " ${testDir}/classes-ex ${testDir}/check"
2251 }
2252
2253 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002254 // Directory that contains smali files is either smali, or smali/art
2255 def smali_dir = file("${dir}/smali/art")
2256 if (smali_dir.exists()) {
2257 workingDir "${testDir}/smali/art"
2258 } else {
2259 workingDir "${testDir}/smali"
2260 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002261 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002262 // This is the command line options for smali prior to 2.2.1, where smali got a new
2263 // command line interface.
2264 args "-c", "smali a *.smali"
2265 // This is the command line options for smali 2.2.1 and later.
2266 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002267 }
2268
2269 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2270 def smali_dir = file("${dir}/smali")
2271 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002272 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002273 dependsOn smaliToDexTask
2274 }
2275 from("${artTestDir}/${name}") {
2276 include 'check'
2277 }
2278 into testDir
2279 }
2280
2281 return copyCheckTask
2282}
2283
2284task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002285 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002286 classpath = sourceSets.main.compileClasspath
2287 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002288 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002289 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002290 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002291 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002292 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002293 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002294 include '**/com/android/tools/r8/CompilationMode.java'
2295 include '**/com/android/tools/r8/D8.java'
2296 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002297 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2298 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002299 include '**/com/android/tools/r8/Diagnostic.java'
2300 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002301 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2302 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002303 include '**/com/android/tools/r8/ProgramConsumer.java'
2304 include '**/com/android/tools/r8/ProgramResource.java'
2305 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002306 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002307 include '**/com/android/tools/r8/ResourceException.java'
2308 include '**/com/android/tools/r8/StringConsumer.java'
2309 include '**/com/android/tools/r8/StringResource.java'
2310 include '**/com/android/tools/r8/Version.java'
2311 include '**/com/android/tools/r8/origin/*.java'
2312}
2313
2314task javadocR8(type: Javadoc) {
2315 title "R8 API"
2316 classpath = sourceSets.main.compileClasspath
2317 source = sourceSets.main.allJava
2318 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2319 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2320 include '**/com/android/tools/r8/BaseCommand.java'
2321 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2322 include '**/com/android/tools/r8/ClassFileConsumer.java'
2323 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2324 include '**/com/android/tools/r8/CompilationFailedException.java'
2325 include '**/com/android/tools/r8/CompilationMode.java'
2326 include '**/com/android/tools/r8/R8.java'
2327 include '**/com/android/tools/r8/R8Command.java'
2328 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2329 include '**/com/android/tools/r8/Diagnostic.java'
2330 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002331 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2332 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002333 include '**/com/android/tools/r8/ProgramConsumer.java'
2334 include '**/com/android/tools/r8/ProgramResource.java'
2335 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2336 include '**/com/android/tools/r8/Resource.java'
2337 include '**/com/android/tools/r8/ResourceException.java'
2338 include '**/com/android/tools/r8/StringConsumer.java'
2339 include '**/com/android/tools/r8/StringResource.java'
2340 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002341 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002342}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002343
2344task copyMavenDeps(type: Copy) {
2345 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002346 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002347 from configurations.testCompile into "$buildDir/deps"
2348}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002349
Rico Wind23a05112019-03-27 08:00:44 +01002350task printMavenDeps {
2351 // Only actually print to stdout when we are updating.
2352 if (project.hasProperty('updatemavendeps')) {
2353 for (Configuration config : configurations) {
2354 if (!config.isCanBeResolved()) {
2355 continue
2356 }
2357 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2358 it.selected.id
2359 }
2360 def result = dependencies.createArtifactResolutionQuery()
2361 .forComponents(componentIds)
2362 .withArtifacts(MavenModule, MavenPomArtifact)
2363 .execute()
2364 for (component in result.resolvedComponents) {
2365 component.getArtifacts(MavenPomArtifact).each {
2366 println "POM: ${it.file} ${component.id}"
2367 }
2368 }
2369 config.each {
2370 println "JAR: ${it}"
2371 }
2372 }
2373 }
2374}
Ian Zerny9713c032020-01-23 11:41:58 +01002375
2376allprojects {
2377 tasks.withType(Exec) {
2378 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002379 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002380 }
2381 }
2382}