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" |
Alix | 289e9c6 | 2023-08-16 15:06:31 +0000 | [diff] [blame] | 24 | "sort" |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 25 | "strings" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 26 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 27 | "android/soong/remoteexec" |
Aditya Choudhary | 9b59352 | 2023-10-06 19:54:58 +0000 | [diff] [blame] | 28 | "android/soong/testing" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 31 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 32 | "android/soong/android" |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 33 | "android/soong/cc" |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 34 | "android/soong/dexpreopt" |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 35 | "android/soong/java/config" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 36 | "android/soong/tradefed" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 37 | ) |
| 38 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 39 | func init() { |
Paul Duffin | 535e0a1 | 2021-03-30 23:34:32 +0100 | [diff] [blame] | 40 | registerJavaBuildComponents(android.InitRegistrationContext) |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 41 | |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 42 | RegisterJavaSdkMemberTypes() |
| 43 | } |
| 44 | |
Paul Duffin | 535e0a1 | 2021-03-30 23:34:32 +0100 | [diff] [blame] | 45 | func registerJavaBuildComponents(ctx android.RegistrationContext) { |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 46 | ctx.RegisterModuleType("java_defaults", DefaultsFactory) |
| 47 | |
| 48 | ctx.RegisterModuleType("java_library", LibraryFactory) |
| 49 | ctx.RegisterModuleType("java_library_static", LibraryStaticFactory) |
| 50 | ctx.RegisterModuleType("java_library_host", LibraryHostFactory) |
| 51 | ctx.RegisterModuleType("java_binary", BinaryFactory) |
| 52 | ctx.RegisterModuleType("java_binary_host", BinaryHostFactory) |
| 53 | ctx.RegisterModuleType("java_test", TestFactory) |
| 54 | ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory) |
| 55 | ctx.RegisterModuleType("java_test_host", TestHostFactory) |
| 56 | ctx.RegisterModuleType("java_test_import", JavaTestImportFactory) |
| 57 | ctx.RegisterModuleType("java_import", ImportFactory) |
| 58 | ctx.RegisterModuleType("java_import_host", ImportFactoryHost) |
| 59 | ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) |
| 60 | ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) |
| 61 | ctx.RegisterModuleType("dex_import", DexImportFactory) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 62 | ctx.RegisterModuleType("java_api_library", ApiLibraryFactory) |
| 63 | ctx.RegisterModuleType("java_api_contribution", ApiContributionFactory) |
Jihoon Kang | fdf3236 | 2023-09-12 00:36:43 +0000 | [diff] [blame] | 64 | ctx.RegisterModuleType("java_api_contribution_import", ApiContributionImportFactory) |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 65 | |
Martin Stjernholm | 0e4cceb | 2021-05-13 02:38:35 +0100 | [diff] [blame] | 66 | // This mutator registers dependencies on dex2oat for modules that should be |
| 67 | // dexpreopted. This is done late when the final variants have been |
| 68 | // established, to not get the dependencies split into the wrong variants and |
| 69 | // to support the checks in dexpreoptDisabled(). |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 70 | ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 71 | ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel() |
Sam Delmerico | 1e3f78f | 2022-09-07 12:07:07 -0400 | [diff] [blame] | 72 | // needs access to ApexInfoProvider which is available after variant creation |
| 73 | ctx.BottomUp("jacoco_deps", jacocoDepsMutator).Parallel() |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 74 | }) |
| 75 | |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 76 | ctx.RegisterParallelSingletonType("logtags", LogtagsSingleton) |
| 77 | ctx.RegisterParallelSingletonType("kythe_java_extract", kytheExtractJavaFactory) |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | func RegisterJavaSdkMemberTypes() { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 81 | // Register sdk member types. |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 82 | android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 83 | android.RegisterSdkMemberType(javaLibsSdkMemberType) |
| 84 | android.RegisterSdkMemberType(javaBootLibsSdkMemberType) |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 85 | android.RegisterSdkMemberType(javaSystemserverLibsSdkMemberType) |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 86 | android.RegisterSdkMemberType(javaTestSdkMemberType) |
| 87 | } |
| 88 | |
| 89 | var ( |
| 90 | // Supports adding java header libraries to module_exports and sdk. |
| 91 | javaHeaderLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 92 | android.SdkMemberTypeBase{ |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 93 | PropertyName: "java_header_libs", |
| 94 | SupportsSdk: true, |
| 95 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 96 | func(_ android.SdkMemberContext, j *Library) android.Path { |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 97 | headerJars := j.HeaderJars() |
| 98 | if len(headerJars) != 1 { |
| 99 | panic(fmt.Errorf("there must be only one header jar from %q", j.Name())) |
| 100 | } |
| 101 | |
| 102 | return headerJars[0] |
| 103 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 104 | sdkSnapshotFilePathForJar, |
| 105 | copyEverythingToSnapshot, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 106 | } |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 107 | |
Paul Duffin | 22ff0aa | 2021-02-04 11:15:34 +0000 | [diff] [blame] | 108 | // Export implementation classes jar as part of the sdk. |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 109 | exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path { |
Paul Duffin | 22ff0aa | 2021-02-04 11:15:34 +0000 | [diff] [blame] | 110 | implementationJars := j.ImplementationAndResourcesJars() |
| 111 | if len(implementationJars) != 1 { |
| 112 | panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name())) |
| 113 | } |
| 114 | return implementationJars[0] |
| 115 | } |
| 116 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 117 | // Supports adding java implementation libraries to module_exports but not sdk. |
| 118 | javaLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 119 | android.SdkMemberTypeBase{ |
Paul Duffin | f5c0a9c | 2020-02-28 14:39:53 +0000 | [diff] [blame] | 120 | PropertyName: "java_libs", |
| 121 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 122 | exportImplementationClassesJar, |
| 123 | sdkSnapshotFilePathForJar, |
| 124 | copyEverythingToSnapshot, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 125 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 126 | |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 127 | snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool { |
| 128 | // In the S build the build will break if updatable-media does not provide a full implementation |
| 129 | // jar. That issue was fixed in Tiramisu by b/229932396. |
| 130 | if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" { |
| 131 | return true |
| 132 | } |
| 133 | |
| 134 | return false |
| 135 | } |
| 136 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 137 | // Supports adding java boot libraries to module_exports and sdk. |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 138 | // |
| 139 | // The build has some implicit dependencies (via the boot jars configuration) on a number of |
| 140 | // modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are |
| 141 | // provided by mainline modules (e.g. art, conscrypt, runtime-i18n) but which are not otherwise |
| 142 | // used outside those mainline modules. |
| 143 | // |
| 144 | // As they are not needed outside the mainline modules adding them to the sdk/module-exports as |
| 145 | // either java_libs, or java_header_libs would end up exporting more information than was strictly |
| 146 | // necessary. The java_boot_libs property to allow those modules to be exported as part of the |
| 147 | // sdk/module_exports without exposing any unnecessary information. |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 148 | javaBootLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 149 | android.SdkMemberTypeBase{ |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 150 | PropertyName: "java_boot_libs", |
| 151 | SupportsSdk: true, |
| 152 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 153 | func(ctx android.SdkMemberContext, j *Library) android.Path { |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 154 | if snapshotRequiresImplementationJar(ctx) { |
| 155 | return exportImplementationClassesJar(ctx, j) |
| 156 | } |
| 157 | |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 158 | // Java boot libs are only provided in the SDK to provide access to their dex implementation |
| 159 | // jar for use by dexpreopting and boot jars package check. They do not need to provide an |
| 160 | // actual implementation jar but the java_import will need a file that exists so just copy an |
| 161 | // empty file. Any attempt to use that file as a jar will cause a build error. |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 162 | return ctx.SnapshotBuilder().EmptyFile() |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 163 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 164 | func(ctx android.SdkMemberContext, osPrefix, name string) string { |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 165 | if snapshotRequiresImplementationJar(ctx) { |
| 166 | return sdkSnapshotFilePathForJar(ctx, osPrefix, name) |
| 167 | } |
| 168 | |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 169 | // Create a special name for the implementation jar to try and provide some useful information |
| 170 | // to a developer that attempts to compile against this. |
| 171 | // TODO(b/175714559): Provide a proper error message in Soong not ninja. |
| 172 | return filepath.Join(osPrefix, "java_boot_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix) |
| 173 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 174 | onlyCopyJarToSnapshot, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 175 | } |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 176 | |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 177 | // Supports adding java systemserver libraries to module_exports and sdk. |
| 178 | // |
| 179 | // The build has some implicit dependencies (via the systemserver jars configuration) on a number |
| 180 | // of modules that are part of the java systemserver classpath and which are provided by mainline |
| 181 | // modules but which are not otherwise used outside those mainline modules. |
| 182 | // |
| 183 | // As they are not needed outside the mainline modules adding them to the sdk/module-exports as |
| 184 | // either java_libs, or java_header_libs would end up exporting more information than was strictly |
| 185 | // necessary. The java_systemserver_libs property to allow those modules to be exported as part of |
| 186 | // the sdk/module_exports without exposing any unnecessary information. |
| 187 | javaSystemserverLibsSdkMemberType = &librarySdkMemberType{ |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 188 | android.SdkMemberTypeBase{ |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 189 | PropertyName: "java_systemserver_libs", |
| 190 | SupportsSdk: true, |
Paul Duffin | f861df7 | 2022-07-01 15:56:06 +0000 | [diff] [blame] | 191 | |
| 192 | // This was only added in Tiramisu. |
| 193 | SupportedBuildReleaseSpecification: "Tiramisu+", |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 194 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 195 | func(ctx android.SdkMemberContext, j *Library) android.Path { |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 196 | // Java systemserver libs are only provided in the SDK to provide access to their dex |
| 197 | // implementation jar for use by dexpreopting. They do not need to provide an actual |
| 198 | // implementation jar but the java_import will need a file that exists so just copy an empty |
| 199 | // file. Any attempt to use that file as a jar will cause a build error. |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 200 | return ctx.SnapshotBuilder().EmptyFile() |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 201 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 202 | func(_ android.SdkMemberContext, osPrefix, name string) string { |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 203 | // Create a special name for the implementation jar to try and provide some useful information |
| 204 | // to a developer that attempts to compile against this. |
| 205 | // TODO(b/175714559): Provide a proper error message in Soong not ninja. |
| 206 | return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix) |
| 207 | }, |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 208 | onlyCopyJarToSnapshot, |
Jiakai Zhang | ea18033 | 2021-09-26 08:58:02 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 211 | // Supports adding java test libraries to module_exports but not sdk. |
| 212 | javaTestSdkMemberType = &testSdkMemberType{ |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 213 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 214 | PropertyName: "java_tests", |
| 215 | }, |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 216 | } |
Zi Wang | ca65b40 | 2022-10-10 13:45:06 -0700 | [diff] [blame] | 217 | |
| 218 | // Rule for generating device binary default wrapper |
| 219 | deviceBinaryWrapper = pctx.StaticRule("deviceBinaryWrapper", blueprint.RuleParams{ |
| 220 | Command: `echo -e '#!/system/bin/sh\n` + |
| 221 | `export CLASSPATH=/system/framework/$jar_name\n` + |
| 222 | `exec app_process /$partition/bin $main_class "$$@"'> ${out}`, |
| 223 | Description: "Generating device binary wrapper ${jar_name}", |
| 224 | }, "jar_name", "partition", "main_class") |
Paul Duffin | 2da0424 | 2021-04-23 19:43:28 +0100 | [diff] [blame] | 225 | ) |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 226 | |
Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 227 | type ProguardSpecInfo struct { |
| 228 | // If true, proguard flags files will be exported to reverse dependencies across libs edges |
| 229 | // If false, proguard flags files will only be exported to reverse dependencies across |
| 230 | // static_libs edges. |
| 231 | Export_proguard_flags_files bool |
| 232 | |
| 233 | // TransitiveDepsProguardSpecFiles is a depset of paths to proguard flags files that are exported from |
| 234 | // all transitive deps. This list includes all proguard flags files from transitive static dependencies, |
| 235 | // and all proguard flags files from transitive libs dependencies which set `export_proguard_spec: true`. |
| 236 | ProguardFlagsFiles *android.DepSet[android.Path] |
| 237 | |
| 238 | // implementation detail to store transitive proguard flags files from exporting shared deps |
| 239 | UnconditionallyExportedProguardFlags *android.DepSet[android.Path] |
| 240 | } |
| 241 | |
| 242 | var ProguardSpecInfoProvider = blueprint.NewProvider(ProguardSpecInfo{}) |
| 243 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 244 | // JavaInfo contains information about a java module for use by modules that depend on it. |
| 245 | type JavaInfo struct { |
| 246 | // HeaderJars is a list of jars that can be passed as the javac classpath in order to link |
| 247 | // against this module. If empty, ImplementationJars should be used instead. |
| 248 | HeaderJars android.Paths |
| 249 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 250 | // set of header jars for all transitive libs deps |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 251 | TransitiveLibsHeaderJars *android.DepSet[android.Path] |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 252 | |
| 253 | // set of header jars for all transitive static libs deps |
Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 254 | TransitiveStaticLibsHeaderJars *android.DepSet[android.Path] |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 255 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 256 | // ImplementationAndResourceJars is a list of jars that contain the implementations of classes |
| 257 | // in the module as well as any resources included in the module. |
| 258 | ImplementationAndResourcesJars android.Paths |
| 259 | |
| 260 | // ImplementationJars is a list of jars that contain the implementations of classes in the |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 261 | //module. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 262 | ImplementationJars android.Paths |
| 263 | |
| 264 | // ResourceJars is a list of jars that contain the resources included in the module. |
| 265 | ResourceJars android.Paths |
| 266 | |
| 267 | // AidlIncludeDirs is a list of directories that should be passed to the aidl tool when |
| 268 | // depending on this module. |
| 269 | AidlIncludeDirs android.Paths |
| 270 | |
| 271 | // SrcJarArgs is a list of arguments to pass to soong_zip to package the sources of this |
| 272 | // module. |
| 273 | SrcJarArgs []string |
| 274 | |
| 275 | // SrcJarDeps is a list of paths to depend on when packaging the sources of this module. |
| 276 | SrcJarDeps android.Paths |
| 277 | |
Anton Hansson | 0e73f9e | 2023-09-20 13:39:57 +0000 | [diff] [blame] | 278 | // The source files of this module and all its transitive static dependencies. |
| 279 | TransitiveSrcFiles *android.DepSet[android.Path] |
| 280 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 281 | // ExportedPlugins is a list of paths that should be used as annotation processors for any |
| 282 | // module that depends on this module. |
| 283 | ExportedPlugins android.Paths |
| 284 | |
| 285 | // ExportedPluginClasses is a list of classes that should be run as annotation processors for |
| 286 | // any module that depends on this module. |
| 287 | ExportedPluginClasses []string |
| 288 | |
| 289 | // ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs, |
| 290 | // requiring disbling turbine for any modules that depend on it. |
| 291 | ExportedPluginDisableTurbine bool |
| 292 | |
| 293 | // JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be |
| 294 | // instrumented by jacoco. |
| 295 | JacocoReportClassesFile android.Path |
| 296 | } |
| 297 | |
| 298 | var JavaInfoProvider = blueprint.NewProvider(JavaInfo{}) |
| 299 | |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 300 | // SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to |
| 301 | // the sysprop implementation library. |
| 302 | type SyspropPublicStubInfo struct { |
| 303 | // JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to |
| 304 | // the sysprop implementation library. |
| 305 | JavaInfo JavaInfo |
| 306 | } |
| 307 | |
| 308 | var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{}) |
| 309 | |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 310 | // Methods that need to be implemented for a module that is added to apex java_libs property. |
| 311 | type ApexDependency interface { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 312 | HeaderJars() android.Paths |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 313 | ImplementationAndResourcesJars() android.Paths |
| 314 | } |
| 315 | |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 316 | // Provides build path and install path to DEX jars. |
| 317 | type UsesLibraryDependency interface { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 318 | DexJarBuildPath() OptionalDexJarPath |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 319 | DexJarInstallPath() android.Path |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 320 | ClassLoaderContexts() dexpreopt.ClassLoaderContextMap |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Jaewoong Jung | 2634264 | 2021-03-17 15:56:23 -0700 | [diff] [blame] | 323 | // TODO(jungjw): Move this to kythe.go once it's created. |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 324 | type xref interface { |
| 325 | XrefJavaFiles() android.Paths |
| 326 | } |
| 327 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 328 | func (j *Module) XrefJavaFiles() android.Paths { |
| 329 | return j.kytheFiles |
| 330 | } |
| 331 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 332 | type dependencyTag struct { |
| 333 | blueprint.BaseDependencyTag |
| 334 | name string |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 335 | |
| 336 | // True if the dependency is relinked at runtime. |
| 337 | runtimeLinked bool |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 338 | |
| 339 | // True if the dependency is a toolchain, for example an annotation processor. |
| 340 | toolchain bool |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 343 | // installDependencyTag is a dependency tag that is annotated to cause the installed files of the |
| 344 | // dependency to be installed when the parent module is installed. |
| 345 | type installDependencyTag struct { |
| 346 | blueprint.BaseDependencyTag |
| 347 | android.InstallAlwaysNeededDependencyTag |
| 348 | name string |
| 349 | } |
| 350 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 351 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 352 | if d.runtimeLinked { |
| 353 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 354 | } else if d.toolchain { |
| 355 | return []android.LicenseAnnotation{android.LicenseAnnotationToolchain} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 356 | } |
| 357 | return nil |
| 358 | } |
| 359 | |
| 360 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 361 | |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 362 | type usesLibraryDependencyTag struct { |
| 363 | dependencyTag |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 364 | sdkVersion int // SDK version in which the library appared as a standalone library. |
| 365 | optional bool // If the dependency is optional or required. |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 368 | func makeUsesLibraryDependencyTag(sdkVersion int, optional bool) usesLibraryDependencyTag { |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 369 | return usesLibraryDependencyTag{ |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 370 | dependencyTag: dependencyTag{ |
| 371 | name: fmt.Sprintf("uses-library-%d", sdkVersion), |
| 372 | runtimeLinked: true, |
| 373 | }, |
| 374 | sdkVersion: sdkVersion, |
| 375 | optional: optional, |
Ulya Trafimovich | b521811 | 2020-10-07 15:11:32 +0100 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 379 | func IsJniDepTag(depTag blueprint.DependencyTag) bool { |
Colin Cross | de78d13 | 2020-10-09 18:59:49 -0700 | [diff] [blame] | 380 | return depTag == jniLibTag |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 381 | } |
| 382 | |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 383 | var ( |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 384 | dataNativeBinsTag = dependencyTag{name: "dataNativeBins"} |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 385 | dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 386 | staticLibTag = dependencyTag{name: "staticlib"} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 387 | libTag = dependencyTag{name: "javalib", runtimeLinked: true} |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 388 | sdkLibTag = dependencyTag{name: "sdklib", runtimeLinked: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 389 | java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 390 | pluginTag = dependencyTag{name: "plugin", toolchain: true} |
| 391 | errorpronePluginTag = dependencyTag{name: "errorprone-plugin", toolchain: true} |
| 392 | exportedPluginTag = dependencyTag{name: "exported-plugin", toolchain: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 393 | bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true} |
| 394 | systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 395 | frameworkResTag = dependencyTag{name: "framework-res"} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 396 | kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true} |
| 397 | kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 398 | kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 399 | proguardRaiseTag = dependencyTag{name: "proguard-raise"} |
| 400 | certificateTag = dependencyTag{name: "certificate"} |
| 401 | instrumentationForTag = dependencyTag{name: "instrumentation_for"} |
Colin Cross | ce56425 | 2022-01-12 11:13:32 -0800 | [diff] [blame] | 402 | extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 403 | jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true} |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 404 | r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 405 | syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 406 | javaApiContributionTag = dependencyTag{name: "java-api-contribution"} |
| 407 | depApiSrcsTag = dependencyTag{name: "dep-api-srcs"} |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 408 | aconfigDeclarationTag = dependencyTag{name: "aconfig-declaration"} |
Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 409 | jniInstallTag = installDependencyTag{name: "jni install"} |
| 410 | binaryInstallTag = installDependencyTag{name: "binary install"} |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 411 | usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false) |
| 412 | usesLibOptTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, true) |
| 413 | usesLibCompat28OptTag = makeUsesLibraryDependencyTag(28, true) |
| 414 | usesLibCompat29ReqTag = makeUsesLibraryDependencyTag(29, false) |
| 415 | usesLibCompat30OptTag = makeUsesLibraryDependencyTag(30, true) |
Colin Cross | be1da47 | 2017-07-07 15:59:46 -0700 | [diff] [blame] | 416 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 417 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 418 | func IsLibDepTag(depTag blueprint.DependencyTag) bool { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 419 | return depTag == libTag || depTag == sdkLibTag |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool { |
| 423 | return depTag == staticLibTag |
| 424 | } |
| 425 | |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 426 | type sdkDep struct { |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 427 | useModule, useFiles, invalidVersion bool |
Colin Cross | 47ff252 | 2017-10-02 14:22:08 -0700 | [diff] [blame] | 428 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 429 | // The modules that will be added to the bootclasspath when targeting 1.8 or lower |
| 430 | bootclasspath []string |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 431 | |
| 432 | // The default system modules to use. Will be an empty string if no system |
| 433 | // modules are to be used. |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 434 | systemModules string |
| 435 | |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 436 | // The modules that will be added to the classpath regardless of the Java language level targeted |
| 437 | classpath []string |
| 438 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 439 | // 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] | 440 | // (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] | 441 | java9Classpath []string |
| 442 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 443 | frameworkResModule string |
| 444 | |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 445 | jars android.Paths |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 446 | aidl android.OptionalPath |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 447 | |
| 448 | noStandardLibs, noFrameworksLibs bool |
| 449 | } |
| 450 | |
| 451 | func (s sdkDep) hasStandardLibs() bool { |
| 452 | return !s.noStandardLibs |
| 453 | } |
| 454 | |
| 455 | func (s sdkDep) hasFrameworkLibs() bool { |
| 456 | return !s.noStandardLibs && !s.noFrameworksLibs |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 459 | type jniLib struct { |
Colin Cross | 403cc15 | 2020-07-06 14:15:24 -0700 | [diff] [blame] | 460 | name string |
| 461 | path android.Path |
| 462 | target android.Target |
| 463 | coverageFile android.OptionalPath |
| 464 | unstrippedFile android.Path |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 465 | partition string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 468 | func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 469 | sdkDep := decodeSdkDep(ctx, sdkContext) |
| 470 | if sdkDep.useModule { |
| 471 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) |
| 472 | ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 473 | ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 474 | if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() { |
Jihoon Kang | b507831 | 2023-03-29 23:25:49 +0000 | [diff] [blame] | 475 | ctx.AddVariationDependencies(nil, proguardRaiseTag, |
Jihoon Kang | 6c0df88 | 2023-06-14 22:43:25 +0000 | [diff] [blame] | 476 | config.LegacyCorePlatformBootclasspathLibraries..., |
Jihoon Kang | b507831 | 2023-03-29 23:25:49 +0000 | [diff] [blame] | 477 | ) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 478 | } |
| 479 | if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() { |
| 480 | ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...) |
| 481 | } |
| 482 | } |
| 483 | if sdkDep.systemModules != "" { |
| 484 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
| 485 | } |
| 486 | } |
| 487 | |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 488 | type deps struct { |
Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 489 | // bootClasspath is the list of jars that form the boot classpath (generally the java.* and |
| 490 | // android.* classes) for tools that still use it. javac targeting 1.9 or higher uses |
| 491 | // systemModules and java9Classpath instead. |
| 492 | bootClasspath classpath |
| 493 | |
| 494 | // classpath is the list of jars that form the classpath for javac and kotlinc rules. It |
| 495 | // contains header jars for all static and non-static dependencies. |
| 496 | classpath classpath |
| 497 | |
| 498 | // dexClasspath is the list of jars that form the classpath for d8 and r8 rules. It contains |
| 499 | // header jars for all non-static dependencies. Static dependencies have already been |
| 500 | // combined into the program jar. |
| 501 | dexClasspath classpath |
| 502 | |
| 503 | // java9Classpath is the list of jars that will be added to the classpath when targeting |
| 504 | // 1.9 or higher. It generally contains the android.* classes, while the java.* classes |
| 505 | // are provided by systemModules. |
| 506 | java9Classpath classpath |
| 507 | |
Colin Cross | 748b2d8 | 2020-11-19 13:52:06 -0800 | [diff] [blame] | 508 | processorPath classpath |
| 509 | errorProneProcessorPath classpath |
| 510 | processorClasses []string |
| 511 | staticJars android.Paths |
| 512 | staticHeaderJars android.Paths |
| 513 | staticResourceJars android.Paths |
| 514 | aidlIncludeDirs android.Paths |
| 515 | srcs android.Paths |
| 516 | srcJars android.Paths |
| 517 | systemModules *systemModules |
| 518 | aidlPreprocess android.OptionalPath |
| 519 | kotlinStdlib android.Paths |
| 520 | kotlinAnnotations android.Paths |
Colin Cross | a1ff7c6 | 2021-09-17 14:11:52 -0700 | [diff] [blame] | 521 | kotlinPlugins android.Paths |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 522 | |
| 523 | disableTurbine bool |
Colin Cross | 32f676a | 2017-09-06 13:41:06 -0700 | [diff] [blame] | 524 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 525 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 526 | func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { |
| 527 | for _, f := range dep.Srcs() { |
| 528 | if f.Ext() != ".jar" { |
| 529 | ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", |
| 530 | ctx.OtherModuleName(dep.(blueprint.Module))) |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 535 | func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 536 | if javaVersion != "" { |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 537 | return normalizeJavaVersion(ctx, javaVersion) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 538 | } else if ctx.Device() { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 539 | return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) |
Sorin Basca | 384250c | 2023-02-02 17:56:19 +0000 | [diff] [blame] | 540 | } else { |
Sorin Basca | be30273 | 2023-02-15 17:52:27 +0000 | [diff] [blame] | 541 | return JAVA_VERSION_17 |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 542 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Jihoon Kang | ff878bf | 2022-12-22 21:26:06 +0000 | [diff] [blame] | 545 | // Java version for stubs generation |
| 546 | func getStubsJavaVersion() javaVersion { |
| 547 | return JAVA_VERSION_8 |
| 548 | } |
| 549 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 550 | type javaVersion int |
| 551 | |
| 552 | const ( |
| 553 | JAVA_VERSION_UNSUPPORTED = 0 |
| 554 | JAVA_VERSION_6 = 6 |
| 555 | JAVA_VERSION_7 = 7 |
| 556 | JAVA_VERSION_8 = 8 |
| 557 | JAVA_VERSION_9 = 9 |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 558 | JAVA_VERSION_11 = 11 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 559 | JAVA_VERSION_17 = 17 |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 560 | ) |
| 561 | |
| 562 | func (v javaVersion) String() string { |
| 563 | switch v { |
| 564 | case JAVA_VERSION_6: |
| 565 | return "1.6" |
| 566 | case JAVA_VERSION_7: |
| 567 | return "1.7" |
| 568 | case JAVA_VERSION_8: |
| 569 | return "1.8" |
| 570 | case JAVA_VERSION_9: |
| 571 | return "1.9" |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 572 | case JAVA_VERSION_11: |
| 573 | return "11" |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 574 | case JAVA_VERSION_17: |
| 575 | return "17" |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 576 | default: |
| 577 | return "unsupported" |
| 578 | } |
| 579 | } |
| 580 | |
Cole Faust | d96eebf | 2022-06-28 14:41:27 -0700 | [diff] [blame] | 581 | func (v javaVersion) StringForKotlinc() string { |
| 582 | // $ ./external/kotlinc/bin/kotlinc -jvm-target foo |
| 583 | // error: unknown JVM target version: foo |
| 584 | // Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17 |
| 585 | switch v { |
| 586 | case JAVA_VERSION_7: |
| 587 | return "1.6" |
| 588 | case JAVA_VERSION_9: |
| 589 | return "9" |
| 590 | default: |
| 591 | return v.String() |
| 592 | } |
| 593 | } |
| 594 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 595 | // Returns true if javac targeting this version uses system modules instead of a bootclasspath. |
| 596 | func (v javaVersion) usesJavaModules() bool { |
| 597 | return v >= 9 |
| 598 | } |
| 599 | |
| 600 | func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion { |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 601 | switch javaVersion { |
| 602 | case "1.6", "6": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 603 | return JAVA_VERSION_6 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 604 | case "1.7", "7": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 605 | return JAVA_VERSION_7 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 606 | case "1.8", "8": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 607 | return JAVA_VERSION_8 |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 608 | case "1.9", "9": |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 609 | return JAVA_VERSION_9 |
Sorin Basca | c0244da | 2021-11-26 17:26:33 +0000 | [diff] [blame] | 610 | case "11": |
| 611 | return JAVA_VERSION_11 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 612 | case "17": |
Sorin Basca | 5938fed | 2022-06-22 12:53:51 +0100 | [diff] [blame] | 613 | return JAVA_VERSION_17 |
Sorin Basca | ce720c3 | 2022-05-24 12:13:50 +0100 | [diff] [blame] | 614 | case "10", "12", "13", "14", "15", "16": |
| 615 | ctx.PropertyErrorf("java_version", "Java language level %s is not supported", javaVersion) |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 616 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 617 | default: |
| 618 | ctx.PropertyErrorf("java_version", "Unrecognized Java language level") |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 619 | return JAVA_VERSION_UNSUPPORTED |
Pete Gillin | 4e8b48a | 2019-07-12 13:16:17 +0100 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 623 | // |
| 624 | // Java libraries (.jar file) |
| 625 | // |
| 626 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 627 | type Library struct { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 628 | Module |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 629 | |
Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 630 | combinedExportedProguardFlagsFile android.Path |
Jared Duke | 5979b30 | 2022-12-19 21:08:39 +0000 | [diff] [blame] | 631 | |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 632 | InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 635 | var _ android.ApexModule = (*Library)(nil) |
| 636 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 637 | // Provides access to the list of permitted packages from apex boot jars. |
Paul Duffin | e739f1e | 2020-05-29 11:24:51 +0100 | [diff] [blame] | 638 | type PermittedPackagesForUpdatableBootJars interface { |
| 639 | PermittedPackagesForUpdatableBootJars() []string |
| 640 | } |
| 641 | |
| 642 | var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil) |
| 643 | |
| 644 | func (j *Library) PermittedPackagesForUpdatableBootJars() []string { |
| 645 | return j.properties.Permitted_packages |
| 646 | } |
| 647 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 648 | func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { |
Ulya Trafimovich | f491dde | 2020-01-24 12:19:45 +0000 | [diff] [blame] | 649 | // Store uncompressed (and aligned) any dex files from jars in APEXes. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 650 | if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() { |
Ulya Trafimovich | f491dde | 2020-01-24 12:19:45 +0000 | [diff] [blame] | 651 | return true |
| 652 | } |
| 653 | |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 654 | // Store uncompressed (and do not strip) dex files from boot class path jars. |
| 655 | if inList(ctx.ModuleName(), ctx.Config().BootJars()) { |
| 656 | return true |
| 657 | } |
| 658 | |
| 659 | // Store uncompressed dex files that are preopted on /system. |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 660 | if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, dexpreopter.installPath)) { |
Vladimir Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 661 | return true |
| 662 | } |
Colin Cross | 083a2aa | 2019-02-06 16:37:12 -0800 | [diff] [blame] | 663 | if ctx.Config().UncompressPrivAppDex() && |
| 664 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) { |
| 665 | return true |
| 666 | } |
| 667 | |
Colin Cross | 2fc72f6 | 2018-12-21 12:59:54 -0800 | [diff] [blame] | 668 | return false |
| 669 | } |
| 670 | |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 671 | // Sets `dexer.dexProperties.Uncompress_dex` to the proper value. |
| 672 | func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) { |
| 673 | if dexer.dexProperties.Uncompress_dex == nil { |
| 674 | // If the value was not force-set by the user, use reasonable default based on the module. |
| 675 | dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter)) |
| 676 | } |
| 677 | } |
| 678 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 679 | func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 680 | |
| 681 | j.provideHiddenAPIPropertyInfo(ctx) |
| 682 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 683 | j.sdkVersion = j.SdkVersion(ctx) |
| 684 | j.minSdkVersion = j.MinSdkVersion(ctx) |
satayev | 0a420e7 | 2021-11-29 17:25:52 +0000 | [diff] [blame] | 685 | j.maxSdkVersion = j.MaxSdkVersion(ctx) |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 686 | |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 687 | j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName()) |
| 688 | |
Sam Delmerico | c8e040c | 2023-10-31 17:27:02 +0000 | [diff] [blame] | 689 | proguardSpecInfo := j.collectProguardSpecInfo(ctx) |
| 690 | ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo) |
Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 691 | exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList() |
| 692 | j.extraProguardFlagsFiles = append(j.extraProguardFlagsFiles, exportedProguardFlagsFiles...) |
| 693 | |
| 694 | combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags") |
| 695 | writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles) |
| 696 | j.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile |
Sam Delmerico | c8e040c | 2023-10-31 17:27:02 +0000 | [diff] [blame] | 697 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 698 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 699 | if !apexInfo.IsForPlatform() { |
| 700 | j.hideApexVariantFromMake = true |
| 701 | } |
| 702 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 703 | j.checkSdkVersions(ctx) |
Mark White | a15790a | 2023-08-22 21:28:11 +0000 | [diff] [blame] | 704 | j.checkHeadersOnly(ctx) |
Colin Cross | 61df14a | 2021-12-01 13:04:46 -0800 | [diff] [blame] | 705 | if ctx.Device() { |
| 706 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 707 | ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) |
| 708 | j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary |
| 709 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
| 710 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
| 711 | j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx) |
| 712 | } |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 713 | j.compile(ctx, nil, nil, nil) |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 714 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 715 | exclusivelyForApex := !apexInfo.IsForPlatform() |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 716 | if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 717 | var extraInstallDeps android.InstallPaths |
Colin Cross | f0f2e2c | 2019-10-15 16:36:40 -0700 | [diff] [blame] | 718 | if j.InstallMixin != nil { |
| 719 | extraInstallDeps = j.InstallMixin(ctx, j.outputFile) |
| 720 | } |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 721 | hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host() |
| 722 | if hostDexNeeded { |
Colin Cross | 3108ce1 | 2021-11-10 14:38:50 -0800 | [diff] [blame] | 723 | j.hostdexInstallFile = ctx.InstallFile( |
| 724 | android.PathForHostDexInstall(ctx, "framework"), |
Colin Cross | 1d0eb7a | 2021-11-03 14:08:20 -0700 | [diff] [blame] | 725 | j.Stem()+"-hostdex.jar", j.outputFile) |
| 726 | } |
| 727 | var installDir android.InstallPath |
| 728 | if ctx.InstallInTestcases() { |
| 729 | var archDir string |
| 730 | if !ctx.Host() { |
| 731 | archDir = ctx.DeviceConfig().DeviceArch() |
| 732 | } |
| 733 | installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) |
| 734 | } else { |
| 735 | installDir = android.PathForModuleInstall(ctx, "framework") |
| 736 | } |
| 737 | j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...) |
Colin Cross | 2c429dc | 2017-08-31 16:45:16 -0700 | [diff] [blame] | 738 | } |
Colin Cross | b7a6324 | 2015-04-16 14:09:14 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 741 | func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 742 | j.deps(ctx) |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 743 | j.usesLibrary.deps(ctx, false) |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 746 | const ( |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 747 | aidlIncludeDir = "aidl" |
| 748 | javaDir = "java" |
| 749 | jarFileSuffix = ".jar" |
| 750 | testConfigSuffix = "-AndroidTest.xml" |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 751 | ) |
| 752 | |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 753 | // path to the jar file of a java library. Relative to <sdk_root>/<api_dir> |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 754 | func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 755 | return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 758 | func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string { |
| 759 | return filepath.Join(javaDir, osPrefix, name+suffix) |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 762 | type librarySdkMemberType struct { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 763 | android.SdkMemberTypeBase |
Paul Duffin | f5c0a9c | 2020-02-28 14:39:53 +0000 | [diff] [blame] | 764 | |
| 765 | // Function to retrieve the appropriate output jar (implementation or header) from |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 766 | // the library. |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 767 | jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path |
| 768 | |
| 769 | // Function to compute the snapshot relative path to which the named library's |
| 770 | // jar should be copied. |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 771 | snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 772 | |
| 773 | // True if only the jar should be copied to the snapshot, false if the jar plus any additional |
| 774 | // files like aidl files should also be copied. |
| 775 | onlyCopyJarToSnapshot bool |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 778 | const ( |
| 779 | onlyCopyJarToSnapshot = true |
| 780 | copyEverythingToSnapshot = false |
| 781 | ) |
| 782 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 783 | func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 784 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { |
| 788 | _, ok := module.(*Library) |
| 789 | return ok |
| 790 | } |
| 791 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 792 | func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 793 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import") |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 794 | } |
Paul Duffin | a0dbf43 | 2019-12-05 11:25:53 +0000 | [diff] [blame] | 795 | |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 796 | func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 797 | return &librarySdkMemberProperties{} |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | type librarySdkMemberProperties struct { |
| 801 | android.SdkMemberPropertiesBase |
| 802 | |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 803 | JarToExport android.Path `android:"arch_variant"` |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 804 | AidlIncludeDirs android.Paths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 805 | |
| 806 | // The list of permitted packages that need to be passed to the prebuilts as they are used to |
| 807 | // create the updatable-bcp-packages.txt file. |
| 808 | PermittedPackages []string |
Paul Duffin | bb638eb | 2022-11-26 13:36:38 +0000 | [diff] [blame] | 809 | |
| 810 | // The value of the min_sdk_version property, translated into a number where possible. |
| 811 | MinSdkVersion *string `supported_build_releases:"Tiramisu+"` |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 812 | |
| 813 | DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 816 | func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 817 | j := variant.(*Library) |
| 818 | |
Paul Duffin | 7ed6ff8 | 2022-11-21 10:57:30 +0000 | [diff] [blame] | 819 | p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j) |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 820 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 821 | p.AidlIncludeDirs = j.AidlIncludeDirs() |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 822 | |
| 823 | p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars() |
Paul Duffin | bb638eb | 2022-11-26 13:36:38 +0000 | [diff] [blame] | 824 | |
| 825 | // If the min_sdk_version was set then add the canonical representation of the API level to the |
| 826 | // snapshot. |
| 827 | if j.deviceProperties.Min_sdk_version != nil { |
Cole Faust | 3486740 | 2023-04-28 12:32:27 -0700 | [diff] [blame] | 828 | canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String()) |
| 829 | if err != nil { |
| 830 | ctx.ModuleErrorf("%s", err) |
| 831 | } |
Paul Duffin | bb638eb | 2022-11-26 13:36:38 +0000 | [diff] [blame] | 832 | p.MinSdkVersion = proptools.StringPtr(canonical) |
| 833 | } |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 834 | |
| 835 | if j.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { |
| 836 | p.DexPreoptProfileGuided = proptools.BoolPtr(true) |
| 837 | } |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 838 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 839 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 840 | func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 841 | builder := ctx.SnapshotBuilder() |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 842 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 843 | memberType := ctx.MemberType().(*librarySdkMemberType) |
| 844 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 845 | exportedJar := p.JarToExport |
| 846 | if exportedJar != nil { |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 847 | // Delegate the creation of the snapshot relative path to the member type. |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 848 | snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name()) |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 849 | |
| 850 | // Copy the exported jar to the snapshot. |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 851 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) |
| 852 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 853 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
| 854 | } |
| 855 | |
Paul Duffin | bb638eb | 2022-11-26 13:36:38 +0000 | [diff] [blame] | 856 | if p.MinSdkVersion != nil { |
| 857 | propertySet.AddProperty("min_sdk_version", *p.MinSdkVersion) |
| 858 | } |
| 859 | |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 860 | if len(p.PermittedPackages) > 0 { |
| 861 | propertySet.AddProperty("permitted_packages", p.PermittedPackages) |
| 862 | } |
| 863 | |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 864 | dexPreoptSet := propertySet.AddPropertySet("dex_preopt") |
| 865 | if p.DexPreoptProfileGuided != nil { |
| 866 | dexPreoptSet.AddProperty("profile_guided", proptools.Bool(p.DexPreoptProfileGuided)) |
| 867 | } |
| 868 | |
Paul Duffin | db170e4 | 2020-12-08 17:48:25 +0000 | [diff] [blame] | 869 | // Do not copy anything else to the snapshot. |
| 870 | if memberType.onlyCopyJarToSnapshot { |
| 871 | return |
| 872 | } |
| 873 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 874 | aidlIncludeDirs := p.AidlIncludeDirs |
| 875 | if len(aidlIncludeDirs) != 0 { |
| 876 | sdkModuleContext := ctx.SdkModuleContext() |
| 877 | for _, dir := range aidlIncludeDirs { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 878 | // TODO(jiyong): copy parcelable declarations only |
| 879 | aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil) |
| 880 | for _, file := range aidlFiles { |
| 881 | builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file)) |
| 882 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 883 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 884 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 885 | // TODO(b/151933053) - add aidl include dirs property |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 886 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 889 | // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well. |
| 890 | // |
| 891 | // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were |
| 892 | // compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used |
| 893 | // as a `static_libs` dependency of another module. |
| 894 | // |
| 895 | // Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on |
| 896 | // a device. |
| 897 | // |
| 898 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 899 | // compiled against the host bootclasspath. |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 900 | func LibraryFactory() android.Module { |
| 901 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 902 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 903 | module.addHostAndDeviceProperties() |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 904 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 905 | module.initModuleAndImport(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 906 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 907 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 908 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 909 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 912 | // java_library_static is an obsolete alias for java_library. |
| 913 | func LibraryStaticFactory() android.Module { |
| 914 | return LibraryFactory() |
| 915 | } |
| 916 | |
| 917 | // java_library_host builds and links sources into a `.jar` file for the host. |
| 918 | // |
| 919 | // A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 920 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 921 | func LibraryHostFactory() android.Module { |
| 922 | module := &Library{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 923 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 924 | module.addHostProperties() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 925 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 926 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 927 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 928 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 929 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 930 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | // |
Colin Cross | b628ea5 | 2018-08-14 16:42:33 -0700 | [diff] [blame] | 934 | // Java Tests |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 935 | // |
| 936 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 937 | // Test option struct. |
| 938 | type TestOptions struct { |
Zhenhuang Wang | 0ac5a43 | 2022-08-12 18:49:20 +0800 | [diff] [blame] | 939 | android.CommonTestOptions |
| 940 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 941 | // a list of extra test configuration files that should be installed with the module. |
| 942 | Extra_test_configs []string `android:"path,arch_variant"` |
Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 943 | |
| 944 | // Extra <option> tags to add to the auto generated test xml file. The "key" |
| 945 | // is optional in each of these. |
| 946 | Tradefed_options []tradefed.Option |
Dan Shi | ec73143 | 2023-05-26 04:21:44 +0000 | [diff] [blame] | 947 | |
| 948 | // Extra <option> tags to add to the auto generated test xml file under the test runner, e.g., AndroidJunitTest. |
| 949 | // The "key" is optional in each of these. |
| 950 | Test_runner_options []tradefed.Option |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 953 | type testProperties struct { |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 954 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 955 | // installed into. |
| 956 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 957 | |
| 958 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 959 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 960 | Test_config *string `android:"path,arch_variant"` |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 961 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 962 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 963 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 964 | Test_config_template *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 965 | |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 966 | // list of files or filegroup modules that provide data that should be installed alongside |
| 967 | // the test |
Jiyong Park | 2b0e490 | 2021-02-16 06:52:39 +0900 | [diff] [blame] | 968 | Data []string `android:"path"` |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 969 | |
| 970 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 971 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 972 | // explicitly. |
| 973 | Auto_gen_config *bool |
easoncylee | 5bcff5d | 2020-04-30 14:57:06 +0800 | [diff] [blame] | 974 | |
| 975 | // Add parameterized mainline modules to auto generated test config. The options will be |
| 976 | // handled by TradeFed to do downloading and installing the specified modules on the device. |
| 977 | Test_mainline_modules []string |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 978 | |
| 979 | // Test options. |
| 980 | Test_options TestOptions |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 981 | |
| 982 | // Names of modules containing JNI libraries that should be installed alongside the test. |
| 983 | Jni_libs []string |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame] | 984 | |
| 985 | // Install the test into a folder named for the module in all test suites. |
| 986 | Per_testcase_directory *bool |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 989 | type hostTestProperties struct { |
| 990 | // list of native binary modules that should be installed alongside the test |
| 991 | Data_native_bins []string `android:"arch_variant"` |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 992 | |
| 993 | // list of device binary modules that should be installed alongside the test |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 994 | // This property only adds the first variant of the dependency |
| 995 | Data_device_bins_first []string `android:"arch_variant"` |
| 996 | |
| 997 | // list of device binary modules that should be installed alongside the test |
| 998 | // This property adds 64bit AND 32bit variants of the dependency |
| 999 | Data_device_bins_both []string `android:"arch_variant"` |
| 1000 | |
| 1001 | // list of device binary modules that should be installed alongside the test |
| 1002 | // This property only adds 64bit variants of the dependency |
| 1003 | Data_device_bins_64 []string `android:"arch_variant"` |
| 1004 | |
| 1005 | // list of device binary modules that should be installed alongside the test |
| 1006 | // This property adds 32bit variants of the dependency if available, or else |
| 1007 | // defaults to the 64bit variant |
| 1008 | Data_device_bins_prefer32 []string `android:"arch_variant"` |
| 1009 | |
| 1010 | // list of device binary modules that should be installed alongside the test |
| 1011 | // This property only adds 32bit variants of the dependency |
| 1012 | Data_device_bins_32 []string `android:"arch_variant"` |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1015 | type testHelperLibraryProperties struct { |
| 1016 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1017 | // installed into. |
| 1018 | Test_suites []string `android:"arch_variant"` |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame] | 1019 | |
| 1020 | // Install the test into a folder named for the module in all test suites. |
| 1021 | Per_testcase_directory *bool |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1024 | type prebuiltTestProperties struct { |
| 1025 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 1026 | // installed into. |
| 1027 | Test_suites []string `android:"arch_variant"` |
| 1028 | |
| 1029 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 1030 | // installed with the module. |
| 1031 | Test_config *string `android:"path,arch_variant"` |
| 1032 | } |
| 1033 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1034 | type Test struct { |
| 1035 | Library |
| 1036 | |
| 1037 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1038 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 1039 | testConfig android.Path |
| 1040 | extraTestConfigs android.Paths |
| 1041 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1044 | type TestHost struct { |
| 1045 | Test |
| 1046 | |
| 1047 | testHostProperties hostTestProperties |
| 1048 | } |
| 1049 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1050 | type TestHelperLibrary struct { |
| 1051 | Library |
| 1052 | |
| 1053 | testHelperLibraryProperties testHelperLibraryProperties |
| 1054 | } |
| 1055 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1056 | type JavaTestImport struct { |
| 1057 | Import |
| 1058 | |
| 1059 | prebuiltTestProperties prebuiltTestProperties |
| 1060 | |
| 1061 | testConfig android.Path |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1062 | dexJarFile android.Path |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Colin Cross | 24cc4be6 | 2021-11-03 14:09:41 -0700 | [diff] [blame] | 1065 | func (j *Test) InstallInTestcases() bool { |
| 1066 | // Host java tests install into $(HOST_OUT_JAVA_LIBRARIES), and then are copied into |
| 1067 | // testcases by base_rules.mk. |
| 1068 | return !j.Host() |
| 1069 | } |
| 1070 | |
| 1071 | func (j *TestHelperLibrary) InstallInTestcases() bool { |
| 1072 | return true |
| 1073 | } |
| 1074 | |
| 1075 | func (j *JavaTestImport) InstallInTestcases() bool { |
| 1076 | return true |
| 1077 | } |
| 1078 | |
Yu Liu | d8aa200 | 2023-10-05 11:40:06 -0700 | [diff] [blame] | 1079 | func (j *TestHost) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 1080 | return ctx.DeviceConfig().NativeCoverageEnabled() |
| 1081 | } |
| 1082 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1083 | func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) { |
| 1084 | if len(j.testHostProperties.Data_device_bins_first) > 0 { |
| 1085 | deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() |
| 1086 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...) |
| 1087 | } |
| 1088 | |
| 1089 | var maybeAndroid32Target *android.Target |
| 1090 | var maybeAndroid64Target *android.Target |
| 1091 | android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32") |
| 1092 | android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64") |
| 1093 | if len(android32TargetList) > 0 { |
| 1094 | maybeAndroid32Target = &android32TargetList[0] |
| 1095 | } |
| 1096 | if len(android64TargetList) > 0 { |
| 1097 | maybeAndroid64Target = &android64TargetList[0] |
| 1098 | } |
| 1099 | |
| 1100 | if len(j.testHostProperties.Data_device_bins_both) > 0 { |
| 1101 | if maybeAndroid32Target == nil && maybeAndroid64Target == nil { |
| 1102 | ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets) |
| 1103 | return |
| 1104 | } |
| 1105 | if maybeAndroid32Target != nil { |
| 1106 | ctx.AddFarVariationDependencies( |
| 1107 | maybeAndroid32Target.Variations(), |
| 1108 | dataDeviceBinsTag, |
| 1109 | j.testHostProperties.Data_device_bins_both..., |
| 1110 | ) |
| 1111 | } |
| 1112 | if maybeAndroid64Target != nil { |
| 1113 | ctx.AddFarVariationDependencies( |
| 1114 | maybeAndroid64Target.Variations(), |
| 1115 | dataDeviceBinsTag, |
| 1116 | j.testHostProperties.Data_device_bins_both..., |
| 1117 | ) |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | if len(j.testHostProperties.Data_device_bins_prefer32) > 0 { |
| 1122 | if maybeAndroid32Target != nil { |
| 1123 | ctx.AddFarVariationDependencies( |
| 1124 | maybeAndroid32Target.Variations(), |
| 1125 | dataDeviceBinsTag, |
| 1126 | j.testHostProperties.Data_device_bins_prefer32..., |
| 1127 | ) |
| 1128 | } else { |
| 1129 | if maybeAndroid64Target == nil { |
| 1130 | ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets) |
| 1131 | return |
| 1132 | } |
| 1133 | ctx.AddFarVariationDependencies( |
| 1134 | maybeAndroid64Target.Variations(), |
| 1135 | dataDeviceBinsTag, |
| 1136 | j.testHostProperties.Data_device_bins_prefer32..., |
| 1137 | ) |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if len(j.testHostProperties.Data_device_bins_32) > 0 { |
| 1142 | if maybeAndroid32Target == nil { |
| 1143 | ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets) |
| 1144 | return |
| 1145 | } |
| 1146 | deviceVariations := maybeAndroid32Target.Variations() |
| 1147 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...) |
| 1148 | } |
| 1149 | |
| 1150 | if len(j.testHostProperties.Data_device_bins_64) > 0 { |
| 1151 | if maybeAndroid64Target == nil { |
| 1152 | ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets) |
| 1153 | return |
| 1154 | } |
| 1155 | deviceVariations := maybeAndroid64Target.Variations() |
| 1156 | ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...) |
| 1157 | } |
| 1158 | } |
| 1159 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1160 | func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1161 | if len(j.testHostProperties.Data_native_bins) > 0 { |
| 1162 | for _, target := range ctx.MultiTargets() { |
| 1163 | ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...) |
| 1164 | } |
| 1165 | } |
| 1166 | |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 1167 | if len(j.testProperties.Jni_libs) > 0 { |
| 1168 | for _, target := range ctx.MultiTargets() { |
| 1169 | sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) |
| 1170 | ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) |
| 1171 | } |
| 1172 | } |
| 1173 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1174 | j.addDataDeviceBinsDeps(ctx) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1175 | j.deps(ctx) |
| 1176 | } |
| 1177 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1178 | func (j *TestHost) AddExtraResource(p android.Path) { |
| 1179 | j.extraResources = append(j.extraResources, p) |
| 1180 | } |
| 1181 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1182 | func (j *TestHost) dataDeviceBins() []string { |
| 1183 | ret := make([]string, 0, |
| 1184 | len(j.testHostProperties.Data_device_bins_first)+ |
| 1185 | len(j.testHostProperties.Data_device_bins_both)+ |
| 1186 | len(j.testHostProperties.Data_device_bins_prefer32)+ |
| 1187 | len(j.testHostProperties.Data_device_bins_32)+ |
| 1188 | len(j.testHostProperties.Data_device_bins_64), |
| 1189 | ) |
| 1190 | |
| 1191 | ret = append(ret, j.testHostProperties.Data_device_bins_first...) |
| 1192 | ret = append(ret, j.testHostProperties.Data_device_bins_both...) |
| 1193 | ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...) |
| 1194 | ret = append(ret, j.testHostProperties.Data_device_bins_32...) |
| 1195 | ret = append(ret, j.testHostProperties.Data_device_bins_64...) |
| 1196 | |
| 1197 | return ret |
| 1198 | } |
| 1199 | |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1200 | func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1201 | var configs []tradefed.Config |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1202 | dataDeviceBins := j.dataDeviceBins() |
| 1203 | if len(dataDeviceBins) > 0 { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1204 | // add Tradefed configuration to push device bins to device for testing |
| 1205 | remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name()) |
| 1206 | options := []tradefed.Option{{Name: "cleanup", Value: "true"}} |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1207 | for _, bin := range dataDeviceBins { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1208 | fullPath := filepath.Join(remoteDir, bin) |
| 1209 | options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath}) |
| 1210 | } |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1211 | configs = append(configs, tradefed.Object{ |
| 1212 | Type: "target_preparer", |
| 1213 | Class: "com.android.tradefed.targetprep.PushFilePreparer", |
| 1214 | Options: options, |
| 1215 | }) |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | j.Test.generateAndroidBuildActionsWithConfig(ctx, configs) |
Aditya Choudhary | 9b59352 | 2023-10-06 19:54:58 +0000 | [diff] [blame] | 1219 | ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{}) |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1222 | func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1223 | j.generateAndroidBuildActionsWithConfig(ctx, nil) |
Aditya Choudhary | 9b59352 | 2023-10-06 19:54:58 +0000 | [diff] [blame] | 1224 | ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{}) |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) { |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1228 | if j.testProperties.Test_options.Unit_test == nil && ctx.Host() { |
| 1229 | // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding. |
Julien Desprez | f666b15 | 2021-03-15 13:07:53 -0700 | [diff] [blame] | 1230 | defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites) |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1231 | j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest) |
| 1232 | } |
Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 1233 | j.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ |
| 1234 | TestConfigProp: j.testProperties.Test_config, |
| 1235 | TestConfigTemplateProp: j.testProperties.Test_config_template, |
| 1236 | TestSuites: j.testProperties.Test_suites, |
| 1237 | Config: configs, |
| 1238 | OptionsForAutogenerated: j.testProperties.Test_options.Tradefed_options, |
Dan Shi | ec73143 | 2023-05-26 04:21:44 +0000 | [diff] [blame] | 1239 | TestRunnerOptions: j.testProperties.Test_options.Test_runner_options, |
Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 1240 | AutoGenConfig: j.testProperties.Auto_gen_config, |
| 1241 | UnitTest: j.testProperties.Test_options.Unit_test, |
| 1242 | DeviceTemplate: "${JavaTestConfigTemplate}", |
| 1243 | HostTemplate: "${JavaHostTestConfigTemplate}", |
| 1244 | HostUnitTestTemplate: "${JavaHostUnitTestConfigTemplate}", |
| 1245 | }) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1246 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1247 | j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1248 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 1249 | j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs) |
| 1250 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1251 | ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) { |
| 1252 | j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) |
| 1253 | }) |
| 1254 | |
Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 1255 | ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) { |
| 1256 | j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) |
| 1257 | }) |
| 1258 | |
Colin Cross | f8d9c49 | 2021-01-26 11:01:43 -0800 | [diff] [blame] | 1259 | ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { |
| 1260 | sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) |
| 1261 | if sharedLibInfo.SharedLibrary != nil { |
| 1262 | // Copy to an intermediate output directory to append "lib[64]" to the path, |
| 1263 | // so that it's compatible with the default rpath values. |
| 1264 | var relPath string |
| 1265 | if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { |
| 1266 | relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) |
| 1267 | } else { |
| 1268 | relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) |
| 1269 | } |
| 1270 | relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) |
| 1271 | ctx.Build(pctx, android.BuildParams{ |
| 1272 | Rule: android.Cp, |
| 1273 | Input: sharedLibInfo.SharedLibrary, |
| 1274 | Output: relocatedLib, |
| 1275 | }) |
| 1276 | j.data = append(j.data, relocatedLib) |
| 1277 | } else { |
| 1278 | ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) |
| 1279 | } |
| 1280 | }) |
| 1281 | |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 1282 | j.Library.GenerateAndroidBuildActions(ctx) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1285 | func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1286 | j.Library.GenerateAndroidBuildActions(ctx) |
| 1287 | } |
| 1288 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1289 | func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 1290 | j.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ |
| 1291 | TestConfigProp: j.prebuiltTestProperties.Test_config, |
| 1292 | TestSuites: j.prebuiltTestProperties.Test_suites, |
| 1293 | DeviceTemplate: "${JavaTestConfigTemplate}", |
| 1294 | HostTemplate: "${JavaHostTestConfigTemplate}", |
| 1295 | HostUnitTestTemplate: "${JavaHostUnitTestConfigTemplate}", |
| 1296 | }) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1297 | |
| 1298 | j.Import.GenerateAndroidBuildActions(ctx) |
| 1299 | } |
| 1300 | |
| 1301 | type testSdkMemberType struct { |
| 1302 | android.SdkMemberTypeBase |
| 1303 | } |
| 1304 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 1305 | func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1306 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | func (mt *testSdkMemberType) IsInstance(module android.Module) bool { |
| 1310 | _, ok := module.(*Test) |
| 1311 | return ok |
| 1312 | } |
| 1313 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1314 | func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1315 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import") |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1316 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1317 | |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1318 | func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1319 | return &testSdkMemberProperties{} |
| 1320 | } |
| 1321 | |
| 1322 | type testSdkMemberProperties struct { |
| 1323 | android.SdkMemberPropertiesBase |
| 1324 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1325 | JarToExport android.Path |
| 1326 | TestConfig android.Path |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1329 | func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1330 | test := variant.(*Test) |
| 1331 | |
| 1332 | implementationJars := test.ImplementationJars() |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1333 | if len(implementationJars) != 1 { |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1334 | 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] | 1335 | } |
| 1336 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1337 | p.JarToExport = implementationJars[0] |
| 1338 | p.TestConfig = test.testConfig |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1339 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1340 | |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1341 | func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1342 | builder := ctx.SnapshotBuilder() |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 1343 | |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1344 | exportedJar := p.JarToExport |
| 1345 | if exportedJar != nil { |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 1346 | snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name()) |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1347 | builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1348 | |
| 1349 | propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | testConfig := p.TestConfig |
| 1353 | if testConfig != nil { |
| 1354 | snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix) |
| 1355 | builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath) |
Paul Duffin | 14eb467 | 2020-03-02 11:33:02 +0000 | [diff] [blame] | 1356 | propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath) |
| 1357 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1360 | // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and |
| 1361 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. |
| 1362 | // |
| 1363 | // By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 1364 | // compiled against the device bootclasspath. |
| 1365 | // |
| 1366 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 1367 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1368 | func TestFactory() android.Module { |
| 1369 | module := &Test{} |
| 1370 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1371 | module.addHostAndDeviceProperties() |
| 1372 | module.AddProperties(&module.testProperties) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1373 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1374 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e302687 | 2019-01-05 22:30:13 -0800 | [diff] [blame] | 1375 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1376 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1377 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1378 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1379 | return module |
| 1380 | } |
| 1381 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1382 | // java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite. |
| 1383 | func TestHelperLibraryFactory() android.Module { |
| 1384 | module := &TestHelperLibrary{} |
| 1385 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1386 | module.addHostAndDeviceProperties() |
| 1387 | module.AddProperties(&module.testHelperLibraryProperties) |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1388 | |
Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 1389 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1390 | module.Module.dexpreopter.isTest = true |
Cole Faust | d57e8b2 | 2022-08-11 11:59:04 -0700 | [diff] [blame] | 1391 | module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) |
Colin Cross | 9a4abed | 2019-04-24 13:19:28 -0700 | [diff] [blame] | 1392 | |
Paul Duffin | 42df144 | 2019-03-20 12:45:53 +0000 | [diff] [blame] | 1393 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1394 | return module |
| 1395 | } |
| 1396 | |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1397 | // java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module |
| 1398 | // and makes sure that it is added to the appropriate test suite. |
| 1399 | // |
| 1400 | // By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 1401 | // compiled against an Android classpath. |
| 1402 | // |
| 1403 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1404 | // for host modules. |
| 1405 | func JavaTestImportFactory() android.Module { |
| 1406 | module := &JavaTestImport{} |
| 1407 | |
| 1408 | module.AddProperties( |
| 1409 | &module.Import.properties, |
| 1410 | &module.prebuiltTestProperties) |
| 1411 | |
| 1412 | module.Import.properties.Installable = proptools.BoolPtr(true) |
| 1413 | |
| 1414 | android.InitPrebuiltModule(module, &module.properties.Jars) |
| 1415 | android.InitApexModule(module) |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 1416 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1417 | return module |
| 1418 | } |
| 1419 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1420 | // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to |
| 1421 | // allow running the test with `atest` or a `TEST_MAPPING` file. |
| 1422 | // |
| 1423 | // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 1424 | // compiled against the host bootclasspath. |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1425 | func TestHostFactory() android.Module { |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1426 | module := &TestHost{} |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1427 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1428 | module.addHostProperties() |
| 1429 | module.AddProperties(&module.testProperties) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1430 | module.AddProperties(&module.testHostProperties) |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1431 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1432 | InitTestHost( |
| 1433 | module, |
| 1434 | proptools.BoolPtr(true), |
| 1435 | nil, |
| 1436 | nil) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1437 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 1438 | InitJavaModuleMultiTargets(module, android.HostSupported) |
Julien Desprez | b216661 | 2021-03-05 18:08:36 +0000 | [diff] [blame] | 1439 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1440 | return module |
| 1441 | } |
| 1442 | |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 1443 | func InitTestHost(th *TestHost, installable *bool, testSuites []string, autoGenConfig *bool) { |
| 1444 | th.properties.Installable = installable |
| 1445 | th.testProperties.Auto_gen_config = autoGenConfig |
| 1446 | th.testProperties.Test_suites = testSuites |
| 1447 | } |
| 1448 | |
Colin Cross | 05638fc | 2018-04-09 18:40:24 -0700 | [diff] [blame] | 1449 | // |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1450 | // Java Binaries (.jar file plus wrapper script) |
| 1451 | // |
| 1452 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1453 | type binaryProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1454 | // installable script to execute the resulting jar |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1455 | Wrapper *string `android:"path,arch_variant"` |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1456 | |
| 1457 | // Name of the class containing main to be inserted into the manifest as Main-Class. |
| 1458 | Main_class *string |
Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 1459 | |
| 1460 | // Names of modules containing JNI libraries that should be installed alongside the host |
| 1461 | // variant of the binary. |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1462 | Jni_libs []string `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1465 | type Binary struct { |
| 1466 | Library |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1467 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1468 | binaryProperties binaryProperties |
Colin Cross | 10a0349 | 2017-08-10 17:09:43 -0700 | [diff] [blame] | 1469 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1470 | isWrapperVariant bool |
| 1471 | |
Colin Cross | c331599 | 2017-12-08 19:12:36 -0800 | [diff] [blame] | 1472 | wrapperFile android.Path |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 1473 | binaryFile android.InstallPath |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Alex Light | 2423717 | 2017-10-26 09:46:21 -0700 | [diff] [blame] | 1476 | func (j *Binary) HostToolPath() android.OptionalPath { |
| 1477 | return android.OptionalPathForPath(j.binaryFile) |
| 1478 | } |
| 1479 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1480 | func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 1481 | j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName()) |
| 1482 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1483 | if ctx.Arch().ArchType == android.Common { |
| 1484 | // Compile the jar |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 1485 | if j.binaryProperties.Main_class != nil { |
| 1486 | if j.properties.Manifest != nil { |
| 1487 | ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set") |
| 1488 | } |
| 1489 | manifestFile := android.PathForModuleOut(ctx, "manifest.txt") |
| 1490 | GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class)) |
| 1491 | j.overrideManifest = android.OptionalPathForPath(manifestFile) |
| 1492 | } |
| 1493 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1494 | j.Library.GenerateAndroidBuildActions(ctx) |
Nan Zhang | 3c807db | 2017-11-03 14:53:31 -0700 | [diff] [blame] | 1495 | } else { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1496 | // Handle the binary wrapper |
| 1497 | j.isWrapperVariant = true |
| 1498 | |
Colin Cross | 366938f | 2017-12-11 16:29:02 -0800 | [diff] [blame] | 1499 | if j.binaryProperties.Wrapper != nil { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1500 | j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1501 | } else { |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1502 | if ctx.Windows() { |
| 1503 | ctx.PropertyErrorf("wrapper", "wrapper is required for Windows") |
| 1504 | } |
| 1505 | |
Zi Wang | ca65b40 | 2022-10-10 13:45:06 -0700 | [diff] [blame] | 1506 | if ctx.Device() { |
| 1507 | // device binary should have a main_class property if it does not |
| 1508 | // have a specific wrapper, so that a default wrapper can |
| 1509 | // be generated for it. |
| 1510 | if j.binaryProperties.Main_class == nil { |
| 1511 | ctx.PropertyErrorf("main_class", "main_class property "+ |
| 1512 | "is required for device binary if no default wrapper is assigned") |
| 1513 | } else { |
| 1514 | wrapper := android.PathForModuleOut(ctx, ctx.ModuleName()+".sh") |
| 1515 | jarName := j.Stem() + ".jar" |
| 1516 | partition := j.PartitionTag(ctx.DeviceConfig()) |
| 1517 | ctx.Build(pctx, android.BuildParams{ |
| 1518 | Rule: deviceBinaryWrapper, |
| 1519 | Output: wrapper, |
| 1520 | Args: map[string]string{ |
| 1521 | "jar_name": jarName, |
| 1522 | "partition": partition, |
| 1523 | "main_class": String(j.binaryProperties.Main_class), |
| 1524 | }, |
| 1525 | }) |
| 1526 | j.wrapperFile = wrapper |
| 1527 | } |
| 1528 | } else { |
| 1529 | j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") |
| 1530 | } |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1531 | } |
| 1532 | |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1533 | ext := "" |
| 1534 | if ctx.Windows() { |
| 1535 | ext = ".bat" |
| 1536 | } |
| 1537 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 1538 | // 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] | 1539 | // of the wrapper variant, which will include the common variant's jar file and any JNI |
| 1540 | // libraries. This is verified by TestBinary. |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1541 | j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"), |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 1542 | ctx.ModuleName()+ext, j.wrapperFile) |
| 1543 | } |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1546 | func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 1547 | if ctx.Arch().ArchType == android.Common { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1548 | j.deps(ctx) |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1549 | } |
Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 1550 | if ctx.Arch().ArchType != android.Common { |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 1551 | // These dependencies ensure the host installation rules will install the jar file and |
| 1552 | // the jni libraries when the wrapper is installed. |
| 1553 | ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...) |
| 1554 | ctx.AddVariationDependencies( |
| 1555 | []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}}, |
| 1556 | binaryInstallTag, ctx.ModuleName()) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1557 | } |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1560 | // java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host |
| 1561 | // as well. |
| 1562 | // |
| 1563 | // By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were |
| 1564 | // compiled against the device bootclasspath. |
| 1565 | // |
| 1566 | // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one |
| 1567 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1568 | func BinaryFactory() android.Module { |
| 1569 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1570 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1571 | module.addHostAndDeviceProperties() |
| 1572 | module.AddProperties(&module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1573 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1574 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1575 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1576 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst) |
| 1577 | android.InitDefaultableModule(module) |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 1578 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1579 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1582 | // java_binary_host builds a `.jar` file and a shell script that executes it for the host. |
| 1583 | // |
| 1584 | // A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were |
| 1585 | // compiled against the host bootclasspath. |
Colin Cross | f506d87 | 2017-07-19 15:53:04 -0700 | [diff] [blame] | 1586 | func BinaryHostFactory() android.Module { |
| 1587 | module := &Binary{} |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1588 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1589 | module.addHostProperties() |
| 1590 | module.AddProperties(&module.binaryProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1591 | |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 1592 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 1593 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1594 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst) |
| 1595 | android.InitDefaultableModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1596 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1599 | type JavaApiContribution struct { |
| 1600 | android.ModuleBase |
| 1601 | android.DefaultableModuleBase |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1602 | embeddableInModuleAndImport |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1603 | |
| 1604 | properties struct { |
| 1605 | // name of the API surface |
| 1606 | Api_surface *string |
| 1607 | |
| 1608 | // relative path to the API signature text file |
| 1609 | Api_file *string `android:"path"` |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | func ApiContributionFactory() android.Module { |
| 1614 | module := &JavaApiContribution{} |
| 1615 | android.InitAndroidModule(module) |
| 1616 | android.InitDefaultableModule(module) |
| 1617 | module.AddProperties(&module.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1618 | module.initModuleAndImport(module) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1619 | return module |
| 1620 | } |
| 1621 | |
| 1622 | type JavaApiImportInfo struct { |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1623 | ApiFile android.Path |
| 1624 | ApiSurface string |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | var JavaApiImportProvider = blueprint.NewProvider(JavaApiImportInfo{}) |
| 1628 | |
| 1629 | func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1630 | var apiFile android.Path = nil |
| 1631 | if apiFileString := ap.properties.Api_file; apiFileString != nil { |
| 1632 | apiFile = android.PathForModuleSrc(ctx, String(apiFileString)) |
| 1633 | } |
| 1634 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1635 | ctx.SetProvider(JavaApiImportProvider, JavaApiImportInfo{ |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1636 | ApiFile: apiFile, |
| 1637 | ApiSurface: proptools.String(ap.properties.Api_surface), |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1638 | }) |
| 1639 | } |
| 1640 | |
| 1641 | type ApiLibrary struct { |
| 1642 | android.ModuleBase |
| 1643 | android.DefaultableModuleBase |
| 1644 | |
Spandan Das | cb368ea | 2023-03-22 04:27:05 +0000 | [diff] [blame] | 1645 | hiddenAPI |
| 1646 | dexer |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1647 | embeddableInModuleAndImport |
Spandan Das | cb368ea | 2023-03-22 04:27:05 +0000 | [diff] [blame] | 1648 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1649 | properties JavaApiLibraryProperties |
| 1650 | |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1651 | stubsSrcJar android.WritablePath |
| 1652 | stubsJar android.WritablePath |
| 1653 | stubsJarWithoutStaticLibs android.WritablePath |
| 1654 | extractedSrcJar android.WritablePath |
Spandan Das | cb368ea | 2023-03-22 04:27:05 +0000 | [diff] [blame] | 1655 | // .dex of stubs, used for hiddenapi processing |
| 1656 | dexJarFile OptionalDexJarPath |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1657 | |
| 1658 | validationPaths android.Paths |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | type JavaApiLibraryProperties struct { |
| 1662 | // name of the API surface |
| 1663 | Api_surface *string |
| 1664 | |
Jihoon Kang | 60d4a09 | 2022-11-17 23:47:43 +0000 | [diff] [blame] | 1665 | // list of Java API contribution modules that consists this API surface |
Spandan Das | c082eb8 | 2022-12-01 21:43:06 +0000 | [diff] [blame] | 1666 | // This is a list of Soong modules |
Jihoon Kang | 60d4a09 | 2022-11-17 23:47:43 +0000 | [diff] [blame] | 1667 | Api_contributions []string |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1668 | |
| 1669 | // List of flags to be passed to the javac compiler to generate jar file |
| 1670 | Javacflags []string |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1671 | |
| 1672 | // List of shared java libs that this module has dependencies to and |
| 1673 | // should be passed as classpath in javac invocation |
| 1674 | Libs []string |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1675 | |
| 1676 | // List of java libs that this module has static dependencies to and will be |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1677 | // merge zipped after metalava invocation |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1678 | Static_libs []string |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1679 | |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1680 | // Java Api library to provide the full API surface stub jar file. |
| 1681 | // If this property is set, the stub jar of this module is created by |
| 1682 | // extracting the compiled class files provided by the |
| 1683 | // full_api_surface_stub module. |
| 1684 | Full_api_surface_stub *string |
Jihoon Kang | 862da6f | 2023-08-01 06:28:51 +0000 | [diff] [blame] | 1685 | |
| 1686 | // Version of previously released API file for compatibility check. |
| 1687 | Previous_api *string `android:"path"` |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1688 | |
| 1689 | // java_system_modules module providing the jar to be added to the |
| 1690 | // bootclasspath when compiling the stubs. |
| 1691 | // The jar will also be passed to metalava as a classpath to |
| 1692 | // generate compilable stubs. |
| 1693 | System_modules *string |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1694 | |
| 1695 | // If true, the module runs validation on the API signature files provided |
| 1696 | // by the modules passed via api_contributions by checking if the files are |
| 1697 | // in sync with the source Java files. However, the environment variable |
| 1698 | // DISABLE_STUB_VALIDATION has precedence over this property. |
| 1699 | Enable_validation *bool |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | func ApiLibraryFactory() android.Module { |
| 1703 | module := &ApiLibrary{} |
| 1704 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1705 | module.AddProperties(&module.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1706 | module.initModuleAndImport(module) |
Jihoon Kang | 1c51f50 | 2023-01-09 23:42:40 +0000 | [diff] [blame] | 1707 | android.InitDefaultableModule(module) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1708 | return module |
| 1709 | } |
| 1710 | |
| 1711 | func (al *ApiLibrary) ApiSurface() *string { |
| 1712 | return al.properties.Api_surface |
| 1713 | } |
| 1714 | |
| 1715 | func (al *ApiLibrary) StubsJar() android.Path { |
| 1716 | return al.stubsJar |
| 1717 | } |
| 1718 | |
| 1719 | func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1720 | srcs android.Paths, homeDir android.WritablePath, |
| 1721 | classpath android.Paths) *android.RuleBuilderCommand { |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1722 | rule.Command().Text("rm -rf").Flag(homeDir.String()) |
| 1723 | rule.Command().Text("mkdir -p").Flag(homeDir.String()) |
| 1724 | |
| 1725 | cmd := rule.Command() |
| 1726 | cmd.FlagWithArg("ANDROID_PREFS_ROOT=", homeDir.String()) |
| 1727 | |
| 1728 | if metalavaUseRbe(ctx) { |
| 1729 | rule.Remoteable(android.RemoteRuleSupports{RBE: true}) |
| 1730 | execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
| 1731 | labels := map[string]string{"type": "tool", "name": "metalava"} |
| 1732 | |
| 1733 | pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16") |
| 1734 | rule.Rewrapper(&remoteexec.REParams{ |
| 1735 | Labels: labels, |
| 1736 | ExecStrategy: execStrategy, |
| 1737 | ToolchainInputs: []string{config.JavaCmd(ctx).String()}, |
| 1738 | Platform: map[string]string{remoteexec.PoolKey: pool}, |
| 1739 | }) |
| 1740 | } |
| 1741 | |
| 1742 | cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")). |
| 1743 | Flag(config.JavacVmFlags). |
| 1744 | Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED"). |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1745 | FlagWithInputList("--source-files ", srcs, " ") |
| 1746 | |
MÃ¥rten Kongstad | bd26244 | 2023-07-12 14:01:49 +0200 | [diff] [blame] | 1747 | cmd.Flag("--color"). |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1748 | Flag("--quiet"). |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1749 | Flag("--include-annotations"). |
| 1750 | // The flag makes nullability issues as warnings rather than errors by replacing |
| 1751 | // @Nullable/@NonNull in the listed packages APIs with @RecentlyNullable/@RecentlyNonNull, |
| 1752 | // and these packages are meant to have everything annotated |
| 1753 | // @RecentlyNullable/@RecentlyNonNull. |
| 1754 | FlagWithArg("--force-convert-to-warning-nullability-annotations ", "+*:-android.*:+android.icu.*:-dalvik.*"). |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1755 | FlagWithArg("--repeat-errors-max ", "10"). |
| 1756 | FlagWithArg("--hide ", "UnresolvedImport"). |
| 1757 | FlagWithArg("--hide ", "InvalidNullabilityOverride"). |
| 1758 | FlagWithArg("--hide ", "ChangedDefault") |
| 1759 | |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1760 | if len(classpath) == 0 { |
| 1761 | // The main purpose of the `--api-class-resolution api` option is to force metalava to ignore |
| 1762 | // classes on the classpath when an API file contains missing classes. However, as this command |
| 1763 | // does not specify `--classpath` this is not needed for that. However, this is also used as a |
| 1764 | // signal to the special metalava code for generating stubs from text files that it needs to add |
| 1765 | // some additional items into the API (e.g. default constructors). |
| 1766 | cmd.FlagWithArg("--api-class-resolution ", "api") |
| 1767 | } else { |
| 1768 | cmd.FlagWithArg("--api-class-resolution ", "api:classpath") |
| 1769 | cmd.FlagWithInputList("--classpath ", classpath, ":") |
| 1770 | } |
Paul Duffin | 5b7035f | 2023-05-31 17:51:33 +0100 | [diff] [blame] | 1771 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1772 | return cmd |
| 1773 | } |
| 1774 | |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 1775 | func (al *ApiLibrary) HeaderJars() android.Paths { |
| 1776 | return android.Paths{al.stubsJar} |
| 1777 | } |
| 1778 | |
| 1779 | func (al *ApiLibrary) OutputDirAndDeps() (android.Path, android.Paths) { |
| 1780 | return nil, nil |
| 1781 | } |
| 1782 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1783 | func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) { |
| 1784 | if stubsDir.Valid() { |
| 1785 | cmd.FlagWithArg("--stubs ", stubsDir.String()) |
| 1786 | } |
| 1787 | } |
| 1788 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1789 | func (al *ApiLibrary) addValidation(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, validationPaths android.Paths) { |
| 1790 | for _, validationPath := range validationPaths { |
| 1791 | cmd.Validation(validationPath) |
| 1792 | } |
| 1793 | } |
| 1794 | |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1795 | // This method extracts the stub class files from the stub jar file provided |
| 1796 | // from full_api_surface_stub module instead of compiling the srcjar generated from invoking metalava. |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1797 | // This method is used because metalava can generate compilable from-text stubs only when |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1798 | // the codebase encompasses all classes listed in the input API text file, and a class can extend |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1799 | // a class that is not within the same API domain. |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1800 | func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.RuleBuilder, stubsDir android.OptionalPath, fullApiSurfaceStubJar android.Path) { |
| 1801 | classFilesList := android.PathForModuleOut(ctx, "metalava", "classes.txt") |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1802 | unzippedSrcJarDir := android.PathForModuleOut(ctx, "metalava", "unzipDir") |
| 1803 | |
| 1804 | rule.Command(). |
| 1805 | BuiltTool("list_files"). |
| 1806 | Text(stubsDir.String()). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1807 | FlagWithOutput("--out ", classFilesList). |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1808 | FlagWithArg("--extensions ", ".java"). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1809 | FlagWithArg("--root ", unzippedSrcJarDir.String()). |
| 1810 | Flag("--classes") |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1811 | |
| 1812 | rule.Command(). |
| 1813 | Text("unzip"). |
| 1814 | Flag("-q"). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1815 | Input(fullApiSurfaceStubJar). |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1816 | FlagWithArg("-d ", unzippedSrcJarDir.String()) |
| 1817 | |
| 1818 | rule.Command(). |
| 1819 | BuiltTool("soong_zip"). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1820 | Flag("-jar"). |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1821 | Flag("-write_if_changed"). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1822 | Flag("-ignore_missing_files"). |
Jihoon Kang | d02a436 | 2023-09-12 23:54:43 +0000 | [diff] [blame] | 1823 | Flag("-quiet"). |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1824 | FlagWithArg("-C ", unzippedSrcJarDir.String()). |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1825 | FlagWithInput("-l ", classFilesList). |
| 1826 | FlagWithOutput("-o ", al.stubsJarWithoutStaticLibs) |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1827 | } |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1828 | |
| 1829 | func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | 60d4a09 | 2022-11-17 23:47:43 +0000 | [diff] [blame] | 1830 | apiContributions := al.properties.Api_contributions |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1831 | addValidations := !ctx.Config().IsEnvTrue("DISABLE_STUB_VALIDATION") && |
| 1832 | proptools.BoolDefault(al.properties.Enable_validation, true) |
Jihoon Kang | 60d4a09 | 2022-11-17 23:47:43 +0000 | [diff] [blame] | 1833 | for _, apiContributionName := range apiContributions { |
| 1834 | ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName) |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1835 | |
| 1836 | // Add the java_api_contribution module generating droidstubs module |
| 1837 | // as dependency when validation adding conditions are met and |
| 1838 | // the java_api_contribution module name has ".api.contribution" suffix. |
| 1839 | // All droidstubs-generated modules possess the suffix in the name, |
| 1840 | // but there is no such guarantee for tests. |
| 1841 | if addValidations { |
| 1842 | if strings.HasSuffix(apiContributionName, ".api.contribution") { |
| 1843 | ctx.AddDependency(ctx.Module(), metalavaCurrentApiTimestampTag, strings.TrimSuffix(apiContributionName, ".api.contribution")) |
| 1844 | } else { |
| 1845 | ctx.ModuleErrorf("Validation is enabled for module %s but a "+ |
| 1846 | "current timestamp provider is not found for the api "+ |
| 1847 | "contribution %s", |
| 1848 | ctx.ModuleName(), |
| 1849 | apiContributionName, |
| 1850 | ) |
| 1851 | } |
| 1852 | } |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1853 | } |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1854 | ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1855 | ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...) |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1856 | if al.properties.Full_api_surface_stub != nil { |
| 1857 | ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Full_api_surface_stub)) |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1858 | } |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1859 | if al.properties.System_modules != nil { |
| 1860 | ctx.AddVariationDependencies(nil, systemModulesTag, String(al.properties.System_modules)) |
| 1861 | } |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 1864 | // Map where key is the api scope name and value is the int value |
| 1865 | // representing the order of the api scope, narrowest to the widest |
| 1866 | var scopeOrderMap = allApiScopes.MapToIndex( |
| 1867 | func(s *apiScope) string { return s.name }) |
Jihoon Kang | 478ca5b | 2023-08-11 23:33:05 +0000 | [diff] [blame] | 1868 | |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 1869 | func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) []JavaApiImportInfo { |
| 1870 | for _, srcFileInfo := range srcFilesInfo { |
| 1871 | if srcFileInfo.ApiSurface == "" { |
| 1872 | ctx.ModuleErrorf("Api surface not defined for the associated api file %s", srcFileInfo.ApiFile) |
Jihoon Kang | 84473f5 | 2023-08-11 22:36:33 +0000 | [diff] [blame] | 1873 | } |
| 1874 | } |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 1875 | sort.Slice(srcFilesInfo, func(i, j int) bool { |
| 1876 | return scopeOrderMap[srcFilesInfo[i].ApiSurface] < scopeOrderMap[srcFilesInfo[j].ApiSurface] |
| 1877 | }) |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1878 | |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 1879 | return srcFilesInfo |
Jihoon Kang | 84473f5 | 2023-08-11 22:36:33 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1882 | func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1883 | |
| 1884 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1885 | |
| 1886 | rule.Sbox(android.PathForModuleOut(ctx, "metalava"), |
| 1887 | android.PathForModuleOut(ctx, "metalava.sbox.textproto")). |
| 1888 | SandboxInputs() |
| 1889 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1890 | stubsDir := android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir")) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1891 | rule.Command().Text("rm -rf").Text(stubsDir.String()) |
| 1892 | rule.Command().Text("mkdir -p").Text(stubsDir.String()) |
| 1893 | |
| 1894 | homeDir := android.PathForModuleOut(ctx, "metalava", "home") |
| 1895 | |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1896 | var srcFilesInfo []JavaApiImportInfo |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1897 | var classPaths android.Paths |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1898 | var staticLibs android.Paths |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1899 | var depApiSrcsStubsJar android.Path |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1900 | var systemModulesPaths android.Paths |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1901 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1902 | tag := ctx.OtherModuleDependencyTag(dep) |
| 1903 | switch tag { |
| 1904 | case javaApiContributionTag: |
| 1905 | provider := ctx.OtherModuleProvider(dep, JavaApiImportProvider).(JavaApiImportInfo) |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1906 | if provider.ApiFile == nil && !ctx.Config().AllowMissingDependencies() { |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1907 | ctx.ModuleErrorf("Error: %s has an empty api file.", dep.Name()) |
| 1908 | } |
Jihoon Kang | 8fe1982 | 2023-09-14 06:27:36 +0000 | [diff] [blame] | 1909 | srcFilesInfo = append(srcFilesInfo, provider) |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1910 | case libTag: |
| 1911 | provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) |
| 1912 | classPaths = append(classPaths, provider.HeaderJars...) |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1913 | case staticLibTag: |
| 1914 | provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) |
| 1915 | staticLibs = append(staticLibs, provider.HeaderJars...) |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1916 | case depApiSrcsTag: |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1917 | provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) |
| 1918 | depApiSrcsStubsJar = provider.HeaderJars[0] |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1919 | case systemModulesTag: |
| 1920 | module := dep.(SystemModulesProvider) |
| 1921 | systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...) |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1922 | case metalavaCurrentApiTimestampTag: |
| 1923 | if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok { |
| 1924 | al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp()) |
| 1925 | } |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 1926 | } |
Jihoon Kang | 60d4a09 | 2022-11-17 23:47:43 +0000 | [diff] [blame] | 1927 | }) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1928 | |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 1929 | srcFilesInfo = al.sortApiFilesByApiScope(ctx, srcFilesInfo) |
| 1930 | var srcFiles android.Paths |
| 1931 | for _, srcFileInfo := range srcFilesInfo { |
| 1932 | srcFiles = append(srcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String())) |
Spandan Das | c082eb8 | 2022-12-01 21:43:06 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Jihoon Kang | 160634c | 2023-05-25 05:28:29 +0000 | [diff] [blame] | 1935 | if srcFiles == nil && !ctx.Config().AllowMissingDependencies() { |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1936 | ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName()) |
| 1937 | } |
| 1938 | |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1939 | cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1940 | |
| 1941 | al.stubsFlags(ctx, cmd, stubsDir) |
| 1942 | |
Jihoon Kang | 862da6f | 2023-08-01 06:28:51 +0000 | [diff] [blame] | 1943 | migratingNullability := String(al.properties.Previous_api) != "" |
| 1944 | if migratingNullability { |
| 1945 | previousApi := android.PathForModuleSrc(ctx, String(al.properties.Previous_api)) |
| 1946 | cmd.FlagWithInput("--migrate-nullness ", previousApi) |
| 1947 | } |
| 1948 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1949 | al.addValidation(ctx, cmd, al.validationPaths) |
| 1950 | |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1951 | al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1952 | al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar") |
| 1953 | al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName())) |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1954 | |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1955 | if depApiSrcsStubsJar != nil { |
| 1956 | al.extractApiSrcs(ctx, rule, stubsDir, depApiSrcsStubsJar) |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1957 | } |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1958 | rule.Command(). |
| 1959 | BuiltTool("soong_zip"). |
| 1960 | Flag("-write_if_changed"). |
| 1961 | Flag("-jar"). |
| 1962 | FlagWithOutput("-o ", al.stubsSrcJar). |
| 1963 | FlagWithArg("-C ", stubsDir.String()). |
| 1964 | FlagWithArg("-D ", stubsDir.String()) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1965 | |
Paul Duffin | 336b16a | 2023-08-15 23:10:13 +0100 | [diff] [blame] | 1966 | rule.Build("metalava", "metalava merged text") |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1967 | |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1968 | if depApiSrcsStubsJar == nil { |
| 1969 | var flags javaBuilderFlags |
| 1970 | flags.javaVersion = getStubsJavaVersion() |
| 1971 | flags.javacFlags = strings.Join(al.properties.Javacflags, " ") |
| 1972 | flags.classpath = classpath(classPaths) |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1973 | flags.bootClasspath = classpath(systemModulesPaths) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 1974 | |
Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1975 | annoSrcJar := android.PathForModuleOut(ctx, ctx.ModuleName(), "anno.srcjar") |
| 1976 | |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1977 | TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 0, android.Paths{}, |
Vadim Spivak | 3c496f0 | 2023-06-08 06:14:59 +0000 | [diff] [blame] | 1978 | android.Paths{al.stubsSrcJar}, annoSrcJar, flags, android.Paths{}) |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1979 | } |
Jihoon Kang | 423d229 | 2022-11-29 23:10:10 +0000 | [diff] [blame] | 1980 | |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1981 | builder := android.NewRuleBuilder(pctx, ctx) |
| 1982 | builder.Command(). |
| 1983 | BuiltTool("merge_zips"). |
| 1984 | Output(al.stubsJar). |
Jihoon Kang | 01e522c | 2023-03-14 01:09:34 +0000 | [diff] [blame] | 1985 | Inputs(android.Paths{al.stubsJarWithoutStaticLibs}). |
Jihoon Kang | e30fff0 | 2023-02-14 20:18:20 +0000 | [diff] [blame] | 1986 | Inputs(staticLibs) |
| 1987 | builder.Build("merge_zips", "merge jar files") |
| 1988 | |
Spandan Das | cb368ea | 2023-03-22 04:27:05 +0000 | [diff] [blame] | 1989 | // compile stubs to .dex for hiddenapi processing |
| 1990 | dexParams := &compileDexParams{ |
| 1991 | flags: javaBuilderFlags{}, |
| 1992 | sdkVersion: al.SdkVersion(ctx), |
| 1993 | minSdkVersion: al.MinSdkVersion(ctx), |
| 1994 | classesJar: al.stubsJar, |
| 1995 | jarName: ctx.ModuleName() + ".jar", |
| 1996 | } |
| 1997 | dexOutputFile := al.dexer.compileDex(ctx, dexParams) |
| 1998 | uncompressed := true |
| 1999 | al.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), al.stubsJar, &uncompressed) |
| 2000 | dexOutputFile = al.hiddenAPIEncodeDex(ctx, dexOutputFile) |
| 2001 | al.dexJarFile = makeDexJarPathFromPath(dexOutputFile) |
| 2002 | |
Jihoon Kang | 423d229 | 2022-11-29 23:10:10 +0000 | [diff] [blame] | 2003 | ctx.Phony(ctx.ModuleName(), al.stubsJar) |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 2004 | |
| 2005 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
Jihoon Kang | 1bff034 | 2023-01-17 20:40:22 +0000 | [diff] [blame] | 2006 | HeaderJars: android.PathsIfNonNil(al.stubsJar), |
| 2007 | ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar), |
| 2008 | ImplementationJars: android.PathsIfNonNil(al.stubsJar), |
| 2009 | AidlIncludeDirs: android.Paths{}, |
Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 2010 | // No aconfig libraries on api libraries |
Jihoon Kang | 362aa9d | 2023-01-20 19:44:07 +0000 | [diff] [blame] | 2011 | }) |
Jihoon Kang | 0ac87c2 | 2022-11-15 19:06:14 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
Spandan Das | cb368ea | 2023-03-22 04:27:05 +0000 | [diff] [blame] | 2014 | func (al *ApiLibrary) DexJarBuildPath() OptionalDexJarPath { |
| 2015 | return al.dexJarFile |
| 2016 | } |
| 2017 | |
| 2018 | func (al *ApiLibrary) DexJarInstallPath() android.Path { |
| 2019 | return al.dexJarFile.Path() |
| 2020 | } |
| 2021 | |
| 2022 | func (al *ApiLibrary) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
| 2023 | return nil |
| 2024 | } |
| 2025 | |
| 2026 | // java_api_library constitutes the sdk, and does not build against one |
| 2027 | func (al *ApiLibrary) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 2028 | return android.SdkSpecNone |
| 2029 | } |
| 2030 | |
| 2031 | // java_api_library is always at "current". Return FutureApiLevel |
| 2032 | func (al *ApiLibrary) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 2033 | return android.FutureApiLevel |
| 2034 | } |
| 2035 | |
| 2036 | // implement the following interfaces for hiddenapi processing |
| 2037 | var _ hiddenAPIModule = (*ApiLibrary)(nil) |
| 2038 | var _ UsesLibraryDependency = (*ApiLibrary)(nil) |
| 2039 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2040 | // |
| 2041 | // Java prebuilts |
| 2042 | // |
| 2043 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2044 | type ImportProperties struct { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 2045 | Jars []string `android:"path,arch_variant"` |
Colin Cross | 461bd1a | 2017-10-20 13:59:18 -0700 | [diff] [blame] | 2046 | |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2047 | // The version of the SDK that the source prebuilt file was built against. Defaults to the |
| 2048 | // current version if not specified. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2049 | Sdk_version *string |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 2050 | |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2051 | // The minimum version of the SDK that this module supports. Defaults to sdk_version if not |
| 2052 | // specified. |
| 2053 | Min_sdk_version *string |
| 2054 | |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 2055 | // The max sdk version placeholder used to replace maxSdkVersion attributes on permission |
| 2056 | // and uses-permission tags in manifest_fixer. |
| 2057 | Replace_max_sdk_version_placeholder *string |
| 2058 | |
Colin Cross | 535e2cf | 2017-10-20 17:57:49 -0700 | [diff] [blame] | 2059 | Installable *bool |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2060 | |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2061 | // If not empty, classes are restricted to the specified packages and their sub-packages. |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2062 | Permitted_packages []string |
| 2063 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2064 | // List of shared java libs that this module has dependencies to |
| 2065 | Libs []string |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2066 | |
| 2067 | // List of files to remove from the jar file(s) |
| 2068 | Exclude_files []string |
| 2069 | |
| 2070 | // List of directories to remove from the jar file(s) |
| 2071 | Exclude_dirs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2072 | |
| 2073 | // if set to true, run Jetifier against .jar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 2074 | Jetifier *bool |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 2075 | |
| 2076 | // set the name of the output |
| 2077 | Stem *string |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 2078 | |
| 2079 | Aidl struct { |
| 2080 | // directories that should be added as include directories for any aidl sources of modules |
| 2081 | // that depend on this module, as well as to aidl for this module. |
| 2082 | Export_include_dirs []string |
| 2083 | } |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | type Import struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2087 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2088 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2089 | android.ApexModuleBase |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 2090 | prebuilt android.Prebuilt |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2091 | |
Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 2092 | // Functionality common to Module and Import. |
| 2093 | embeddableInModuleAndImport |
| 2094 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2095 | hiddenAPI |
| 2096 | dexer |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 2097 | dexpreopter |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2098 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2099 | properties ImportProperties |
| 2100 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2101 | // output file containing classes.dex and resources |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2102 | dexJarFile OptionalDexJarPath |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2103 | dexJarInstallFile android.Path |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2104 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 2105 | combinedClasspathFile android.Path |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 2106 | classLoaderContexts dexpreopt.ClassLoaderContextMap |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 2107 | exportAidlIncludeDirs android.Paths |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2108 | |
| 2109 | hideApexVariantFromMake bool |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2110 | |
| 2111 | sdkVersion android.SdkSpec |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2112 | minSdkVersion android.ApiLevel |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 2115 | var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil) |
| 2116 | |
| 2117 | func (j *Import) PermittedPackagesForUpdatableBootJars() []string { |
| 2118 | return j.properties.Permitted_packages |
| 2119 | } |
| 2120 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2121 | func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 2122 | return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version)) |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2125 | func (j *Import) SystemModules() string { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2126 | return "none" |
| 2127 | } |
| 2128 | |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2129 | func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2130 | if j.properties.Min_sdk_version != nil { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2131 | return android.ApiLevelFrom(ctx, *j.properties.Min_sdk_version) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2132 | } |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2133 | return j.SdkVersion(ctx).ApiLevel |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 2136 | func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 2137 | if j.properties.Replace_max_sdk_version_placeholder != nil { |
Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 2138 | return android.ApiLevelFrom(ctx, *j.properties.Replace_max_sdk_version_placeholder) |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 2139 | } |
Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 2140 | // Default is PrivateApiLevel |
| 2141 | return android.SdkSpecPrivate.ApiLevel |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 2144 | func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 2145 | return j.SdkVersion(ctx).ApiLevel |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 2146 | } |
| 2147 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2148 | func (j *Import) Prebuilt() *android.Prebuilt { |
Colin Cross | ec7a042 | 2017-07-07 14:47:12 -0700 | [diff] [blame] | 2149 | return &j.prebuilt |
| 2150 | } |
| 2151 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2152 | func (j *Import) PrebuiltSrcs() []string { |
| 2153 | return j.properties.Jars |
| 2154 | } |
| 2155 | |
| 2156 | func (j *Import) Name() string { |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 2157 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 2158 | } |
| 2159 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2160 | func (j *Import) Stem() string { |
| 2161 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 2162 | } |
| 2163 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 2164 | func (a *Import) JacocoReportClassesFile() android.Path { |
| 2165 | return nil |
| 2166 | } |
| 2167 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 2168 | func (j *Import) LintDepSets() LintDepSets { |
| 2169 | return LintDepSets{} |
| 2170 | } |
| 2171 | |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2172 | func (j *Import) getStrictUpdatabilityLinting() bool { |
| 2173 | return false |
| 2174 | } |
| 2175 | |
| 2176 | func (j *Import) setStrictUpdatabilityLinting(bool) { |
| 2177 | } |
| 2178 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2179 | func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 2180 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2181 | |
| 2182 | if ctx.Device() && Bool(j.dexProperties.Compile_dex) { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2183 | sdkDeps(ctx, android.SdkContext(j), j.dexer) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2184 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2187 | func (j *Import) commonBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2188 | j.sdkVersion = j.SdkVersion(ctx) |
| 2189 | j.minSdkVersion = j.MinSdkVersion(ctx) |
| 2190 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2191 | if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { |
| 2192 | j.hideApexVariantFromMake = true |
| 2193 | } |
| 2194 | |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 2195 | if ctx.Windows() { |
| 2196 | j.HideFromMake() |
| 2197 | } |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2201 | j.commonBuildActions(ctx) |
Dan Willemsen | 8e6b371 | 2021-09-20 23:11:24 -0700 | [diff] [blame] | 2202 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 2203 | jars := android.PathsForModuleSrc(ctx, j.properties.Jars) |
Colin Cross | e1d62a8 | 2015-04-03 16:53:05 -0700 | [diff] [blame] | 2204 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2205 | jarName := j.Stem() + ".jar" |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2206 | outputFile := android.PathForModuleOut(ctx, "combined", jarName) |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2207 | TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{}, |
| 2208 | false, j.properties.Exclude_files, j.properties.Exclude_dirs) |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 2209 | if Bool(j.properties.Jetifier) { |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 2210 | inputFile := outputFile |
| 2211 | outputFile = android.PathForModuleOut(ctx, "jetifier", jarName) |
| 2212 | TransformJetifier(ctx, outputFile, inputFile) |
| 2213 | } |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 2214 | j.combinedClasspathFile = outputFile |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 2215 | j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2216 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2217 | var flags javaBuilderFlags |
| 2218 | |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 2219 | j.collectTransitiveHeaderJars(ctx) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2220 | ctx.VisitDirectDeps(func(module android.Module) { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2221 | tag := ctx.OtherModuleDependencyTag(module) |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2222 | if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { |
| 2223 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2224 | switch tag { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2225 | case libTag, sdkLibTag: |
Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 2226 | flags.classpath = append(flags.classpath, dep.HeaderJars...) |
| 2227 | flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...) |
| 2228 | case staticLibTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2229 | flags.classpath = append(flags.classpath, dep.HeaderJars...) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2230 | case bootClasspathTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2231 | flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2232 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2233 | } else if dep, ok := module.(SdkLibraryDependency); ok { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2234 | switch tag { |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2235 | case libTag, sdkLibTag: |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2236 | flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2237 | } |
| 2238 | } |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2239 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2240 | addCLCFromDep(ctx, module, j.classLoaderContexts) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2241 | }) |
| 2242 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2243 | j.maybeInstall(ctx, jarName, outputFile) |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 2244 | |
| 2245 | j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2246 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2247 | if ctx.Device() { |
| 2248 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar |
| 2249 | // obtained from the associated deapexer module. |
| 2250 | ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 2251 | if ai.ForPrebuiltApex { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2252 | // Get the path of the dex implementation jar from the `deapexer` module. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2253 | di := android.FindDeapexerProviderForModule(ctx) |
| 2254 | if di == nil { |
| 2255 | return // An error has been reported by FindDeapexerProviderForModule. |
| 2256 | } |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2257 | dexJarFileApexRootRelative := apexRootRelativePathToJavaLib(j.BaseModuleName()) |
| 2258 | if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2259 | dexJarFile := makeDexJarPathFromPath(dexOutputPath) |
| 2260 | j.dexJarFile = dexJarFile |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 2261 | installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName())) |
| 2262 | j.dexJarInstallFile = installPath |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 2263 | |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 2264 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 2265 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 2266 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2267 | |
| 2268 | if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { |
| 2269 | j.dexpreopter.inputProfilePathOnHost = profilePath |
| 2270 | } |
| 2271 | |
Jiakai Zhang | 5b24f72 | 2021-09-30 09:32:57 +0000 | [diff] [blame] | 2272 | j.dexpreopt(ctx, dexOutputPath) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 2273 | |
| 2274 | // Initialize the hiddenapi structure. |
| 2275 | j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex) |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 2276 | } else { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2277 | // This should never happen as a variant for a prebuilt_apex is only created if the |
| 2278 | // prebuilt_apex has been configured to export the java library dex file. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2279 | ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName()) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2280 | } |
| 2281 | } else if Bool(j.dexProperties.Compile_dex) { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2282 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2283 | if sdkDep.invalidVersion { |
| 2284 | ctx.AddMissingDependencies(sdkDep.bootclasspath) |
| 2285 | ctx.AddMissingDependencies(sdkDep.java9Classpath) |
| 2286 | } else if sdkDep.useFiles { |
| 2287 | // sdkDep.jar is actually equivalent to turbine header.jar. |
| 2288 | flags.classpath = append(flags.classpath, sdkDep.jars...) |
| 2289 | } |
| 2290 | |
| 2291 | // Dex compilation |
| 2292 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 2293 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 2294 | ctx, android.PathForModuleInstall(ctx, "framework", jarName)) |
Jiakai Zhang | 22450f2 | 2021-10-11 03:05:20 +0000 | [diff] [blame] | 2295 | setUncompressDex(ctx, &j.dexpreopter, &j.dexer) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2296 | j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex |
| 2297 | |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame] | 2298 | var dexOutputFile android.OutputPath |
Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 2299 | dexParams := &compileDexParams{ |
| 2300 | flags: flags, |
| 2301 | sdkVersion: j.SdkVersion(ctx), |
| 2302 | minSdkVersion: j.MinSdkVersion(ctx), |
| 2303 | classesJar: outputFile, |
| 2304 | jarName: jarName, |
| 2305 | } |
| 2306 | |
| 2307 | dexOutputFile = j.dexer.compileDex(ctx, dexParams) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2308 | if ctx.Failed() { |
| 2309 | return |
| 2310 | } |
| 2311 | |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 2312 | // Initialize the hiddenapi structure. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2313 | j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), outputFile, j.dexProperties.Uncompress_dex) |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 2314 | |
| 2315 | // Encode hidden API flags in dex file. |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 2316 | dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 2317 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2318 | j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2319 | j.dexJarInstallFile = android.PathForModuleInstall(ctx, "framework", jarName) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2320 | } |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2321 | } |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2322 | |
| 2323 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 2324 | HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile), |
Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 2325 | TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, |
| 2326 | TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2327 | ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile), |
| 2328 | ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile), |
| 2329 | AidlIncludeDirs: j.exportAidlIncludeDirs, |
Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 2330 | // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 2331 | }) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2334 | func (j *Import) maybeInstall(ctx android.ModuleContext, jarName string, outputFile android.Path) { |
| 2335 | if !Bool(j.properties.Installable) { |
| 2336 | return |
| 2337 | } |
| 2338 | |
| 2339 | var installDir android.InstallPath |
| 2340 | if ctx.InstallInTestcases() { |
| 2341 | var archDir string |
| 2342 | if !ctx.Host() { |
| 2343 | archDir = ctx.DeviceConfig().DeviceArch() |
| 2344 | } |
| 2345 | installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir) |
| 2346 | } else { |
| 2347 | installDir = android.PathForModuleInstall(ctx, "framework") |
| 2348 | } |
| 2349 | ctx.InstallFile(installDir, jarName, outputFile) |
| 2350 | } |
| 2351 | |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 2352 | func (j *Import) OutputFiles(tag string) (android.Paths, error) { |
| 2353 | switch tag { |
Saeid Farivar Asanjan | 128fe5c | 2020-10-15 17:54:40 +0000 | [diff] [blame] | 2354 | case "", ".jar": |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 2355 | return android.Paths{j.combinedClasspathFile}, nil |
| 2356 | default: |
| 2357 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | var _ android.OutputFileProducer = (*Import)(nil) |
| 2362 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 2363 | func (j *Import) HeaderJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2364 | if j.combinedClasspathFile == nil { |
| 2365 | return nil |
| 2366 | } |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 2367 | return android.Paths{j.combinedClasspathFile} |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 2370 | func (j *Import) ImplementationAndResourcesJars() android.Paths { |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2371 | if j.combinedClasspathFile == nil { |
| 2372 | return nil |
| 2373 | } |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 2374 | return android.Paths{j.combinedClasspathFile} |
| 2375 | } |
| 2376 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2377 | func (j *Import) DexJarBuildPath() OptionalDexJarPath { |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2378 | return j.dexJarFile |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 2379 | } |
| 2380 | |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 2381 | func (j *Import) DexJarInstallPath() android.Path { |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2382 | return j.dexJarInstallFile |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 2383 | } |
| 2384 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 2385 | func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
| 2386 | return j.classLoaderContexts |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 2387 | } |
| 2388 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2389 | var _ android.ApexModule = (*Import)(nil) |
| 2390 | |
| 2391 | // Implements android.ApexModule |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2392 | func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
Paul Duffin | 0d3c2e1 | 2020-05-17 08:34:50 +0100 | [diff] [blame] | 2393 | return j.depIsInSameApex(ctx, dep) |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2394 | } |
| 2395 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2396 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2397 | func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2398 | sdkVersion android.ApiLevel) error { |
Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2399 | sdkVersionSpec := j.SdkVersion(ctx) |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2400 | minSdkVersion := j.MinSdkVersion(ctx) |
| 2401 | if !minSdkVersion.Specified() { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2402 | return fmt.Errorf("min_sdk_version is not specified") |
| 2403 | } |
Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2404 | // If the module is compiling against core (via sdk_version), skip comparison check. |
| 2405 | if sdkVersionSpec.Kind == android.SdkCore { |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2406 | return nil |
| 2407 | } |
Spandan Das | 7fa982c | 2023-02-24 18:38:56 +0000 | [diff] [blame] | 2408 | if minSdkVersion.GreaterThan(sdkVersion) { |
| 2409 | return fmt.Errorf("newer SDK(%v)", minSdkVersion) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2410 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2411 | return nil |
| 2412 | } |
| 2413 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2414 | // requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or |
| 2415 | // java_sdk_library_import with the specified base module name requires to be exported from a |
| 2416 | // prebuilt_apex/apex_set. |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2417 | func requiredFilesFromPrebuiltApexForImport(name string, d *dexpreopter) []string { |
| 2418 | dexJarFileApexRootRelative := apexRootRelativePathToJavaLib(name) |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 2419 | // Add the dex implementation jar to the set of exported files. |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2420 | files := []string{ |
| 2421 | dexJarFileApexRootRelative, |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2422 | } |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2423 | if BoolDefault(d.importDexpreoptProperties.Dex_preopt.Profile_guided, false) { |
| 2424 | files = append(files, dexJarFileApexRootRelative+".prof") |
| 2425 | } |
| 2426 | return files |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 2429 | // apexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for |
| 2430 | // the java library with the specified name. |
| 2431 | func apexRootRelativePathToJavaLib(name string) string { |
| 2432 | return filepath.Join("javalib", name+".jar") |
| 2433 | } |
| 2434 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2435 | var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil) |
| 2436 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 2437 | func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string { |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2438 | name := j.BaseModuleName() |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2439 | return requiredFilesFromPrebuiltApexForImport(name, &j.dexpreopter) |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2440 | } |
| 2441 | |
albaltai | 36ff7dc | 2018-12-25 14:35:23 +0800 | [diff] [blame] | 2442 | // Add compile time check for interface implementation |
| 2443 | var _ android.IDEInfo = (*Import)(nil) |
| 2444 | var _ android.IDECustomizedModuleName = (*Import)(nil) |
| 2445 | |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 2446 | // Collect information for opening IDE project files in java/jdeps.go. |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 2447 | |
| 2448 | func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { |
| 2449 | dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...) |
| 2450 | } |
| 2451 | |
| 2452 | func (j *Import) IDECustomizedModuleName() string { |
| 2453 | // TODO(b/113562217): Extract the base module name from the Import name, often the Import name |
| 2454 | // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better |
| 2455 | // solution to get the Import name. |
Ulya Trafimovich | 497a093 | 2021-07-14 16:35:33 +0100 | [diff] [blame] | 2456 | return android.RemoveOptionalPrebuiltPrefix(j.Name()) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2459 | var _ android.PrebuiltInterface = (*Import)(nil) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2460 | |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 2461 | func (j *Import) IsInstallable() bool { |
| 2462 | return Bool(j.properties.Installable) |
| 2463 | } |
| 2464 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 2465 | var _ DexpreopterInterface = (*Import)(nil) |
Bill Peckham | ff89ffa | 2020-12-23 16:13:04 -0800 | [diff] [blame] | 2466 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2467 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module. |
| 2468 | // |
| 2469 | // By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were |
| 2470 | // compiled against an Android classpath. |
| 2471 | // |
| 2472 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 2473 | // for host modules. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2474 | func ImportFactory() android.Module { |
| 2475 | module := &Import{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2476 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2477 | module.AddProperties( |
| 2478 | &module.properties, |
| 2479 | &module.dexer.dexProperties, |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2480 | &module.importDexpreoptProperties, |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2481 | ) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2482 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2483 | module.initModuleAndImport(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2484 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 2485 | module.dexProperties.Optimize.EnabledByDefault = false |
| 2486 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2487 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2488 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2489 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2490 | return module |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2493 | // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host |
| 2494 | // module. |
| 2495 | // |
| 2496 | // A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were |
| 2497 | // compiled against a host bootclasspath. |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2498 | func ImportFactoryHost() android.Module { |
| 2499 | module := &Import{} |
| 2500 | |
| 2501 | module.AddProperties(&module.properties) |
| 2502 | |
| 2503 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2504 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2505 | InitJavaModule(module, android.HostSupported) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 2506 | return module |
| 2507 | } |
| 2508 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2509 | // dex_import module |
| 2510 | |
| 2511 | type DexImportProperties struct { |
Colin Cross | 5cfc70d | 2019-07-15 13:36:55 -0700 | [diff] [blame] | 2512 | Jars []string `android:"path"` |
Jiyong Park | 4c4c024 | 2019-10-21 14:53:15 +0900 | [diff] [blame] | 2513 | |
| 2514 | // set the name of the output |
| 2515 | Stem *string |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | type DexImport struct { |
| 2519 | android.ModuleBase |
| 2520 | android.DefaultableModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2521 | android.ApexModuleBase |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2522 | prebuilt android.Prebuilt |
| 2523 | |
| 2524 | properties DexImportProperties |
| 2525 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2526 | dexJarFile OptionalDexJarPath |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2527 | |
| 2528 | dexpreopter |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2529 | |
| 2530 | hideApexVariantFromMake bool |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | func (j *DexImport) Prebuilt() *android.Prebuilt { |
| 2534 | return &j.prebuilt |
| 2535 | } |
| 2536 | |
| 2537 | func (j *DexImport) PrebuiltSrcs() []string { |
| 2538 | return j.properties.Jars |
| 2539 | } |
| 2540 | |
| 2541 | func (j *DexImport) Name() string { |
| 2542 | return j.prebuilt.Name(j.ModuleBase.Name()) |
| 2543 | } |
| 2544 | |
Jiyong Park | 0b23875 | 2019-10-29 11:23:10 +0900 | [diff] [blame] | 2545 | func (j *DexImport) Stem() string { |
| 2546 | return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) |
| 2547 | } |
| 2548 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 2549 | func (a *DexImport) JacocoReportClassesFile() android.Path { |
| 2550 | return nil |
| 2551 | } |
| 2552 | |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2553 | func (a *DexImport) LintDepSets() LintDepSets { |
| 2554 | return LintDepSets{} |
| 2555 | } |
| 2556 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 2557 | func (j *DexImport) IsInstallable() bool { |
| 2558 | return true |
| 2559 | } |
| 2560 | |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2561 | func (j *DexImport) getStrictUpdatabilityLinting() bool { |
| 2562 | return false |
| 2563 | } |
| 2564 | |
| 2565 | func (j *DexImport) setStrictUpdatabilityLinting(bool) { |
| 2566 | } |
| 2567 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2568 | func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2569 | if len(j.properties.Jars) != 1 { |
| 2570 | ctx.PropertyErrorf("jars", "exactly one jar must be provided") |
| 2571 | } |
| 2572 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2573 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 2574 | if !apexInfo.IsForPlatform() { |
| 2575 | j.hideApexVariantFromMake = true |
| 2576 | } |
| 2577 | |
Jiakai Zhang | 519c5c8 | 2021-09-16 06:15:39 +0000 | [diff] [blame] | 2578 | j.dexpreopter.installPath = j.dexpreopter.getInstallPath( |
| 2579 | ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2580 | j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) |
| 2581 | |
| 2582 | inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") |
| 2583 | dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") |
| 2584 | |
| 2585 | if j.dexpreopter.uncompressedDex { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2586 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2587 | |
| 2588 | temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned") |
| 2589 | rule.Temporary(temporary) |
| 2590 | |
| 2591 | // use zip2zip to uncompress classes*.dex files |
| 2592 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2593 | BuiltTool("zip2zip"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2594 | FlagWithInput("-i ", inputJar). |
| 2595 | FlagWithOutput("-o ", temporary). |
| 2596 | FlagWithArg("-0 ", "'classes*.dex'") |
| 2597 | |
| 2598 | // use zipalign to align uncompressed classes*.dex files |
| 2599 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2600 | BuiltTool("zipalign"). |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2601 | Flag("-f"). |
| 2602 | Text("4"). |
| 2603 | Input(temporary). |
| 2604 | Output(dexOutputFile) |
| 2605 | |
| 2606 | rule.DeleteTemporaryFiles() |
| 2607 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 2608 | rule.Build("uncompress_dex", "uncompress dex") |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2609 | } else { |
| 2610 | ctx.Build(pctx, android.BuildParams{ |
| 2611 | Rule: android.Cp, |
| 2612 | Input: inputJar, |
| 2613 | Output: dexOutputFile, |
| 2614 | }) |
| 2615 | } |
| 2616 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2617 | j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2618 | |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 2619 | j.dexpreopt(ctx, dexOutputFile) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2620 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2621 | if apexInfo.IsForPlatform() { |
Jiyong Park | 01bca75 | 2020-06-08 19:24:09 +0900 | [diff] [blame] | 2622 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), |
| 2623 | j.Stem()+".jar", dexOutputFile) |
| 2624 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2625 | } |
| 2626 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2627 | func (j *DexImport) DexJarBuildPath() OptionalDexJarPath { |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2628 | return j.dexJarFile |
| 2629 | } |
| 2630 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2631 | var _ android.ApexModule = (*DexImport)(nil) |
| 2632 | |
| 2633 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2634 | func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2635 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2636 | // we don't check prebuilt modules for sdk_version |
| 2637 | return nil |
| 2638 | } |
| 2639 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2640 | // dex_import imports a `.jar` file containing classes.dex files. |
| 2641 | // |
| 2642 | // A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed |
| 2643 | // to the device. |
| 2644 | func DexImportFactory() android.Module { |
| 2645 | module := &DexImport{} |
| 2646 | |
| 2647 | module.AddProperties(&module.properties) |
| 2648 | |
| 2649 | android.InitPrebuiltModule(module, &module.properties.Jars) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2650 | android.InitApexModule(module) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2651 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2652 | return module |
| 2653 | } |
| 2654 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2655 | // Defaults |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2656 | type Defaults struct { |
| 2657 | android.ModuleBase |
| 2658 | android.DefaultsModuleBase |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 2659 | android.ApexModuleBase |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2662 | // java_defaults provides a set of properties that can be inherited by other java or android modules. |
| 2663 | // |
| 2664 | // A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each |
| 2665 | // property in the defaults module that exists in the depending module will be prepended to the depending module's |
| 2666 | // value for that property. |
| 2667 | // |
| 2668 | // Example: |
| 2669 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2670 | // java_defaults { |
| 2671 | // name: "example_defaults", |
| 2672 | // srcs: ["common/**/*.java"], |
| 2673 | // javacflags: ["-Xlint:all"], |
| 2674 | // aaptflags: ["--auto-add-overlay"], |
| 2675 | // } |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2676 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2677 | // java_library { |
| 2678 | // name: "example", |
| 2679 | // defaults: ["example_defaults"], |
| 2680 | // srcs: ["example/**/*.java"], |
| 2681 | // } |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 2682 | // |
| 2683 | // is functionally identical to: |
| 2684 | // |
Sam Delmerico | 277795c | 2022-02-25 17:04:37 +0000 | [diff] [blame] | 2685 | // java_library { |
| 2686 | // name: "example", |
| 2687 | // srcs: [ |
| 2688 | // "common/**/*.java", |
| 2689 | // "example/**/*.java", |
| 2690 | // ], |
| 2691 | // javacflags: ["-Xlint:all"], |
| 2692 | // } |
Paul Duffin | 4735766 | 2019-12-05 14:07:14 +0000 | [diff] [blame] | 2693 | func DefaultsFactory() android.Module { |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2694 | module := &Defaults{} |
| 2695 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2696 | module.AddProperties( |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 2697 | &CommonProperties{}, |
| 2698 | &DeviceProperties{}, |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 2699 | &OverridableDeviceProperties{}, |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 2700 | &DexProperties{}, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 2701 | &DexpreoptProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 2702 | &android.ProtoProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2703 | &aaptProperties{}, |
| 2704 | &androidLibraryProperties{}, |
| 2705 | &appProperties{}, |
| 2706 | &appTestProperties{}, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2707 | &overridableAppProperties{}, |
Kun Niu | bd0fd20 | 2023-05-23 17:51:44 +0000 | [diff] [blame] | 2708 | &hostTestProperties{}, |
Roland Levillain | b5b0ff3 | 2020-02-04 15:45:49 +0000 | [diff] [blame] | 2709 | &testProperties{}, |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 2710 | &ImportProperties{}, |
| 2711 | &AARImportProperties{}, |
| 2712 | &sdkLibraryProperties{}, |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2713 | &commonToSdkLibraryAndImportProperties{}, |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 2714 | &DexImportProperties{}, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 2715 | &android.ApexProperties{}, |
Jaewoong Jung | bf13546 | 2020-04-26 15:10:51 -0700 | [diff] [blame] | 2716 | &RuntimeResourceOverlayProperties{}, |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 2717 | &LintProperties{}, |
Colin Cross | cbce0b0 | 2021-02-09 10:38:30 -0800 | [diff] [blame] | 2718 | &appTestHelperAppProperties{}, |
Jihoon Kang | 1c51f50 | 2023-01-09 23:42:40 +0000 | [diff] [blame] | 2719 | &JavaApiLibraryProperties{}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2720 | ) |
| 2721 | |
| 2722 | android.InitDefaultsModule(module) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 2723 | return module |
| 2724 | } |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2725 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2726 | func kytheExtractJavaFactory() android.Singleton { |
| 2727 | return &kytheExtractJavaSingleton{} |
| 2728 | } |
| 2729 | |
| 2730 | type kytheExtractJavaSingleton struct { |
| 2731 | } |
| 2732 | |
| 2733 | func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 2734 | var xrefTargets android.Paths |
| 2735 | ctx.VisitAllModules(func(module android.Module) { |
| 2736 | if javaModule, ok := module.(xref); ok { |
| 2737 | xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) |
| 2738 | } |
| 2739 | }) |
| 2740 | // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets |
| 2741 | if len(xrefTargets) > 0 { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 2742 | ctx.Phony("xref_java", xrefTargets...) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 2743 | } |
| 2744 | } |
| 2745 | |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2746 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2747 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 2748 | var String = proptools.String |
Sam Delmerico | 1717b3b | 2023-07-18 15:07:24 -0400 | [diff] [blame] | 2749 | var inList = android.InList[string] |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2750 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2751 | // Add class loader context (CLC) of a given dependency to the current CLC. |
| 2752 | func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, |
| 2753 | clcMap dexpreopt.ClassLoaderContextMap) { |
| 2754 | |
| 2755 | dep, ok := depModule.(UsesLibraryDependency) |
| 2756 | if !ok { |
| 2757 | return |
| 2758 | } |
| 2759 | |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2760 | depName := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(depModule)) |
| 2761 | |
| 2762 | var sdkLib *string |
| 2763 | if lib, ok := depModule.(SdkLibraryDependency); ok && lib.sharedLibrary() { |
| 2764 | // A shared SDK library. This should be added as a top-level CLC element. |
| 2765 | sdkLib = &depName |
| 2766 | } else if ulib, ok := depModule.(ProvidesUsesLib); ok { |
| 2767 | // A non-SDK library disguised as an SDK library by the means of `provides_uses_lib` |
| 2768 | // property. This should be handled in the same way as a shared SDK library. |
| 2769 | sdkLib = ulib.ProvidesUsesLib() |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2770 | } |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2771 | |
| 2772 | depTag := ctx.OtherModuleDependencyTag(depModule) |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 2773 | if IsLibDepTag(depTag) { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2774 | // Ok, propagate <uses-library> through non-static library dependencies. |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 2775 | } else if tag, ok := depTag.(usesLibraryDependencyTag); ok && tag.sdkVersion == dexpreopt.AnySdkVersion { |
| 2776 | // Ok, propagate <uses-library> through non-compatibility <uses-library> dependencies. |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2777 | } else if depTag == staticLibTag { |
| 2778 | // Propagate <uses-library> through static library dependencies, unless it is a component |
| 2779 | // library (such as stubs). Component libraries have a dependency on their SDK library, |
| 2780 | // which should not be pulled just because of a static component library. |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2781 | if sdkLib != nil { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2782 | return |
| 2783 | } |
| 2784 | } else { |
| 2785 | // Don't propagate <uses-library> for other dependency tags. |
| 2786 | return |
| 2787 | } |
| 2788 | |
Ulya Trafimovich | 840efb6 | 2021-07-15 14:34:40 +0100 | [diff] [blame] | 2789 | // If this is an SDK (or SDK-like) library, then it should be added as a node in the CLC tree, |
| 2790 | // and its CLC should be added as subtree of that node. Otherwise the library is not a |
| 2791 | // <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies |
| 2792 | // from its CLC should be added to the current CLC. |
| 2793 | if sdkLib != nil { |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 2794 | clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false, |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2795 | dep.DexJarBuildPath().PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts()) |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2796 | } else { |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 2797 | clcMap.AddContextMap(dep.ClassLoaderContexts(), depName) |
| 2798 | } |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 2799 | } |
Wei Li | bafb6d6 | 2021-12-10 03:14:59 -0800 | [diff] [blame] | 2800 | |
Jihoon Kang | fdf3236 | 2023-09-12 00:36:43 +0000 | [diff] [blame] | 2801 | type JavaApiContributionImport struct { |
| 2802 | JavaApiContribution |
| 2803 | |
| 2804 | prebuilt android.Prebuilt |
| 2805 | } |
| 2806 | |
| 2807 | func ApiContributionImportFactory() android.Module { |
| 2808 | module := &JavaApiContributionImport{} |
| 2809 | android.InitAndroidModule(module) |
| 2810 | android.InitDefaultableModule(module) |
| 2811 | android.InitPrebuiltModule(module, &[]string{""}) |
| 2812 | module.AddProperties(&module.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2813 | module.AddProperties(&module.sdkLibraryComponentProperties) |
Jihoon Kang | fdf3236 | 2023-09-12 00:36:43 +0000 | [diff] [blame] | 2814 | return module |
| 2815 | } |
| 2816 | |
| 2817 | func (module *JavaApiContributionImport) Prebuilt() *android.Prebuilt { |
| 2818 | return &module.prebuilt |
| 2819 | } |
| 2820 | |
| 2821 | func (module *JavaApiContributionImport) Name() string { |
| 2822 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 2823 | } |
| 2824 | |
| 2825 | func (ap *JavaApiContributionImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2826 | ap.JavaApiContribution.GenerateAndroidBuildActions(ctx) |
| 2827 | } |