Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 api |
| 16 | |
| 17 | import ( |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 18 | "sort" |
| 19 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
| 21 | |
| 22 | "android/soong/android" |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 23 | "android/soong/bazel" |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 24 | "android/soong/genrule" |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 25 | "android/soong/java" |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 26 | ) |
| 27 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 28 | const art = "art.module.public.api" |
| 29 | const conscrypt = "conscrypt.module.public.api" |
| 30 | const i18n = "i18n.module.public.api" |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 31 | const virtualization = "framework-virtualization" |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 32 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 33 | var core_libraries_modules = []string{art, conscrypt, i18n} |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 34 | |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 35 | // List of modules that are not yet updatable, and hence they can still compile |
| 36 | // against hidden APIs. These modules are filtered out when building the |
| 37 | // updatable-framework-module-impl (because updatable-framework-module-impl is |
| 38 | // built against module_current SDK). Instead they are directly statically |
| 39 | // linked into the all-framework-module-lib, which is building against hidden |
| 40 | // APIs. |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 41 | // In addition, the modules in this list are allowed to contribute to test APIs |
| 42 | // stubs. |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 43 | var non_updatable_modules = []string{virtualization} |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 44 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 45 | // The intention behind this soong plugin is to generate a number of "merged" |
| 46 | // API-related modules that would otherwise require a large amount of very |
| 47 | // similar Android.bp boilerplate to define. For example, the merged current.txt |
| 48 | // API definitions (created by merging the non-updatable current.txt with all |
| 49 | // the module current.txts). This simplifies the addition of new android |
| 50 | // modules, by reducing the number of genrules etc a new module must be added to. |
| 51 | |
| 52 | // The properties of the combined_apis module type. |
| 53 | type CombinedApisProperties struct { |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 54 | // Module libraries in the bootclasspath |
| 55 | Bootclasspath []string |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 56 | // Module libraries on the bootclasspath if include_nonpublic_framework_api is true. |
| 57 | Conditional_bootclasspath []string |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 58 | // Module libraries in system server |
| 59 | System_server_classpath []string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | type CombinedApis struct { |
| 63 | android.ModuleBase |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 64 | android.BazelModuleBase |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 65 | |
| 66 | properties CombinedApisProperties |
| 67 | } |
| 68 | |
| 69 | func init() { |
| 70 | registerBuildComponents(android.InitRegistrationContext) |
| 71 | } |
| 72 | |
| 73 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 74 | ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory) |
| 75 | } |
| 76 | |
| 77 | var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents) |
| 78 | |
| 79 | func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 80 | } |
| 81 | |
| 82 | type genruleProps struct { |
| 83 | Name *string |
| 84 | Cmd *string |
| 85 | Dists []android.Dist |
| 86 | Out []string |
| 87 | Srcs []string |
| 88 | Tools []string |
| 89 | Visibility []string |
| 90 | } |
| 91 | |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 92 | type libraryProps struct { |
| 93 | Name *string |
| 94 | Sdk_version *string |
| 95 | Static_libs []string |
| 96 | Visibility []string |
| 97 | } |
| 98 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 99 | type fgProps struct { |
| 100 | Name *string |
| 101 | Srcs []string |
| 102 | Visibility []string |
| 103 | } |
| 104 | |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 105 | type Bazel_module struct { |
| 106 | Bp2build_available *bool |
| 107 | } |
| 108 | type bazelProperties struct { |
| 109 | *Bazel_module |
| 110 | } |
| 111 | |
| 112 | var bp2buildNotAvailable = bazelProperties{ |
| 113 | &Bazel_module{ |
| 114 | Bp2build_available: proptools.BoolPtr(false), |
| 115 | }, |
| 116 | } |
| 117 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 118 | // Struct to pass parameters for the various merged [current|removed].txt file modules we create. |
| 119 | type MergedTxtDefinition struct { |
| 120 | // "current.txt" or "removed.txt" |
| 121 | TxtFilename string |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 122 | // Filename in the new dist dir. "android.txt" or "android-removed.txt" |
| 123 | DistFilename string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 124 | // The module for the non-updatable / non-module part of the api. |
| 125 | BaseTxt string |
| 126 | // The list of modules that are relevant for this merged txt. |
| 127 | Modules []string |
| 128 | // The output tag for each module to use.e.g. {.public.api.txt} for current.txt |
| 129 | ModuleTag string |
| 130 | // public, system, module-lib or system-server |
| 131 | Scope string |
| 132 | } |
| 133 | |
| 134 | func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { |
| 135 | metalavaCmd := "$(location metalava)" |
| 136 | // Silence reflection warnings. See b/168689341 |
| 137 | metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " |
| 138 | metalavaCmd += " --quiet --no-banner --format=v2 " |
| 139 | |
| 140 | filename := txt.TxtFilename |
| 141 | if txt.Scope != "public" { |
| 142 | filename = txt.Scope + "-" + filename |
| 143 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 144 | props := genruleProps{} |
| 145 | props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename) |
| 146 | props.Tools = []string{"metalava"} |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 147 | props.Out = []string{filename} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 148 | props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 149 | props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 150 | props.Dists = []android.Dist{ |
| 151 | { |
| 152 | Targets: []string{"droidcore"}, |
| 153 | Dir: proptools.StringPtr("api"), |
| 154 | Dest: proptools.StringPtr(filename), |
| 155 | }, |
| 156 | { |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 157 | Targets: []string{"api_txt", "sdk"}, |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 158 | Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"), |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 159 | Dest: proptools.StringPtr(txt.DistFilename), |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 160 | }, |
| 161 | } |
| 162 | props.Visibility = []string{"//visibility:public"} |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 163 | ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 166 | func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { |
| 167 | for _, i := range []struct{ |
| 168 | name string |
| 169 | tag string |
| 170 | modules []string |
| 171 | }{ |
| 172 | { |
| 173 | name: "all-modules-public-annotations", |
| 174 | tag: "{.public.annotations.zip}", |
| 175 | modules: modules, |
| 176 | }, { |
| 177 | name: "all-modules-system-annotations", |
| 178 | tag: "{.system.annotations.zip}", |
| 179 | modules: modules, |
| 180 | }, { |
| 181 | name: "all-modules-module-lib-annotations", |
| 182 | tag: "{.module-lib.annotations.zip}", |
| 183 | modules: modules, |
| 184 | }, { |
| 185 | name: "all-modules-system-server-annotations", |
| 186 | tag: "{.system-server.annotations.zip}", |
| 187 | modules: system_server_modules, |
| 188 | }, |
| 189 | } { |
| 190 | props := fgProps{} |
| 191 | props.Name = proptools.StringPtr(i.name) |
| 192 | props.Srcs = createSrcs(i.modules, i.tag) |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 193 | ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 194 | } |
Anton Hansson | 74b1564 | 2022-06-23 08:27:23 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 197 | func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 198 | // For the filtered api versions, we prune all APIs except art module's APIs. because |
| 199 | // 1) ART apis are available by default to all modules, while other module-to-module deps are |
| 200 | // explicit and probably receive more scrutiny anyway |
| 201 | // 2) The number of ART/libcore APIs is large, so not linting them would create a large gap |
| 202 | // 3) It's a compromise. Ideally we wouldn't be filtering out any module APIs, and have |
| 203 | // per-module lint databases that excludes just that module's APIs. Alas, that's more |
| 204 | // difficult to achieve. |
| 205 | modules = remove(modules, art) |
| 206 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 207 | for _, i := range []struct{ |
| 208 | name string |
| 209 | out string |
| 210 | in string |
| 211 | }{ |
| 212 | { |
| 213 | // We shouldn't need public-filtered or system-filtered. |
| 214 | // public-filtered is currently used to lint things that |
| 215 | // use the module sdk or the system server sdk, but those |
| 216 | // should be switched over to module-filtered and |
| 217 | // system-server-filtered, and then public-filtered can |
| 218 | // be removed. |
| 219 | name: "api-versions-xml-public-filtered", |
| 220 | out: "api-versions-public-filtered.xml", |
| 221 | in: ":api_versions_public{.api_versions.xml}", |
| 222 | }, { |
| 223 | name: "api-versions-xml-module-lib-filtered", |
| 224 | out: "api-versions-module-lib-filtered.xml", |
| 225 | in: ":api_versions_module_lib{.api_versions.xml}", |
| 226 | }, { |
| 227 | name: "api-versions-xml-system-server-filtered", |
| 228 | out: "api-versions-system-server-filtered.xml", |
| 229 | in: ":api_versions_system_server{.api_versions.xml}", |
| 230 | }, |
| 231 | } { |
| 232 | props := genruleProps{} |
| 233 | props.Name = proptools.StringPtr(i.name) |
| 234 | props.Out = []string{i.out} |
| 235 | // Note: order matters: first parameter is the full api-versions.xml |
| 236 | // after that the stubs files in any order |
| 237 | // stubs files are all modules that export API surfaces EXCEPT ART |
| 238 | props.Srcs = append([]string{i.in}, createSrcs(modules, ".stubs{.jar}")...) |
| 239 | props.Tools = []string{"api_versions_trimmer"} |
| 240 | props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)") |
| 241 | props.Dists = []android.Dist{{Targets: []string{"sdk"}}} |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 242 | ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 243 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 246 | func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) { |
| 247 | props := libraryProps{} |
| 248 | props.Name = proptools.StringPtr("all-modules-public-stubs") |
| 249 | props.Static_libs = transformArray(modules, "", ".stubs") |
| 250 | props.Sdk_version = proptools.StringPtr("module_current") |
| 251 | props.Visibility = []string{"//frameworks/base"} |
| 252 | ctx.CreateModule(java.LibraryFactory, &props) |
| 253 | } |
| 254 | |
| 255 | func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) { |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 256 | // First create the all-updatable-modules-system-stubs |
| 257 | { |
| 258 | updatable_modules := removeAll(modules, non_updatable_modules) |
| 259 | props := libraryProps{} |
| 260 | props.Name = proptools.StringPtr("all-updatable-modules-system-stubs") |
| 261 | props.Static_libs = transformArray(updatable_modules, "", ".stubs.system") |
| 262 | props.Sdk_version = proptools.StringPtr("module_current") |
| 263 | props.Visibility = []string{"//frameworks/base"} |
| 264 | ctx.CreateModule(java.LibraryFactory, &props) |
| 265 | } |
| 266 | // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules |
| 267 | // into all-modules-system-stubs. |
| 268 | { |
| 269 | props := libraryProps{} |
| 270 | props.Name = proptools.StringPtr("all-modules-system-stubs") |
| 271 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system") |
| 272 | props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs") |
| 273 | props.Sdk_version = proptools.StringPtr("module_current") |
| 274 | props.Visibility = []string{"//frameworks/base"} |
| 275 | ctx.CreateModule(java.LibraryFactory, &props) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) { |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 280 | props := libraryProps{} |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 281 | props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs") |
| 282 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test") |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 283 | props.Sdk_version = proptools.StringPtr("module_current") |
| 284 | props.Visibility = []string{"//frameworks/base"} |
| 285 | ctx.CreateModule(java.LibraryFactory, &props) |
| 286 | } |
| 287 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 288 | func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) { |
| 289 | // This module is for the "framework-all" module, which should not include the core libraries. |
| 290 | modules = removeAll(modules, core_libraries_modules) |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 291 | // Remove the modules that belong to non-updatable APEXes since those are allowed to compile |
| 292 | // against unstable APIs. |
| 293 | modules = removeAll(modules, non_updatable_modules) |
| 294 | // First create updatable-framework-module-impl, which contains all updatable modules. |
| 295 | // This module compiles against module_lib SDK. |
| 296 | { |
| 297 | props := libraryProps{} |
| 298 | props.Name = proptools.StringPtr("updatable-framework-module-impl") |
| 299 | props.Static_libs = transformArray(modules, "", ".impl") |
| 300 | props.Sdk_version = proptools.StringPtr("module_current") |
| 301 | props.Visibility = []string{"//frameworks/base"} |
| 302 | ctx.CreateModule(java.LibraryFactory, &props) |
| 303 | } |
| 304 | |
| 305 | // Now create all-framework-module-impl, which contains updatable-framework-module-impl |
| 306 | // and all non-updatable modules. This module compiles against hidden APIs. |
| 307 | { |
| 308 | props := libraryProps{} |
| 309 | props.Name = proptools.StringPtr("all-framework-module-impl") |
| 310 | props.Static_libs = transformArray(non_updatable_modules, "", ".impl") |
| 311 | props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl") |
| 312 | props.Sdk_version = proptools.StringPtr("core_platform") |
| 313 | props.Visibility = []string{"//frameworks/base"} |
| 314 | ctx.CreateModule(java.LibraryFactory, &props) |
| 315 | } |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 319 | // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes. |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 320 | modules = removeAll(modules, core_libraries_modules) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 321 | props := libraryProps{} |
| 322 | props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 323 | props.Static_libs = transformArray(modules, "", ".stubs.module_lib") |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 324 | props.Sdk_version = proptools.StringPtr("module_current") |
| 325 | props.Visibility = []string{"//frameworks/base"} |
| 326 | ctx.CreateModule(java.LibraryFactory, &props) |
| 327 | } |
| 328 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 329 | func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) { |
| 330 | props := fgProps{} |
| 331 | props.Name = proptools.StringPtr("all-modules-public-stubs-source") |
| 332 | props.Srcs = createSrcs(modules, "{.public.stubs.source}") |
| 333 | props.Visibility = []string{"//frameworks/base"} |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 334 | ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 337 | func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 338 | var textFiles []MergedTxtDefinition |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 339 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 340 | tagSuffix := []string{".api.txt}", ".removed-api.txt}"} |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 341 | distFilename := []string{"android.txt", "android-removed.txt"} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 342 | for i, f := range []string{"current.txt", "removed.txt"} { |
| 343 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 344 | TxtFilename: f, |
| 345 | DistFilename: distFilename[i], |
| 346 | BaseTxt: ":non-updatable-" + f, |
| 347 | Modules: bootclasspath, |
| 348 | ModuleTag: "{.public" + tagSuffix[i], |
| 349 | Scope: "public", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 350 | }) |
| 351 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 352 | TxtFilename: f, |
| 353 | DistFilename: distFilename[i], |
| 354 | BaseTxt: ":non-updatable-system-" + f, |
| 355 | Modules: bootclasspath, |
| 356 | ModuleTag: "{.system" + tagSuffix[i], |
| 357 | Scope: "system", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 358 | }) |
| 359 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 360 | TxtFilename: f, |
| 361 | DistFilename: distFilename[i], |
| 362 | BaseTxt: ":non-updatable-module-lib-" + f, |
| 363 | Modules: bootclasspath, |
| 364 | ModuleTag: "{.module-lib" + tagSuffix[i], |
| 365 | Scope: "module-lib", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 366 | }) |
| 367 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 368 | TxtFilename: f, |
| 369 | DistFilename: distFilename[i], |
| 370 | BaseTxt: ":non-updatable-system-server-" + f, |
| 371 | Modules: system_server_classpath, |
| 372 | ModuleTag: "{.system-server" + tagSuffix[i], |
| 373 | Scope: "system-server", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 374 | }) |
| 375 | } |
| 376 | for _, txt := range textFiles { |
| 377 | createMergedTxt(ctx, txt) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 382 | bootclasspath := a.properties.Bootclasspath |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 383 | system_server_classpath := a.properties.System_server_classpath |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 384 | if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") { |
| 385 | bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...) |
| 386 | sort.Strings(bootclasspath) |
| 387 | } |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 388 | createMergedTxts(ctx, bootclasspath, system_server_classpath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 389 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 390 | createMergedPublicStubs(ctx, bootclasspath) |
| 391 | createMergedSystemStubs(ctx, bootclasspath) |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 392 | createMergedTestStubsForNonUpdatableModules(ctx) |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 393 | createMergedFrameworkModuleLibStubs(ctx, bootclasspath) |
| 394 | createMergedFrameworkImpl(ctx, bootclasspath) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 395 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 396 | createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath) |
Anton Hansson | cc18e03 | 2022-01-12 14:45:22 +0000 | [diff] [blame] | 397 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 398 | createFilteredApiVersions(ctx, bootclasspath) |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 399 | |
| 400 | createPublicStubsSourceFilegroup(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | func combinedApisModuleFactory() android.Module { |
| 404 | module := &CombinedApis{} |
| 405 | module.AddProperties(&module.properties) |
| 406 | android.InitAndroidModule(module) |
| 407 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 408 | android.InitBazelModule(module) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 409 | return module |
| 410 | } |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 411 | |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame^] | 412 | type bazelCombinedApisAttributes struct { |
| 413 | Scope bazel.StringAttribute |
| 414 | Base bazel.LabelAttribute |
| 415 | Deps bazel.LabelListAttribute |
| 416 | } |
| 417 | |
| 418 | // combined_apis bp2build converter |
| 419 | func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
| 420 | basePrefix := "non-updatable" |
| 421 | scopeNames := []string{"public", "system", "module-lib", "system-server"} |
| 422 | scopeToSuffix := map[string]string{ |
| 423 | "public": "-current.txt", |
| 424 | "system": "-system-current.txt", |
| 425 | "module-lib": "-module-lib-current.txt", |
| 426 | "system-server": "-system-server-current.txt", |
| 427 | } |
| 428 | |
| 429 | for _, scopeName := range scopeNames{ |
| 430 | suffix := scopeToSuffix[scopeName] |
| 431 | name := a.Name() + suffix |
| 432 | |
| 433 | var scope bazel.StringAttribute |
| 434 | scope.SetValue(scopeName) |
| 435 | |
| 436 | var base bazel.LabelAttribute |
| 437 | base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix)) |
| 438 | |
| 439 | var deps bazel.LabelListAttribute |
| 440 | classpath := a.properties.Bootclasspath |
| 441 | if scopeName == "system-server" { |
| 442 | classpath = a.properties.System_server_classpath |
| 443 | } |
| 444 | deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath)) |
| 445 | |
| 446 | attrs := bazelCombinedApisAttributes{ |
| 447 | Scope: scope, |
| 448 | Base: base, |
| 449 | Deps: deps, |
| 450 | } |
| 451 | props := bazel.BazelTargetModuleProperties{ |
| 452 | Rule_class: "merged_txts", |
| 453 | Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl", |
| 454 | } |
| 455 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs) |
| 456 | } |
| 457 | } |
| 458 | |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 459 | // Various utility methods below. |
| 460 | |
| 461 | // Creates an array of ":<m><tag>" for each m in <modules>. |
| 462 | func createSrcs(modules []string, tag string) []string { |
| 463 | return transformArray(modules, ":", tag) |
| 464 | } |
| 465 | |
| 466 | // Creates an array of "<prefix><m><suffix>", for each m in <modules>. |
| 467 | func transformArray(modules []string, prefix, suffix string) []string { |
| 468 | a := make([]string, 0, len(modules)) |
| 469 | for _, module := range modules { |
| 470 | a = append(a, prefix+module+suffix) |
| 471 | } |
| 472 | return a |
| 473 | } |
| 474 | |
| 475 | func removeAll(s []string, vs []string) []string { |
| 476 | for _, v := range vs { |
| 477 | s = remove(s, v) |
| 478 | } |
| 479 | return s |
| 480 | } |
| 481 | |
| 482 | func remove(s []string, v string) []string { |
| 483 | s2 := make([]string, 0, len(s)) |
| 484 | for _, sv := range s { |
| 485 | if sv != v { |
| 486 | s2 = append(s2, sv) |
| 487 | } |
| 488 | } |
| 489 | return s2 |
| 490 | } |