Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | // This file contains the module types for compiling Java for Android, and converts the properties |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 18 | // into the flags and filenames necessary to pass to the Module. The final creation of the rules |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 19 | // is handled in builder.go |
| 20 | |
| 21 | import ( |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 22 | "fmt" |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 23 | "path/filepath" |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 24 | "strconv" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 25 | "strings" |
| 26 | |
| 27 | "github.com/google/blueprint" |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/pathtools" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint/proptools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 30 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 31 | "android/soong/android" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 32 | "android/soong/java/config" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 33 | "android/soong/tradefed" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 36 | func init() { |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 37 | RegisterJavaBuildComponents(android.InitRegistrationContext) |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 38 | |
| 39 | // Register sdk member types. |
| 40 | android.RegisterSdkMemberType(&headerLibrarySdkMemberType{ |
| 41 | librarySdkMemberType{ |
| 42 | android.SdkMemberTypeBase{ |
| 43 | PropertyName: "java_header_libs", |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 44 | SupportsSdk: true, |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 45 | }, |
| 46 | }, |
| 47 | }) |
| 48 | |
| 49 | android.RegisterSdkMemberType(&implLibrarySdkMemberType{ |
| 50 | librarySdkMemberType{ |
| 51 | android.SdkMemberTypeBase{ |
| 52 | PropertyName: "java_libs", |
| 53 | }, |
| 54 | }, |
| 55 | }) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 56 | |
| 57 | android.RegisterSdkMemberType(&testSdkMemberType{ |
| 58 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 59 | PropertyName: "java_tests", |
| 60 | }, |
| 61 | }) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 64 | func RegisterJavaBuildComponents(ctx android.RegistrationContext) { |
| 65 | ctx.RegisterModuleType("java_defaults", DefaultsFactory) |
| 66 | |
| 67 | ctx.RegisterModuleType("java_library", LibraryFactory) |
| 68 | ctx.RegisterModuleType("java_library_static", LibraryStaticFactory) |
| 69 | ctx.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 70 | ctx.RegisterModuleType("java_binary", BinaryFactory) |
| 71 | ctx.RegisterModuleType("java_binary_host", BinaryHostFactory) |
| 72 | ctx.RegisterModuleType("java_test", TestFactory) |
| 73 | ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory) |
| 74 | ctx.RegisterModuleType("java_test_host", TestHostFactory) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 75 | ctx.RegisterModuleType("java_test_import", JavaTestImportFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 76 | ctx.RegisterModuleType("java_import", ImportFactory) |
| 77 | ctx.RegisterModuleType("java_import_host", ImportFactoryHost) |
| 78 | ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) |
| 79 | ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) |
| 80 | ctx.RegisterModuleType("dex_import", DexImportFactory) |
| 81 | |
| 82 | ctx.RegisterSingletonType("logtags", LogtagsSingleton) |
| 83 | ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) |
| 84 | } |
| 85 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 86 | func (j *Module) checkSdkVersion(ctx android.ModuleContext) { |
| 87 | if j.SocSpecific() || j.DeviceSpecific() || |
| 88 | (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { |
| 89 | if sc, ok := ctx.Module().(sdkContext); ok { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 90 | if !sc.sdkVersion().specified() { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 91 | ctx.PropertyErrorf("sdk_version", |
| 92 | "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).") |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 98 | func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { |
| 99 | if sc, ok := ctx.Module().(sdkContext); ok { |
| 100 | usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis) |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 101 | sdkVersionSpecified := sc.sdkVersion().specified() |
| 102 | if usePlatformAPI && sdkVersionSpecified { |
| 103 | ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.") |
| 104 | } else if !usePlatformAPI && !sdkVersionSpecified { |
| 105 | ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.") |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } |
| 109 | } |
| 110 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 111 | // TODO: |
| 112 | // Autogenerated files: |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 113 | // Renderscript |
| 114 | // Post-jar passes: |
| 115 | // Proguard |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 116 | // Rmtypedefs |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 117 | // DroidDoc |
| 118 | // Findbugs |
| 119 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 120 | type CompilerProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 121 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 122 | // or .aidl files. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 123 | Srcs []string `android:"path,arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 124 | |
| 125 | // list of source files that should not be used to build the Java module. |
| 126 | // This is most useful in the arch/multilib variants to remove non-common files |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 127 | Exclude_srcs []string `android:"path,arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 128 | |
| 129 | // list of directories containing Java resources |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 130 | Java_resource_dirs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 131 | |
Colin Cross | 86a63ff | 2017-09-27 17:33:10 -0700 | [diff] [blame] | 132 | // list of directories that should be excluded from java_resource_dirs |
| 133 | Exclude_java_resource_dirs []string `android:"arch_variant"` |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 134 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 135 | // list of files to use as Java resources |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 136 | Java_resources []string `android:"path,arch_variant"` |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 137 | |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 138 | // list of files that should be excluded from java_resources and java_resource_dirs |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 139 | Exclude_java_resources []string `android:"path,arch_variant"` |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 140 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 141 | // list of module-specific flags that will be used for javac compiles |
| 142 | Javacflags []string `android:"arch_variant"` |
| 143 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 144 | // list of module-specific flags that will be used for kotlinc compiles |
| 145 | Kotlincflags []string `android:"arch_variant"` |
| 146 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 147 | // list of of java libraries that will be in the classpath |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 148 | Libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 149 | |
| 150 | // list of java libraries that will be compiled into the resulting jar |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 151 | Static_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 152 | |
| 153 | // manifest file to be included in resulting jar |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 154 | Manifest *string `android:"path"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 155 | |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 156 | // if not blank, run jarjar using the specified rules file |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 157 | Jarjar_rules *string `android:"path,arch_variant"` |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 158 | |
| 159 | // If not blank, set the java version passed to javac as -source and -target |
| 160 | Java_version *string |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 161 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 162 | // If set to true, allow this module to be dexed and installed on devices. Has no |
| 163 | // effect on host modules, which are always considered installable. |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 164 | Installable *bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 165 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 166 | // If set to true, include sources used to compile the module in to the final jar |
| 167 | Include_srcs *bool |
| 168 | |
Vladimir Marko | 0975ee0 | 2019-04-02 10:29:55 +0100 | [diff] [blame] | 169 | // If not empty, classes are restricted to the specified packages and their sub-packages. |
| 170 | // This restriction is checked after applying jarjar rules and including static libs. |
| 171 | Permitted_packages []string |
| 172 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 173 | // List of modules to use as annotation processors |
| 174 | Plugins []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 175 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 176 | // List of modules to export to libraries that directly depend on this library as annotation processors |
| 177 | Exported_plugins []string |
| 178 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 179 | // The number of Java source entries each Javac instance can process |
| 180 | Javac_shard_size *int64 |
| 181 | |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 182 | // Add host jdk tools.jar to bootclasspath |
| 183 | Use_tools_jar *bool |
| 184 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 185 | Openjdk9 struct { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 186 | // List of source files that should only be used when passing -source 1.9 or higher |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 187 | Srcs []string `android:"path"` |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 188 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 189 | // List of javac flags that should only be used when passing -source 1.9 or higher |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 190 | Javacflags []string |
| 191 | } |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 192 | |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 193 | // When compiling language level 9+ .java code in packages that are part of |
| 194 | // a system module, patch_module names the module that your sources and |
| 195 | // dependencies should be patched into. The Android runtime currently |
| 196 | // doesn't implement the JEP 261 module system so this option is only |
| 197 | // supported at compile time. It should only be needed to compile tests in |
| 198 | // packages that exist in libcore and which are inconvenient to move |
| 199 | // elsewhere. |
Tobias Thierer | dda713d | 2018-09-19 16:16:19 +0100 | [diff] [blame] | 200 | Patch_module *string `android:"arch_variant"` |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 201 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 202 | Jacoco struct { |
| 203 | // List of classes to include for instrumentation with jacoco to collect coverage |
| 204 | // information at runtime when building with coverage enabled. If unset defaults to all |
| 205 | // classes. |
| 206 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 207 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 208 | // it matches classes in the package that have the class name as a prefix. |
| 209 | Include_filter []string |
| 210 | |
| 211 | // List of classes to exclude from instrumentation with jacoco to collect coverage |
| 212 | // information at runtime when building with coverage enabled. Overrides classes selected |
| 213 | // by the include_filter property. |
| 214 | // Supports '*' as the last character of an entry in the list as a wildcard match. |
| 215 | // If preceded by '.' it matches all classes in the package and subpackages, otherwise |
| 216 | // it matches classes in the package that have the class name as a prefix. |
| 217 | Exclude_filter []string |
| 218 | } |
| 219 | |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 220 | Errorprone struct { |
| 221 | // List of javac flags that should only be used when running errorprone. |
| 222 | Javacflags []string |
| 223 | } |
| 224 | |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 225 | Proto struct { |
| 226 | // List of extra options that will be passed to the proto generator. |
| 227 | Output_params []string |
| 228 | } |
| 229 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 230 | Instrument bool `blueprint:"mutated"` |
Alex Light | 7f004a7 | 2019-02-21 13:27:37 -0800 | [diff] [blame] | 231 | |
| 232 | // List of files to include in the META-INF/services folder of the resulting jar. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 233 | Services []string `android:"path,arch_variant"` |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 236 | type CompilerDeviceProperties struct { |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 237 | // list of module-specific flags that will be used for dex compiles |
| 238 | Dxflags []string `android:"arch_variant"` |
| 239 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 240 | // if not blank, set to the version of the sdk to compile against. |
| 241 | // Defaults to compiling against the current platform. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 242 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 243 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 244 | // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. |
| 245 | // Defaults to sdk_version if not set. |
| 246 | Min_sdk_version *string |
| 247 | |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 248 | // if not blank, set the targetSdkVersion in the AndroidManifest.xml. |
| 249 | // Defaults to sdk_version if not set. |
| 250 | Target_sdk_version *string |
| 251 | |
Jeongik Cha | 356dac4 | 2019-08-19 14:09:52 +0900 | [diff] [blame] | 252 | // Whether to compile against the platform APIs instead of an SDK. |
| 253 | // If true, then sdk_version must be empty. The value of this field |
| 254 | // is ignored when module's type isn't android_app. |
Colin Cross | 6af2e49 | 2018-05-22 11:12:33 -0700 | [diff] [blame] | 255 | Platform_apis *bool |
| 256 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 257 | Aidl struct { |
| 258 | // Top level directories to pass to aidl tool |
| 259 | Include_dirs []string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 260 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 261 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 262 | Local_include_dirs []string |
| 263 | |
| 264 | // directories that should be added as include directories for any aidl sources of modules |
| 265 | // that depend on this module, as well as to aidl for this module. |
| 266 | Export_include_dirs []string |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 267 | |
| 268 | // whether to generate traces (for systrace) for this interface |
| 269 | Generate_traces *bool |
Olivier Gaillard | 0a4cfbc | 2018-07-16 23:37:03 +0100 | [diff] [blame] | 270 | |
| 271 | // whether to generate Binder#GetTransaction name method. |
| 272 | Generate_get_transaction_name *bool |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 273 | } |
Colin Cross | 9243010 | 2017-10-09 14:59:32 -0700 | [diff] [blame] | 274 | |
| 275 | // If true, export a copy of the module as a -hostdex module for host testing. |
| 276 | Hostdex *bool |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 277 | |
Colin Cross | 7f87f4f | 2019-04-24 13:41:45 -0700 | [diff] [blame] | 278 | Target struct { |
| 279 | Hostdex struct { |
| 280 | // Additional required dependencies to add to -hostdex modules. |
| 281 | Required []string |
| 282 | } |
| 283 | } |
| 284 | |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 285 | // If set to true, compile dex regardless of installable. Defaults to false. |
| 286 | Compile_dex *bool |
| 287 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 288 | Optimize struct { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 289 | // If false, disable all optimization. Defaults to true for android_app and android_test |
| 290 | // modules, false for java_library and java_test modules. |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 291 | Enabled *bool |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 292 | // True if the module containing this has it set by default. |
| 293 | EnabledByDefault bool `blueprint:"mutated"` |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 294 | |
| 295 | // If true, optimize for size by removing unused code. Defaults to true for apps, |
| 296 | // false for libraries and tests. |
| 297 | Shrink *bool |
| 298 | |
| 299 | // If true, optimize bytecode. Defaults to false. |
| 300 | Optimize *bool |
| 301 | |
| 302 | // If true, obfuscate bytecode. Defaults to false. |
| 303 | Obfuscate *bool |
| 304 | |
| 305 | // If true, do not use the flag files generated by aapt that automatically keep |
| 306 | // classes referenced by the app manifest. Defaults to false. |
| 307 | No_aapt_flags *bool |
| 308 | |
| 309 | // Flags to pass to proguard. |
| 310 | Proguard_flags []string |
| 311 | |
| 312 | // Specifies the locations of files containing proguard flags. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 313 | Proguard_flags_files []string `android:"path"` |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 316 | // When targeting 1.9 and above, override the modules to use with --system, |
| 317 | // otherwise provides defaults libraries to add to the bootclasspath. |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 318 | System_modules *string |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 319 | |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 320 | // set the name of the output |
| 321 | Stem *string |
| 322 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 323 | UncompressDex bool `blueprint:"mutated"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 324 | IsSDKLibrary bool `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 327 | func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { |
| 328 | return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault) |
| 329 | } |
| 330 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 331 | // Module contains the properties and members used by all java module types |
| 332 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 333 | android.ModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 334 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 335 | android.ApexModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 336 | android.SdkBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 337 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 338 | properties CompilerProperties |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 339 | protoProperties android.ProtoProperties |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 340 | deviceProperties CompilerDeviceProperties |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 341 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 342 | // jar file containing header classes including static library dependencies, suitable for |
| 343 | // inserting into the bootclasspath/classpath of another compile |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 344 | headerJarFile android.Path |
| 345 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 346 | // jar file containing implementation classes including static library dependencies but no |
| 347 | // resources |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 348 | implementationJarFile android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 349 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 350 | // jar file containing only resources including from static library dependencies |
| 351 | resourceJar android.Path |
| 352 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 353 | // args and dependencies to package source files into a srcjar |
| 354 | srcJarArgs []string |
| 355 | srcJarDeps android.Paths |
| 356 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 357 | // jar file containing implementation classes and resources including static library |
| 358 | // dependencies |
| 359 | implementationAndResourcesJar android.Path |
| 360 | |
| 361 | // output file containing classes.dex and resources |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 362 | dexJarFile android.Path |
| 363 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 364 | // output file that contains classes.dex if it should be in the output file |
| 365 | maybeStrippedDexJarFile android.Path |
| 366 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 367 | // output file containing uninstrumented classes that will be instrumented by jacoco |
| 368 | jacocoReportClassesFile android.Path |
| 369 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 370 | // output file containing mapping of obfuscated names |
| 371 | proguardDictionary android.Path |
| 372 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 373 | // output file of the module, which may be a classes jar or a dex jar |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 374 | outputFile android.Path |
| 375 | extraOutputFiles android.Paths |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 376 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 377 | exportAidlIncludeDirs android.Paths |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 378 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 379 | logtagsSrcs android.Paths |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 380 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 381 | // installed file for binary dependency |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 382 | installFile android.Path |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 383 | |
| 384 | // list of .java files and srcjars that was passed to javac |
| 385 | compiledJavaSrcs android.Paths |
| 386 | compiledSrcJars android.Paths |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 387 | |
| 388 | // list of extra progurad flag files |
| 389 | extraProguardFlagFiles android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 390 | |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 391 | // manifest file to use instead of properties.Manifest |
| 392 | overrideManifest android.OptionalPath |
| 393 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 394 | // list of SDK lib names that this java module is exporting |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 395 | exportedSdkLibs []string |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 396 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 397 | // list of plugins that this java module is exporting |
| 398 | exportedPluginJars android.Paths |
| 399 | |
| 400 | // list of plugins that this java module is exporting |
| 401 | exportedPluginClasses []string |
| 402 | |
| 403 | // list of source files, collected from srcFiles with unique java and all kt files, |
patricktu | 242faad | 2019-09-24 15:41:30 +0800 | [diff] [blame] | 404 | // will be used by android.IDEInfo struct |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 405 | expandIDEInfoCompiledSrcs []string |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 406 | |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 407 | // expanded Jarjar_rules |
| 408 | expandJarjarRules android.Path |
| 409 | |
Vladimir Marko | 0975ee0 | 2019-04-02 10:29:55 +0100 | [diff] [blame] | 410 | // list of additional targets for checkbuild |
| 411 | additionalCheckedModules android.Paths |
| 412 | |
Colin Cross | 988708c | 2019-05-06 14:04:11 -0700 | [diff] [blame] | 413 | // Extra files generated by the module type to be added as java resources. |
| 414 | extraResources android.Paths |
| 415 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 416 | hiddenAPI |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 417 | dexpreopter |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 418 | |
| 419 | // list of the xref extraction files |
| 420 | kytheFiles android.Paths |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 423 | func (j *Module) OutputFiles(tag string) (android.Paths, error) { |
| 424 | switch tag { |
| 425 | case "": |
| 426 | return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil |
Colin Cross | 375ca3c | 2019-05-29 14:40:58 -0700 | [diff] [blame] | 427 | case ".jar": |
| 428 | return android.Paths{j.implementationAndResourcesJar}, nil |
Colin Cross | 2d975b1 | 2019-07-29 16:47:42 -0700 | [diff] [blame] | 429 | case ".proguard_map": |
| 430 | return android.Paths{j.proguardDictionary}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 431 | default: |
| 432 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 433 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 436 | var _ android.OutputFileProducer = (*Module)(nil) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 437 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 438 | type Dependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 439 | HeaderJars() android.Paths |
| 440 | ImplementationJars() android.Paths |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 441 | ResourceJars() android.Paths |
| 442 | ImplementationAndResourcesJars() android.Paths |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 443 | DexJar() android.Path |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 444 | AidlIncludeDirs() android.Paths |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 445 | ExportedSdkLibs() []string |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 446 | ExportedPlugins() (android.Paths, []string) |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 447 | SrcJarArgs() ([]string, android.Paths) |
Colin Cross | e323f3c | 2019-09-17 15:34:09 -0700 | [diff] [blame] | 448 | BaseModuleName() string |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 449 | JacocoReportClassesFile() android.Path |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 452 | type SdkLibraryDependency interface { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 453 | SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths |
| 454 | SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 455 | } |
| 456 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 457 | type xref interface { |
| 458 | XrefJavaFiles() android.Paths |
| 459 | } |
| 460 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 461 | func (j *Module) XrefJavaFiles() android.Paths { |
| 462 | return j.kytheFiles |
| 463 | } |
| 464 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 465 | func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 466 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 467 | android.InitDefaultableModule(module) |
| 468 | } |
| 469 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 470 | type dependencyTag struct { |
| 471 | blueprint.BaseDependencyTag |
| 472 | name string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 475 | type jniDependencyTag struct { |
| 476 | blueprint.BaseDependencyTag |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 479 | func IsJniDepTag(depTag blueprint.DependencyTag) bool { |
| 480 | _, ok := depTag.(*jniDependencyTag) |
| 481 | return ok |
| 482 | } |
| 483 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 484 | var ( |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 485 | staticLibTag = dependencyTag{name: "staticlib"} |
| 486 | libTag = dependencyTag{name: "javalib"} |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 487 | java9LibTag = dependencyTag{name: "java9lib"} |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 488 | pluginTag = dependencyTag{name: "plugin"} |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 489 | exportedPluginTag = dependencyTag{name: "exported-plugin"} |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 490 | bootClasspathTag = dependencyTag{name: "bootclasspath"} |
| 491 | systemModulesTag = dependencyTag{name: "system modules"} |
| 492 | frameworkResTag = dependencyTag{name: "framework-res"} |
| 493 | frameworkApkTag = dependencyTag{name: "framework-apk"} |
| 494 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"} |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 495 | kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"} |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 496 | proguardRaiseTag = dependencyTag{name: "proguard-raise"} |
| 497 | certificateTag = dependencyTag{name: "certificate"} |
| 498 | instrumentationForTag = dependencyTag{name: "instrumentation_for"} |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 499 | usesLibTag = dependencyTag{name: "uses-library"} |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 500 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 501 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 502 | func IsLibDepTag(depTag blueprint.DependencyTag) bool { |
| 503 | return depTag == libTag |
| 504 | } |
| 505 | |
| 506 | func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool { |
| 507 | return depTag == staticLibTag |
| 508 | } |
| 509 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 510 | type sdkDep struct { |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 511 | useModule, useFiles, useDefaultLibs, invalidVersion bool |
| 512 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 513 | // The modules that will be added to the bootclasspath when targeting 1.8 or lower |
| 514 | bootclasspath []string |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 515 | |
| 516 | // The default system modules to use. Will be an empty string if no system |
| 517 | // modules are to be used. |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 518 | systemModules string |
| 519 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 520 | // The modules that will be added ot the classpath when targeting 1.9 or higher |
| 521 | java9Classpath []string |
| 522 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 523 | frameworkResModule string |
| 524 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 525 | jars android.Paths |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 526 | aidl android.OptionalPath |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 527 | |
| 528 | noStandardLibs, noFrameworksLibs bool |
| 529 | } |
| 530 | |
| 531 | func (s sdkDep) hasStandardLibs() bool { |
| 532 | return !s.noStandardLibs |
| 533 | } |
| 534 | |
| 535 | func (s sdkDep) hasFrameworkLibs() bool { |
| 536 | return !s.noStandardLibs && !s.noFrameworksLibs |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 539 | type jniLib struct { |
| 540 | name string |
| 541 | path android.Path |
| 542 | target android.Target |
| 543 | } |
| 544 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 545 | func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 546 | return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 547 | } |
| 548 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 549 | func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 550 | return j.shouldInstrument(ctx) && |
| 551 | (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") || |
| 552 | ctx.Config().UnbundledBuild()) |
| 553 | } |
| 554 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 555 | func (j *Module) sdkVersion() sdkSpec { |
| 556 | return sdkSpecFrom(String(j.deviceProperties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 559 | func (j *Module) systemModules() string { |
| 560 | return proptools.String(j.deviceProperties.System_modules) |
| 561 | } |
| 562 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 563 | func (j *Module) minSdkVersion() sdkSpec { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 564 | if j.deviceProperties.Min_sdk_version != nil { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 565 | return sdkSpecFrom(*j.deviceProperties.Min_sdk_version) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 566 | } |
| 567 | return j.sdkVersion() |
| 568 | } |
| 569 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 570 | func (j *Module) targetSdkVersion() sdkSpec { |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 571 | if j.deviceProperties.Target_sdk_version != nil { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 572 | return sdkSpecFrom(*j.deviceProperties.Target_sdk_version) |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 573 | } |
| 574 | return j.sdkVersion() |
| 575 | } |
| 576 | |
Jiyong Park | b02bb40 | 2019-12-03 00:43:57 +0900 | [diff] [blame] | 577 | func (j *Module) AvailableFor(what string) bool { |
| 578 | if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) { |
| 579 | // Exception: for hostdex: true libraries, the platform variant is created |
| 580 | // even if it's not marked as available to platform. In that case, the platform |
| 581 | // variant is used only for the hostdex and not installed to the device. |
| 582 | return true |
| 583 | } |
| 584 | return j.ApexModuleBase.AvailableFor(what) |
| 585 | } |
| 586 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 587 | func (j *Module) deps(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 588 | if ctx.Device() { |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 589 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 590 | if sdkDep.useDefaultLibs { |
| 591 | ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) |
| 592 | ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) |
| 593 | if sdkDep.hasFrameworkLibs() { |
| 594 | ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 595 | } |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 596 | } else if sdkDep.useModule { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 597 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 598 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 599 | ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 600 | if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() { |
| 601 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...) |
| 602 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...) |
| 603 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 604 | } |
Colin Cross | 6d8d8c6 | 2019-10-28 15:10:03 -0700 | [diff] [blame] | 605 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 606 | if ctx.ModuleName() == "android_stubs_current" || |
| 607 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 863f05b | 2018-08-07 13:41:10 -0700 | [diff] [blame] | 608 | ctx.ModuleName() == "android_test_stubs_current" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 609 | ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 610 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 611 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 612 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 613 | syspropPublicStubs := syspropPublicStubs(ctx.Config()) |
| 614 | |
| 615 | // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library, |
| 616 | // and redirects dependency to public stub depending on the link type. |
| 617 | rewriteSyspropLibs := func(libs []string, prop string) []string { |
| 618 | // make a copy |
| 619 | ret := android.CopyOf(libs) |
| 620 | |
| 621 | for idx, lib := range libs { |
| 622 | stub, ok := syspropPublicStubs[lib] |
| 623 | |
| 624 | if !ok { |
| 625 | continue |
| 626 | } |
| 627 | |
| 628 | linkType, _ := j.getLinkType(ctx.ModuleName()) |
Inseob Kim | c523951 | 2020-01-14 15:36:21 +0900 | [diff] [blame] | 629 | // only platform modules can use internal props |
| 630 | if linkType != javaPlatform { |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 631 | ret[idx] = stub |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
| 635 | return ret |
| 636 | } |
| 637 | |
| 638 | ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...) |
| 639 | ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 640 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 641 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...) |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 642 | ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 643 | |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 644 | android.ProtoDeps(ctx, &j.protoProperties) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 645 | if j.hasSrcExt(".proto") { |
| 646 | protoDeps(ctx, &j.protoProperties) |
| 647 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 648 | |
| 649 | if j.hasSrcExt(".kt") { |
| 650 | // TODO(ccross): move this to a mutator pass that can tell if generated sources contain |
| 651 | // Kotlin files |
Colin Cross | 0b03d97 | 2019-05-13 11:06:25 -0700 | [diff] [blame] | 652 | ctx.AddVariationDependencies(nil, kotlinStdlibTag, |
| 653 | "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8") |
Colin Cross | 7788c12 | 2019-01-23 16:14:02 -0800 | [diff] [blame] | 654 | if len(j.properties.Plugins) > 0 { |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 655 | ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") |
| 656 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 657 | } |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 658 | |
Ulya Trafimovich | 38dfa0f | 2020-01-07 16:37:02 +0000 | [diff] [blame] | 659 | // Framework libraries need special handling in static coverage builds: they should not have |
| 660 | // static dependency on jacoco, otherwise there would be multiple conflicting definitions of |
| 661 | // the same jacoco classes coming from different bootclasspath jars. |
| 662 | if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) { |
| 663 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { |
| 664 | j.properties.Instrument = true |
| 665 | } |
| 666 | } else if j.shouldInstrumentStatic(ctx) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 667 | ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 668 | } |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | func hasSrcExt(srcs []string, ext string) bool { |
| 672 | for _, src := range srcs { |
| 673 | if filepath.Ext(src) == ext { |
| 674 | return true |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | return false |
| 679 | } |
| 680 | |
| 681 | func (j *Module) hasSrcExt(ext string) bool { |
| 682 | return hasSrcExt(j.properties.Srcs, ext) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 685 | func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 686 | aidlIncludeDirs android.Paths) (string, android.Paths) { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 687 | |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 688 | aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs) |
| 689 | aidlIncludes = append(aidlIncludes, |
| 690 | android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...) |
| 691 | aidlIncludes = append(aidlIncludes, |
| 692 | android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 693 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 694 | var flags []string |
| 695 | var deps android.Paths |
Steven Moreland | 667f688 | 2018-07-26 12:55:08 -0700 | [diff] [blame] | 696 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 697 | if aidlPreprocess.Valid() { |
| 698 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 699 | deps = append(deps, aidlPreprocess.Path()) |
| 700 | } else if len(aidlIncludeDirs) > 0 { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 701 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 704 | if len(j.exportAidlIncludeDirs) > 0 { |
| 705 | flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I")) |
| 706 | } |
| 707 | |
| 708 | if len(aidlIncludes) > 0 { |
| 709 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 710 | } |
| 711 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 712 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
Colin Cross | 32f3898 | 2018-02-22 11:47:25 -0800 | [diff] [blame] | 713 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
Colin Cross | d48633a | 2017-07-13 14:41:17 -0700 | [diff] [blame] | 714 | flags = append(flags, "-I"+src.String()) |
| 715 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 716 | |
Martijn Coenen | eab1564 | 2018-03-09 09:29:59 +0100 | [diff] [blame] | 717 | if Bool(j.deviceProperties.Aidl.Generate_traces) { |
| 718 | flags = append(flags, "-t") |
| 719 | } |
| 720 | |
Olivier Gaillard | 0a4cfbc | 2018-07-16 23:37:03 +0100 | [diff] [blame] | 721 | if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) { |
| 722 | flags = append(flags, "--transaction_names") |
| 723 | } |
| 724 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 725 | return strings.Join(flags, " "), deps |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 728 | type deps struct { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 729 | classpath classpath |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 730 | java9Classpath classpath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 731 | bootClasspath classpath |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 732 | processorPath classpath |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 733 | processorClasses []string |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 734 | staticJars android.Paths |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 735 | staticHeaderJars android.Paths |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 736 | staticResourceJars android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 737 | aidlIncludeDirs android.Paths |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 738 | srcs android.Paths |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 739 | srcJars android.Paths |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 740 | systemModules *systemModules |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 741 | aidlPreprocess android.OptionalPath |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 742 | kotlinStdlib android.Paths |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 743 | kotlinAnnotations android.Paths |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 744 | |
| 745 | disableTurbine bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 746 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 747 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 748 | func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { |
| 749 | for _, f := range dep.Srcs() { |
| 750 | if f.Ext() != ".jar" { |
| 751 | ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", |
| 752 | ctx.OtherModuleName(dep.(blueprint.Module))) |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 757 | type linkType int |
| 758 | |
| 759 | const ( |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 760 | // TODO(jiyong) rename these for better readability. Make the allowed |
| 761 | // and disallowed link types explicit |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 762 | javaCore linkType = iota |
| 763 | javaSdk |
| 764 | javaSystem |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 765 | javaModule |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 766 | javaPlatform |
| 767 | ) |
| 768 | |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 769 | type linkTypeContext interface { |
| 770 | android.Module |
| 771 | getLinkType(name string) (ret linkType, stubs bool) |
| 772 | } |
| 773 | |
| 774 | func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 775 | ver := m.sdkVersion() |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 776 | switch { |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 777 | case name == "core.current.stubs" || name == "core.platform.api.stubs" || |
| 778 | name == "stub-annotations" || name == "private-stub-annotations-jar" || |
Pete Gillin | cbff326 | 2019-05-08 15:10:06 +0100 | [diff] [blame] | 779 | name == "core-lambda-stubs" || name == "core-generated-annotation-stubs": |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 780 | return javaCore, true |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 781 | case ver.kind == sdkCore: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 782 | return javaCore, false |
| 783 | case name == "android_system_stubs_current": |
| 784 | return javaSystem, true |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 785 | case ver.kind == sdkSystem: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 786 | return javaSystem, false |
| 787 | case name == "android_test_stubs_current": |
| 788 | return javaSystem, true |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 789 | case ver.kind == sdkTest: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 790 | return javaPlatform, false |
| 791 | case name == "android_stubs_current": |
| 792 | return javaSdk, true |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 793 | case ver.kind == sdkPublic: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 794 | return javaSdk, false |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 795 | case name == "android_module_lib_stubs_current": |
| 796 | return javaModule, true |
| 797 | case ver.kind == sdkModule: |
| 798 | return javaModule, false |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 799 | case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 800 | return javaPlatform, false |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 801 | case !ver.valid(): |
| 802 | panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw)) |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 803 | default: |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 804 | return javaSdk, false |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 808 | func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) { |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 809 | if ctx.Host() { |
| 810 | return |
| 811 | } |
| 812 | |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 813 | myLinkType, stubs := from.getLinkType(ctx.ModuleName()) |
Jiyong Park | 46f78fb | 2018-10-20 16:33:17 +0900 | [diff] [blame] | 814 | if stubs { |
| 815 | return |
| 816 | } |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 817 | otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to)) |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 818 | commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source." |
| 819 | |
| 820 | switch myLinkType { |
| 821 | case javaCore: |
| 822 | if otherLinkType != javaCore { |
| 823 | ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage, |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 824 | ctx.OtherModuleName(to)) |
| 825 | } |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 826 | break |
| 827 | case javaSdk: |
| 828 | if otherLinkType != javaCore && otherLinkType != javaSdk { |
| 829 | ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage, |
| 830 | ctx.OtherModuleName(to)) |
| 831 | } |
| 832 | break |
| 833 | case javaSystem: |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 834 | if otherLinkType == javaPlatform || otherLinkType == javaModule { |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 835 | ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage, |
| 836 | ctx.OtherModuleName(to)) |
| 837 | } |
| 838 | break |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 839 | case javaModule: |
| 840 | if otherLinkType == javaPlatform { |
| 841 | ctx.ModuleErrorf("compiles against module API, but dependency %q is compiling against private API."+commonMessage, |
| 842 | ctx.OtherModuleName(to)) |
| 843 | } |
| 844 | break |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 845 | case javaPlatform: |
| 846 | // no restriction on link-type |
| 847 | break |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 851 | func (j *Module) collectDeps(ctx android.ModuleContext) deps { |
| 852 | var deps deps |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 853 | |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 854 | if ctx.Device() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 855 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 856 | if sdkDep.invalidVersion { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 857 | ctx.AddMissingDependencies(sdkDep.bootclasspath) |
| 858 | ctx.AddMissingDependencies(sdkDep.java9Classpath) |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 859 | } else if sdkDep.useFiles { |
| 860 | // sdkDep.jar is actually equivalent to turbine header.jar. |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 861 | deps.classpath = append(deps.classpath, sdkDep.jars...) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 862 | deps.aidlPreprocess = sdkDep.aidl |
| 863 | } else { |
| 864 | deps.aidlPreprocess = sdkDep.aidl |
Colin Cross | 300f038 | 2018-03-06 13:11:51 -0800 | [diff] [blame] | 865 | } |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 868 | ctx.VisitDirectDeps(func(module android.Module) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 869 | otherName := ctx.OtherModuleName(module) |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 870 | tag := ctx.OtherModuleDependencyTag(module) |
| 871 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 872 | if _, ok := tag.(*jniDependencyTag); ok { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 873 | // Handled by AndroidApp.collectAppDeps |
| 874 | return |
| 875 | } |
| 876 | if tag == certificateTag { |
| 877 | // Handled by AndroidApp.collectAppDeps |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 878 | return |
| 879 | } |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 880 | switch module.(type) { |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 881 | case *Library, *AndroidLibrary: |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 882 | if to, ok := module.(linkTypeContext); ok { |
| 883 | switch tag { |
| 884 | case bootClasspathTag, libTag, staticLibTag: |
| 885 | checkLinkType(ctx, j, to, tag.(dependencyTag)) |
| 886 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 887 | } |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 888 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 889 | switch dep := module.(type) { |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 890 | case SdkLibraryDependency: |
| 891 | switch tag { |
| 892 | case libTag: |
| 893 | deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) |
| 894 | // names of sdk libs that are directly depended are exported |
| 895 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 896 | case staticLibTag: |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 897 | ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) |
| 898 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 899 | case Dependency: |
| 900 | switch tag { |
| 901 | case bootClasspathTag: |
| 902 | deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 903 | case libTag, instrumentationForTag: |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 904 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 905 | // sdk lib names from dependencies are re-exported |
| 906 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 907 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 908 | pluginJars, pluginClasses := dep.ExportedPlugins() |
| 909 | addPlugins(&deps, pluginJars, pluginClasses...) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 910 | case java9LibTag: |
| 911 | deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 912 | case staticLibTag: |
| 913 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
| 914 | deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...) |
| 915 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 916 | deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 917 | // sdk lib names from dependencies are re-exported |
| 918 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 919 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 920 | pluginJars, pluginClasses := dep.ExportedPlugins() |
| 921 | addPlugins(&deps, pluginJars, pluginClasses...) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 922 | case pluginTag: |
| 923 | if plugin, ok := dep.(*Plugin); ok { |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 924 | if plugin.pluginProperties.Processor_class != nil { |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 925 | addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class) |
| 926 | } else { |
| 927 | addPlugins(&deps, plugin.ImplementationAndResourcesJars()) |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 928 | } |
| 929 | deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api) |
| 930 | } else { |
| 931 | ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) |
| 932 | } |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 933 | case exportedPluginTag: |
| 934 | if plugin, ok := dep.(*Plugin); ok { |
| 935 | if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api { |
| 936 | ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName) |
| 937 | } |
| 938 | j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...) |
| 939 | if plugin.pluginProperties.Processor_class != nil { |
| 940 | j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class) |
| 941 | } |
| 942 | } else { |
| 943 | ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName) |
| 944 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 945 | case frameworkApkTag: |
| 946 | if ctx.ModuleName() == "android_stubs_current" || |
| 947 | ctx.ModuleName() == "android_system_stubs_current" || |
Nan Zhang | 863f05b | 2018-08-07 13:41:10 -0700 | [diff] [blame] | 948 | ctx.ModuleName() == "android_test_stubs_current" { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 949 | // framework stubs.jar need to depend on framework-res.apk, in order to pull the |
| 950 | // resource files out of there for aapt. |
| 951 | // |
| 952 | // Normally the package rule runs aapt, which includes the resource, |
| 953 | // but we're not running that in our package rule so just copy in the |
| 954 | // resource files here. |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 955 | deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 956 | } |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 957 | case kotlinStdlibTag: |
Colin Cross | 0b03d97 | 2019-05-13 11:06:25 -0700 | [diff] [blame] | 958 | deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...) |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 959 | case kotlinAnnotationsTag: |
| 960 | deps.kotlinAnnotations = dep.HeaderJars() |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 963 | case android.SourceFileProducer: |
| 964 | switch tag { |
| 965 | case libTag: |
| 966 | checkProducesJars(ctx, dep) |
| 967 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 968 | case staticLibTag: |
| 969 | checkProducesJars(ctx, dep) |
| 970 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 971 | deps.staticJars = append(deps.staticJars, dep.Srcs()...) |
| 972 | deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 973 | } |
| 974 | default: |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 975 | switch tag { |
Paul Duffin | 68289b0 | 2019-09-20 13:50:52 +0100 | [diff] [blame] | 976 | case bootClasspathTag: |
| 977 | // If a system modules dependency has been added to the bootclasspath |
| 978 | // then add its libs to the bootclasspath. |
| 979 | sm := module.(*SystemModules) |
| 980 | deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...) |
| 981 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 982 | case systemModulesTag: |
| 983 | if deps.systemModules != nil { |
| 984 | panic("Found two system module dependencies") |
| 985 | } |
| 986 | sm := module.(*SystemModules) |
Dan Willemsen | ff60a73 | 2019-06-13 16:52:01 +0000 | [diff] [blame] | 987 | if sm.outputDir == nil || len(sm.outputDeps) == 0 { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 988 | panic("Missing directory for system module dependency") |
| 989 | } |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 990 | deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 991 | } |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 992 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 993 | }) |
| 994 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 995 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
| 996 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 997 | return deps |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 1000 | func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) { |
| 1001 | deps.processorPath = append(deps.processorPath, pluginJars...) |
| 1002 | deps.processorClasses = append(deps.processorClasses, pluginClasses...) |
| 1003 | } |
| 1004 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1005 | func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1006 | sdk, err := sdkContext.sdkVersion().effectiveVersion(ctx) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1007 | if err != nil { |
| 1008 | ctx.PropertyErrorf("sdk_version", "%s", err) |
| 1009 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 1010 | if javaVersion != "" { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1011 | return normalizeJavaVersion(ctx, javaVersion) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 1012 | } else if ctx.Device() && sdk <= 23 { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1013 | return JAVA_VERSION_7 |
Pete Gillin | a1c9e9d | 2019-10-17 14:52:07 +0100 | [diff] [blame] | 1014 | } else if ctx.Device() && sdk <= 29 { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1015 | return JAVA_VERSION_8 |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 1016 | } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1017 | // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1018 | return JAVA_VERSION_8 |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 1019 | } else { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1020 | return JAVA_VERSION_9 |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 1021 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1024 | type javaVersion int |
| 1025 | |
| 1026 | const ( |
| 1027 | JAVA_VERSION_UNSUPPORTED = 0 |
| 1028 | JAVA_VERSION_6 = 6 |
| 1029 | JAVA_VERSION_7 = 7 |
| 1030 | JAVA_VERSION_8 = 8 |
| 1031 | JAVA_VERSION_9 = 9 |
| 1032 | ) |
| 1033 | |
| 1034 | func (v javaVersion) String() string { |
| 1035 | switch v { |
| 1036 | case JAVA_VERSION_6: |
| 1037 | return "1.6" |
| 1038 | case JAVA_VERSION_7: |
| 1039 | return "1.7" |
| 1040 | case JAVA_VERSION_8: |
| 1041 | return "1.8" |
| 1042 | case JAVA_VERSION_9: |
| 1043 | return "1.9" |
| 1044 | default: |
| 1045 | return "unsupported" |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | // Returns true if javac targeting this version uses system modules instead of a bootclasspath. |
| 1050 | func (v javaVersion) usesJavaModules() bool { |
| 1051 | return v >= 9 |
| 1052 | } |
| 1053 | |
| 1054 | func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion { |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1055 | switch javaVersion { |
| 1056 | case "1.6", "6": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1057 | return JAVA_VERSION_6 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1058 | case "1.7", "7": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1059 | return JAVA_VERSION_7 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1060 | case "1.8", "8": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1061 | return JAVA_VERSION_8 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1062 | case "1.9", "9": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1063 | return JAVA_VERSION_9 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1064 | case "10", "11": |
| 1065 | ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported") |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1066 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1067 | default: |
| 1068 | ctx.PropertyErrorf("java_version", "Unrecognized Java language level") |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1069 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1073 | func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1074 | |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 1075 | var flags javaBuilderFlags |
| 1076 | |
Tobias Thierer | 06dd04f | 2018-09-11 16:21:05 +0100 | [diff] [blame] | 1077 | // javaVersion flag. |
| 1078 | flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
| 1079 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1080 | // javac flags. |
Colin Cross | f03c82b | 2015-04-13 13:53:40 -0700 | [diff] [blame] | 1081 | javacFlags := j.properties.Javacflags |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1082 | if flags.javaVersion.usesJavaModules() { |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 1083 | javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1084 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 1085 | if ctx.Config().MinimizeJavaDebugInfo() { |
Colin Cross | 126a25c | 2017-10-31 13:55:34 -0700 | [diff] [blame] | 1086 | // Override the -g flag passed globally to remove local variable debug info to reduce |
| 1087 | // disk and memory usage. |
| 1088 | javacFlags = append(javacFlags, "-g:source,lines") |
| 1089 | } |
Colin Cross | c228a70 | 2019-11-06 16:18:05 -0800 | [diff] [blame] | 1090 | javacFlags = append(javacFlags, "-Xlint:-dep-ann") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 1091 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 1092 | if ctx.Config().RunErrorProne() { |
| 1093 | if config.ErrorProneClasspath == nil { |
| 1094 | ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?") |
| 1095 | } |
| 1096 | |
| 1097 | errorProneFlags := []string{ |
| 1098 | "-Xplugin:ErrorProne", |
| 1099 | "${config.ErrorProneChecks}", |
| 1100 | } |
| 1101 | errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...) |
| 1102 | |
| 1103 | flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " + |
| 1104 | "'" + strings.Join(errorProneFlags, " ") + "'" |
| 1105 | flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath)) |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1108 | // classpath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1109 | flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...) |
| 1110 | flags.classpath = append(flags.classpath, deps.classpath...) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 1111 | flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 1112 | flags.processorPath = append(flags.processorPath, deps.processorPath...) |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 1113 | |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 1114 | flags.processor = strings.Join(deps.processorClasses, ",") |
| 1115 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1116 | if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() && |
| 1117 | decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() { |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 1118 | // Give host-side tools a version of OpenJDK's standard libraries |
| 1119 | // close to what they're targeting. As of Dec 2017, AOSP is only |
| 1120 | // bundling OpenJDK 8 and 9, so nothing < 8 is available. |
| 1121 | // |
| 1122 | // When building with OpenJDK 8, the following should have no |
| 1123 | // effect since those jars would be available by default. |
| 1124 | // |
| 1125 | // When building with OpenJDK 9 but targeting a version < 1.8, |
| 1126 | // putting them on the bootclasspath means that: |
| 1127 | // a) code can't (accidentally) refer to OpenJDK 9 specific APIs |
| 1128 | // b) references to existing APIs are not reinterpreted in an |
| 1129 | // OpenJDK 9-specific way, eg. calls to subclasses of |
| 1130 | // java.nio.Buffer as in http://b/70862583 |
| 1131 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 1132 | flags.bootClasspath = append(flags.bootClasspath, |
| 1133 | android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"), |
| 1134 | android.PathForSource(ctx, java8Home, "jre/lib/rt.jar")) |
Nan Zhang | 5f8cb42 | 2018-02-06 10:34:32 -0800 | [diff] [blame] | 1135 | if Bool(j.properties.Use_tools_jar) { |
| 1136 | flags.bootClasspath = append(flags.bootClasspath, |
| 1137 | android.PathForSource(ctx, java8Home, "lib/tools.jar")) |
| 1138 | } |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1141 | if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() { |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1142 | // Manually specify build directory in case it is not under the repo root. |
| 1143 | // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so |
| 1144 | // just adding a symlink under the root doesn't help.) |
| 1145 | patchPaths := ".:" + ctx.Config().BuildDir() |
| 1146 | classPath := flags.classpath.FormJavaClassPath("") |
| 1147 | if classPath != "" { |
| 1148 | patchPaths += ":" + classPath |
| 1149 | } |
| 1150 | javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths) |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1153 | // systemModules |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 1154 | flags.systemModules = deps.systemModules |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 1155 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1156 | // aidl flags. |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 1157 | flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1158 | |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 1159 | if len(javacFlags) > 0 { |
| 1160 | // optimization. |
| 1161 | ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " ")) |
| 1162 | flags.javacFlags = "$javacFlags" |
| 1163 | } |
| 1164 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1165 | return flags |
| 1166 | } |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1167 | |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1168 | func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { |
Colin Cross | ebe1a51 | 2017-11-14 13:12:14 -0800 | [diff] [blame] | 1169 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1170 | |
| 1171 | deps := j.collectDeps(ctx) |
| 1172 | flags := j.collectBuilderFlags(ctx, deps) |
| 1173 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1174 | if flags.javaVersion.usesJavaModules() { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1175 | j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) |
| 1176 | } |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1177 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1178 | if hasSrcExt(srcFiles.Strings(), ".proto") { |
Colin Cross | 0f2ee15 | 2017-12-14 15:22:43 -0800 | [diff] [blame] | 1179 | flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 1182 | srcFiles = j.genSources(ctx, srcFiles, flags) |
| 1183 | |
| 1184 | srcJars := srcFiles.FilterByExt(".srcjar") |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 1185 | srcJars = append(srcJars, deps.srcJars...) |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1186 | if aaptSrcJar != nil { |
| 1187 | srcJars = append(srcJars, aaptSrcJar) |
| 1188 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1189 | |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1190 | if j.properties.Jarjar_rules != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1191 | j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1194 | jarName := ctx.ModuleName() + ".jar" |
| 1195 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 1196 | javaSrcFiles := srcFiles.FilterByExt(".java") |
| 1197 | var uniqueSrcFiles android.Paths |
| 1198 | set := make(map[string]bool) |
| 1199 | for _, v := range javaSrcFiles { |
| 1200 | if _, found := set[v.String()]; !found { |
| 1201 | set[v.String()] = true |
| 1202 | uniqueSrcFiles = append(uniqueSrcFiles, v) |
| 1203 | } |
| 1204 | } |
| 1205 | |
patricktu | 242faad | 2019-09-24 15:41:30 +0800 | [diff] [blame] | 1206 | // Collect .java files for AIDEGen |
| 1207 | j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...) |
| 1208 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1209 | var kotlinJars android.Paths |
| 1210 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1211 | if srcFiles.HasExt(".kt") { |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1212 | // user defined kotlin flags. |
| 1213 | kotlincFlags := j.properties.Kotlincflags |
| 1214 | CheckKotlincFlags(ctx, kotlincFlags) |
| 1215 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1216 | // If there are kotlin files, compile them first but pass all the kotlin and java files |
| 1217 | // kotlinc will use the java files to resolve types referenced by the kotlin files, but |
| 1218 | // won't emit any classes for them. |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1219 | kotlincFlags = append(kotlincFlags, "-no-stdlib") |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1220 | if ctx.Device() { |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1221 | kotlincFlags = append(kotlincFlags, "-no-jdk") |
| 1222 | } |
| 1223 | if len(kotlincFlags) > 0 { |
| 1224 | // optimization. |
| 1225 | ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " ")) |
| 1226 | flags.kotlincFlags += "$kotlincFlags" |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Przemyslaw Szczepaniak | 4b5fe9d | 2018-02-13 14:32:54 +0000 | [diff] [blame] | 1229 | var kotlinSrcFiles android.Paths |
| 1230 | kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...) |
| 1231 | kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...) |
| 1232 | |
patricktu | 242faad | 2019-09-24 15:41:30 +0800 | [diff] [blame] | 1233 | // Collect .kt files for AIDEGen |
| 1234 | j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...) |
| 1235 | |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 1236 | flags.classpath = append(flags.classpath, deps.kotlinStdlib...) |
| 1237 | flags.classpath = append(flags.classpath, deps.kotlinAnnotations...) |
| 1238 | |
| 1239 | flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...) |
| 1240 | flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...) |
| 1241 | |
| 1242 | if len(flags.processorPath) > 0 { |
| 1243 | // Use kapt for annotation processing |
| 1244 | kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar") |
| 1245 | kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags) |
| 1246 | srcJars = append(srcJars, kaptSrcJar) |
| 1247 | // Disable annotation processing in javac, it's already been handled by kapt |
| 1248 | flags.processorPath = nil |
Colin Cross | 3a3e94c | 2019-01-23 15:39:50 -0800 | [diff] [blame] | 1249 | flags.processor = "" |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 1250 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1251 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1252 | kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName) |
Colin Cross | 21fc9bb | 2019-01-18 15:05:09 -0800 | [diff] [blame] | 1253 | kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1254 | if ctx.Failed() { |
| 1255 | return |
| 1256 | } |
| 1257 | |
| 1258 | // Make javac rule depend on the kotlinc rule |
| 1259 | flags.classpath = append(flags.classpath, kotlinJar) |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 1260 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1261 | // Jar kotlin classes into the final jar after javac |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1262 | kotlinJars = append(kotlinJars, kotlinJar) |
Colin Cross | 9b38aef | 2018-08-27 15:42:25 -0700 | [diff] [blame] | 1263 | kotlinJars = append(kotlinJars, deps.kotlinStdlib...) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1266 | jars := append(android.Paths(nil), kotlinJars...) |
| 1267 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 1268 | // Store the list of .java files that was passed to javac |
| 1269 | j.compiledJavaSrcs = uniqueSrcFiles |
| 1270 | j.compiledSrcJars = srcJars |
| 1271 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1272 | enable_sharding := false |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 1273 | if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1274 | if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { |
| 1275 | enable_sharding = true |
Ashley Rose | e36efcf | 2019-01-16 17:34:08 -0500 | [diff] [blame] | 1276 | // Formerly, there was a check here that prevented annotation processors |
| 1277 | // from being used when sharding was enabled, as some annotation processors |
| 1278 | // do not function correctly in sharded environments. It was removed to |
| 1279 | // allow for the use of annotation processors that do function correctly |
| 1280 | // with sharding enabled. See: b/77284273. |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1281 | } |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1282 | j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars) |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 1283 | if ctx.Failed() { |
| 1284 | return |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1285 | } |
| 1286 | } |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1287 | if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 { |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1288 | var extraJarDeps android.Paths |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 1289 | if ctx.Config().RunErrorProne() { |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1290 | // If error-prone is enabled, add an additional rule to compile the java files into |
| 1291 | // a separate set of classes (so that they don't overwrite the normal ones and require |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1292 | // a rebuild when error-prone is turned off). |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1293 | // TODO(ccross): Once we always compile with javac9 we may be able to conditionally |
| 1294 | // enable error-prone without affecting the output class files. |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1295 | errorprone := android.PathForModuleOut(ctx, "errorprone", jarName) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1296 | RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 1297 | extraJarDeps = append(extraJarDeps, errorprone) |
| 1298 | } |
| 1299 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1300 | if enable_sharding { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1301 | flags.classpath = append(flags.classpath, j.headerJarFile) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1302 | shardSize := int(*(j.properties.Javac_shard_size)) |
| 1303 | var shardSrcs []android.Paths |
| 1304 | if len(uniqueSrcFiles) > 0 { |
Colin Cross | 0a2f719 | 2019-09-23 14:33:09 -0700 | [diff] [blame] | 1305 | shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1306 | for idx, shardSrc := range shardSrcs { |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 1307 | classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc, |
| 1308 | nil, flags, extraJarDeps) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1309 | jars = append(jars, classes) |
| 1310 | } |
| 1311 | } |
| 1312 | if len(srcJars) > 0 { |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 1313 | classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs), |
| 1314 | nil, srcJars, flags, extraJarDeps) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1315 | jars = append(jars, classes) |
| 1316 | } |
| 1317 | } else { |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 1318 | classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1319 | jars = append(jars, classes) |
| 1320 | } |
Colin Cross | d689143 | 2017-09-27 17:39:56 -0700 | [diff] [blame] | 1321 | if ctx.Failed() { |
| 1322 | return |
| 1323 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1326 | j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles |
| 1327 | |
| 1328 | var includeSrcJar android.WritablePath |
| 1329 | if Bool(j.properties.Include_srcs) { |
| 1330 | includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar") |
| 1331 | TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps) |
| 1332 | } |
| 1333 | |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 1334 | dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, |
| 1335 | j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1336 | fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) |
Colin Cross | 988708c | 2019-05-06 14:04:11 -0700 | [diff] [blame] | 1337 | extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1338 | |
| 1339 | var resArgs []string |
| 1340 | var resDeps android.Paths |
| 1341 | |
| 1342 | resArgs = append(resArgs, dirArgs...) |
| 1343 | resDeps = append(resDeps, dirDeps...) |
| 1344 | |
| 1345 | resArgs = append(resArgs, fileArgs...) |
| 1346 | resDeps = append(resDeps, fileDeps...) |
| 1347 | |
Colin Cross | 988708c | 2019-05-06 14:04:11 -0700 | [diff] [blame] | 1348 | resArgs = append(resArgs, extraArgs...) |
| 1349 | resDeps = append(resDeps, extraDeps...) |
| 1350 | |
Colin Cross | 40a3671 | 2017-09-27 17:41:35 -0700 | [diff] [blame] | 1351 | if len(resArgs) > 0 { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1352 | resourceJar := android.PathForModuleOut(ctx, "res", jarName) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1353 | TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1354 | j.resourceJar = resourceJar |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 1355 | if ctx.Failed() { |
| 1356 | return |
| 1357 | } |
| 1358 | } |
| 1359 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1360 | var resourceJars android.Paths |
| 1361 | if j.resourceJar != nil { |
| 1362 | resourceJars = append(resourceJars, j.resourceJar) |
| 1363 | } |
| 1364 | if Bool(j.properties.Include_srcs) { |
| 1365 | resourceJars = append(resourceJars, includeSrcJar) |
| 1366 | } |
| 1367 | resourceJars = append(resourceJars, deps.staticResourceJars...) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1368 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1369 | if len(resourceJars) > 1 { |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1370 | combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1371 | TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{}, |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1372 | false, nil, nil) |
| 1373 | j.resourceJar = combinedJar |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1374 | } else if len(resourceJars) == 1 { |
| 1375 | j.resourceJar = resourceJars[0] |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1378 | if len(deps.staticJars) > 0 { |
| 1379 | jars = append(jars, deps.staticJars...) |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1380 | } |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1381 | |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1382 | manifest := j.overrideManifest |
| 1383 | if !manifest.Valid() && j.properties.Manifest != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1384 | manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1385 | } |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 1386 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1387 | services := android.PathsForModuleSrc(ctx, j.properties.Services) |
Alex Light | 7f004a7 | 2019-02-21 13:27:37 -0800 | [diff] [blame] | 1388 | if len(services) > 0 { |
| 1389 | servicesJar := android.PathForModuleOut(ctx, "services", jarName) |
| 1390 | var zipargs []string |
| 1391 | for _, file := range services { |
| 1392 | serviceFile := file.String() |
| 1393 | zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile) |
| 1394 | } |
| 1395 | ctx.Build(pctx, android.BuildParams{ |
| 1396 | Rule: zip, |
| 1397 | Output: servicesJar, |
| 1398 | Implicits: services, |
| 1399 | Args: map[string]string{ |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 1400 | "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "), |
Alex Light | 7f004a7 | 2019-02-21 13:27:37 -0800 | [diff] [blame] | 1401 | }, |
| 1402 | }) |
| 1403 | jars = append(jars, servicesJar) |
| 1404 | } |
| 1405 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1406 | // Combine the classes built from sources, any manifests, and any static libraries into |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1407 | // classes.jar. If there is only one input jar this step will be skipped. |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1408 | var outputFile android.ModuleOutPath |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1409 | |
| 1410 | if len(jars) == 1 && !manifest.Valid() { |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1411 | if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok { |
| 1412 | // Optimization: skip the combine step if there is nothing to do |
| 1413 | // TODO(ccross): this leaves any module-info.class files, but those should only come from |
| 1414 | // prebuilt dependencies until we support modules in the platform build, so there shouldn't be |
| 1415 | // any if len(jars) == 1. |
| 1416 | outputFile = moduleOutPath |
| 1417 | } else { |
| 1418 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
| 1419 | ctx.Build(pctx, android.BuildParams{ |
| 1420 | Rule: android.Cp, |
| 1421 | Input: jars[0], |
| 1422 | Output: combinedJar, |
| 1423 | }) |
| 1424 | outputFile = combinedJar |
| 1425 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1426 | } else { |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1427 | combinedJar := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1428 | TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, |
Colin Cross | 9b38aef | 2018-08-27 15:42:25 -0700 | [diff] [blame] | 1429 | false, nil, nil) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1430 | outputFile = combinedJar |
| 1431 | } |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1432 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1433 | // jarjar implementation jar if necessary |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1434 | if j.expandJarjarRules != nil { |
Colin Cross | 8649b26 | 2017-09-27 18:03:17 -0700 | [diff] [blame] | 1435 | // Transform classes.jar into classes-jarjar.jar |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1436 | jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1437 | TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules) |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1438 | outputFile = jarjarFile |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1439 | |
| 1440 | // jarjar resource jar if necessary |
| 1441 | if j.resourceJar != nil { |
| 1442 | resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1443 | TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules) |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1444 | j.resourceJar = resourceJarJarFile |
| 1445 | } |
| 1446 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1447 | if ctx.Failed() { |
| 1448 | return |
| 1449 | } |
| 1450 | } |
Vladimir Marko | 0975ee0 | 2019-04-02 10:29:55 +0100 | [diff] [blame] | 1451 | |
| 1452 | // Check package restrictions if necessary. |
| 1453 | if len(j.properties.Permitted_packages) > 0 { |
| 1454 | // Check packages and copy to package-checked file. |
| 1455 | pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp") |
| 1456 | CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages) |
| 1457 | j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile) |
| 1458 | |
| 1459 | if ctx.Failed() { |
| 1460 | return |
| 1461 | } |
| 1462 | } |
| 1463 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1464 | j.implementationJarFile = outputFile |
| 1465 | if j.headerJarFile == nil { |
| 1466 | j.headerJarFile = j.implementationJarFile |
| 1467 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1468 | |
Colin Cross | 3144dfc | 2018-01-03 15:06:47 -0800 | [diff] [blame] | 1469 | if j.shouldInstrument(ctx) { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1470 | outputFile = j.instrument(ctx, flags, outputFile, jarName) |
| 1471 | } |
| 1472 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1473 | // merge implementation jar with resources if necessary |
| 1474 | implementationAndResourcesJar := outputFile |
| 1475 | if j.resourceJar != nil { |
Colin Cross | 08a409d | 2019-04-29 10:22:44 -0700 | [diff] [blame] | 1476 | jars := android.Paths{j.resourceJar, implementationAndResourcesJar} |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1477 | combinedJar := android.PathForModuleOut(ctx, "withres", jarName) |
Colin Cross | 08a409d | 2019-04-29 10:22:44 -0700 | [diff] [blame] | 1478 | TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest, |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1479 | false, nil, nil) |
| 1480 | implementationAndResourcesJar = combinedJar |
| 1481 | } |
| 1482 | |
| 1483 | j.implementationAndResourcesJar = implementationAndResourcesJar |
| 1484 | |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1485 | if ctx.Device() && j.hasCode(ctx) && |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1486 | (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) { |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1487 | // Dex compilation |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1488 | var dexOutputFile android.ModuleOutPath |
David Brazdil | 17ef563 | 2018-06-27 10:27:45 +0100 | [diff] [blame] | 1489 | dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1490 | if ctx.Failed() { |
| 1491 | return |
| 1492 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1493 | |
Jiyong Park | 09cb629 | 2019-07-15 15:29:23 +0900 | [diff] [blame] | 1494 | // Hidden API CSV generation and dex encoding |
| 1495 | dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile, |
| 1496 | j.deviceProperties.UncompressDex) |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1497 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1498 | // merge dex jar with resources if necessary |
| 1499 | if j.resourceJar != nil { |
| 1500 | jars := android.Paths{dexOutputFile, j.resourceJar} |
| 1501 | combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName) |
| 1502 | TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{}, |
| 1503 | false, nil, nil) |
Nicolas Geoffray | f343872 | 2019-01-23 15:57:21 +0000 | [diff] [blame] | 1504 | if j.deviceProperties.UncompressDex { |
| 1505 | combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName) |
| 1506 | TransformZipAlign(ctx, combinedAlignedJar, combinedJar) |
| 1507 | dexOutputFile = combinedAlignedJar |
| 1508 | } else { |
| 1509 | dexOutputFile = combinedJar |
| 1510 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | j.dexJarFile = dexOutputFile |
| 1514 | |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 1515 | // Dexpreopting |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1516 | dexOutputFile = j.dexpreopt(ctx, dexOutputFile) |
| 1517 | |
| 1518 | j.maybeStrippedDexJarFile = dexOutputFile |
| 1519 | |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1520 | outputFile = dexOutputFile |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1521 | |
| 1522 | if ctx.Failed() { |
| 1523 | return |
| 1524 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1525 | } else { |
| 1526 | outputFile = implementationAndResourcesJar |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1527 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1528 | |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1529 | ctx.CheckbuildFile(outputFile) |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1530 | |
| 1531 | // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource |
| 1532 | j.outputFile = outputFile.WithoutRel() |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 1535 | func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int, |
| 1536 | srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath { |
| 1537 | |
| 1538 | kzipName := pathtools.ReplaceExtension(jarName, "kzip") |
| 1539 | if idx >= 0 { |
| 1540 | kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip" |
| 1541 | jarName += strconv.Itoa(idx) |
| 1542 | } |
| 1543 | |
| 1544 | classes := android.PathForModuleOut(ctx, "javac", jarName) |
| 1545 | TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps) |
| 1546 | |
| 1547 | if ctx.Config().EmitXrefRules() { |
| 1548 | extractionFile := android.PathForModuleOut(ctx, kzipName) |
| 1549 | emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps) |
| 1550 | j.kytheFiles = append(j.kytheFiles, extractionFile) |
| 1551 | } |
| 1552 | |
| 1553 | return classes |
| 1554 | } |
| 1555 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1556 | // Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user, |
| 1557 | // since some of these flags may be used internally. |
| 1558 | func CheckKotlincFlags(ctx android.ModuleContext, flags []string) { |
| 1559 | for _, flag := range flags { |
| 1560 | flag = strings.TrimSpace(flag) |
| 1561 | |
| 1562 | if !strings.HasPrefix(flag, "-") { |
| 1563 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag) |
| 1564 | } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") { |
| 1565 | ctx.PropertyErrorf("kotlincflags", |
| 1566 | "Bad flag: `%s`, only use internal compiler for consistency.", flag) |
| 1567 | } else if inList(flag, config.KotlincIllegalFlags) { |
| 1568 | ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag) |
| 1569 | } else if flag == "-include-runtime" { |
| 1570 | ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag) |
| 1571 | } else { |
| 1572 | args := strings.Split(flag, " ") |
| 1573 | if args[0] == "-kotlin-home" { |
| 1574 | ctx.PropertyErrorf("kotlincflags", |
| 1575 | "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag) |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | } |
| 1580 | |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1581 | func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths, |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1582 | deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1583 | |
| 1584 | var jars android.Paths |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 1585 | if len(srcFiles) > 0 || len(srcJars) > 0 { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1586 | // Compile java sources into turbine.jar. |
| 1587 | turbineJar := android.PathForModuleOut(ctx, "turbine", jarName) |
| 1588 | TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags) |
| 1589 | if ctx.Failed() { |
| 1590 | return nil |
| 1591 | } |
| 1592 | jars = append(jars, turbineJar) |
| 1593 | } |
| 1594 | |
Colin Cross | 55f63ea | 2018-08-27 12:37:09 -0700 | [diff] [blame] | 1595 | jars = append(jars, extraJars...) |
| 1596 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1597 | // Combine any static header libraries into classes-header.jar. If there is only |
| 1598 | // one input jar this step will be skipped. |
| 1599 | var headerJar android.Path |
| 1600 | jars = append(jars, deps.staticHeaderJars...) |
| 1601 | |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1602 | // we cannot skip the combine step for now if there is only one jar |
| 1603 | // since we have to strip META-INF/TRANSITIVE dir from turbine.jar |
| 1604 | combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1605 | TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, |
Colin Cross | 6c6e6cd | 2019-05-08 14:30:12 -0700 | [diff] [blame] | 1606 | false, nil, []string{"META-INF/TRANSITIVE"}) |
Colin Cross | 5c6ecc1 | 2017-10-23 18:12:27 -0700 | [diff] [blame] | 1607 | headerJar = combinedJar |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1608 | |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1609 | if j.expandJarjarRules != nil { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1610 | // Transform classes.jar into classes-jarjar.jar |
| 1611 | jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1612 | TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1613 | headerJar = jarjarFile |
| 1614 | if ctx.Failed() { |
| 1615 | return nil |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | return headerJar |
| 1620 | } |
| 1621 | |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1622 | func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags, |
Colin Cross | 3063b78 | 2018-08-15 11:19:12 -0700 | [diff] [blame] | 1623 | classesJar android.Path, jarName string) android.ModuleOutPath { |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1624 | |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 1625 | specs := j.jacocoModuleToZipCommand(ctx) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1626 | |
Colin Cross | 84c3882 | 2018-01-03 15:59:46 -0800 | [diff] [blame] | 1627 | jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 1628 | instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName) |
| 1629 | |
| 1630 | jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs) |
| 1631 | |
| 1632 | j.jacocoReportClassesFile = jacocoReportClassesFile |
| 1633 | |
| 1634 | return instrumentedJar |
| 1635 | } |
| 1636 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1637 | var _ Dependency = (*Module)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1638 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1639 | func (j *Module) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1640 | if j.headerJarFile == nil { |
| 1641 | return nil |
| 1642 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1643 | return android.Paths{j.headerJarFile} |
| 1644 | } |
| 1645 | |
| 1646 | func (j *Module) ImplementationJars() android.Paths { |
shinwang | 9e4c07a | 2018-12-24 15:41:04 +0800 | [diff] [blame] | 1647 | if j.implementationJarFile == nil { |
| 1648 | return nil |
| 1649 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1650 | return android.Paths{j.implementationJarFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1653 | func (j *Module) DexJar() android.Path { |
| 1654 | return j.dexJarFile |
| 1655 | } |
| 1656 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1657 | func (j *Module) ResourceJars() android.Paths { |
| 1658 | if j.resourceJar == nil { |
| 1659 | return nil |
| 1660 | } |
| 1661 | return android.Paths{j.resourceJar} |
| 1662 | } |
| 1663 | |
| 1664 | func (j *Module) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1665 | if j.implementationAndResourcesJar == nil { |
| 1666 | return nil |
| 1667 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1668 | return android.Paths{j.implementationAndResourcesJar} |
| 1669 | } |
| 1670 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1671 | func (j *Module) AidlIncludeDirs() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1672 | // exportAidlIncludeDirs is type android.Paths already |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 1673 | return j.exportAidlIncludeDirs |
| 1674 | } |
| 1675 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1676 | func (j *Module) ExportedSdkLibs() []string { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1677 | // exportedSdkLibs is type []string |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1678 | return j.exportedSdkLibs |
| 1679 | } |
| 1680 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 1681 | func (j *Module) ExportedPlugins() (android.Paths, []string) { |
| 1682 | return j.exportedPluginJars, j.exportedPluginClasses |
| 1683 | } |
| 1684 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1685 | func (j *Module) SrcJarArgs() ([]string, android.Paths) { |
| 1686 | return j.srcJarArgs, j.srcJarDeps |
| 1687 | } |
| 1688 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1689 | var _ logtagsProducer = (*Module)(nil) |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1690 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1691 | func (j *Module) logtags() android.Paths { |
Colin Cross | f05fe97 | 2015-04-10 17:45:20 -0700 | [diff] [blame] | 1692 | return j.logtagsSrcs |
| 1693 | } |
| 1694 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1695 | // Collect information for opening IDE project files in java/jdeps.go. |
| 1696 | func (j *Module) IDEInfo(dpInfo *android.IdeInfo) { |
| 1697 | dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...) |
| 1698 | dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...) |
patricktu | 18c82ff | 2019-05-10 15:48:50 +0800 | [diff] [blame] | 1699 | dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1700 | dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...) |
Steven Moreland | c4efd9c | 2019-01-18 11:51:25 -0800 | [diff] [blame] | 1701 | if j.expandJarjarRules != nil { |
| 1702 | dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String()) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | func (j *Module) CompilerDeps() []string { |
| 1707 | jdeps := []string{} |
| 1708 | jdeps = append(jdeps, j.properties.Libs...) |
| 1709 | jdeps = append(jdeps, j.properties.Static_libs...) |
| 1710 | return jdeps |
| 1711 | } |
| 1712 | |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 1713 | func (j *Module) hasCode(ctx android.ModuleContext) bool { |
| 1714 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
| 1715 | return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0 |
| 1716 | } |
| 1717 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1718 | func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1719 | depTag := ctx.OtherModuleDependencyTag(dep) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1720 | // Dependencies other than the static linkage are all considered crossing APEX boundary |
| 1721 | // Also, a dependency to an sdk member is also considered as such. This is required because |
| 1722 | // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. |
| 1723 | return depTag == staticLibTag || j.IsInAnySdk() |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 1724 | } |
| 1725 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1726 | func (j *Module) Stem() string { |
| 1727 | return proptools.StringDefault(j.deviceProperties.Stem, j.Name()) |
| 1728 | } |
| 1729 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1730 | func (j *Module) JacocoReportClassesFile() android.Path { |
| 1731 | return j.jacocoReportClassesFile |
| 1732 | } |
| 1733 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1734 | // |
| 1735 | // Java libraries (.jar file) |
| 1736 | // |
| 1737 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1738 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1739 | Module |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 1740 | |
| 1741 | InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1744 | func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { |
Ulya Trafimovich | f491dde | 2020-01-24 12:19:45 +0000 | [diff] [blame] | 1745 | // Store uncompressed (and aligned) any dex files from jars in APEXes. |
| 1746 | if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() { |
| 1747 | return true |
| 1748 | } |
| 1749 | |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 1750 | // Store uncompressed (and do not strip) dex files from boot class path jars. |
| 1751 | if inList(ctx.ModuleName(), ctx.Config().BootJars()) { |
| 1752 | return true |
| 1753 | } |
| 1754 | |
| 1755 | // Store uncompressed dex files that are preopted on /system. |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1756 | if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) { |
Vladimir Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 1757 | return true |
| 1758 | } |
Colin Cross | 083a2aa | 2019-02-06 16:37:12 -0800 | [diff] [blame] | 1759 | if ctx.Config().UncompressPrivAppDex() && |
| 1760 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) { |
| 1761 | return true |
| 1762 | } |
| 1763 | |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 1764 | return false |
| 1765 | } |
| 1766 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1767 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1768 | j.checkSdkVersion(ctx) |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1769 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1770 | j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 1771 | j.dexpreopter.isInstallable = Bool(j.properties.Installable) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1772 | j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 1773 | j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 1774 | j.compile(ctx, nil) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1775 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1776 | exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform() |
| 1777 | if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 1778 | var extraInstallDeps android.Paths |
| 1779 | if j.InstallMixin != nil { |
| 1780 | extraInstallDeps = j.InstallMixin(ctx, j.outputFile) |
| 1781 | } |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 1782 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 1783 | ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...) |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 1784 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1787 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1788 | j.deps(ctx) |
| 1789 | } |
| 1790 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 1791 | const ( |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1792 | aidlIncludeDir = "aidl" |
| 1793 | javaDir = "java" |
| 1794 | jarFileSuffix = ".jar" |
| 1795 | testConfigSuffix = "-AndroidTest.xml" |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 1796 | ) |
| 1797 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1798 | // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1799 | func sdkSnapshotFilePathForJar(member android.SdkMember) string { |
| 1800 | return sdkSnapshotFilePathForMember(member, jarFileSuffix) |
| 1801 | } |
| 1802 | |
| 1803 | func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string { |
| 1804 | return filepath.Join(javaDir, member.Name()+suffix) |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1807 | type librarySdkMemberType struct { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 1808 | android.SdkMemberTypeBase |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1812 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 1813 | } |
| 1814 | |
| 1815 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { |
| 1816 | _, ok := module.(*Library) |
| 1817 | return ok |
| 1818 | } |
| 1819 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1820 | func (mt *librarySdkMemberType) buildSnapshot( |
| 1821 | sdkModuleContext android.ModuleContext, |
| 1822 | builder android.SnapshotBuilder, |
| 1823 | member android.SdkMember, |
| 1824 | jarToExportGetter func(j *Library) android.Path) { |
| 1825 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1826 | variants := member.Variants() |
| 1827 | if len(variants) != 1 { |
| 1828 | sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) |
| 1829 | for _, variant := range variants { |
| 1830 | sdkModuleContext.ModuleErrorf(" %q", variant) |
| 1831 | } |
| 1832 | } |
| 1833 | variant := variants[0] |
| 1834 | j := variant.(*Library) |
| 1835 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1836 | exportedJar := jarToExportGetter(j) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1837 | snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1838 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 1839 | |
| 1840 | for _, dir := range j.AidlIncludeDirs() { |
| 1841 | // TODO(jiyong): copy parcelable declarations only |
| 1842 | aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) |
| 1843 | for _, file := range aidlFiles { |
| 1844 | builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) |
| 1845 | } |
| 1846 | } |
| 1847 | |
Paul Duffin | 9d8d609 | 2019-12-05 18:19:29 +0000 | [diff] [blame] | 1848 | module := builder.AddPrebuiltModule(member, "java_import") |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 1849 | module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1852 | type headerLibrarySdkMemberType struct { |
| 1853 | librarySdkMemberType |
| 1854 | } |
| 1855 | |
| 1856 | func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { |
| 1857 | mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path { |
| 1858 | headerJars := j.HeaderJars() |
| 1859 | if len(headerJars) != 1 { |
| 1860 | panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) |
| 1861 | } |
| 1862 | |
| 1863 | return headerJars[0] |
| 1864 | }) |
| 1865 | } |
| 1866 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 1867 | type implLibrarySdkMemberType struct { |
| 1868 | librarySdkMemberType |
| 1869 | } |
| 1870 | |
| 1871 | func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { |
| 1872 | mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path { |
| 1873 | implementationJars := j.ImplementationJars() |
| 1874 | if len(implementationJars) != 1 { |
| 1875 | panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) |
| 1876 | } |
| 1877 | |
| 1878 | return implementationJars[0] |
| 1879 | }) |
| 1880 | } |
| 1881 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1882 | // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. |
| 1883 | // |
| 1884 | // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were |
| 1885 | // compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used |
| 1886 | // as a `static_libs` dependency of another module. |
| 1887 | // |
| 1888 | // Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on |
| 1889 | // a device. |
| 1890 | // |
| 1891 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 1892 | // compiled against the host bootclasspath. |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1893 | func LibraryFactory() android.Module { |
| 1894 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1895 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1896 | module.AddProperties( |
| 1897 | &module.Module.properties, |
| 1898 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1899 | &module.Module.dexpreoptProperties, |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1900 | &module.Module.protoProperties) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1901 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1902 | android.InitApexModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1903 | android.InitSdkAwareModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1904 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1905 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1908 | // java_library_static is an obsolete alias for java_library. |
| 1909 | func LibraryStaticFactory() android.Module { |
| 1910 | return LibraryFactory() |
| 1911 | } |
| 1912 | |
| 1913 | // java_library_host builds and links sources into a `.jar` file for the host. |
| 1914 | // |
| 1915 | // A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 1916 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1917 | func LibraryHostFactory() android.Module { |
| 1918 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1919 | |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 1920 | module.AddProperties( |
| 1921 | &module.Module.properties, |
| 1922 | &module.Module.protoProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1923 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1924 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1925 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1926 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1927 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1928 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | // |
Colin Cross | b628ea5 | 2018-08-14 16:42:33 -0700 | [diff] [blame] | 1932 | // Java Tests |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1933 | // |
| 1934 | |
| 1935 | type testProperties struct { |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1936 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1937 | // installed into. |
| 1938 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 1939 | |
| 1940 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 1941 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 1942 | Test_config *string `android:"path,arch_variant"` |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1943 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 1944 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 1945 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 1946 | Test_config_template *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 1947 | |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1948 | // list of files or filegroup modules that provide data that should be installed alongside |
| 1949 | // the test |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 1950 | Data []string `android:"path"` |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 1953 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 1954 | // explicitly. |
| 1955 | Auto_gen_config *bool |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1958 | type testHelperLibraryProperties struct { |
| 1959 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1960 | // installed into. |
| 1961 | Test_suites []string `android:"arch_variant"` |
| 1962 | } |
| 1963 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1964 | type prebuiltTestProperties struct { |
| 1965 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1966 | // installed into. |
| 1967 | Test_suites []string `android:"arch_variant"` |
| 1968 | |
| 1969 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 1970 | // installed with the module. |
| 1971 | Test_config *string `android:"path,arch_variant"` |
| 1972 | } |
| 1973 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1974 | type Test struct { |
| 1975 | Library |
| 1976 | |
| 1977 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1978 | |
| 1979 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 1980 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1983 | type TestHelperLibrary struct { |
| 1984 | Library |
| 1985 | |
| 1986 | testHelperLibraryProperties testHelperLibraryProperties |
| 1987 | } |
| 1988 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1989 | type JavaTestImport struct { |
| 1990 | Import |
| 1991 | |
| 1992 | prebuiltTestProperties prebuiltTestProperties |
| 1993 | |
| 1994 | testConfig android.Path |
| 1995 | } |
| 1996 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1997 | func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 1998 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, |
| 1999 | j.testProperties.Test_suites, j.testProperties.Auto_gen_config) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 2000 | j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 2001 | |
| 2002 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 2005 | func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2006 | j.Library.GenerateAndroidBuildActions(ctx) |
| 2007 | } |
| 2008 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 2009 | func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2010 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil, |
| 2011 | j.prebuiltTestProperties.Test_suites, nil) |
| 2012 | |
| 2013 | j.Import.GenerateAndroidBuildActions(ctx) |
| 2014 | } |
| 2015 | |
| 2016 | type testSdkMemberType struct { |
| 2017 | android.SdkMemberTypeBase |
| 2018 | } |
| 2019 | |
| 2020 | func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 2021 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 2022 | } |
| 2023 | |
| 2024 | func (mt *testSdkMemberType) IsInstance(module android.Module) bool { |
| 2025 | _, ok := module.(*Test) |
| 2026 | return ok |
| 2027 | } |
| 2028 | |
| 2029 | func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { |
| 2030 | variants := member.Variants() |
| 2031 | if len(variants) != 1 { |
| 2032 | sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) |
| 2033 | for _, variant := range variants { |
| 2034 | sdkModuleContext.ModuleErrorf(" %q", variant) |
| 2035 | } |
| 2036 | } |
| 2037 | variant := variants[0] |
| 2038 | j := variant.(*Test) |
| 2039 | |
| 2040 | implementationJars := j.ImplementationJars() |
| 2041 | if len(implementationJars) != 1 { |
| 2042 | panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) |
| 2043 | } |
| 2044 | |
| 2045 | snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member) |
| 2046 | builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath) |
| 2047 | |
| 2048 | snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix) |
| 2049 | builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath) |
| 2050 | |
| 2051 | module := builder.AddPrebuiltModule(member, "java_test_import") |
| 2052 | module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
| 2053 | module.AddProperty("test_config", snapshotRelativeTestConfigPath) |
| 2054 | } |
| 2055 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2056 | // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and |
| 2057 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. |
| 2058 | // |
| 2059 | // By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 2060 | // compiled against the device bootclasspath. |
| 2061 | // |
| 2062 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 2063 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2064 | func TestFactory() android.Module { |
| 2065 | module := &Test{} |
| 2066 | |
| 2067 | module.AddProperties( |
| 2068 | &module.Module.properties, |
| 2069 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 2070 | &module.Module.dexpreoptProperties, |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2071 | &module.Module.protoProperties, |
| 2072 | &module.testProperties) |
| 2073 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 2074 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e302687 | 2019-01-05 22:30:13 -0800 | [diff] [blame] | 2075 | module.Module.dexpreopter.isTest = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 2076 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2077 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2078 | return module |
| 2079 | } |
| 2080 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 2081 | // java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite. |
| 2082 | func TestHelperLibraryFactory() android.Module { |
| 2083 | module := &TestHelperLibrary{} |
| 2084 | |
| 2085 | module.AddProperties( |
| 2086 | &module.Module.properties, |
| 2087 | &module.Module.deviceProperties, |
| 2088 | &module.Module.dexpreoptProperties, |
| 2089 | &module.Module.protoProperties, |
| 2090 | &module.testHelperLibraryProperties) |
| 2091 | |
Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 2092 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 2093 | module.Module.dexpreopter.isTest = true |
| 2094 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 2095 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 2096 | return module |
| 2097 | } |
| 2098 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 2099 | // java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module |
| 2100 | // and makes sure that it is added to the appropriate test suite. |
| 2101 | // |
| 2102 | // By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 2103 | // compiled against an Android classpath. |
| 2104 | // |
| 2105 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 2106 | // for host modules. |
| 2107 | func JavaTestImportFactory() android.Module { |
| 2108 | module := &JavaTestImport{} |
| 2109 | |
| 2110 | module.AddProperties( |
| 2111 | &module.Import.properties, |
| 2112 | &module.prebuiltTestProperties) |
| 2113 | |
| 2114 | module.Import.properties.Installable = proptools.BoolPtr(true) |
| 2115 | |
| 2116 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 2117 | android.InitApexModule(module) |
| 2118 | android.InitSdkAwareModule(module) |
| 2119 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 2120 | return module |
| 2121 | } |
| 2122 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2123 | // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to |
| 2124 | // allow running the test with `atest` or a `TEST_MAPPING` file. |
| 2125 | // |
| 2126 | // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 2127 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2128 | func TestHostFactory() android.Module { |
| 2129 | module := &Test{} |
| 2130 | |
| 2131 | module.AddProperties( |
| 2132 | &module.Module.properties, |
| 2133 | &module.Module.protoProperties, |
| 2134 | &module.testProperties) |
| 2135 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 2136 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 2137 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2138 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 2139 | return module |
| 2140 | } |
| 2141 | |
| 2142 | // |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2143 | // Java Binaries (.jar file plus wrapper script) |
| 2144 | // |
| 2145 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2146 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 2147 | // installable script to execute the resulting jar |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 2148 | Wrapper *string `android:"path"` |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 2149 | |
| 2150 | // Name of the class containing main to be inserted into the manifest as Main-Class. |
| 2151 | Main_class *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2154 | type Binary struct { |
| 2155 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2156 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2157 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 2158 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2159 | isWrapperVariant bool |
| 2160 | |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 2161 | wrapperFile android.Path |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 2162 | binaryFile android.InstallPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 2165 | func (j *Binary) HostToolPath() android.OptionalPath { |
| 2166 | return android.OptionalPathForPath(j.binaryFile) |
| 2167 | } |
| 2168 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2169 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2170 | if ctx.Arch().ArchType == android.Common { |
| 2171 | // Compile the jar |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 2172 | if j.binaryProperties.Main_class != nil { |
| 2173 | if j.properties.Manifest != nil { |
| 2174 | ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") |
| 2175 | } |
| 2176 | manifestFile := android.PathForModuleOut(ctx, "manifest.txt") |
| 2177 | GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) |
| 2178 | j.overrideManifest = android.OptionalPathForPath(manifestFile) |
| 2179 | } |
| 2180 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2181 | j.Library.GenerateAndroidBuildActions(ctx) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 2182 | } else { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2183 | // Handle the binary wrapper |
| 2184 | j.isWrapperVariant = true |
| 2185 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 2186 | if j.binaryProperties.Wrapper != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 2187 | j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2188 | } else { |
| 2189 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") |
| 2190 | } |
| 2191 | |
| 2192 | // Depend on the installed jar so that the wrapper doesn't get executed by |
| 2193 | // another build rule before the jar has been installed. |
| 2194 | jarFile := ctx.PrimaryModule().(*Binary).installFile |
| 2195 | |
| 2196 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
| 2197 | ctx.ModuleName(), j.wrapperFile, jarFile) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 2198 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2201 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2202 | if ctx.Arch().ArchType == android.Common { |
| 2203 | j.deps(ctx) |
| 2204 | } |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2207 | // java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host |
| 2208 | // as well. |
| 2209 | // |
| 2210 | // By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 2211 | // compiled against the device bootclasspath. |
| 2212 | // |
| 2213 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 2214 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2215 | func BinaryFactory() android.Module { |
| 2216 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2217 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2218 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 2219 | &module.Module.properties, |
| 2220 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 2221 | &module.Module.dexpreoptProperties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 2222 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 2223 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2224 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 2225 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 2226 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2227 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) |
| 2228 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2229 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2232 | // java_binary_host builds a `.jar` file and a shell script that executes it for the host. |
| 2233 | // |
| 2234 | // A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 2235 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 2236 | func BinaryHostFactory() android.Module { |
| 2237 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2238 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2239 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 2240 | &module.Module.properties, |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 2241 | &module.Module.protoProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 2242 | &module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2243 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 2244 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 2245 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 2246 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) |
| 2247 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2248 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | // |
| 2252 | // Java prebuilts |
| 2253 | // |
| 2254 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2255 | type ImportProperties struct { |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 2256 | Jars []string `android:"path"` |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 2257 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2258 | Sdk_version *string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 2259 | |
| 2260 | Installable *bool |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2261 | |
| 2262 | // List of shared java libs that this module has dependencies to |
| 2263 | Libs []string |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2264 | |
| 2265 | // List of files to remove from the jar file(s) |
| 2266 | Exclude_files []string |
| 2267 | |
| 2268 | // List of directories to remove from the jar file(s) |
| 2269 | Exclude_dirs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2270 | |
| 2271 | // if set to true, run Jetifier against .jar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 2272 | Jetifier *bool |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 2273 | |
| 2274 | // set the name of the output |
| 2275 | Stem *string |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2279 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2280 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2281 | android.ApexModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 2282 | prebuilt android.Prebuilt |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 2283 | android.SdkBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2284 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2285 | properties ImportProperties |
| 2286 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 2287 | combinedClasspathFile android.Path |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2288 | exportedSdkLibs []string |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2291 | func (j *Import) sdkVersion() sdkSpec { |
| 2292 | return sdkSpecFrom(String(j.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2295 | func (j *Import) minSdkVersion() sdkSpec { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 2296 | return j.sdkVersion() |
| 2297 | } |
| 2298 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2299 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 2300 | return &j.prebuilt |
| 2301 | } |
| 2302 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2303 | func (j *Import) PrebuiltSrcs() []string { |
| 2304 | return j.properties.Jars |
| 2305 | } |
| 2306 | |
| 2307 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 2308 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 2309 | } |
| 2310 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2311 | func (j *Import) Stem() string { |
| 2312 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 2313 | } |
| 2314 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 2315 | func (a *Import) JacocoReportClassesFile() android.Path { |
| 2316 | return nil |
| 2317 | } |
| 2318 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2319 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 2320 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2323 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 2324 | jars := android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 2325 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2326 | jarName := j.Stem() + ".jar" |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2327 | outputFile := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2328 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, |
| 2329 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 2330 | if Bool(j.properties.Jetifier) { |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2331 | inputFile := outputFile |
| 2332 | outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) |
| 2333 | TransformJetifier(ctx, outputFile, inputFile) |
| 2334 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 2335 | j.combinedClasspathFile = outputFile |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2336 | |
| 2337 | ctx.VisitDirectDeps(func(module android.Module) { |
| 2338 | otherName := ctx.OtherModuleName(module) |
| 2339 | tag := ctx.OtherModuleDependencyTag(module) |
| 2340 | |
| 2341 | switch dep := module.(type) { |
| 2342 | case Dependency: |
| 2343 | switch tag { |
| 2344 | case libTag, staticLibTag: |
| 2345 | // sdk lib names from dependencies are re-exported |
| 2346 | j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) |
| 2347 | } |
| 2348 | case SdkLibraryDependency: |
| 2349 | switch tag { |
| 2350 | case libTag: |
| 2351 | // names of sdk libs that are directly depended are exported |
| 2352 | j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) |
| 2353 | } |
| 2354 | } |
| 2355 | }) |
| 2356 | |
| 2357 | j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs) |
Nan Zhang | 4973ecf | 2018-08-10 13:42:12 -0700 | [diff] [blame] | 2358 | if Bool(j.properties.Installable) { |
| 2359 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 2360 | jarName, outputFile) |
Nan Zhang | 4973ecf | 2018-08-10 13:42:12 -0700 | [diff] [blame] | 2361 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2364 | var _ Dependency = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2365 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 2366 | func (j *Import) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2367 | if j.combinedClasspathFile == nil { |
| 2368 | return nil |
| 2369 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2370 | return android.Paths{j.combinedClasspathFile} |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | func (j *Import) ImplementationJars() android.Paths { |
shinwang | 9e4c07a | 2018-12-24 15:41:04 +0800 | [diff] [blame] | 2374 | if j.combinedClasspathFile == nil { |
| 2375 | return nil |
| 2376 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2377 | return android.Paths{j.combinedClasspathFile} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 2380 | func (j *Import) ResourceJars() android.Paths { |
| 2381 | return nil |
| 2382 | } |
| 2383 | |
| 2384 | func (j *Import) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2385 | if j.combinedClasspathFile == nil { |
| 2386 | return nil |
| 2387 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 2388 | return android.Paths{j.combinedClasspathFile} |
| 2389 | } |
| 2390 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 2391 | func (j *Import) DexJar() android.Path { |
| 2392 | return nil |
| 2393 | } |
| 2394 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2395 | func (j *Import) AidlIncludeDirs() android.Paths { |
Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [diff] [blame] | 2396 | return nil |
| 2397 | } |
| 2398 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2399 | func (j *Import) ExportedSdkLibs() []string { |
| 2400 | return j.exportedSdkLibs |
| 2401 | } |
| 2402 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 2403 | func (j *Import) ExportedPlugins() (android.Paths, []string) { |
| 2404 | return nil, nil |
| 2405 | } |
| 2406 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 2407 | func (j *Import) SrcJarArgs() ([]string, android.Paths) { |
| 2408 | return nil, nil |
| 2409 | } |
| 2410 | |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2411 | func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 2412 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 2413 | // dependencies other than the static linkage are all considered crossing APEX boundary |
| 2414 | // Also, a dependency to an sdk member is also considered as such. This is required because |
| 2415 | // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator. |
| 2416 | return depTag == staticLibTag || j.IsInAnySdk() |
| 2417 | } |
| 2418 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2419 | // Add compile time check for interface implementation |
| 2420 | var _ android.IDEInfo = (*Import)(nil) |
| 2421 | var _ android.IDECustomizedModuleName = (*Import)(nil) |
| 2422 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 2423 | // Collect information for opening IDE project files in java/jdeps.go. |
| 2424 | const ( |
| 2425 | removedPrefix = "prebuilt_" |
| 2426 | ) |
| 2427 | |
| 2428 | func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { |
| 2429 | dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) |
| 2430 | } |
| 2431 | |
| 2432 | func (j *Import) IDECustomizedModuleName() string { |
| 2433 | // TODO(b/113562217): Extract the base module name from the Import name, often the Import name |
| 2434 | // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better |
| 2435 | // solution to get the Import name. |
| 2436 | name := j.Name() |
| 2437 | if strings.HasPrefix(name, removedPrefix) { |
patricktu | bb640e0 | 2018-10-11 18:33:16 +0800 | [diff] [blame] | 2438 | name = strings.TrimPrefix(name, removedPrefix) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 2439 | } |
| 2440 | return name |
| 2441 | } |
| 2442 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2443 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2444 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2445 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module. |
| 2446 | // |
| 2447 | // By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 2448 | // compiled against an Android classpath. |
| 2449 | // |
| 2450 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 2451 | // for host modules. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2452 | func ImportFactory() android.Module { |
| 2453 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2454 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2455 | module.AddProperties(&module.properties) |
| 2456 | |
| 2457 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2458 | android.InitApexModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 2459 | android.InitSdkAwareModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2460 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2461 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2464 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host |
| 2465 | // module. |
| 2466 | // |
| 2467 | // A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were |
| 2468 | // compiled against a host bootclasspath. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2469 | func ImportFactoryHost() android.Module { |
| 2470 | module := &Import{} |
| 2471 | |
| 2472 | module.AddProperties(&module.properties) |
| 2473 | |
| 2474 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2475 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2476 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2477 | return module |
| 2478 | } |
| 2479 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2480 | // dex_import module |
| 2481 | |
| 2482 | type DexImportProperties struct { |
Colin Cross | 5cfc70d | 2019-07-15 13:36:55 -0700 | [diff] [blame] | 2483 | Jars []string `android:"path"` |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 2484 | |
| 2485 | // set the name of the output |
| 2486 | Stem *string |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | type DexImport struct { |
| 2490 | android.ModuleBase |
| 2491 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2492 | android.ApexModuleBase |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2493 | prebuilt android.Prebuilt |
| 2494 | |
| 2495 | properties DexImportProperties |
| 2496 | |
| 2497 | dexJarFile android.Path |
| 2498 | maybeStrippedDexJarFile android.Path |
| 2499 | |
| 2500 | dexpreopter |
| 2501 | } |
| 2502 | |
| 2503 | func (j *DexImport) Prebuilt() *android.Prebuilt { |
| 2504 | return &j.prebuilt |
| 2505 | } |
| 2506 | |
| 2507 | func (j *DexImport) PrebuiltSrcs() []string { |
| 2508 | return j.properties.Jars |
| 2509 | } |
| 2510 | |
| 2511 | func (j *DexImport) Name() string { |
| 2512 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 2513 | } |
| 2514 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2515 | func (j *DexImport) Stem() string { |
| 2516 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 2517 | } |
| 2518 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2519 | func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2520 | if len(j.properties.Jars) != 1 { |
| 2521 | ctx.PropertyErrorf("jars", "exactly one jar must be provided") |
| 2522 | } |
| 2523 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2524 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2525 | j.dexpreopter.isInstallable = true |
| 2526 | j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) |
| 2527 | |
| 2528 | inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") |
| 2529 | dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") |
| 2530 | |
| 2531 | if j.dexpreopter.uncompressedDex { |
| 2532 | rule := android.NewRuleBuilder() |
| 2533 | |
| 2534 | temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned") |
| 2535 | rule.Temporary(temporary) |
| 2536 | |
| 2537 | // use zip2zip to uncompress classes*.dex files |
| 2538 | rule.Command(). |
Colin Cross | ee94d6a | 2019-07-08 17:08:34 -0700 | [diff] [blame] | 2539 | BuiltTool(ctx, "zip2zip"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2540 | FlagWithInput("-i ", inputJar). |
| 2541 | FlagWithOutput("-o ", temporary). |
| 2542 | FlagWithArg("-0 ", "'classes*.dex'") |
| 2543 | |
| 2544 | // use zipalign to align uncompressed classes*.dex files |
| 2545 | rule.Command(). |
Colin Cross | ee94d6a | 2019-07-08 17:08:34 -0700 | [diff] [blame] | 2546 | BuiltTool(ctx, "zipalign"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2547 | Flag("-f"). |
| 2548 | Text("4"). |
| 2549 | Input(temporary). |
| 2550 | Output(dexOutputFile) |
| 2551 | |
| 2552 | rule.DeleteTemporaryFiles() |
| 2553 | |
| 2554 | rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex") |
| 2555 | } else { |
| 2556 | ctx.Build(pctx, android.BuildParams{ |
| 2557 | Rule: android.Cp, |
| 2558 | Input: inputJar, |
| 2559 | Output: dexOutputFile, |
| 2560 | }) |
| 2561 | } |
| 2562 | |
| 2563 | j.dexJarFile = dexOutputFile |
| 2564 | |
| 2565 | dexOutputFile = j.dexpreopt(ctx, dexOutputFile) |
| 2566 | |
| 2567 | j.maybeStrippedDexJarFile = dexOutputFile |
| 2568 | |
| 2569 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 2570 | ctx.ModuleName()+".jar", dexOutputFile) |
| 2571 | } |
| 2572 | |
| 2573 | func (j *DexImport) DexJar() android.Path { |
| 2574 | return j.dexJarFile |
| 2575 | } |
| 2576 | |
| 2577 | // dex_import imports a `.jar` file containing classes.dex files. |
| 2578 | // |
| 2579 | // A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed |
| 2580 | // to the device. |
| 2581 | func DexImportFactory() android.Module { |
| 2582 | module := &DexImport{} |
| 2583 | |
| 2584 | module.AddProperties(&module.properties) |
| 2585 | |
| 2586 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2587 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2588 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2589 | return module |
| 2590 | } |
| 2591 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2592 | // |
| 2593 | // Defaults |
| 2594 | // |
| 2595 | type Defaults struct { |
| 2596 | android.ModuleBase |
| 2597 | android.DefaultsModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2598 | android.ApexModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2601 | // java_defaults provides a set of properties that can be inherited by other java or android modules. |
| 2602 | // |
| 2603 | // A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each |
| 2604 | // property in the defaults module that exists in the depending module will be prepended to the depending module's |
| 2605 | // value for that property. |
| 2606 | // |
| 2607 | // Example: |
| 2608 | // |
| 2609 | // java_defaults { |
| 2610 | // name: "example_defaults", |
| 2611 | // srcs: ["common/**/*.java"], |
| 2612 | // javacflags: ["-Xlint:all"], |
| 2613 | // aaptflags: ["--auto-add-overlay"], |
| 2614 | // } |
| 2615 | // |
| 2616 | // java_library { |
| 2617 | // name: "example", |
| 2618 | // defaults: ["example_defaults"], |
| 2619 | // srcs: ["example/**/*.java"], |
| 2620 | // } |
| 2621 | // |
| 2622 | // is functionally identical to: |
| 2623 | // |
| 2624 | // java_library { |
| 2625 | // name: "example", |
| 2626 | // srcs: [ |
| 2627 | // "common/**/*.java", |
| 2628 | // "example/**/*.java", |
| 2629 | // ], |
| 2630 | // javacflags: ["-Xlint:all"], |
| 2631 | // } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2632 | func defaultsFactory() android.Module { |
| 2633 | return DefaultsFactory() |
| 2634 | } |
| 2635 | |
Paul Duffin | 4735766 | 2019-12-05 14:07:14 +0000 | [diff] [blame] | 2636 | func DefaultsFactory() android.Module { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2637 | module := &Defaults{} |
| 2638 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2639 | module.AddProperties( |
| 2640 | &CompilerProperties{}, |
| 2641 | &CompilerDeviceProperties{}, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 2642 | &DexpreoptProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 2643 | &android.ProtoProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2644 | &aaptProperties{}, |
| 2645 | &androidLibraryProperties{}, |
| 2646 | &appProperties{}, |
| 2647 | &appTestProperties{}, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2648 | &overridableAppProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2649 | &ImportProperties{}, |
| 2650 | &AARImportProperties{}, |
| 2651 | &sdkLibraryProperties{}, |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2652 | &DexImportProperties{}, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2653 | &android.ApexProperties{}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2654 | ) |
| 2655 | |
| 2656 | android.InitDefaultsModule(module) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2657 | return module |
| 2658 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2659 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2660 | func kytheExtractJavaFactory() android.Singleton { |
| 2661 | return &kytheExtractJavaSingleton{} |
| 2662 | } |
| 2663 | |
| 2664 | type kytheExtractJavaSingleton struct { |
| 2665 | } |
| 2666 | |
| 2667 | func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 2668 | var xrefTargets android.Paths |
| 2669 | ctx.VisitAllModules(func(module android.Module) { |
| 2670 | if javaModule, ok := module.(xref); ok { |
| 2671 | xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) |
| 2672 | } |
| 2673 | }) |
| 2674 | // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets |
| 2675 | if len(xrefTargets) > 0 { |
| 2676 | ctx.Build(pctx, android.BuildParams{ |
| 2677 | Rule: blueprint.Phony, |
| 2678 | Output: android.PathForPhony(ctx, "xref_java"), |
| 2679 | Inputs: xrefTargets, |
| 2680 | }) |
| 2681 | } |
| 2682 | } |
| 2683 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2684 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2685 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2686 | var String = proptools.String |
Colin Cross | 0d0ba59 | 2018-02-20 13:33:42 -0800 | [diff] [blame] | 2687 | var inList = android.InList |