blob: cdf2b9c4d2956b7b519c08f47719f782776cace8 [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
Ian Zerny5fffb0a2019-02-11 13:54:22 +01006import net.ltgt.gradle.errorprone.CheckSeverity
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02007import org.gradle.internal.os.OperatingSystem
Ian Zernyb2d27c42019-02-20 09:09:41 +01008import tasks.DownloadDependency
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00009import tasks.GetJarsFromConfiguration
Stephan Herhut417a72a2017-07-18 10:38:30 +020010import utils.Utils
Mads Ager418d1ca2017-05-22 09:35:49 +020011
Ian Zerny5fffb0a2019-02-11 13:54:22 +010012buildscript {
13 repositories {
Rico Wind23a05112019-03-27 08:00:44 +010014 maven {
15 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
16 }
Ian Zerny5fffb0a2019-02-11 13:54:22 +010017 mavenCentral()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010018 maven {
19 url "https://plugins.gradle.org/m2/"
20 }
Morten Krogh-Jespersen68cc4b62019-03-21 10:32:17 +010021 jcenter()
Ian Zerny5fffb0a2019-02-11 13:54:22 +010022 }
23 dependencies {
clementbera0bca05e2019-05-29 14:11:18 +020024 classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010025 }
26}
27
28plugins {
29 id "net.ltgt.errorprone" version "0.7"
30}
31
32apply plugin: 'java'
33apply plugin: 'idea'
34
Sebastien Hertz143ed112018-02-13 14:26:41 +010035ext {
36 androidSupportVersion = '25.4.0'
clementbera45cea0a2019-04-09 09:26:57 +020037 asmVersion = '7.1'
Sebastien Hertz143ed112018-02-13 14:26:41 +010038 espressoVersion = '3.0.0'
39 fastutilVersion = '7.2.0'
40 guavaVersion = '23.0'
41 joptSimpleVersion = '4.6'
Mads Ager48dd79e2018-05-15 09:13:55 +020042 gsonVersion = '2.7'
Morten Krogh-Jespersen94ff6762019-03-20 14:45:23 +010043 junitVersion = '4.13-beta-2'
Jinseong Jeone11145f2018-12-13 10:57:29 -080044 mockitoVersion = '2.10.0'
Jinseong Jeon87caee62019-08-16 00:17:26 -070045 kotlinVersion = '1.3.41'
Jinseong Jeon20124782019-08-06 22:52:17 -070046 kotlinExtMetadataJVMVersion = '0.1.0'
Sebastien Hertz143ed112018-02-13 14:26:41 +010047 smaliVersion = '2.2b4'
Ian Zerny5fffb0a2019-02-11 13:54:22 +010048 errorproneVersion = '2.3.2'
clementbera4f9c2a92019-07-09 08:50:37 +020049 testngVersion = '6.10'
Sebastien Hertz143ed112018-02-13 14:26:41 +010050}
51
Mads Ager418d1ca2017-05-22 09:35:49 +020052apply from: 'copyAdditionalJctfCommonFiles.gradle'
53
54repositories {
Rico Wind23a05112019-03-27 08:00:44 +010055 maven {
56 url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
57 }
Yohann Roussel126f6872017-08-03 16:25:32 +020058 maven { url 'https://maven.google.com' }
Mads Ager418d1ca2017-05-22 09:35:49 +020059 mavenCentral()
Morten Krogh-Jespersene45b0f92019-03-21 09:56:19 +010060 maven { url 'https://kotlin.bintray.com/kotlinx' }
Mads Ager418d1ca2017-05-22 09:35:49 +020061}
62
Jinseong Jeon05064e12018-07-03 00:21:12 -070063if (project.hasProperty('with_code_coverage')) {
64 apply plugin: 'jacoco'
65}
66
Mads Ager418d1ca2017-05-22 09:35:49 +020067// Custom source set for example tests and generated tests.
68sourceSets {
69 test {
70 java {
71 srcDirs = [
clementbera0fe940d2019-04-23 12:45:18 +020072 'src/test/java',
73 'build/generated/test/java',
74 ]
75 }
76 }
Yohann Rousselbb571622017-11-09 10:47:36 +010077 apiUsageSample {
78 java {
Mathias Rave3f3c522018-05-30 08:22:17 +020079 srcDirs = ['src/test/apiUsageSample', 'src/main/java']
80 include 'com/android/tools/apiusagesample/*.java'
81 include 'com/android/tools/r8/BaseCompilerCommandParser.java'
82 include 'com/android/tools/r8/D8CommandParser.java'
83 include 'com/android/tools/r8/R8CommandParser.java'
84 include 'com/android/tools/r8/utils/FlagFile.java'
Yohann Rousselbb571622017-11-09 10:47:36 +010085 }
Yohann Rousselbb571622017-11-09 10:47:36 +010086 }
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +010087 cfSegments {
88 java {
89 srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
90 }
91 output.resourcesDir = 'build/classes/cfSegments'
92 }
Mads Ager418d1ca2017-05-22 09:35:49 +020093 debugTestResources {
94 java {
95 srcDirs = ['src/test/debugTestResources']
96 }
97 output.resourcesDir = 'build/classes/debugTestResources'
98 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +020099 debugTestResourcesJava8 {
100 java {
101 srcDirs = ['src/test/debugTestResourcesJava8']
102 }
103 output.resourcesDir = 'build/classes/debugTestResourcesJava8'
104 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +0200105 debugTestResourcesKotlin {
106 java {
107 srcDirs = ['src/test/debugTestResourcesKotlin']
108 }
109 output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
110 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200111 examples {
112 java {
Ivan Gavrilovic664f34d2018-11-09 10:02:40 -0800113 srcDirs = ['src/test/examples']
Mads Ager418d1ca2017-05-22 09:35:49 +0200114 }
115 output.resourcesDir = 'build/classes/examples'
116 }
Ian Zernyd3020482019-04-25 07:05:04 +0200117 examplesJava9 {
118 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200119 srcDirs = ['src/test/examplesJava9']
Ian Zernyd3020482019-04-25 07:05:04 +0200120 }
121 }
122 examplesJava11 {
123 java {
clementbera0bdd90f2019-07-06 11:15:23 +0200124 srcDirs = ['src/test/examplesJava11']
125 }
126 }
clementbera4f9c2a92019-07-09 08:50:37 +0200127 jdk11TimeTests {
128 java {
129 srcDirs = [
130 'third_party/openjdk/jdk-11-test/java/time/tck',
131 'third_party/openjdk/jdk-11-test/java/time/test'
132 ]
133 exclude '**/TestZoneTextPrinterParser.java'
134 }
135 }
clementberaefa10522019-07-11 11:20:46 +0200136 examplesTestNGRunner {
clementbera4f9c2a92019-07-09 08:50:37 +0200137 java {
138 srcDirs = ['src/test/testngrunner']
139 }
140 }
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +0100141 examplesKotlin {
142 java {
143 srcDirs = ['src/test/examplesKotlin']
144 }
145 output.resourcesDir = 'build/classes/examplesKotlin'
146 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200147 examplesAndroidN {
148 java {
149 srcDirs = ['src/test/examplesAndroidN']
150 }
151 output.resourcesDir = 'build/classes/examplesAndroidN'
152 }
153 examplesAndroidO {
154 java {
155 srcDirs = ['src/test/examplesAndroidO']
156 }
157 output.resourcesDir = 'build/classes/examplesAndroidO'
158 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +0200159 examplesAndroidP {
160 java {
161 srcDirs = ['src/test/examplesAndroidP']
162 }
163 output.resourcesDir = 'build/classes/examplesAndroidP'
164 }
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200165 examplesProto {
166 java {
167 srcDirs = ['src/test/examplesProto']
168 }
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +0200169 compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
170 compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200171 output.resourcesDir = 'build/classes/examplesProto'
172 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200173 jctfCommon {
174 java {
175 srcDirs = [
176 'third_party/jctf/Harness/src',
177 'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
178 'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
179 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
180 'third_party/jctf/LibTests/src/org',
181 'build/additionalJctfCommonFiles'
182 ]
183 }
184 resources {
185 srcDirs = ['third_party/jctf/LibTests/resources']
186 }
187 }
188 jctfTests {
189 java {
190 srcDirs = [
191 'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
192 // 'third_party/jctf/VMTests/src',
193 ]
194 }
195 }
Sebastien Hertzd3313772018-01-16 14:12:37 +0100196 kotlinR8TestResources {
197 java {
198 srcDirs = ['src/test/kotlinR8TestResources']
199 }
200 output.resourcesDir = 'build/classes/kotlinR8TestResources'
201 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200202}
203
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800204// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
205// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
206// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
207// for context.
208idea {
209 sourceSets.all { SourceSet sources ->
210 module {
211 if (sources.name == "main") {
212 sourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100213 outputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800214 } else {
215 testSourceDirs += sources.java.srcDirs
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100216 testOutputDir sources.output.classesDirs[0]
Ivan Gavrilovic22790f32018-11-07 17:34:38 -0800217 }
218 }
219 }
220}
221
Yohann Roussel126f6872017-08-03 16:25:32 +0200222configurations {
223 supportLibs
224}
225
Mads Ager418d1ca2017-05-22 09:35:49 +0200226dependencies {
Mads Agerd1d0da92018-12-10 13:56:50 +0100227 implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
228 implementation "com.google.code.gson:gson:$gsonVersion"
Mads Ager0aa48052017-09-15 12:39:15 +0200229 // Include all of guava when compiling the code, but exclude annotations that we don't
230 // need from the packaging.
Sebastien Hertz143ed112018-02-13 14:26:41 +0100231 compileOnly("com.google.guava:guava:$guavaVersion")
Mads Agerd1d0da92018-12-10 13:56:50 +0100232 implementation("com.google.guava:guava:$guavaVersion", {
Mads Ager0aa48052017-09-15 12:39:15 +0200233 exclude group: 'com.google.errorprone'
234 exclude group: 'com.google.code.findbugs'
235 exclude group: 'com.google.j2objc'
236 exclude group: 'org.codehaus.mojo'
237 })
Mads Agerd1d0da92018-12-10 13:56:50 +0100238 implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
239 implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
240 implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
241 implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
242 implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
243 implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
244 implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
clementbera4f9c2a92019-07-09 08:50:37 +0200245 jdk11TimeTestsCompile group: 'org.testng', name: 'testng', version: testngVersion
clementberaefa10522019-07-11 11:20:46 +0200246 examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200247 testCompile sourceSets.examples.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100248 testCompile "junit:junit:$junitVersion"
249 testCompile group: 'org.smali', name: 'smali', version: smaliVersion
Mads Ager418d1ca2017-05-22 09:35:49 +0200250 testCompile files('third_party/jasmin/jasmin-2.4.jar')
251 testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
Jean-Marie Henaffce162f32017-10-04 10:39:27 +0200252 testCompile files('third_party/ddmlib/ddmlib.jar')
Sebastien Hertz143ed112018-02-13 14:26:41 +0100253 jctfCommonCompile "junit:junit:$junitVersion"
254 jctfTestsCompile "junit:junit:$junitVersion"
Mads Ager418d1ca2017-05-22 09:35:49 +0200255 jctfTestsCompile sourceSets.jctfCommon.output
Sebastien Hertz143ed112018-02-13 14:26:41 +0100256 examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
257 examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
Stephan Herhut52cb1022017-10-24 15:10:41 +0200258 // Import Guava for @Nullable annotation
Sebastien Hertz143ed112018-02-13 14:26:41 +0100259 examplesCompile "com.google.guava:guava:$guavaVersion"
Jinseong Jeone11145f2018-12-13 10:57:29 -0800260 examplesCompile "junit:junit:$junitVersion"
261 examplesCompile "org.mockito:mockito-core:$mockitoVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100262 supportLibs "com.android.support:support-v4:$androidSupportVersion"
263 supportLibs "junit:junit:$junitVersion"
264 supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
Yohann Rousselbb571622017-11-09 10:47:36 +0100265 apiUsageSampleCompile sourceSets.main.output
Tamas Kenezb865eee2018-12-03 16:50:45 +0100266 apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
Sebastien Hertz143ed112018-02-13 14:26:41 +0100267 debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
268 examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
269 kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100270 errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
Stephan Herhut417a72a2017-07-18 10:38:30 +0200271}
272
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100273def r8LibPath = "$buildDir/libs/r8lib.jar"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100274def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100275def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100276def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100277def r8LibTestPath = "$buildDir/classes/r8libtest"
clementbera0bca05e2019-05-29 14:11:18 +0200278def java11ClassFiles = "build/classes/java/mainJava11"
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100279
Jean-Marie Henaff39587a82017-06-08 15:20:13 +0200280def osString = OperatingSystem.current().isLinux() ? "linux" :
281 OperatingSystem.current().isMacOsX() ? "mac" : "windows"
Mads Ager418d1ca2017-05-22 09:35:49 +0200282
283def cloudDependencies = [
284 "tests" : [
mikaelpeltierc2aa6652017-10-06 12:53:37 +0200285 "2017-10-04/art",
Rico Wind132bfb42019-03-08 09:27:36 +0100286 "2016-12-19/art"
Mads Ager418d1ca2017-05-22 09:35:49 +0200287 ],
288 "third_party": [
Rico Windf72fa152018-10-22 15:41:03 +0200289 "android_cts_baseline",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200290 "android_jar/lib-v14",
Stephan Herhutb3aca8b2017-12-22 14:14:53 +0100291 "android_jar/lib-v15",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200292 "android_jar/lib-v19",
293 "android_jar/lib-v21",
Stephan Herhutd48be0d2018-01-04 15:33:10 +0100294 "android_jar/lib-v22",
295 "android_jar/lib-v23",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200296 "android_jar/lib-v24",
297 "android_jar/lib-v25",
298 "android_jar/lib-v26",
Søren Gjessec2ffae82018-12-21 12:20:18 +0100299 "android_jar/lib-v27",
300 "android_jar/lib-v28",
Rico Windf72fa152018-10-22 15:41:03 +0200301 "core-lambda-stubs",
302 "dart-sdk",
303 "ddmlib",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200304 "gradle/gradle",
Morten Krogh-Jespersen72f5dff2018-10-12 15:27:39 +0200305 "jacoco",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200306 "jasmin",
307 "jctf",
Morten Krogh-Jespersen4187e162019-03-25 13:19:17 +0100308 "junit",
Rico Windf72fa152018-10-22 15:41:03 +0200309 "jdwp-tests",
Søren Gjesse70f75b12019-08-22 12:32:02 +0200310 "jsr223-api-1.0",
Søren Gjessef6c0a782019-08-22 12:48:46 +0200311 "rhino-android-1.1.1",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200312 "kotlin",
Ian Zerny23942992019-07-10 14:33:52 +0200313 "kotlin-compiler-1.3.41",
Mathias Rav5285faf2018-03-20 14:16:32 +0100314 "openjdk/openjdk-rt-1.8",
Søren Gjesse952e1d52019-05-28 12:51:30 +0200315 "openjdk/desugar_jdk_libs",
clementbera8dbfeda2019-07-03 11:24:13 +0200316 "openjdk/jdk-11-test",
Rico Windf72fa152018-10-22 15:41:03 +0200317 "proguard/proguard5.2.1",
318 "proguard/proguard6.0.1",
Mathias Rav891831f2018-04-26 14:51:18 +0200319 "r8",
Mads Ager418d1ca2017-05-22 09:35:49 +0200320 ],
321 // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
322 // container on other platforms where supported.
323 "tools" : [
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200324 "linux/art",
325 "linux/art-5.1.1",
326 "linux/art-6.0.1",
327 "linux/art-7.0.0",
Søren Gjesse1528c022018-11-23 15:14:05 +0100328 "linux/art-8.1.0",
Søren Gjessefe7c0112018-12-03 12:33:12 +0100329 "linux/art-9.0.0",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200330 "linux/dalvik",
Stephan Herhut02f0f9d2018-01-04 10:27:31 +0100331 "linux/dalvik-4.0.4",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200332 "${osString}/dx",
Mads Ager418d1ca2017-05-22 09:35:49 +0200333 ]
334]
335
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100336def cloudSystemDependencies = [
337 linux: [
clementbera81738ec2019-04-11 11:32:31 +0200338 "third_party": ["openjdk/openjdk-9.0.4/linux",
clementberab4fa18d2019-04-12 09:09:40 +0200339 "openjdk/jdk8/linux-x86",
340 "openjdk/jdk-11/Linux"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100341 ],
342 osx: [
clementbera81738ec2019-04-11 11:32:31 +0200343 "third_party": ["openjdk/openjdk-9.0.4/osx",
clementberab4fa18d2019-04-12 09:09:40 +0200344 "openjdk/jdk8/darwin-x86",
345 "openjdk/jdk-11/Mac"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100346 ],
347 windows: [
clementberab4fa18d2019-04-12 09:09:40 +0200348 "third_party": ["openjdk/openjdk-9.0.4/windows",
349 "openjdk/jdk-11/Windows"],
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100350 ],
351]
352
353if (OperatingSystem.current().isWindows()) {
354 cloudSystemDependencies.windows.each { entry ->
355 cloudDependencies.get(entry.key).addAll(entry.value)
356 }
357} else if (OperatingSystem.current().isLinux()) {
358 cloudSystemDependencies.linux.each { entry ->
359 cloudDependencies.get(entry.key).addAll(entry.value)
360 }
361} else if (OperatingSystem.current().isMacOsX()) {
362 cloudSystemDependencies.osx.each { entry ->
363 cloudDependencies.get(entry.key).addAll(entry.value)
364 }
365} else {
366 println "WARNING: Unsupported system: " + OperatingSystem.current()
367}
368
369def getDownloadDepsTaskName(entryKey, entryFile) {
370 return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
371}
372
Ian Zernyb2d27c42019-02-20 09:09:41 +0100373def getFetchDepsTaskName(entryKey, entryFile) {
374 return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
375}
376
Mads Ager418d1ca2017-05-22 09:35:49 +0200377cloudDependencies.each { entry ->
378 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100379 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
380 type DownloadDependency.Type.GOOGLE_STORAGE
381 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200382 }
383 }
384}
385
386def x20Dependencies = [
387 "third_party": [
Rico Windc346c4a2018-10-23 08:04:16 +0200388 "benchmarks/kotlin-benches",
Jinseong Jeonb0c2dc02019-07-18 11:41:11 -0700389 "chrome/chrome_180917_ffbaa8",
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100390 "classlib",
Morten Krogh-Jespersen480784d2019-02-05 08:10:46 +0100391 "cf_segments",
Rico Windf72fa152018-10-22 15:41:03 +0200392 "desugar/desugar_20180308",
Ian Zernybd2fdcc2019-03-22 13:57:21 +0100393 "internal/issue-127524985",
Rico Windf72fa152018-10-22 15:41:03 +0200394 "framework",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200395 "gmail/gmail_android_170604.16",
Søren Gjesseb552e842018-09-28 12:17:29 +0200396 "gmail/gmail_android_180826.15",
Rico Windf72fa152018-10-22 15:41:03 +0200397 "gmscore/gmscore_v10",
398 "gmscore/gmscore_v9",
399 "gmscore/latest",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200400 "gmscore/v4",
401 "gmscore/v5",
402 "gmscore/v6",
403 "gmscore/v7",
404 "gmscore/v8",
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200405 "nest/nest_20180926_7c6cfb",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200406 "photos/2017-06-06",
Rico Windf72fa152018-10-22 15:41:03 +0200407 "proguard/proguard_internal_159423826",
408 "proguardsettings",
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +0200409 "proto",
410 "protobuf-lite",
Sebastien Hertzf83b5902017-10-02 11:55:41 +0200411 "youtube/youtube.android_12.10",
412 "youtube/youtube.android_12.17",
413 "youtube/youtube.android_12.22",
Søren Gjessefe2de552018-09-24 16:31:10 +0200414 "youtube/youtube.android_13.37",
Rico Wind5acd2b62019-05-10 08:29:01 +0200415 "youtube/youtube.android_14.19"
Mads Ager418d1ca2017-05-22 09:35:49 +0200416 ],
417]
418
419x20Dependencies.each { entry ->
420 entry.value.each { entryFile ->
Ian Zernyb2d27c42019-02-20 09:09:41 +0100421 task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
422 type DownloadDependency.Type.X20
423 dependency "${entry.key}/${entryFile}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200424 }
425 }
426}
427
Rico Wind897bb712017-05-23 10:44:29 +0200428task downloadProguard {
429 cloudDependencies.each { entry ->
430 entry.value.each { entryFile ->
431 if (entryFile.contains("proguard")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100432 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Wind897bb712017-05-23 10:44:29 +0200433 }
434 }
435 }
436}
437
Rico Windf6c74ce2018-12-04 08:50:55 +0100438task downloadOpenJDKrt {
439 cloudDependencies.each { entry ->
440 entry.value.each { entryFile ->
441 if (entryFile.contains("openjdk-rt")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100442 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Rico Windf6c74ce2018-12-04 08:50:55 +0100443 }
444 }
445 }
446}
447
Tamas Kenez427205b2017-06-29 15:57:09 +0200448task downloadDx {
449 cloudDependencies.each { entry ->
450 entry.value.each { entryFile ->
Tamas Kenezcea7c202017-10-13 10:53:32 +0200451 if (entryFile.endsWith("/dx")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100452 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez427205b2017-06-29 15:57:09 +0200453 }
454 }
455 }
456}
457
Tamas Kenez0e10c562017-06-08 10:00:34 +0200458task downloadAndroidCts {
459 cloudDependencies.each { entry ->
460 entry.value.each { entryFile ->
461 if (entryFile.contains("android_cts_baseline")) {
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100462 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Tamas Kenez0e10c562017-06-08 10:00:34 +0200463 }
464 }
465 }
466}
467
Mads Ager418d1ca2017-05-22 09:35:49 +0200468task downloadDeps {
469 cloudDependencies.each { entry ->
470 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100471 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200472 }
473 }
474 if (!project.hasProperty('no_internal')) {
475 x20Dependencies.each { entry ->
476 entry.value.each { entryFile ->
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100477 dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
Mads Ager418d1ca2017-05-22 09:35:49 +0200478 }
479 }
480 }
481}
482
483allprojects {
484 sourceCompatibility = JavaVersion.VERSION_1_8
485 targetCompatibility = JavaVersion.VERSION_1_8
486}
487
Rico Wind266336c2019-02-25 10:11:38 +0100488// TODO(ricow): Remove debug prints
489println("NOTE: Current operating system: " + OperatingSystem.current())
490println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
491
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100492// Check if running with the JDK location from tools/jdk.py.
493if (OperatingSystem.current().isWindows()) {
494 println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
495} else {
496 def javaHomeOut = new StringBuilder()
497 def javaHomeErr = new StringBuilder()
498 def javaHomeProc = './tools/jdk.py'.execute()
499 javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
500 def jdkHome = new File(javaHomeOut.toString().trim())
501 if (!jdkHome.exists()) {
502 println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
503 } else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
504 println("WARNING: Gradle is running in a non-pinned Java"
505 + ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
506 + ". Expected: " + jdkHome)
Rico Wind266336c2019-02-25 10:11:38 +0100507 } else {
508 println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100509 }
Mads Agerc7d14d32018-09-27 11:09:46 +0200510}
511
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100512sourceSets.configureEach { sourceSet ->
513 tasks.named(sourceSet.compileJavaTaskName).configure {
514 // Default disable errorprone (enabled and setup below).
515 options.errorprone.enabled = false
516 options.compilerArgs << '-Xlint:unchecked'
Ian Zerny09135aa2019-02-12 16:03:34 +0100517 // Run all compilation tasks in a forked subprocess.
518 options.fork = true
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100519 // Javac often runs out of stack space when compiling the tests.
520 // Increase the stack size for the javac process.
Ian Zerny09135aa2019-02-12 16:03:34 +0100521 options.forkOptions.jvmArgs << "-Xss4m"
Ian Zerny26307fb2019-03-06 15:18:17 +0100522 // Test compilation is sometimes hitting the default limit at 1g, increase it.
523 options.forkOptions.jvmArgs << "-Xmx2g"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100524 // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
525 options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
526 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200527}
528
Ian Zernyd3020482019-04-25 07:05:04 +0200529tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
530 def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
clementbera0fe940d2019-04-23 12:45:18 +0200531 options.fork = true
532 options.forkOptions.jvmArgs = []
533 if (OperatingSystem.current().isLinux()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200534 options.forkOptions.javaHome = file(jdkDir + 'linux')
clementbera0fe940d2019-04-23 12:45:18 +0200535 } else if (OperatingSystem.current().isMacOsX()) {
Ian Zernyd3020482019-04-25 07:05:04 +0200536 options.forkOptions.javaHome = file(jdkDir + 'osx')
clementbera0fe940d2019-04-23 12:45:18 +0200537 } else {
Ian Zernyd3020482019-04-25 07:05:04 +0200538 options.forkOptions.javaHome = file(jdkDir + 'windows')
539 }
540 sourceCompatibility = JavaVersion.VERSION_1_9
541 targetCompatibility = JavaVersion.VERSION_1_9
542}
543
clementbera0bdd90f2019-07-06 11:15:23 +0200544def setJava11Compilation(sourceSet) {
545 tasks.named(sourceSet).get().configure {
546 def jdkDir = 'third_party/openjdk/jdk-11/'
547 options.fork = true
548 options.forkOptions.jvmArgs = []
549 if (OperatingSystem.current().isLinux()) {
550 options.forkOptions.javaHome = file(jdkDir + 'Linux')
551 } else if (OperatingSystem.current().isMacOsX()) {
552 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
553 } else {
554 options.forkOptions.javaHome = file(jdkDir + 'Windows')
555 }
556 sourceCompatibility = JavaVersion.VERSION_11
557 targetCompatibility = JavaVersion.VERSION_11
clementbera0fe940d2019-04-23 12:45:18 +0200558 }
clementbera0fe940d2019-04-23 12:45:18 +0200559}
560
clementbera0bdd90f2019-07-06 11:15:23 +0200561setJava11Compilation(sourceSets.examplesJava11.compileJavaTaskName)
clementberaefa10522019-07-11 11:20:46 +0200562setJava11Compilation(sourceSets.examplesTestNGRunner.compileJavaTaskName)
clementbera4f9c2a92019-07-09 08:50:37 +0200563setJava11Compilation(sourceSets.jdk11TimeTests.compileJavaTaskName)
clementbera0bdd90f2019-07-06 11:15:23 +0200564
clementbera0bca05e2019-05-29 14:11:18 +0200565task compileMainWithJava11 (type: JavaCompile) {
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()) {
Jake Whartona5204f32019-06-26 08:29:21 -0400572 options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
clementbera0bca05e2019-05-29 14:11:18 +0200573 } else {
574 options.forkOptions.javaHome = file(jdkDir + 'Windows')
575 }
576 source = sourceSets.main.allSource
577 destinationDir = file(java11ClassFiles)
578 sourceCompatibility = JavaVersion.VERSION_11
579 targetCompatibility = JavaVersion.VERSION_11
580 classpath = sourceSets.main.compileClasspath
581}
clementbera0fe940d2019-04-23 12:45:18 +0200582
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100583if (!project.hasProperty('without_error_prone') &&
584 // Don't enable error prone on Java 8 as the plugin setup does not support it.
585 !org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200586 compileJava {
587 // Enable error prone for D8/R8 sources.
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100588 options.errorprone.enabled = true
589 options.errorprone.disableAllChecks = true
590 options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
591 options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
592 options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
593 options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
594 options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
595 options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
596 options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
597 options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
598 options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
599 options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
600 options.errorprone.check('FallThrough', CheckSeverity.ERROR)
601 options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
602 options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
603 options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
604 options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
605 options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
606 options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
607 options.errorprone.check('FloatCast', CheckSeverity.ERROR)
608 options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
Mikaël Peltierc9c1e8f2017-10-17 15:45:42 +0200609 }
610}
611
Mads Ager418d1ca2017-05-22 09:35:49 +0200612compileJctfCommonJava {
613 dependsOn 'copyAdditionalJctfCommonFiles'
614 options.compilerArgs = ['-Xlint:none']
615}
616
617compileJctfTestsJava {
618 dependsOn 'jctfCommonClasses'
619 options.compilerArgs = ['-Xlint:none']
620}
621
Yohann Roussel7f47c032017-09-14 12:19:06 +0200622task consolidatedLicense {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200623 def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
Mads Agerd1d0da92018-12-10 13:56:50 +0100624
Yohann Roussel7f47c032017-09-14 12:19:06 +0200625 inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
Mads Agerd1d0da92018-12-10 13:56:50 +0100626 def runtimeClasspath = configurations.findByName("runtimeClasspath")
627 inputs.files { runtimeClasspath.getResolvedConfiguration().files }
628
Yohann Roussel7f47c032017-09-14 12:19:06 +0200629 outputs.files license
Mads Agerd1d0da92018-12-10 13:56:50 +0100630
Yohann Roussel7f47c032017-09-14 12:19:06 +0200631 doLast {
Mads Agerd1d0da92018-12-10 13:56:50 +0100632 def dependencies = []
633 runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
634 def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
635 dependencies.add("${identifier.group}:${identifier.module}")
636 }
637 def libraryLicenses = file('LIBRARY-LICENSE').text
638 dependencies.each {
639 if (!libraryLicenses.contains("- artifact: $it")) {
640 throw new GradleException("No license for $it in LIBRARY_LICENSE")
641 }
642 }
643
Yohann Roussel7f47c032017-09-14 12:19:06 +0200644 license.getParentFile().mkdirs()
645 license.createNewFile()
646 license.text = "This file lists all licenses for code distributed.\n"
647 license.text += "All non-library code has the following 3-Clause BSD license.\n"
648 license.text += "\n"
649 license.text += "\n"
650 license.text += file('LICENSE').text
651 license.text += "\n"
652 license.text += "\n"
653 license.text += "Summary of distributed libraries:\n"
654 license.text += "\n"
Mads Agerd1d0da92018-12-10 13:56:50 +0100655 license.text += libraryLicenses
Yohann Roussel7f47c032017-09-14 12:19:06 +0200656 license.text += "\n"
657 license.text += "\n"
658 license.text += "Licenses details:\n"
659 fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
660 license.text += "\n"
661 license.text += "\n"
662 license.text += file.text
663 }
664 }
665}
666
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200667static mergeServiceFiles(ShadowJar task) {
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700668 // Everything under META-INF is not included by default.
669 // Should include before 'relocate' so that the service file path and its content
670 // are properly relocated as well.
671 task.mergeServiceFiles {
672 include 'META-INF/services/*'
673 }
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200674}
675
676static configureRelocations(ShadowJar task) {
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000677 task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
Mads Ager48dd79e2018-05-15 09:13:55 +0200678 task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000679 task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
680 task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000681 task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000682 task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
Søren Gjesse7c560852018-06-20 16:27:21 +0200683 task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
684 task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
685 task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
Søren Gjesse06ed1322018-06-21 11:15:07 +0200686 task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000687}
688
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100689task repackageDepsNoRelocate(type: ShadowJar) {
690 configurations = [project.configurations.runtimeClasspath]
691 mergeServiceFiles(it)
692 exclude { it.getRelativePath().getPathString() == "module-info.class" }
693 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Morten Krogh-Jespersen54f196e2019-01-14 16:10:08 +0100694 baseName 'deps-not-relocated'
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100695}
696
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000697task repackageDeps(type: ShadowJar) {
Mads Ager64772812018-12-10 14:21:10 +0100698 configurations = [project.configurations.runtimeClasspath]
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200699 mergeServiceFiles(it)
700 if (!project.hasProperty('lib_no_relocate')) {
701 configureRelocations(it)
702 }
Ivan Gavrilovic2afc0cc2018-07-09 14:31:55 +0100703 exclude { it.getRelativePath().getPathString() == "module-info.class" }
Jinseong Jeon40ceab02018-07-09 14:25:31 -0700704 exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000705 baseName 'deps'
706}
707
708task repackageSources(type: ShadowJar) {
Mads Ager418d1ca2017-05-22 09:35:49 +0200709 from sourceSets.main.output
Morten Krogh-Jespersen00699af2018-10-09 10:54:42 +0200710 mergeServiceFiles(it)
711 if (!project.hasProperty('lib_no_relocate')) {
712 configureRelocations(it)
713 }
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000714 baseName 'sources'
715}
716
clementbera0bca05e2019-05-29 14:11:18 +0200717task repackageSources11(type: ShadowJar) {
718 dependsOn compileMainWithJava11
719 from file(java11ClassFiles)
720 mergeServiceFiles(it)
721 if (!project.hasProperty('lib_no_relocate')) {
722 configureRelocations(it)
723 }
clementbera55e84822019-06-06 16:08:11 +0200724 baseName 'sources11'
clementbera0bca05e2019-05-29 14:11:18 +0200725}
726
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100727task r8WithRelocatedDeps(type: ShadowJar) {
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200728 from consolidatedLicense.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100729 baseName 'r8_with_relocated_deps'
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200730 classifier = null
731 version = null
732 manifest {
733 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
734 }
735 from repackageSources.outputs.files
Morten Krogh-Jespersen764f23a2018-12-10 15:47:11 +0100736 from repackageDeps.outputs.files
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100737 configureRelocations(it)
Ian Zerny80533c92019-01-24 10:32:09 +0100738 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200739 exclude "**/*.kotlin_metadata"
Morten Krogh-Jespersene47021f2018-10-10 11:08:23 +0200740}
741
clementbera0bca05e2019-05-29 14:11:18 +0200742task r8WithRelocatedDeps11(type: ShadowJar) {
743 from consolidatedLicense.outputs.files
744 baseName 'r8_with_relocated_deps_11'
745 classifier = null
746 version = null
747 manifest {
748 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
749 }
750 from repackageSources11.outputs.files
751 from repackageDeps.outputs.files
752 configureRelocations(it)
753 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200754 exclude "**/*.kotlin_metadata"
clementbera0bca05e2019-05-29 14:11:18 +0200755}
756
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100757task r8WithoutDeps(type: ShadowJar) {
758 from consolidatedLicense.outputs.files
759 baseName 'r8_without_deps'
760 classifier = null
761 version = null
762 manifest {
763 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
764 }
765 from sourceSets.main.output
766}
767
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000768task R8(type: ShadowJar) {
Yohann Roussel7f47c032017-09-14 12:19:06 +0200769 from consolidatedLicense.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200770 baseName 'r8'
Mikaël Peltiere5e54722017-08-18 12:01:59 +0200771 classifier = null
772 version = null
Mads Ager418d1ca2017-05-22 09:35:49 +0200773 manifest {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200774 attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
Mads Ager418d1ca2017-05-22 09:35:49 +0200775 }
776 // In order to build without dependencies, pass the exclude_deps property using:
777 // gradle -Pexclude_deps R8
778 if (!project.hasProperty('exclude_deps')) {
Gautam Korlamad356f22017-12-04 21:45:30 -0800779 from repackageSources.outputs.files
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000780 from repackageDeps.outputs.files
Gautam Korlamad356f22017-12-04 21:45:30 -0800781 } else {
782 from sourceSets.main.output
Mads Ager418d1ca2017-05-22 09:35:49 +0200783 }
Ian Zerny80533c92019-01-24 10:32:09 +0100784 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200785 exclude "**/*.kotlin_metadata"
Mads Ager418d1ca2017-05-22 09:35:49 +0200786}
787
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100788task R8NoManifestNoDeps(type: ShadowJar) {
789 from consolidatedLicense.outputs.files
790 baseName 'r8nomanifest-exclude-deps'
791 classifier = null
792 version = null
793 from sourceSets.main.output
794}
795
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100796task R8NoManifest(type: ShadowJar) {
797 from consolidatedLicense.outputs.files
798 baseName 'r8nomanifest'
799 classifier = null
800 version = null
801 // In order to build without dependencies, pass the exclude_deps property using:
802 // gradle -Pexclude_deps R8
803 if (!project.hasProperty('exclude_deps')) {
804 from repackageSources.outputs.files
805 from repackageDeps.outputs.files
806 } else {
807 from sourceSets.main.output
808 }
Ian Zerny80533c92019-01-24 10:32:09 +0100809 exclude "META-INF/*.kotlin_module"
Søren Gjesse09516862019-07-03 14:38:40 +0200810 exclude "**/*.kotlin_metadata"
Tamas Kenez8224fbc2018-12-10 09:57:56 +0100811}
812
Ivan Gavrilovic4876d2a2017-11-30 18:57:48 +0000813task D8(type: ShadowJar) {
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200814 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200815 baseName 'd8'
816 manifest {
mikaelpeltier80939312017-08-17 15:00:09 +0200817 attributes 'Main-Class': 'com.android.tools.r8.D8'
Mads Ager418d1ca2017-05-22 09:35:49 +0200818 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200819}
820
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200821task CompatDx(type: ShadowJar) {
822 from R8.outputs.files
Mads Ager418d1ca2017-05-22 09:35:49 +0200823 baseName 'compatdx'
824 manifest {
825 attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
826 }
Mads Ager418d1ca2017-05-22 09:35:49 +0200827}
828
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200829task CompatProguard(type: ShadowJar) {
830 from R8.outputs.files
Søren Gjesse1d21da72017-09-01 12:05:38 +0200831 baseName 'compatproguard'
832 manifest {
833 attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
834 }
Lars Bak44cef522017-08-10 16:02:39 +0200835}
836
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100837def baseR8CommandLine(args = []) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100838 // Execute r8 commands against a stable r8 with relocated dependencies.
Morten Krogh-Jespersen4849e792019-08-20 13:27:13 +0200839 // TODO(b/139725780): See if we can remove or lower the heap size (-Xmx6g).
Rico Windcfb65512019-02-27 12:57:34 +0100840 return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
Morten Krogh-Jespersen4849e792019-08-20 13:27:13 +0200841 "-Xmx6g", "-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100842}
843
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200844def r8CfCommandLine(input, output, pgConfs = [], args = ["--release"], libs = []) {
845 def allArgs = [
846 "--classfile",
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100847 input,
848 "--output", output,
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100849 "--pg-map-output", output + ".map",
850 "--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200851 ] + args + libs.collectMany { ["--lib", it] } + pgConfs.collectMany { ["--pg-conf", it] }
852 return baseR8CommandLine(allArgs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100853}
854
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200855def r8LibCreateTask(name, pgConfs = [], r8Task, output, args = ["--release"], libs = []) {
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100856 return tasks.create("r8Lib${name}", Exec) {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200857 inputs.files ([pgConfs, r8WithRelocatedDeps.outputs, r8Task.outputs, libs])
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100858 outputs.file output
859 dependsOn downloadOpenJDKrt
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100860 dependsOn r8WithRelocatedDeps
861 dependsOn r8Task
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200862 commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConfs, args, libs)
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +0100863 workingDir = projectDir
864 }
865}
866
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100867task testJar(type: ShadowJar, dependsOn: testClasses) {
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100868 baseName = "r8tests"
869 from sourceSets.test.output
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200870 // We only want to include tests that use R8 when generating keep rules for applymapping.
871 include "com/android/tools/r8/**"
872 include "dalvik/**"
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100873}
874
875def generateR8LibKeepRules(name, r8Source, testSource, output) {
876 return tasks.create("generateR8LibKeepRules_" + name, Exec) {
877 doFirst {
878 standardOutput new FileOutputStream(output)
879 }
880 dependsOn r8WithRelocatedDeps
881 dependsOn r8Source
882 dependsOn testSource
883 dependsOn downloadOpenJDKrt
884 inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
885 outputs.file output
886 commandLine baseR8CommandLine([
887 "printuses",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200888 "--keeprules-allowobfuscation",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100889 "third_party/openjdk/openjdk-rt-1.8/rt.jar",
890 r8Source.outputs.files[0],
891 testSource.outputs.files[0]])
892 workingDir = projectDir
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100893 }
Morten Krogh-Jespersen4aa109f2018-12-21 13:27:51 +0100894}
895
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100896task R8LibApiOnly {
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200897 dependsOn r8LibCreateTask("Api", ["src/main/keep.txt"], R8NoManifest, r8LibPath)
Morten Krogh-Jespersencc5c7d02019-01-10 19:57:15 +0100898 outputs.file r8LibPath
899}
900
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100901task R8Lib {
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100902 def genRulesTask = generateR8LibKeepRules(
903 "Main",
904 R8NoManifest,
905 testJar,
906 r8LibGeneratedKeepRulesPath)
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100907 dependsOn r8LibCreateTask(
908 "Main",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200909 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +0100910 R8NoManifest,
911 r8LibPath,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100912 ).dependsOn(genRulesTask)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +0100913 outputs.file r8LibPath
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100914}
915
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100916task R8LibNoDeps {
917 def genRulesTask = generateR8LibKeepRules(
918 "NoDeps",
919 R8NoManifestNoDeps,
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200920 testJar,
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100921 r8LibGeneratedKeepRulesExcludeDepsPath
922 )
923 dependsOn r8LibCreateTask(
924 "NoDeps",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200925 ["src/main/keep.txt", "src/main/keep-applymapping.txt", genRulesTask.outputs.files[0]],
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100926 R8NoManifestNoDeps,
927 r8LibExludeDepsPath,
Søren Gjesse92992fe2019-08-30 14:04:22 +0200928 "--release",
Morten Krogh-Jespersencae32a72019-01-11 11:02:19 +0100929 repackageDepsNoRelocate.outputs.files
930 ).dependsOn(repackageDepsNoRelocate, genRulesTask)
931 outputs.file r8LibExludeDepsPath
932}
933
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100934task CompatDxLib {
935 dependsOn r8LibCreateTask(
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200936 "CompatDx", ["src/main/keep-compatdx.txt"], CompatDx, "build/libs/compatdxlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100937}
938
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100939task CompatProguardLib {
940 dependsOn r8LibCreateTask(
941 "CompatPg",
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +0200942 ["src/main/keep-compatproguard.txt"],
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +0100943 CompatProguard,
944 "build/libs/compatproguardlib.jar")
Tamas Kenezf960e9c2018-12-03 16:13:29 +0100945}
946
Mads Ager418d1ca2017-05-22 09:35:49 +0200947task sourceJar(type: Jar, dependsOn: classes) {
948 classifier = 'src'
949 from sourceSets.main.allSource
950}
951
952task jctfCommonJar(type: Jar) {
953 from sourceSets.jctfCommon.output
954 baseName 'jctfCommon'
955}
956
957artifacts {
958 archives sourceJar
959}
960
961task createArtTests(type: Exec) {
962 def outputDir = "build/generated/test/java/com/android/tools/r8/art"
Mads Ager7e5bd722017-05-24 07:17:27 +0200963 def createArtTestsScript = "tools/create_art_tests.py"
Ian Zerny5fffb0a2019-02-11 13:54:22 +0100964 inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
Mads Ager418d1ca2017-05-22 09:35:49 +0200965 outputs.dir outputDir
966 dependsOn downloadDeps
Mads Ager677e3002017-05-24 07:54:51 +0200967 commandLine "python", createArtTestsScript
Mads Ager418d1ca2017-05-22 09:35:49 +0200968 workingDir = projectDir
969}
970
971task createJctfTests(type: Exec) {
Stephan Herhutea6ee582017-05-23 13:14:34 +0200972 def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
Tamas Kenez25a99e92017-05-29 10:15:30 +0200973 def script = "tools/create_jctf_tests.py"
Mads Ager418d1ca2017-05-22 09:35:49 +0200974 inputs.file script
975 outputs.dir outputDir
976 dependsOn downloadDeps
Tamas Kenez25a99e92017-05-29 10:15:30 +0200977 commandLine "python", script
Mads Ager418d1ca2017-05-22 09:35:49 +0200978 workingDir = projectDir
979}
980
981compileTestJava {
982 dependsOn createArtTests
983 dependsOn createJctfTests
984}
985
Morten Krogh-Jespersen7bc93dc2019-01-29 09:53:08 +0100986task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
987 from sourceSets.cfSegments.output
988 baseName 'cf_segments'
989 destinationDir file('build/libs')
990}
991
Ian Zernyee23a172018-01-03 09:08:48 +0100992task buildD8ApiUsageSample(type: Jar) {
993 from sourceSets.apiUsageSample.output
994 baseName 'd8_api_usage_sample'
995 destinationDir file('tests')
996}
997
Ian Zerny923a0c12018-01-03 10:59:18 +0100998task buildR8ApiUsageSample(type: Jar) {
999 from sourceSets.apiUsageSample.output
1000 baseName 'r8_api_usage_sample'
1001 destinationDir file('tests')
1002}
1003
Yohann Roussel548ae942018-01-05 11:13:28 +01001004task buildApiSampleJars {
Yohann Roussel548ae942018-01-05 11:13:28 +01001005 dependsOn buildD8ApiUsageSample
1006 dependsOn buildR8ApiUsageSample
1007}
1008
Mads Ager418d1ca2017-05-22 09:35:49 +02001009task buildDebugInfoExamplesDex {
1010 def examplesDir = file("src/test/java")
1011 def hostJar = "debuginfo_examples.jar"
1012 def hostDexJar = "debuginfo_examples_dex.jar"
1013 task "compile_debuginfo_examples"(type: JavaCompile) {
1014 source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java")
1015 destinationDir = file("build/test/debuginfo_examples/classes")
1016 classpath = sourceSets.main.compileClasspath
1017 sourceCompatibility = JavaVersion.VERSION_1_7
1018 targetCompatibility = JavaVersion.VERSION_1_7
1019 options.compilerArgs += ["-Xlint:-options"]
1020 }
1021 task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") {
1022 archiveName = hostJar
1023 destinationDir = file("build/test/")
1024 from "build/test/debuginfo_examples/classes"
1025 include "**/*.class"
1026 }
1027 task "dex_debuginfo_examples"(type: Exec,
1028 dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001029 if (OperatingSystem.current().isWindows()) {
1030 executable file("tools/windows/dx/bin/dx.bat")
Jinseong Jeon35a1eff2017-09-24 23:28:08 -07001031 } else if (OperatingSystem.current().isMacOsX()) {
1032 executable file("tools/mac/dx/bin/dx");
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001033 } else {
1034 executable file("tools/linux/dx/bin/dx");
1035 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001036 args "--dex"
1037 args "--output=build/test/${hostDexJar}"
1038 args "build/test/${hostJar}"
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001039 inputs.files files("build/test/${hostJar}")
Mads Ager418d1ca2017-05-22 09:35:49 +02001040 outputs.file file("build/test/${hostDexJar}")
1041 }
1042 dependsOn dex_debuginfo_examples
1043}
1044
1045task buildDebugTestResourcesJars {
Mads Ager418d1ca2017-05-22 09:35:49 +02001046 def resourcesDir = file("src/test/debugTestResources")
1047 def hostJar = "debug_test_resources.jar"
1048 task "compile_debugTestResources"(type: JavaCompile) {
1049 source = fileTree(dir: resourcesDir, include: '**/*.java')
1050 destinationDir = file("build/test/debugTestResources/classes")
1051 classpath = sourceSets.main.compileClasspath
1052 sourceCompatibility = JavaVersion.VERSION_1_7
1053 targetCompatibility = JavaVersion.VERSION_1_7
1054 options.compilerArgs += ["-g", "-Xlint:-options"]
1055 }
1056 task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") {
1057 archiveName = hostJar
1058 destinationDir = file("build/test/")
1059 from "build/test/debugTestResources/classes"
1060 include "**/*.class"
1061 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001062 def java8ResourcesDir = file("src/test/debugTestResourcesJava8")
1063 def java8HostJar = "debug_test_resources_java8.jar"
1064 task "compile_debugTestResourcesJava8"(type: JavaCompile) {
1065 source = fileTree(dir: java8ResourcesDir, include: '**/*.java')
1066 destinationDir = file("build/test/debugTestResourcesJava8/classes")
1067 classpath = sourceSets.main.compileClasspath
1068 sourceCompatibility = JavaVersion.VERSION_1_8
1069 targetCompatibility = JavaVersion.VERSION_1_8
1070 options.compilerArgs += ["-g", "-Xlint:-options"]
1071 }
1072 task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") {
1073 archiveName = java8HostJar
1074 destinationDir = file("build/test/")
1075 from "build/test/debugTestResourcesJava8/classes"
1076 include "**/*.class"
1077 }
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001078 def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001079 def kotlinHostJar = "debug_test_resources_kotlin.jar"
1080 task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
1081 source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
1082 destination = file("build/test/${kotlinHostJar}")
Sebastien Hertz1d7702b2017-08-18 09:07:27 +02001083 }
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001084 dependsOn downloadDeps
Mads Ager418d1ca2017-05-22 09:35:49 +02001085 dependsOn jar_debugTestResources
Sebastien Hertz964c5c22017-05-23 15:22:23 +02001086 dependsOn jar_debugTestResourcesJava8
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001087 dependsOn jar_debugTestResourcesKotlin
Mads Ager418d1ca2017-05-22 09:35:49 +02001088}
1089
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001090// Examples used by tests, where Android specific APIs are used.
1091task buildExampleAndroidApi(type: JavaCompile) {
1092 source = fileTree(dir: file("src/test/examplesAndroidApi"), include: "**/*.java")
1093 destinationDir = file("build/test/examplesAndroidApi/classes")
1094 classpath = files("third_party/android_jar/lib-v26/android.jar")
1095 sourceCompatibility = JavaVersion.VERSION_1_8
1096 targetCompatibility = JavaVersion.VERSION_1_8
1097}
1098
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001099task buildExampleKotlinJars {
1100 def kotlinSrcDir = file("src/test/examplesKotlin")
1101 kotlinSrcDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001102 def name = dir.getName();
1103 dependsOn "compile_example_kotlin_${name}"
1104 task "compile_example_kotlin_${name}"(type: kotlin.Kotlinc) {
1105 source = fileTree(dir: file("src/test/examplesKotlin/${name}"), include: '**/*.kt')
1106 destination = file("build/test/examplesKotlin/${name}.jar")
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001107 }
1108 }
1109}
1110
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001111task buildProtoGeneratedSources {
1112 def examplesProtoDir = file("src/test/examplesProto")
1113 examplesProtoDir.eachDir { dir ->
1114 def name = dir.getName()
1115 task "compile_proto_generated_source_${name}"(type: JavaCompile) {
1116 source = {
1117 file('third_party/proto').listFiles()
1118 .findAll { it.name.startsWith(name) && it.name.endsWith('-src.jar') }
1119 .collect { zipTree(it) }
1120 }
1121 destinationDir = file("build/generated/test/proto/${name}_classes")
1122 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1123 sourceCompatibility = JavaVersion.VERSION_1_8
1124 targetCompatibility = JavaVersion.VERSION_1_8
1125 }
1126 task "jar_proto_generated_source_${name}"(type: Jar, dependsOn: "compile_proto_generated_source_${name}") {
1127 archiveName = "${name}.jar"
1128 destinationDir = file("build/generated/test/proto")
1129 from "build/generated/test/proto/${name}_classes"
1130 include "/**/*.class"
1131 }
1132 dependsOn "jar_proto_generated_source_${name}"
1133 }
1134}
1135
1136task buildExamplesProto {
1137 def examplesProtoDir = file("src/test/examplesProto")
1138 def examplesProtoOutputDir = file("build/test/examplesProto");
1139 dependsOn buildProtoGeneratedSources
1140 task "compile_examples_proto"(type: JavaCompile) {
1141 source = fileTree(dir: examplesProtoDir, include: "**/*.java")
1142 destinationDir = file("build/test/examplesProto/classes")
Christoffer Quist Adamsen5d398fe2019-06-14 15:00:14 +02001143 classpath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
1144 classpath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001145 sourceCompatibility = JavaVersion.VERSION_1_8
1146 targetCompatibility = JavaVersion.VERSION_1_8
1147 }
1148 examplesProtoDir.eachDir { dir ->
1149 def name = dir.getName()
1150 task "jar_examples_proto_${name}"(type: Jar, dependsOn: "compile_examples_proto") {
1151 archiveName = "${name}.jar"
1152 destinationDir = examplesProtoOutputDir
1153 from "build/test/examplesProto/classes"
1154 include name + "/**/*.class"
1155 }
1156 dependsOn "jar_examples_proto_${name}"
1157 }
1158}
1159
Lars Bakc91e87e2017-08-18 08:53:10 +02001160// Proto lite generated code yields warnings when compiling with javac.
1161// We change the options passed to javac to ignore it.
1162compileExamplesJava.options.compilerArgs = ["-Xlint:none"]
1163
Søren Gjesse7320ce52018-05-07 15:45:22 +02001164
Mads Ager418d1ca2017-05-22 09:35:49 +02001165task buildExampleJars {
Rico Wind897bb712017-05-23 10:44:29 +02001166 dependsOn downloadProguard
Mads Ager418d1ca2017-05-22 09:35:49 +02001167 def examplesDir = file("src/test/examples")
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001168 def proguardScript
1169 if (OperatingSystem.current().isWindows()) {
1170 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
1171 } else {
1172 proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
1173 }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001174 task extractExamplesRuntime(type: Sync) {
1175 dependsOn configurations.examplesRuntime
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001176 from { configurations.examplesRuntime.collect { zipTree(it) } }
Stephan Herhut417a72a2017-07-18 10:38:30 +02001177 include "**/*.class"
1178 includeEmptyDirs false
1179 into "$buildDir/runtime/examples/"
1180 }
1181
Søren Gjesse7320ce52018-05-07 15:45:22 +02001182 task "copy_examples_resources"(type: org.gradle.api.tasks.Copy) {
1183 from examplesDir
1184 exclude "**/*.java"
1185 exclude "**/keep-rules*.txt"
1186 into file("build/test/examples/classes")
1187 }
1188
1189 task "compile_examples"(type: JavaCompile) {
Søren Gjesse7320ce52018-05-07 15:45:22 +02001190 dependsOn "copy_examples_resources"
Rico Wind40fd2c12018-09-12 12:14:44 +02001191 source examplesDir
Stephan Herhut417a72a2017-07-18 10:38:30 +02001192 include "**/*.java"
Mads Ager418d1ca2017-05-22 09:35:49 +02001193 destinationDir = file("build/test/examples/classes")
Stephan Herhut417a72a2017-07-18 10:38:30 +02001194 classpath = sourceSets.examples.compileClasspath
Mads Ager418d1ca2017-05-22 09:35:49 +02001195 sourceCompatibility = JavaVersion.VERSION_1_7
1196 targetCompatibility = JavaVersion.VERSION_1_7
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001197 options.compilerArgs = ["-g:source,lines", "-Xlint:none"]
1198 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001199 task "compile_examples_debuginfo_all"(type: JavaCompile) {
1200 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001201 include "**/*.java"
1202 destinationDir = file("build/test/examples/classes_debuginfo_all")
1203 classpath = sourceSets.examples.compileClasspath
1204 sourceCompatibility = JavaVersion.VERSION_1_7
1205 targetCompatibility = JavaVersion.VERSION_1_7
1206 options.compilerArgs = ["-g", "-Xlint:none"]
1207 }
Rico Wind40fd2c12018-09-12 12:14:44 +02001208 task "compile_examples_debuginfo_none"(type: JavaCompile) {
1209 source examplesDir
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001210 include "**/*.java"
1211 destinationDir = file("build/test/examples/classes_debuginfo_none")
1212 classpath = sourceSets.examples.compileClasspath
1213 sourceCompatibility = JavaVersion.VERSION_1_7
1214 targetCompatibility = JavaVersion.VERSION_1_7
1215 options.compilerArgs = ["-g:none", "-Xlint:none"]
Mads Ager418d1ca2017-05-22 09:35:49 +02001216 }
1217 examplesDir.eachDir { dir ->
1218 def name = dir.getName();
1219 def exampleOutputDir = file("build/test/examples");
1220 def jarName = "${name}.jar"
1221 dependsOn "jar_example_${name}"
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001222 dependsOn "jar_example_${name}_debuginfo_all"
1223 dependsOn "jar_example_${name}_debuginfo_none"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001224 dependsOn "extractExamplesRuntime"
1225 def runtimeDependencies = copySpec { }
Mads Ager418d1ca2017-05-22 09:35:49 +02001226 // The "throwing" test verifies debugging/stack info on the post-proguarded output.
1227 def proguardConfigPath = "${dir}/proguard.cfg"
1228 if (new File(proguardConfigPath).exists()) {
1229 task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
1230 archiveName = "${name}_pre_proguard.jar"
1231 destinationDir = exampleOutputDir
1232 from "build/test/examples/classes"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001233 include name + "/**/*.class"
1234 with runtimeDependencies
1235 includeEmptyDirs false
Mads Ager418d1ca2017-05-22 09:35:49 +02001236 }
1237 def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
1238 def proguardJarPath = "${exampleOutputDir}/${jarName}"
1239 def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
1240 task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001241 inputs.files files(
1242 tasks.getByPath("pre_proguard_example_${name}"),
1243 proguardConfigPath)
Mads Ager418d1ca2017-05-22 09:35:49 +02001244 // Enable these to get stdout and stderr redirected to files...
1245 // standardOutput = new FileOutputStream('proguard.stdout')
1246 // errorOutput = new FileOutputStream('proguard.stderr')
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001247 def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
Mads Ager418d1ca2017-05-22 09:35:49 +02001248 " -outjars ${proguardJarPath}" +
1249 " -include ${proguardConfigPath}" +
Jean-Marie Henaff872e4422017-06-13 10:26:20 +02001250 " -printmapping ${proguardMapPath}"
1251 if (OperatingSystem.current().isWindows()) {
1252 executable "${proguardScript}"
1253 args "${proguardArguments}"
1254 } else {
1255 executable "bash"
1256 args "-c", "${proguardScript} '${proguardArguments}'"
1257 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001258 outputs.file proguardJarPath
1259 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001260 // TODO: Consider performing distinct proguard compilations.
1261 task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
1262 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001263 into "${exampleOutputDir}"
1264 rename(".*", "${name}_debuginfo_all.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001265 }
1266 task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
1267 from "${exampleOutputDir}/${name}.jar"
Tamas Kenez925cb642017-09-19 10:41:15 +02001268 into "${exampleOutputDir}"
1269 rename(".*", "${name}_debuginfo_none.jar")
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001270 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001271 } else {
1272 task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001273 archiveName = "${name}.jar"
Mads Ager418d1ca2017-05-22 09:35:49 +02001274 destinationDir = exampleOutputDir
1275 from "build/test/examples/classes"
Søren Gjesse7320ce52018-05-07 15:45:22 +02001276 include name + "/**/*"
Stephan Herhut417a72a2017-07-18 10:38:30 +02001277 with runtimeDependencies
Søren Gjesse7320ce52018-05-07 15:45:22 +02001278 includeEmptyDirs true
Mads Ager418d1ca2017-05-22 09:35:49 +02001279 }
Tamas Kenezc5163ed2017-09-19 09:27:37 +02001280 task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
1281 archiveName = "${name}_debuginfo_all.jar"
1282 destinationDir = exampleOutputDir
1283 from "build/test/examples/classes_debuginfo_all"
1284 include name + "/**/*.class"
1285 with runtimeDependencies
1286 includeEmptyDirs false
1287 }
1288 task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
1289 archiveName = "${name}_debuginfo_none.jar"
1290 destinationDir = exampleOutputDir
1291 from "build/test/examples/classes_debuginfo_none"
1292 include name + "/**/*.class"
1293 with runtimeDependencies
1294 includeEmptyDirs false
1295 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001296 }
1297 }
1298}
1299
1300task buildExampleAndroidNJars {
1301 dependsOn downloadDeps
1302 def examplesDir = file("src/test/examplesAndroidN")
1303 task "compile_examplesAndroidN"(type: JavaCompile) {
1304 source = fileTree(dir: examplesDir, include: '**/*.java')
1305 destinationDir = file("build/test/examplesAndroidN/classes")
1306 classpath = sourceSets.main.compileClasspath
1307 sourceCompatibility = JavaVersion.VERSION_1_8
1308 targetCompatibility = JavaVersion.VERSION_1_8
1309 options.compilerArgs += ["-Xlint:-options"]
1310 }
1311 examplesDir.eachDir { dir ->
1312 def name = dir.getName();
1313 def exampleOutputDir = file("build/test/examplesAndroidN");
1314 def jarName = "${name}.jar"
1315 dependsOn "jar_examplesAndroidN_${name}"
1316 task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") {
1317 archiveName = jarName
1318 destinationDir = exampleOutputDir
1319 from "build/test/examplesAndroidN/classes"
1320 include "**/" + name + "/**/*.class"
1321 }
1322 }
1323}
1324
1325
1326task buildExampleAndroidOJars {
1327 dependsOn downloadDeps
1328 def examplesDir = file("src/test/examplesAndroidO")
1329 // NOTE: we want to enable a scenario when test needs to reference some
1330 // classes generated by legacy (1.6) Java compiler to test some specific
1331 // behaviour. To do so we compile all the java files located in sub-directory
1332 // called 'legacy' with Java 1.6, then compile the rest of the files with
1333 // Java 1.8 and a reference to previously generated 1.6 classes.
1334
1335 // Compiling all classes in dirs 'legacy' with old Java version.
1336 task "compile_examplesAndroidO_Legacy"(type: JavaCompile) {
1337 source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java')
1338 destinationDir = file("build/test/examplesAndroidOLegacy/classes")
1339 classpath = sourceSets.main.compileClasspath
1340 sourceCompatibility = JavaVersion.VERSION_1_6
1341 targetCompatibility = JavaVersion.VERSION_1_6
1342 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1343 }
1344 // Compiling the rest of the files as Java 1.8 code.
1345 task "compile_examplesAndroidO"(type: JavaCompile) {
1346 dependsOn "compile_examplesAndroidO_Legacy"
1347 source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java')
1348 destinationDir = file("build/test/examplesAndroidO/classes")
1349 classpath = sourceSets.main.compileClasspath
1350 classpath += files("build/test/examplesAndroidOLegacy/classes")
1351 sourceCompatibility = JavaVersion.VERSION_1_8
1352 targetCompatibility = JavaVersion.VERSION_1_8
1353 options.compilerArgs += ["-Xlint:-options", "-parameters"]
1354 }
1355 examplesDir.eachDir { dir ->
1356 def name = dir.getName();
1357 def destinationDir = file("build/test/examplesAndroidO/classes");
1358 if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) {
1359 task "generate_examplesAndroidO_${name}"(type: JavaExec,
1360 dependsOn: "compile_examplesAndroidO") {
1361 main = name + ".TestGenerator"
1362 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1363 args destinationDir
1364 }
1365 } else {
1366 task "generate_examplesAndroidO_${name}" () {}
1367 }
1368 }
1369 examplesDir.eachDir { dir ->
1370 def name = dir.getName();
1371 def exampleOutputDir = file("build/test/examplesAndroidO");
1372 def jarName = "${name}.jar"
1373 dependsOn "jar_examplesAndroidO_${name}"
1374 task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO",
1375 "generate_examplesAndroidO_${name}"]) {
1376 archiveName = jarName
1377 destinationDir = exampleOutputDir
1378 from "build/test/examplesAndroidO/classes" // Java 1.8 classes
1379 from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes
1380 include "**/" + name + "/**/*.class"
1381 // Do not include generator into the test runtime jar, it is not useful.
1382 // Otherwise, shrinking will need ASM jars.
1383 exclude "**/TestGenerator*"
1384 }
1385 }
1386}
1387
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001388task buildExampleAndroidPJars {
1389 dependsOn downloadDeps
1390 def examplesDir = file("src/test/examplesAndroidP")
1391
1392 task "compile_examplesAndroidP"(type: JavaCompile) {
1393 source = fileTree(dir: examplesDir, include: '**/*.java')
1394 destinationDir = file("build/test/examplesAndroidP/classes")
1395 classpath = sourceSets.main.compileClasspath
1396 sourceCompatibility = JavaVersion.VERSION_1_8
1397 targetCompatibility = JavaVersion.VERSION_1_8
1398 options.compilerArgs += ["-Xlint:-options"]
1399 }
1400 examplesDir.eachDir { dir ->
1401 def name = dir.getName();
1402 def destinationDir = file("build/test/examplesAndroidP/classes");
1403 if (file("src/test/examplesAndroidP/" + name + "/TestGenerator.java").isFile()) {
1404 task "generate_examplesAndroidP_${name}"(type: JavaExec,
1405 dependsOn: "compile_examplesAndroidP") {
1406 main = name + ".TestGenerator"
1407 classpath = files(destinationDir, sourceSets.main.compileClasspath)
1408 args destinationDir
1409 }
1410 } else {
1411 task "generate_examplesAndroidP_${name}" () {}
1412 }
1413 }
1414 examplesDir.eachDir { dir ->
1415 def name = dir.getName();
1416 def exampleOutputDir = file("build/test/examplesAndroidP");
1417 def jarName = "${name}.jar"
1418 dependsOn "jar_examplesAndroidP_${name}"
1419 task "jar_examplesAndroidP_${name}"(type: Jar,
1420 dependsOn: ["compile_examplesAndroidP",
1421 "generate_examplesAndroidP_${name}"]) {
1422 archiveName = jarName
1423 destinationDir = exampleOutputDir
1424 from "build/test/examplesAndroidP/classes" // Java 1.8 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 Peltier61633d42017-10-13 16:51:06 +02001433task buildExampleJava9Jars {
1434 def examplesDir = file("src/test/examplesJava9")
1435 examplesDir.eachDir { dir ->
1436 def name = dir.getName();
1437 def exampleOutputDir = file("build/test/examplesJava9");
1438 def jarName = "${name}.jar"
1439 dependsOn "jar_examplesJava9_${name}"
1440 task "jar_examplesJava9_${name}"(type: Jar) {
1441 archiveName = jarName
1442 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001443 from sourceSets.examplesJava9.output
Mikaël Peltier61633d42017-10-13 16:51:06 +02001444 include "**/" + name + "/**/*.class"
1445 }
1446 }
1447}
1448
clementberad7ab1dd2019-04-16 16:05:00 +02001449task buildExampleJava11Jars {
1450 def examplesDir = file("src/test/examplesJava11")
1451 examplesDir.eachDir { dir ->
1452 def name = dir.getName();
1453 def exampleOutputDir = file("build/test/examplesJava11");
1454 def jarName = "${name}.jar"
1455 dependsOn "jar_examplesJava11_${name}"
1456 task "jar_examplesJava11_${name}"(type: Jar) {
1457 archiveName = jarName
1458 destinationDir = exampleOutputDir
Ian Zernyd3020482019-04-25 07:05:04 +02001459 from sourceSets.examplesJava11.output
clementberad7ab1dd2019-04-16 16:05:00 +02001460 include "**/" + name + "/**/*.class"
1461 }
1462 }
1463}
1464
clementberaa92e3cd2019-07-12 14:13:22 +02001465task provideArtFrameworksDependencies {
1466 cloudDependencies.tools.forEach({ art ->
1467 if (art.contains("art")) {
1468 def taskName = art.replace('/','_')
1469 dependsOn "patch_${taskName}"
1470 task "patch_${taskName}"(type: org.gradle.api.tasks.Copy){
1471 from "tools/${art}/framework"
1472 include "**.jar"
1473 into file("tools/${art}/out/host/linux-x86/framework")
1474 }
1475 }
1476 })
1477}
1478
clementbera4f9c2a92019-07-09 08:50:37 +02001479task provideJdk11TestsDependencies(type: org.gradle.api.tasks.Copy) {
1480 from sourceSets.jdk11TimeTests.compileClasspath
1481 include "**/**.jar"
1482 into file("build/test/jdk11Tests")
1483}
1484
1485task buildJdk11TimeTestsJar {
1486 def exampleOutputDir = file("build/test/jdk11Tests");
1487 def jarName = "jdk11TimeTests.jar"
1488 dependsOn "jar_jdk11TimeTests"
1489 dependsOn provideJdk11TestsDependencies
1490 task "jar_jdk11TimeTests"(type: Jar) {
1491 archiveName = jarName
1492 destinationDir = exampleOutputDir
clementberaefa10522019-07-11 11:20:46 +02001493 from sourceSets.examplesTestNGRunner.output
clementbera4f9c2a92019-07-09 08:50:37 +02001494 include "**.class"
1495 from sourceSets.jdk11TimeTests.output
1496 include "**.class"
1497 include "**/**.class"
1498 }
1499}
1500
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001501task buildExamplesKotlin {
1502 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1503 logger.lifecycle("WARNING: Testing (including building kotlin examples) is only partially" +
1504 " supported on your platform (" + OperatingSystem.current().getName() + ").")
1505 } else if (!OperatingSystem.current().isLinux()) {
1506 logger.lifecycle("WARNING: Testing (including building kotlin examples) is not supported " +
1507 "on your platform. It is fully supported on Linux and partially supported on " +
1508 "Mac OS and Windows")
1509 return;
1510 }
1511 def examplesDir = file("src/test/examplesKotlin")
1512 examplesDir.eachDir { dir ->
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001513 def name = dir.getName();
1514 dependsOn "dex_example_kotlin_${name}"
1515 def exampleOutputDir = file("build/test/examplesKotlin/" + name);
1516 def dexPath = file("${exampleOutputDir}")
1517 task "dex_example_kotlin_${name}"(type: dx.Dx,
1518 dependsOn: "compile_example_kotlin_${name}") {
1519 doFirst {
1520 if (!dexPath.exists()) {
1521 dexPath.mkdirs()
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001522 }
1523 }
Sebastien Hertz2ac9bac2018-01-15 16:33:44 +00001524 source = files(tasks.getByPath("compile_example_kotlin_${name}")).asFileTree
1525 destination = dexPath
1526 debug = false
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001527 }
1528 }
1529}
1530
Sebastien Hertzd3313772018-01-16 14:12:37 +01001531task buildKotlinR8TestResources {
1532 def examplesDir = file("src/test/kotlinR8TestResources")
1533 examplesDir.eachDir { dir ->
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001534 kotlin.Kotlinc.KotlinTargetVersion.values().each { kotlinTargetVersion ->
1535 def name = dir.getName()
1536 def taskName = "jar_kotlinR8TestResources_${name}_${kotlinTargetVersion}"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001537 def outputFile = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}.jar"
1538 def javaOutput = "build/test/kotlinR8TestResources/${kotlinTargetVersion}/${name}/java"
Denis Vnukovc22da842018-03-14 12:57:20 -07001539 def javaOutputJarName = "${name}.java.jar"
Morten Krogh-Jespersen6c1f2fa2019-01-04 13:23:13 +00001540 def javaOutputJarDir = "build/test/kotlinR8TestResources/${kotlinTargetVersion}"
Denis Vnukovc22da842018-03-14 12:57:20 -07001541 task "${taskName}Kotlin"(type: kotlin.Kotlinc) {
1542 source = fileTree(dir: file("${examplesDir}/${name}"),
1543 include: ['**/*.kt', '**/*.java'])
Sebastien Hertzfe97a712018-02-13 12:08:59 +01001544 destination = file(outputFile)
1545 targetVersion = kotlinTargetVersion
1546 }
Denis Vnukovc22da842018-03-14 12:57:20 -07001547 task "${taskName}Java"(type: JavaCompile) {
1548 source = fileTree(dir: file("${examplesDir}/${name}"), include: '**/*.java')
1549 destinationDir = file(javaOutput)
1550 classpath = sourceSets.main.compileClasspath
1551 sourceCompatibility = JavaVersion.VERSION_1_6
1552 targetCompatibility = JavaVersion.VERSION_1_6
1553 options.compilerArgs += ["-g", "-Xlint:-options"]
1554 }
1555 task "${taskName}JavaJar"(type: Jar, dependsOn: "${taskName}Java") {
1556 archiveName = javaOutputJarName
1557 destinationDir = file(javaOutputJarDir)
1558 from javaOutput
1559 include "**/*.class"
1560 }
1561 dependsOn "${taskName}Kotlin", "${taskName}JavaJar"
Sebastien Hertzd3313772018-01-16 14:12:37 +01001562 }
Sebastien Hertzd3313772018-01-16 14:12:37 +01001563 }
1564}
1565
Mads Ager418d1ca2017-05-22 09:35:49 +02001566task buildExamples {
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001567 if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) {
1568 logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " +
1569 "platform (" + OperatingSystem.current().getName() + ").")
Mads Ager418d1ca2017-05-22 09:35:49 +02001570 } else if (!OperatingSystem.current().isLinux()) {
1571 logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001572 "It is fully supported on Linux and partially supported on Mac OS and Windows")
Mads Ager418d1ca2017-05-22 09:35:49 +02001573 return;
1574 }
1575 dependsOn buildDebugTestResourcesJars
1576 dependsOn buildExampleJars
1577 dependsOn buildExampleAndroidNJars
1578 dependsOn buildExampleAndroidOJars
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +02001579 dependsOn buildExampleAndroidPJars
Mikaël Peltier61633d42017-10-13 16:51:06 +02001580 dependsOn buildExampleJava9Jars
clementberad7ab1dd2019-04-16 16:05:00 +02001581 dependsOn buildExampleJava11Jars
Søren Gjesse5b4ee0a2018-01-30 13:46:39 +01001582 dependsOn buildExampleAndroidApi
Mads Ager418d1ca2017-05-22 09:35:49 +02001583 def examplesDir = file("src/test/examples")
Yohann Rousself820a572017-05-31 20:25:51 +02001584 def noDexTests = [
1585 "multidex",
1586 "multidex002",
1587 "multidex004",
1588 ]
Mads Ager418d1ca2017-05-22 09:35:49 +02001589 examplesDir.eachDir { dir ->
1590 def name = dir.getName();
Yohann Rousself820a572017-05-31 20:25:51 +02001591 if (!(name in noDexTests)) {
1592 dependsOn "dex_example_${name}"
1593 def exampleOutputDir = file("build/test/examples/" + name);
1594 def dexPath = file("${exampleOutputDir}")
1595 def debug = (name == "throwing")
1596 if (!dexPath.exists()) {
1597 dexPath.mkdirs()
1598 }
1599 task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") {
1600 source = files(tasks.getByPath("jar_example_${name}")).asFileTree
1601 destination = dexPath
1602 debug = debug
1603 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001604 }
1605 }
1606}
1607
1608task buildSmali {
1609 def smaliDir = file("src/test/smali")
1610 smaliDir.eachDirRecurse() { dir ->
1611 def name = dir.getName();
1612 def relativeDir = smaliDir.toPath().relativize(dir.toPath());
1613 def smaliOutputDir = file("build/test/smali/" + relativeDir);
1614 smaliOutputDir.mkdirs()
1615 outputs.dir smaliOutputDir
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001616 def taskName = "smali_build_${relativeDir.toString().replace('/', '_').replace('\\', '_')}"
Mads Ager418d1ca2017-05-22 09:35:49 +02001617 def smaliFiles = fileTree(dir: dir, include: '*.smali')
1618 def javaFiles = fileTree(dir: dir, include: '*.java')
1619 def destDir = smaliOutputDir;
1620 def destFile = destDir.toPath().resolve("${name}.dex").toFile()
1621 def intermediateFileName = "${name}-intermediate.dex";
1622 def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile()
1623 if (javaFiles.empty) {
1624 if (!smaliFiles.empty) {
1625 dependsOn "${taskName}_smali"
1626 task "${taskName}_smali"(type: smali.Smali) {
1627 source = smaliFiles
1628 destination = destFile
1629 }
1630 }
1631 } else {
1632 dependsOn "${taskName}_dexmerger"
1633 task "${taskName}_smali"(type: smali.Smali) {
1634 source = smaliFiles
1635 destination = intermediateFile
1636 }
1637 task "${taskName}_java"(type: JavaCompile) {
1638 source = javaFiles
1639 destinationDir destDir
1640 classpath = sourceSets.main.compileClasspath
1641 sourceCompatibility = JavaVersion.VERSION_1_7
1642 targetCompatibility = JavaVersion.VERSION_1_7
1643 options.compilerArgs += ["-Xlint:-options"]
1644 }
1645 task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") {
1646 archiveName = "Test.jar"
1647 destinationDir = destDir
1648 from fileTree(dir: destDir, include: 'Test.class')
1649 }
1650 task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") {
1651 source = fileTree(dir: destDir, include: 'Test.jar')
1652 destination = destDir
1653 }
1654 task "${taskName}_dexmerger"(
1655 type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
1656 source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
1657 destination = destFile
1658 }
1659 }
1660 }
1661}
1662
1663tasks.withType(Test) {
Rico Windc56f21c2019-03-12 07:29:57 +01001664 println("NOTE: Number of processors " + Runtime.runtime.availableProcessors())
Mads Ager418d1ca2017-05-22 09:35:49 +02001665 def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK')
1666 def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3
1667 // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
Rico Wind3defc8d2019-03-27 08:07:31 +01001668 maxParallelForks = (Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1) + 1
Rico Windc56f21c2019-03-12 07:29:57 +01001669 println("NOTE: Max parallel forks " + maxParallelForks)
Mads Ager418d1ca2017-05-22 09:35:49 +02001670 forkEvery = 0
Søren Gjesseaf1c5e22017-06-15 12:24:03 +02001671 if (project.hasProperty('disable_assertions')) {
1672 enableAssertions = false
1673 }
Ian Zerny16c2f2d2019-02-19 07:25:11 +01001674 // TODO(b/124091860): Increase the max heap size to avoid OOM when running tests.
Rico Wind97b0a992019-08-30 11:09:15 +02001675 if (project.hasProperty('test_xmx')) {
1676 maxHeapSize = project.property('test_xmx')
1677 } else {
1678 maxHeapSize = "4G"
1679 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001680}
1681
1682task buildPreNJdwpTestsJar(type: Jar) {
1683 baseName = 'jdwp-tests-preN'
1684 from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
1685 // Exclude the classes containing java8
1686 exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class'
1687 exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class'
1688 includeEmptyDirs = false
1689}
1690
Ian Zerny74143162017-11-24 13:46:35 +01001691task buildPreNJdwpTestsDex(type: Exec, dependsOn: "buildPreNJdwpTestsJar") {
1692 def inFile = buildPreNJdwpTestsJar.archivePath
1693 def outFile = new File(buildPreNJdwpTestsJar.destinationDir, buildPreNJdwpTestsJar.baseName + '-dex.jar')
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001694 inputs.files files(inFile)
Ian Zerny74143162017-11-24 13:46:35 +01001695 outputs.file outFile
1696 if (OperatingSystem.current().isWindows()) {
1697 executable file("tools/windows/dx/bin/dx.bat")
1698 } else if (OperatingSystem.current().isMacOsX()) {
1699 executable file("tools/mac/dx/bin/dx");
1700 } else {
1701 executable file("tools/linux/dx/bin/dx");
1702 }
1703 args "--dex"
1704 args "--output=${outFile}"
1705 args inFile
1706}
1707
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001708task getJarsFromSupportLibs(type: GetJarsFromConfiguration) {
1709 setConfiguration(configurations.supportLibs)
Yohann Roussel126f6872017-08-03 16:25:32 +02001710}
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001711def getR8LibSourceTask() {
1712 if (project.hasProperty('r8lib')) {
1713 return R8NoManifest
1714 } else if (project.hasProperty('r8lib_no_deps')) {
1715 return R8NoManifestNoDeps
1716 }
1717 return null
1718}
Yohann Roussel126f6872017-08-03 16:25:32 +02001719
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001720def getR8LibTask() {
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001721 if (project.hasProperty('r8lib')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001722 return R8Lib
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001723 } else if (project.hasProperty('r8lib_no_deps')) {
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001724 return R8LibNoDeps
Morten Krogh-Jespersenb39fbe52018-12-17 14:58:48 +01001725 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001726 return null
1727}
1728
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001729task generateR8TestKeepRules {
1730 def path = "build/generated/r8tests-keep.txt"
1731 outputs.file path
1732 if (getR8LibTask() != null) {
1733 dependsOn getR8LibTask()
1734 doLast {
1735 file(path).write """-keep class ** { *; }
1736-dontshrink
1737-dontoptimize
1738-keepattributes *
1739-applymapping ${getR8LibTask().outputs.files[0]}.map
1740"""
1741 }
1742 }
1743}
1744
1745task buildR8LibCfTestDeps(type: Exec) {
1746 if (getR8LibTask() == null) {
1747 return
1748 }
1749 def outputPath = "build/libs/r8libtestdeps-cf.jar"
1750 dependsOn downloadDeps
1751 dependsOn getR8LibTask()
1752 dependsOn getR8LibSourceTask()
1753 dependsOn generateR8TestKeepRules
1754 dependsOn testJar
1755 // Take all .jar files as libraries and append the generated test classes in classes/java/test.
1756 def addedLibraries = sourceSets.test.runtimeClasspath.findAll { pkg ->
1757 return pkg.toString().endsWith(".jar")
1758 } + ["${buildDir}/classes/java/test"]
1759 inputs.files testJar.outputs.files +
1760 generateR8TestKeepRules.outputs.files +
1761 getR8LibTask().outputs
1762 commandLine = r8CfCommandLine(
1763 testJar.outputs.files[0],
1764 outputPath,
1765 [generateR8TestKeepRules.outputs.files[0]],
1766 ["--debug", "--classpath", getR8LibSourceTask().outputs.files[0]],
1767 getR8LibSourceTask().outputs.files + addedLibraries)
1768 workingDir = projectDir
1769 outputs.file outputPath
1770}
1771
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001772task configureTestForR8Lib(type: Copy) {
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001773 dependsOn testJar
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001774 inputs.files buildR8LibCfTestDeps.outputs
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001775 if (getR8LibTask() != null) {
Morten Krogh-Jespersene0616982019-01-03 12:42:36 +01001776 dependsOn getR8LibTask()
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001777 delete r8LibTestPath
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001778 from zipTree(buildR8LibCfTestDeps.outputs.files[0])
1779 def examplesDir = file("build/test")
1780 examplesDir.eachDir { dir ->
1781 from ("${buildDir}/test/${dir.getName()}/classes")
1782 }
1783 from ("${buildDir}/runtime/examples")
Morten Krogh-Jespersene28db462019-01-09 13:32:15 +01001784 into r8LibTestPath
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001785 }
1786 outputs.dir r8LibTestPath
Morten Krogh-Jespersen807b15f2018-12-17 14:24:22 +01001787}
1788
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001789def printStackTrace(TestResult result) {
1790 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1791 def out = new StringBuffer()
1792 def err = new StringBuffer()
Rico Windacc291f2019-03-06 11:36:33 +01001793 def command = "python tools/retrace.py"
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001794 def header = "RETRACED STACKTRACE";
1795 if (System.getenv('BUILDBOT_BUILDERNAME') != null
1796 && !System.getenv('BUILDBOT_BUILDERNAME').endsWith("_release")) {
1797 header += ": (${command} --commit_hash ${System.getenv('BUILDBOT_REVISION')})";
1798 }
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001799 out.append("\n--------------------------------------\n")
Morten Krogh-Jespersen046b18e2019-01-17 15:40:14 +01001800 out.append("${header}\n")
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001801 out.append("--------------------------------------\n")
1802 Process process = command.execute()
1803 def processIn = new PrintStream(process.getOut())
1804 process.consumeProcessOutput(out, err)
1805 result.exception.printStackTrace(processIn)
1806 processIn.flush()
1807 processIn.close()
1808 process.waitFor()
1809 out.append("\n\n--------------------------------------\n")
1810 out.append("OBFUSCATED STACKTRACE\n")
1811 out.append("--------------------------------------\n")
1812 result.exceptions.add(0, new Exception(out.toString()))
1813 } else {
1814 result.exception.printStackTrace()
1815 }
1816}
1817
Mads Ager418d1ca2017-05-22 09:35:49 +02001818test {
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +02001819 if (project.hasProperty('generate_golden_files_to')) {
1820 systemProperty 'generate_golden_files_to', project.property('generate_golden_files_to')
1821 assert project.hasProperty('HEAD_sha1')
1822 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1823 }
1824
1825 if (project.hasProperty('use_golden_files_in')) {
1826 systemProperty 'use_golden_files_in', project.property('use_golden_files_in')
1827 assert project.hasProperty('HEAD_sha1')
1828 systemProperty 'test_git_HEAD_sha1', project.property('HEAD_sha1')
1829 }
Ian Zerny4b0de282019-06-28 09:32:24 +02001830
Ivan Gavrilovic635c7e52017-12-01 15:10:45 +00001831 dependsOn getJarsFromSupportLibs
Morten Krogh-Jespersen75c38f72018-10-05 09:02:11 +02001832 // R8.jar is required for running bootstrap tests.
1833 dependsOn R8
Mads Ager418d1ca2017-05-22 09:35:49 +02001834 testLogging.exceptionFormat = 'full'
1835 if (project.hasProperty('print_test_stdout')) {
1836 testLogging.showStandardStreams = true
1837 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001838 if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') {
Ian Zerny324d7612019-03-20 10:52:28 +01001839 println "NOTE: Running with non default vm: " + project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001840 systemProperty 'dex_vm', project.property('dex_vm')
Mads Ager418d1ca2017-05-22 09:35:49 +02001841 }
Tamas Kenez0cad51c2017-08-21 14:42:01 +02001842
Ian Zerny324d7612019-03-20 10:52:28 +01001843 // Forward runtime configurations for test parameters.
1844 if (project.hasProperty('runtimes')) {
1845 println "NOTE: Running with runtimes: " + project.property('runtimes')
1846 systemProperty 'runtimes', project.property('runtimes')
Ian Zerny4dfd5a52019-03-12 07:56:11 +01001847 }
1848
Christoffer Quist Adamsen748e4662019-08-23 14:53:49 +02001849 if (project.hasProperty('slow_tests')) {
1850 systemProperty 'slow_tests', project.property('slow_tests')
1851 }
1852
Mads Ager418d1ca2017-05-22 09:35:49 +02001853 if (project.hasProperty('one_line_per_test')) {
1854 beforeTest { desc ->
1855 println "Start executing test ${desc.name} [${desc.className}]"
1856 }
1857 afterTest { desc, result ->
Rico Windf88b6be2018-12-11 15:14:05 +01001858 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001859 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001860 }
Rico Windda6836e2018-12-07 12:32:03 +01001861 if (project.hasProperty('update_test_timestamp')) {
1862 file(project.getProperty('update_test_timestamp')).text = new Date().getTime()
1863 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001864 println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
1865 }
Rico Windf88b6be2018-12-11 15:14:05 +01001866 } else {
1867 afterTest { desc, result ->
1868 if (result.resultType == TestResult.ResultType.FAILURE) {
Morten Krogh-Jespersen017a7002019-01-10 14:14:17 +01001869 printStackTrace(result)
Rico Windf88b6be2018-12-11 15:14:05 +01001870 }
1871 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001872 }
1873 if (project.hasProperty('no_internal')) {
1874 exclude "com/android/tools/r8/internal/**"
Christoffer Quist Adamsen74288f02019-06-14 12:30:17 +02001875 } else {
1876 dependsOn buildExamplesProto
Mads Ager418d1ca2017-05-22 09:35:49 +02001877 }
1878 if (project.hasProperty('only_internal')) {
1879 include "com/android/tools/r8/internal/**"
1880 }
Rico Wind4e218292019-03-07 12:44:49 +01001881
Mads Ager418d1ca2017-05-22 09:35:49 +02001882 if (project.hasProperty('tool')) {
1883 if (project.property('tool') == 'r8') {
Rico Windf02167a2019-03-15 12:27:03 +01001884 exclude "com/android/tools/r8/jctf/**"
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001885 } else if (project.property('tool') == 'd8') {
Rico Windf02167a2019-03-15 12:27:03 +01001886 if (project.hasProperty('only_jctf')) {
1887 include "com/android/tools/r8/jctf/d8/**"
1888 } else {
Rico Wind819f7c52019-03-20 09:44:27 +01001889 // Don't run anything, deprecated
1890 println "Running with deprecated tool d8, not running any tests"
1891 include ""
Rico Windf02167a2019-03-15 12:27:03 +01001892 }
Tamas Kenezcfb2c052018-10-12 11:03:57 +02001893 } else {
1894 assert(project.property('tool') == 'r8cf')
Rico Windf02167a2019-03-15 12:27:03 +01001895 assert(project.hasProperty('only_jctf'))
1896 include "com/android/tools/r8/jctf/r8cf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001897 }
1898 }
1899 if (!project.hasProperty('all_tests')) {
1900 exclude "com/android/tools/r8/art/dx/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001901 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001902 if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) {
Stephan Herhutea6ee582017-05-23 13:14:34 +02001903 exclude "com/android/tools/r8/jctf/**"
Mads Ager418d1ca2017-05-22 09:35:49 +02001904 }
Rico Wind8e2f7e42019-02-21 10:13:21 +01001905 if (project.hasProperty('shard_count') ) {
1906 assert project.hasProperty('shard_number')
1907 int shard_count = project.getProperty('shard_count') as Integer
1908 int shard_number = project.getProperty('shard_number') as Integer
1909 assert shard_count < 65536
1910 assert shard_number < shard_count
1911 exclude {
1912 entry ->
1913 // Don't leave out directories. Leaving out a directory means all entries below.
1914 if (entry.file.isDirectory()) {
1915 return false
1916 }
1917 def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
1918 int hash = Integer.parseInt(first4, 16)
1919 return hash % shard_count != shard_number
1920 }
1921 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001922 if (project.hasProperty('jctf_compile_only')) {
1923 println "JCTF: compiling only"
1924 systemProperty 'jctf_compile_only', '1'
1925 }
Tamas Kenezb77b7d82017-08-17 14:05:16 +02001926 if (project.hasProperty('test_dir')) {
1927 systemProperty 'test_dir', project.property('test_dir')
1928 }
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001929 if (project.hasProperty('r8lib') || project.hasProperty('r8lib_no_deps')) {
1930 dependsOn configureTestForR8Lib
Morten Krogh-Jespersenf0f528d2019-08-19 19:25:03 +02001931 // R8lib should be used instead of the main output and all the tests in r8 should be mapped
1932 // and exists in r8LibtestPath.
1933 classpath = sourceSets.test.runtimeClasspath.filter {
1934 !it.getAbsolutePath().contains("/build/")
1935 }
1936 classpath += files([r8LibPath, r8LibTestPath])
Ian Zerny5fffb0a2019-02-11 13:54:22 +01001937 testClassesDirs = files(r8LibTestPath)
Morten Krogh-Jespersen7df24322018-12-21 13:39:54 +01001938 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001939 if (OperatingSystem.current().isLinux()
1940 || OperatingSystem.current().isMacOsX()
1941 || OperatingSystem.current().isWindows()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02001942 if (OperatingSystem.current().isMacOsX()) {
1943 logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " +
1944 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " +
1945 "See tools/docker/README.md for details.")
1946 }
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001947 if (OperatingSystem.current().isWindows()) {
1948 logger.lifecycle("WARNING: Testing in only partially supported on Windows. " +
1949 "Art only runs on Linux and tests requiring Art will be skipped")
1950 }
Mads Ager418d1ca2017-05-22 09:35:49 +02001951 dependsOn downloadDeps
1952 dependsOn buildExamples
Mikaël Peltier3c8b6ea2017-12-12 13:00:21 +01001953 dependsOn buildExamplesKotlin
Sebastien Hertzd3313772018-01-16 14:12:37 +01001954 dependsOn buildKotlinR8TestResources
Mads Ager418d1ca2017-05-22 09:35:49 +02001955 dependsOn buildSmali
1956 dependsOn jctfCommonJar
1957 dependsOn jctfTestsClasses
1958 dependsOn buildDebugInfoExamplesDex
1959 dependsOn buildPreNJdwpTestsJar
Mathias Ravcd795072018-03-22 12:47:32 +01001960 dependsOn buildPreNJdwpTestsDex
clementbera4f9c2a92019-07-09 08:50:37 +02001961 dependsOn buildJdk11TimeTestsJar
clementberaa92e3cd2019-07-12 14:13:22 +02001962 dependsOn provideArtFrameworksDependencies
Mads Ager418d1ca2017-05-22 09:35:49 +02001963 } else {
1964 logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " +
Jean-Marie Henaff39587a82017-06-08 15:20:13 +02001965 "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.")
Mads Ager418d1ca2017-05-22 09:35:49 +02001966 }
1967}
1968
1969// The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage.
1970//
1971// To build and upload a new set of the Art tests for use with R8 follow these steps:
1972//
1973// First of all an Android checkout is required. Currently it must be located
1974// in $HOME/android/master.
1975//
1976// TODO(ricow): simplify this
1977//
1978// Before: update the checked in art, see scripts/update-host-art.sh
1979//
1980// 1. Get an android checkout in $HOME/android/master and apply the patch from
1981// https://android-review.googlesource.com/#/c/294187/
1982//
1983// 2. run the following commands in the Android checkout directory:
1984//
1985// source build/envsetup.sh
Søren Gjesse34b77732017-07-07 13:56:21 +02001986// lunch aosp_angler-userdebug # or lunch aosp_angler-eng
1987// m desugar
1988// m -j30 test-art-host
1989// DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld
1990//
1991// Without running the test.py command the classes.jar file used by desugar in
1992// $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/
1993// seems to be missing - there is probably also a make target to build it more directly
Mads Ager418d1ca2017-05-22 09:35:49 +02001994//
1995// 3. In the R8 project root directory, make sure we have a clean state before starting:
1996// tools/gradle.py downloadDeps
1997// tools/gradle.py clean
1998// rm -rf tests/art
1999//
2000// 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 +02002001// Make sure you have smali on your path, please use the build binary in the
2002// out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1,
2003// if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might
2004// 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 +02002005// After Android O, Jack is no longer alive, do not forget to uncomment call to buildArtTest for
2006// Jack if you build an android version using Jack.
Mads Ager418d1ca2017-05-22 09:35:49 +02002007//
Søren Gjesse34b77732017-07-07 13:56:21 +02002008// PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests
Mads Ager418d1ca2017-05-22 09:35:49 +02002009//
2010// 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in
2011// skippedTests with an explanation. Rerun from step 3.
2012//
2013// 5. Run the tests:
2014// tools/gradle.py clean
2015// tools/test.py
2016//
Søren Gjesse34b77732017-07-07 13:56:21 +02002017// 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note
2018// that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to
2019// failuresToTriage.
Mads Ager418d1ca2017-05-22 09:35:49 +02002020//
Søren Gjesse34b77732017-07-07 13:56:21 +02002021// 6. To upload a new version to Google Cloud Storage:
Mads Ager418d1ca2017-05-22 09:35:49 +02002022// cd tests
2023// upload_to_google_storage.py -a --bucket r8-deps art
Søren Gjesse34b77732017-07-07 13:56:21 +02002024//
2025// 7. Update the manifest file describing the Android repo used:
2026// repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r
Mads Ager418d1ca2017-05-22 09:35:49 +02002027
Mads Ager418d1ca2017-05-22 09:35:49 +02002028def androidCheckoutDir = file("${System.env.HOME}/android/master")
Mads Ager418d1ca2017-05-22 09:35:49 +02002029
2030def artTestDir = file("${androidCheckoutDir}/art/test")
2031
2032if (project.hasProperty('android_source')) {
2033 task buildArtTests {
2034 outputs.upToDateWhen { false }
2035 def toBeTriaged = [
2036 "903-hello-tagging",
2037 "904-object-allocation",
2038 "905-object-free",
2039 "906-iterate-heap",
2040 "907-get-loaded-classes",
2041 "908-gc-start-finish",
2042 "954-invoke-polymorphic-verifier",
2043 "955-methodhandles-smali",
2044 "596-monitor-inflation",
2045 ]
2046 def skippedTests = toBeTriaged + [
2047 // This test produces no jar.
2048 "000-nop",
2049 // This does not build, as it tests the error when the application exceeds more
2050 // than 65536 methods
2051 "089-many-methods",
2052 // Requires some jack beta jar
2053 "956-methodhandles",
2054 ]
2055
2056 def skippedTestsDx = [
2057 // Tests with custom build scripts, where javac is not passed the options
2058 // -source 1.7 -target 1.7.
2059 "462-checker-inlining-across-dex-files",
2060 "556-invoke-super",
2061 "569-checker-pattern-replacement",
2062 // These tests use jack even when --build-with-javac-dx is specified.
2063 "004-JniTest",
2064 "048-reflect-v8",
2065 "146-bad-interface",
2066 "563-checker-invoke-super",
2067 "580-checker-string-fact-intrinsics", // java.lang.StringFactory
2068 "604-hot-static-interface",
2069 "957-methodhandle-transforms",
2070 "958-methodhandle-emulated-stackframe",
2071 "959-invoke-polymorphic-accessors",
2072 "961-default-iface-resolution-gen",
2073 "962-iface-static",
2074 "963-default-range-smali",
2075 "964-default-iface-init-gen",
2076 "965-default-verify",
2077 "966-default-conflict",
2078 "967-default-ame",
2079 "968-default-partial-compile-gen",
2080 "969-iface-super",
2081 "970-iface-super-resolution-gen",
2082 "971-iface-super",
2083 // These tests does not build with --build-with-javac-dx
2084 "004-NativeAllocations", // Javac error
2085 "031-class-attributes",
2086 "138-duplicate-classes-check",
2087 "157-void-class", // Javac error
2088 "580-checker-string-factory-intrinsics",
2089 "612-jit-dex-cache",
2090 "613-inlining-dex-cache",
2091 "900-hello-plugin", // --experimental agents
2092 "901-hello-ti-agent", // --experimental agents
2093 "902-hello-transformation", // --experimental agents
2094 "909-attach-agent", // --experimental agents
2095 "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda
2096 "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references
2097 "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda
2098 "960-default-smali", // --experimental default-methods
2099 // These tests force the build to use jack
2100 "953-invoke-polymorphic-compiler",
2101 "958-methodhandle-stackframe",
2102 ]
2103
2104 def artTestBuildDir = file("${projectDir}/tests/art")
2105
2106 if (androidCheckoutDir.exists()) {
2107 dependsOn downloadDeps
2108 artTestBuildDir.mkdirs()
Mads Ager418d1ca2017-05-22 09:35:49 +02002109 artTestDir.eachDir { dir ->
2110 def name = dir.getName();
2111 def markerFile = dir.toPath().resolve("info.txt").toFile();
2112 if (markerFile.exists() && !(name in skippedTests)) {
2113 if (!(name in skippedTestsDx)) {
Rico Windde2af6c2019-03-26 15:21:08 +01002114 dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir);
Mads Ager418d1ca2017-05-22 09:35:49 +02002115 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002116 }
2117 }
2118 }
2119 doFirst {
2120 if (!androidCheckoutDir.exists()) {
2121 throw new InvalidUserDataException(
2122 "This task requires an Android checkout in ${androidCheckoutDir}");
Mads Ager418d1ca2017-05-22 09:35:49 +02002123 }
2124 }
2125 doLast {
2126 copy {
2127 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64")
2128 into file("${artTestBuildDir}/lib64")
2129 include 'lib*.so'
2130 }
2131 copy {
2132 from file("${androidCheckoutDir}/out/host/linux-x86/lib64")
2133 into file("${artTestBuildDir}/lib64")
2134 include 'libart.so'
2135 include 'libbacktrace.so'
2136 include 'libbase.so'
2137 include 'libc++.so'
2138 include 'libcutils.so'
2139 include 'liblz4.so'
2140 include 'liblzma.so'
2141 include 'libnativebridge.so'
2142 include 'libnativeloader.so'
2143 include 'libsigchain.so'
2144 include 'libunwind.so'
2145 include 'libziparchive.so'
2146 }
2147 copy {
2148 from file("${androidCheckoutDir}/out/host/linux-x86/nativetest")
2149 into file("${artTestBuildDir}/lib")
2150 include 'lib*.so'
2151 }
2152 copy {
2153 from file("${androidCheckoutDir}/out/host/linux-x86/lib")
2154 into file("${artTestBuildDir}/lib")
2155 include 'libart.so'
2156 include 'libbacktrace.so'
2157 include 'libbase.so'
2158 include 'libc++.so'
2159 include 'libcutils.so'
2160 include 'liblz4.so'
2161 include 'liblzma.so'
2162 include 'libnativebridge.so'
2163 include 'libnativeloader.so'
2164 include 'libsigchain.so'
2165 include 'libunwind.so'
2166 include 'libziparchive.so'
2167 }
2168 }
2169 }
2170}
2171
Rico Windde2af6c2019-03-26 15:21:08 +01002172def buildArtTest(androidCheckoutDir, artTestBuildDir, dir) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002173 def artTestDir = file("${androidCheckoutDir}/art/test")
2174 def artRunTestScript = file("${artTestDir}/run-test")
2175 def dxExecutable = new File("tools/linux/dx/bin/dx");
Jean-Marie Henaff34d85f72017-06-14 10:32:04 +02002176 def dexMergerExecutable = Utils.dexMergerExecutable()
Mads Ager418d1ca2017-05-22 09:35:49 +02002177
Søren Gjesse34b77732017-07-07 13:56:21 +02002178 def name = dir.getName()
Rico Windde2af6c2019-03-26 15:21:08 +01002179 def buildTask = "build_art_test_dx_${name}"
2180 def sanitizeTask = "sanitize_art_test_dx_${name}"
2181 def copyCheckTask = "copy_check_art_test_dx_${name}"
2182 def smaliToDexTask = "smali_to_dex_dx_${name}"
Mads Ager418d1ca2017-05-22 09:35:49 +02002183
2184 def buildInputs = fileTree(dir: dir, include: '**/*')
Rico Windde2af6c2019-03-26 15:21:08 +01002185 def testDir = file("${artTestBuildDir}/dx/${name}")
Mads Ager418d1ca2017-05-22 09:35:49 +02002186 def outputJar = testDir.toPath().resolve("${name}.jar").toFile()
2187 testDir.mkdirs()
Rico Windde2af6c2019-03-26 15:21:08 +01002188 task "$buildTask"(type: Exec) {
2189 outputs.upToDateWhen { false }
2190 inputs.file buildInputs
2191 executable "${artRunTestScript}"
2192 args "--host"
2193 args "--build-only"
2194 args "--build-with-javac-dx"
2195 args "--output-path", "${testDir}"
2196 args "${name}"
2197 environment DX: "${dxExecutable.absolutePath}"
2198 environment DXMERGER: "${dexMergerExecutable.absolutePath}"
2199 environment ANDROID_BUILD_TOP: "${androidCheckoutDir}"
2200 outputs.file outputJar
Mads Ager418d1ca2017-05-22 09:35:49 +02002201 }
2202 task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) {
2203 outputs.upToDateWhen { false }
2204 executable "/bin/bash"
2205 args "-c"
2206 args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" +
2207 " ${testDir}/classes-ex ${testDir}/check"
2208 }
2209
2210 task "${smaliToDexTask}"(type: Exec) {
Mikaël Peltiere116cb62017-10-05 10:50:30 +02002211 // Directory that contains smali files is either smali, or smali/art
2212 def smali_dir = file("${dir}/smali/art")
2213 if (smali_dir.exists()) {
2214 workingDir "${testDir}/smali/art"
2215 } else {
2216 workingDir "${testDir}/smali"
2217 }
Mads Ager418d1ca2017-05-22 09:35:49 +02002218 executable "/bin/bash"
Søren Gjesse34b77732017-07-07 13:56:21 +02002219 // This is the command line options for smali prior to 2.2.1, where smali got a new
2220 // command line interface.
2221 args "-c", "smali a *.smali"
2222 // This is the command line options for smali 2.2.1 and later.
2223 // args "-c", "smali -o out.dex *.smali"
Mads Ager418d1ca2017-05-22 09:35:49 +02002224 }
2225
2226 task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) {
2227 def smali_dir = file("${dir}/smali")
2228 outputs.upToDateWhen { false }
Rico Windde2af6c2019-03-26 15:21:08 +01002229 if (smali_dir.exists()) {
Mads Ager418d1ca2017-05-22 09:35:49 +02002230 dependsOn smaliToDexTask
2231 }
2232 from("${artTestDir}/${name}") {
2233 include 'check'
2234 }
2235 into testDir
2236 }
2237
2238 return copyCheckTask
2239}
2240
2241task javadocD8(type: Javadoc) {
Ian Zerny850f13d2018-01-04 11:25:38 +01002242 title "D8 API"
Mads Ager418d1ca2017-05-22 09:35:49 +02002243 classpath = sourceSets.main.compileClasspath
2244 source = sourceSets.main.allJava
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002245 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002246 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002247 include '**/com/android/tools/r8/BaseCommand.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002248 include '**/com/android/tools/r8/BaseCompilerCommand.java'
Yohann Rousselb16d0f62017-10-09 16:08:09 +02002249 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002250 include '**/com/android/tools/r8/CompilationFailedException.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002251 include '**/com/android/tools/r8/CompilationMode.java'
2252 include '**/com/android/tools/r8/D8.java'
2253 include '**/com/android/tools/r8/D8Command.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002254 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2255 include '**/com/android/tools/r8/DexFilePerClassFileConsumer.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002256 include '**/com/android/tools/r8/Diagnostic.java'
2257 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002258 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2259 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002260 include '**/com/android/tools/r8/ProgramConsumer.java'
2261 include '**/com/android/tools/r8/ProgramResource.java'
2262 include '**/com/android/tools/r8/ProgramResourceProvider.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002263 include '**/com/android/tools/r8/Resource.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002264 include '**/com/android/tools/r8/ResourceException.java'
2265 include '**/com/android/tools/r8/StringConsumer.java'
2266 include '**/com/android/tools/r8/StringResource.java'
2267 include '**/com/android/tools/r8/Version.java'
2268 include '**/com/android/tools/r8/origin/*.java'
2269}
2270
2271task javadocR8(type: Javadoc) {
2272 title "R8 API"
2273 classpath = sourceSets.main.compileClasspath
2274 source = sourceSets.main.allJava
2275 include '**/com/android/tools/r8/ArchiveClassFileProvider.java'
2276 include '**/com/android/tools/r8/ArchiveProgramResourceProvider.java'
2277 include '**/com/android/tools/r8/BaseCommand.java'
2278 include '**/com/android/tools/r8/BaseCompilerCommand.java'
2279 include '**/com/android/tools/r8/ClassFileConsumer.java'
2280 include '**/com/android/tools/r8/ClassFileResourceProvider.java'
2281 include '**/com/android/tools/r8/CompilationFailedException.java'
2282 include '**/com/android/tools/r8/CompilationMode.java'
2283 include '**/com/android/tools/r8/R8.java'
2284 include '**/com/android/tools/r8/R8Command.java'
2285 include '**/com/android/tools/r8/DexIndexedConsumer.java'
2286 include '**/com/android/tools/r8/Diagnostic.java'
2287 include '**/com/android/tools/r8/DiagnosticsHandler.java'
Ian Zernyef028f52018-01-08 14:23:17 +01002288 include '**/com/android/tools/r8/DirectoryClassFileProvider.java'
2289 include '**/com/android/tools/r8/OutputMode.java'
Ian Zerny850f13d2018-01-04 11:25:38 +01002290 include '**/com/android/tools/r8/ProgramConsumer.java'
2291 include '**/com/android/tools/r8/ProgramResource.java'
2292 include '**/com/android/tools/r8/ProgramResourceProvider.java'
2293 include '**/com/android/tools/r8/Resource.java'
2294 include '**/com/android/tools/r8/ResourceException.java'
2295 include '**/com/android/tools/r8/StringConsumer.java'
2296 include '**/com/android/tools/r8/StringResource.java'
2297 include '**/com/android/tools/r8/Version.java'
Yohann Roussel078c9942017-11-28 15:55:46 +01002298 include '**/com/android/tools/r8/origin/*.java'
Mads Ager418d1ca2017-05-22 09:35:49 +02002299}
Søren Gjesse39a909a2017-10-12 09:49:20 +02002300
2301task copyMavenDeps(type: Copy) {
2302 from configurations.compile into "$buildDir/deps"
Morten Krogh-Jespersen75773302019-01-07 09:45:08 +01002303 from configurations.compileClasspath into "$buildDir/deps"
Søren Gjesse39a909a2017-10-12 09:49:20 +02002304 from configurations.testCompile into "$buildDir/deps"
2305}
Mikaël Peltier61633d42017-10-13 16:51:06 +02002306
Rico Wind23a05112019-03-27 08:00:44 +01002307task printMavenDeps {
2308 // Only actually print to stdout when we are updating.
2309 if (project.hasProperty('updatemavendeps')) {
2310 for (Configuration config : configurations) {
2311 if (!config.isCanBeResolved()) {
2312 continue
2313 }
2314 def componentIds = config.incoming.resolutionResult.allDependencies.collect {
2315 it.selected.id
2316 }
2317 def result = dependencies.createArtifactResolutionQuery()
2318 .forComponents(componentIds)
2319 .withArtifacts(MavenModule, MavenPomArtifact)
2320 .execute()
2321 for (component in result.resolvedComponents) {
2322 component.getArtifacts(MavenPomArtifact).each {
2323 println "POM: ${it.file} ${component.id}"
2324 }
2325 }
2326 config.each {
2327 println "JAR: ${it}"
2328 }
2329 }
2330 }
2331}