Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // 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. |
Jean-Marie Henaff | 34d85f7 | 2017-06-14 10:32:04 +0200 | [diff] [blame] | 4 | import org.gradle.internal.os.OperatingSystem |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 5 | import utils.Utils |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 6 | |
| 7 | apply plugin: 'java' |
| 8 | apply plugin: 'idea' |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 9 | apply plugin: 'com.google.protobuf' |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 10 | apply plugin: 'com.github.johnrengelman.shadow' |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 11 | apply plugin: 'com.cookpad.android.licensetools' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 12 | |
| 13 | apply from: 'copyAdditionalJctfCommonFiles.gradle' |
| 14 | |
Sebastien Hertz | e2687b6 | 2017-07-25 11:16:04 +0200 | [diff] [blame] | 15 | |
| 16 | if (project.hasProperty('with_code_coverage')) { |
| 17 | apply plugin: 'jacoco' |
| 18 | } |
| 19 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 20 | repositories { |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 21 | maven { url 'https://maven.google.com' } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 22 | mavenCentral() |
| 23 | } |
| 24 | |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 25 | buildscript { |
| 26 | repositories { |
| 27 | mavenCentral() |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 28 | jcenter() |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 29 | } |
| 30 | dependencies { |
| 31 | classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1' |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 32 | classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1' |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 33 | classpath 'com.cookpad.android.licensetools:license-tools-plugin:0.23.0' |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 37 | // Custom source set for example tests and generated tests. |
| 38 | sourceSets { |
| 39 | test { |
| 40 | java { |
| 41 | srcDirs = [ |
| 42 | 'src/test/java', |
| 43 | 'build/generated/test/java', |
| 44 | ] |
| 45 | } |
| 46 | } |
| 47 | debugTestResources { |
| 48 | java { |
| 49 | srcDirs = ['src/test/debugTestResources'] |
| 50 | } |
| 51 | output.resourcesDir = 'build/classes/debugTestResources' |
| 52 | } |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 53 | debugTestResourcesJava8 { |
| 54 | java { |
| 55 | srcDirs = ['src/test/debugTestResourcesJava8'] |
| 56 | } |
| 57 | output.resourcesDir = 'build/classes/debugTestResourcesJava8' |
| 58 | } |
Sebastien Hertz | 1d7702b | 2017-08-18 09:07:27 +0200 | [diff] [blame] | 59 | debugTestResourcesKotlin { |
| 60 | java { |
| 61 | srcDirs = ['src/test/debugTestResourcesKotlin'] |
| 62 | } |
| 63 | output.resourcesDir = 'build/classes/debugTestResourcesKotlin' |
| 64 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 65 | examples { |
| 66 | java { |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 67 | srcDirs = ['src/test/examples', 'build/generated/source/proto/examples/javalite/' ] |
| 68 | } |
| 69 | proto { |
| 70 | srcDirs = [ |
| 71 | 'src/test/examples', |
| 72 | ] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 73 | } |
| 74 | output.resourcesDir = 'build/classes/examples' |
| 75 | } |
| 76 | examplesAndroidN { |
| 77 | java { |
| 78 | srcDirs = ['src/test/examplesAndroidN'] |
| 79 | } |
| 80 | output.resourcesDir = 'build/classes/examplesAndroidN' |
| 81 | } |
| 82 | examplesAndroidO { |
| 83 | java { |
| 84 | srcDirs = ['src/test/examplesAndroidO'] |
| 85 | } |
| 86 | output.resourcesDir = 'build/classes/examplesAndroidO' |
| 87 | } |
| 88 | jctfCommon { |
| 89 | java { |
| 90 | srcDirs = [ |
| 91 | 'third_party/jctf/Harness/src', |
| 92 | 'third_party/jctf/LibTests/src/com/google/jctf/test/categories', |
| 93 | 'third_party/jctf/LibTests/src/com/google/jctf/test/helper', |
| 94 | 'third_party/jctf/LibTests/src/com/google/jctf/testHelpers', |
| 95 | 'third_party/jctf/LibTests/src/org', |
| 96 | 'build/additionalJctfCommonFiles' |
| 97 | ] |
| 98 | } |
| 99 | resources { |
| 100 | srcDirs = ['third_party/jctf/LibTests/resources'] |
| 101 | } |
| 102 | } |
| 103 | jctfTests { |
| 104 | java { |
| 105 | srcDirs = [ |
| 106 | 'third_party/jctf/LibTests/src/com/google/jctf/test/lib', |
| 107 | // 'third_party/jctf/VMTests/src', |
| 108 | ] |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 113 | configurations { |
| 114 | supportLibs |
| 115 | } |
| 116 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 117 | dependencies { |
| 118 | compile 'net.sf.jopt-simple:jopt-simple:4.6' |
Mads Ager | cd06c80 | 2017-08-22 13:44:34 +0200 | [diff] [blame] | 119 | compile 'com.googlecode.json-simple:json-simple:1.1' |
Mads Ager | 0aa4805 | 2017-09-15 12:39:15 +0200 | [diff] [blame] | 120 | // Include all of guava when compiling the code, but exclude annotations that we don't |
| 121 | // need from the packaging. |
| 122 | compileOnly('com.google.guava:guava:23.0') |
| 123 | compile('com.google.guava:guava:23.0', { |
| 124 | exclude group: 'com.google.errorprone' |
| 125 | exclude group: 'com.google.code.findbugs' |
| 126 | exclude group: 'com.google.j2objc' |
| 127 | exclude group: 'org.codehaus.mojo' |
| 128 | }) |
Stephan Herhut | b17bb8d | 2017-05-23 12:34:55 +0200 | [diff] [blame] | 129 | compile group: 'it.unimi.dsi', name: 'fastutil', version: '7.2.0' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 130 | compile group: 'org.apache.commons', name: 'commons-compress', version: '1.12' |
| 131 | compile group: 'org.ow2.asm', name: 'asm', version: '5.1' |
| 132 | compile group: 'org.ow2.asm', name: 'asm-commons', version: '5.1' |
| 133 | compile group: 'org.ow2.asm', name: 'asm-tree', version: '5.1' |
| 134 | compile group: 'org.ow2.asm', name: 'asm-util', version: '5.1' |
| 135 | testCompile sourceSets.examples.output |
| 136 | testCompile 'junit:junit:4.12' |
| 137 | testCompile group: 'org.smali', name: 'smali', version: '2.2b4' |
| 138 | testCompile files('third_party/jasmin/jasmin-2.4.jar') |
| 139 | testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar') |
| 140 | jctfCommonCompile 'junit:junit:4.12' |
| 141 | jctfTestsCompile 'junit:junit:4.12' |
| 142 | jctfTestsCompile sourceSets.jctfCommon.output |
| 143 | examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '5.1' |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 144 | examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0' |
| 145 | examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0' |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 146 | supportLibs 'com.android.support:support-v4:25.4.0' |
| 147 | supportLibs 'junit:junit:4.12' |
| 148 | supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0' |
Sebastien Hertz | 9006e9c | 2017-09-11 11:03:26 +0200 | [diff] [blame] | 149 | debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3' |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 152 | licenseTools { |
| 153 | licensesYaml = file('LIBRARY-LICENSE') |
| 154 | } |
| 155 | |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 156 | protobuf { |
| 157 | protoc { |
| 158 | // Download from repositories |
| 159 | artifact = 'com.google.protobuf:protoc:3.0.0' |
| 160 | } |
| 161 | plugins { |
| 162 | javalite { |
| 163 | artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' |
| 164 | } |
| 165 | } |
| 166 | generateProtoTasks { |
| 167 | all().each { task -> |
| 168 | task.builtins { |
| 169 | // Disable the java code generator, as we want javalite only. |
| 170 | remove java |
| 171 | } |
| 172 | task.plugins { |
| 173 | javalite {} |
| 174 | } |
| 175 | } |
| 176 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 179 | def osString = OperatingSystem.current().isLinux() ? "linux" : |
| 180 | OperatingSystem.current().isMacOsX() ? "mac" : "windows" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 181 | |
| 182 | def cloudDependencies = [ |
| 183 | "tests" : [ |
mikaelpeltier | 962da33 | 2017-08-18 11:40:55 +0200 | [diff] [blame] | 184 | "2017-07-27/art.tar.gz", |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 185 | "2016-12-19/art.tar.gz" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 186 | ], |
| 187 | "third_party": [ |
| 188 | "android_jar/lib-v14.tar.gz", |
| 189 | "android_jar/lib-v19.tar.gz", |
Søren Gjesse | ab22077 | 2017-06-23 13:05:53 +0200 | [diff] [blame] | 190 | "android_jar/lib-v21.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 191 | "android_jar/lib-v24.tar.gz", |
| 192 | "android_jar/lib-v25.tar.gz", |
| 193 | "android_jar/lib-v26.tar.gz", |
| 194 | "proguard/proguard5.2.1.tar.gz", |
| 195 | "gradle/gradle.tar.gz", |
| 196 | "jdwp-tests.tar.gz", |
| 197 | "jasmin.tar.gz", |
| 198 | "jctf.tar.gz", |
Sebastien Hertz | 1d7702b | 2017-08-18 09:07:27 +0200 | [diff] [blame] | 199 | "kotlin.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 200 | "android_cts_baseline.tar.gz", |
| 201 | ], |
| 202 | // All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker |
| 203 | // container on other platforms where supported. |
| 204 | "tools" : [ |
| 205 | "linux/art.tar.gz", |
| 206 | "linux/art-5.1.1.tar.gz", |
| 207 | "linux/art-6.0.1.tar.gz", |
| 208 | "linux/art-7.0.0.tar.gz", |
| 209 | "linux/dalvik.tar.gz", |
| 210 | "${osString}/dx.tar.gz", |
| 211 | ] |
| 212 | ] |
| 213 | |
| 214 | cloudDependencies.each { entry -> |
| 215 | entry.value.each { entryFile -> |
| 216 | task "download_deps_${entry.key}/${entryFile}"(type: Exec) { |
| 217 | def gzFile = "${entry.key}/${entryFile}" |
| 218 | def sha1File = "${gzFile}.sha1" |
| 219 | inputs.file sha1File |
| 220 | outputs.file gzFile |
Jean-Marie Henaff | 872e442 | 2017-06-13 10:26:20 +0200 | [diff] [blame] | 221 | List<String> dlFromStorageArgs = ["-n", "-b", "r8-deps", "-u", "-s", "${sha1File}"] |
| 222 | if (OperatingSystem.current().isWindows()) { |
| 223 | executable "download_from_google_storage.bat" |
| 224 | args dlFromStorageArgs |
| 225 | } else { |
| 226 | executable "bash" |
| 227 | args "-c", "download_from_google_storage " + String.join(" ", dlFromStorageArgs) |
| 228 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | def x20Dependencies = [ |
| 234 | "third_party": [ |
Søren Gjesse | 5ecb04a | 2017-06-13 09:44:32 +0200 | [diff] [blame] | 235 | "gmail/gmail_android_170604.16.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 236 | "gmscore/v4.tar.gz", |
| 237 | "gmscore/v5.tar.gz", |
| 238 | "gmscore/v6.tar.gz", |
| 239 | "gmscore/v7.tar.gz", |
| 240 | "gmscore/v8.tar.gz", |
| 241 | "gmscore/gmscore_v9.tar.gz", |
| 242 | "gmscore/gmscore_v10.tar.gz", |
Stephan Herhut | 4e74330 | 2017-06-09 13:09:03 +0200 | [diff] [blame] | 243 | "gmscore/latest.tar.gz", |
Mads Ager | ae64640 | 2017-06-07 13:32:43 +0200 | [diff] [blame] | 244 | "photos/2017-06-06.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 245 | "youtube/youtube.android_12.10.tar.gz", |
Søren Gjesse | feac2ef | 2017-05-22 17:09:29 +0200 | [diff] [blame] | 246 | "youtube/youtube.android_12.17.tar.gz", |
Søren Gjesse | 9be8498 | 2017-06-09 14:21:03 +0200 | [diff] [blame] | 247 | "youtube/youtube.android_12.22.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 248 | "proguardsettings.tar.gz", |
Tamas Kenez | 5febf24 | 2017-06-20 16:00:44 +0200 | [diff] [blame] | 249 | "proguard/proguard_internal_159423826.tar.gz", |
Tamas Kenez | 6741971 | 2017-06-26 11:11:45 +0200 | [diff] [blame] | 250 | "framework.tar.gz", |
Tamas Kenez | 391fca8 | 2017-06-29 18:16:01 +0200 | [diff] [blame] | 251 | "goyt.tar.gz", |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 252 | ], |
| 253 | ] |
| 254 | |
| 255 | x20Dependencies.each { entry -> |
| 256 | entry.value.each { entryFile -> |
| 257 | task "download_deps_${entry.key}/${entryFile}"(type: Exec) { |
| 258 | def gzFile = "${entry.key}/${entryFile}" |
| 259 | def sha1File = "${gzFile}.sha1" |
| 260 | inputs.file sha1File |
| 261 | outputs.file gzFile |
| 262 | executable "bash" |
| 263 | args "-c", "tools/download_from_x20.py ${sha1File}" |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
Rico Wind | 897bb71 | 2017-05-23 10:44:29 +0200 | [diff] [blame] | 268 | task downloadProguard { |
| 269 | cloudDependencies.each { entry -> |
| 270 | entry.value.each { entryFile -> |
| 271 | if (entryFile.contains("proguard")) { |
| 272 | dependsOn "download_deps_${entry.key}/${entryFile}" |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
Tamas Kenez | 427205b | 2017-06-29 15:57:09 +0200 | [diff] [blame] | 278 | task downloadDx { |
| 279 | cloudDependencies.each { entry -> |
| 280 | entry.value.each { entryFile -> |
| 281 | if (entryFile.contains("dx.tar")) { |
| 282 | dependsOn "download_deps_${entry.key}/${entryFile}" |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
Tamas Kenez | 0e10c56 | 2017-06-08 10:00:34 +0200 | [diff] [blame] | 288 | task downloadAndroidCts { |
| 289 | cloudDependencies.each { entry -> |
| 290 | entry.value.each { entryFile -> |
| 291 | if (entryFile.contains("android_cts_baseline")) { |
| 292 | dependsOn "download_deps_${entry.key}/${entryFile}" |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 298 | task downloadDeps { |
| 299 | cloudDependencies.each { entry -> |
| 300 | entry.value.each { entryFile -> |
| 301 | dependsOn "download_deps_${entry.key}/${entryFile}" |
| 302 | } |
| 303 | } |
| 304 | if (!project.hasProperty('no_internal')) { |
| 305 | x20Dependencies.each { entry -> |
| 306 | entry.value.each { entryFile -> |
| 307 | dependsOn "download_deps_${entry.key}/${entryFile}" |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | allprojects { |
| 314 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 315 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 316 | } |
| 317 | |
| 318 | tasks.withType(JavaCompile) { |
| 319 | options.compilerArgs << '-Xlint:unchecked' |
| 320 | } |
| 321 | |
| 322 | compileJctfCommonJava { |
| 323 | dependsOn 'copyAdditionalJctfCommonFiles' |
| 324 | options.compilerArgs = ['-Xlint:none'] |
| 325 | } |
| 326 | |
| 327 | compileJctfTestsJava { |
| 328 | dependsOn 'jctfCommonClasses' |
| 329 | options.compilerArgs = ['-Xlint:none'] |
| 330 | } |
| 331 | |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 332 | task consolidatedLicense { |
| 333 | // checkLicenses verifies that the list of libraries referenced in 'LIBRARY-LICENSE' is |
| 334 | // corresponding to the effective list of embedded libraries. |
| 335 | dependsOn 'checkLicenses' |
| 336 | def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE') |
| 337 | inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing') |
| 338 | outputs.files license |
| 339 | doLast { |
| 340 | license.getParentFile().mkdirs() |
| 341 | license.createNewFile() |
| 342 | license.text = "This file lists all licenses for code distributed.\n" |
| 343 | license.text += "All non-library code has the following 3-Clause BSD license.\n" |
| 344 | license.text += "\n" |
| 345 | license.text += "\n" |
| 346 | license.text += file('LICENSE').text |
| 347 | license.text += "\n" |
| 348 | license.text += "\n" |
| 349 | license.text += "Summary of distributed libraries:\n" |
| 350 | license.text += "\n" |
| 351 | license.text += file('LIBRARY-LICENSE').text |
| 352 | license.text += "\n" |
| 353 | license.text += "\n" |
| 354 | license.text += "Licenses details:\n" |
| 355 | fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file -> |
| 356 | license.text += "\n" |
| 357 | license.text += "\n" |
| 358 | license.text += file.text |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Mikaël Peltier | e5e5472 | 2017-08-18 12:01:59 +0200 | [diff] [blame] | 363 | task R8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 364 | from sourceSets.main.output |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 365 | from consolidatedLicense.outputs.files |
| 366 | exclude { path -> |
| 367 | path.getRelativePath().getPathString().startsWith("META-INF") |
| 368 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 369 | baseName 'r8' |
Mikaël Peltier | e5e5472 | 2017-08-18 12:01:59 +0200 | [diff] [blame] | 370 | classifier = null |
| 371 | version = null |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 372 | manifest { |
| 373 | attributes 'Main-Class': 'com.android.tools.r8.R8' |
| 374 | } |
| 375 | // In order to build without dependencies, pass the exclude_deps property using: |
| 376 | // gradle -Pexclude_deps R8 |
| 377 | if (!project.hasProperty('exclude_deps')) { |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 378 | // Relocating dependencies to avoid conflicts. Keep this as precise as possible |
| 379 | // to avoid rewriting unrelated strings. |
| 380 | relocate 'com.google.common', 'com.android.tools.r8.com.google.common' |
| 381 | relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty' |
Mikaël Peltier | e5e5472 | 2017-08-18 12:01:59 +0200 | [diff] [blame] | 382 | relocate 'joptsimple', 'com.android.tools.r8.joptsimple' |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 383 | relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons' |
| 384 | relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm' |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 385 | relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple' |
Mikaël Peltier | e5e5472 | 2017-08-18 12:01:59 +0200 | [diff] [blame] | 386 | relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 387 | // Also include dependencies |
Mikaël Peltier | e5e5472 | 2017-08-18 12:01:59 +0200 | [diff] [blame] | 388 | configurations = [project.configurations.compile] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 392 | task D8(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 393 | from sourceSets.main.output |
Yohann Roussel | 7f47c03 | 2017-09-14 12:19:06 +0200 | [diff] [blame] | 394 | from consolidatedLicense.outputs.files |
| 395 | exclude { path -> |
| 396 | path.getRelativePath().getPathString().startsWith("META-INF") |
| 397 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 398 | baseName 'd8' |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 399 | classifier = null |
| 400 | version = null |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 401 | manifest { |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 402 | attributes 'Main-Class': 'com.android.tools.r8.D8' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 403 | } |
| 404 | // In order to build without dependencies, pass the exclude_deps property using: |
| 405 | // gradle -Pexclude_deps D8 |
| 406 | if (!project.hasProperty('exclude_deps')) { |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 407 | // Relocating dependencies to avoid conflicts. Keep this as precise as possible |
| 408 | // to avoid rewriting unrelated strings. |
| 409 | relocate 'com.google.common', 'com.android.tools.r8.com.google.common' |
| 410 | relocate 'com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty' |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 411 | relocate 'joptsimple', 'com.android.tools.r8.joptsimple' |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 412 | relocate 'org.apache.commons', 'com.android.tools.r8.org.apache.commons' |
| 413 | relocate 'org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm' |
Stephan Herhut | 93123ef | 2017-08-22 12:05:11 +0200 | [diff] [blame] | 414 | relocate 'org.json.simple', 'com.android.tools.r8.org.json.simple' |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 415 | relocate 'it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 416 | // Also include dependencies |
mikaelpeltier | 8093931 | 2017-08-17 15:00:09 +0200 | [diff] [blame] | 417 | configurations = [project.configurations.compile] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | task CompatDx(type: Jar) { |
| 422 | from sourceSets.main.output |
| 423 | baseName 'compatdx' |
| 424 | manifest { |
| 425 | attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx' |
| 426 | } |
| 427 | // In order to build without dependencies, pass the exclude_deps property using: |
| 428 | // gradle -Pexclude_deps CompatDx |
| 429 | if (!project.hasProperty('exclude_deps')) { |
| 430 | // Also include dependencies |
| 431 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 432 | } |
| 433 | } |
| 434 | |
Søren Gjesse | 1d21da7 | 2017-09-01 12:05:38 +0200 | [diff] [blame] | 435 | task CompatProguard(type: Jar) { |
| 436 | from sourceSets.main.output |
| 437 | baseName 'compatproguard' |
| 438 | manifest { |
| 439 | attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard' |
| 440 | } |
| 441 | // In order to build without dependencies, pass the exclude_deps property using: |
| 442 | // gradle -Pexclude_deps CompatProguard |
| 443 | if (!project.hasProperty('exclude_deps')) { |
| 444 | // Also include dependencies |
| 445 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 446 | } |
| 447 | } |
| 448 | |
Tamas Kenez | 971eec6 | 2017-05-24 11:08:40 +0200 | [diff] [blame] | 449 | task D8Logger(type: Jar) { |
| 450 | from sourceSets.main.output |
| 451 | baseName 'd8logger' |
| 452 | manifest { |
| 453 | attributes 'Main-Class': 'com.android.tools.r8.D8Logger' |
| 454 | } |
| 455 | // In order to build without dependencies, pass the exclude_deps property using: |
| 456 | // gradle -Pexclude_deps D8Logger |
| 457 | if (!project.hasProperty('exclude_deps')) { |
| 458 | // Also include dependencies |
| 459 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 460 | } |
| 461 | } |
| 462 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 463 | task disasm(type: Jar) { |
| 464 | from sourceSets.main.output |
| 465 | baseName 'disasm' |
| 466 | manifest { |
| 467 | attributes 'Main-Class': 'com.android.tools.r8.Disassemble' |
| 468 | } |
| 469 | // In order to build without dependencies, pass the exclude_deps property using: |
| 470 | // gradle -Pexclude_deps D8 |
| 471 | if (!project.hasProperty('exclude_deps')) { |
| 472 | // Also include dependencies |
| 473 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | task bisect(type: Jar) { |
| 478 | from sourceSets.main.output |
| 479 | baseName 'bisect' |
| 480 | manifest { |
| 481 | attributes 'Main-Class': 'com.android.tools.r8.bisect.Bisect' |
| 482 | } |
| 483 | // In order to build without dependencies, pass the exclude_deps property using: |
| 484 | // gradle -Pexclude_deps R8 |
| 485 | if (!project.hasProperty('exclude_deps')) { |
| 486 | // Also include dependencies |
| 487 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 488 | } |
| 489 | } |
| 490 | |
Lars Bak | 90c1804 | 2017-06-26 14:21:08 +0200 | [diff] [blame] | 491 | task DexSegments(type: Jar) { |
| 492 | from sourceSets.main.output |
| 493 | baseName 'dexsegments' |
| 494 | manifest { |
| 495 | attributes 'Main-Class': 'com.android.tools.r8.DexSegments' |
| 496 | } |
| 497 | // In order to build without dependencies, pass the exclude_deps property using: |
| 498 | // gradle -Pexclude_deps DexSegments |
| 499 | if (!project.hasProperty('exclude_deps')) { |
| 500 | // Also include dependencies |
| 501 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 502 | } |
| 503 | } |
| 504 | |
Søren Gjesse | c4e5e93 | 2017-09-04 17:01:23 +0200 | [diff] [blame] | 505 | task maindex(type: Jar) { |
| 506 | from sourceSets.main.output |
| 507 | baseName 'maindex' |
| 508 | manifest { |
| 509 | attributes 'Main-Class': 'com.android.tools.r8.GenerateMainDexList' |
| 510 | } |
| 511 | // In order to build without dependencies, pass the exclude_deps property using: |
| 512 | // gradle -Pexclude_deps maindex |
| 513 | if (!project.hasProperty('exclude_deps')) { |
| 514 | // Also include dependencies |
| 515 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 516 | } |
| 517 | } |
| 518 | |
Lars Bak | 44cef52 | 2017-08-10 16:02:39 +0200 | [diff] [blame] | 519 | task ExtractMarker(type: Jar) { |
| 520 | from sourceSets.main.output |
| 521 | baseName 'extractmarker' |
| 522 | manifest { |
| 523 | attributes 'Main-Class': 'com.android.tools.r8.ExtractMarker' |
| 524 | } |
| 525 | // In order to build without dependencies, pass the exclude_deps property using: |
| 526 | // gradle -Pexclude_deps ExtractMarker |
| 527 | if (!project.hasProperty('exclude_deps')) { |
| 528 | // Also include dependencies |
| 529 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } |
| 530 | } |
| 531 | } |
| 532 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 533 | task sourceJar(type: Jar, dependsOn: classes) { |
| 534 | classifier = 'src' |
| 535 | from sourceSets.main.allSource |
| 536 | } |
| 537 | |
| 538 | task jctfCommonJar(type: Jar) { |
| 539 | from sourceSets.jctfCommon.output |
| 540 | baseName 'jctfCommon' |
| 541 | } |
| 542 | |
| 543 | artifacts { |
| 544 | archives sourceJar |
| 545 | } |
| 546 | |
| 547 | task createArtTests(type: Exec) { |
| 548 | def outputDir = "build/generated/test/java/com/android/tools/r8/art" |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 549 | def createArtTestsScript = "tools/create_art_tests.py" |
mikaelpeltier | 962da33 | 2017-08-18 11:40:55 +0200 | [diff] [blame] | 550 | inputs.file "tests/2017-07-27/art.tar.gz" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 551 | inputs.file createArtTestsScript |
| 552 | outputs.dir outputDir |
| 553 | dependsOn downloadDeps |
Mads Ager | 677e300 | 2017-05-24 07:54:51 +0200 | [diff] [blame] | 554 | commandLine "python", createArtTestsScript |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 555 | workingDir = projectDir |
| 556 | } |
| 557 | |
| 558 | task createJctfTests(type: Exec) { |
Stephan Herhut | ea6ee58 | 2017-05-23 13:14:34 +0200 | [diff] [blame] | 559 | def outputDir = "build/generated/test/java/com/android/tools/r8/jctf" |
Tamas Kenez | 25a99e9 | 2017-05-29 10:15:30 +0200 | [diff] [blame] | 560 | def script = "tools/create_jctf_tests.py" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 561 | inputs.file script |
| 562 | outputs.dir outputDir |
| 563 | dependsOn downloadDeps |
Tamas Kenez | 25a99e9 | 2017-05-29 10:15:30 +0200 | [diff] [blame] | 564 | commandLine "python", script |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 565 | workingDir = projectDir |
| 566 | } |
| 567 | |
| 568 | compileTestJava { |
| 569 | dependsOn createArtTests |
| 570 | dependsOn createJctfTests |
| 571 | } |
| 572 | |
| 573 | task buildDebugInfoExamplesDex { |
| 574 | def examplesDir = file("src/test/java") |
| 575 | def hostJar = "debuginfo_examples.jar" |
| 576 | def hostDexJar = "debuginfo_examples_dex.jar" |
| 577 | task "compile_debuginfo_examples"(type: JavaCompile) { |
| 578 | source = fileTree(dir: examplesDir, include: "com/android/tools/r8/debuginfo/*Test.java") |
| 579 | destinationDir = file("build/test/debuginfo_examples/classes") |
| 580 | classpath = sourceSets.main.compileClasspath |
| 581 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 582 | targetCompatibility = JavaVersion.VERSION_1_7 |
| 583 | options.compilerArgs += ["-Xlint:-options"] |
| 584 | } |
| 585 | task "jar_debuginfo_examples"(type: Jar, dependsOn: "compile_debuginfo_examples") { |
| 586 | archiveName = hostJar |
| 587 | destinationDir = file("build/test/") |
| 588 | from "build/test/debuginfo_examples/classes" |
| 589 | include "**/*.class" |
| 590 | } |
| 591 | task "dex_debuginfo_examples"(type: Exec, |
| 592 | dependsOn: ["jar_debuginfo_examples", "downloadDeps"]) { |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 593 | if (OperatingSystem.current().isWindows()) { |
| 594 | executable file("tools/windows/dx/bin/dx.bat") |
| 595 | } else { |
| 596 | executable file("tools/linux/dx/bin/dx"); |
| 597 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 598 | args "--dex" |
| 599 | args "--output=build/test/${hostDexJar}" |
| 600 | args "build/test/${hostJar}" |
| 601 | inputs.file file("build/test/${hostJar}") |
| 602 | outputs.file file("build/test/${hostDexJar}") |
| 603 | } |
| 604 | dependsOn dex_debuginfo_examples |
| 605 | } |
| 606 | |
| 607 | task buildDebugTestResourcesJars { |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 608 | def resourcesDir = file("src/test/debugTestResources") |
| 609 | def hostJar = "debug_test_resources.jar" |
| 610 | task "compile_debugTestResources"(type: JavaCompile) { |
| 611 | source = fileTree(dir: resourcesDir, include: '**/*.java') |
| 612 | destinationDir = file("build/test/debugTestResources/classes") |
| 613 | classpath = sourceSets.main.compileClasspath |
| 614 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 615 | targetCompatibility = JavaVersion.VERSION_1_7 |
| 616 | options.compilerArgs += ["-g", "-Xlint:-options"] |
| 617 | } |
| 618 | task "jar_debugTestResources"(type: Jar, dependsOn: "compile_debugTestResources") { |
| 619 | archiveName = hostJar |
| 620 | destinationDir = file("build/test/") |
| 621 | from "build/test/debugTestResources/classes" |
| 622 | include "**/*.class" |
| 623 | } |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 624 | def java8ResourcesDir = file("src/test/debugTestResourcesJava8") |
| 625 | def java8HostJar = "debug_test_resources_java8.jar" |
| 626 | task "compile_debugTestResourcesJava8"(type: JavaCompile) { |
| 627 | source = fileTree(dir: java8ResourcesDir, include: '**/*.java') |
| 628 | destinationDir = file("build/test/debugTestResourcesJava8/classes") |
| 629 | classpath = sourceSets.main.compileClasspath |
| 630 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 631 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 632 | options.compilerArgs += ["-g", "-Xlint:-options"] |
| 633 | } |
| 634 | task "jar_debugTestResourcesJava8"(type: Jar, dependsOn: "compile_debugTestResourcesJava8") { |
| 635 | archiveName = java8HostJar |
| 636 | destinationDir = file("build/test/") |
| 637 | from "build/test/debugTestResourcesJava8/classes" |
| 638 | include "**/*.class" |
| 639 | } |
Sebastien Hertz | 1d7702b | 2017-08-18 09:07:27 +0200 | [diff] [blame] | 640 | def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin") |
| 641 | def kotlinHostJar = "debug_test_resources_kotlin.jar" |
Sebastien Hertz | 9006e9c | 2017-09-11 11:03:26 +0200 | [diff] [blame] | 642 | task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) { |
| 643 | source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt') |
| 644 | destination = file("build/test/${kotlinHostJar}") |
Sebastien Hertz | 1d7702b | 2017-08-18 09:07:27 +0200 | [diff] [blame] | 645 | } |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 646 | dependsOn downloadDeps |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 647 | dependsOn jar_debugTestResources |
Sebastien Hertz | 964c5c2 | 2017-05-23 15:22:23 +0200 | [diff] [blame] | 648 | dependsOn jar_debugTestResourcesJava8 |
Sebastien Hertz | 1d7702b | 2017-08-18 09:07:27 +0200 | [diff] [blame] | 649 | dependsOn jar_debugTestResourcesKotlin |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Lars Bak | c91e87e | 2017-08-18 08:53:10 +0200 | [diff] [blame] | 652 | // Proto lite generated code yields warnings when compiling with javac. |
| 653 | // We change the options passed to javac to ignore it. |
| 654 | compileExamplesJava.options.compilerArgs = ["-Xlint:none"] |
| 655 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 656 | task buildExampleJars { |
Rico Wind | 897bb71 | 2017-05-23 10:44:29 +0200 | [diff] [blame] | 657 | dependsOn downloadProguard |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 658 | def examplesDir = file("src/test/examples") |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 659 | def protoSourceDir = file("build/generated/source/proto/examples/javalite") |
Jean-Marie Henaff | 872e442 | 2017-06-13 10:26:20 +0200 | [diff] [blame] | 660 | def proguardScript |
| 661 | if (OperatingSystem.current().isWindows()) { |
| 662 | proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat" |
| 663 | } else { |
| 664 | proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh" |
| 665 | } |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 666 | task extractExamplesRuntime(type: Sync) { |
| 667 | dependsOn configurations.examplesRuntime |
| 668 | from configurations.examplesRuntime.collect { zipTree(it) } |
| 669 | include "**/*.class" |
| 670 | includeEmptyDirs false |
| 671 | into "$buildDir/runtime/examples/" |
| 672 | } |
| 673 | |
| 674 | task "compile_examples"(type: JavaCompile, dependsOn: "generateExamplesProto") { |
| 675 | source examplesDir, protoSourceDir |
| 676 | include "**/*.java" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 677 | destinationDir = file("build/test/examples/classes") |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 678 | classpath = sourceSets.examples.compileClasspath |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 679 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 680 | targetCompatibility = JavaVersion.VERSION_1_7 |
Tamas Kenez | c5163ed | 2017-09-19 09:27:37 +0200 | [diff] [blame] | 681 | options.compilerArgs = ["-g:source,lines", "-Xlint:none"] |
| 682 | } |
| 683 | task "compile_examples_debuginfo_all"(type: JavaCompile, dependsOn: "generateExamplesProto") { |
| 684 | source examplesDir, protoSourceDir |
| 685 | include "**/*.java" |
| 686 | destinationDir = file("build/test/examples/classes_debuginfo_all") |
| 687 | classpath = sourceSets.examples.compileClasspath |
| 688 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 689 | targetCompatibility = JavaVersion.VERSION_1_7 |
| 690 | options.compilerArgs = ["-g", "-Xlint:none"] |
| 691 | } |
| 692 | task "compile_examples_debuginfo_none"(type: JavaCompile, dependsOn: "generateExamplesProto") { |
| 693 | source examplesDir, protoSourceDir |
| 694 | include "**/*.java" |
| 695 | destinationDir = file("build/test/examples/classes_debuginfo_none") |
| 696 | classpath = sourceSets.examples.compileClasspath |
| 697 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 698 | targetCompatibility = JavaVersion.VERSION_1_7 |
| 699 | options.compilerArgs = ["-g:none", "-Xlint:none"] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 700 | } |
| 701 | examplesDir.eachDir { dir -> |
| 702 | def name = dir.getName(); |
| 703 | def exampleOutputDir = file("build/test/examples"); |
| 704 | def jarName = "${name}.jar" |
| 705 | dependsOn "jar_example_${name}" |
Tamas Kenez | c5163ed | 2017-09-19 09:27:37 +0200 | [diff] [blame] | 706 | dependsOn "jar_example_${name}_debuginfo_all" |
| 707 | dependsOn "jar_example_${name}_debuginfo_none" |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 708 | dependsOn "extractExamplesRuntime" |
| 709 | def runtimeDependencies = copySpec { } |
| 710 | if (!fileTree(dir: dir, include: '**/*.proto').empty) { |
| 711 | // If we have any proto use, we have to include those classes and the runtime. |
| 712 | runtimeDependencies = copySpec { |
| 713 | from "$buildDir/runtime/examples/" |
| 714 | include "com/google/protobuf/**/*.class" |
| 715 | } |
| 716 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 717 | // The "throwing" test verifies debugging/stack info on the post-proguarded output. |
| 718 | def proguardConfigPath = "${dir}/proguard.cfg" |
| 719 | if (new File(proguardConfigPath).exists()) { |
| 720 | task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") { |
| 721 | archiveName = "${name}_pre_proguard.jar" |
| 722 | destinationDir = exampleOutputDir |
| 723 | from "build/test/examples/classes" |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 724 | include name + "/**/*.class" |
| 725 | with runtimeDependencies |
| 726 | includeEmptyDirs false |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 727 | } |
| 728 | def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first(); |
| 729 | def proguardJarPath = "${exampleOutputDir}/${jarName}" |
| 730 | def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map" |
| 731 | task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") { |
| 732 | inputs.files tasks.getByPath("pre_proguard_example_${name}") |
| 733 | inputs.file proguardConfigPath |
| 734 | // Enable these to get stdout and stderr redirected to files... |
| 735 | // standardOutput = new FileOutputStream('proguard.stdout') |
| 736 | // errorOutput = new FileOutputStream('proguard.stderr') |
Jean-Marie Henaff | 872e442 | 2017-06-13 10:26:20 +0200 | [diff] [blame] | 737 | def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" + |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 738 | " -outjars ${proguardJarPath}" + |
| 739 | " -include ${proguardConfigPath}" + |
Jean-Marie Henaff | 872e442 | 2017-06-13 10:26:20 +0200 | [diff] [blame] | 740 | " -printmapping ${proguardMapPath}" |
| 741 | if (OperatingSystem.current().isWindows()) { |
| 742 | executable "${proguardScript}" |
| 743 | args "${proguardArguments}" |
| 744 | } else { |
| 745 | executable "bash" |
| 746 | args "-c", "${proguardScript} '${proguardArguments}'" |
| 747 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 748 | outputs.file proguardJarPath |
| 749 | } |
Tamas Kenez | c5163ed | 2017-09-19 09:27:37 +0200 | [diff] [blame] | 750 | // TODO: Consider performing distinct proguard compilations. |
| 751 | task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") { |
| 752 | from "${exampleOutputDir}/${name}.jar" |
| 753 | into "${exampleOutputDir}/${name}_debuginfo_all.jar" |
| 754 | } |
| 755 | task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") { |
| 756 | from "${exampleOutputDir}/${name}.jar" |
| 757 | into "${exampleOutputDir}/${name}_debuginfo_none.jar" |
| 758 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 759 | } else { |
| 760 | task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") { |
Tamas Kenez | c5163ed | 2017-09-19 09:27:37 +0200 | [diff] [blame] | 761 | archiveName = "${name}.jar" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 762 | destinationDir = exampleOutputDir |
| 763 | from "build/test/examples/classes" |
Stephan Herhut | 417a72a | 2017-07-18 10:38:30 +0200 | [diff] [blame] | 764 | include name + "/**/*.class" |
| 765 | with runtimeDependencies |
| 766 | includeEmptyDirs false |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 767 | } |
Tamas Kenez | c5163ed | 2017-09-19 09:27:37 +0200 | [diff] [blame] | 768 | task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") { |
| 769 | archiveName = "${name}_debuginfo_all.jar" |
| 770 | destinationDir = exampleOutputDir |
| 771 | from "build/test/examples/classes_debuginfo_all" |
| 772 | include name + "/**/*.class" |
| 773 | with runtimeDependencies |
| 774 | includeEmptyDirs false |
| 775 | } |
| 776 | task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") { |
| 777 | archiveName = "${name}_debuginfo_none.jar" |
| 778 | destinationDir = exampleOutputDir |
| 779 | from "build/test/examples/classes_debuginfo_none" |
| 780 | include name + "/**/*.class" |
| 781 | with runtimeDependencies |
| 782 | includeEmptyDirs false |
| 783 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | task buildExampleAndroidNJars { |
| 789 | dependsOn downloadDeps |
| 790 | def examplesDir = file("src/test/examplesAndroidN") |
| 791 | task "compile_examplesAndroidN"(type: JavaCompile) { |
| 792 | source = fileTree(dir: examplesDir, include: '**/*.java') |
| 793 | destinationDir = file("build/test/examplesAndroidN/classes") |
| 794 | classpath = sourceSets.main.compileClasspath |
| 795 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 796 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 797 | options.compilerArgs += ["-Xlint:-options"] |
| 798 | } |
| 799 | examplesDir.eachDir { dir -> |
| 800 | def name = dir.getName(); |
| 801 | def exampleOutputDir = file("build/test/examplesAndroidN"); |
| 802 | def jarName = "${name}.jar" |
| 803 | dependsOn "jar_examplesAndroidN_${name}" |
| 804 | task "jar_examplesAndroidN_${name}"(type: Jar, dependsOn: "compile_examplesAndroidN") { |
| 805 | archiveName = jarName |
| 806 | destinationDir = exampleOutputDir |
| 807 | from "build/test/examplesAndroidN/classes" |
| 808 | include "**/" + name + "/**/*.class" |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | |
| 814 | task buildExampleAndroidOJars { |
| 815 | dependsOn downloadDeps |
| 816 | def examplesDir = file("src/test/examplesAndroidO") |
| 817 | // NOTE: we want to enable a scenario when test needs to reference some |
| 818 | // classes generated by legacy (1.6) Java compiler to test some specific |
| 819 | // behaviour. To do so we compile all the java files located in sub-directory |
| 820 | // called 'legacy' with Java 1.6, then compile the rest of the files with |
| 821 | // Java 1.8 and a reference to previously generated 1.6 classes. |
| 822 | |
| 823 | // Compiling all classes in dirs 'legacy' with old Java version. |
| 824 | task "compile_examplesAndroidO_Legacy"(type: JavaCompile) { |
| 825 | source = fileTree(dir: examplesDir, include: '**/legacy/**/*.java') |
| 826 | destinationDir = file("build/test/examplesAndroidOLegacy/classes") |
| 827 | classpath = sourceSets.main.compileClasspath |
| 828 | sourceCompatibility = JavaVersion.VERSION_1_6 |
| 829 | targetCompatibility = JavaVersion.VERSION_1_6 |
| 830 | options.compilerArgs += ["-Xlint:-options", "-parameters"] |
| 831 | } |
| 832 | // Compiling the rest of the files as Java 1.8 code. |
| 833 | task "compile_examplesAndroidO"(type: JavaCompile) { |
| 834 | dependsOn "compile_examplesAndroidO_Legacy" |
| 835 | source = fileTree(dir: examplesDir, include: '**/*.java', exclude: '**/legacy/**/*.java') |
| 836 | destinationDir = file("build/test/examplesAndroidO/classes") |
| 837 | classpath = sourceSets.main.compileClasspath |
| 838 | classpath += files("build/test/examplesAndroidOLegacy/classes") |
| 839 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 840 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 841 | options.compilerArgs += ["-Xlint:-options", "-parameters"] |
| 842 | } |
| 843 | examplesDir.eachDir { dir -> |
| 844 | def name = dir.getName(); |
| 845 | def destinationDir = file("build/test/examplesAndroidO/classes"); |
| 846 | if (file("src/test/examplesAndroidO/" + name + "/TestGenerator.java").isFile()) { |
| 847 | task "generate_examplesAndroidO_${name}"(type: JavaExec, |
| 848 | dependsOn: "compile_examplesAndroidO") { |
| 849 | main = name + ".TestGenerator" |
| 850 | classpath = files(destinationDir, sourceSets.main.compileClasspath) |
| 851 | args destinationDir |
| 852 | } |
| 853 | } else { |
| 854 | task "generate_examplesAndroidO_${name}" () {} |
| 855 | } |
| 856 | } |
| 857 | examplesDir.eachDir { dir -> |
| 858 | def name = dir.getName(); |
| 859 | def exampleOutputDir = file("build/test/examplesAndroidO"); |
| 860 | def jarName = "${name}.jar" |
| 861 | dependsOn "jar_examplesAndroidO_${name}" |
| 862 | task "jar_examplesAndroidO_${name}"(type: Jar, dependsOn: ["compile_examplesAndroidO", |
| 863 | "generate_examplesAndroidO_${name}"]) { |
| 864 | archiveName = jarName |
| 865 | destinationDir = exampleOutputDir |
| 866 | from "build/test/examplesAndroidO/classes" // Java 1.8 classes |
| 867 | from "build/test/examplesAndroidOLegacy/classes" // Java 1.6 classes |
| 868 | include "**/" + name + "/**/*.class" |
| 869 | // Do not include generator into the test runtime jar, it is not useful. |
| 870 | // Otherwise, shrinking will need ASM jars. |
| 871 | exclude "**/TestGenerator*" |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | task buildExamples { |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 877 | if (OperatingSystem.current().isMacOsX() || OperatingSystem.current().isWindows()) { |
| 878 | logger.lifecycle("WARNING: Testing (including building examples) is only partially supported on your " + |
| 879 | "platform (" + OperatingSystem.current().getName() + ").") |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 880 | } else if (!OperatingSystem.current().isLinux()) { |
| 881 | logger.lifecycle("WARNING: Testing (including building examples) is not supported on your platform. " + |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 882 | "It is fully supported on Linux and partially supported on Mac OS and Windows") |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 883 | return; |
| 884 | } |
| 885 | dependsOn buildDebugTestResourcesJars |
| 886 | dependsOn buildExampleJars |
| 887 | dependsOn buildExampleAndroidNJars |
| 888 | dependsOn buildExampleAndroidOJars |
| 889 | def examplesDir = file("src/test/examples") |
Yohann Roussel | f820a57 | 2017-05-31 20:25:51 +0200 | [diff] [blame] | 890 | def noDexTests = [ |
| 891 | "multidex", |
| 892 | "multidex002", |
| 893 | "multidex004", |
| 894 | ] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 895 | examplesDir.eachDir { dir -> |
| 896 | def name = dir.getName(); |
Yohann Roussel | f820a57 | 2017-05-31 20:25:51 +0200 | [diff] [blame] | 897 | if (!(name in noDexTests)) { |
| 898 | dependsOn "dex_example_${name}" |
| 899 | def exampleOutputDir = file("build/test/examples/" + name); |
| 900 | def dexPath = file("${exampleOutputDir}") |
| 901 | def debug = (name == "throwing") |
| 902 | if (!dexPath.exists()) { |
| 903 | dexPath.mkdirs() |
| 904 | } |
| 905 | task "dex_example_${name}"(type: dx.Dx, dependsOn: "jar_example_${name}") { |
| 906 | source = files(tasks.getByPath("jar_example_${name}")).asFileTree |
| 907 | destination = dexPath |
| 908 | debug = debug |
| 909 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | task buildSmali { |
| 915 | def smaliDir = file("src/test/smali") |
| 916 | smaliDir.eachDirRecurse() { dir -> |
| 917 | def name = dir.getName(); |
| 918 | def relativeDir = smaliDir.toPath().relativize(dir.toPath()); |
| 919 | def smaliOutputDir = file("build/test/smali/" + relativeDir); |
| 920 | smaliOutputDir.mkdirs() |
| 921 | outputs.dir smaliOutputDir |
| 922 | def taskName = "smali_build_${relativeDir.toString().replace('/', '_')}" |
| 923 | def smaliFiles = fileTree(dir: dir, include: '*.smali') |
| 924 | def javaFiles = fileTree(dir: dir, include: '*.java') |
| 925 | def destDir = smaliOutputDir; |
| 926 | def destFile = destDir.toPath().resolve("${name}.dex").toFile() |
| 927 | def intermediateFileName = "${name}-intermediate.dex"; |
| 928 | def intermediateFile = destDir.toPath().resolve(intermediateFileName).toFile() |
| 929 | if (javaFiles.empty) { |
| 930 | if (!smaliFiles.empty) { |
| 931 | dependsOn "${taskName}_smali" |
| 932 | task "${taskName}_smali"(type: smali.Smali) { |
| 933 | source = smaliFiles |
| 934 | destination = destFile |
| 935 | } |
| 936 | } |
| 937 | } else { |
| 938 | dependsOn "${taskName}_dexmerger" |
| 939 | task "${taskName}_smali"(type: smali.Smali) { |
| 940 | source = smaliFiles |
| 941 | destination = intermediateFile |
| 942 | } |
| 943 | task "${taskName}_java"(type: JavaCompile) { |
| 944 | source = javaFiles |
| 945 | destinationDir destDir |
| 946 | classpath = sourceSets.main.compileClasspath |
| 947 | sourceCompatibility = JavaVersion.VERSION_1_7 |
| 948 | targetCompatibility = JavaVersion.VERSION_1_7 |
| 949 | options.compilerArgs += ["-Xlint:-options"] |
| 950 | } |
| 951 | task "${taskName}_jar"(type: Jar, dependsOn: "${taskName}_java") { |
| 952 | archiveName = "Test.jar" |
| 953 | destinationDir = destDir |
| 954 | from fileTree(dir: destDir, include: 'Test.class') |
| 955 | } |
| 956 | task "${taskName}_dx"(type: dx.Dx, dependsOn: "${taskName}_jar") { |
| 957 | source = fileTree(dir: destDir, include: 'Test.jar') |
| 958 | destination = destDir |
| 959 | } |
| 960 | task "${taskName}_dexmerger"( |
| 961 | type: dx.DexMerger, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) { |
| 962 | source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName]) |
| 963 | destination = destFile |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | tasks.withType(Test) { |
| 970 | def userDefinedCoresPerFork = System.getenv('R8_GRADLE_CORES_PER_FORK') |
| 971 | def coresPerFork = userDefinedCoresPerFork ? userDefinedCoresPerFork.toInteger() : 3 |
| 972 | // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html. |
| 973 | maxParallelForks = Runtime.runtime.availableProcessors().intdiv(coresPerFork) ?: 1 |
| 974 | forkEvery = 0 |
| 975 | // Use the Concurrent Mark Sweep GC (CMS) to keep memory usage at a resonable level. |
| 976 | jvmArgs = ["-XX:+UseConcMarkSweepGC"] |
Søren Gjesse | af1c5e2 | 2017-06-15 12:24:03 +0200 | [diff] [blame] | 977 | if (project.hasProperty('disable_assertions')) { |
| 978 | enableAssertions = false |
| 979 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | task buildPreNJdwpTestsJar(type: Jar) { |
| 983 | baseName = 'jdwp-tests-preN' |
| 984 | from zipTree('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar') |
| 985 | // Exclude the classes containing java8 |
| 986 | exclude 'org/apache/harmony/jpda/tests/jdwp/InterfaceType/*.class' |
| 987 | exclude 'org/apache/harmony/jpda/tests/jdwp/ObjectReference/InvokeMethodDefault*.class' |
| 988 | includeEmptyDirs = false |
| 989 | } |
| 990 | |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 991 | task supportLibDir() { |
| 992 | doLast { |
| 993 | File dir = file("build/supportlibraries") |
| 994 | dir.mkdir() |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | configurations.supportLibs.files.each { file -> |
| 999 | if (file.getName().endsWith(".aar")) { |
| 1000 | def name = "extract_"+file.getName() |
| 1001 | task "${name}"(type: Copy) { |
| 1002 | dependsOn supportLibDir |
| 1003 | from zipTree(file) |
| 1004 | into "build/supportlibraries" |
| 1005 | eachFile { FileCopyDetails fcp -> |
| 1006 | if (fcp.relativePath.pathString.equals("classes.jar")) { |
| 1007 | // remap the file to the root with correct name |
| 1008 | fcp.relativePath = new RelativePath(true, file.getName().replace(".aar", ".jar")) |
| 1009 | } else { |
| 1010 | fcp.exclude() |
| 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | task supportLibList() { |
| 1018 | configurations.supportLibs.files.each { |
| 1019 | if (it.getName().endsWith(".aar")) { |
| 1020 | dependsOn "extract_"+it.getName() |
| 1021 | } |
| 1022 | } |
| 1023 | doLast { |
Yohann Roussel | 630dfe1 | 2017-08-03 17:24:08 +0200 | [diff] [blame] | 1024 | file("build/generated").mkdir() |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 1025 | def file = file("build/generated/supportlibraries.txt") |
| 1026 | file.createNewFile() |
| 1027 | file.text = "" |
| 1028 | configurations.supportLibs.files.each { |
| 1029 | if (it.getName().endsWith(".aar")) { |
| 1030 | def outName = it.getName().replace(".aar", ".jar") |
| 1031 | file.text += ("build/supportlibraries/" |
| 1032 | + outName + "\n") |
| 1033 | } else { |
| 1034 | file.text += (it.getPath() + "\n") |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 1040 | task AospJarTest(type: Exec) { |
| 1041 | dependsOn CompatDx, downloadDeps |
| 1042 | def script = "tools/test_aosp_jar.py" |
| 1043 | inputs.file script |
| 1044 | commandLine "python", script, "--no-build" |
| 1045 | workingDir = projectDir |
| 1046 | } |
| 1047 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1048 | test { |
Yohann Roussel | 126f687 | 2017-08-03 16:25:32 +0200 | [diff] [blame] | 1049 | dependsOn supportLibList |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1050 | testLogging.exceptionFormat = 'full' |
| 1051 | if (project.hasProperty('print_test_stdout')) { |
| 1052 | testLogging.showStandardStreams = true |
| 1053 | } |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 1054 | if (project.hasProperty('dex_vm') && project.property('dex_vm') != 'default') { |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1055 | println "Running with non default vm: " + project.property('dex_vm') |
| 1056 | systemProperty 'dex_vm', project.property('dex_vm') |
| 1057 | if (project.property('dex_vm') == '5.1.1' || project.property('dex_vm') == '6.0.1') { |
| 1058 | // R8 and D8 compute the dex file version number based on the input. |
| 1059 | // Jack generates dex files with version 37 which art 5.1.1 and 6.0.1 will not run. |
| 1060 | // Therefore we skip the jack generated art tests with those art versions. |
| 1061 | exclude "com/android/tools/r8/art/jack/**" |
| 1062 | } |
| 1063 | } |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 1064 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1065 | if (project.hasProperty('one_line_per_test')) { |
| 1066 | beforeTest { desc -> |
| 1067 | println "Start executing test ${desc.name} [${desc.className}]" |
| 1068 | } |
| 1069 | afterTest { desc, result -> |
| 1070 | println "Done executing test ${desc.name} [${desc.className}] with result: ${result.resultType}" |
| 1071 | } |
| 1072 | } |
| 1073 | if (project.hasProperty('no_internal')) { |
| 1074 | exclude "com/android/tools/r8/internal/**" |
| 1075 | } |
| 1076 | if (project.hasProperty('only_internal')) { |
| 1077 | include "com/android/tools/r8/internal/**" |
| 1078 | } |
| 1079 | if (project.hasProperty('tool')) { |
| 1080 | if (project.property('tool') == 'r8') { |
| 1081 | exclude "com/android/tools/r8/art/*/d8/**" |
Tamas Kenez | 69c2e8b | 2017-05-31 13:41:07 +0200 | [diff] [blame] | 1082 | exclude "com/android/tools/r8/jctf/d8/**" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1083 | } else { |
| 1084 | assert(project.property('tool') == 'd8') |
| 1085 | exclude "com/android/tools/r8/art/*/r8/**" |
Tamas Kenez | 69c2e8b | 2017-05-31 13:41:07 +0200 | [diff] [blame] | 1086 | exclude "com/android/tools/r8/jctf/r8/**" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | if (!project.hasProperty('all_tests')) { |
| 1090 | exclude "com/android/tools/r8/art/dx/**" |
| 1091 | exclude "com/android/tools/r8/art/jack/**" |
| 1092 | } |
| 1093 | // TODO(tamaskenez) enable jctf on all_tests when consolidated |
| 1094 | if (!project.hasProperty('jctf') && !project.hasProperty('only_jctf')) { |
Stephan Herhut | ea6ee58 | 2017-05-23 13:14:34 +0200 | [diff] [blame] | 1095 | exclude "com/android/tools/r8/jctf/**" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1096 | } |
| 1097 | if (project.hasProperty('only_jctf')) { |
Stephan Herhut | ea6ee58 | 2017-05-23 13:14:34 +0200 | [diff] [blame] | 1098 | include "com/android/tools/r8/jctf/**" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1099 | } |
| 1100 | if (project.hasProperty('jctf_compile_only')) { |
| 1101 | println "JCTF: compiling only" |
| 1102 | systemProperty 'jctf_compile_only', '1' |
| 1103 | } |
Tamas Kenez | b77b7d8 | 2017-08-17 14:05:16 +0200 | [diff] [blame] | 1104 | if (project.hasProperty('test_dir')) { |
| 1105 | systemProperty 'test_dir', project.property('test_dir') |
| 1106 | } |
Tamas Kenez | 0cad51c | 2017-08-21 14:42:01 +0200 | [diff] [blame] | 1107 | if (project.hasProperty('aosp_jar')) { |
| 1108 | dependsOn AospJarTest |
| 1109 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1110 | |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 1111 | if (OperatingSystem.current().isLinux() |
| 1112 | || OperatingSystem.current().isMacOsX() |
| 1113 | || OperatingSystem.current().isWindows()) { |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1114 | if (OperatingSystem.current().isMacOsX()) { |
| 1115 | logger.lifecycle("WARNING: Testing in only partially supported on Mac OS. " + |
| 1116 | "Art only runs on Linux and tests requiring Art runs in a Docker container, which must be present. " + |
| 1117 | "See tools/docker/README.md for details.") |
| 1118 | } |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 1119 | if (OperatingSystem.current().isWindows()) { |
| 1120 | logger.lifecycle("WARNING: Testing in only partially supported on Windows. " + |
| 1121 | "Art only runs on Linux and tests requiring Art will be skipped") |
| 1122 | } |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1123 | dependsOn downloadDeps |
| 1124 | dependsOn buildExamples |
| 1125 | dependsOn buildSmali |
| 1126 | dependsOn jctfCommonJar |
| 1127 | dependsOn jctfTestsClasses |
| 1128 | dependsOn buildDebugInfoExamplesDex |
| 1129 | dependsOn buildPreNJdwpTestsJar |
| 1130 | } else { |
| 1131 | logger.lifecycle("WARNING: Testing in not supported on your platform. Testing is only fully supported on " + |
Jean-Marie Henaff | 39587a8 | 2017-06-08 15:20:13 +0200 | [diff] [blame] | 1132 | "Linux and partially supported on Mac OS and Windows. Art does not run on other platforms.") |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | // The Art tests we use for R8 are pre-build and downloaded from Google Cloud Storage. |
| 1137 | // |
| 1138 | // To build and upload a new set of the Art tests for use with R8 follow these steps: |
| 1139 | // |
| 1140 | // First of all an Android checkout is required. Currently it must be located |
| 1141 | // in $HOME/android/master. |
| 1142 | // |
| 1143 | // TODO(ricow): simplify this |
| 1144 | // |
| 1145 | // Before: update the checked in art, see scripts/update-host-art.sh |
| 1146 | // |
| 1147 | // 1. Get an android checkout in $HOME/android/master and apply the patch from |
| 1148 | // https://android-review.googlesource.com/#/c/294187/ |
| 1149 | // |
| 1150 | // 2. run the following commands in the Android checkout directory: |
| 1151 | // |
| 1152 | // source build/envsetup.sh |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1153 | // lunch aosp_angler-userdebug # or lunch aosp_angler-eng |
| 1154 | // m desugar |
| 1155 | // m -j30 test-art-host |
| 1156 | // DESUGAR=false ANDROID_COMPILE_WITH_JACK=false art/test.py --host -t 001-HelloWorld |
| 1157 | // |
| 1158 | // Without running the test.py command the classes.jar file used by desugar in |
| 1159 | // $HOME/android/master/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/ |
| 1160 | // seems to be missing - there is probably also a make target to build it more directly |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1161 | // |
| 1162 | // 3. In the R8 project root directory, make sure we have a clean state before starting: |
| 1163 | // tools/gradle.py downloadDeps |
| 1164 | // tools/gradle.py clean |
| 1165 | // rm -rf tests/art |
| 1166 | // |
| 1167 | // 4. Now build in the R8 checkout (-P hack to not generate dirs when not running this target) |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1168 | // Make sure you have smali on your path, please use the build binary in the |
| 1169 | // out/host/linux-x86/bin directory of the android checkout. Currently this is version pre 2.2.1, |
| 1170 | // if that is updated the call to smali in "task "${smaliToDexTask}"(type: Exec)" below might |
| 1171 | // need to change as smali got a completely new command line interface in version 2.2.1. |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1172 | // |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1173 | // PATH=$HOME/android/master/out/host/linux-x86/bin:$PATH tools/gradle.py -Pandroid_source buildArtTests |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1174 | // |
| 1175 | // 4a. If any failures are produced in step 4, figure out what went wrong and add an entry in |
| 1176 | // skippedTests with an explanation. Rerun from step 3. |
| 1177 | // |
| 1178 | // 5. Run the tests: |
| 1179 | // tools/gradle.py clean |
| 1180 | // tools/test.py |
| 1181 | // |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1182 | // 5a. If any more tests fail, either fix the issue or add them to the failuresToTriage list (note |
| 1183 | // that you need to change "_" to "-" from stdout). Rerun from step 5 if anything was added to |
| 1184 | // failuresToTriage. |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1185 | // |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1186 | // 6. To upload a new version to Google Cloud Storage: |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1187 | // cd tests |
| 1188 | // upload_to_google_storage.py -a --bucket r8-deps art |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1189 | // |
| 1190 | // 7. Update the manifest file describing the Android repo used: |
| 1191 | // repo manifest -o <r8-checkout-root>/tools/linux/aosp_master_manifest.xml -r |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1192 | |
| 1193 | enum DexTool { |
| 1194 | JACK, |
| 1195 | DX |
| 1196 | } |
| 1197 | |
| 1198 | def androidCheckoutDir = file("${System.env.HOME}/android/master") |
| 1199 | def androidCheckoutJack = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack"); |
| 1200 | def androidCheckoutJackServer = file("${androidCheckoutDir}/out/host/linux-x86/bin/jack-admin"); |
| 1201 | |
| 1202 | def artTestDir = file("${androidCheckoutDir}/art/test") |
| 1203 | |
| 1204 | if (project.hasProperty('android_source')) { |
| 1205 | task buildArtTests { |
| 1206 | outputs.upToDateWhen { false } |
| 1207 | def toBeTriaged = [ |
| 1208 | "903-hello-tagging", |
| 1209 | "904-object-allocation", |
| 1210 | "905-object-free", |
| 1211 | "906-iterate-heap", |
| 1212 | "907-get-loaded-classes", |
| 1213 | "908-gc-start-finish", |
| 1214 | "954-invoke-polymorphic-verifier", |
| 1215 | "955-methodhandles-smali", |
| 1216 | "596-monitor-inflation", |
| 1217 | ] |
| 1218 | def skippedTests = toBeTriaged + [ |
| 1219 | // This test produces no jar. |
| 1220 | "000-nop", |
| 1221 | // This does not build, as it tests the error when the application exceeds more |
| 1222 | // than 65536 methods |
| 1223 | "089-many-methods", |
| 1224 | // Requires some jack beta jar |
| 1225 | "956-methodhandles", |
| 1226 | ] |
| 1227 | |
| 1228 | def skippedTestsDx = [ |
| 1229 | // Tests with custom build scripts, where javac is not passed the options |
| 1230 | // -source 1.7 -target 1.7. |
| 1231 | "462-checker-inlining-across-dex-files", |
| 1232 | "556-invoke-super", |
| 1233 | "569-checker-pattern-replacement", |
| 1234 | // These tests use jack even when --build-with-javac-dx is specified. |
| 1235 | "004-JniTest", |
| 1236 | "048-reflect-v8", |
| 1237 | "146-bad-interface", |
| 1238 | "563-checker-invoke-super", |
| 1239 | "580-checker-string-fact-intrinsics", // java.lang.StringFactory |
| 1240 | "604-hot-static-interface", |
| 1241 | "957-methodhandle-transforms", |
| 1242 | "958-methodhandle-emulated-stackframe", |
| 1243 | "959-invoke-polymorphic-accessors", |
| 1244 | "961-default-iface-resolution-gen", |
| 1245 | "962-iface-static", |
| 1246 | "963-default-range-smali", |
| 1247 | "964-default-iface-init-gen", |
| 1248 | "965-default-verify", |
| 1249 | "966-default-conflict", |
| 1250 | "967-default-ame", |
| 1251 | "968-default-partial-compile-gen", |
| 1252 | "969-iface-super", |
| 1253 | "970-iface-super-resolution-gen", |
| 1254 | "971-iface-super", |
| 1255 | // These tests does not build with --build-with-javac-dx |
| 1256 | "004-NativeAllocations", // Javac error |
| 1257 | "031-class-attributes", |
| 1258 | "138-duplicate-classes-check", |
| 1259 | "157-void-class", // Javac error |
| 1260 | "580-checker-string-factory-intrinsics", |
| 1261 | "612-jit-dex-cache", |
| 1262 | "613-inlining-dex-cache", |
| 1263 | "900-hello-plugin", // --experimental agents |
| 1264 | "901-hello-ti-agent", // --experimental agents |
| 1265 | "902-hello-transformation", // --experimental agents |
| 1266 | "909-attach-agent", // --experimental agents |
| 1267 | "946-obsolete-throw", // -source 1.7 -target 1.7, but use lambda |
| 1268 | "950-redefine-intrinsic", // -source 1.7 -target 1.7, but use method references |
| 1269 | "951-threaded-obsolete", // -source 1.7 -target 1.7, but use lambda |
| 1270 | "960-default-smali", // --experimental default-methods |
| 1271 | // These tests force the build to use jack |
| 1272 | "953-invoke-polymorphic-compiler", |
| 1273 | "958-methodhandle-stackframe", |
| 1274 | ] |
| 1275 | |
| 1276 | def artTestBuildDir = file("${projectDir}/tests/art") |
| 1277 | |
| 1278 | if (androidCheckoutDir.exists()) { |
| 1279 | dependsOn downloadDeps |
| 1280 | artTestBuildDir.mkdirs() |
| 1281 | // Ensure Jack server is running. |
| 1282 | "${androidCheckoutJackServer} start-server".execute() |
| 1283 | artTestDir.eachDir { dir -> |
| 1284 | def name = dir.getName(); |
| 1285 | def markerFile = dir.toPath().resolve("info.txt").toFile(); |
| 1286 | if (markerFile.exists() && !(name in skippedTests)) { |
| 1287 | if (!(name in skippedTestsDx)) { |
| 1288 | dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.DX); |
| 1289 | } |
| 1290 | dependsOn buildArtTest(androidCheckoutDir, artTestBuildDir, dir, DexTool.JACK); |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | doFirst { |
| 1295 | if (!androidCheckoutDir.exists()) { |
| 1296 | throw new InvalidUserDataException( |
| 1297 | "This task requires an Android checkout in ${androidCheckoutDir}"); |
| 1298 | } else if (!androidCheckoutJack.exists() || |
| 1299 | !androidCheckoutJackServer.exists()) { |
| 1300 | throw new InvalidUserDataException( |
| 1301 | "This task requires that tools for host testing have been build in the " + |
| 1302 | "Android checkout in ${androidCheckoutDir}"); |
| 1303 | } |
| 1304 | } |
| 1305 | doLast { |
| 1306 | copy { |
| 1307 | from file("${androidCheckoutDir}/out/host/linux-x86/nativetest64") |
| 1308 | into file("${artTestBuildDir}/lib64") |
| 1309 | include 'lib*.so' |
| 1310 | } |
| 1311 | copy { |
| 1312 | from file("${androidCheckoutDir}/out/host/linux-x86/lib64") |
| 1313 | into file("${artTestBuildDir}/lib64") |
| 1314 | include 'libart.so' |
| 1315 | include 'libbacktrace.so' |
| 1316 | include 'libbase.so' |
| 1317 | include 'libc++.so' |
| 1318 | include 'libcutils.so' |
| 1319 | include 'liblz4.so' |
| 1320 | include 'liblzma.so' |
| 1321 | include 'libnativebridge.so' |
| 1322 | include 'libnativeloader.so' |
| 1323 | include 'libsigchain.so' |
| 1324 | include 'libunwind.so' |
| 1325 | include 'libziparchive.so' |
| 1326 | } |
| 1327 | copy { |
| 1328 | from file("${androidCheckoutDir}/out/host/linux-x86/nativetest") |
| 1329 | into file("${artTestBuildDir}/lib") |
| 1330 | include 'lib*.so' |
| 1331 | } |
| 1332 | copy { |
| 1333 | from file("${androidCheckoutDir}/out/host/linux-x86/lib") |
| 1334 | into file("${artTestBuildDir}/lib") |
| 1335 | include 'libart.so' |
| 1336 | include 'libbacktrace.so' |
| 1337 | include 'libbase.so' |
| 1338 | include 'libc++.so' |
| 1339 | include 'libcutils.so' |
| 1340 | include 'liblz4.so' |
| 1341 | include 'liblzma.so' |
| 1342 | include 'libnativebridge.so' |
| 1343 | include 'libnativeloader.so' |
| 1344 | include 'libsigchain.so' |
| 1345 | include 'libunwind.so' |
| 1346 | include 'libziparchive.so' |
| 1347 | } |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | def buildArtTest(androidCheckoutDir, artTestBuildDir, dir, dexTool) { |
| 1353 | def artTestDir = file("${androidCheckoutDir}/art/test") |
| 1354 | def artRunTestScript = file("${artTestDir}/run-test") |
| 1355 | def dxExecutable = new File("tools/linux/dx/bin/dx"); |
Jean-Marie Henaff | 34d85f7 | 2017-06-14 10:32:04 +0200 | [diff] [blame] | 1356 | def dexMergerExecutable = Utils.dexMergerExecutable() |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1357 | def dexToolName = dexTool == DexTool.DX ? "dx" : "jack" |
| 1358 | |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1359 | def name = dir.getName() |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1360 | def buildTask = "build_art_test_${dexToolName}_${name}" |
| 1361 | def sanitizeTask = "sanitize_art_test_${dexToolName}_${name}" |
| 1362 | def copyCheckTask = "copy_check_art_test_${dexToolName}_${name}" |
| 1363 | def smaliToDexTask = "smali_to_dex_${dexToolName}_${name}" |
| 1364 | |
| 1365 | def buildInputs = fileTree(dir: dir, include: '**/*') |
| 1366 | def testDir = file("${artTestBuildDir}/${dexToolName}/${name}") |
| 1367 | def outputJar = testDir.toPath().resolve("${name}.jar").toFile() |
| 1368 | testDir.mkdirs() |
| 1369 | if (dexTool == DexTool.DX) { |
| 1370 | task "$buildTask"(type: Exec) { |
| 1371 | outputs.upToDateWhen { false } |
| 1372 | inputs.file buildInputs |
| 1373 | executable "${artRunTestScript}" |
| 1374 | args "--host" |
| 1375 | args "--build-only" |
| 1376 | args "--build-with-javac-dx" |
| 1377 | args "--output-path", "${testDir}" |
| 1378 | args "${name}" |
| 1379 | environment DX: "${dxExecutable.absolutePath}" |
| 1380 | environment DXMERGER: "${dexMergerExecutable.absolutePath}" |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1381 | environment ANDROID_BUILD_TOP: "${androidCheckoutDir}" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1382 | outputs.file outputJar |
| 1383 | } |
| 1384 | } else { |
| 1385 | assert dexTool == DexTool.JACK |
| 1386 | def javaLibs = "${androidCheckoutDir}/out/host/common/obj/JAVA_LIBRARIES" |
| 1387 | def jackClasspath = "${javaLibs}/core-libart-hostdex_intermediates/classes.jack:" + |
| 1388 | "${javaLibs}/core-oj-hostdex_intermediates/classes.jack" |
| 1389 | task "$buildTask"(type: Exec) { |
| 1390 | outputs.upToDateWhen { false } |
| 1391 | inputs.file buildInputs |
| 1392 | executable "${artRunTestScript}" |
| 1393 | args "--host" |
| 1394 | args "--build-only" |
| 1395 | args "--output-path", "${testDir}" |
| 1396 | args "${name}" |
| 1397 | environment JACK: "${androidCheckoutDir}/out/host/linux-x86/bin/jack" |
| 1398 | environment JACK_CLASSPATH: jackClasspath |
| 1399 | environment DXMERGER: "${dexMergerExecutable.absolutePath}" |
| 1400 | environment ANDROID_BUILD_TOP: "${androidCheckoutDir}" |
| 1401 | outputs.file outputJar |
| 1402 | } |
| 1403 | } |
| 1404 | task "${sanitizeTask}"(type: Exec, dependsOn: buildTask) { |
| 1405 | outputs.upToDateWhen { false } |
| 1406 | executable "/bin/bash" |
| 1407 | args "-c" |
| 1408 | args "rm -rf ${testDir}/smali_*.dex ${testDir}/*-ex.dex ${testDir}/*-ex.jar" + |
| 1409 | " ${testDir}/classes-ex ${testDir}/check" |
| 1410 | } |
| 1411 | |
| 1412 | task "${smaliToDexTask}"(type: Exec) { |
| 1413 | workingDir "${testDir}/smali" |
| 1414 | executable "/bin/bash" |
Søren Gjesse | 34b7773 | 2017-07-07 13:56:21 +0200 | [diff] [blame] | 1415 | // This is the command line options for smali prior to 2.2.1, where smali got a new |
| 1416 | // command line interface. |
| 1417 | args "-c", "smali a *.smali" |
| 1418 | // This is the command line options for smali 2.2.1 and later. |
| 1419 | // args "-c", "smali -o out.dex *.smali" |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | task "${copyCheckTask}"(type: Copy, dependsOn: sanitizeTask) { |
| 1423 | def smali_dir = file("${dir}/smali") |
| 1424 | outputs.upToDateWhen { false } |
| 1425 | if (smali_dir.exists() && dexTool == DexTool.DX) { |
| 1426 | dependsOn smaliToDexTask |
| 1427 | } |
| 1428 | from("${artTestDir}/${name}") { |
| 1429 | include 'check' |
| 1430 | } |
| 1431 | into testDir |
| 1432 | } |
| 1433 | |
| 1434 | return copyCheckTask |
| 1435 | } |
| 1436 | |
| 1437 | task javadocD8(type: Javadoc) { |
| 1438 | classpath = sourceSets.main.compileClasspath |
| 1439 | source = sourceSets.main.allJava |
| 1440 | include '**/com/android/tools/r8/BaseCommand.java' |
| 1441 | include '**/com/android/tools/r8/BaseOutput.java' |
| 1442 | include '**/com/android/tools/r8/CompilationException.java' |
| 1443 | include '**/com/android/tools/r8/CompilationMode.java' |
| 1444 | include '**/com/android/tools/r8/D8.java' |
| 1445 | include '**/com/android/tools/r8/D8Command.java' |
| 1446 | include '**/com/android/tools/r8/D8Output.java' |
| 1447 | include '**/com/android/tools/r8/Resource.java' |
| 1448 | } |