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