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