blob: aa89c2450288e3568bfc8ebf4ba8af0753889476 [file] [log] [blame]
Anton Hansson0860aaf2021-10-08 16:48:03 +01001// 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
15package api
16
17import (
Cole Faustb1fc07e2024-09-05 11:37:57 -070018 "slices"
Anton Hansson07a12952022-01-12 17:28:39 +000019
Anton Hansson0860aaf2021-10-08 16:48:03 +010020 "github.com/google/blueprint/proptools"
21
22 "android/soong/android"
Anton Hanssoncb00f942022-01-13 09:45:12 +000023 "android/soong/java"
Anton Hansson0860aaf2021-10-08 16:48:03 +010024)
25
Anton Hansson05e944d2022-01-13 12:26:30 +000026const art = "art.module.public.api"
27const conscrypt = "conscrypt.module.public.api"
28const i18n = "i18n.module.public.api"
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000029const virtualization = "framework-virtualization"
Mark White3cc5e002023-08-07 11:18:09 +000030const location = "framework-location"
Anton Hansson09a9c4e2022-04-08 10:59:46 +010031
Anton Hansson95e89a82022-01-28 11:31:50 +000032var core_libraries_modules = []string{art, conscrypt, i18n}
Zi Wang0d6a5302023-02-16 14:54:01 -080033
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000034// List of modules that are not yet updatable, and hence they can still compile
35// against hidden APIs. These modules are filtered out when building the
36// updatable-framework-module-impl (because updatable-framework-module-impl is
37// built against module_current SDK). Instead they are directly statically
38// linked into the all-framework-module-lib, which is building against hidden
39// APIs.
Nikita Ioffe5593fbb2022-12-01 14:52:34 +000040// In addition, the modules in this list are allowed to contribute to test APIs
41// stubs.
Roshan Pius96dac952023-12-07 10:54:05 -080042var non_updatable_modules = []string{virtualization, location}
Anton Hansson05e944d2022-01-13 12:26:30 +000043
Anton Hansson0860aaf2021-10-08 16:48:03 +010044// The intention behind this soong plugin is to generate a number of "merged"
45// API-related modules that would otherwise require a large amount of very
46// similar Android.bp boilerplate to define. For example, the merged current.txt
47// API definitions (created by merging the non-updatable current.txt with all
48// the module current.txts). This simplifies the addition of new android
49// modules, by reducing the number of genrules etc a new module must be added to.
50
51// The properties of the combined_apis module type.
52type CombinedApisProperties struct {
Anton Hansson16ff3572022-01-11 18:36:35 +000053 // Module libraries in the bootclasspath
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000054 Bootclasspath proptools.Configurable[[]string]
Anton Hansson07a12952022-01-12 17:28:39 +000055 // Module libraries on the bootclasspath if include_nonpublic_framework_api is true.
56 Conditional_bootclasspath []string
Anton Hansson16ff3572022-01-11 18:36:35 +000057 // Module libraries in system server
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000058 System_server_classpath proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +010059}
60
61type CombinedApis struct {
62 android.ModuleBase
63
64 properties CombinedApisProperties
65}
66
67func init() {
68 registerBuildComponents(android.InitRegistrationContext)
69}
70
71func registerBuildComponents(ctx android.RegistrationContext) {
72 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
73}
74
75var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
76
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000077func (a *CombinedApis) apiFingerprintStubDeps(ctx android.BottomUpMutatorContext) []string {
Cole Faustb1fc07e2024-09-05 11:37:57 -070078 bootClasspath := a.properties.Bootclasspath.GetOrDefault(ctx, nil)
79 systemServerClasspath := a.properties.System_server_classpath.GetOrDefault(ctx, nil)
80 var ret []string
Spandan Das67b79062024-02-12 11:40:51 +000081 ret = append(
82 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070083 transformArray(bootClasspath, "", ".stubs")...,
Spandan Das67b79062024-02-12 11:40:51 +000084 )
85 ret = append(
86 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070087 transformArray(bootClasspath, "", ".stubs.system")...,
Spandan Das67b79062024-02-12 11:40:51 +000088 )
89 ret = append(
90 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070091 transformArray(bootClasspath, "", ".stubs.module_lib")...,
Spandan Das67b79062024-02-12 11:40:51 +000092 )
93 ret = append(
94 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070095 transformArray(systemServerClasspath, "", ".stubs.system_server")...,
Spandan Das67b79062024-02-12 11:40:51 +000096 )
97 return ret
98}
99
100func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000101 ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps(ctx)...)
Spandan Das67b79062024-02-12 11:40:51 +0000102}
103
Anton Hansson0860aaf2021-10-08 16:48:03 +0100104func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Spandan Das67b79062024-02-12 11:40:51 +0000105 ctx.WalkDeps(func(child, parent android.Module) bool {
106 if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" {
107 // Stubs of BCP and SSCP libraries should not have any dependencies on apps
108 // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true
109 ctx.ModuleErrorf(
110 "Module %s is not a valid dependency of the stub library %s\n."+
111 "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n",
112 child.Name(), parent.Name())
113 return false // error detected
114 }
115 return true
116 })
117
Anton Hansson0860aaf2021-10-08 16:48:03 +0100118}
119
120type genruleProps struct {
121 Name *string
122 Cmd *string
123 Dists []android.Dist
124 Out []string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700125 Srcs proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +0100126 Tools []string
127 Visibility []string
128}
129
Anton Hanssoncb00f942022-01-13 09:45:12 +0000130type libraryProps struct {
Jihoon Kanga7073b52024-02-12 23:18:52 +0000131 Name *string
132 Sdk_version *string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700133 Static_libs proptools.Configurable[[]string]
Jihoon Kanga7073b52024-02-12 23:18:52 +0000134 Visibility []string
135 Defaults []string
136 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000137}
138
Anton Hansson4468d7c2022-01-14 12:10:01 +0000139type fgProps struct {
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700140 Name *string
141 Srcs proptools.Configurable[[]string]
142 Device_common_srcs proptools.Configurable[[]string]
143 Visibility []string
Anton Hansson4468d7c2022-01-14 12:10:01 +0000144}
145
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000146type defaultsProps struct {
147 Name *string
148 Api_surface *string
149 Api_contributions []string
150 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000151 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000152}
153
Anton Hansson0860aaf2021-10-08 16:48:03 +0100154// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
155type MergedTxtDefinition struct {
156 // "current.txt" or "removed.txt"
157 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100158 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
159 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160 // The module for the non-updatable / non-module part of the api.
161 BaseTxt string
162 // The list of modules that are relevant for this merged txt.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700163 Modules proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +0100164 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
165 ModuleTag string
166 // public, system, module-lib or system-server
167 Scope string
168}
169
Jihoon Kang31cf2742024-02-07 19:52:19 +0000170func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100171 metalavaCmd := "$(location metalava)"
172 // Silence reflection warnings. See b/168689341
173 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100174 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100175
176 filename := txt.TxtFilename
177 if txt.Scope != "public" {
178 filename = txt.Scope + "-" + filename
179 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000180 moduleName := ctx.ModuleName() + stubsTypeSuffix + filename
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000181
Anton Hansson0860aaf2021-10-08 16:48:03 +0100182 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000183 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100184 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000185 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100186 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700187 props.Srcs = proptools.NewSimpleConfigurable([]string{txt.BaseTxt})
188 props.Srcs.Append(createSrcs(txt.Modules, txt.ModuleTag))
Jihoon Kang31cf2742024-02-07 19:52:19 +0000189 if doDist {
190 props.Dists = []android.Dist{
191 {
192 Targets: []string{"droidcore"},
193 Dir: proptools.StringPtr("api"),
194 Dest: proptools.StringPtr(filename),
195 },
196 {
197 Targets: []string{"api_txt", "sdk"},
198 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
199 Dest: proptools.StringPtr(txt.DistFilename),
200 },
201 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100202 }
203 props.Visibility = []string{"//visibility:public"}
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700204 ctx.CreateModule(java.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100205}
206
Cole Faustb1fc07e2024-09-05 11:37:57 -0700207func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules proptools.Configurable[[]string]) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000208 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700209 name string
210 tag string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700211 modules proptools.Configurable[[]string]
Cole Faustdcda3702022-10-04 14:46:35 -0700212 }{
213 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000214 name: "all-modules-public-annotations",
215 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700216 modules: modules,
217 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000218 name: "all-modules-system-annotations",
219 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700220 modules: modules,
221 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000222 name: "all-modules-module-lib-annotations",
223 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700224 modules: modules,
225 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000226 name: "all-modules-system-server-annotations",
227 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700228 modules: system_server_modules,
229 },
230 } {
231 props := fgProps{}
232 props.Name = proptools.StringPtr(i.name)
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700233 props.Device_common_srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800234 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700235 }
Anton Hansson74b15642022-06-23 08:27:23 +0000236}
237
Cole Faustb1fc07e2024-09-05 11:37:57 -0700238func createMergedPublicStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
239 modules = modules.Clone()
240 transformConfigurableArray(modules, "", ".stubs")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000241 props := libraryProps{}
242 props.Name = proptools.StringPtr("all-modules-public-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700243 props.Static_libs = modules
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000244 props.Sdk_version = proptools.StringPtr("module_current")
245 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000246 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000247 ctx.CreateModule(java.LibraryFactory, &props)
248}
249
Cole Faustb1fc07e2024-09-05 11:37:57 -0700250func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
251 modules = modules.Clone()
252 transformConfigurableArray(modules, "", ".stubs.exportable")
Jihoon Kang059b9492023-12-29 00:40:34 +0000253 props := libraryProps{}
254 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700255 props.Static_libs = modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000256 props.Sdk_version = proptools.StringPtr("module_current")
257 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000258 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000259 ctx.CreateModule(java.LibraryFactory, &props)
260}
261
Cole Faustb1fc07e2024-09-05 11:37:57 -0700262func createMergedSystemStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000263 // First create the all-updatable-modules-system-stubs
264 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700265 updatable_modules := modules.Clone()
266 removeAll(updatable_modules, non_updatable_modules)
267 transformConfigurableArray(updatable_modules, "", ".stubs.system")
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000268 props := libraryProps{}
269 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700270 props.Static_libs = updatable_modules
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000271 props.Sdk_version = proptools.StringPtr("module_current")
272 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000273 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000274 ctx.CreateModule(java.LibraryFactory, &props)
275 }
276 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
277 // into all-modules-system-stubs.
278 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700279 static_libs := transformArray(non_updatable_modules, "", ".stubs.system")
280 static_libs = append(static_libs, "all-updatable-modules-system-stubs")
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000281 props := libraryProps{}
282 props.Name = proptools.StringPtr("all-modules-system-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700283 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000284 props.Sdk_version = proptools.StringPtr("module_current")
285 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000286 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000287 ctx.CreateModule(java.LibraryFactory, &props)
288 }
289}
290
Cole Faustb1fc07e2024-09-05 11:37:57 -0700291func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Jihoon Kang059b9492023-12-29 00:40:34 +0000292 // First create the all-updatable-modules-system-stubs
293 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700294 updatable_modules := modules.Clone()
295 removeAll(updatable_modules, non_updatable_modules)
296 transformConfigurableArray(updatable_modules, "", ".stubs.exportable.system")
Jihoon Kang059b9492023-12-29 00:40:34 +0000297 props := libraryProps{}
298 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700299 props.Static_libs = updatable_modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000300 props.Sdk_version = proptools.StringPtr("module_current")
301 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000302 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000303 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 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700308 static_libs := transformArray(non_updatable_modules, "", ".stubs.exportable.system")
309 static_libs = append(static_libs, "all-updatable-modules-system-stubs-exportable")
Jihoon Kang059b9492023-12-29 00:40:34 +0000310 props := libraryProps{}
311 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700312 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Jihoon Kang059b9492023-12-29 00:40:34 +0000313 props.Sdk_version = proptools.StringPtr("module_current")
314 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000315 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000316 ctx.CreateModule(java.LibraryFactory, &props)
317 }
318}
319
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000320func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000321 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000322 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700323 props.Static_libs = proptools.NewSimpleConfigurable(transformArray(non_updatable_modules, "", ".stubs.test"))
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000324 props.Sdk_version = proptools.StringPtr("module_current")
325 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000326 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000327 ctx.CreateModule(java.LibraryFactory, &props)
328}
329
Jihoon Kang059b9492023-12-29 00:40:34 +0000330func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
331 props := libraryProps{}
332 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700333 props.Static_libs = proptools.NewSimpleConfigurable(transformArray(non_updatable_modules, "", ".stubs.exportable.test"))
Jihoon Kang059b9492023-12-29 00:40:34 +0000334 props.Sdk_version = proptools.StringPtr("module_current")
335 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000336 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000337 ctx.CreateModule(java.LibraryFactory, &props)
338}
339
Cole Faustb1fc07e2024-09-05 11:37:57 -0700340func createMergedFrameworkImpl(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
341 modules = modules.Clone()
Anton Hansson95e89a82022-01-28 11:31:50 +0000342 // This module is for the "framework-all" module, which should not include the core libraries.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700343 removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000344 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
345 // against unstable APIs.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700346 removeAll(modules, non_updatable_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000347 // First create updatable-framework-module-impl, which contains all updatable modules.
348 // This module compiles against module_lib SDK.
349 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700350 transformConfigurableArray(modules, "", ".impl")
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000351 props := libraryProps{}
352 props.Name = proptools.StringPtr("updatable-framework-module-impl")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700353 props.Static_libs = modules
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000354 props.Sdk_version = proptools.StringPtr("module_current")
355 props.Visibility = []string{"//frameworks/base"}
356 ctx.CreateModule(java.LibraryFactory, &props)
357 }
358
359 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
360 // and all non-updatable modules. This module compiles against hidden APIs.
361 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700362 static_libs := transformArray(non_updatable_modules, "", ".impl")
363 static_libs = append(static_libs, "updatable-framework-module-impl")
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000364 props := libraryProps{}
365 props.Name = proptools.StringPtr("all-framework-module-impl")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700366 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000367 props.Sdk_version = proptools.StringPtr("core_platform")
368 props.Visibility = []string{"//frameworks/base"}
369 ctx.CreateModule(java.LibraryFactory, &props)
370 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000371}
372
Cole Faustb1fc07e2024-09-05 11:37:57 -0700373func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
374 modules = modules.Clone()
Jihoon Kang059b9492023-12-29 00:40:34 +0000375 // The user of this module compiles against the "core" SDK and against non-updatable modules,
376 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700377 removeAll(modules, core_libraries_modules)
378 removeAll(modules, non_updatable_modules)
379 transformConfigurableArray(modules, "", ".stubs.exportable.module_lib")
Jihoon Kang059b9492023-12-29 00:40:34 +0000380 props := libraryProps{}
381 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700382 props.Static_libs = modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000383 props.Sdk_version = proptools.StringPtr("module_current")
384 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000385 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000386 ctx.CreateModule(java.LibraryFactory, &props)
387}
388
Cole Faustb1fc07e2024-09-05 11:37:57 -0700389func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
390 modules = modules.Clone()
Mark White3cc5e002023-08-07 11:18:09 +0000391 // The user of this module compiles against the "core" SDK and against non-updatable modules,
392 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700393 removeAll(modules, core_libraries_modules)
394 removeAll(modules, non_updatable_modules)
395 transformConfigurableArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000396 props := libraryProps{}
397 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700398 props.Static_libs = modules
Anton Hanssoncb00f942022-01-13 09:45:12 +0000399 props.Sdk_version = proptools.StringPtr("module_current")
400 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000401 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000402 ctx.CreateModule(java.LibraryFactory, &props)
403}
404
Cole Faustb1fc07e2024-09-05 11:37:57 -0700405func createMergedFrameworkSystemServerExportableStubs(ctx android.LoadHookContext, bootclasspath, system_server_classpath proptools.Configurable[[]string]) {
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100406 // The user of this module compiles against the "core" SDK and against non-updatable bootclasspathModules,
407 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700408 bootclasspathModules := bootclasspath.Clone()
409 removeAll(bootclasspathModules, core_libraries_modules)
410 removeAll(bootclasspathModules, non_updatable_modules)
411 transformConfigurableArray(bootclasspathModules, "", ".stubs.exportable.module_lib")
412
413 system_server_classpath = system_server_classpath.Clone()
414 transformConfigurableArray(system_server_classpath, "", ".stubs.exportable.system_server")
415
416 // Include all the module-lib APIs from the bootclasspath libraries.
417 // Then add all the system-server APIs from the service-* libraries.
418 bootclasspathModules.Append(system_server_classpath)
419
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100420 props := libraryProps{}
421 props.Name = proptools.StringPtr("framework-updatable-stubs-system_server_api-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700422 props.Static_libs = bootclasspathModules
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100423 props.Sdk_version = proptools.StringPtr("system_server_current")
424 props.Visibility = []string{"//frameworks/base"}
425 props.Is_stubs_module = proptools.BoolPtr(true)
426 ctx.CreateModule(java.LibraryFactory, &props)
427}
428
Cole Faustb1fc07e2024-09-05 11:37:57 -0700429func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Anton Hansson4468d7c2022-01-14 12:10:01 +0000430 props := fgProps{}
Jihoon Kange4553d02024-11-07 19:40:30 +0000431 props.Name = proptools.StringPtr("all-modules-public-stubs-source-exportable")
432 transformConfigurableArray(modules, "", ".stubs.source")
433 props.Device_common_srcs = createSrcs(modules, "{.exportable}")
Anton Hansson4468d7c2022-01-14 12:10:01 +0000434 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800435 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000436}
437
Cole Faustb1fc07e2024-09-05 11:37:57 -0700438func createMergedTxts(
439 ctx android.LoadHookContext,
440 bootclasspath proptools.Configurable[[]string],
441 system_server_classpath proptools.Configurable[[]string],
442 baseTxtModulePrefix string,
443 stubsTypeSuffix string,
444 doDist bool,
445) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100446 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000447
Anton Hansson0860aaf2021-10-08 16:48:03 +0100448 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100449 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100450 for i, f := range []string{"current.txt", "removed.txt"} {
451 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800452 TxtFilename: f,
453 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000454 BaseTxt: ":" + baseTxtModulePrefix + f,
Colin Crossc6420762023-12-07 12:38:40 -0800455 Modules: bootclasspath,
456 ModuleTag: "{.public" + tagSuffix[i],
457 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100458 })
459 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800460 TxtFilename: f,
461 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000462 BaseTxt: ":" + baseTxtModulePrefix + "system-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800463 Modules: bootclasspath,
464 ModuleTag: "{.system" + tagSuffix[i],
465 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100466 })
467 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800468 TxtFilename: f,
469 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000470 BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800471 Modules: bootclasspath,
472 ModuleTag: "{.module-lib" + tagSuffix[i],
473 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100474 })
475 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800476 TxtFilename: f,
477 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000478 BaseTxt: ":" + baseTxtModulePrefix + "system-server-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800479 Modules: system_server_classpath,
480 ModuleTag: "{.system-server" + tagSuffix[i],
481 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100482 })
483 }
484 for _, txt := range textFiles {
Jihoon Kang31cf2742024-02-07 19:52:19 +0000485 createMergedTxt(ctx, txt, stubsTypeSuffix, doDist)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100486 }
487}
488
489func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700490 bootclasspath := a.properties.Bootclasspath.Clone()
491 system_server_classpath := a.properties.System_server_classpath.Clone()
Anton Hansson07a12952022-01-12 17:28:39 +0000492 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700493 bootclasspath.AppendSimpleValue(a.properties.Conditional_bootclasspath)
Anton Hansson07a12952022-01-12 17:28:39 +0000494 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000495 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false)
496 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100497
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000498 createMergedPublicStubs(ctx, bootclasspath)
499 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000500 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000501 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
502 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000503
Jihoon Kang059b9492023-12-29 00:40:34 +0000504 createMergedPublicExportableStubs(ctx, bootclasspath)
505 createMergedSystemExportableStubs(ctx, bootclasspath)
506 createMergedTestExportableStubsForNonUpdatableModules(ctx)
507 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100508 createMergedFrameworkSystemServerExportableStubs(ctx, bootclasspath, system_server_classpath)
Jihoon Kang059b9492023-12-29 00:40:34 +0000509
Cole Faustdcda3702022-10-04 14:46:35 -0700510 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000511
Anton Hansson4468d7c2022-01-14 12:10:01 +0000512 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100513}
514
515func combinedApisModuleFactory() android.Module {
516 module := &CombinedApis{}
517 module.AddProperties(&module.properties)
Cole Faustfbc4f882024-10-07 16:35:00 -0700518 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100519 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
520 return module
521}
Anton Hanssonfd316452022-01-14 11:15:52 +0000522
523// Various utility methods below.
524
525// Creates an array of ":<m><tag>" for each m in <modules>.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700526func createSrcs(modules proptools.Configurable[[]string], tag string) proptools.Configurable[[]string] {
527 result := modules.Clone()
528 transformConfigurableArray(result, ":", tag)
529 return result
Anton Hanssonfd316452022-01-14 11:15:52 +0000530}
531
532// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
533func transformArray(modules []string, prefix, suffix string) []string {
534 a := make([]string, 0, len(modules))
535 for _, module := range modules {
536 a = append(a, prefix+module+suffix)
537 }
538 return a
539}
540
Cole Faustb1fc07e2024-09-05 11:37:57 -0700541// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
542func transformConfigurableArray(modules proptools.Configurable[[]string], prefix, suffix string) {
543 modules.AddPostProcessor(func(s []string) []string {
544 return transformArray(s, prefix, suffix)
545 })
546}
547
548func removeAll(s proptools.Configurable[[]string], vs []string) {
549 s.AddPostProcessor(func(s []string) []string {
550 a := make([]string, 0, len(s))
551 for _, module := range s {
552 if !slices.Contains(vs, module) {
553 a = append(a, module)
554 }
555 }
556 return a
557 })
Anton Hanssonfd316452022-01-14 11:15:52 +0000558}
559
560func remove(s []string, v string) []string {
561 s2 := make([]string, 0, len(s))
562 for _, sv := range s {
563 if sv != v {
564 s2 = append(s2, sv)
565 }
566 }
567 return s2
568}