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