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" |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 24 | "strings" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 25 | |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 26 | "android/soong/bazel" |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 27 | "android/soong/bazel/cquery" |
Sam Delmerico | 4e27229 | 2022-01-06 20:03:51 +0000 | [diff] [blame] | 28 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 31 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 32 | "android/soong/android" |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 33 | "android/soong/cc" |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 34 | "android/soong/dexpreopt" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 35 | "android/soong/java/config" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 36 | "android/soong/tradefed" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 37 | ) |
| 38 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 39 | func init() { |
Paul Duffin | 535e0a1 | 2021-03-30 23:34:32 +0100 | [diff] [blame] | 40 | registerJavaBuildComponents(android.InitRegistrationContext) |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 41 | |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 42 | RegisterJavaSdkMemberTypes() |
| 43 | } |
| 44 | |
Paul Duffin | 535e0a1 | 2021-03-30 23:34:32 +0100 | [diff] [blame] | 45 | func registerJavaBuildComponents(ctx android.RegistrationContext) { |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 46 | ctx.RegisterModuleType("java_defaults", DefaultsFactory) |
| 47 | |
| 48 | ctx.RegisterModuleType("java_library", LibraryFactory) |
| 49 | ctx.RegisterModuleType("java_library_static", LibraryStaticFactory) |
| 50 | ctx.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 51 | ctx.RegisterModuleType("java_binary", BinaryFactory) |
| 52 | ctx.RegisterModuleType("java_binary_host", BinaryHostFactory) |
| 53 | ctx.RegisterModuleType("java_test", TestFactory) |
| 54 | ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory) |
| 55 | ctx.RegisterModuleType("java_test_host", TestHostFactory) |
| 56 | ctx.RegisterModuleType("java_test_import", JavaTestImportFactory) |
| 57 | ctx.RegisterModuleType("java_import", ImportFactory) |
| 58 | ctx.RegisterModuleType("java_import_host", ImportFactoryHost) |
| 59 | ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) |
| 60 | ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) |
| 61 | ctx.RegisterModuleType("dex_import", DexImportFactory) |
| 62 | |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 63 | // This mutator registers dependencies on dex2oat for modules that should be |
| 64 | // dexpreopted. This is done late when the final variants have been |
| 65 | // established, to not get the dependencies split into the wrong variants and |
| 66 | // to support the checks in dexpreoptDisabled(). |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 67 | ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 68 | ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel() |
Sam Delmerico | 1e3f78f | 2022-09-07 12:07:07 -0400 | [diff] [blame] | 69 | // needs access to ApexInfoProvider which is available after variant creation |
| 70 | ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 71 | }) |
| 72 | |
| 73 | ctx.RegisterSingletonType("logtags", LogtagsSingleton) |
| 74 | ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) |
| 75 | } |
| 76 | |
| 77 | func RegisterJavaSdkMemberTypes() { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 78 | // Register sdk member types. |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 79 | android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 80 | android.RegisterSdkMemberType(javaLibsSdkMemberType) |
| 81 | android.RegisterSdkMemberType(javaBootLibsSdkMemberType) |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 82 | android.RegisterSdkMemberType(javaSystemserverLibsSdkMemberType) |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 83 | android.RegisterSdkMemberType(javaTestSdkMemberType) |
| 84 | } |
| 85 | |
| 86 | var ( |
| 87 | // Supports adding java header libraries to module_exports and sdk. |
| 88 | javaHeaderLibsSdkMemberType = &librarySdkMemberType{ |
| 89 | android.SdkMemberTypeBase{ |
| 90 | PropertyName: "java_header_libs", |
| 91 | SupportsSdk: true, |
| 92 | }, |
| 93 | func(_ android.SdkMemberContext, j *Library) android.Path { |
| 94 | headerJars := j.HeaderJars() |
| 95 | if len(headerJars) != 1 { |
| 96 | panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) |
| 97 | } |
| 98 | |
| 99 | return headerJars[0] |
| 100 | }, |
| 101 | sdkSnapshotFilePathForJar, |
| 102 | copyEverythingToSnapshot, |
| 103 | } |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 104 | |
Paul Duffin | 22ff0aa | 2021-02-04 11:15:34 +0000 | [diff] [blame] | 105 | // Export implementation classes jar as part of the sdk. |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 106 | exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path { |
Paul Duffin | 22ff0aa | 2021-02-04 11:15:34 +0000 | [diff] [blame] | 107 | implementationJars := j.ImplementationAndResourcesJars() |
| 108 | if len(implementationJars) != 1 { |
| 109 | panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) |
| 110 | } |
| 111 | return implementationJars[0] |
| 112 | } |
| 113 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 114 | // Supports adding java implementation libraries to module_exports but not sdk. |
| 115 | javaLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | f5c0a9c | 2020-02-28 14:39:53 +0000 | [diff] [blame] | 116 | android.SdkMemberTypeBase{ |
| 117 | PropertyName: "java_libs", |
| 118 | }, |
Paul Duffin | 22ff0aa | 2021-02-04 11:15:34 +0000 | [diff] [blame] | 119 | exportImplementationClassesJar, |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 120 | sdkSnapshotFilePathForJar, |
| 121 | copyEverythingToSnapshot, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 122 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 123 | |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 124 | snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { |
| 125 | // In the S build the build will break if updatable-media does not provide a full implementation |
| 126 | // jar. That issue was fixed in Tiramisu by b/229932396. |
| 127 | if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { |
| 128 | return true |
| 129 | } |
| 130 | |
| 131 | return false |
| 132 | } |
| 133 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 134 | // Supports adding java boot libraries to module_exports and sdk. |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 135 | // |
| 136 | // The build has some implicit dependencies (via the boot jars configuration) on a number of |
| 137 | // modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are |
| 138 | // provided by mainline modules (e.g. art, conscrypt, runtime-i18n) but which are not otherwise |
| 139 | // used outside those mainline modules. |
| 140 | // |
| 141 | // As they are not needed outside the mainline modules adding them to the sdk/module-exports as |
| 142 | // either java_libs, or java_header_libs would end up exporting more information than was strictly |
| 143 | // necessary. The java_boot_libs property to allow those modules to be exported as part of the |
| 144 | // sdk/module_exports without exposing any unnecessary information. |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 145 | javaBootLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 146 | android.SdkMemberTypeBase{ |
| 147 | PropertyName: "java_boot_libs", |
| 148 | SupportsSdk: true, |
| 149 | }, |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 150 | func(ctx android.SdkMemberContext, j *Library) android.Path { |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 151 | if snapshotRequiresImplementationJar(ctx) { |
| 152 | return exportImplementationClassesJar(ctx, j) |
| 153 | } |
| 154 | |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 155 | // Java boot libs are only provided in the SDK to provide access to their dex implementation |
| 156 | // jar for use by dexpreopting and boot jars package check. They do not need to provide an |
| 157 | // actual implementation jar but the java_import will need a file that exists so just copy an |
| 158 | // empty file. Any attempt to use that file as a jar will cause a build error. |
| 159 | return ctx.SnapshotBuilder().EmptyFile() |
| 160 | }, |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 161 | func(ctx android.SdkMemberContext, osPrefix, name string) string { |
| 162 | if snapshotRequiresImplementationJar(ctx) { |
| 163 | return sdkSnapshotFilePathForJar(ctx, osPrefix, name) |
| 164 | } |
| 165 | |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 166 | // Create a special name for the implementation jar to try and provide some useful information |
| 167 | // to a developer that attempts to compile against this. |
| 168 | // TODO(b/175714559): Provide a proper error message in Soong not ninja. |
| 169 | return filepath.Join(osPrefix, "java_boot_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix) |
| 170 | }, |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 171 | onlyCopyJarToSnapshot, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 172 | } |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 173 | |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 174 | // Supports adding java systemserver libraries to module_exports and sdk. |
| 175 | // |
| 176 | // The build has some implicit dependencies (via the systemserver jars configuration) on a number |
| 177 | // of modules that are part of the java systemserver classpath and which are provided by mainline |
| 178 | // modules but which are not otherwise used outside those mainline modules. |
| 179 | // |
| 180 | // As they are not needed outside the mainline modules adding them to the sdk/module-exports as |
| 181 | // either java_libs, or java_header_libs would end up exporting more information than was strictly |
| 182 | // necessary. The java_systemserver_libs property to allow those modules to be exported as part of |
| 183 | // the sdk/module_exports without exposing any unnecessary information. |
| 184 | javaSystemserverLibsSdkMemberType = &librarySdkMemberType{ |
| 185 | android.SdkMemberTypeBase{ |
| 186 | PropertyName: "java_systemserver_libs", |
| 187 | SupportsSdk: true, |
Paul Duffin | f861df7 | 2022-07-01 15:56:06 +0000 | [diff] [blame] | 188 | |
| 189 | // This was only added in Tiramisu. |
| 190 | SupportedBuildReleaseSpecification: "Tiramisu+", |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 191 | }, |
| 192 | func(ctx android.SdkMemberContext, j *Library) android.Path { |
| 193 | // Java systemserver libs are only provided in the SDK to provide access to their dex |
| 194 | // implementation jar for use by dexpreopting. They do not need to provide an actual |
| 195 | // implementation jar but the java_import will need a file that exists so just copy an empty |
| 196 | // file. Any attempt to use that file as a jar will cause a build error. |
| 197 | return ctx.SnapshotBuilder().EmptyFile() |
| 198 | }, |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 199 | func(_ android.SdkMemberContext, osPrefix, name string) string { |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 200 | // Create a special name for the implementation jar to try and provide some useful information |
| 201 | // to a developer that attempts to compile against this. |
| 202 | // TODO(b/175714559): Provide a proper error message in Soong not ninja. |
| 203 | return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix) |
| 204 | }, |
| 205 | onlyCopyJarToSnapshot, |
| 206 | } |
| 207 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 208 | // Supports adding java test libraries to module_exports but not sdk. |
| 209 | javaTestSdkMemberType = &testSdkMemberType{ |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 210 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 211 | PropertyName: "java_tests", |
| 212 | }, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 213 | } |
| 214 | ) |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 215 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 216 | // JavaInfo contains information about a java module for use by modules that depend on it. |
| 217 | type JavaInfo struct { |
| 218 | // HeaderJars is a list of jars that can be passed as the javac classpath in order to link |
| 219 | // against this module. If empty, ImplementationJars should be used instead. |
| 220 | HeaderJars android.Paths |
| 221 | |
| 222 | // ImplementationAndResourceJars is a list of jars that contain the implementations of classes |
| 223 | // in the module as well as any resources included in the module. |
| 224 | ImplementationAndResourcesJars android.Paths |
| 225 | |
| 226 | // ImplementationJars is a list of jars that contain the implementations of classes in the |
| 227 | //module. |
| 228 | ImplementationJars android.Paths |
| 229 | |
| 230 | // ResourceJars is a list of jars that contain the resources included in the module. |
| 231 | ResourceJars android.Paths |
| 232 | |
| 233 | // AidlIncludeDirs is a list of directories that should be passed to the aidl tool when |
| 234 | // depending on this module. |
| 235 | AidlIncludeDirs android.Paths |
| 236 | |
| 237 | // SrcJarArgs is a list of arguments to pass to soong_zip to package the sources of this |
| 238 | // module. |
| 239 | SrcJarArgs []string |
| 240 | |
| 241 | // SrcJarDeps is a list of paths to depend on when packaging the sources of this module. |
| 242 | SrcJarDeps android.Paths |
| 243 | |
| 244 | // ExportedPlugins is a list of paths that should be used as annotation processors for any |
| 245 | // module that depends on this module. |
| 246 | ExportedPlugins android.Paths |
| 247 | |
| 248 | // ExportedPluginClasses is a list of classes that should be run as annotation processors for |
| 249 | // any module that depends on this module. |
| 250 | ExportedPluginClasses []string |
| 251 | |
| 252 | // ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs, |
| 253 | // requiring disbling turbine for any modules that depend on it. |
| 254 | ExportedPluginDisableTurbine bool |
| 255 | |
| 256 | // JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be |
| 257 | // instrumented by jacoco. |
| 258 | JacocoReportClassesFile android.Path |
| 259 | } |
| 260 | |
| 261 | var JavaInfoProvider = blueprint.NewProvider(JavaInfo{}) |
| 262 | |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 263 | // SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to |
| 264 | // the sysprop implementation library. |
| 265 | type SyspropPublicStubInfo struct { |
| 266 | // JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to |
| 267 | // the sysprop implementation library. |
| 268 | JavaInfo JavaInfo |
| 269 | } |
| 270 | |
| 271 | var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{}) |
| 272 | |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 273 | // Methods that need to be implemented for a module that is added to apex java_libs property. |
| 274 | type ApexDependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 275 | HeaderJars() android.Paths |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 276 | ImplementationAndResourcesJars() android.Paths |
| 277 | } |
| 278 | |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 279 | // Provides build path and install path to DEX jars. |
| 280 | type UsesLibraryDependency interface { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 281 | DexJarBuildPath() OptionalDexJarPath |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 282 | DexJarInstallPath() android.Path |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 283 | ClassLoaderContexts() dexpreopt.ClassLoaderContextMap |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 286 | // TODO(jungjw): Move this to kythe.go once it's created. |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 287 | type xref interface { |
| 288 | XrefJavaFiles() android.Paths |
| 289 | } |
| 290 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 291 | func (j *Module) XrefJavaFiles() android.Paths { |
| 292 | return j.kytheFiles |
| 293 | } |
| 294 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 295 | type dependencyTag struct { |
| 296 | blueprint.BaseDependencyTag |
| 297 | name string |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 298 | |
| 299 | // True if the dependency is relinked at runtime. |
| 300 | runtimeLinked bool |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 301 | |
| 302 | // True if the dependency is a toolchain, for example an annotation processor. |
| 303 | toolchain bool |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 306 | // installDependencyTag is a dependency tag that is annotated to cause the installed files of the |
| 307 | // dependency to be installed when the parent module is installed. |
| 308 | type installDependencyTag struct { |
| 309 | blueprint.BaseDependencyTag |
| 310 | android.InstallAlwaysNeededDependencyTag |
| 311 | name string |
| 312 | } |
| 313 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 314 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 315 | if d.runtimeLinked { |
| 316 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 317 | } else if d.toolchain { |
| 318 | return []android.LicenseAnnotation{android.LicenseAnnotationToolchain} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 319 | } |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 324 | |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 325 | type usesLibraryDependencyTag struct { |
| 326 | dependencyTag |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 327 | sdkVersion int // SDK version in which the library appared as a standalone library. |
| 328 | optional bool // If the dependency is optional or required. |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 331 | func makeUsesLibraryDependencyTag(sdkVersion int, optional bool) usesLibraryDependencyTag { |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 332 | return usesLibraryDependencyTag{ |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 333 | dependencyTag: dependencyTag{ |
| 334 | name: fmt.Sprintf("uses-library-%d", sdkVersion), |
| 335 | runtimeLinked: true, |
| 336 | }, |
| 337 | sdkVersion: sdkVersion, |
| 338 | optional: optional, |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 342 | func IsJniDepTag(depTag blueprint.DependencyTag) bool { |
Colin Cross | de78d13 | 2020-10-09 18:59:49 -0700 | [diff] [blame] | 343 | return depTag == jniLibTag |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 344 | } |
| 345 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 346 | var ( |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 347 | dataNativeBinsTag = dependencyTag{name: "dataNativeBins"} |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 348 | dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 349 | staticLibTag = dependencyTag{name: "staticlib"} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 350 | libTag = dependencyTag{name: "javalib", runtimeLinked: true} |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 351 | sdkLibTag = dependencyTag{name: "sdklib", runtimeLinked: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 352 | java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 353 | pluginTag = dependencyTag{name: "plugin", toolchain: true} |
| 354 | errorpronePluginTag = dependencyTag{name: "errorprone-plugin", toolchain: true} |
| 355 | exportedPluginTag = dependencyTag{name: "exported-plugin", toolchain: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 356 | bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true} |
| 357 | systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 358 | frameworkResTag = dependencyTag{name: "framework-res"} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 359 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true} |
| 360 | kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 361 | kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 362 | proguardRaiseTag = dependencyTag{name: "proguard-raise"} |
| 363 | certificateTag = dependencyTag{name: "certificate"} |
| 364 | instrumentationForTag = dependencyTag{name: "instrumentation_for"} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 365 | extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 366 | jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 367 | syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} |
| 368 | jniInstallTag = installDependencyTag{name: "jni install"} |
| 369 | binaryInstallTag = installDependencyTag{name: "binary install"} |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 370 | usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false) |
| 371 | usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true) |
| 372 | usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true) |
| 373 | usesLibCompat29ReqTag = makeUsesLibraryDependencyTag(29, false) |
| 374 | usesLibCompat30OptTag = makeUsesLibraryDependencyTag(30, true) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 375 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 376 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 377 | func IsLibDepTag(depTag blueprint.DependencyTag) bool { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 378 | return depTag == libTag || depTag == sdkLibTag |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool { |
| 382 | return depTag == staticLibTag |
| 383 | } |
| 384 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 385 | type sdkDep struct { |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 386 | useModule, useFiles, invalidVersion bool |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 387 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 388 | // The modules that will be added to the bootclasspath when targeting 1.8 or lower |
| 389 | bootclasspath []string |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 390 | |
| 391 | // The default system modules to use. Will be an empty string if no system |
| 392 | // modules are to be used. |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 393 | systemModules string |
| 394 | |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 395 | // The modules that will be added to the classpath regardless of the Java language level targeted |
| 396 | classpath []string |
| 397 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 398 | // 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] | 399 | // (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] | 400 | java9Classpath []string |
| 401 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 402 | frameworkResModule string |
| 403 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 404 | jars android.Paths |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 405 | aidl android.OptionalPath |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 406 | |
| 407 | noStandardLibs, noFrameworksLibs bool |
| 408 | } |
| 409 | |
| 410 | func (s sdkDep) hasStandardLibs() bool { |
| 411 | return !s.noStandardLibs |
| 412 | } |
| 413 | |
| 414 | func (s sdkDep) hasFrameworkLibs() bool { |
| 415 | return !s.noStandardLibs && !s.noFrameworksLibs |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 418 | type jniLib struct { |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 419 | name string |
| 420 | path android.Path |
| 421 | target android.Target |
| 422 | coverageFile android.OptionalPath |
| 423 | unstrippedFile android.Path |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 426 | func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 427 | sdkDep := decodeSdkDep(ctx, sdkContext) |
| 428 | if sdkDep.useModule { |
| 429 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) |
| 430 | ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 431 | ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 432 | if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() { |
| 433 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...) |
| 434 | } |
| 435 | if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() { |
| 436 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...) |
| 437 | } |
| 438 | } |
| 439 | if sdkDep.systemModules != "" { |
| 440 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
| 441 | } |
| 442 | } |
| 443 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 444 | type deps struct { |
Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 445 | // bootClasspath is the list of jars that form the boot classpath (generally the java.* and |
| 446 | // android.* classes) for tools that still use it. javac targeting 1.9 or higher uses |
| 447 | // systemModules and java9Classpath instead. |
| 448 | bootClasspath classpath |
| 449 | |
| 450 | // classpath is the list of jars that form the classpath for javac and kotlinc rules. It |
| 451 | // contains header jars for all static and non-static dependencies. |
| 452 | classpath classpath |
| 453 | |
| 454 | // dexClasspath is the list of jars that form the classpath for d8 and r8 rules. It contains |
| 455 | // header jars for all non-static dependencies. Static dependencies have already been |
| 456 | // combined into the program jar. |
| 457 | dexClasspath classpath |
| 458 | |
| 459 | // java9Classpath is the list of jars that will be added to the classpath when targeting |
| 460 | // 1.9 or higher. It generally contains the android.* classes, while the java.* classes |
| 461 | // are provided by systemModules. |
| 462 | java9Classpath classpath |
| 463 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 464 | processorPath classpath |
| 465 | errorProneProcessorPath classpath |
| 466 | processorClasses []string |
| 467 | staticJars android.Paths |
| 468 | staticHeaderJars android.Paths |
| 469 | staticResourceJars android.Paths |
| 470 | aidlIncludeDirs android.Paths |
| 471 | srcs android.Paths |
| 472 | srcJars android.Paths |
| 473 | systemModules *systemModules |
| 474 | aidlPreprocess android.OptionalPath |
| 475 | kotlinStdlib android.Paths |
| 476 | kotlinAnnotations android.Paths |
Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 477 | kotlinPlugins android.Paths |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 478 | |
| 479 | disableTurbine bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 480 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 481 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 482 | func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { |
| 483 | for _, f := range dep.Srcs() { |
| 484 | if f.Ext() != ".jar" { |
| 485 | ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", |
| 486 | ctx.OtherModuleName(dep.(blueprint.Module))) |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 491 | func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 492 | if javaVersion != "" { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 493 | return normalizeJavaVersion(ctx, javaVersion) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 494 | } else if ctx.Device() { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 495 | return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 496 | } else if ctx.Config().TargetsJava17() { |
| 497 | // Temporary experimental flag to be able to try and build with |
| 498 | // java version 17 options. The flag, if used, just sets Java |
| 499 | // 17 as the default version, leaving any components that |
| 500 | // target an older version intact. |
| 501 | return JAVA_VERSION_17 |
Sorin Basca | 8d3e0bb | 2022-01-20 15:21:51 +0000 | [diff] [blame] | 502 | } else { |
Sorin Basca | 18ecf61 | 2022-01-23 09:01:07 +0000 | [diff] [blame] | 503 | return JAVA_VERSION_11 |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 504 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 507 | type javaVersion int |
| 508 | |
| 509 | const ( |
| 510 | JAVA_VERSION_UNSUPPORTED = 0 |
| 511 | JAVA_VERSION_6 = 6 |
| 512 | JAVA_VERSION_7 = 7 |
| 513 | JAVA_VERSION_8 = 8 |
| 514 | JAVA_VERSION_9 = 9 |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 515 | JAVA_VERSION_11 = 11 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 516 | JAVA_VERSION_17 = 17 |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 517 | ) |
| 518 | |
| 519 | func (v javaVersion) String() string { |
| 520 | switch v { |
| 521 | case JAVA_VERSION_6: |
| 522 | return "1.6" |
| 523 | case JAVA_VERSION_7: |
| 524 | return "1.7" |
| 525 | case JAVA_VERSION_8: |
| 526 | return "1.8" |
| 527 | case JAVA_VERSION_9: |
| 528 | return "1.9" |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 529 | case JAVA_VERSION_11: |
| 530 | return "11" |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 531 | case JAVA_VERSION_17: |
| 532 | return "17" |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 533 | default: |
| 534 | return "unsupported" |
| 535 | } |
| 536 | } |
| 537 | |
Cole Faust | d96eebf | 2022-06-28 14:41:27 -0700 | [diff] [blame] | 538 | func (v javaVersion) StringForKotlinc() string { |
| 539 | // $ ./external/kotlinc/bin/kotlinc -jvm-target foo |
| 540 | // error: unknown JVM target version: foo |
| 541 | // Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17 |
| 542 | switch v { |
| 543 | case JAVA_VERSION_7: |
| 544 | return "1.6" |
| 545 | case JAVA_VERSION_9: |
| 546 | return "9" |
| 547 | default: |
| 548 | return v.String() |
| 549 | } |
| 550 | } |
| 551 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 552 | // Returns true if javac targeting this version uses system modules instead of a bootclasspath. |
| 553 | func (v javaVersion) usesJavaModules() bool { |
| 554 | return v >= 9 |
| 555 | } |
| 556 | |
| 557 | func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion { |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 558 | switch javaVersion { |
| 559 | case "1.6", "6": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 560 | return JAVA_VERSION_6 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 561 | case "1.7", "7": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 562 | return JAVA_VERSION_7 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 563 | case "1.8", "8": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 564 | return JAVA_VERSION_8 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 565 | case "1.9", "9": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 566 | return JAVA_VERSION_9 |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 567 | case "11": |
| 568 | return JAVA_VERSION_11 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 569 | case "17": |
Sorin Basca | 5938fed | 2022-06-22 12:53:51 +0100 | [diff] [blame] | 570 | return JAVA_VERSION_17 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 571 | case "10", "12", "13", "14", "15", "16": |
| 572 | ctx.PropertyErrorf("java_version", "Java language level %s is not supported", javaVersion) |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 573 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 574 | default: |
| 575 | ctx.PropertyErrorf("java_version", "Unrecognized Java language level") |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 576 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 580 | // |
| 581 | // Java libraries (.jar file) |
| 582 | // |
| 583 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 584 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 585 | Module |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 586 | |
| 587 | InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 590 | var _ android.ApexModule = (*Library)(nil) |
| 591 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 592 | // Provides access to the list of permitted packages from apex boot jars. |
Paul Duffin | e739f1e | 2020-05-29 11:24:51 +0100 | [diff] [blame] | 593 | type PermittedPackagesForUpdatableBootJars interface { |
| 594 | PermittedPackagesForUpdatableBootJars() []string |
| 595 | } |
| 596 | |
| 597 | var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil) |
| 598 | |
| 599 | func (j *Library) PermittedPackagesForUpdatableBootJars() []string { |
| 600 | return j.properties.Permitted_packages |
| 601 | } |
| 602 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 603 | func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { |
Ulya Trafimovich | f491dde | 2020-01-24 12:19:45 +0000 | [diff] [blame] | 604 | // Store uncompressed (and aligned) any dex files from jars in APEXes. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 605 | if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() { |
Ulya Trafimovich | f491dde | 2020-01-24 12:19:45 +0000 | [diff] [blame] | 606 | return true |
| 607 | } |
| 608 | |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 609 | // Store uncompressed (and do not strip) dex files from boot class path jars. |
| 610 | if inList(ctx.ModuleName(), ctx.Config().BootJars()) { |
| 611 | return true |
| 612 | } |
| 613 | |
| 614 | // Store uncompressed dex files that are preopted on /system. |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 615 | if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, dexpreopter.installPath)) { |
Vladimir Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 616 | return true |
| 617 | } |
Colin Cross | 083a2aa | 2019-02-06 16:37:12 -0800 | [diff] [blame] | 618 | if ctx.Config().UncompressPrivAppDex() && |
| 619 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) { |
| 620 | return true |
| 621 | } |
| 622 | |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 623 | return false |
| 624 | } |
| 625 | |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 626 | // Sets `dexer.dexProperties.Uncompress_dex` to the proper value. |
| 627 | func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) { |
| 628 | if dexer.dexProperties.Uncompress_dex == nil { |
| 629 | // If the value was not force-set by the user, use reasonable default based on the module. |
| 630 | dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter)) |
| 631 | } |
| 632 | } |
| 633 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 634 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 635 | |
| 636 | j.provideHiddenAPIPropertyInfo(ctx) |
| 637 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 638 | j.sdkVersion = j.SdkVersion(ctx) |
| 639 | j.minSdkVersion = j.MinSdkVersion(ctx) |
satayev | 0a420e7 | 2021-11-29 17:25:52 +0000 | [diff] [blame] | 640 | j.maxSdkVersion = j.MaxSdkVersion(ctx) |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 641 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 642 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 643 | if !apexInfo.IsForPlatform() { |
| 644 | j.hideApexVariantFromMake = true |
| 645 | } |
| 646 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 647 | j.checkSdkVersions(ctx) |
Colin Cross | 61df14a | 2021-12-01 13:04:46 -0800 | [diff] [blame] | 648 | if ctx.Device() { |
| 649 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 650 | ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) |
| 651 | j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary |
| 652 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
| 653 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
| 654 | j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
| 655 | } |
Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 656 | j.compile(ctx, nil) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 657 | |
bralee | 1fbf440 | 2020-05-21 10:11:59 +0800 | [diff] [blame] | 658 | // Collect the module directory for IDE info in java/jdeps.go. |
| 659 | j.modulePaths = append(j.modulePaths, ctx.ModuleDir()) |
| 660 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 661 | exclusivelyForApex := !apexInfo.IsForPlatform() |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 662 | if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 663 | var extraInstallDeps android.Paths |
| 664 | if j.InstallMixin != nil { |
| 665 | extraInstallDeps = j.InstallMixin(ctx, j.outputFile) |
| 666 | } |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 667 | hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host() |
| 668 | if hostDexNeeded { |
Colin Cross | 3108ce1 | 2021-11-10 14:38:50 -0800 | [diff] [blame] | 669 | j.hostdexInstallFile = ctx.InstallFile( |
| 670 | android.PathForHostDexInstall(ctx, "framework"), |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 671 | j.Stem()+"-hostdex.jar", j.outputFile) |
| 672 | } |
| 673 | var installDir android.InstallPath |
| 674 | if ctx.InstallInTestcases() { |
| 675 | var archDir string |
| 676 | if !ctx.Host() { |
| 677 | archDir = ctx.DeviceConfig().DeviceArch() |
| 678 | } |
| 679 | installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) |
| 680 | } else { |
| 681 | installDir = android.PathForModuleInstall(ctx, "framework") |
| 682 | } |
| 683 | j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 684 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 687 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 688 | j.deps(ctx) |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 689 | j.usesLibrary.deps(ctx, false) |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 692 | const ( |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 693 | aidlIncludeDir = "aidl" |
| 694 | javaDir = "java" |
| 695 | jarFileSuffix = ".jar" |
| 696 | testConfigSuffix = "-AndroidTest.xml" |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 697 | ) |
| 698 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 699 | // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 700 | func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 701 | return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 704 | func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string { |
| 705 | return filepath.Join(javaDir, osPrefix, name+suffix) |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 708 | type librarySdkMemberType struct { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 709 | android.SdkMemberTypeBase |
Paul Duffin | f5c0a9c | 2020-02-28 14:39:53 +0000 | [diff] [blame] | 710 | |
| 711 | // Function to retrieve the appropriate output jar (implementation or header) from |
| 712 | // the library. |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 713 | jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path |
| 714 | |
| 715 | // Function to compute the snapshot relative path to which the named library's |
| 716 | // jar should be copied. |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 717 | snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 718 | |
| 719 | // True if only the jar should be copied to the snapshot, false if the jar plus any additional |
| 720 | // files like aidl files should also be copied. |
| 721 | onlyCopyJarToSnapshot bool |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 724 | const ( |
| 725 | onlyCopyJarToSnapshot = true |
| 726 | copyEverythingToSnapshot = false |
| 727 | ) |
| 728 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 729 | func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 730 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { |
| 734 | _, ok := module.(*Library) |
| 735 | return ok |
| 736 | } |
| 737 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 738 | func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 739 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import") |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 740 | } |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 741 | |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 742 | func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 743 | return &librarySdkMemberProperties{} |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | type librarySdkMemberProperties struct { |
| 747 | android.SdkMemberPropertiesBase |
| 748 | |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 749 | JarToExport android.Path `android:"arch_variant"` |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 750 | AidlIncludeDirs android.Paths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 751 | |
| 752 | // The list of permitted packages that need to be passed to the prebuilts as they are used to |
| 753 | // create the updatable-bcp-packages.txt file. |
| 754 | PermittedPackages []string |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 757 | func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 758 | j := variant.(*Library) |
| 759 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 760 | p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j) |
| 761 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 762 | p.AidlIncludeDirs = j.AidlIncludeDirs() |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 763 | |
| 764 | p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars() |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 765 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 766 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 767 | func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 768 | builder := ctx.SnapshotBuilder() |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 769 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 770 | memberType := ctx.MemberType().(*librarySdkMemberType) |
| 771 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 772 | exportedJar := p.JarToExport |
| 773 | if exportedJar != nil { |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 774 | // Delegate the creation of the snapshot relative path to the member type. |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 775 | snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 776 | |
| 777 | // Copy the exported jar to the snapshot. |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 778 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) |
| 779 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 780 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
| 781 | } |
| 782 | |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 783 | if len(p.PermittedPackages) > 0 { |
| 784 | propertySet.AddProperty("permitted_packages", p.PermittedPackages) |
| 785 | } |
| 786 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 787 | // Do not copy anything else to the snapshot. |
| 788 | if memberType.onlyCopyJarToSnapshot { |
| 789 | return |
| 790 | } |
| 791 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 792 | aidlIncludeDirs := p.AidlIncludeDirs |
| 793 | if len(aidlIncludeDirs) != 0 { |
| 794 | sdkModuleContext := ctx.SdkModuleContext() |
| 795 | for _, dir := range aidlIncludeDirs { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 796 | // TODO(jiyong): copy parcelable declarations only |
| 797 | aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) |
| 798 | for _, file := range aidlFiles { |
| 799 | builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) |
| 800 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 801 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 802 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 803 | // TODO(b/151933053) - add aidl include dirs property |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 804 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 807 | // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. |
| 808 | // |
| 809 | // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were |
| 810 | // compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used |
| 811 | // as a `static_libs` dependency of another module. |
| 812 | // |
| 813 | // Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on |
| 814 | // a device. |
| 815 | // |
| 816 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 817 | // compiled against the host bootclasspath. |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 818 | func LibraryFactory() android.Module { |
| 819 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 820 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 821 | module.addHostAndDeviceProperties() |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 822 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 823 | module.initModuleAndImport(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 824 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 825 | android.InitApexModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 826 | android.InitSdkAwareModule(module) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 827 | android.InitBazelModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 828 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 829 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 832 | // java_library_static is an obsolete alias for java_library. |
| 833 | func LibraryStaticFactory() android.Module { |
| 834 | return LibraryFactory() |
| 835 | } |
| 836 | |
| 837 | // java_library_host builds and links sources into a `.jar` file for the host. |
| 838 | // |
| 839 | // A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 840 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 841 | func LibraryHostFactory() android.Module { |
| 842 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 843 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 844 | module.addHostProperties() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 845 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 846 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 847 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 848 | android.InitApexModule(module) |
Paul Duffin | b6b89a4 | 2021-05-06 16:33:43 +0100 | [diff] [blame] | 849 | android.InitSdkAwareModule(module) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 850 | android.InitBazelModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 851 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 852 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | // |
Colin Cross | b628ea5 | 2018-08-14 16:42:33 -0700 | [diff] [blame] | 856 | // Java Tests |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 857 | // |
| 858 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 859 | // Test option struct. |
| 860 | type TestOptions struct { |
Zhenhuang Wang | 0ac5a43 | 2022-08-12 18:49:20 +0800 | [diff] [blame] | 861 | android.CommonTestOptions |
| 862 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 863 | // a list of extra test configuration files that should be installed with the module. |
| 864 | Extra_test_configs []string `android:"path,arch_variant"` |
| 865 | } |
| 866 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 867 | type testProperties struct { |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 868 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 869 | // installed into. |
| 870 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 871 | |
| 872 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 873 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 874 | Test_config *string `android:"path,arch_variant"` |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 875 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 876 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 877 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 878 | Test_config_template *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 879 | |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 880 | // list of files or filegroup modules that provide data that should be installed alongside |
| 881 | // the test |
Jiyong Park | 2b0e490 | 2021-02-16 06:52:39 +0900 | [diff] [blame] | 882 | Data []string `android:"path"` |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 883 | |
| 884 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 885 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 886 | // explicitly. |
| 887 | Auto_gen_config *bool |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 888 | |
| 889 | // Add parameterized mainline modules to auto generated test config. The options will be |
| 890 | // handled by TradeFed to do downloading and installing the specified modules on the device. |
| 891 | Test_mainline_modules []string |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 892 | |
| 893 | // Test options. |
| 894 | Test_options TestOptions |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 895 | |
| 896 | // Names of modules containing JNI libraries that should be installed alongside the test. |
| 897 | Jni_libs []string |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame] | 898 | |
| 899 | // Install the test into a folder named for the module in all test suites. |
| 900 | Per_testcase_directory *bool |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 903 | type hostTestProperties struct { |
| 904 | // list of native binary modules that should be installed alongside the test |
| 905 | Data_native_bins []string `android:"arch_variant"` |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 906 | |
| 907 | // list of device binary modules that should be installed alongside the test |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 908 | // This property only adds the first variant of the dependency |
| 909 | Data_device_bins_first []string `android:"arch_variant"` |
| 910 | |
| 911 | // list of device binary modules that should be installed alongside the test |
| 912 | // This property adds 64bit AND 32bit variants of the dependency |
| 913 | Data_device_bins_both []string `android:"arch_variant"` |
| 914 | |
| 915 | // list of device binary modules that should be installed alongside the test |
| 916 | // This property only adds 64bit variants of the dependency |
| 917 | Data_device_bins_64 []string `android:"arch_variant"` |
| 918 | |
| 919 | // list of device binary modules that should be installed alongside the test |
| 920 | // This property adds 32bit variants of the dependency if available, or else |
| 921 | // defaults to the 64bit variant |
| 922 | Data_device_bins_prefer32 []string `android:"arch_variant"` |
| 923 | |
| 924 | // list of device binary modules that should be installed alongside the test |
| 925 | // This property only adds 32bit variants of the dependency |
| 926 | Data_device_bins_32 []string `android:"arch_variant"` |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 929 | type testHelperLibraryProperties struct { |
| 930 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 931 | // installed into. |
| 932 | Test_suites []string `android:"arch_variant"` |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame] | 933 | |
| 934 | // Install the test into a folder named for the module in all test suites. |
| 935 | Per_testcase_directory *bool |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 938 | type prebuiltTestProperties struct { |
| 939 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 940 | // installed into. |
| 941 | Test_suites []string `android:"arch_variant"` |
| 942 | |
| 943 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 944 | // installed with the module. |
| 945 | Test_config *string `android:"path,arch_variant"` |
| 946 | } |
| 947 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 948 | type Test struct { |
| 949 | Library |
| 950 | |
| 951 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 952 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 953 | testConfig android.Path |
| 954 | extraTestConfigs android.Paths |
| 955 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 958 | type TestHost struct { |
| 959 | Test |
| 960 | |
| 961 | testHostProperties hostTestProperties |
| 962 | } |
| 963 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 964 | type TestHelperLibrary struct { |
| 965 | Library |
| 966 | |
| 967 | testHelperLibraryProperties testHelperLibraryProperties |
| 968 | } |
| 969 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 970 | type JavaTestImport struct { |
| 971 | Import |
| 972 | |
| 973 | prebuiltTestProperties prebuiltTestProperties |
| 974 | |
| 975 | testConfig android.Path |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 976 | dexJarFile android.Path |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Colin Cross | 24cc4be6 | 2021-11-03 14:09:41 -0700 | [diff] [blame] | 979 | func (j *Test) InstallInTestcases() bool { |
| 980 | // Host java tests install into $(HOST_OUT_JAVA_LIBRARIES), and then are copied into |
| 981 | // testcases by base_rules.mk. |
| 982 | return !j.Host() |
| 983 | } |
| 984 | |
| 985 | func (j *TestHelperLibrary) InstallInTestcases() bool { |
| 986 | return true |
| 987 | } |
| 988 | |
| 989 | func (j *JavaTestImport) InstallInTestcases() bool { |
| 990 | return true |
| 991 | } |
| 992 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 993 | func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) { |
| 994 | if len(j.testHostProperties.Data_device_bins_first) > 0 { |
| 995 | deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() |
| 996 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...) |
| 997 | } |
| 998 | |
| 999 | var maybeAndroid32Target *android.Target |
| 1000 | var maybeAndroid64Target *android.Target |
| 1001 | android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32") |
| 1002 | android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64") |
| 1003 | if len(android32TargetList) > 0 { |
| 1004 | maybeAndroid32Target = &android32TargetList[0] |
| 1005 | } |
| 1006 | if len(android64TargetList) > 0 { |
| 1007 | maybeAndroid64Target = &android64TargetList[0] |
| 1008 | } |
| 1009 | |
| 1010 | if len(j.testHostProperties.Data_device_bins_both) > 0 { |
| 1011 | if maybeAndroid32Target == nil && maybeAndroid64Target == nil { |
| 1012 | ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets) |
| 1013 | return |
| 1014 | } |
| 1015 | if maybeAndroid32Target != nil { |
| 1016 | ctx.AddFarVariationDependencies( |
| 1017 | maybeAndroid32Target.Variations(), |
| 1018 | dataDeviceBinsTag, |
| 1019 | j.testHostProperties.Data_device_bins_both..., |
| 1020 | ) |
| 1021 | } |
| 1022 | if maybeAndroid64Target != nil { |
| 1023 | ctx.AddFarVariationDependencies( |
| 1024 | maybeAndroid64Target.Variations(), |
| 1025 | dataDeviceBinsTag, |
| 1026 | j.testHostProperties.Data_device_bins_both..., |
| 1027 | ) |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | if len(j.testHostProperties.Data_device_bins_prefer32) > 0 { |
| 1032 | if maybeAndroid32Target != nil { |
| 1033 | ctx.AddFarVariationDependencies( |
| 1034 | maybeAndroid32Target.Variations(), |
| 1035 | dataDeviceBinsTag, |
| 1036 | j.testHostProperties.Data_device_bins_prefer32..., |
| 1037 | ) |
| 1038 | } else { |
| 1039 | if maybeAndroid64Target == nil { |
| 1040 | ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets) |
| 1041 | return |
| 1042 | } |
| 1043 | ctx.AddFarVariationDependencies( |
| 1044 | maybeAndroid64Target.Variations(), |
| 1045 | dataDeviceBinsTag, |
| 1046 | j.testHostProperties.Data_device_bins_prefer32..., |
| 1047 | ) |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | if len(j.testHostProperties.Data_device_bins_32) > 0 { |
| 1052 | if maybeAndroid32Target == nil { |
| 1053 | ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets) |
| 1054 | return |
| 1055 | } |
| 1056 | deviceVariations := maybeAndroid32Target.Variations() |
| 1057 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...) |
| 1058 | } |
| 1059 | |
| 1060 | if len(j.testHostProperties.Data_device_bins_64) > 0 { |
| 1061 | if maybeAndroid64Target == nil { |
| 1062 | ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets) |
| 1063 | return |
| 1064 | } |
| 1065 | deviceVariations := maybeAndroid64Target.Variations() |
| 1066 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...) |
| 1067 | } |
| 1068 | } |
| 1069 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1070 | func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1071 | if len(j.testHostProperties.Data_native_bins) > 0 { |
| 1072 | for _, target := range ctx.MultiTargets() { |
| 1073 | ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...) |
| 1074 | } |
| 1075 | } |
| 1076 | |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 1077 | if len(j.testProperties.Jni_libs) > 0 { |
| 1078 | for _, target := range ctx.MultiTargets() { |
| 1079 | sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) |
| 1080 | ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) |
| 1081 | } |
| 1082 | } |
| 1083 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1084 | j.addDataDeviceBinsDeps(ctx) |
| 1085 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1086 | j.deps(ctx) |
| 1087 | } |
| 1088 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1089 | func (j *TestHost) AddExtraResource(p android.Path) { |
| 1090 | j.extraResources = append(j.extraResources, p) |
| 1091 | } |
| 1092 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1093 | func (j *TestHost) dataDeviceBins() []string { |
| 1094 | ret := make([]string, 0, |
| 1095 | len(j.testHostProperties.Data_device_bins_first)+ |
| 1096 | len(j.testHostProperties.Data_device_bins_both)+ |
| 1097 | len(j.testHostProperties.Data_device_bins_prefer32)+ |
| 1098 | len(j.testHostProperties.Data_device_bins_32)+ |
| 1099 | len(j.testHostProperties.Data_device_bins_64), |
| 1100 | ) |
| 1101 | |
| 1102 | ret = append(ret, j.testHostProperties.Data_device_bins_first...) |
| 1103 | ret = append(ret, j.testHostProperties.Data_device_bins_both...) |
| 1104 | ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...) |
| 1105 | ret = append(ret, j.testHostProperties.Data_device_bins_32...) |
| 1106 | ret = append(ret, j.testHostProperties.Data_device_bins_64...) |
| 1107 | |
| 1108 | return ret |
| 1109 | } |
| 1110 | |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1111 | func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1112 | var configs []tradefed.Config |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1113 | dataDeviceBins := j.dataDeviceBins() |
| 1114 | if len(dataDeviceBins) > 0 { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1115 | // add Tradefed configuration to push device bins to device for testing |
| 1116 | remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name()) |
| 1117 | options := []tradefed.Option{{Name: "cleanup", Value: "true"}} |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1118 | for _, bin := range dataDeviceBins { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1119 | fullPath := filepath.Join(remoteDir, bin) |
| 1120 | options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath}) |
| 1121 | } |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1122 | configs = append(configs, tradefed.Object{ |
| 1123 | Type: "target_preparer", |
| 1124 | Class: "com.android.tradefed.targetprep.PushFilePreparer", |
| 1125 | Options: options, |
| 1126 | }) |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | j.Test.generateAndroidBuildActionsWithConfig(ctx, configs) |
| 1130 | } |
| 1131 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1132 | func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1133 | j.generateAndroidBuildActionsWithConfig(ctx, nil) |
| 1134 | } |
| 1135 | |
| 1136 | func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) { |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1137 | if j.testProperties.Test_options.Unit_test == nil && ctx.Host() { |
| 1138 | // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding. |
Julien Desprez | f666b15 | 2021-03-15 13:07:53 -0700 | [diff] [blame] | 1139 | defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites) |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1140 | j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest) |
| 1141 | } |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1142 | |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 1143 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1144 | j.testProperties.Test_suites, configs, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1145 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1146 | j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1147 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 1148 | j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs) |
| 1149 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1150 | ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) { |
| 1151 | j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) |
| 1152 | }) |
| 1153 | |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1154 | ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) { |
| 1155 | j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) |
| 1156 | }) |
| 1157 | |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 1158 | ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { |
| 1159 | sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) |
| 1160 | if sharedLibInfo.SharedLibrary != nil { |
| 1161 | // Copy to an intermediate output directory to append "lib[64]" to the path, |
| 1162 | // so that it's compatible with the default rpath values. |
| 1163 | var relPath string |
| 1164 | if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { |
| 1165 | relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) |
| 1166 | } else { |
| 1167 | relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) |
| 1168 | } |
| 1169 | relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) |
| 1170 | ctx.Build(pctx, android.BuildParams{ |
| 1171 | Rule: android.Cp, |
| 1172 | Input: sharedLibInfo.SharedLibrary, |
| 1173 | Output: relocatedLib, |
| 1174 | }) |
| 1175 | j.data = append(j.data, relocatedLib) |
| 1176 | } else { |
| 1177 | ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) |
| 1178 | } |
| 1179 | }) |
| 1180 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1181 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1184 | func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1185 | j.Library.GenerateAndroidBuildActions(ctx) |
| 1186 | } |
| 1187 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1188 | func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1189 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil, |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1190 | j.prebuiltTestProperties.Test_suites, nil, nil, nil) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1191 | |
| 1192 | j.Import.GenerateAndroidBuildActions(ctx) |
| 1193 | } |
| 1194 | |
| 1195 | type testSdkMemberType struct { |
| 1196 | android.SdkMemberTypeBase |
| 1197 | } |
| 1198 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 1199 | func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1200 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | func (mt *testSdkMemberType) IsInstance(module android.Module) bool { |
| 1204 | _, ok := module.(*Test) |
| 1205 | return ok |
| 1206 | } |
| 1207 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1208 | func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1209 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import") |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1210 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1211 | |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1212 | func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1213 | return &testSdkMemberProperties{} |
| 1214 | } |
| 1215 | |
| 1216 | type testSdkMemberProperties struct { |
| 1217 | android.SdkMemberPropertiesBase |
| 1218 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1219 | JarToExport android.Path |
| 1220 | TestConfig android.Path |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1223 | func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1224 | test := variant.(*Test) |
| 1225 | |
| 1226 | implementationJars := test.ImplementationJars() |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1227 | if len(implementationJars) != 1 { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1228 | 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] | 1229 | } |
| 1230 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1231 | p.JarToExport = implementationJars[0] |
| 1232 | p.TestConfig = test.testConfig |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1233 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1234 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1235 | func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1236 | builder := ctx.SnapshotBuilder() |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1237 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1238 | exportedJar := p.JarToExport |
| 1239 | if exportedJar != nil { |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 1240 | snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1241 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1242 | |
| 1243 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | testConfig := p.TestConfig |
| 1247 | if testConfig != nil { |
| 1248 | snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix) |
| 1249 | builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath) |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1250 | propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath) |
| 1251 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1254 | // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and |
| 1255 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. |
| 1256 | // |
| 1257 | // By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 1258 | // compiled against the device bootclasspath. |
| 1259 | // |
| 1260 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 1261 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1262 | func TestFactory() android.Module { |
| 1263 | module := &Test{} |
| 1264 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1265 | module.addHostAndDeviceProperties() |
| 1266 | module.AddProperties(&module.testProperties) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1267 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1268 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e302687 | 2019-01-05 22:30:13 -0800 | [diff] [blame] | 1269 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1270 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1271 | |
Paul Duffin | b6b89a4 | 2021-05-06 16:33:43 +0100 | [diff] [blame] | 1272 | android.InitSdkAwareModule(module) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1273 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1274 | return module |
| 1275 | } |
| 1276 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1277 | // java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite. |
| 1278 | func TestHelperLibraryFactory() android.Module { |
| 1279 | module := &TestHelperLibrary{} |
| 1280 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1281 | module.addHostAndDeviceProperties() |
| 1282 | module.AddProperties(&module.testHelperLibraryProperties) |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1283 | |
Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 1284 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1285 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1286 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 1287 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1288 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1289 | return module |
| 1290 | } |
| 1291 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1292 | // java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module |
| 1293 | // and makes sure that it is added to the appropriate test suite. |
| 1294 | // |
| 1295 | // By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 1296 | // compiled against an Android classpath. |
| 1297 | // |
| 1298 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1299 | // for host modules. |
| 1300 | func JavaTestImportFactory() android.Module { |
| 1301 | module := &JavaTestImport{} |
| 1302 | |
| 1303 | module.AddProperties( |
| 1304 | &module.Import.properties, |
| 1305 | &module.prebuiltTestProperties) |
| 1306 | |
| 1307 | module.Import.properties.Installable = proptools.BoolPtr(true) |
| 1308 | |
| 1309 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 1310 | android.InitApexModule(module) |
| 1311 | android.InitSdkAwareModule(module) |
| 1312 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1313 | return module |
| 1314 | } |
| 1315 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1316 | // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to |
| 1317 | // allow running the test with `atest` or a `TEST_MAPPING` file. |
| 1318 | // |
| 1319 | // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 1320 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1321 | func TestHostFactory() android.Module { |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1322 | module := &TestHost{} |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1323 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1324 | module.addHostProperties() |
| 1325 | module.AddProperties(&module.testProperties) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1326 | module.AddProperties(&module.testHostProperties) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1327 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1328 | InitTestHost( |
| 1329 | module, |
| 1330 | proptools.BoolPtr(true), |
| 1331 | nil, |
| 1332 | nil) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1333 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1334 | InitJavaModuleMultiTargets(module, android.HostSupported) |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1335 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1336 | return module |
| 1337 | } |
| 1338 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1339 | func InitTestHost(th *TestHost, installable *bool, testSuites []string, autoGenConfig *bool) { |
| 1340 | th.properties.Installable = installable |
| 1341 | th.testProperties.Auto_gen_config = autoGenConfig |
| 1342 | th.testProperties.Test_suites = testSuites |
| 1343 | } |
| 1344 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1345 | // |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1346 | // Java Binaries (.jar file plus wrapper script) |
| 1347 | // |
| 1348 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1349 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1350 | // installable script to execute the resulting jar |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1351 | Wrapper *string `android:"path,arch_variant"` |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1352 | |
| 1353 | // Name of the class containing main to be inserted into the manifest as Main-Class. |
| 1354 | Main_class *string |
Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 1355 | |
| 1356 | // Names of modules containing JNI libraries that should be installed alongside the host |
| 1357 | // variant of the binary. |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1358 | Jni_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1361 | type Binary struct { |
| 1362 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1363 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1364 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1365 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1366 | isWrapperVariant bool |
| 1367 | |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1368 | wrapperFile android.Path |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 1369 | binaryFile android.InstallPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 1372 | func (j *Binary) HostToolPath() android.OptionalPath { |
| 1373 | return android.OptionalPathForPath(j.binaryFile) |
| 1374 | } |
| 1375 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1376 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1377 | if ctx.Arch().ArchType == android.Common { |
| 1378 | // Compile the jar |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1379 | if j.binaryProperties.Main_class != nil { |
| 1380 | if j.properties.Manifest != nil { |
| 1381 | ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") |
| 1382 | } |
| 1383 | manifestFile := android.PathForModuleOut(ctx, "manifest.txt") |
| 1384 | GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) |
| 1385 | j.overrideManifest = android.OptionalPathForPath(manifestFile) |
| 1386 | } |
| 1387 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1388 | j.Library.GenerateAndroidBuildActions(ctx) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1389 | } else { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1390 | // Handle the binary wrapper |
| 1391 | j.isWrapperVariant = true |
| 1392 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1393 | if j.binaryProperties.Wrapper != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1394 | j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1395 | } else { |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1396 | if ctx.Windows() { |
| 1397 | ctx.PropertyErrorf("wrapper", "wrapper is required for Windows") |
| 1398 | } |
| 1399 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1400 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") |
| 1401 | } |
| 1402 | |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1403 | ext := "" |
| 1404 | if ctx.Windows() { |
| 1405 | ext = ".bat" |
| 1406 | } |
| 1407 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 1408 | // 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] | 1409 | // of the wrapper variant, which will include the common variant's jar file and any JNI |
| 1410 | // libraries. This is verified by TestBinary. |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1411 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1412 | ctx.ModuleName()+ext, j.wrapperFile) |
| 1413 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1416 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 1417 | if ctx.Arch().ArchType == android.Common { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1418 | j.deps(ctx) |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1419 | } |
Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 1420 | if ctx.Arch().ArchType != android.Common { |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 1421 | // These dependencies ensure the host installation rules will install the jar file and |
| 1422 | // the jni libraries when the wrapper is installed. |
| 1423 | ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...) |
| 1424 | ctx.AddVariationDependencies( |
| 1425 | []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}}, |
| 1426 | binaryInstallTag, ctx.ModuleName()) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1427 | } |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1430 | // java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host |
| 1431 | // as well. |
| 1432 | // |
| 1433 | // By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 1434 | // compiled against the device bootclasspath. |
| 1435 | // |
| 1436 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 1437 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1438 | func BinaryFactory() android.Module { |
| 1439 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1440 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1441 | module.addHostAndDeviceProperties() |
| 1442 | module.AddProperties(&module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1443 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1444 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1445 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1446 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) |
| 1447 | android.InitDefaultableModule(module) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 1448 | android.InitBazelModule(module) |
| 1449 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1450 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1453 | // java_binary_host builds a `.jar` file and a shell script that executes it for the host. |
| 1454 | // |
| 1455 | // A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 1456 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1457 | func BinaryHostFactory() android.Module { |
| 1458 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1459 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1460 | module.addHostProperties() |
| 1461 | module.AddProperties(&module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1462 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1463 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1464 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1465 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) |
| 1466 | android.InitDefaultableModule(module) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 1467 | android.InitBazelModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1468 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | // |
| 1472 | // Java prebuilts |
| 1473 | // |
| 1474 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1475 | type ImportProperties struct { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 1476 | Jars []string `android:"path,arch_variant"` |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 1477 | |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1478 | // The version of the SDK that the source prebuilt file was built against. Defaults to the |
| 1479 | // current version if not specified. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1480 | Sdk_version *string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1481 | |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1482 | // The minimum version of the SDK that this module supports. Defaults to sdk_version if not |
| 1483 | // specified. |
| 1484 | Min_sdk_version *string |
| 1485 | |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 1486 | // The max sdk version placeholder used to replace maxSdkVersion attributes on permission |
| 1487 | // and uses-permission tags in manifest_fixer. |
| 1488 | Replace_max_sdk_version_placeholder *string |
| 1489 | |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1490 | Installable *bool |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1491 | |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 1492 | // If not empty, classes are restricted to the specified packages and their sub-packages. |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 1493 | Permitted_packages []string |
| 1494 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1495 | // List of shared java libs that this module has dependencies to |
| 1496 | Libs []string |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1497 | |
| 1498 | // List of files to remove from the jar file(s) |
| 1499 | Exclude_files []string |
| 1500 | |
| 1501 | // List of directories to remove from the jar file(s) |
| 1502 | Exclude_dirs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1503 | |
| 1504 | // if set to true, run Jetifier against .jar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1505 | Jetifier *bool |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 1506 | |
| 1507 | // set the name of the output |
| 1508 | Stem *string |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1509 | |
| 1510 | Aidl struct { |
| 1511 | // directories that should be added as include directories for any aidl sources of modules |
| 1512 | // that depend on this module, as well as to aidl for this module. |
| 1513 | Export_include_dirs []string |
| 1514 | } |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1518 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1519 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1520 | android.ApexModuleBase |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 1521 | android.BazelModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1522 | prebuilt android.Prebuilt |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1523 | android.SdkBase |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1524 | |
Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 1525 | // Functionality common to Module and Import. |
| 1526 | embeddableInModuleAndImport |
| 1527 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1528 | hiddenAPI |
| 1529 | dexer |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 1530 | dexpreopter |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1531 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1532 | properties ImportProperties |
| 1533 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1534 | // output file containing classes.dex and resources |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1535 | dexJarFile OptionalDexJarPath |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 1536 | dexJarInstallFile android.Path |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1537 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1538 | combinedClasspathFile android.Path |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1539 | classLoaderContexts dexpreopt.ClassLoaderContextMap |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1540 | exportAidlIncludeDirs android.Paths |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1541 | |
| 1542 | hideApexVariantFromMake bool |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1543 | |
| 1544 | sdkVersion android.SdkSpec |
| 1545 | minSdkVersion android.SdkSpec |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 1548 | var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil) |
| 1549 | |
| 1550 | func (j *Import) PermittedPackagesForUpdatableBootJars() []string { |
| 1551 | return j.properties.Permitted_packages |
| 1552 | } |
| 1553 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1554 | func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 1555 | return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version)) |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1558 | func (j *Import) SystemModules() string { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1559 | return "none" |
| 1560 | } |
| 1561 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1562 | func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1563 | if j.properties.Min_sdk_version != nil { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1564 | return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1565 | } |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1566 | return j.SdkVersion(ctx) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 1569 | func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { |
| 1570 | if j.properties.Replace_max_sdk_version_placeholder != nil { |
| 1571 | return android.SdkSpecFrom(ctx, *j.properties.Replace_max_sdk_version_placeholder) |
| 1572 | } |
| 1573 | return android.SdkSpecFrom(ctx, "") |
| 1574 | } |
| 1575 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1576 | func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 1577 | return j.SdkVersion(ctx) |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1580 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1581 | return &j.prebuilt |
| 1582 | } |
| 1583 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1584 | func (j *Import) PrebuiltSrcs() []string { |
| 1585 | return j.properties.Jars |
| 1586 | } |
| 1587 | |
| 1588 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 1589 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 1590 | } |
| 1591 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1592 | func (j *Import) Stem() string { |
| 1593 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 1594 | } |
| 1595 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1596 | func (a *Import) JacocoReportClassesFile() android.Path { |
| 1597 | return nil |
| 1598 | } |
| 1599 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 1600 | func (j *Import) LintDepSets() LintDepSets { |
| 1601 | return LintDepSets{} |
| 1602 | } |
| 1603 | |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 1604 | func (j *Import) getStrictUpdatabilityLinting() bool { |
| 1605 | return false |
| 1606 | } |
| 1607 | |
| 1608 | func (j *Import) setStrictUpdatabilityLinting(bool) { |
| 1609 | } |
| 1610 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1611 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1612 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1613 | |
| 1614 | if ctx.Device() && Bool(j.dexProperties.Compile_dex) { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1615 | sdkDeps(ctx, android.SdkContext(j), j.dexer) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1616 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 1619 | func (j *Import) commonBuildActions(ctx android.ModuleContext) { |
| 1620 | //TODO(b/231322772) these should come from Bazel once available |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1621 | j.sdkVersion = j.SdkVersion(ctx) |
| 1622 | j.minSdkVersion = j.MinSdkVersion(ctx) |
| 1623 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1624 | if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { |
| 1625 | j.hideApexVariantFromMake = true |
| 1626 | } |
| 1627 | |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1628 | if ctx.Windows() { |
| 1629 | j.HideFromMake() |
| 1630 | } |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1634 | j.commonBuildActions(ctx) |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1635 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1636 | jars := android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 1637 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1638 | jarName := j.Stem() + ".jar" |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1639 | outputFile := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1640 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, |
| 1641 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1642 | if Bool(j.properties.Jetifier) { |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1643 | inputFile := outputFile |
| 1644 | outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) |
| 1645 | TransformJetifier(ctx, outputFile, inputFile) |
| 1646 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1647 | j.combinedClasspathFile = outputFile |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1648 | j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1649 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1650 | var flags javaBuilderFlags |
| 1651 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1652 | ctx.VisitDirectDeps(func(module android.Module) { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1653 | tag := ctx.OtherModuleDependencyTag(module) |
| 1654 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1655 | if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { |
| 1656 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1657 | switch tag { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 1658 | case libTag, sdkLibTag: |
Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 1659 | flags.classpath = append(flags.classpath, dep.HeaderJars...) |
| 1660 | flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...) |
| 1661 | case staticLibTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1662 | flags.classpath = append(flags.classpath, dep.HeaderJars...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1663 | case bootClasspathTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1664 | flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1665 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1666 | } else if dep, ok := module.(SdkLibraryDependency); ok { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1667 | switch tag { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 1668 | case libTag, sdkLibTag: |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1669 | flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1670 | } |
| 1671 | } |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 1672 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1673 | addCLCFromDep(ctx, module, j.classLoaderContexts) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1674 | }) |
| 1675 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 1676 | j.maybeInstall(ctx, jarName, outputFile) |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1677 | |
| 1678 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1679 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1680 | if ctx.Device() { |
| 1681 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar |
| 1682 | // obtained from the associated deapexer module. |
| 1683 | ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1684 | if ai.ForPrebuiltApex { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1685 | // Get the path of the dex implementation jar from the `deapexer` module. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 1686 | di := android.FindDeapexerProviderForModule(ctx) |
| 1687 | if di == nil { |
| 1688 | return // An error has been reported by FindDeapexerProviderForModule. |
| 1689 | } |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1690 | if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1691 | dexJarFile := makeDexJarPathFromPath(dexOutputPath) |
| 1692 | j.dexJarFile = dexJarFile |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 1693 | installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName())) |
| 1694 | j.dexJarInstallFile = installPath |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 1695 | |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 1696 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 1697 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 1698 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
| 1699 | j.dexpreopt(ctx, dexOutputPath) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 1700 | |
| 1701 | // Initialize the hiddenapi structure. |
| 1702 | j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex) |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 1703 | } else { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1704 | // This should never happen as a variant for a prebuilt_apex is only created if the |
| 1705 | // prebuilt_apex has been configured to export the java library dex file. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 1706 | ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName()) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } else if Bool(j.dexProperties.Compile_dex) { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1709 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1710 | if sdkDep.invalidVersion { |
| 1711 | ctx.AddMissingDependencies(sdkDep.bootclasspath) |
| 1712 | ctx.AddMissingDependencies(sdkDep.java9Classpath) |
| 1713 | } else if sdkDep.useFiles { |
| 1714 | // sdkDep.jar is actually equivalent to turbine header.jar. |
| 1715 | flags.classpath = append(flags.classpath, sdkDep.jars...) |
| 1716 | } |
| 1717 | |
| 1718 | // Dex compilation |
| 1719 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 1720 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 1721 | ctx, android.PathForModuleInstall(ctx, "framework", jarName)) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 1722 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1723 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
| 1724 | |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame] | 1725 | var dexOutputFile android.OutputPath |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1726 | dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1727 | if ctx.Failed() { |
| 1728 | return |
| 1729 | } |
| 1730 | |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 1731 | // Initialize the hiddenapi structure. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1732 | j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), outputFile, j.dexProperties.Uncompress_dex) |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 1733 | |
| 1734 | // Encode hidden API flags in dex file. |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 1735 | dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1736 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1737 | j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 1738 | j.dexJarInstallFile = android.PathForModuleInstall(ctx, "framework", jarName) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1739 | } |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1740 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1741 | |
| 1742 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 1743 | HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile), |
| 1744 | ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile), |
| 1745 | ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile), |
| 1746 | AidlIncludeDirs: j.exportAidlIncludeDirs, |
| 1747 | }) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 1750 | func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) { |
| 1751 | if !Bool(j.properties.Installable) { |
| 1752 | return |
| 1753 | } |
| 1754 | |
| 1755 | var installDir android.InstallPath |
| 1756 | if ctx.InstallInTestcases() { |
| 1757 | var archDir string |
| 1758 | if !ctx.Host() { |
| 1759 | archDir = ctx.DeviceConfig().DeviceArch() |
| 1760 | } |
| 1761 | installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) |
| 1762 | } else { |
| 1763 | installDir = android.PathForModuleInstall(ctx, "framework") |
| 1764 | } |
| 1765 | ctx.InstallFile(installDir, jarName, outputFile) |
| 1766 | } |
| 1767 | |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1768 | func (j *Import) OutputFiles(tag string) (android.Paths, error) { |
| 1769 | switch tag { |
Saeid Farivar Asanjan | 128fe5c | 2020-10-15 17:54:40 +0000 | [diff] [blame] | 1770 | case "", ".jar": |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1771 | return android.Paths{j.combinedClasspathFile}, nil |
| 1772 | default: |
| 1773 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | var _ android.OutputFileProducer = (*Import)(nil) |
| 1778 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1779 | func (j *Import) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1780 | if j.combinedClasspathFile == nil { |
| 1781 | return nil |
| 1782 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1783 | return android.Paths{j.combinedClasspathFile} |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1786 | func (j *Import) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1787 | if j.combinedClasspathFile == nil { |
| 1788 | return nil |
| 1789 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1790 | return android.Paths{j.combinedClasspathFile} |
| 1791 | } |
| 1792 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1793 | func (j *Import) DexJarBuildPath() OptionalDexJarPath { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1794 | return j.dexJarFile |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 1797 | func (j *Import) DexJarInstallPath() android.Path { |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 1798 | return j.dexJarInstallFile |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1801 | func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
| 1802 | return j.classLoaderContexts |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1803 | } |
| 1804 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1805 | var _ android.ApexModule = (*Import)(nil) |
| 1806 | |
| 1807 | // Implements android.ApexModule |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1808 | func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 1809 | return j.depIsInSameApex(ctx, dep) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1810 | } |
| 1811 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1812 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1813 | func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 1814 | sdkVersion android.ApiLevel) error { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1815 | sdkSpec := j.MinSdkVersion(ctx) |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1816 | if !sdkSpec.Specified() { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1817 | return fmt.Errorf("min_sdk_version is not specified") |
| 1818 | } |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1819 | if sdkSpec.Kind == android.SdkCore { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1820 | return nil |
| 1821 | } |
Jooyung Han | 4c4da06 | 2021-06-23 10:23:16 +0900 | [diff] [blame] | 1822 | if sdkSpec.ApiLevel.GreaterThan(sdkVersion) { |
| 1823 | return fmt.Errorf("newer SDK(%v)", sdkSpec.ApiLevel) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1824 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1825 | return nil |
| 1826 | } |
| 1827 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1828 | // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or |
| 1829 | // java_sdk_library_import with the specified base module name requires to be exported from a |
| 1830 | // prebuilt_apex/apex_set. |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1831 | func requiredFilesFromPrebuiltApexForImport(name string) []string { |
| 1832 | // Add the dex implementation jar to the set of exported files. |
| 1833 | return []string{ |
| 1834 | apexRootRelativePathToJavaLib(name), |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1835 | } |
| 1836 | } |
| 1837 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1838 | // apexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for |
| 1839 | // the java library with the specified name. |
| 1840 | func apexRootRelativePathToJavaLib(name string) string { |
| 1841 | return filepath.Join("javalib", name+".jar") |
| 1842 | } |
| 1843 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1844 | var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil) |
| 1845 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1846 | func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string { |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1847 | name := j.BaseModuleName() |
| 1848 | return requiredFilesFromPrebuiltApexForImport(name) |
| 1849 | } |
| 1850 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1851 | // Add compile time check for interface implementation |
| 1852 | var _ android.IDEInfo = (*Import)(nil) |
| 1853 | var _ android.IDECustomizedModuleName = (*Import)(nil) |
| 1854 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1855 | // Collect information for opening IDE project files in java/jdeps.go. |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1856 | |
| 1857 | func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { |
| 1858 | dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) |
| 1859 | } |
| 1860 | |
| 1861 | func (j *Import) IDECustomizedModuleName() string { |
| 1862 | // TODO(b/113562217): Extract the base module name from the Import name, often the Import name |
| 1863 | // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better |
| 1864 | // solution to get the Import name. |
Ulya Trafimovich | 497a093 | 2021-07-14 16:35:33 +0100 | [diff] [blame] | 1865 | return android.RemoveOptionalPrebuiltPrefix(j.Name()) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1868 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1869 | |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 1870 | func (j *Import) IsInstallable() bool { |
| 1871 | return Bool(j.properties.Installable) |
| 1872 | } |
| 1873 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 1874 | var _ DexpreopterInterface = (*Import)(nil) |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 1875 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1876 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module. |
| 1877 | // |
| 1878 | // By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 1879 | // compiled against an Android classpath. |
| 1880 | // |
| 1881 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1882 | // for host modules. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1883 | func ImportFactory() android.Module { |
| 1884 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1885 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1886 | module.AddProperties( |
| 1887 | &module.properties, |
| 1888 | &module.dexer.dexProperties, |
| 1889 | ) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1890 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1891 | module.initModuleAndImport(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1892 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1893 | module.dexProperties.Optimize.EnabledByDefault = false |
| 1894 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1895 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1896 | android.InitApexModule(module) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1897 | android.InitSdkAwareModule(module) |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 1898 | android.InitBazelModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1899 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1900 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1903 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host |
| 1904 | // module. |
| 1905 | // |
| 1906 | // A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were |
| 1907 | // compiled against a host bootclasspath. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1908 | func ImportFactoryHost() android.Module { |
| 1909 | module := &Import{} |
| 1910 | |
| 1911 | module.AddProperties(&module.properties) |
| 1912 | |
| 1913 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1914 | android.InitApexModule(module) |
Sam Delmerico | 5f83b49 | 2022-02-28 18:50:56 +0000 | [diff] [blame] | 1915 | android.InitBazelModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1916 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1917 | return module |
| 1918 | } |
| 1919 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1920 | // dex_import module |
| 1921 | |
| 1922 | type DexImportProperties struct { |
Colin Cross | 5cfc70d | 2019-07-15 13:36:55 -0700 | [diff] [blame] | 1923 | Jars []string `android:"path"` |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 1924 | |
| 1925 | // set the name of the output |
| 1926 | Stem *string |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | type DexImport struct { |
| 1930 | android.ModuleBase |
| 1931 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1932 | android.ApexModuleBase |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1933 | prebuilt android.Prebuilt |
| 1934 | |
| 1935 | properties DexImportProperties |
| 1936 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1937 | dexJarFile OptionalDexJarPath |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1938 | |
| 1939 | dexpreopter |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1940 | |
| 1941 | hideApexVariantFromMake bool |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | func (j *DexImport) Prebuilt() *android.Prebuilt { |
| 1945 | return &j.prebuilt |
| 1946 | } |
| 1947 | |
| 1948 | func (j *DexImport) PrebuiltSrcs() []string { |
| 1949 | return j.properties.Jars |
| 1950 | } |
| 1951 | |
| 1952 | func (j *DexImport) Name() string { |
| 1953 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 1954 | } |
| 1955 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1956 | func (j *DexImport) Stem() string { |
| 1957 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 1958 | } |
| 1959 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 1960 | func (a *DexImport) JacocoReportClassesFile() android.Path { |
| 1961 | return nil |
| 1962 | } |
| 1963 | |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 1964 | func (a *DexImport) LintDepSets() LintDepSets { |
| 1965 | return LintDepSets{} |
| 1966 | } |
| 1967 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 1968 | func (j *DexImport) IsInstallable() bool { |
| 1969 | return true |
| 1970 | } |
| 1971 | |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 1972 | func (j *DexImport) getStrictUpdatabilityLinting() bool { |
| 1973 | return false |
| 1974 | } |
| 1975 | |
| 1976 | func (j *DexImport) setStrictUpdatabilityLinting(bool) { |
| 1977 | } |
| 1978 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1979 | func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1980 | if len(j.properties.Jars) != 1 { |
| 1981 | ctx.PropertyErrorf("jars", "exactly one jar must be provided") |
| 1982 | } |
| 1983 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1984 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1985 | if !apexInfo.IsForPlatform() { |
| 1986 | j.hideApexVariantFromMake = true |
| 1987 | } |
| 1988 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 1989 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 1990 | ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1991 | j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) |
| 1992 | |
| 1993 | inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") |
| 1994 | dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") |
| 1995 | |
| 1996 | if j.dexpreopter.uncompressedDex { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1997 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1998 | |
| 1999 | temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned") |
| 2000 | rule.Temporary(temporary) |
| 2001 | |
| 2002 | // use zip2zip to uncompress classes*.dex files |
| 2003 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2004 | BuiltTool("zip2zip"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2005 | FlagWithInput("-i ", inputJar). |
| 2006 | FlagWithOutput("-o ", temporary). |
| 2007 | FlagWithArg("-0 ", "'classes*.dex'") |
| 2008 | |
| 2009 | // use zipalign to align uncompressed classes*.dex files |
| 2010 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2011 | BuiltTool("zipalign"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2012 | Flag("-f"). |
| 2013 | Text("4"). |
| 2014 | Input(temporary). |
| 2015 | Output(dexOutputFile) |
| 2016 | |
| 2017 | rule.DeleteTemporaryFiles() |
| 2018 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2019 | rule.Build("uncompress_dex", "uncompress dex") |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2020 | } else { |
| 2021 | ctx.Build(pctx, android.BuildParams{ |
| 2022 | Rule: android.Cp, |
| 2023 | Input: inputJar, |
| 2024 | Output: dexOutputFile, |
| 2025 | }) |
| 2026 | } |
| 2027 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2028 | j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2029 | |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 2030 | j.dexpreopt(ctx, dexOutputFile) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2031 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2032 | if apexInfo.IsForPlatform() { |
Jiyong Park | 01bca75 | 2020-06-08 19:24:09 +0900 | [diff] [blame] | 2033 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 2034 | j.Stem()+".jar", dexOutputFile) |
| 2035 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2036 | } |
| 2037 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2038 | func (j *DexImport) DexJarBuildPath() OptionalDexJarPath { |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2039 | return j.dexJarFile |
| 2040 | } |
| 2041 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2042 | var _ android.ApexModule = (*DexImport)(nil) |
| 2043 | |
| 2044 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2045 | func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2046 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2047 | // we don't check prebuilt modules for sdk_version |
| 2048 | return nil |
| 2049 | } |
| 2050 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2051 | // dex_import imports a `.jar` file containing classes.dex files. |
| 2052 | // |
| 2053 | // A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed |
| 2054 | // to the device. |
| 2055 | func DexImportFactory() android.Module { |
| 2056 | module := &DexImport{} |
| 2057 | |
| 2058 | module.AddProperties(&module.properties) |
| 2059 | |
| 2060 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2061 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2062 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2063 | return module |
| 2064 | } |
| 2065 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2066 | // Defaults |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2067 | type Defaults struct { |
| 2068 | android.ModuleBase |
| 2069 | android.DefaultsModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2070 | android.ApexModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2073 | // java_defaults provides a set of properties that can be inherited by other java or android modules. |
| 2074 | // |
| 2075 | // A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each |
| 2076 | // property in the defaults module that exists in the depending module will be prepended to the depending module's |
| 2077 | // value for that property. |
| 2078 | // |
| 2079 | // Example: |
| 2080 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2081 | // java_defaults { |
| 2082 | // name: "example_defaults", |
| 2083 | // srcs: ["common/**/*.java"], |
| 2084 | // javacflags: ["-Xlint:all"], |
| 2085 | // aaptflags: ["--auto-add-overlay"], |
| 2086 | // } |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2087 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2088 | // java_library { |
| 2089 | // name: "example", |
| 2090 | // defaults: ["example_defaults"], |
| 2091 | // srcs: ["example/**/*.java"], |
| 2092 | // } |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2093 | // |
| 2094 | // is functionally identical to: |
| 2095 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2096 | // java_library { |
| 2097 | // name: "example", |
| 2098 | // srcs: [ |
| 2099 | // "common/**/*.java", |
| 2100 | // "example/**/*.java", |
| 2101 | // ], |
| 2102 | // javacflags: ["-Xlint:all"], |
| 2103 | // } |
Paul Duffin | 4735766 | 2019-12-05 14:07:14 +0000 | [diff] [blame] | 2104 | func DefaultsFactory() android.Module { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2105 | module := &Defaults{} |
| 2106 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2107 | module.AddProperties( |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 2108 | &CommonProperties{}, |
| 2109 | &DeviceProperties{}, |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 2110 | &OverridableDeviceProperties{}, |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 2111 | &DexProperties{}, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 2112 | &DexpreoptProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 2113 | &android.ProtoProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2114 | &aaptProperties{}, |
| 2115 | &androidLibraryProperties{}, |
| 2116 | &appProperties{}, |
| 2117 | &appTestProperties{}, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2118 | &overridableAppProperties{}, |
Roland Levillain | b5b0ff3 | 2020-02-04 15:45:49 +0000 | [diff] [blame] | 2119 | &testProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2120 | &ImportProperties{}, |
| 2121 | &AARImportProperties{}, |
| 2122 | &sdkLibraryProperties{}, |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2123 | &commonToSdkLibraryAndImportProperties{}, |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2124 | &DexImportProperties{}, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2125 | &android.ApexProperties{}, |
Jaewoong Jung | bf13546 | 2020-04-26 15:10:51 -0700 | [diff] [blame] | 2126 | &RuntimeResourceOverlayProperties{}, |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 2127 | &LintProperties{}, |
Colin Cross | cbce0b0 | 2021-02-09 10:38:30 -0800 | [diff] [blame] | 2128 | &appTestHelperAppProperties{}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2129 | ) |
| 2130 | |
| 2131 | android.InitDefaultsModule(module) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2132 | return module |
| 2133 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2134 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2135 | func kytheExtractJavaFactory() android.Singleton { |
| 2136 | return &kytheExtractJavaSingleton{} |
| 2137 | } |
| 2138 | |
| 2139 | type kytheExtractJavaSingleton struct { |
| 2140 | } |
| 2141 | |
| 2142 | func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 2143 | var xrefTargets android.Paths |
| 2144 | ctx.VisitAllModules(func(module android.Module) { |
| 2145 | if javaModule, ok := module.(xref); ok { |
| 2146 | xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) |
| 2147 | } |
| 2148 | }) |
| 2149 | // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets |
| 2150 | if len(xrefTargets) > 0 { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 2151 | ctx.Phony("xref_java", xrefTargets...) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2152 | } |
| 2153 | } |
| 2154 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2155 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2156 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2157 | var String = proptools.String |
Colin Cross | 0d0ba59 | 2018-02-20 13:33:42 -0800 | [diff] [blame] | 2158 | var inList = android.InList |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2159 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2160 | // Add class loader context (CLC) of a given dependency to the current CLC. |
| 2161 | func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, |
| 2162 | clcMap dexpreopt.ClassLoaderContextMap) { |
| 2163 | |
| 2164 | dep, ok := depModule.(UsesLibraryDependency) |
| 2165 | if !ok { |
| 2166 | return |
| 2167 | } |
| 2168 | |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2169 | depName := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(depModule)) |
| 2170 | |
| 2171 | var sdkLib *string |
| 2172 | if lib, ok := depModule.(SdkLibraryDependency); ok && lib.sharedLibrary() { |
| 2173 | // A shared SDK library. This should be added as a top-level CLC element. |
| 2174 | sdkLib = &depName |
| 2175 | } else if ulib, ok := depModule.(ProvidesUsesLib); ok { |
| 2176 | // A non-SDK library disguised as an SDK library by the means of `provides_uses_lib` |
| 2177 | // property. This should be handled in the same way as a shared SDK library. |
| 2178 | sdkLib = ulib.ProvidesUsesLib() |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2179 | } |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2180 | |
| 2181 | depTag := ctx.OtherModuleDependencyTag(depModule) |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame^] | 2182 | if IsLibDepTag(depTag) { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2183 | // Ok, propagate <uses-library> through non-static library dependencies. |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 2184 | } else if tag, ok := depTag.(usesLibraryDependencyTag); ok && tag.sdkVersion == dexpreopt.AnySdkVersion { |
| 2185 | // Ok, propagate <uses-library> through non-compatibility <uses-library> dependencies. |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2186 | } else if depTag == staticLibTag { |
| 2187 | // Propagate <uses-library> through static library dependencies, unless it is a component |
| 2188 | // library (such as stubs). Component libraries have a dependency on their SDK library, |
| 2189 | // which should not be pulled just because of a static component library. |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2190 | if sdkLib != nil { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2191 | return |
| 2192 | } |
| 2193 | } else { |
| 2194 | // Don't propagate <uses-library> for other dependency tags. |
| 2195 | return |
| 2196 | } |
| 2197 | |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2198 | // If this is an SDK (or SDK-like) library, then it should be added as a node in the CLC tree, |
| 2199 | // and its CLC should be added as subtree of that node. Otherwise the library is not a |
| 2200 | // <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies |
| 2201 | // from its CLC should be added to the current CLC. |
| 2202 | if sdkLib != nil { |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 2203 | clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false, |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2204 | dep.DexJarBuildPath().PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts()) |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2205 | } else { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2206 | clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) |
| 2207 | } |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2208 | } |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2209 | |
Sam Delmerico | 7998581 | 2022-03-23 20:20:42 +0000 | [diff] [blame] | 2210 | type javaResourcesAttributes struct { |
| 2211 | Resources bazel.LabelListAttribute |
| 2212 | Resource_strip_prefix *string |
| 2213 | } |
| 2214 | |
| 2215 | func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorContext) *javaResourcesAttributes { |
| 2216 | var resources bazel.LabelList |
| 2217 | var resourceStripPrefix *string |
| 2218 | |
| 2219 | if m.properties.Java_resources != nil { |
| 2220 | resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources)) |
| 2221 | } |
| 2222 | |
| 2223 | //TODO(b/179889880) handle case where glob includes files outside package |
| 2224 | resDeps := ResourceDirsToFiles( |
| 2225 | ctx, |
| 2226 | m.properties.Java_resource_dirs, |
| 2227 | m.properties.Exclude_java_resource_dirs, |
| 2228 | m.properties.Exclude_java_resources, |
| 2229 | ) |
| 2230 | |
| 2231 | for i, resDep := range resDeps { |
| 2232 | dir, files := resDep.dir, resDep.files |
| 2233 | |
| 2234 | resources.Append(bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, files))) |
| 2235 | |
| 2236 | // Bazel includes the relative path from the WORKSPACE root when placing the resource |
| 2237 | // inside the JAR file, so we need to remove that prefix |
| 2238 | resourceStripPrefix = proptools.StringPtr(dir.String()) |
| 2239 | if i > 0 { |
| 2240 | // TODO(b/226423379) allow multiple resource prefixes |
| 2241 | ctx.ModuleErrorf("bp2build does not support more than one directory in java_resource_dirs (b/226423379)") |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | return &javaResourcesAttributes{ |
| 2246 | Resources: bazel.MakeLabelListAttribute(resources), |
| 2247 | Resource_strip_prefix: resourceStripPrefix, |
| 2248 | } |
| 2249 | } |
| 2250 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2251 | type javaCommonAttributes struct { |
Sam Delmerico | 7998581 | 2022-03-23 20:20:42 +0000 | [diff] [blame] | 2252 | *javaResourcesAttributes |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2253 | Srcs bazel.LabelListAttribute |
Sam Delmerico | 77267c7 | 2022-03-18 14:11:07 +0000 | [diff] [blame] | 2254 | Plugins bazel.LabelListAttribute |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2255 | Javacopts bazel.StringListAttribute |
| 2256 | } |
| 2257 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2258 | type javaDependencyLabels struct { |
| 2259 | // Dependencies which DO NOT contribute to the API visible to upstream dependencies. |
| 2260 | Deps bazel.LabelListAttribute |
| 2261 | // Dependencies which DO contribute to the API visible to upstream dependencies. |
| 2262 | StaticDeps bazel.LabelListAttribute |
| 2263 | } |
| 2264 | |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2265 | type eventLogTagsAttributes struct { |
| 2266 | Srcs bazel.LabelListAttribute |
| 2267 | } |
| 2268 | |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2269 | type aidlLibraryAttributes struct { |
| 2270 | Srcs bazel.LabelListAttribute |
| 2271 | } |
| 2272 | |
| 2273 | type javaAidlLibraryAttributes struct { |
| 2274 | Deps bazel.LabelListAttribute |
| 2275 | } |
| 2276 | |
| 2277 | // convertLibraryAttrsBp2Build converts a few shared attributes from java_* modules |
| 2278 | // and also separates dependencies into dynamic dependencies and static dependencies. |
| 2279 | // Each corresponding Bazel target type, can have a different method for handling |
| 2280 | // dynamic vs. static dependencies, and so these are returned to the calling function. |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2281 | func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *javaDependencyLabels) { |
Sam Delmerico | e91d030 | 2022-02-23 15:28:33 +0000 | [diff] [blame] | 2282 | var srcs bazel.LabelListAttribute |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2283 | var deps bazel.LabelList |
| 2284 | var staticDeps bazel.LabelList |
| 2285 | |
Sam Delmerico | e91d030 | 2022-02-23 15:28:33 +0000 | [diff] [blame] | 2286 | archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{}) |
| 2287 | for axis, configToProps := range archVariantProps { |
| 2288 | for config, _props := range configToProps { |
| 2289 | if archProps, ok := _props.(*CommonProperties); ok { |
| 2290 | archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs) |
| 2291 | srcs.SetSelectValue(axis, config, archSrcs) |
| 2292 | } |
| 2293 | } |
| 2294 | } |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 2295 | |
| 2296 | javaSrcPartition := "java" |
| 2297 | protoSrcPartition := "proto" |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2298 | logtagSrcPartition := "logtag" |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2299 | aidlSrcPartition := "aidl" |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 2300 | srcPartitions := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{ |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2301 | javaSrcPartition: bazel.LabelPartition{Extensions: []string{".java"}, Keep_remainder: true}, |
| 2302 | logtagSrcPartition: bazel.LabelPartition{Extensions: []string{".logtags", ".logtag"}}, |
| 2303 | protoSrcPartition: android.ProtoSrcLabelPartition, |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2304 | aidlSrcPartition: android.AidlSrcLabelPartition, |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 2305 | }) |
| 2306 | |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2307 | javaSrcs := srcPartitions[javaSrcPartition] |
| 2308 | |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2309 | if !srcPartitions[logtagSrcPartition].IsEmpty() { |
| 2310 | logtagsLibName := m.Name() + "_logtags" |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2311 | ctx.CreateBazelTargetModule( |
| 2312 | bazel.BazelTargetModuleProperties{ |
| 2313 | Rule_class: "event_log_tags", |
| 2314 | Bzl_load_location: "//build/make/tools:event_log_tags.bzl", |
| 2315 | }, |
| 2316 | android.CommonAttributes{Name: logtagsLibName}, |
| 2317 | &eventLogTagsAttributes{ |
| 2318 | Srcs: srcPartitions[logtagSrcPartition], |
| 2319 | }, |
| 2320 | ) |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2321 | |
| 2322 | logtagsSrcs := bazel.MakeLabelList([]bazel.Label{{Label: ":" + logtagsLibName}}) |
| 2323 | javaSrcs.Append(bazel.MakeLabelListAttribute(logtagsSrcs)) |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2324 | } |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2325 | |
| 2326 | if !srcPartitions[aidlSrcPartition].IsEmpty() { |
| 2327 | aidlLibs, aidlSrcs := srcPartitions[aidlSrcPartition].Partition(func(src bazel.Label) bool { |
| 2328 | return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName) |
| 2329 | }) |
| 2330 | |
| 2331 | if !aidlSrcs.IsEmpty() { |
| 2332 | aidlLibName := m.Name() + "_aidl_library" |
| 2333 | ctx.CreateBazelTargetModule( |
| 2334 | bazel.BazelTargetModuleProperties{ |
| 2335 | Rule_class: "aidl_library", |
| 2336 | Bzl_load_location: "//build/bazel/rules/aidl:library.bzl", |
| 2337 | }, |
| 2338 | android.CommonAttributes{Name: aidlLibName}, |
| 2339 | &aidlLibraryAttributes{ |
| 2340 | Srcs: aidlSrcs, |
| 2341 | }, |
| 2342 | ) |
| 2343 | aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) |
| 2344 | } |
| 2345 | |
| 2346 | javaAidlLibName := m.Name() + "_java_aidl_library" |
| 2347 | ctx.CreateBazelTargetModule( |
| 2348 | bazel.BazelTargetModuleProperties{ |
| 2349 | Rule_class: "java_aidl_library", |
| 2350 | Bzl_load_location: "//build/bazel/rules/java:aidl_library.bzl", |
| 2351 | }, |
| 2352 | android.CommonAttributes{Name: javaAidlLibName}, |
| 2353 | &javaAidlLibraryAttributes{ |
| 2354 | Deps: aidlLibs, |
| 2355 | }, |
| 2356 | ) |
| 2357 | |
| 2358 | staticDeps.Add(&bazel.Label{Label: ":" + javaAidlLibName}) |
| 2359 | } |
Sam Delmerico | 24da73c | 2022-03-16 20:36:54 +0000 | [diff] [blame] | 2360 | |
Sam Delmerico | 58614c0 | 2022-03-15 21:02:09 +0000 | [diff] [blame] | 2361 | var javacopts []string |
| 2362 | if m.properties.Javacflags != nil { |
| 2363 | javacopts = append(javacopts, m.properties.Javacflags...) |
| 2364 | } |
Vinh Tran | 3ac6daf | 2022-04-22 19:09:58 -0400 | [diff] [blame] | 2365 | if m.properties.Java_version != nil { |
| 2366 | javaVersion := normalizeJavaVersion(ctx, *m.properties.Java_version).String() |
| 2367 | javacopts = append(javacopts, fmt.Sprintf("-source %s -target %s", javaVersion, javaVersion)) |
| 2368 | } |
| 2369 | |
Sam Delmerico | 58614c0 | 2022-03-15 21:02:09 +0000 | [diff] [blame] | 2370 | epEnabled := m.properties.Errorprone.Enabled |
| 2371 | //TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable |
| 2372 | if Bool(epEnabled) { |
| 2373 | javacopts = append(javacopts, m.properties.Errorprone.Javacflags...) |
| 2374 | } |
| 2375 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2376 | commonAttrs := &javaCommonAttributes{ |
Sam Delmerico | 7998581 | 2022-03-23 20:20:42 +0000 | [diff] [blame] | 2377 | Srcs: javaSrcs, |
| 2378 | javaResourcesAttributes: m.convertJavaResourcesAttributes(ctx), |
Sam Delmerico | 77267c7 | 2022-03-18 14:11:07 +0000 | [diff] [blame] | 2379 | Plugins: bazel.MakeLabelListAttribute( |
| 2380 | android.BazelLabelForModuleDeps(ctx, m.properties.Plugins), |
| 2381 | ), |
Sam Delmerico | 58614c0 | 2022-03-15 21:02:09 +0000 | [diff] [blame] | 2382 | Javacopts: bazel.MakeStringListAttribute(javacopts), |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | if m.properties.Libs != nil { |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 2386 | deps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Libs)))) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2387 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2388 | |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 2389 | if m.properties.Static_libs != nil { |
Romain Jobredeaux | c9b2bba | 2022-02-15 09:35:07 -0500 | [diff] [blame] | 2390 | staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs)))) |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 2391 | } |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 2392 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2393 | protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition]) |
| 2394 | // Soong does not differentiate between a java_library and the Bazel equivalent of |
| 2395 | // a java_proto_library + proto_library pair. Instead, in Soong proto sources are |
| 2396 | // listed directly in the srcs of a java_library, and the classes produced |
| 2397 | // by protoc are included directly in the resulting JAR. Thus upstream dependencies |
| 2398 | // that depend on a java_library with proto sources can link directly to the protobuf API, |
| 2399 | // and so this should be a static dependency. |
| 2400 | staticDeps.Add(protoDepLabel) |
Sam Delmerico | c768102 | 2022-02-04 21:01:20 +0000 | [diff] [blame] | 2401 | |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2402 | depLabels := &javaDependencyLabels{} |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2403 | depLabels.Deps = bazel.MakeLabelListAttribute(deps) |
| 2404 | depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps) |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 2405 | |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2406 | return commonAttrs, depLabels |
| 2407 | } |
| 2408 | |
| 2409 | type javaLibraryAttributes struct { |
| 2410 | *javaCommonAttributes |
| 2411 | Deps bazel.LabelListAttribute |
| 2412 | Exports bazel.LabelListAttribute |
Sam Delmerico | fde9fb5 | 2022-01-28 20:53:38 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2416 | commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx) |
| 2417 | |
| 2418 | deps := depLabels.Deps |
| 2419 | if !commonAttrs.Srcs.IsEmpty() { |
| 2420 | deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them |
| 2421 | |
| 2422 | sdkVersion := m.SdkVersion(ctx) |
| 2423 | if sdkVersion.Kind == android.SdkPublic && sdkVersion.ApiLevel == android.FutureApiLevel { |
| 2424 | // TODO(b/220869005) remove forced dependency on current public android.jar |
| 2425 | deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:public_current_android_sdk_java_import")) |
| 2426 | } |
Sam Delmerico | 97bd127 | 2022-08-25 14:45:31 -0400 | [diff] [blame] | 2427 | } else if !deps.IsEmpty() { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2428 | ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") |
| 2429 | } |
| 2430 | |
| 2431 | attrs := &javaLibraryAttributes{ |
| 2432 | javaCommonAttributes: commonAttrs, |
| 2433 | Deps: deps, |
| 2434 | Exports: depLabels.StaticDeps, |
| 2435 | } |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2436 | |
| 2437 | props := bazel.BazelTargetModuleProperties{ |
| 2438 | Rule_class: "java_library", |
| 2439 | Bzl_load_location: "//build/bazel/rules/java:library.bzl", |
| 2440 | } |
| 2441 | |
| 2442 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) |
| 2443 | } |
| 2444 | |
| 2445 | type javaBinaryHostAttributes struct { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2446 | *javaCommonAttributes |
| 2447 | Deps bazel.LabelListAttribute |
| 2448 | Runtime_deps bazel.LabelListAttribute |
| 2449 | Main_class string |
| 2450 | Jvm_flags bazel.StringListAttribute |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | // JavaBinaryHostBp2Build is for java_binary_host bp2build. |
| 2454 | func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) { |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2455 | commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx) |
| 2456 | |
| 2457 | deps := depLabels.Deps |
| 2458 | deps.Append(depLabels.StaticDeps) |
| 2459 | if m.binaryProperties.Jni_libs != nil { |
| 2460 | deps.Append(bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs))) |
| 2461 | } |
| 2462 | |
| 2463 | var runtimeDeps bazel.LabelListAttribute |
| 2464 | if commonAttrs.Srcs.IsEmpty() { |
| 2465 | // if there are no sources, then the dependencies can only be used at runtime |
| 2466 | runtimeDeps = deps |
| 2467 | deps = bazel.LabelListAttribute{} |
| 2468 | } |
| 2469 | |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2470 | mainClass := "" |
| 2471 | if m.binaryProperties.Main_class != nil { |
| 2472 | mainClass = *m.binaryProperties.Main_class |
| 2473 | } |
| 2474 | if m.properties.Manifest != nil { |
| 2475 | mainClassInManifest, err := android.GetMainClassInManifest(ctx.Config(), android.PathForModuleSrc(ctx, *m.properties.Manifest).String()) |
| 2476 | if err != nil { |
| 2477 | return |
| 2478 | } |
| 2479 | mainClass = mainClassInManifest |
| 2480 | } |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2481 | |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2482 | attrs := &javaBinaryHostAttributes{ |
Sam Delmerico | c016143 | 2022-02-25 21:34:51 +0000 | [diff] [blame] | 2483 | javaCommonAttributes: commonAttrs, |
| 2484 | Deps: deps, |
| 2485 | Runtime_deps: runtimeDeps, |
| 2486 | Main_class: mainClass, |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | // Attribute jvm_flags |
| 2490 | if m.binaryProperties.Jni_libs != nil { |
| 2491 | jniLibPackages := map[string]bool{} |
| 2492 | for _, jniLibLabel := range android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs).Includes { |
| 2493 | jniLibPackage := jniLibLabel.Label |
| 2494 | indexOfColon := strings.Index(jniLibLabel.Label, ":") |
| 2495 | if indexOfColon > 0 { |
| 2496 | // JNI lib from other package |
| 2497 | jniLibPackage = jniLibLabel.Label[2:indexOfColon] |
| 2498 | } else if indexOfColon == 0 { |
| 2499 | // JNI lib in the same package of java_binary |
| 2500 | packageOfCurrentModule := m.GetBazelLabel(ctx, m) |
| 2501 | jniLibPackage = packageOfCurrentModule[2:strings.Index(packageOfCurrentModule, ":")] |
| 2502 | } |
| 2503 | if _, inMap := jniLibPackages[jniLibPackage]; !inMap { |
| 2504 | jniLibPackages[jniLibPackage] = true |
| 2505 | } |
| 2506 | } |
| 2507 | jniLibPaths := []string{} |
| 2508 | for jniLibPackage, _ := range jniLibPackages { |
| 2509 | // See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH |
| 2510 | jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage) |
| 2511 | } |
| 2512 | attrs.Jvm_flags = bazel.MakeStringListAttribute([]string{"-Djava.library.path=" + strings.Join(jniLibPaths, ":")}) |
| 2513 | } |
| 2514 | |
| 2515 | props := bazel.BazelTargetModuleProperties{ |
| 2516 | Rule_class: "java_binary", |
| 2517 | } |
| 2518 | |
| 2519 | // Create the BazelTargetModule. |
| 2520 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) |
| 2521 | } |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 2522 | |
| 2523 | type bazelJavaImportAttributes struct { |
| 2524 | Jars bazel.LabelListAttribute |
| 2525 | } |
| 2526 | |
| 2527 | // java_import bp2Build converter. |
| 2528 | func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
Sam Delmerico | 4898316 | 2022-02-22 21:41:33 +0000 | [diff] [blame] | 2529 | var jars bazel.LabelListAttribute |
| 2530 | archVariantProps := i.GetArchVariantProperties(ctx, &ImportProperties{}) |
| 2531 | for axis, configToProps := range archVariantProps { |
| 2532 | for config, _props := range configToProps { |
| 2533 | if archProps, ok := _props.(*ImportProperties); ok { |
| 2534 | archJars := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Jars, []string(nil)) |
| 2535 | jars.SetSelectValue(axis, config, archJars) |
| 2536 | } |
| 2537 | } |
| 2538 | } |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 2539 | |
| 2540 | attrs := &bazelJavaImportAttributes{ |
| 2541 | Jars: jars, |
| 2542 | } |
| 2543 | props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"} |
| 2544 | |
| 2545 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs) |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2546 | } |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 2547 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2548 | var _ android.MixedBuildBuildable = (*Import)(nil) |
| 2549 | |
| 2550 | func (i *Import) getBazelModuleLabel(ctx android.BaseModuleContext) string { |
| 2551 | return android.RemoveOptionalPrebuiltPrefixFromBazelLabel(i.GetBazelLabel(ctx, i)) |
| 2552 | } |
| 2553 | |
| 2554 | func (i *Import) ProcessBazelQueryResponse(ctx android.ModuleContext) { |
| 2555 | i.commonBuildActions(ctx) |
| 2556 | |
| 2557 | bazelCtx := ctx.Config().BazelContext |
| 2558 | filePaths, err := bazelCtx.GetOutputFiles(i.getBazelModuleLabel(ctx), android.GetConfigKey(ctx)) |
| 2559 | if err != nil { |
| 2560 | ctx.ModuleErrorf(err.Error()) |
| 2561 | return |
| 2562 | } |
| 2563 | |
| 2564 | bazelJars := android.Paths{} |
| 2565 | for _, bazelOutputFile := range filePaths { |
| 2566 | bazelJars = append(bazelJars, android.PathForBazelOut(ctx, bazelOutputFile)) |
| 2567 | } |
| 2568 | |
| 2569 | jarName := android.RemoveOptionalPrebuiltPrefix(i.Name()) + ".jar" |
| 2570 | outputFile := android.PathForModuleOut(ctx, "bazelCombined", jarName) |
| 2571 | TransformJarsToJar(ctx, outputFile, "combine prebuilt jars", bazelJars, |
| 2572 | android.OptionalPath{}, // manifest |
| 2573 | false, // stripDirEntries |
| 2574 | []string{}, // filesToStrip |
| 2575 | []string{}, // dirsToStrip |
| 2576 | ) |
| 2577 | i.combinedClasspathFile = outputFile |
| 2578 | |
| 2579 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 2580 | HeaderJars: android.PathsIfNonNil(i.combinedClasspathFile), |
| 2581 | ImplementationAndResourcesJars: android.PathsIfNonNil(i.combinedClasspathFile), |
| 2582 | ImplementationJars: android.PathsIfNonNil(i.combinedClasspathFile), |
| 2583 | //TODO(b/240308299) include AIDL information from Bazel |
| 2584 | }) |
| 2585 | |
| 2586 | i.maybeInstall(ctx, jarName, outputFile) |
| 2587 | } |
| 2588 | |
| 2589 | func (i *Import) QueueBazelCall(ctx android.BaseModuleContext) { |
| 2590 | bazelCtx := ctx.Config().BazelContext |
| 2591 | bazelCtx.QueueBazelRequest(i.getBazelModuleLabel(ctx), cquery.GetOutputFiles, android.GetConfigKey(ctx)) |
| 2592 | } |
| 2593 | |
| 2594 | func (i *Import) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { |
| 2595 | return true |
Romain Jobredeaux | 428a366 | 2022-01-28 11:12:52 -0500 | [diff] [blame] | 2596 | } |