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" |
| 23 | "android/soong/genrule" |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 24 | "android/soong/java" |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 25 | ) |
| 26 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 27 | const art = "art.module.public.api" |
| 28 | const conscrypt = "conscrypt.module.public.api" |
| 29 | const i18n = "i18n.module.public.api" |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 30 | const virtualization = "framework-virtualization" |
Mark White | 3cc5e00 | 2023-08-07 11:18:09 +0000 | [diff] [blame] | 31 | const location = "framework-location" |
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. |
Roshan Pius | 96dac95 | 2023-12-07 10:54:05 -0800 | [diff] [blame] | 43 | var non_updatable_modules = []string{virtualization, location} |
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 |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 55 | Bootclasspath proptools.Configurable[[]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 |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 59 | System_server_classpath proptools.Configurable[[]string] |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | type CombinedApis struct { |
| 63 | android.ModuleBase |
| 64 | |
| 65 | properties CombinedApisProperties |
| 66 | } |
| 67 | |
| 68 | func init() { |
| 69 | registerBuildComponents(android.InitRegistrationContext) |
| 70 | } |
| 71 | |
| 72 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 73 | ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory) |
| 74 | } |
| 75 | |
| 76 | var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents) |
| 77 | |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 78 | func (a *CombinedApis) bootclasspath(ctx android.ConfigAndErrorContext) []string { |
| 79 | return a.properties.Bootclasspath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil) |
| 80 | } |
| 81 | |
| 82 | func (a *CombinedApis) systemServerClasspath(ctx android.ConfigAndErrorContext) []string { |
| 83 | return a.properties.System_server_classpath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil) |
| 84 | } |
| 85 | |
| 86 | func (a *CombinedApis) apiFingerprintStubDeps(ctx android.BottomUpMutatorContext) []string { |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 87 | ret := []string{} |
| 88 | ret = append( |
| 89 | ret, |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 90 | transformArray(a.bootclasspath(ctx), "", ".stubs")..., |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 91 | ) |
| 92 | ret = append( |
| 93 | ret, |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 94 | transformArray(a.bootclasspath(ctx), "", ".stubs.system")..., |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 95 | ) |
| 96 | ret = append( |
| 97 | ret, |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 98 | transformArray(a.bootclasspath(ctx), "", ".stubs.module_lib")..., |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 99 | ) |
| 100 | ret = append( |
| 101 | ret, |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 102 | transformArray(a.systemServerClasspath(ctx), "", ".stubs.system_server")..., |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 103 | ) |
| 104 | return ret |
| 105 | } |
| 106 | |
| 107 | func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 108 | ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps(ctx)...) |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 111 | func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 67b7906 | 2024-02-12 11:40:51 +0000 | [diff] [blame] | 112 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 113 | if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" { |
| 114 | // Stubs of BCP and SSCP libraries should not have any dependencies on apps |
| 115 | // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true |
| 116 | ctx.ModuleErrorf( |
| 117 | "Module %s is not a valid dependency of the stub library %s\n."+ |
| 118 | "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n", |
| 119 | child.Name(), parent.Name()) |
| 120 | return false // error detected |
| 121 | } |
| 122 | return true |
| 123 | }) |
| 124 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | type genruleProps struct { |
| 128 | Name *string |
| 129 | Cmd *string |
| 130 | Dists []android.Dist |
| 131 | Out []string |
| 132 | Srcs []string |
| 133 | Tools []string |
| 134 | Visibility []string |
| 135 | } |
| 136 | |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 137 | type libraryProps struct { |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 138 | Name *string |
| 139 | Sdk_version *string |
| 140 | Static_libs []string |
| 141 | Visibility []string |
| 142 | Defaults []string |
| 143 | Is_stubs_module *bool |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 146 | type fgProps struct { |
| 147 | Name *string |
| 148 | Srcs []string |
| 149 | Visibility []string |
| 150 | } |
| 151 | |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 152 | type defaultsProps struct { |
| 153 | Name *string |
| 154 | Api_surface *string |
| 155 | Api_contributions []string |
| 156 | Defaults_visibility []string |
Jihoon Kang | 471a05b | 2023-08-01 06:37:17 +0000 | [diff] [blame] | 157 | Previous_api *string |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 160 | // Struct to pass parameters for the various merged [current|removed].txt file modules we create. |
| 161 | type MergedTxtDefinition struct { |
| 162 | // "current.txt" or "removed.txt" |
| 163 | TxtFilename string |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 164 | // Filename in the new dist dir. "android.txt" or "android-removed.txt" |
| 165 | DistFilename string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 166 | // The module for the non-updatable / non-module part of the api. |
| 167 | BaseTxt string |
| 168 | // The list of modules that are relevant for this merged txt. |
| 169 | Modules []string |
| 170 | // The output tag for each module to use.e.g. {.public.api.txt} for current.txt |
| 171 | ModuleTag string |
| 172 | // public, system, module-lib or system-server |
| 173 | Scope string |
| 174 | } |
| 175 | |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 176 | func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) { |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 177 | metalavaCmd := "$(location metalava)" |
| 178 | // Silence reflection warnings. See b/168689341 |
| 179 | metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " |
Paul Duffin | f3b1fc4 | 2023-08-14 22:03:06 +0100 | [diff] [blame] | 180 | metalavaCmd += " --quiet merge-signatures --format=v2 " |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 181 | |
| 182 | filename := txt.TxtFilename |
| 183 | if txt.Scope != "public" { |
| 184 | filename = txt.Scope + "-" + filename |
| 185 | } |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 186 | moduleName := ctx.ModuleName() + stubsTypeSuffix + filename |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame] | 187 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 188 | props := genruleProps{} |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame] | 189 | props.Name = proptools.StringPtr(moduleName) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 190 | props.Tools = []string{"metalava"} |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 191 | props.Out = []string{filename} |
Paul Duffin | f3b1fc4 | 2023-08-14 22:03:06 +0100 | [diff] [blame] | 192 | props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 193 | props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...) |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 194 | if doDist { |
| 195 | props.Dists = []android.Dist{ |
| 196 | { |
| 197 | Targets: []string{"droidcore"}, |
| 198 | Dir: proptools.StringPtr("api"), |
| 199 | Dest: proptools.StringPtr(filename), |
| 200 | }, |
| 201 | { |
| 202 | Targets: []string{"api_txt", "sdk"}, |
| 203 | Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"), |
| 204 | Dest: proptools.StringPtr(txt.DistFilename), |
| 205 | }, |
| 206 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 207 | } |
| 208 | props.Visibility = []string{"//visibility:public"} |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 209 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 212 | func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 213 | for _, i := range []struct { |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 214 | name string |
| 215 | tag string |
| 216 | modules []string |
| 217 | }{ |
| 218 | { |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 219 | name: "all-modules-public-annotations", |
| 220 | tag: "{.public.annotations.zip}", |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 221 | modules: modules, |
| 222 | }, { |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 223 | name: "all-modules-system-annotations", |
| 224 | tag: "{.system.annotations.zip}", |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 225 | modules: modules, |
| 226 | }, { |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 227 | name: "all-modules-module-lib-annotations", |
| 228 | tag: "{.module-lib.annotations.zip}", |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 229 | modules: modules, |
| 230 | }, { |
Jihoon Kang | 1e4ac1d | 2023-04-07 18:50:38 +0000 | [diff] [blame] | 231 | name: "all-modules-system-server-annotations", |
| 232 | tag: "{.system-server.annotations.zip}", |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 233 | modules: system_server_modules, |
| 234 | }, |
| 235 | } { |
| 236 | props := fgProps{} |
| 237 | props.Name = proptools.StringPtr(i.name) |
| 238 | props.Srcs = createSrcs(i.modules, i.tag) |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 239 | ctx.CreateModule(android.FileGroupFactory, &props) |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 240 | } |
Anton Hansson | 74b1564 | 2022-06-23 08:27:23 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 243 | func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) { |
| 244 | props := libraryProps{} |
| 245 | props.Name = proptools.StringPtr("all-modules-public-stubs") |
| 246 | props.Static_libs = transformArray(modules, "", ".stubs") |
| 247 | props.Sdk_version = proptools.StringPtr("module_current") |
| 248 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 249 | props.Is_stubs_module = proptools.BoolPtr(true) |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 250 | ctx.CreateModule(java.LibraryFactory, &props) |
| 251 | } |
| 252 | |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 253 | func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) { |
| 254 | props := libraryProps{} |
| 255 | props.Name = proptools.StringPtr("all-modules-public-stubs-exportable") |
| 256 | props.Static_libs = transformArray(modules, "", ".stubs.exportable") |
| 257 | props.Sdk_version = proptools.StringPtr("module_current") |
| 258 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 259 | props.Is_stubs_module = proptools.BoolPtr(true) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 260 | ctx.CreateModule(java.LibraryFactory, &props) |
| 261 | } |
| 262 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 263 | func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) { |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 264 | // First create the all-updatable-modules-system-stubs |
| 265 | { |
| 266 | updatable_modules := removeAll(modules, non_updatable_modules) |
| 267 | props := libraryProps{} |
| 268 | props.Name = proptools.StringPtr("all-updatable-modules-system-stubs") |
| 269 | props.Static_libs = transformArray(updatable_modules, "", ".stubs.system") |
| 270 | props.Sdk_version = proptools.StringPtr("module_current") |
| 271 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 272 | props.Is_stubs_module = proptools.BoolPtr(true) |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 273 | ctx.CreateModule(java.LibraryFactory, &props) |
| 274 | } |
| 275 | // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules |
| 276 | // into all-modules-system-stubs. |
| 277 | { |
| 278 | props := libraryProps{} |
| 279 | props.Name = proptools.StringPtr("all-modules-system-stubs") |
| 280 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system") |
| 281 | props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs") |
| 282 | props.Sdk_version = proptools.StringPtr("module_current") |
| 283 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 284 | props.Is_stubs_module = proptools.BoolPtr(true) |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 285 | ctx.CreateModule(java.LibraryFactory, &props) |
| 286 | } |
| 287 | } |
| 288 | |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 289 | func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) { |
| 290 | // First create the all-updatable-modules-system-stubs |
| 291 | { |
| 292 | updatable_modules := removeAll(modules, non_updatable_modules) |
| 293 | props := libraryProps{} |
| 294 | props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable") |
| 295 | props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system") |
| 296 | props.Sdk_version = proptools.StringPtr("module_current") |
| 297 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 298 | props.Is_stubs_module = proptools.BoolPtr(true) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 299 | ctx.CreateModule(java.LibraryFactory, &props) |
| 300 | } |
| 301 | // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules |
| 302 | // into all-modules-system-stubs. |
| 303 | { |
| 304 | props := libraryProps{} |
| 305 | props.Name = proptools.StringPtr("all-modules-system-stubs-exportable") |
| 306 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system") |
| 307 | props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable") |
| 308 | props.Sdk_version = proptools.StringPtr("module_current") |
| 309 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 310 | props.Is_stubs_module = proptools.BoolPtr(true) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 311 | ctx.CreateModule(java.LibraryFactory, &props) |
| 312 | } |
| 313 | } |
| 314 | |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 315 | func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) { |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 316 | props := libraryProps{} |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 317 | props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs") |
| 318 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test") |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 319 | props.Sdk_version = proptools.StringPtr("module_current") |
| 320 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 321 | props.Is_stubs_module = proptools.BoolPtr(true) |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 322 | ctx.CreateModule(java.LibraryFactory, &props) |
| 323 | } |
| 324 | |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 325 | func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) { |
| 326 | props := libraryProps{} |
| 327 | props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable") |
| 328 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test") |
| 329 | props.Sdk_version = proptools.StringPtr("module_current") |
| 330 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 331 | props.Is_stubs_module = proptools.BoolPtr(true) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 332 | ctx.CreateModule(java.LibraryFactory, &props) |
| 333 | } |
| 334 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 335 | func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) { |
| 336 | // This module is for the "framework-all" module, which should not include the core libraries. |
| 337 | modules = removeAll(modules, core_libraries_modules) |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 338 | // Remove the modules that belong to non-updatable APEXes since those are allowed to compile |
| 339 | // against unstable APIs. |
| 340 | modules = removeAll(modules, non_updatable_modules) |
| 341 | // First create updatable-framework-module-impl, which contains all updatable modules. |
| 342 | // This module compiles against module_lib SDK. |
| 343 | { |
| 344 | props := libraryProps{} |
| 345 | props.Name = proptools.StringPtr("updatable-framework-module-impl") |
| 346 | props.Static_libs = transformArray(modules, "", ".impl") |
| 347 | props.Sdk_version = proptools.StringPtr("module_current") |
| 348 | props.Visibility = []string{"//frameworks/base"} |
| 349 | ctx.CreateModule(java.LibraryFactory, &props) |
| 350 | } |
| 351 | |
| 352 | // Now create all-framework-module-impl, which contains updatable-framework-module-impl |
| 353 | // and all non-updatable modules. This module compiles against hidden APIs. |
| 354 | { |
| 355 | props := libraryProps{} |
| 356 | props.Name = proptools.StringPtr("all-framework-module-impl") |
| 357 | props.Static_libs = transformArray(non_updatable_modules, "", ".impl") |
| 358 | props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl") |
| 359 | props.Sdk_version = proptools.StringPtr("core_platform") |
| 360 | props.Visibility = []string{"//frameworks/base"} |
| 361 | ctx.CreateModule(java.LibraryFactory, &props) |
| 362 | } |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 365 | func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) { |
| 366 | // The user of this module compiles against the "core" SDK and against non-updatable modules, |
| 367 | // so remove to avoid dupes. |
| 368 | modules = removeAll(modules, core_libraries_modules) |
| 369 | modules = removeAll(modules, non_updatable_modules) |
| 370 | props := libraryProps{} |
| 371 | props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable") |
| 372 | props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib") |
| 373 | props.Sdk_version = proptools.StringPtr("module_current") |
| 374 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 375 | props.Is_stubs_module = proptools.BoolPtr(true) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 376 | ctx.CreateModule(java.LibraryFactory, &props) |
| 377 | } |
| 378 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 379 | func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) { |
Mark White | 3cc5e00 | 2023-08-07 11:18:09 +0000 | [diff] [blame] | 380 | // The user of this module compiles against the "core" SDK and against non-updatable modules, |
| 381 | // so remove to avoid dupes. |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 382 | modules = removeAll(modules, core_libraries_modules) |
Mark White | 3cc5e00 | 2023-08-07 11:18:09 +0000 | [diff] [blame] | 383 | modules = removeAll(modules, non_updatable_modules) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 384 | props := libraryProps{} |
| 385 | props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 386 | props.Static_libs = transformArray(modules, "", ".stubs.module_lib") |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 387 | props.Sdk_version = proptools.StringPtr("module_current") |
| 388 | props.Visibility = []string{"//frameworks/base"} |
Jihoon Kang | a7073b5 | 2024-02-12 23:18:52 +0000 | [diff] [blame] | 389 | props.Is_stubs_module = proptools.BoolPtr(true) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 390 | ctx.CreateModule(java.LibraryFactory, &props) |
| 391 | } |
| 392 | |
Paul Duffin | fb5e07d | 2024-05-02 14:51:41 +0100 | [diff] [blame] | 393 | func createMergedFrameworkSystemServerExportableStubs(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { |
| 394 | // The user of this module compiles against the "core" SDK and against non-updatable bootclasspathModules, |
| 395 | // so remove to avoid dupes. |
| 396 | bootclasspathModules := removeAll(bootclasspath, core_libraries_modules) |
| 397 | bootclasspathModules = removeAll(bootclasspath, non_updatable_modules) |
| 398 | modules := append( |
| 399 | // Include all the module-lib APIs from the bootclasspath libraries. |
| 400 | transformArray(bootclasspathModules, "", ".stubs.exportable.module_lib"), |
| 401 | // Then add all the system-server APIs from the service-* libraries. |
| 402 | transformArray(system_server_classpath, "", ".stubs.exportable.system_server")..., |
| 403 | ) |
| 404 | props := libraryProps{} |
| 405 | props.Name = proptools.StringPtr("framework-updatable-stubs-system_server_api-exportable") |
| 406 | props.Static_libs = modules |
| 407 | props.Sdk_version = proptools.StringPtr("system_server_current") |
| 408 | props.Visibility = []string{"//frameworks/base"} |
| 409 | props.Is_stubs_module = proptools.BoolPtr(true) |
| 410 | ctx.CreateModule(java.LibraryFactory, &props) |
| 411 | } |
| 412 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 413 | func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) { |
| 414 | props := fgProps{} |
| 415 | props.Name = proptools.StringPtr("all-modules-public-stubs-source") |
| 416 | props.Srcs = createSrcs(modules, "{.public.stubs.source}") |
| 417 | props.Visibility = []string{"//frameworks/base"} |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 418 | ctx.CreateModule(android.FileGroupFactory, &props) |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 421 | func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string, baseTxtModulePrefix, stubsTypeSuffix string, doDist bool) { |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 422 | var textFiles []MergedTxtDefinition |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 423 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 424 | tagSuffix := []string{".api.txt}", ".removed-api.txt}"} |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 425 | distFilename := []string{"android.txt", "android-removed.txt"} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 426 | for i, f := range []string{"current.txt", "removed.txt"} { |
| 427 | textFiles = append(textFiles, MergedTxtDefinition{ |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 428 | TxtFilename: f, |
| 429 | DistFilename: distFilename[i], |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 430 | BaseTxt: ":" + baseTxtModulePrefix + f, |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 431 | Modules: bootclasspath, |
| 432 | ModuleTag: "{.public" + tagSuffix[i], |
| 433 | Scope: "public", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 434 | }) |
| 435 | textFiles = append(textFiles, MergedTxtDefinition{ |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 436 | TxtFilename: f, |
| 437 | DistFilename: distFilename[i], |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 438 | BaseTxt: ":" + baseTxtModulePrefix + "system-" + f, |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 439 | Modules: bootclasspath, |
| 440 | ModuleTag: "{.system" + tagSuffix[i], |
| 441 | Scope: "system", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 442 | }) |
| 443 | textFiles = append(textFiles, MergedTxtDefinition{ |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 444 | TxtFilename: f, |
| 445 | DistFilename: distFilename[i], |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 446 | BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f, |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 447 | Modules: bootclasspath, |
| 448 | ModuleTag: "{.module-lib" + tagSuffix[i], |
| 449 | Scope: "module-lib", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 450 | }) |
| 451 | textFiles = append(textFiles, MergedTxtDefinition{ |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 452 | TxtFilename: f, |
| 453 | DistFilename: distFilename[i], |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 454 | BaseTxt: ":" + baseTxtModulePrefix + "system-server-" + f, |
Colin Cross | c642076 | 2023-12-07 12:38:40 -0800 | [diff] [blame] | 455 | Modules: system_server_classpath, |
| 456 | ModuleTag: "{.system-server" + tagSuffix[i], |
| 457 | Scope: "system-server", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 458 | }) |
| 459 | } |
| 460 | for _, txt := range textFiles { |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 461 | createMergedTxt(ctx, txt, stubsTypeSuffix, doDist) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 466 | bootclasspath := a.bootclasspath(ctx) |
| 467 | system_server_classpath := a.systemServerClasspath(ctx) |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 468 | if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") { |
| 469 | bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...) |
| 470 | sort.Strings(bootclasspath) |
| 471 | } |
Jihoon Kang | 31cf274 | 2024-02-07 19:52:19 +0000 | [diff] [blame] | 472 | createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false) |
| 473 | createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 474 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 475 | createMergedPublicStubs(ctx, bootclasspath) |
| 476 | createMergedSystemStubs(ctx, bootclasspath) |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame] | 477 | createMergedTestStubsForNonUpdatableModules(ctx) |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 478 | createMergedFrameworkModuleLibStubs(ctx, bootclasspath) |
| 479 | createMergedFrameworkImpl(ctx, bootclasspath) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 480 | |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 481 | createMergedPublicExportableStubs(ctx, bootclasspath) |
| 482 | createMergedSystemExportableStubs(ctx, bootclasspath) |
| 483 | createMergedTestExportableStubsForNonUpdatableModules(ctx) |
| 484 | createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath) |
Paul Duffin | fb5e07d | 2024-05-02 14:51:41 +0100 | [diff] [blame] | 485 | createMergedFrameworkSystemServerExportableStubs(ctx, bootclasspath, system_server_classpath) |
Jihoon Kang | 059b949 | 2023-12-29 00:40:34 +0000 | [diff] [blame] | 486 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 487 | createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath) |
Anton Hansson | cc18e03 | 2022-01-12 14:45:22 +0000 | [diff] [blame] | 488 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 489 | createPublicStubsSourceFilegroup(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | func combinedApisModuleFactory() android.Module { |
| 493 | module := &CombinedApis{} |
| 494 | module.AddProperties(&module.properties) |
| 495 | android.InitAndroidModule(module) |
| 496 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) |
| 497 | return module |
| 498 | } |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 499 | |
| 500 | // Various utility methods below. |
| 501 | |
| 502 | // Creates an array of ":<m><tag>" for each m in <modules>. |
| 503 | func createSrcs(modules []string, tag string) []string { |
| 504 | return transformArray(modules, ":", tag) |
| 505 | } |
| 506 | |
| 507 | // Creates an array of "<prefix><m><suffix>", for each m in <modules>. |
| 508 | func transformArray(modules []string, prefix, suffix string) []string { |
| 509 | a := make([]string, 0, len(modules)) |
| 510 | for _, module := range modules { |
| 511 | a = append(a, prefix+module+suffix) |
| 512 | } |
| 513 | return a |
| 514 | } |
| 515 | |
| 516 | func removeAll(s []string, vs []string) []string { |
| 517 | for _, v := range vs { |
| 518 | s = remove(s, v) |
| 519 | } |
| 520 | return s |
| 521 | } |
| 522 | |
| 523 | func remove(s []string, v string) []string { |
| 524 | s2 := make([]string, 0, len(s)) |
| 525 | for _, sv := range s { |
| 526 | if sv != v { |
| 527 | s2 = append(s2, sv) |
| 528 | } |
| 529 | } |
| 530 | return s2 |
| 531 | } |