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