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