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