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