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