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