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