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