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