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