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