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