blob: 92e940a266c2fe9cb3d4908709d1982f2fd8a3ba [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) {
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +0200923 dependsOn r8WithDeps
924 dependsOn testJarSources
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200925 def output = "$buildDir/libs/r8tests.jar"
926 outputs.file output
927 workingDir = projectDir
Morten Krogh-Jespersenac1a4d22020-05-04 01:42:13 +0200928 inputs.files ([testJarSources.outputs, r8WithDeps.outputs])
Morten Krogh-Jespersen4a5b1012020-05-02 21:54:11 +0200929 commandLine baseR8CommandLine([
930 "relocator",
931 "--input",
932 testJarSources.outputs.files[0],
933 "--output",
934 output,
935 "--map",
936 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"
937 ])
938}
939
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200940task generateR8LibKeepRules(type: Exec) {
941 doFirst {
942 // TODO(b/154785341): We should remove this.
943 standardOutput new FileOutputStream(r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100944 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200945 dependsOn r8WithRelocatedDeps
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +0200946 dependsOn r8NoManifestWithDeps
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200947 dependsOn testJar
948 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +0200949 inputs.files ([
950 r8WithRelocatedDeps.outputs,
951 r8NoManifestWithDeps.outputs,
952 testJar.outputs])
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200953 outputs.file r8LibGeneratedKeepRulesPath
954 commandLine baseR8CommandLine([
955 "printuses",
956 "--keeprules-allowobfuscation",
957 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
Morten Krogh-Jespersen30b07902020-05-03 00:35:45 +0200958 r8NoManifestWithDeps.outputs.files[0],
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200959 testJar.outputs.files[0]])
960 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100961}
962
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100963task R8LibApiOnly {
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200964 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], r8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100965 outputs.file r8LibPath
966}
967
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100968task R8Lib {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100969 dependsOn r8LibCreateTask(
970 "Main",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200971 ["src/main/keep.txt",
972 "src/main/keep-applymapping.txt",
973 generateR8LibKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200974 r8NoManifestWithRelocatedDeps,
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100975 r8LibPath,
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200976 ).dependsOn(generateR8LibKeepRules)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100977 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100978}
979
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100980task R8LibNoDeps {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100981 dependsOn r8LibCreateTask(
982 "NoDeps",
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +0200983 ["src/main/keep.txt", "src/main/keep-applymapping.txt"],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200984 r8NoManifestWithoutDeps,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100985 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200986 "--release",
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +0200987 repackageDeps.outputs.files
988 ).dependsOn(repackageDeps)
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100989 outputs.file r8LibExludeDepsPath
990}
991
Mads Ager418d1ca2017-05-22 09:35:49 +0200992task sourceJar(type: Jar, dependsOn: classes) {
993 classifier = 'src'
994 from sourceSets.main.allSource
995}
996
997task jctfCommonJar(type: Jar) {
998 from sourceSets.jctfCommon.output
999 baseName 'jctfCommon'
1000}
1001
1002artifacts {
1003 archives sourceJar
1004}
1005
1006task createArtTests(type: Exec) {
1007 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +02001008 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001009 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +02001010 outputs.dir outputDir
1011 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +02001012 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +02001013 workingDir = projectDir
1014}
1015
1016task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001017 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +02001018 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +02001019 inputs.file script
1020 outputs.dir outputDir
1021 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +02001022 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +02001023 workingDir = projectDir
1024}
1025
1026compileTestJava {
1027 dependsOn createArtTests
1028 dependsOn createJctfTests
1029}
1030
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +01001031task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
1032 from sourceSets.cfSegments.output
1033 baseName 'cf_segments'
1034 destinationDir file('build/libs')
1035}
1036
Ian Zernyee23a172018-01-03 09:08:48 +01001037task buildD8ApiUsageSample(type: Jar) {
1038 from sourceSets.apiUsageSample.output
1039 baseName 'd8_api_usage_sample'
1040 destinationDir file('tests')
1041}
1042
Ian Zerny923a0c12018-01-03 10:59:18 +01001043task buildR8ApiUsageSample(type: Jar) {
1044 from sourceSets.apiUsageSample.output
1045 baseName 'r8_api_usage_sample'
1046 destinationDir file('tests')
1047}
1048
Yohann Roussel548ae942018-01-05 11:13:28 +01001049task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001050 dependsOn buildD8ApiUsageSample
1051 dependsOn buildR8ApiUsageSample
1052}
1053
Mads Ager418d1ca2017-05-22 09:35:49 +02001054task buildDebugInfoExamplesDex {
1055 def examplesDir = file("src/test/java")
1056 def hostJar = "debuginfo_examples.jar"
1057 def hostDexJar = "debuginfo_examples_dex.jar"
1058 task "compile_debuginfo_examples"(type: JavaCompile) {
1059 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1060 destinationDir = file("build/test/debuginfo_examples/classes")
1061 classpath = sourceSets.main.compileClasspath
1062 sourceCompatibility = JavaVersion.VERSION_1_7
1063 targetCompatibility = JavaVersion.VERSION_1_7
1064 options.compilerArgs += ["-Xlint:-options"]
1065 }
1066 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1067 archiveName = hostJar
1068 destinationDir = file("build/test/")
1069 from "build/test/debuginfo_examples/classes"
1070 include "**/*.class"
1071 }
1072 task "dex_debuginfo_examples"(type: Exec,
1073 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001074 if (OperatingSystem.current().isWindows()) {
1075 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001076 } else if (OperatingSystem.current().isMacOsX()) {
1077 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001078 } else {
1079 executable file("tools/linux/dx/bin/dx");
1080 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001081 args "--dex"
1082 args "--output=build/test/${hostDexJar}"
1083 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001084 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001085 outputs.file file("build/test/${hostDexJar}")
1086 }
1087 dependsOn dex_debuginfo_examples
1088}
1089
1090task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001091 def resourcesDir = file("src/test/debugTestResources")
1092 def hostJar = "debug_test_resources.jar"
1093 task "compile_debugTestResources"(type: JavaCompile) {
1094 source = fileTree(dir: resourcesDir, include: '**/*.java')
1095 destinationDir = file("build/test/debugTestResources/classes")
1096 classpath = sourceSets.main.compileClasspath
1097 sourceCompatibility = JavaVersion.VERSION_1_7
1098 targetCompatibility = JavaVersion.VERSION_1_7
1099 options.compilerArgs += ["-g", "-Xlint:-options"]
1100 }
1101 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1102 archiveName = hostJar
1103 destinationDir = file("build/test/")
1104 from "build/test/debugTestResources/classes"
1105 include "**/*.class"
1106 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001107 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1108 def java8HostJar = "debug_test_resources_java8.jar"
1109 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1110 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1111 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1112 classpath = sourceSets.main.compileClasspath
1113 sourceCompatibility = JavaVersion.VERSION_1_8
1114 targetCompatibility = JavaVersion.VERSION_1_8
1115 options.compilerArgs += ["-g", "-Xlint:-options"]
1116 }
1117 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1118 archiveName = java8HostJar
1119 destinationDir = file("build/test/")
1120 from "build/test/debugTestResourcesJava8/classes"
1121 include "**/*.class"
1122 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001123 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001124 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1125 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1126 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1127 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001128 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001129 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001130 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001131 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001132 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001133}
1134
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001135// Examples used by tests, where Android specific APIs are used.
1136task buildExampleAndroidApi(type: JavaCompile) {
1137 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1138 destinationDir = file("build/test/examplesAndroidApi/classes")
1139 classpath = files("third_party/android_jar/lib-v26/android.jar")
1140 sourceCompatibility = JavaVersion.VERSION_1_8
1141 targetCompatibility = JavaVersion.VERSION_1_8
1142}
1143
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001144task buildExampleKotlinJars {
1145 def kotlinSrcDir = file("src/test/examplesKotlin")
1146 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001147 def name = dir.getName();
1148 dependsOn "compile_example_kotlin_${name}"
1149 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1150 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1151 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001152 }
1153 }
1154}
1155
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001156task buildProtoGeneratedSources {
1157 def examplesProtoDir = file("src/test/examplesProto")
1158 examplesProtoDir.eachDir { dir ->
1159 def name = dir.getName()
1160 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1161 source = {
1162 file('third_party/proto').listFiles()
1163 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1164 .collect { zipTree(it) }
1165 }
1166 destinationDir = file("build/generated/test/proto/${name}_classes")
1167 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1168 sourceCompatibility = JavaVersion.VERSION_1_8
1169 targetCompatibility = JavaVersion.VERSION_1_8
1170 }
1171 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1172 archiveName = "${name}.jar"
1173 destinationDir = file("build/generated/test/proto")
1174 from "build/generated/test/proto/${name}_classes"
1175 include "/**/*.class"
1176 }
1177 dependsOn "jar_proto_generated_source_${name}"
1178 }
1179}
1180
1181task buildExamplesProto {
1182 def examplesProtoDir = file("src/test/examplesProto")
1183 def examplesProtoOutputDir = file("build/test/examplesProto");
1184 dependsOn buildProtoGeneratedSources
1185 task "compile_examples_proto"(type: JavaCompile) {
1186 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1187 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001188 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1189 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001190 sourceCompatibility = JavaVersion.VERSION_1_8
1191 targetCompatibility = JavaVersion.VERSION_1_8
1192 }
1193 examplesProtoDir.eachDir { dir ->
1194 def name = dir.getName()
1195 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1196 archiveName = "${name}.jar"
1197 destinationDir = examplesProtoOutputDir
1198 from "build/test/examplesProto/classes"
1199 include name + "/**/*.class"
1200 }
1201 dependsOn "jar_examples_proto_${name}"
1202 }
1203}
1204
Lars Bakc91e87e2017-08-18 08:53:10 +02001205// Proto lite generated code yields warnings when compiling with javac.
1206// We change the options passed to javac to ignore it.
1207compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1208
Søren Gjesse7320ce52018-05-07 15:45:22 +02001209
Mads Ager418d1ca2017-05-22 09:35:49 +02001210task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001211 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001212 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001213 def proguardScript
1214 if (OperatingSystem.current().isWindows()) {
1215 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1216 } else {
1217 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1218 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001219 task extractExamplesRuntime(type: Sync) {
1220 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001221 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001222 include "**/*.class"
1223 includeEmptyDirs false
1224 into "$buildDir/runtime/examples/"
1225 }
1226
Søren Gjesse7320ce52018-05-07 15:45:22 +02001227 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1228 from examplesDir
1229 exclude "**/*.java"
1230 exclude "**/keep-rules*.txt"
1231 into file("build/test/examples/classes")
1232 }
1233
1234 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001235 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001236 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001237 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001238 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001239 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001240 sourceCompatibility = JavaVersion.VERSION_1_7
1241 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001242 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1243 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001244 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1245 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001246 include "**/*.java"
1247 destinationDir = file("build/test/examples/classes_debuginfo_all")
1248 classpath = sourceSets.examples.compileClasspath
1249 sourceCompatibility = JavaVersion.VERSION_1_7
1250 targetCompatibility = JavaVersion.VERSION_1_7
1251 options.compilerArgs = ["-g", "-Xlint:none"]
1252 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001253 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1254 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001255 include "**/*.java"
1256 destinationDir = file("build/test/examples/classes_debuginfo_none")
1257 classpath = sourceSets.examples.compileClasspath
1258 sourceCompatibility = JavaVersion.VERSION_1_7
1259 targetCompatibility = JavaVersion.VERSION_1_7
1260 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001261 }
1262 examplesDir.eachDir { dir ->
1263 def name = dir.getName();
1264 def exampleOutputDir = file("build/test/examples");
1265 def jarName = "${name}.jar"
1266 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001267 dependsOn "jar_example_${name}_debuginfo_all"
1268 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001269 dependsOn "extractExamplesRuntime"
1270 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001271 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1272 def proguardConfigPath = "${dir}/proguard.cfg"
1273 if (new File(proguardConfigPath).exists()) {
1274 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1275 archiveName = "${name}_pre_proguard.jar"
1276 destinationDir = exampleOutputDir
1277 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001278 include name + "/**/*.class"
1279 with runtimeDependencies
1280 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001281 }
1282 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1283 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1284 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1285 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001286 inputs.files files(
1287 tasks.getByPath("pre_proguard_example_${name}"),
1288 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001289 // Enable these to get stdout and stderr redirected to files...
1290 // standardOutput = new FileOutputStream('proguard.stdout')
1291 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001292 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001293 " -outjars ${proguardJarPath}" +
1294 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001295 " -printmapping ${proguardMapPath}"
1296 if (OperatingSystem.current().isWindows()) {
1297 executable "${proguardScript}"
1298 args "${proguardArguments}"
1299 } else {
1300 executable "bash"
1301 args "-c", "${proguardScript} '${proguardArguments}'"
1302 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001303 outputs.file proguardJarPath
1304 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001305 // TODO: Consider performing distinct proguard compilations.
1306 task "jar_example_${name}_debuginfo_all"(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_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001310 }
1311 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1312 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001313 into "${exampleOutputDir}"
1314 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001315 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001316 } else {
1317 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001318 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001319 destinationDir = exampleOutputDir
1320 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001321 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001322 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001323 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001324 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001325 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1326 archiveName = "${name}_debuginfo_all.jar"
1327 destinationDir = exampleOutputDir
1328 from "build/test/examples/classes_debuginfo_all"
1329 include name + "/**/*.class"
1330 with runtimeDependencies
1331 includeEmptyDirs false
1332 }
1333 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1334 archiveName = "${name}_debuginfo_none.jar"
1335 destinationDir = exampleOutputDir
1336 from "build/test/examples/classes_debuginfo_none"
1337 include name + "/**/*.class"
1338 with runtimeDependencies
1339 includeEmptyDirs false
1340 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001341 }
1342 }
1343}
1344
1345task buildExampleAndroidNJars {
1346 dependsOn downloadDeps
1347 def examplesDir = file("src/test/examplesAndroidN")
1348 task "compile_examplesAndroidN"(type: JavaCompile) {
1349 source = fileTree(dir: examplesDir, include: '**/*.java')
1350 destinationDir = file("build/test/examplesAndroidN/classes")
1351 classpath = sourceSets.main.compileClasspath
1352 sourceCompatibility = JavaVersion.VERSION_1_8
1353 targetCompatibility = JavaVersion.VERSION_1_8
1354 options.compilerArgs += ["-Xlint:-options"]
1355 }
1356 examplesDir.eachDir { dir ->
1357 def name = dir.getName();
1358 def exampleOutputDir = file("build/test/examplesAndroidN");
1359 def jarName = "${name}.jar"
1360 dependsOn "jar_examplesAndroidN_${name}"
1361 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1362 archiveName = jarName
1363 destinationDir = exampleOutputDir
1364 from "build/test/examplesAndroidN/classes"
1365 include "**/" + name + "/**/*.class"
1366 }
1367 }
1368}
1369
1370
1371task buildExampleAndroidOJars {
1372 dependsOn downloadDeps
1373 def examplesDir = file("src/test/examplesAndroidO")
1374 // NOTE: we want to enable a scenario when test needs to reference some
1375 // classes generated by legacy (1.6) Java compiler to test some specific
1376 // behaviour. To do so we compile all the java files located in sub-directory
1377 // called 'legacy' with Java 1.6, then compile the rest of the files with
1378 // Java 1.8 and a reference to previously generated 1.6 classes.
1379
1380 // Compiling all classes in dirs 'legacy' with old Java version.
1381 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1382 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1383 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1384 classpath = sourceSets.main.compileClasspath
1385 sourceCompatibility = JavaVersion.VERSION_1_6
1386 targetCompatibility = JavaVersion.VERSION_1_6
1387 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1388 }
1389 // Compiling the rest of the files as Java 1.8 code.
1390 task "compile_examplesAndroidO"(type: JavaCompile) {
1391 dependsOn "compile_examplesAndroidO_Legacy"
1392 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1393 destinationDir = file("build/test/examplesAndroidO/classes")
1394 classpath = sourceSets.main.compileClasspath
1395 classpath += files("build/test/examplesAndroidOLegacy/classes")
1396 sourceCompatibility = JavaVersion.VERSION_1_8
1397 targetCompatibility = JavaVersion.VERSION_1_8
1398 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1399 }
1400 examplesDir.eachDir { dir ->
1401 def name = dir.getName();
1402 def destinationDir = file("build/test/examplesAndroidO/classes");
1403 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1404 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1405 dependsOn: "compile_examplesAndroidO") {
1406 main = name + ".TestGenerator"
1407 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1408 args destinationDir
1409 }
1410 } else {
1411 task "generate_examplesAndroidO_${name}" () {}
1412 }
1413 }
1414 examplesDir.eachDir { dir ->
1415 def name = dir.getName();
1416 def exampleOutputDir = file("build/test/examplesAndroidO");
1417 def jarName = "${name}.jar"
1418 dependsOn "jar_examplesAndroidO_${name}"
1419 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1420 "generate_examplesAndroidO_${name}"]) {
1421 archiveName = jarName
1422 destinationDir = exampleOutputDir
1423 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1424 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1425 include "**/" + name + "/**/*.class"
1426 // Do not include generator into the test runtime jar, it is not useful.
1427 // Otherwise, shrinking will need ASM jars.
1428 exclude "**/TestGenerator*"
1429 }
1430 }
1431}
1432
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001433task buildExampleAndroidPJars {
1434 dependsOn downloadDeps
1435 def examplesDir = file("src/test/examplesAndroidP")
1436
1437 task "compile_examplesAndroidP"(type: JavaCompile) {
1438 source = fileTree(dir: examplesDir, include: '**/*.java')
1439 destinationDir = file("build/test/examplesAndroidP/classes")
1440 classpath = sourceSets.main.compileClasspath
1441 sourceCompatibility = JavaVersion.VERSION_1_8
1442 targetCompatibility = JavaVersion.VERSION_1_8
1443 options.compilerArgs += ["-Xlint:-options"]
1444 }
1445 examplesDir.eachDir { dir ->
1446 def name = dir.getName();
1447 def destinationDir = file("build/test/examplesAndroidP/classes");
1448 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1449 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1450 dependsOn: "compile_examplesAndroidP") {
1451 main = name + ".TestGenerator"
1452 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1453 args destinationDir
1454 }
1455 } else {
1456 task "generate_examplesAndroidP_${name}" () {}
1457 }
1458 }
1459 examplesDir.eachDir { dir ->
1460 def name = dir.getName();
1461 def exampleOutputDir = file("build/test/examplesAndroidP");
1462 def jarName = "${name}.jar"
1463 dependsOn "jar_examplesAndroidP_${name}"
1464 task "jar_examplesAndroidP_${name}"(type: Jar,
1465 dependsOn: ["compile_examplesAndroidP",
1466 "generate_examplesAndroidP_${name}"]) {
1467 archiveName = jarName
1468 destinationDir = exampleOutputDir
1469 from "build/test/examplesAndroidP/classes" // Java 1.8 classes
1470 include "**/" + name + "/**/*.class"
1471 // Do not include generator into the test runtime jar, it is not useful.
1472 // Otherwise, shrinking will need ASM jars.
1473 exclude "**/TestGenerator*"
1474 }
1475 }
1476}
1477
Mikaël Peltier61633d42017-10-13 16:51:06 +02001478task buildExampleJava9Jars {
1479 def examplesDir = file("src/test/examplesJava9")
1480 examplesDir.eachDir { dir ->
1481 def name = dir.getName();
1482 def exampleOutputDir = file("build/test/examplesJava9");
1483 def jarName = "${name}.jar"
1484 dependsOn "jar_examplesJava9_${name}"
1485 task "jar_examplesJava9_${name}"(type: Jar) {
1486 archiveName = jarName
1487 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001488 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001489 include "**/" + name + "/**/*.class"
1490 }
1491 }
1492}
1493
Jake Wharton2000b2f2019-12-11 20:37:49 -05001494task buildExampleJava10Jars {
1495 def examplesDir = file("src/test/examplesJava10")
1496 examplesDir.eachDir { dir ->
1497 def name = dir.getName();
1498 def exampleOutputDir = file("build/test/examplesJava10");
1499 def jarName = "${name}.jar"
1500 dependsOn "jar_examplesJava10_${name}"
1501 task "jar_examplesJava10_${name}"(type: Jar) {
1502 archiveName = jarName
1503 destinationDir = exampleOutputDir
1504 from sourceSets.examplesJava10.output
1505 include "**/" + name + "/**/*.class"
1506 }
1507 }
1508}
1509
clementberad7ab1dd2019-04-16 16:05:00 +02001510task buildExampleJava11Jars {
1511 def examplesDir = file("src/test/examplesJava11")
1512 examplesDir.eachDir { dir ->
1513 def name = dir.getName();
1514 def exampleOutputDir = file("build/test/examplesJava11");
1515 def jarName = "${name}.jar"
1516 dependsOn "jar_examplesJava11_${name}"
1517 task "jar_examplesJava11_${name}"(type: Jar) {
1518 archiveName = jarName
1519 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001520 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001521 include "**/" + name + "/**/*.class"
1522 }
1523 }
1524}
1525
clementberaa92e3cd2019-07-12 14:13:22 +02001526task provideArtFrameworksDependencies {
1527 cloudDependencies.tools.forEach({ art ->
1528 if (art.contains("art")) {
1529 def taskName = art.replace('/','_')
1530 dependsOn "patch_${taskName}"
1531 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1532 from "tools/${art}/framework"
1533 include "**.jar"
1534 into file("tools/${art}/out/host/linux-x86/framework")
1535 }
1536 }
1537 })
1538}
1539
clementbera4f9c2a92019-07-09 08:50:37 +02001540task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1541 from sourceSets.jdk11TimeTests.compileClasspath
1542 include "**/**.jar"
1543 into file("build/test/jdk11Tests")
1544}
1545
1546task buildJdk11TimeTestsJar {
1547 def exampleOutputDir = file("build/test/jdk11Tests");
1548 def jarName = "jdk11TimeTests.jar"
1549 dependsOn "jar_jdk11TimeTests"
1550 dependsOn provideJdk11TestsDependencies
1551 task "jar_jdk11TimeTests"(type: Jar) {
1552 archiveName = jarName
1553 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001554 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001555 include "**.class"
1556 from sourceSets.jdk11TimeTests.output
1557 include "**.class"
1558 include "**/**.class"
1559 }
1560}
1561
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001562task buildExamplesKotlin {
1563 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1564 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1565 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1566 } else if (!OperatingSystem.current().isLinux()) {
1567 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1568 "on your platform. It is fully supported on Linux and partially supported on " +
1569 "Mac OS and Windows")
1570 return;
1571 }
1572 def examplesDir = file("src/test/examplesKotlin")
1573 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001574 def name = dir.getName();
1575 dependsOn "dex_example_kotlin_${name}"
1576 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1577 def dexPath = file("${exampleOutputDir}")
Jake Wharton2d7aab82019-09-13 10:24:26 -04001578 task "dex_example_kotlin_${name}"(type: DxTask,
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001579 dependsOn: "compile_example_kotlin_${name}") {
1580 doFirst {
1581 if (!dexPath.exists()) {
1582 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001583 }
1584 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001585 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1586 destination = dexPath
1587 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001588 }
1589 }
1590}
1591
Sebastien Hertzd3313772018-01-16 14:12:37 +01001592task buildKotlinR8TestResources {
1593 def examplesDir = file("src/test/kotlinR8TestResources")
1594 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001595 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1596 def name = dir.getName()
1597 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001598 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1599 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001600 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001601 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001602 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1603 source = fileTree(dir: file("${examplesDir}/${name}"),
1604 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001605 destination = file(outputFile)
1606 targetVersion = kotlinTargetVersion
1607 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001608 task "${taskName}Java"(type: JavaCompile) {
1609 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1610 destinationDir = file(javaOutput)
1611 classpath = sourceSets.main.compileClasspath
1612 sourceCompatibility = JavaVersion.VERSION_1_6
1613 targetCompatibility = JavaVersion.VERSION_1_6
1614 options.compilerArgs += ["-g", "-Xlint:-options"]
1615 }
1616 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1617 archiveName = javaOutputJarName
1618 destinationDir = file(javaOutputJarDir)
1619 from javaOutput
1620 include "**/*.class"
1621 }
1622 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001623 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001624 }
1625}
1626
Mads Ager418d1ca2017-05-22 09:35:49 +02001627task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001628 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1629 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1630 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001631 } else if (!OperatingSystem.current().isLinux()) {
1632 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001633 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001634 return;
1635 }
1636 dependsOn buildDebugTestResourcesJars
1637 dependsOn buildExampleJars
1638 dependsOn buildExampleAndroidNJars
1639 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001640 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001641 dependsOn buildExampleJava9Jars
Jake Wharton2000b2f2019-12-11 20:37:49 -05001642 dependsOn buildExampleJava10Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001643 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001644 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001645 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001646 def noDexTests = [
1647 "multidex",
1648 "multidex002",
1649 "multidex004",
1650 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001651 examplesDir.eachDir { dir ->
1652 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001653 if (!(name in noDexTests)) {
1654 dependsOn "dex_example_${name}"
1655 def exampleOutputDir = file("build/test/examples/" + name);
1656 def dexPath = file("${exampleOutputDir}")
1657 def debug = (name == "throwing")
1658 if (!dexPath.exists()) {
1659 dexPath.mkdirs()
1660 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001661 task "dex_example_${name}"(type: DxTask, dependsOn: "jar_example_${name}") {
Yohann Rousself820a572017-05-31 20:25:51 +02001662 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1663 destination = dexPath
1664 debug = debug
1665 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001666 }
1667 }
1668}
1669
1670task buildSmali {
1671 def smaliDir = file("src/test/smali")
1672 smaliDir.eachDirRecurse() { dir ->
1673 def name = dir.getName();
1674 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1675 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1676 smaliOutputDir.mkdirs()
1677 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001678 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001679 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1680 def javaFiles = fileTree(dir: dir, include: '*.java')
1681 def destDir = smaliOutputDir;
1682 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1683 def intermediateFileName = "${name}-intermediate.dex";
1684 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1685 if (javaFiles.empty) {
1686 if (!smaliFiles.empty) {
1687 dependsOn "${taskName}_smali"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001688 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001689 source = smaliFiles
1690 destination = destFile
1691 }
1692 }
1693 } else {
1694 dependsOn "${taskName}_dexmerger"
Jake Wharton2d7aab82019-09-13 10:24:26 -04001695 task "${taskName}_smali"(type: SmaliTask) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001696 source = smaliFiles
1697 destination = intermediateFile
1698 }
1699 task "${taskName}_java"(type: JavaCompile) {
1700 source = javaFiles
1701 destinationDir destDir
1702 classpath = sourceSets.main.compileClasspath
1703 sourceCompatibility = JavaVersion.VERSION_1_7
1704 targetCompatibility = JavaVersion.VERSION_1_7
1705 options.compilerArgs += ["-Xlint:-options"]
1706 }
1707 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1708 archiveName = "Test.jar"
1709 destinationDir = destDir
1710 from fileTree(dir: destDir, include: 'Test.class')
1711 }
Jake Wharton2d7aab82019-09-13 10:24:26 -04001712 task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
Mads Ager418d1ca2017-05-22 09:35:49 +02001713 source = fileTree(dir: destDir, include: 'Test.jar')
1714 destination = destDir
1715 }
1716 task "${taskName}_dexmerger"(
Jake Wharton2d7aab82019-09-13 10:24:26 -04001717 type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001718 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1719 destination = destFile
1720 }
1721 }
1722 }
1723}
1724
1725tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001726 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001727 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
Rico Wind73da9f12019-09-19 09:27:07 +02001728 def processors = Runtime.runtime.availableProcessors()
Mads Ager418d1ca2017-05-22 09:35:49 +02001729 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind73da9f12019-09-19 09:27:07 +02001730 if (userDefinedCoresPerFork) {
1731 maxParallelForks = processors.intdiv(userDefinedCoresPerFork.toInteger()) ?: 1
1732 } else {
1733 // On normal work machines this seems to give the best test execution time (without freezing)
1734 maxParallelForks = processors.intdiv(3) ?: 1
1735 }
Rico Windc56f21c2019-03-12 07:29:57 +01001736 println("NOTE: Max parallel forks " + maxParallelForks)
Rico Wind73da9f12019-09-19 09:27:07 +02001737
Mads Ager418d1ca2017-05-22 09:35:49 +02001738 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001739 if (project.hasProperty('disable_assertions')) {
1740 enableAssertions = false
1741 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001742 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001743 if (project.hasProperty('test_xmx')) {
1744 maxHeapSize = project.property('test_xmx')
1745 } else {
1746 maxHeapSize = "4G"
1747 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001748}
1749
1750task buildPreNJdwpTestsJar(type: Jar) {
1751 baseName = 'jdwp-tests-preN'
1752 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1753 // Exclude the classes containing java8
1754 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1755 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1756 includeEmptyDirs = false
1757}
1758
Ian Zerny74143162017-11-24 13:46:35 +01001759task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1760 def inFile = buildPreNJdwpTestsJar.archivePath
1761 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001762 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001763 outputs.file outFile
1764 if (OperatingSystem.current().isWindows()) {
1765 executable file("tools/windows/dx/bin/dx.bat")
1766 } else if (OperatingSystem.current().isMacOsX()) {
1767 executable file("tools/mac/dx/bin/dx");
1768 } else {
1769 executable file("tools/linux/dx/bin/dx");
1770 }
1771 args "--dex"
1772 args "--output=${outFile}"
1773 args inFile
1774}
1775
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001776task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1777 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001778}
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001779
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001780task generateR8TestKeepRules {
1781 def path = "build/generated/r8tests-keep.txt"
1782 outputs.file path
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001783 dependsOn R8Lib
1784 doLast {
1785 file(path).write """-keep class ** { *; }
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001786-dontshrink
1787-dontoptimize
1788-keepattributes *
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001789-applymapping ${R8Lib.outputs.files[0]}.map
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001790"""
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001791 }
1792}
1793
1794task buildR8LibCfTestDeps(type: Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001795 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1796 dependsOn downloadDeps
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001797 dependsOn r8NoManifest
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001798 dependsOn R8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001799 dependsOn generateR8TestKeepRules
1800 dependsOn testJar
1801 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1802 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1803 return pkg.toString().endsWith(".jar")
1804 } + ["${buildDir}/classes/java/test"]
1805 inputs.files testJar.outputs.files +
1806 generateR8TestKeepRules.outputs.files +
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001807 R8Lib.outputs
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001808 commandLine = r8CfCommandLine(
1809 testJar.outputs.files[0],
1810 outputPath,
1811 [generateR8TestKeepRules.outputs.files[0]],
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001812 ["--debug", "--classpath", r8NoManifest.outputs.files[0]],
1813 r8NoManifest.outputs.files + addedLibraries)
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001814 workingDir = projectDir
1815 outputs.file outputPath
1816}
1817
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001818task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001819 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001820 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001821 dependsOn R8Lib
1822 delete r8LibTestPath
1823 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1824 def examplesDir = file("build/test")
1825 examplesDir.eachDir { dir ->
1826 from ("${buildDir}/test/${dir.getName()}/classes")
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001827 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001828 from ("${buildDir}/runtime/examples")
1829 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001830 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001831}
1832
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001833def printStackTrace(TestResult result) {
1834 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1835 def out = new StringBuffer()
1836 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001837 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001838 def header = "RETRACED STACKTRACE";
1839 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1840 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1841 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1842 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001843 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001844 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001845 out.append("--------------------------------------\n")
1846 Process process = command.execute()
1847 def processIn = new PrintStream(process.getOut())
1848 process.consumeProcessOutput(out, err)
1849 result.exception.printStackTrace(processIn)
1850 processIn.flush()
1851 processIn.close()
Morten Krogh-Jespersenfe0d7e12020-01-31 08:50:17 +01001852 if (process.waitFor() != 0) {
1853 out.append("ERROR DURING RETRACING\n")
1854 out.append(err.toString())
1855 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001856 out.append("\n\n--------------------------------------\n")
1857 out.append("OBFUSCATED STACKTRACE\n")
1858 out.append("--------------------------------------\n")
1859 result.exceptions.add(0, new Exception(out.toString()))
1860 } else {
1861 result.exception.printStackTrace()
1862 }
1863}
1864
Mads Ager418d1ca2017-05-22 09:35:49 +02001865test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001866 if (project.hasProperty('generate_golden_files_to')) {
1867 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1868 assert project.hasProperty('HEAD_sha1')
1869 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1870 }
1871
1872 if (project.hasProperty('use_golden_files_in')) {
1873 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1874 assert project.hasProperty('HEAD_sha1')
1875 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1876 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001877
Ian Zerny64312222019-12-05 15:12:24 +01001878 dependsOn buildLibraryDesugarConversions
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001879 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001880 // R8.jar is required for running bootstrap tests.
Morten Krogh-Jespersen47393d92020-05-01 12:39:38 +02001881 dependsOn r8
Mads Ager418d1ca2017-05-22 09:35:49 +02001882 testLogging.exceptionFormat = 'full'
1883 if (project.hasProperty('print_test_stdout')) {
1884 testLogging.showStandardStreams = true
1885 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001886 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001887 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001888 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001889 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001890
Ian Zerny324d7612019-03-20 10:52:28 +01001891 // Forward runtime configurations for test parameters.
1892 if (project.hasProperty('runtimes')) {
1893 println "NOTE: Running with runtimes: " + project.property('runtimes')
1894 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001895 }
1896
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001897 if (project.hasProperty('slow_tests')) {
1898 systemProperty 'slow_tests', project.property('slow_tests')
1899 }
1900
Mads Ager418d1ca2017-05-22 09:35:49 +02001901 if (project.hasProperty('one_line_per_test')) {
1902 beforeTest { desc ->
1903 println "Start executing test ${desc.name} [${desc.className}]"
1904 }
1905 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001906 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001907 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001908 }
Rico Windda6836e2018-12-07 12:32:03 +01001909 if (project.hasProperty('update_test_timestamp')) {
1910 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1911 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001912 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1913 }
Rico Windf88b6be2018-12-11 15:14:05 +01001914 } else {
1915 afterTest { desc, result ->
1916 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001917 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001918 }
1919 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001920 }
1921 if (project.hasProperty('no_internal')) {
1922 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001923 } else {
1924 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001925 }
1926 if (project.hasProperty('only_internal')) {
1927 include "com/android/tools/r8/internal/**"
1928 }
Rico Wind4e218292019-03-07 12:44:49 +01001929
Mads Ager418d1ca2017-05-22 09:35:49 +02001930 if (project.hasProperty('tool')) {
1931 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001932 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001933 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001934 if (project.hasProperty('only_jctf')) {
1935 include "com/android/tools/r8/jctf/d8/**"
1936 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001937 // Don't run anything, deprecated
1938 println "Running with deprecated tool d8, not running any tests"
1939 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001940 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001941 } else {
1942 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001943 assert(project.hasProperty('only_jctf'))
1944 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001945 }
1946 }
1947 if (!project.hasProperty('all_tests')) {
1948 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001949 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001950 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001951 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001952 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001953 if (project.hasProperty('shard_count') ) {
1954 assert project.hasProperty('shard_number')
1955 int shard_count = project.getProperty('shard_count') as Integer
1956 int shard_number = project.getProperty('shard_number') as Integer
1957 assert shard_count < 65536
1958 assert shard_number < shard_count
1959 exclude {
1960 entry ->
1961 // Don't leave out directories. Leaving out a directory means all entries below.
1962 if (entry.file.isDirectory()) {
1963 return false
1964 }
1965 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1966 int hash = Integer.parseInt(first4, 16)
1967 return hash % shard_count != shard_number
1968 }
1969 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001970 if (project.hasProperty('jctf_compile_only')) {
1971 println "JCTF: compiling only"
1972 systemProperty 'jctf_compile_only', '1'
1973 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001974 if (project.hasProperty('test_dir')) {
1975 systemProperty 'test_dir', project.property('test_dir')
1976 }
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001977 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001978 dependsOn configureTestForR8Lib
Morten Krogh-Jespersendfa3f512020-04-23 09:34:40 +02001979 // R8lib should be used instead of the main output and all the tests in
1980 // r8 should be mapped and exists in r8LibTestPath.
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001981 classpath = sourceSets.test.runtimeClasspath.filter {
1982 !it.getAbsolutePath().contains("/build/")
1983 }
1984 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001985 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001986 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001987 if (OperatingSystem.current().isLinux()
1988 || OperatingSystem.current().isMacOsX()
1989 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001990 if (OperatingSystem.current().isMacOsX()) {
1991 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1992 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1993 "See tools/docker/README.md for details.")
1994 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001995 if (OperatingSystem.current().isWindows()) {
1996 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1997 "Art only runs on Linux and tests requiring Art will be skipped")
1998 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001999 dependsOn downloadDeps
2000 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01002001 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01002002 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02002003 dependsOn buildSmali
2004 dependsOn jctfCommonJar
2005 dependsOn jctfTestsClasses
2006 dependsOn buildDebugInfoExamplesDex
2007 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01002008 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02002009 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02002010 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02002011 } else {
2012 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02002013 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02002014 }
2015}
2016
2017// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
2018//
2019// To build and upload a new set of the Art tests for use with R8 follow these steps:
2020//
2021// First of all an Android checkout is required. Currently it must be located
2022// in $HOME/android/master.
2023//
2024// TODO(ricow): simplify this
2025//
2026// Before: update the checked in art, see scripts/update-host-art.sh
2027//
2028// 1. Get an android checkout in $HOME/android/master and apply the patch from
2029// https://android-review.googlesource.com/#/c/294187/
2030//
2031// 2. run the following commands in the Android checkout directory:
2032//
2033// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02002034// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
2035// m desugar
2036// m -j30 test-art-host
2037// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
2038//
2039// Without running the test.py command the classes.jar file used by desugar in
2040// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
2041// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02002042//
2043// 3. In the R8 project root directory, make sure we have a clean state before starting:
2044// tools/gradle.py downloadDeps
2045// tools/gradle.py clean
2046// rm -rf tests/art
2047//
2048// 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 +02002049// Make sure you have smali on your path, please use the build binary in the
2050// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2051// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2052// 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 +02002053// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2054// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002055//
Søren Gjesse34b77732017-07-07 13:56:21 +02002056// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002057//
2058// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2059// skippedTests with an explanation. Rerun from step 3.
2060//
2061// 5. Run the tests:
2062// tools/gradle.py clean
2063// tools/test.py
2064//
Søren Gjesse34b77732017-07-07 13:56:21 +02002065// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2066// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2067// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002068//
Søren Gjesse34b77732017-07-07 13:56:21 +02002069// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002070// cd tests
2071// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002072//
2073// 7. Update the manifest file describing the Android repo used:
2074// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002075
Mads Ager418d1ca2017-05-22 09:35:49 +02002076def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002077
2078def artTestDir = file("${androidCheckoutDir}/art/test")
2079
2080if (project.hasProperty('android_source')) {
2081 task buildArtTests {
2082 outputs.upToDateWhen { false }
2083 def toBeTriaged = [
2084 "903-hello-tagging",
2085 "904-object-allocation",
2086 "905-object-free",
2087 "906-iterate-heap",
2088 "907-get-loaded-classes",
2089 "908-gc-start-finish",
2090 "954-invoke-polymorphic-verifier",
2091 "955-methodhandles-smali",
2092 "596-monitor-inflation",
2093 ]
2094 def skippedTests = toBeTriaged + [
2095 // This test produces no jar.
2096 "000-nop",
2097 // This does not build, as it tests the error when the application exceeds more
2098 // than 65536 methods
2099 "089-many-methods",
2100 // Requires some jack beta jar
2101 "956-methodhandles",
2102 ]
2103
2104 def skippedTestsDx = [
2105 // Tests with custom build scripts, where javac is not passed the options
2106 // -source 1.7 -target 1.7.
2107 "462-checker-inlining-across-dex-files",
2108 "556-invoke-super",
2109 "569-checker-pattern-replacement",
2110 // These tests use jack even when --build-with-javac-dx is specified.
2111 "004-JniTest",
2112 "048-reflect-v8",
2113 "146-bad-interface",
2114 "563-checker-invoke-super",
2115 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2116 "604-hot-static-interface",
2117 "957-methodhandle-transforms",
2118 "958-methodhandle-emulated-stackframe",
2119 "959-invoke-polymorphic-accessors",
2120 "961-default-iface-resolution-gen",
2121 "962-iface-static",
2122 "963-default-range-smali",
2123 "964-default-iface-init-gen",
2124 "965-default-verify",
2125 "966-default-conflict",
2126 "967-default-ame",
2127 "968-default-partial-compile-gen",
2128 "969-iface-super",
2129 "970-iface-super-resolution-gen",
2130 "971-iface-super",
2131 // These tests does not build with --build-with-javac-dx
2132 "004-NativeAllocations", // Javac error
2133 "031-class-attributes",
2134 "138-duplicate-classes-check",
2135 "157-void-class", // Javac error
2136 "580-checker-string-factory-intrinsics",
2137 "612-jit-dex-cache",
2138 "613-inlining-dex-cache",
2139 "900-hello-plugin", // --experimental agents
2140 "901-hello-ti-agent", // --experimental agents
2141 "902-hello-transformation", // --experimental agents
2142 "909-attach-agent", // --experimental agents
2143 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2144 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2145 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2146 "960-default-smali", // --experimental default-methods
2147 // These tests force the build to use jack
2148 "953-invoke-polymorphic-compiler",
2149 "958-methodhandle-stackframe",
2150 ]
2151
2152 def artTestBuildDir = file("${projectDir}/tests/art")
2153
2154 if (androidCheckoutDir.exists()) {
2155 dependsOn downloadDeps
2156 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002157 artTestDir.eachDir { dir ->
2158 def name = dir.getName();
2159 def markerFile = dir.toPath().resolve("info.txt").toFile();
2160 if (markerFile.exists() && !(name in skippedTests)) {
2161 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002162 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002163 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002164 }
2165 }
2166 }
2167 doFirst {
2168 if (!androidCheckoutDir.exists()) {
2169 throw new InvalidUserDataException(
2170 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002171 }
2172 }
2173 doLast {
2174 copy {
2175 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2176 into file("${artTestBuildDir}/lib64")
2177 include 'lib*.so'
2178 }
2179 copy {
2180 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2181 into file("${artTestBuildDir}/lib64")
2182 include 'libart.so'
2183 include 'libbacktrace.so'
2184 include 'libbase.so'
2185 include 'libc++.so'
2186 include 'libcutils.so'
2187 include 'liblz4.so'
2188 include 'liblzma.so'
2189 include 'libnativebridge.so'
2190 include 'libnativeloader.so'
2191 include 'libsigchain.so'
2192 include 'libunwind.so'
2193 include 'libziparchive.so'
2194 }
2195 copy {
2196 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2197 into file("${artTestBuildDir}/lib")
2198 include 'lib*.so'
2199 }
2200 copy {
2201 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2202 into file("${artTestBuildDir}/lib")
2203 include 'libart.so'
2204 include 'libbacktrace.so'
2205 include 'libbase.so'
2206 include 'libc++.so'
2207 include 'libcutils.so'
2208 include 'liblz4.so'
2209 include 'liblzma.so'
2210 include 'libnativebridge.so'
2211 include 'libnativeloader.so'
2212 include 'libsigchain.so'
2213 include 'libunwind.so'
2214 include 'libziparchive.so'
2215 }
2216 }
2217 }
2218}
2219
Rico Windde2af6c2019-03-26 15:21:08 +01002220def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002221 def artTestDir = file("${androidCheckoutDir}/art/test")
2222 def artRunTestScript = file("${artTestDir}/run-test")
2223 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002224 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002225
Søren Gjesse34b77732017-07-07 13:56:21 +02002226 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002227 def buildTask = "build_art_test_dx_${name}"
2228 def sanitizeTask = "sanitize_art_test_dx_${name}"
2229 def copyCheckTask = "copy_check_art_test_dx_${name}"
2230 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002231
2232 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002233 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002234 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2235 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002236 task "$buildTask"(type: Exec) {
2237 outputs.upToDateWhen { false }
2238 inputs.file buildInputs
2239 executable "${artRunTestScript}"
2240 args "--host"
2241 args "--build-only"
2242 args "--build-with-javac-dx"
2243 args "--output-path", "${testDir}"
2244 args "${name}"
2245 environment DX: "${dxExecutable.absolutePath}"
2246 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2247 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2248 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002249 }
2250 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2251 outputs.upToDateWhen { false }
2252 executable "/bin/bash"
2253 args "-c"
2254 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2255 " ${testDir}/classes-ex ${testDir}/check"
2256 }
2257
2258 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002259 // Directory that contains smali files is either smali, or smali/art
2260 def smali_dir = file("${dir}/smali/art")
2261 if (smali_dir.exists()) {
2262 workingDir "${testDir}/smali/art"
2263 } else {
2264 workingDir "${testDir}/smali"
2265 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002266 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002267 // This is the command line options for smali prior to 2.2.1, where smali got a new
2268 // command line interface.
2269 args "-c", "smali a *.smali"
2270 // This is the command line options for smali 2.2.1 and later.
2271 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002272 }
2273
2274 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2275 def smali_dir = file("${dir}/smali")
2276 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002277 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002278 dependsOn smaliToDexTask
2279 }
2280 from("${artTestDir}/${name}") {
2281 include 'check'
2282 }
2283 into testDir
2284 }
2285
2286 return copyCheckTask
2287}
2288
2289task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002290 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002291 classpath = sourceSets.main.compileClasspath
2292 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002293 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002294 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002295 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002296 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002297 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002298 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002299 include '**/com/android/tools/r8/CompilationMode.java'
2300 include '**/com/android/tools/r8/D8.java'
2301 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002302 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2303 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002304 include '**/com/android/tools/r8/Diagnostic.java'
2305 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002306 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2307 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002308 include '**/com/android/tools/r8/ProgramConsumer.java'
2309 include '**/com/android/tools/r8/ProgramResource.java'
2310 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002311 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002312 include '**/com/android/tools/r8/ResourceException.java'
2313 include '**/com/android/tools/r8/StringConsumer.java'
2314 include '**/com/android/tools/r8/StringResource.java'
2315 include '**/com/android/tools/r8/Version.java'
2316 include '**/com/android/tools/r8/origin/*.java'
2317}
2318
2319task javadocR8(type: Javadoc) {
2320 title "R8 API"
2321 classpath = sourceSets.main.compileClasspath
2322 source = sourceSets.main.allJava
2323 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2324 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2325 include '**/com/android/tools/r8/BaseCommand.java'
2326 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2327 include '**/com/android/tools/r8/ClassFileConsumer.java'
2328 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2329 include '**/com/android/tools/r8/CompilationFailedException.java'
2330 include '**/com/android/tools/r8/CompilationMode.java'
2331 include '**/com/android/tools/r8/R8.java'
2332 include '**/com/android/tools/r8/R8Command.java'
2333 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2334 include '**/com/android/tools/r8/Diagnostic.java'
2335 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002336 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2337 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002338 include '**/com/android/tools/r8/ProgramConsumer.java'
2339 include '**/com/android/tools/r8/ProgramResource.java'
2340 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2341 include '**/com/android/tools/r8/Resource.java'
2342 include '**/com/android/tools/r8/ResourceException.java'
2343 include '**/com/android/tools/r8/StringConsumer.java'
2344 include '**/com/android/tools/r8/StringResource.java'
2345 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002346 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002347}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002348
2349task copyMavenDeps(type: Copy) {
2350 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002351 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002352 from configurations.testCompile into "$buildDir/deps"
2353}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002354
Rico Wind23a05112019-03-27 08:00:44 +01002355task printMavenDeps {
2356 // Only actually print to stdout when we are updating.
2357 if (project.hasProperty('updatemavendeps')) {
2358 for (Configuration config : configurations) {
2359 if (!config.isCanBeResolved()) {
2360 continue
2361 }
2362 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2363 it.selected.id
2364 }
2365 def result = dependencies.createArtifactResolutionQuery()
2366 .forComponents(componentIds)
2367 .withArtifacts(MavenModule, MavenPomArtifact)
2368 .execute()
2369 for (component in result.resolvedComponents) {
2370 component.getArtifacts(MavenPomArtifact).each {
2371 println "POM: ${it.file} ${component.id}"
2372 }
2373 }
2374 config.each {
2375 println "JAR: ${it}"
2376 }
2377 }
2378 }
2379}
Ian Zerny9713c032020-01-23 11:41:58 +01002380
2381allprojects {
2382 tasks.withType(Exec) {
2383 doFirst {
Ian Zerny9794cfd2020-02-04 07:57:35 +01002384 println commandLine.join(' ')
Ian Zerny9713c032020-01-23 11:41:58 +01002385 }
2386 }
2387}