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