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