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