| 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) | 
| satayev | e9b63a8 | 2021-11-29 17:25:52 +0000 | [diff] [blame^] | 490 | j.maxSdkVersion = j.MaxSdkVersion(ctx) | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 491 |  | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 492 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) | 
|  | 493 | if !apexInfo.IsForPlatform() { | 
|  | 494 | j.hideApexVariantFromMake = true | 
|  | 495 | } | 
|  | 496 |  | 
| Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 497 | j.checkSdkVersions(ctx) | 
| Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 498 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 499 | j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 500 | if j.dexProperties.Uncompress_dex == nil { | 
| David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 501 | // 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] | 502 | j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) | 
| David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 503 | } | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 504 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 505 | j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) | 
| Jaewoong Jung | a24af3b | 2019-05-13 09:23:20 -0700 | [diff] [blame] | 506 | j.compile(ctx, nil) | 
| Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 507 |  | 
| bralee | 1fbf440 | 2020-05-21 10:11:59 +0800 | [diff] [blame] | 508 | // Collect the module directory for IDE info in java/jdeps.go. | 
|  | 509 | j.modulePaths = append(j.modulePaths, ctx.ModuleDir()) | 
|  | 510 |  | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 511 | exclusivelyForApex := !apexInfo.IsForPlatform() | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 512 | if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { | 
| Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 513 | var extraInstallDeps android.Paths | 
|  | 514 | if j.InstallMixin != nil { | 
|  | 515 | extraInstallDeps = j.InstallMixin(ctx, j.outputFile) | 
|  | 516 | } | 
| Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 517 | j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), | 
| Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 518 | j.Stem()+".jar", j.outputFile, extraInstallDeps...) | 
| Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 519 | } | 
| Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 520 | } | 
|  | 521 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 522 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 523 | j.deps(ctx) | 
|  | 524 | } | 
|  | 525 |  | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 526 | const ( | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 527 | aidlIncludeDir   = "aidl" | 
|  | 528 | javaDir          = "java" | 
|  | 529 | jarFileSuffix    = ".jar" | 
|  | 530 | testConfigSuffix = "-AndroidTest.xml" | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 531 | ) | 
|  | 532 |  | 
| Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 533 | // 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] | 534 | func sdkSnapshotFilePathForJar(osPrefix, name string) string { | 
|  | 535 | return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 536 | } | 
|  | 537 |  | 
| Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 538 | func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string { | 
|  | 539 | return filepath.Join(javaDir, osPrefix, name+suffix) | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 540 | } | 
|  | 541 |  | 
| Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 542 | type librarySdkMemberType struct { | 
| Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 543 | android.SdkMemberTypeBase | 
| Paul Duffin | f5c0a9c | 2020-02-28 14:39:53 +0000 | [diff] [blame] | 544 |  | 
|  | 545 | // Function to retrieve the appropriate output jar (implementation or header) from | 
|  | 546 | // the library. | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 547 | jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path | 
|  | 548 |  | 
|  | 549 | // Function to compute the snapshot relative path to which the named library's | 
|  | 550 | // jar should be copied. | 
|  | 551 | snapshotPathGetter func(osPrefix, name string) string | 
|  | 552 |  | 
|  | 553 | // True if only the jar should be copied to the snapshot, false if the jar plus any additional | 
|  | 554 | // files like aidl files should also be copied. | 
|  | 555 | onlyCopyJarToSnapshot bool | 
| Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 556 | } | 
|  | 557 |  | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 558 | const ( | 
|  | 559 | onlyCopyJarToSnapshot    = true | 
|  | 560 | copyEverythingToSnapshot = false | 
|  | 561 | ) | 
|  | 562 |  | 
| Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 563 | func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { | 
|  | 564 | mctx.AddVariationDependencies(nil, dependencyTag, names...) | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { | 
|  | 568 | _, ok := module.(*Library) | 
|  | 569 | return ok | 
|  | 570 | } | 
|  | 571 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 572 | func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { | 
|  | 573 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import") | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 574 | } | 
| Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 575 |  | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 576 | func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 577 | return &librarySdkMemberProperties{} | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 578 | } | 
|  | 579 |  | 
|  | 580 | type librarySdkMemberProperties struct { | 
|  | 581 | android.SdkMemberPropertiesBase | 
|  | 582 |  | 
| Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 583 | JarToExport     android.Path `android:"arch_variant"` | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 584 | AidlIncludeDirs android.Paths | 
| Paul Duffin | 7b3e10a | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 585 |  | 
|  | 586 | // The list of permitted packages that need to be passed to the prebuilts as they are used to | 
|  | 587 | // create the updatable-bcp-packages.txt file. | 
|  | 588 | PermittedPackages []string | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 589 | } | 
|  | 590 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 591 | func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { | 
| Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 592 | j := variant.(*Library) | 
|  | 593 |  | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 594 | p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j) | 
|  | 595 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 596 | p.AidlIncludeDirs = j.AidlIncludeDirs() | 
| Paul Duffin | 7b3e10a | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 597 |  | 
|  | 598 | p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars() | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 599 | } | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 600 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 601 | func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 602 | builder := ctx.SnapshotBuilder() | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 603 |  | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 604 | memberType := ctx.MemberType().(*librarySdkMemberType) | 
|  | 605 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 606 | exportedJar := p.JarToExport | 
|  | 607 | if exportedJar != nil { | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 608 | // Delegate the creation of the snapshot relative path to the member type. | 
|  | 609 | snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name()) | 
|  | 610 |  | 
|  | 611 | // Copy the exported jar to the snapshot. | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 612 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) | 
|  | 613 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 614 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) | 
|  | 615 | } | 
|  | 616 |  | 
| Paul Duffin | 7b3e10a | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 617 | if len(p.PermittedPackages) > 0 { | 
|  | 618 | propertySet.AddProperty("permitted_packages", p.PermittedPackages) | 
|  | 619 | } | 
|  | 620 |  | 
| Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 621 | // Do not copy anything else to the snapshot. | 
|  | 622 | if memberType.onlyCopyJarToSnapshot { | 
|  | 623 | return | 
|  | 624 | } | 
|  | 625 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 626 | aidlIncludeDirs := p.AidlIncludeDirs | 
|  | 627 | if len(aidlIncludeDirs) != 0 { | 
|  | 628 | sdkModuleContext := ctx.SdkModuleContext() | 
|  | 629 | for _, dir := range aidlIncludeDirs { | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 630 | // TODO(jiyong): copy parcelable declarations only | 
|  | 631 | aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) | 
|  | 632 | for _, file := range aidlFiles { | 
|  | 633 | builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) | 
|  | 634 | } | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 635 | } | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 636 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 637 | // TODO(b/151933053) - add aidl include dirs property | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 638 | } | 
| Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 639 | } | 
|  | 640 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 641 | // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. | 
|  | 642 | // | 
|  | 643 | // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were | 
|  | 644 | // compiled against the device bootclasspath.  This jar is not suitable for installing on a device, but can be used | 
|  | 645 | // as a `static_libs` dependency of another module. | 
|  | 646 | // | 
|  | 647 | // Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on | 
|  | 648 | // a device. | 
|  | 649 | // | 
|  | 650 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one | 
|  | 651 | // compiled against the host bootclasspath. | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 652 | func LibraryFactory() android.Module { | 
|  | 653 | module := &Library{} | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 654 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 655 | module.addHostAndDeviceProperties() | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 656 |  | 
| Paul Duffin | 3accbb5 | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 657 | module.initModuleAndImport(module) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 658 |  | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 659 | android.InitApexModule(module) | 
| Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 660 | android.InitSdkAwareModule(module) | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 661 | InitJavaModule(module, android.HostAndDeviceSupported) | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 662 | return module | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 663 | } | 
|  | 664 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 665 | // java_library_static is an obsolete alias for java_library. | 
|  | 666 | func LibraryStaticFactory() android.Module { | 
|  | 667 | return LibraryFactory() | 
|  | 668 | } | 
|  | 669 |  | 
|  | 670 | // java_library_host builds and links sources into a `.jar` file for the host. | 
|  | 671 | // | 
|  | 672 | // A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were | 
|  | 673 | // compiled against the host bootclasspath. | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 674 | func LibraryHostFactory() android.Module { | 
|  | 675 | module := &Library{} | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 676 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 677 | module.addHostProperties() | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 678 |  | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 679 | module.Module.properties.Installable = proptools.BoolPtr(true) | 
|  | 680 |  | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 681 | android.InitApexModule(module) | 
| Paul Duffin | b6b89a4 | 2021-05-06 16:33:43 +0100 | [diff] [blame] | 682 | android.InitSdkAwareModule(module) | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 683 | InitJavaModule(module, android.HostSupported) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 684 | return module | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 685 | } | 
|  | 686 |  | 
|  | 687 | // | 
| Colin Cross | b628ea5 | 2018-08-14 16:42:33 -0700 | [diff] [blame] | 688 | // Java Tests | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 689 | // | 
|  | 690 |  | 
| Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 691 | // Test option struct. | 
|  | 692 | type TestOptions struct { | 
|  | 693 | // a list of extra test configuration files that should be installed with the module. | 
|  | 694 | Extra_test_configs []string `android:"path,arch_variant"` | 
| Dan Shi | d79572f | 2020-11-13 14:33:46 -0800 | [diff] [blame] | 695 |  | 
|  | 696 | // If the test is a hostside(no device required) unittest that shall be run during presubmit check. | 
|  | 697 | Unit_test *bool | 
| Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 698 | } | 
|  | 699 |  | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 700 | type testProperties struct { | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 701 | // list of compatibility suites (for example "cts", "vts") that the module should be | 
|  | 702 | // installed into. | 
|  | 703 | Test_suites []string `android:"arch_variant"` | 
| Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 704 |  | 
|  | 705 | // the name of the test configuration (for example "AndroidTest.xml") that should be | 
|  | 706 | // installed with the module. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 707 | Test_config *string `android:"path,arch_variant"` | 
| Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 708 |  | 
| Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 709 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that | 
|  | 710 | // should be installed with the module. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 711 | Test_config_template *string `android:"path,arch_variant"` | 
| Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 712 |  | 
| Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 713 | // list of files or filegroup modules that provide data that should be installed alongside | 
|  | 714 | // the test | 
| Jiyong Park | 2b0e490 | 2021-02-16 06:52:39 +0900 | [diff] [blame] | 715 | Data []string `android:"path"` | 
| Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 716 |  | 
|  | 717 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml | 
|  | 718 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true | 
|  | 719 | // explicitly. | 
|  | 720 | Auto_gen_config *bool | 
| easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 721 |  | 
|  | 722 | // Add parameterized mainline modules to auto generated test config. The options will be | 
|  | 723 | // handled by TradeFed to do downloading and installing the specified modules on the device. | 
|  | 724 | Test_mainline_modules []string | 
| Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 725 |  | 
|  | 726 | // Test options. | 
|  | 727 | Test_options TestOptions | 
| Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 728 |  | 
|  | 729 | // Names of modules containing JNI libraries that should be installed alongside the test. | 
|  | 730 | Jni_libs []string | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 731 | } | 
|  | 732 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 733 | type hostTestProperties struct { | 
|  | 734 | // list of native binary modules that should be installed alongside the test | 
|  | 735 | Data_native_bins []string `android:"arch_variant"` | 
|  | 736 | } | 
|  | 737 |  | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 738 | type testHelperLibraryProperties struct { | 
|  | 739 | // list of compatibility suites (for example "cts", "vts") that the module should be | 
|  | 740 | // installed into. | 
|  | 741 | Test_suites []string `android:"arch_variant"` | 
|  | 742 | } | 
|  | 743 |  | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 744 | type prebuiltTestProperties struct { | 
|  | 745 | // list of compatibility suites (for example "cts", "vts") that the module should be | 
|  | 746 | // installed into. | 
|  | 747 | Test_suites []string `android:"arch_variant"` | 
|  | 748 |  | 
|  | 749 | // the name of the test configuration (for example "AndroidTest.xml") that should be | 
|  | 750 | // installed with the module. | 
|  | 751 | Test_config *string `android:"path,arch_variant"` | 
|  | 752 | } | 
|  | 753 |  | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 754 | type Test struct { | 
|  | 755 | Library | 
|  | 756 |  | 
|  | 757 | testProperties testProperties | 
| Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 758 |  | 
| Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 759 | testConfig       android.Path | 
|  | 760 | extraTestConfigs android.Paths | 
|  | 761 | data             android.Paths | 
| Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 762 | } | 
|  | 763 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 764 | type TestHost struct { | 
|  | 765 | Test | 
|  | 766 |  | 
|  | 767 | testHostProperties hostTestProperties | 
|  | 768 | } | 
|  | 769 |  | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 770 | type TestHelperLibrary struct { | 
|  | 771 | Library | 
|  | 772 |  | 
|  | 773 | testHelperLibraryProperties testHelperLibraryProperties | 
|  | 774 | } | 
|  | 775 |  | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 776 | type JavaTestImport struct { | 
|  | 777 | Import | 
|  | 778 |  | 
|  | 779 | prebuiltTestProperties prebuiltTestProperties | 
|  | 780 |  | 
|  | 781 | testConfig android.Path | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 782 | dexJarFile android.Path | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 783 | } | 
|  | 784 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 785 | func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 786 | if len(j.testHostProperties.Data_native_bins) > 0 { | 
|  | 787 | for _, target := range ctx.MultiTargets() { | 
|  | 788 | ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...) | 
|  | 789 | } | 
|  | 790 | } | 
|  | 791 |  | 
| Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 792 | if len(j.testProperties.Jni_libs) > 0 { | 
|  | 793 | for _, target := range ctx.MultiTargets() { | 
|  | 794 | sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) | 
|  | 795 | ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) | 
|  | 796 | } | 
|  | 797 | } | 
|  | 798 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 799 | j.deps(ctx) | 
|  | 800 | } | 
|  | 801 |  | 
| Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 802 | func (j *TestHost) AddExtraResource(p android.Path) { | 
|  | 803 | j.extraResources = append(j.extraResources, p) | 
|  | 804 | } | 
|  | 805 |  | 
| Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 806 | func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 807 | if j.testProperties.Test_options.Unit_test == nil && ctx.Host() { | 
|  | 808 | // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding. | 
| Julien Desprez | f666b15 | 2021-03-15 13:07:53 -0700 | [diff] [blame] | 809 | defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites) | 
| Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 810 | j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest) | 
|  | 811 | } | 
| Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 812 | 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] | 813 | 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] | 814 |  | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 815 | j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) | 
| Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 816 |  | 
| Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 817 | j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs) | 
|  | 818 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 819 | ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) { | 
|  | 820 | j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) | 
|  | 821 | }) | 
|  | 822 |  | 
| Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 823 | ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { | 
|  | 824 | sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) | 
|  | 825 | if sharedLibInfo.SharedLibrary != nil { | 
|  | 826 | // Copy to an intermediate output directory to append "lib[64]" to the path, | 
|  | 827 | // so that it's compatible with the default rpath values. | 
|  | 828 | var relPath string | 
|  | 829 | if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { | 
|  | 830 | relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) | 
|  | 831 | } else { | 
|  | 832 | relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) | 
|  | 833 | } | 
|  | 834 | relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) | 
|  | 835 | ctx.Build(pctx, android.BuildParams{ | 
|  | 836 | Rule:   android.Cp, | 
|  | 837 | Input:  sharedLibInfo.SharedLibrary, | 
|  | 838 | Output: relocatedLib, | 
|  | 839 | }) | 
|  | 840 | j.data = append(j.data, relocatedLib) | 
|  | 841 | } else { | 
|  | 842 | ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) | 
|  | 843 | } | 
|  | 844 | }) | 
|  | 845 |  | 
| Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 846 | j.Library.GenerateAndroidBuildActions(ctx) | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 847 | } | 
|  | 848 |  | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 849 | func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 850 | j.Library.GenerateAndroidBuildActions(ctx) | 
|  | 851 | } | 
|  | 852 |  | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 853 | func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 854 | j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil, | 
| Julien Desprez | 70898c4 | 2020-11-19 09:43:45 -0800 | [diff] [blame] | 855 | j.prebuiltTestProperties.Test_suites, nil, nil) | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 856 |  | 
|  | 857 | j.Import.GenerateAndroidBuildActions(ctx) | 
|  | 858 | } | 
|  | 859 |  | 
|  | 860 | type testSdkMemberType struct { | 
|  | 861 | android.SdkMemberTypeBase | 
|  | 862 | } | 
|  | 863 |  | 
|  | 864 | func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { | 
|  | 865 | mctx.AddVariationDependencies(nil, dependencyTag, names...) | 
|  | 866 | } | 
|  | 867 |  | 
|  | 868 | func (mt *testSdkMemberType) IsInstance(module android.Module) bool { | 
|  | 869 | _, ok := module.(*Test) | 
|  | 870 | return ok | 
|  | 871 | } | 
|  | 872 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 873 | func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { | 
|  | 874 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import") | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 875 | } | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 876 |  | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 877 | func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { | 
|  | 878 | return &testSdkMemberProperties{} | 
|  | 879 | } | 
|  | 880 |  | 
|  | 881 | type testSdkMemberProperties struct { | 
|  | 882 | android.SdkMemberPropertiesBase | 
|  | 883 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 884 | JarToExport android.Path | 
|  | 885 | TestConfig  android.Path | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 886 | } | 
|  | 887 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 888 | func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 889 | test := variant.(*Test) | 
|  | 890 |  | 
|  | 891 | implementationJars := test.ImplementationJars() | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 892 | if len(implementationJars) != 1 { | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 893 | 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] | 894 | } | 
|  | 895 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 896 | p.JarToExport = implementationJars[0] | 
|  | 897 | p.TestConfig = test.testConfig | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 898 | } | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 899 |  | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 900 | func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 901 | builder := ctx.SnapshotBuilder() | 
| Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 902 |  | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 903 | exportedJar := p.JarToExport | 
|  | 904 | if exportedJar != nil { | 
|  | 905 | snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name()) | 
|  | 906 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 907 |  | 
|  | 908 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) | 
| Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 909 | } | 
|  | 910 |  | 
|  | 911 | testConfig := p.TestConfig | 
|  | 912 | if testConfig != nil { | 
|  | 913 | snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix) | 
|  | 914 | builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath) | 
| Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 915 | propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath) | 
|  | 916 | } | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 917 | } | 
|  | 918 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 919 | // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and | 
|  | 920 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. | 
|  | 921 | // | 
|  | 922 | // By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were | 
|  | 923 | // compiled against the device bootclasspath. | 
|  | 924 | // | 
|  | 925 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one | 
|  | 926 | // compiled against the host bootclasspath. | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 927 | func TestFactory() android.Module { | 
|  | 928 | module := &Test{} | 
|  | 929 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 930 | module.addHostAndDeviceProperties() | 
|  | 931 | module.AddProperties(&module.testProperties) | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 932 |  | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 933 | module.Module.properties.Installable = proptools.BoolPtr(true) | 
| Colin Cross | e302687 | 2019-01-05 22:30:13 -0800 | [diff] [blame] | 934 | module.Module.dexpreopter.isTest = true | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 935 | module.Module.linter.test = true | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 936 |  | 
| Paul Duffin | b6b89a4 | 2021-05-06 16:33:43 +0100 | [diff] [blame] | 937 | android.InitSdkAwareModule(module) | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 938 | InitJavaModule(module, android.HostAndDeviceSupported) | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 939 | return module | 
|  | 940 | } | 
|  | 941 |  | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 942 | // java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite. | 
|  | 943 | func TestHelperLibraryFactory() android.Module { | 
|  | 944 | module := &TestHelperLibrary{} | 
|  | 945 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 946 | module.addHostAndDeviceProperties() | 
|  | 947 | module.AddProperties(&module.testHelperLibraryProperties) | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 948 |  | 
| Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 949 | module.Module.properties.Installable = proptools.BoolPtr(true) | 
|  | 950 | module.Module.dexpreopter.isTest = true | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 951 | module.Module.linter.test = true | 
| Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 952 |  | 
| Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 953 | InitJavaModule(module, android.HostAndDeviceSupported) | 
|  | 954 | return module | 
|  | 955 | } | 
|  | 956 |  | 
| Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 957 | // java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module | 
|  | 958 | // and makes sure that it is added to the appropriate test suite. | 
|  | 959 | // | 
|  | 960 | // By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were | 
|  | 961 | // compiled against an Android classpath. | 
|  | 962 | // | 
|  | 963 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one | 
|  | 964 | // for host modules. | 
|  | 965 | func JavaTestImportFactory() android.Module { | 
|  | 966 | module := &JavaTestImport{} | 
|  | 967 |  | 
|  | 968 | module.AddProperties( | 
|  | 969 | &module.Import.properties, | 
|  | 970 | &module.prebuiltTestProperties) | 
|  | 971 |  | 
|  | 972 | module.Import.properties.Installable = proptools.BoolPtr(true) | 
|  | 973 |  | 
|  | 974 | android.InitPrebuiltModule(module, &module.properties.Jars) | 
|  | 975 | android.InitApexModule(module) | 
|  | 976 | android.InitSdkAwareModule(module) | 
|  | 977 | InitJavaModule(module, android.HostAndDeviceSupported) | 
|  | 978 | return module | 
|  | 979 | } | 
|  | 980 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 981 | // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to | 
|  | 982 | // allow running the test with `atest` or a `TEST_MAPPING` file. | 
|  | 983 | // | 
|  | 984 | // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were | 
|  | 985 | // compiled against the host bootclasspath. | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 986 | func TestHostFactory() android.Module { | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 987 | module := &TestHost{} | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 988 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 989 | module.addHostProperties() | 
|  | 990 | module.AddProperties(&module.testProperties) | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 991 | module.AddProperties(&module.testHostProperties) | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 992 |  | 
| Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 993 | InitTestHost( | 
|  | 994 | module, | 
|  | 995 | proptools.BoolPtr(true), | 
|  | 996 | nil, | 
|  | 997 | nil) | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 998 |  | 
| Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 999 | InitJavaModuleMultiTargets(module, android.HostSupported) | 
| Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1000 |  | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1001 | return module | 
|  | 1002 | } | 
|  | 1003 |  | 
| Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1004 | func InitTestHost(th *TestHost, installable *bool, testSuites []string, autoGenConfig *bool) { | 
|  | 1005 | th.properties.Installable = installable | 
|  | 1006 | th.testProperties.Auto_gen_config = autoGenConfig | 
|  | 1007 | th.testProperties.Test_suites = testSuites | 
|  | 1008 | } | 
|  | 1009 |  | 
| Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1010 | // | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1011 | // Java Binaries (.jar file plus wrapper script) | 
|  | 1012 | // | 
|  | 1013 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1014 | type binaryProperties struct { | 
| Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1015 | // installable script to execute the resulting jar | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 1016 | Wrapper *string `android:"path"` | 
| Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1017 |  | 
|  | 1018 | // Name of the class containing main to be inserted into the manifest as Main-Class. | 
|  | 1019 | Main_class *string | 
| Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 1020 |  | 
|  | 1021 | // Names of modules containing JNI libraries that should be installed alongside the host | 
|  | 1022 | // variant of the binary. | 
|  | 1023 | Jni_libs []string | 
| Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1024 | } | 
|  | 1025 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1026 | type Binary struct { | 
|  | 1027 | Library | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1028 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1029 | binaryProperties binaryProperties | 
| Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1030 |  | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1031 | isWrapperVariant bool | 
|  | 1032 |  | 
| Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1033 | wrapperFile android.Path | 
| Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 1034 | binaryFile  android.InstallPath | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1035 | } | 
|  | 1036 |  | 
| Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 1037 | func (j *Binary) HostToolPath() android.OptionalPath { | 
|  | 1038 | return android.OptionalPathForPath(j.binaryFile) | 
|  | 1039 | } | 
|  | 1040 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1041 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1042 | if ctx.Arch().ArchType == android.Common { | 
|  | 1043 | // Compile the jar | 
| Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1044 | if j.binaryProperties.Main_class != nil { | 
|  | 1045 | if j.properties.Manifest != nil { | 
|  | 1046 | ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") | 
|  | 1047 | } | 
|  | 1048 | manifestFile := android.PathForModuleOut(ctx, "manifest.txt") | 
|  | 1049 | GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) | 
|  | 1050 | j.overrideManifest = android.OptionalPathForPath(manifestFile) | 
|  | 1051 | } | 
|  | 1052 |  | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1053 | j.Library.GenerateAndroidBuildActions(ctx) | 
| Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1054 | } else { | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1055 | // Handle the binary wrapper | 
|  | 1056 | j.isWrapperVariant = true | 
|  | 1057 |  | 
| Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1058 | if j.binaryProperties.Wrapper != nil { | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1059 | j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1060 | } else { | 
|  | 1061 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") | 
|  | 1062 | } | 
|  | 1063 |  | 
| Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 1064 | // 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] | 1065 | // of the wrapper variant, which will include the common variant's jar file and any JNI | 
|  | 1066 | // libraries.  This is verified by TestBinary. | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1067 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), | 
| Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 1068 | ctx.ModuleName(), j.wrapperFile) | 
| Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1069 | } | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1070 | } | 
|  | 1071 |  | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1072 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1073 | if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() { | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1074 | j.deps(ctx) | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1075 | } | 
|  | 1076 | if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() { | 
| Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 1077 | // These dependencies ensure the host installation rules will install the jar file and | 
|  | 1078 | // the jni libraries when the wrapper is installed. | 
|  | 1079 | ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...) | 
|  | 1080 | ctx.AddVariationDependencies( | 
|  | 1081 | []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}}, | 
|  | 1082 | binaryInstallTag, ctx.ModuleName()) | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1083 | } | 
| Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1084 | } | 
|  | 1085 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1086 | // java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host | 
|  | 1087 | // as well. | 
|  | 1088 | // | 
|  | 1089 | // By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were | 
|  | 1090 | // compiled against the device bootclasspath. | 
|  | 1091 | // | 
|  | 1092 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one | 
|  | 1093 | // compiled against the host bootclasspath. | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1094 | func BinaryFactory() android.Module { | 
|  | 1095 | module := &Binary{} | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1096 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1097 | module.addHostAndDeviceProperties() | 
|  | 1098 | module.AddProperties(&module.binaryProperties) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1099 |  | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1100 | module.Module.properties.Installable = proptools.BoolPtr(true) | 
|  | 1101 |  | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1102 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) | 
|  | 1103 | android.InitDefaultableModule(module) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1104 | return module | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1105 | } | 
|  | 1106 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1107 | // java_binary_host builds a `.jar` file and a shell script that executes it for the host. | 
|  | 1108 | // | 
|  | 1109 | // A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were | 
|  | 1110 | // compiled against the host bootclasspath. | 
| Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1111 | func BinaryHostFactory() android.Module { | 
|  | 1112 | module := &Binary{} | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1113 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1114 | module.addHostProperties() | 
|  | 1115 | module.AddProperties(&module.binaryProperties) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1116 |  | 
| Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1117 | module.Module.properties.Installable = proptools.BoolPtr(true) | 
|  | 1118 |  | 
| Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1119 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) | 
|  | 1120 | android.InitDefaultableModule(module) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1121 | return module | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1122 | } | 
|  | 1123 |  | 
|  | 1124 | // | 
|  | 1125 | // Java prebuilts | 
|  | 1126 | // | 
|  | 1127 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1128 | type ImportProperties struct { | 
| Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 1129 | Jars []string `android:"path,arch_variant"` | 
| Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 1130 |  | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1131 | // The version of the SDK that the source prebuilt file was built against. Defaults to the | 
|  | 1132 | // current version if not specified. | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1133 | Sdk_version *string | 
| Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1134 |  | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1135 | // The minimum version of the SDK that this module supports. Defaults to sdk_version if not | 
|  | 1136 | // specified. | 
|  | 1137 | Min_sdk_version *string | 
|  | 1138 |  | 
| Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 1139 | Installable *bool | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1140 |  | 
| Paul Duffin | 7b3e10a | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 1141 | // If not empty, classes are restricted to the specified packages and their sub-packages. | 
|  | 1142 | // This information is used to generate the updatable-bcp-packages.txt file. | 
|  | 1143 | Permitted_packages []string | 
|  | 1144 |  | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1145 | // List of shared java libs that this module has dependencies to | 
|  | 1146 | Libs []string | 
| Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1147 |  | 
|  | 1148 | // List of files to remove from the jar file(s) | 
|  | 1149 | Exclude_files []string | 
|  | 1150 |  | 
|  | 1151 | // List of directories to remove from the jar file(s) | 
|  | 1152 | Exclude_dirs []string | 
| Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1153 |  | 
|  | 1154 | // if set to true, run Jetifier against .jar file. Defaults to false. | 
| Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1155 | Jetifier *bool | 
| Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 1156 |  | 
|  | 1157 | // set the name of the output | 
|  | 1158 | Stem *string | 
| Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1159 |  | 
|  | 1160 | Aidl struct { | 
|  | 1161 | // directories that should be added as include directories for any aidl sources of modules | 
|  | 1162 | // that depend on this module, as well as to aidl for this module. | 
|  | 1163 | Export_include_dirs []string | 
|  | 1164 | } | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1165 | } | 
|  | 1166 |  | 
|  | 1167 | type Import struct { | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1168 | android.ModuleBase | 
| Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1169 | android.DefaultableModuleBase | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1170 | android.ApexModuleBase | 
| Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1171 | prebuilt android.Prebuilt | 
| Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1172 | android.SdkBase | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1173 |  | 
| Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 1174 | // Functionality common to Module and Import. | 
|  | 1175 | embeddableInModuleAndImport | 
|  | 1176 |  | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1177 | hiddenAPI | 
|  | 1178 | dexer | 
| Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 1179 | dexpreopter | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1180 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1181 | properties ImportProperties | 
|  | 1182 |  | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1183 | // output file containing classes.dex and resources | 
|  | 1184 | dexJarFile android.Path | 
|  | 1185 |  | 
| Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 1186 | combinedClasspathFile android.Path | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1187 | classLoaderContexts   dexpreopt.ClassLoaderContextMap | 
| Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1188 | exportAidlIncludeDirs android.Paths | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1189 |  | 
|  | 1190 | hideApexVariantFromMake bool | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1191 |  | 
|  | 1192 | sdkVersion    android.SdkSpec | 
|  | 1193 | minSdkVersion android.SdkSpec | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1194 | } | 
|  | 1195 |  | 
| Paul Duffin | dbcc296 | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 1196 | var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil) | 
|  | 1197 |  | 
|  | 1198 | func (j *Import) PermittedPackagesForUpdatableBootJars() []string { | 
|  | 1199 | return j.properties.Permitted_packages | 
|  | 1200 | } | 
|  | 1201 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1202 | func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { | 
|  | 1203 | return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version)) | 
| Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 1204 | } | 
|  | 1205 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1206 | func (j *Import) SystemModules() string { | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1207 | return "none" | 
|  | 1208 | } | 
|  | 1209 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1210 | func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1211 | if j.properties.Min_sdk_version != nil { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1212 | return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version) | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1213 | } | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1214 | return j.SdkVersion(ctx) | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1215 | } | 
|  | 1216 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1217 | func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { | 
|  | 1218 | return j.SdkVersion(ctx) | 
| Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 1219 | } | 
|  | 1220 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1221 | func (j *Import) Prebuilt() *android.Prebuilt { | 
| Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 1222 | return &j.prebuilt | 
|  | 1223 | } | 
|  | 1224 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1225 | func (j *Import) PrebuiltSrcs() []string { | 
|  | 1226 | return j.properties.Jars | 
|  | 1227 | } | 
|  | 1228 |  | 
|  | 1229 | func (j *Import) Name() string { | 
| Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 1230 | return j.prebuilt.Name(j.ModuleBase.Name()) | 
|  | 1231 | } | 
|  | 1232 |  | 
| Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1233 | func (j *Import) Stem() string { | 
|  | 1234 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) | 
|  | 1235 | } | 
|  | 1236 |  | 
| Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1237 | func (a *Import) JacocoReportClassesFile() android.Path { | 
|  | 1238 | return nil | 
|  | 1239 | } | 
|  | 1240 |  | 
| Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 1241 | func (j *Import) LintDepSets() LintDepSets { | 
|  | 1242 | return LintDepSets{} | 
|  | 1243 | } | 
|  | 1244 |  | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 1245 | func (j *Import) getStrictUpdatabilityLinting() bool { | 
|  | 1246 | return false | 
|  | 1247 | } | 
|  | 1248 |  | 
|  | 1249 | func (j *Import) setStrictUpdatabilityLinting(bool) { | 
|  | 1250 | } | 
|  | 1251 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1252 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1253 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1254 |  | 
|  | 1255 | if ctx.Device() && Bool(j.dexProperties.Compile_dex) { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1256 | sdkDeps(ctx, android.SdkContext(j), j.dexer) | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1257 | } | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1258 | } | 
|  | 1259 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1260 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1261 | j.sdkVersion = j.SdkVersion(ctx) | 
|  | 1262 | j.minSdkVersion = j.MinSdkVersion(ctx) | 
|  | 1263 |  | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1264 | if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { | 
|  | 1265 | j.hideApexVariantFromMake = true | 
|  | 1266 | } | 
|  | 1267 |  | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1268 | jars := android.PathsForModuleSrc(ctx, j.properties.Jars) | 
| Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 1269 |  | 
| Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1270 | jarName := j.Stem() + ".jar" | 
| Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1271 | outputFile := android.PathForModuleOut(ctx, "combined", jarName) | 
| Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1272 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, | 
|  | 1273 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) | 
| Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1274 | if Bool(j.properties.Jetifier) { | 
| Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1275 | inputFile := outputFile | 
|  | 1276 | outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) | 
|  | 1277 | TransformJetifier(ctx, outputFile, inputFile) | 
|  | 1278 | } | 
| Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 1279 | j.combinedClasspathFile = outputFile | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1280 | j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1281 |  | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1282 | var flags javaBuilderFlags | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1283 | var deapexerModule android.Module | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1284 |  | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1285 | ctx.VisitDirectDeps(func(module android.Module) { | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1286 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 1287 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1288 | if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { | 
|  | 1289 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1290 | switch tag { | 
|  | 1291 | case libTag, staticLibTag: | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1292 | flags.classpath = append(flags.classpath, dep.HeaderJars...) | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1293 | case bootClasspathTag: | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1294 | flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...) | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1295 | } | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1296 | } else if dep, ok := module.(SdkLibraryDependency); ok { | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1297 | switch tag { | 
|  | 1298 | case libTag: | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1299 | flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...) | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1300 | } | 
|  | 1301 | } | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 1302 |  | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1303 | addCLCFromDep(ctx, module, j.classLoaderContexts) | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1304 |  | 
|  | 1305 | // Save away the `deapexer` module on which this depends, if any. | 
|  | 1306 | if tag == android.DeapexerTag { | 
| Martin Stjernholm | 9599406 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 1307 | if deapexerModule != nil { | 
|  | 1308 | ctx.ModuleErrorf("Ambiguous duplicate deapexer module dependencies %q and %q", | 
|  | 1309 | deapexerModule.Name(), module.Name()) | 
|  | 1310 | } | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1311 | deapexerModule = module | 
|  | 1312 | } | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1313 | }) | 
|  | 1314 |  | 
| Nan Zhang | 4973ecf | 2018-08-10 13:42:12 -0700 | [diff] [blame] | 1315 | if Bool(j.properties.Installable) { | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1316 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), | 
| Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 1317 | jarName, outputFile) | 
| Nan Zhang | 4973ecf | 2018-08-10 13:42:12 -0700 | [diff] [blame] | 1318 | } | 
| Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1319 |  | 
|  | 1320 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1321 |  | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1322 | if ctx.Device() { | 
|  | 1323 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar | 
|  | 1324 | // obtained from the associated deapexer module. | 
|  | 1325 | ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) | 
|  | 1326 | if ai.ForPrebuiltApex { | 
|  | 1327 | if deapexerModule == nil { | 
|  | 1328 | // 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] | 1329 | // 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] | 1330 | ctx.ModuleErrorf("internal error: module %q does not depend on a `deapexer` module for prebuilt_apex %q", | 
|  | 1331 | j.Name(), ai.ApexVariationName) | 
| Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 1332 | return | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1333 | } | 
|  | 1334 |  | 
|  | 1335 | // Get the path of the dex implementation jar from the `deapexer` module. | 
|  | 1336 | di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) | 
| Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1337 | if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil { | 
| Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 1338 | j.dexJarFile = dexOutputPath | 
| Paul Duffin | f88ab95 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 1339 |  | 
|  | 1340 | // Initialize the hiddenapi structure. | 
| Paul Duffin | 6c6dde0 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 1341 | j.initHiddenAPI(ctx, dexOutputPath, outputFile, nil) | 
| Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 1342 | } else { | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1343 | // This should never happen as a variant for a prebuilt_apex is only created if the | 
|  | 1344 | // prebuilt_apex has been configured to export the java library dex file. | 
|  | 1345 | ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name()) | 
|  | 1346 | } | 
|  | 1347 | } else if Bool(j.dexProperties.Compile_dex) { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1348 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1349 | if sdkDep.invalidVersion { | 
|  | 1350 | ctx.AddMissingDependencies(sdkDep.bootclasspath) | 
|  | 1351 | ctx.AddMissingDependencies(sdkDep.java9Classpath) | 
|  | 1352 | } else if sdkDep.useFiles { | 
|  | 1353 | // sdkDep.jar is actually equivalent to turbine header.jar. | 
|  | 1354 | flags.classpath = append(flags.classpath, sdkDep.jars...) | 
|  | 1355 | } | 
|  | 1356 |  | 
|  | 1357 | // Dex compilation | 
|  | 1358 |  | 
|  | 1359 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", jarName) | 
|  | 1360 | if j.dexProperties.Uncompress_dex == nil { | 
|  | 1361 | // If the value was not force-set by the user, use reasonable default based on the module. | 
|  | 1362 | j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter)) | 
|  | 1363 | } | 
|  | 1364 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex | 
|  | 1365 |  | 
| Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame] | 1366 | var dexOutputFile android.OutputPath | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1367 | dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName) | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1368 | if ctx.Failed() { | 
|  | 1369 | return | 
|  | 1370 | } | 
|  | 1371 |  | 
| Paul Duffin | f88ab95 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 1372 | // Initialize the hiddenapi structure. | 
| Paul Duffin | 6c6dde0 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 1373 | j.initHiddenAPI(ctx, dexOutputFile, outputFile, j.dexProperties.Uncompress_dex) | 
| Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 1374 |  | 
|  | 1375 | // Encode hidden API flags in dex file. | 
| Paul Duffin | 6c6dde0 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 1376 | dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile) | 
| Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 1377 |  | 
|  | 1378 | j.dexJarFile = dexOutputFile | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1379 | } | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1380 | } | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1381 |  | 
|  | 1382 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ | 
|  | 1383 | HeaderJars:                     android.PathsIfNonNil(j.combinedClasspathFile), | 
|  | 1384 | ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile), | 
|  | 1385 | ImplementationJars:             android.PathsIfNonNil(j.combinedClasspathFile), | 
|  | 1386 | AidlIncludeDirs:                j.exportAidlIncludeDirs, | 
|  | 1387 | }) | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1388 | } | 
|  | 1389 |  | 
| Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1390 | func (j *Import) OutputFiles(tag string) (android.Paths, error) { | 
|  | 1391 | switch tag { | 
| Saeid Farivar Asanjan | 128fe5c | 2020-10-15 17:54:40 +0000 | [diff] [blame] | 1392 | case "", ".jar": | 
| Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1393 | return android.Paths{j.combinedClasspathFile}, nil | 
|  | 1394 | default: | 
|  | 1395 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 1396 | } | 
|  | 1397 | } | 
|  | 1398 |  | 
|  | 1399 | var _ android.OutputFileProducer = (*Import)(nil) | 
|  | 1400 |  | 
| Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1401 | func (j *Import) HeaderJars() android.Paths { | 
| albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1402 | if j.combinedClasspathFile == nil { | 
|  | 1403 | return nil | 
|  | 1404 | } | 
| Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 1405 | return android.Paths{j.combinedClasspathFile} | 
| Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 1406 | } | 
|  | 1407 |  | 
| Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1408 | func (j *Import) ImplementationAndResourcesJars() android.Paths { | 
| albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1409 | if j.combinedClasspathFile == nil { | 
|  | 1410 | return nil | 
|  | 1411 | } | 
| Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1412 | return android.Paths{j.combinedClasspathFile} | 
|  | 1413 | } | 
|  | 1414 |  | 
| Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 1415 | func (j *Import) DexJarBuildPath() android.Path { | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1416 | return j.dexJarFile | 
| Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1417 | } | 
|  | 1418 |  | 
| Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 1419 | func (j *Import) DexJarInstallPath() android.Path { | 
|  | 1420 | return nil | 
|  | 1421 | } | 
|  | 1422 |  | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1423 | func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { | 
|  | 1424 | return j.classLoaderContexts | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1425 | } | 
|  | 1426 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1427 | var _ android.ApexModule = (*Import)(nil) | 
|  | 1428 |  | 
|  | 1429 | // Implements android.ApexModule | 
| Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1430 | func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { | 
| Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 1431 | return j.depIsInSameApex(ctx, dep) | 
| Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1432 | } | 
|  | 1433 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1434 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1435 | func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
|  | 1436 | sdkVersion android.ApiLevel) error { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1437 | sdkSpec := j.MinSdkVersion(ctx) | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1438 | if !sdkSpec.Specified() { | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1439 | return fmt.Errorf("min_sdk_version is not specified") | 
|  | 1440 | } | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1441 | if sdkSpec.Kind == android.SdkCore { | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1442 | return nil | 
|  | 1443 | } | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1444 | ver, err := sdkSpec.EffectiveVersion(ctx) | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1445 | if err != nil { | 
|  | 1446 | return err | 
|  | 1447 | } | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 1448 | if ver.GreaterThan(sdkVersion) { | 
| Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 1449 | return fmt.Errorf("newer SDK(%v)", ver) | 
|  | 1450 | } | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1451 | return nil | 
|  | 1452 | } | 
|  | 1453 |  | 
| Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1454 | // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or | 
|  | 1455 | // java_sdk_library_import with the specified base module name requires to be exported from a | 
|  | 1456 | // prebuilt_apex/apex_set. | 
| Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1457 | func requiredFilesFromPrebuiltApexForImport(name string) []string { | 
|  | 1458 | // Add the dex implementation jar to the set of exported files. | 
|  | 1459 | return []string{ | 
|  | 1460 | apexRootRelativePathToJavaLib(name), | 
| Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1461 | } | 
|  | 1462 | } | 
|  | 1463 |  | 
| Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1464 | // apexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for | 
|  | 1465 | // the java library with the specified name. | 
|  | 1466 | func apexRootRelativePathToJavaLib(name string) string { | 
|  | 1467 | return filepath.Join("javalib", name+".jar") | 
|  | 1468 | } | 
|  | 1469 |  | 
| Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1470 | var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil) | 
|  | 1471 |  | 
| Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 1472 | func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string { | 
| Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 1473 | name := j.BaseModuleName() | 
|  | 1474 | return requiredFilesFromPrebuiltApexForImport(name) | 
|  | 1475 | } | 
|  | 1476 |  | 
| albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 1477 | // Add compile time check for interface implementation | 
|  | 1478 | var _ android.IDEInfo = (*Import)(nil) | 
|  | 1479 | var _ android.IDECustomizedModuleName = (*Import)(nil) | 
|  | 1480 |  | 
| Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1481 | // Collect information for opening IDE project files in java/jdeps.go. | 
|  | 1482 | const ( | 
|  | 1483 | removedPrefix = "prebuilt_" | 
|  | 1484 | ) | 
|  | 1485 |  | 
|  | 1486 | func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { | 
|  | 1487 | dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) | 
|  | 1488 | } | 
|  | 1489 |  | 
|  | 1490 | func (j *Import) IDECustomizedModuleName() string { | 
|  | 1491 | // TODO(b/113562217): Extract the base module name from the Import name, often the Import name | 
|  | 1492 | // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better | 
|  | 1493 | // solution to get the Import name. | 
|  | 1494 | name := j.Name() | 
|  | 1495 | if strings.HasPrefix(name, removedPrefix) { | 
| patricktu | bb640e0 | 2018-10-11 18:33:16 +0800 | [diff] [blame] | 1496 | name = strings.TrimPrefix(name, removedPrefix) | 
| Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1497 | } | 
|  | 1498 | return name | 
|  | 1499 | } | 
|  | 1500 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1501 | var _ android.PrebuiltInterface = (*Import)(nil) | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1502 |  | 
| Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 1503 | func (j *Import) IsInstallable() bool { | 
|  | 1504 | return Bool(j.properties.Installable) | 
|  | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | var _ dexpreopterInterface = (*Import)(nil) | 
|  | 1508 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1509 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module. | 
|  | 1510 | // | 
|  | 1511 | // By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were | 
|  | 1512 | // compiled against an Android classpath. | 
|  | 1513 | // | 
|  | 1514 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one | 
|  | 1515 | // for host modules. | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1516 | func ImportFactory() android.Module { | 
|  | 1517 | module := &Import{} | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1518 |  | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1519 | module.AddProperties( | 
|  | 1520 | &module.properties, | 
|  | 1521 | &module.dexer.dexProperties, | 
|  | 1522 | ) | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1523 |  | 
| Paul Duffin | 3accbb5 | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1524 | module.initModuleAndImport(module) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1525 |  | 
| Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1526 | module.dexProperties.Optimize.EnabledByDefault = false | 
|  | 1527 |  | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1528 | android.InitPrebuiltModule(module, &module.properties.Jars) | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1529 | android.InitApexModule(module) | 
| Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1530 | android.InitSdkAwareModule(module) | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1531 | InitJavaModule(module, android.HostAndDeviceSupported) | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1532 | return module | 
| Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1533 | } | 
|  | 1534 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1535 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host | 
|  | 1536 | // module. | 
|  | 1537 | // | 
|  | 1538 | // A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were | 
|  | 1539 | // compiled against a host bootclasspath. | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1540 | func ImportFactoryHost() android.Module { | 
|  | 1541 | module := &Import{} | 
|  | 1542 |  | 
|  | 1543 | module.AddProperties(&module.properties) | 
|  | 1544 |  | 
|  | 1545 | android.InitPrebuiltModule(module, &module.properties.Jars) | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1546 | android.InitApexModule(module) | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1547 | InitJavaModule(module, android.HostSupported) | 
| Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 1548 | return module | 
|  | 1549 | } | 
|  | 1550 |  | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1551 | // dex_import module | 
|  | 1552 |  | 
|  | 1553 | type DexImportProperties struct { | 
| Colin Cross | 5cfc70d | 2019-07-15 13:36:55 -0700 | [diff] [blame] | 1554 | Jars []string `android:"path"` | 
| Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 1555 |  | 
|  | 1556 | // set the name of the output | 
|  | 1557 | Stem *string | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1558 | } | 
|  | 1559 |  | 
|  | 1560 | type DexImport struct { | 
|  | 1561 | android.ModuleBase | 
|  | 1562 | android.DefaultableModuleBase | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1563 | android.ApexModuleBase | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1564 | prebuilt android.Prebuilt | 
|  | 1565 |  | 
|  | 1566 | properties DexImportProperties | 
|  | 1567 |  | 
| Colin Cross | b014f07 | 2021-02-26 14:54:36 -0800 | [diff] [blame] | 1568 | dexJarFile android.Path | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1569 |  | 
|  | 1570 | dexpreopter | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1571 |  | 
|  | 1572 | hideApexVariantFromMake bool | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1573 | } | 
|  | 1574 |  | 
|  | 1575 | func (j *DexImport) Prebuilt() *android.Prebuilt { | 
|  | 1576 | return &j.prebuilt | 
|  | 1577 | } | 
|  | 1578 |  | 
|  | 1579 | func (j *DexImport) PrebuiltSrcs() []string { | 
|  | 1580 | return j.properties.Jars | 
|  | 1581 | } | 
|  | 1582 |  | 
|  | 1583 | func (j *DexImport) Name() string { | 
|  | 1584 | return j.prebuilt.Name(j.ModuleBase.Name()) | 
|  | 1585 | } | 
|  | 1586 |  | 
| Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1587 | func (j *DexImport) Stem() string { | 
|  | 1588 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) | 
|  | 1589 | } | 
|  | 1590 |  | 
| Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 1591 | func (a *DexImport) JacocoReportClassesFile() android.Path { | 
|  | 1592 | return nil | 
|  | 1593 | } | 
|  | 1594 |  | 
| Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 1595 | func (a *DexImport) LintDepSets() LintDepSets { | 
|  | 1596 | return LintDepSets{} | 
|  | 1597 | } | 
|  | 1598 |  | 
| Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 1599 | func (j *DexImport) IsInstallable() bool { | 
|  | 1600 | return true | 
|  | 1601 | } | 
|  | 1602 |  | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 1603 | func (j *DexImport) getStrictUpdatabilityLinting() bool { | 
|  | 1604 | return false | 
|  | 1605 | } | 
|  | 1606 |  | 
|  | 1607 | func (j *DexImport) setStrictUpdatabilityLinting(bool) { | 
|  | 1608 | } | 
|  | 1609 |  | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1610 | func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 1611 | if len(j.properties.Jars) != 1 { | 
|  | 1612 | ctx.PropertyErrorf("jars", "exactly one jar must be provided") | 
|  | 1613 | } | 
|  | 1614 |  | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1615 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) | 
|  | 1616 | if !apexInfo.IsForPlatform() { | 
|  | 1617 | j.hideApexVariantFromMake = true | 
|  | 1618 | } | 
|  | 1619 |  | 
| Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 1620 | j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1621 | j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) | 
|  | 1622 |  | 
|  | 1623 | inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") | 
|  | 1624 | dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") | 
|  | 1625 |  | 
|  | 1626 | if j.dexpreopter.uncompressedDex { | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1627 | rule := android.NewRuleBuilder(pctx, ctx) | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1628 |  | 
|  | 1629 | temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned") | 
|  | 1630 | rule.Temporary(temporary) | 
|  | 1631 |  | 
|  | 1632 | // use zip2zip to uncompress classes*.dex files | 
|  | 1633 | rule.Command(). | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1634 | BuiltTool("zip2zip"). | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1635 | FlagWithInput("-i ", inputJar). | 
|  | 1636 | FlagWithOutput("-o ", temporary). | 
|  | 1637 | FlagWithArg("-0 ", "'classes*.dex'") | 
|  | 1638 |  | 
|  | 1639 | // use zipalign to align uncompressed classes*.dex files | 
|  | 1640 | rule.Command(). | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1641 | BuiltTool("zipalign"). | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1642 | Flag("-f"). | 
|  | 1643 | Text("4"). | 
|  | 1644 | Input(temporary). | 
|  | 1645 | Output(dexOutputFile) | 
|  | 1646 |  | 
|  | 1647 | rule.DeleteTemporaryFiles() | 
|  | 1648 |  | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 1649 | rule.Build("uncompress_dex", "uncompress dex") | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1650 | } else { | 
|  | 1651 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1652 | Rule:   android.Cp, | 
|  | 1653 | Input:  inputJar, | 
|  | 1654 | Output: dexOutputFile, | 
|  | 1655 | }) | 
|  | 1656 | } | 
|  | 1657 |  | 
|  | 1658 | j.dexJarFile = dexOutputFile | 
|  | 1659 |  | 
| Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 1660 | j.dexpreopt(ctx, dexOutputFile) | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1661 |  | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1662 | if apexInfo.IsForPlatform() { | 
| Jiyong Park | 01bca75 | 2020-06-08 19:24:09 +0900 | [diff] [blame] | 1663 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), | 
|  | 1664 | j.Stem()+".jar", dexOutputFile) | 
|  | 1665 | } | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1666 | } | 
|  | 1667 |  | 
| Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 1668 | func (j *DexImport) DexJarBuildPath() android.Path { | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1669 | return j.dexJarFile | 
|  | 1670 | } | 
|  | 1671 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1672 | var _ android.ApexModule = (*DexImport)(nil) | 
|  | 1673 |  | 
|  | 1674 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1675 | func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
|  | 1676 | sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1677 | // we don't check prebuilt modules for sdk_version | 
|  | 1678 | return nil | 
|  | 1679 | } | 
|  | 1680 |  | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1681 | // dex_import imports a `.jar` file containing classes.dex files. | 
|  | 1682 | // | 
|  | 1683 | // A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed | 
|  | 1684 | // to the device. | 
|  | 1685 | func DexImportFactory() android.Module { | 
|  | 1686 | module := &DexImport{} | 
|  | 1687 |  | 
|  | 1688 | module.AddProperties(&module.properties) | 
|  | 1689 |  | 
|  | 1690 | android.InitPrebuiltModule(module, &module.properties.Jars) | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1691 | android.InitApexModule(module) | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1692 | InitJavaModule(module, android.DeviceSupported) | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1693 | return module | 
|  | 1694 | } | 
|  | 1695 |  | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1696 | // | 
|  | 1697 | // Defaults | 
|  | 1698 | // | 
|  | 1699 | type Defaults struct { | 
|  | 1700 | android.ModuleBase | 
|  | 1701 | android.DefaultsModuleBase | 
| Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 1702 | android.ApexModuleBase | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1703 | } | 
|  | 1704 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1705 | // java_defaults provides a set of properties that can be inherited by other java or android modules. | 
|  | 1706 | // | 
|  | 1707 | // A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`.  Each | 
|  | 1708 | // property in the defaults module that exists in the depending module will be prepended to the depending module's | 
|  | 1709 | // value for that property. | 
|  | 1710 | // | 
|  | 1711 | // Example: | 
|  | 1712 | // | 
|  | 1713 | //     java_defaults { | 
|  | 1714 | //         name: "example_defaults", | 
|  | 1715 | //         srcs: ["common/**/*.java"], | 
|  | 1716 | //         javacflags: ["-Xlint:all"], | 
|  | 1717 | //         aaptflags: ["--auto-add-overlay"], | 
|  | 1718 | //     } | 
|  | 1719 | // | 
|  | 1720 | //     java_library { | 
|  | 1721 | //         name: "example", | 
|  | 1722 | //         defaults: ["example_defaults"], | 
|  | 1723 | //         srcs: ["example/**/*.java"], | 
|  | 1724 | //     } | 
|  | 1725 | // | 
|  | 1726 | // is functionally identical to: | 
|  | 1727 | // | 
|  | 1728 | //     java_library { | 
|  | 1729 | //         name: "example", | 
|  | 1730 | //         srcs: [ | 
|  | 1731 | //             "common/**/*.java", | 
|  | 1732 | //             "example/**/*.java", | 
|  | 1733 | //         ], | 
|  | 1734 | //         javacflags: ["-Xlint:all"], | 
|  | 1735 | //     } | 
| Paul Duffin | 4735766 | 2019-12-05 14:07:14 +0000 | [diff] [blame] | 1736 | func DefaultsFactory() android.Module { | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1737 | module := &Defaults{} | 
|  | 1738 |  | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1739 | module.AddProperties( | 
| Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 1740 | &CommonProperties{}, | 
|  | 1741 | &DeviceProperties{}, | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1742 | &DexProperties{}, | 
| Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1743 | &DexpreoptProperties{}, | 
| Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 1744 | &android.ProtoProperties{}, | 
| Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1745 | &aaptProperties{}, | 
|  | 1746 | &androidLibraryProperties{}, | 
|  | 1747 | &appProperties{}, | 
|  | 1748 | &appTestProperties{}, | 
| Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 1749 | &overridableAppProperties{}, | 
| Roland Levillain | b5b0ff3 | 2020-02-04 15:45:49 +0000 | [diff] [blame] | 1750 | &testProperties{}, | 
| Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 1751 | &ImportProperties{}, | 
|  | 1752 | &AARImportProperties{}, | 
|  | 1753 | &sdkLibraryProperties{}, | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1754 | &commonToSdkLibraryAndImportProperties{}, | 
| Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 1755 | &DexImportProperties{}, | 
| Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1756 | &android.ApexProperties{}, | 
| Jaewoong Jung | bf13546 | 2020-04-26 15:10:51 -0700 | [diff] [blame] | 1757 | &RuntimeResourceOverlayProperties{}, | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 1758 | &LintProperties{}, | 
| Colin Cross | cbce0b0 | 2021-02-09 10:38:30 -0800 | [diff] [blame] | 1759 | &appTestHelperAppProperties{}, | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1760 | ) | 
|  | 1761 |  | 
|  | 1762 | android.InitDefaultsModule(module) | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1763 | return module | 
|  | 1764 | } | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1765 |  | 
| Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1766 | func kytheExtractJavaFactory() android.Singleton { | 
|  | 1767 | return &kytheExtractJavaSingleton{} | 
|  | 1768 | } | 
|  | 1769 |  | 
|  | 1770 | type kytheExtractJavaSingleton struct { | 
|  | 1771 | } | 
|  | 1772 |  | 
|  | 1773 | func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 1774 | var xrefTargets android.Paths | 
|  | 1775 | ctx.VisitAllModules(func(module android.Module) { | 
|  | 1776 | if javaModule, ok := module.(xref); ok { | 
|  | 1777 | xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) | 
|  | 1778 | } | 
|  | 1779 | }) | 
|  | 1780 | // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets | 
|  | 1781 | if len(xrefTargets) > 0 { | 
| Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 1782 | ctx.Phony("xref_java", xrefTargets...) | 
| Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1783 | } | 
|  | 1784 | } | 
|  | 1785 |  | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1786 | var Bool = proptools.Bool | 
| Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 1787 | var BoolDefault = proptools.BoolDefault | 
| Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 1788 | var String = proptools.String | 
| Colin Cross | 0d0ba59 | 2018-02-20 13:33:42 -0800 | [diff] [blame] | 1789 | var inList = android.InList | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 1790 |  | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1791 | // Add class loader context (CLC) of a given dependency to the current CLC. | 
|  | 1792 | func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, | 
|  | 1793 | clcMap dexpreopt.ClassLoaderContextMap) { | 
|  | 1794 |  | 
|  | 1795 | dep, ok := depModule.(UsesLibraryDependency) | 
|  | 1796 | if !ok { | 
|  | 1797 | return | 
|  | 1798 | } | 
|  | 1799 |  | 
|  | 1800 | // Find out if the dependency is either an SDK library or an ordinary library that is disguised | 
|  | 1801 | // as an SDK library by the means of `provides_uses_lib` property. If yes, the library is itself | 
|  | 1802 | // a <uses-library> and should be added as a node in the CLC tree, and its CLC should be added | 
|  | 1803 | // as subtree of that node. Otherwise the library is not a <uses_library> and should not be | 
|  | 1804 | // added to CLC, but the transitive <uses-library> dependencies from its CLC should be added to | 
|  | 1805 | // the current CLC. | 
|  | 1806 | var implicitSdkLib *string | 
|  | 1807 | comp, isComp := depModule.(SdkLibraryComponentDependency) | 
|  | 1808 | if isComp { | 
|  | 1809 | implicitSdkLib = comp.OptionalImplicitSdkLibrary() | 
|  | 1810 | // OptionalImplicitSdkLibrary() may be nil so need to fall through to ProvidesUsesLib(). | 
|  | 1811 | } | 
|  | 1812 | if implicitSdkLib == nil { | 
|  | 1813 | if ulib, ok := depModule.(ProvidesUsesLib); ok { | 
|  | 1814 | implicitSdkLib = ulib.ProvidesUsesLib() | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 1815 | } | 
|  | 1816 | } | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1817 |  | 
|  | 1818 | depTag := ctx.OtherModuleDependencyTag(depModule) | 
|  | 1819 | if depTag == libTag || depTag == usesLibTag { | 
|  | 1820 | // Ok, propagate <uses-library> through non-static library dependencies. | 
|  | 1821 | } else if depTag == staticLibTag { | 
|  | 1822 | // Propagate <uses-library> through static library dependencies, unless it is a component | 
|  | 1823 | // library (such as stubs). Component libraries have a dependency on their SDK library, | 
|  | 1824 | // which should not be pulled just because of a static component library. | 
|  | 1825 | if implicitSdkLib != nil { | 
|  | 1826 | return | 
|  | 1827 | } | 
|  | 1828 | } else { | 
|  | 1829 | // Don't propagate <uses-library> for other dependency tags. | 
|  | 1830 | return | 
|  | 1831 | } | 
|  | 1832 |  | 
|  | 1833 | if implicitSdkLib != nil { | 
| Ulya Trafimovich | 7bc1cf5 | 2021-01-05 15:41:55 +0000 | [diff] [blame] | 1834 | clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *implicitSdkLib, | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 1835 | dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts()) | 
|  | 1836 | } else { | 
|  | 1837 | depName := ctx.OtherModuleName(depModule) | 
|  | 1838 | clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) | 
|  | 1839 | } | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 1840 | } |