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