blob: 5b7f534443fb47bf7e7821879cad203540865bab [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 (
Anton Hansson07a12952022-01-12 17:28:39 +000018 "sort"
19
Anton Hansson0860aaf2021-10-08 16:48:03 +010020 "github.com/google/blueprint/proptools"
21
22 "android/soong/android"
23 "android/soong/genrule"
Anton Hanssoncb00f942022-01-13 09:45:12 +000024 "android/soong/java"
Anton Hansson0860aaf2021-10-08 16:48:03 +010025)
26
Anton Hansson05e944d2022-01-13 12:26:30 +000027const art = "art.module.public.api"
28const conscrypt = "conscrypt.module.public.api"
29const i18n = "i18n.module.public.api"
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000030const virtualization = "framework-virtualization"
Mark White3cc5e002023-08-07 11:18:09 +000031const location = "framework-location"
Anton Hansson09a9c4e2022-04-08 10:59:46 +010032
Anton Hansson95e89a82022-01-28 11:31:50 +000033var core_libraries_modules = []string{art, conscrypt, i18n}
Zi Wang0d6a5302023-02-16 14:54:01 -080034
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000035// List of modules that are not yet updatable, and hence they can still compile
36// against hidden APIs. These modules are filtered out when building the
37// updatable-framework-module-impl (because updatable-framework-module-impl is
38// built against module_current SDK). Instead they are directly statically
39// linked into the all-framework-module-lib, which is building against hidden
40// APIs.
Nikita Ioffe5593fbb2022-12-01 14:52:34 +000041// In addition, the modules in this list are allowed to contribute to test APIs
42// stubs.
Roshan Pius96dac952023-12-07 10:54:05 -080043var non_updatable_modules = []string{virtualization, location}
Anton Hansson05e944d2022-01-13 12:26:30 +000044
Anton Hansson0860aaf2021-10-08 16:48:03 +010045// The intention behind this soong plugin is to generate a number of "merged"
46// API-related modules that would otherwise require a large amount of very
47// similar Android.bp boilerplate to define. For example, the merged current.txt
48// API definitions (created by merging the non-updatable current.txt with all
49// the module current.txts). This simplifies the addition of new android
50// modules, by reducing the number of genrules etc a new module must be added to.
51
52// The properties of the combined_apis module type.
53type CombinedApisProperties struct {
Anton Hansson16ff3572022-01-11 18:36:35 +000054 // Module libraries in the bootclasspath
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000055 Bootclasspath proptools.Configurable[[]string]
Anton Hansson07a12952022-01-12 17:28:39 +000056 // Module libraries on the bootclasspath if include_nonpublic_framework_api is true.
57 Conditional_bootclasspath []string
Anton Hansson16ff3572022-01-11 18:36:35 +000058 // Module libraries in system server
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000059 System_server_classpath proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +010060}
61
62type CombinedApis struct {
63 android.ModuleBase
64
65 properties CombinedApisProperties
66}
67
68func init() {
69 registerBuildComponents(android.InitRegistrationContext)
70}
71
72func registerBuildComponents(ctx android.RegistrationContext) {
73 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
74}
75
76var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
77
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000078func (a *CombinedApis) bootclasspath(ctx android.ConfigAndErrorContext) []string {
79 return a.properties.Bootclasspath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil)
80}
81
82func (a *CombinedApis) systemServerClasspath(ctx android.ConfigAndErrorContext) []string {
83 return a.properties.System_server_classpath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil)
84}
85
86func (a *CombinedApis) apiFingerprintStubDeps(ctx android.BottomUpMutatorContext) []string {
Spandan Das67b79062024-02-12 11:40:51 +000087 ret := []string{}
88 ret = append(
89 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000090 transformArray(a.bootclasspath(ctx), "", ".stubs")...,
Spandan Das67b79062024-02-12 11:40:51 +000091 )
92 ret = append(
93 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000094 transformArray(a.bootclasspath(ctx), "", ".stubs.system")...,
Spandan Das67b79062024-02-12 11:40:51 +000095 )
96 ret = append(
97 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000098 transformArray(a.bootclasspath(ctx), "", ".stubs.module_lib")...,
Spandan Das67b79062024-02-12 11:40:51 +000099 )
100 ret = append(
101 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000102 transformArray(a.systemServerClasspath(ctx), "", ".stubs.system_server")...,
Spandan Das67b79062024-02-12 11:40:51 +0000103 )
104 return ret
105}
106
107func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000108 ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps(ctx)...)
Spandan Das67b79062024-02-12 11:40:51 +0000109}
110
Anton Hansson0860aaf2021-10-08 16:48:03 +0100111func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Spandan Das67b79062024-02-12 11:40:51 +0000112 ctx.WalkDeps(func(child, parent android.Module) bool {
113 if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" {
114 // Stubs of BCP and SSCP libraries should not have any dependencies on apps
115 // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true
116 ctx.ModuleErrorf(
117 "Module %s is not a valid dependency of the stub library %s\n."+
118 "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n",
119 child.Name(), parent.Name())
120 return false // error detected
121 }
122 return true
123 })
124
Anton Hansson0860aaf2021-10-08 16:48:03 +0100125}
126
127type genruleProps struct {
128 Name *string
129 Cmd *string
130 Dists []android.Dist
131 Out []string
132 Srcs []string
133 Tools []string
134 Visibility []string
135}
136
Anton Hanssoncb00f942022-01-13 09:45:12 +0000137type libraryProps struct {
Jihoon Kanga7073b52024-02-12 23:18:52 +0000138 Name *string
139 Sdk_version *string
140 Static_libs []string
141 Visibility []string
142 Defaults []string
143 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000144}
145
Anton Hansson4468d7c2022-01-14 12:10:01 +0000146type fgProps struct {
147 Name *string
148 Srcs []string
149 Visibility []string
150}
151
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000152type defaultsProps struct {
153 Name *string
154 Api_surface *string
155 Api_contributions []string
156 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000157 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000158}
159
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
161type MergedTxtDefinition struct {
162 // "current.txt" or "removed.txt"
163 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100164 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
165 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100166 // The module for the non-updatable / non-module part of the api.
167 BaseTxt string
168 // The list of modules that are relevant for this merged txt.
169 Modules []string
170 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
171 ModuleTag string
172 // public, system, module-lib or system-server
173 Scope string
174}
175
Jihoon Kang31cf2742024-02-07 19:52:19 +0000176func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100177 metalavaCmd := "$(location metalava)"
178 // Silence reflection warnings. See b/168689341
179 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100180 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100181
182 filename := txt.TxtFilename
183 if txt.Scope != "public" {
184 filename = txt.Scope + "-" + filename
185 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000186 moduleName := ctx.ModuleName() + stubsTypeSuffix + filename
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000187
Anton Hansson0860aaf2021-10-08 16:48:03 +0100188 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000189 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100190 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000191 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100192 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000193 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Jihoon Kang31cf2742024-02-07 19:52:19 +0000194 if doDist {
195 props.Dists = []android.Dist{
196 {
197 Targets: []string{"droidcore"},
198 Dir: proptools.StringPtr("api"),
199 Dest: proptools.StringPtr(filename),
200 },
201 {
202 Targets: []string{"api_txt", "sdk"},
203 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
204 Dest: proptools.StringPtr(txt.DistFilename),
205 },
206 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100207 }
208 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800209 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100210}
211
Cole Faustdcda3702022-10-04 14:46:35 -0700212func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000213 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700214 name string
215 tag string
216 modules []string
217 }{
218 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000219 name: "all-modules-public-annotations",
220 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700221 modules: modules,
222 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000223 name: "all-modules-system-annotations",
224 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700225 modules: modules,
226 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000227 name: "all-modules-module-lib-annotations",
228 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700229 modules: modules,
230 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000231 name: "all-modules-system-server-annotations",
232 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700233 modules: system_server_modules,
234 },
235 } {
236 props := fgProps{}
237 props.Name = proptools.StringPtr(i.name)
238 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800239 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700240 }
Anton Hansson74b15642022-06-23 08:27:23 +0000241}
242
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000243func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
244 props := libraryProps{}
245 props.Name = proptools.StringPtr("all-modules-public-stubs")
246 props.Static_libs = transformArray(modules, "", ".stubs")
247 props.Sdk_version = proptools.StringPtr("module_current")
248 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000249 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000250 ctx.CreateModule(java.LibraryFactory, &props)
251}
252
Jihoon Kang059b9492023-12-29 00:40:34 +0000253func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
254 props := libraryProps{}
255 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
256 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
257 props.Sdk_version = proptools.StringPtr("module_current")
258 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000259 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000260 ctx.CreateModule(java.LibraryFactory, &props)
261}
262
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000263func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000264 // First create the all-updatable-modules-system-stubs
265 {
266 updatable_modules := removeAll(modules, non_updatable_modules)
267 props := libraryProps{}
268 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
269 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
270 props.Sdk_version = proptools.StringPtr("module_current")
271 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000272 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000273 ctx.CreateModule(java.LibraryFactory, &props)
274 }
275 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
276 // into all-modules-system-stubs.
277 {
278 props := libraryProps{}
279 props.Name = proptools.StringPtr("all-modules-system-stubs")
280 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
281 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
282 props.Sdk_version = proptools.StringPtr("module_current")
283 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000284 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000285 ctx.CreateModule(java.LibraryFactory, &props)
286 }
287}
288
Jihoon Kang059b9492023-12-29 00:40:34 +0000289func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
290 // First create the all-updatable-modules-system-stubs
291 {
292 updatable_modules := removeAll(modules, non_updatable_modules)
293 props := libraryProps{}
294 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
295 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
296 props.Sdk_version = proptools.StringPtr("module_current")
297 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000298 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000299 ctx.CreateModule(java.LibraryFactory, &props)
300 }
301 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
302 // into all-modules-system-stubs.
303 {
304 props := libraryProps{}
305 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
306 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
307 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
308 props.Sdk_version = proptools.StringPtr("module_current")
309 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000310 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000311 ctx.CreateModule(java.LibraryFactory, &props)
312 }
313}
314
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000315func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000316 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000317 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
318 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000319 props.Sdk_version = proptools.StringPtr("module_current")
320 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000321 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000322 ctx.CreateModule(java.LibraryFactory, &props)
323}
324
Jihoon Kang059b9492023-12-29 00:40:34 +0000325func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
326 props := libraryProps{}
327 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
328 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
329 props.Sdk_version = proptools.StringPtr("module_current")
330 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000331 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000332 ctx.CreateModule(java.LibraryFactory, &props)
333}
334
Anton Hansson95e89a82022-01-28 11:31:50 +0000335func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
336 // This module is for the "framework-all" module, which should not include the core libraries.
337 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000338 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
339 // against unstable APIs.
340 modules = removeAll(modules, non_updatable_modules)
341 // First create updatable-framework-module-impl, which contains all updatable modules.
342 // This module compiles against module_lib SDK.
343 {
344 props := libraryProps{}
345 props.Name = proptools.StringPtr("updatable-framework-module-impl")
346 props.Static_libs = transformArray(modules, "", ".impl")
347 props.Sdk_version = proptools.StringPtr("module_current")
348 props.Visibility = []string{"//frameworks/base"}
349 ctx.CreateModule(java.LibraryFactory, &props)
350 }
351
352 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
353 // and all non-updatable modules. This module compiles against hidden APIs.
354 {
355 props := libraryProps{}
356 props.Name = proptools.StringPtr("all-framework-module-impl")
357 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
358 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
359 props.Sdk_version = proptools.StringPtr("core_platform")
360 props.Visibility = []string{"//frameworks/base"}
361 ctx.CreateModule(java.LibraryFactory, &props)
362 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000363}
364
Jihoon Kang059b9492023-12-29 00:40:34 +0000365func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
366 // The user of this module compiles against the "core" SDK and against non-updatable modules,
367 // so remove to avoid dupes.
368 modules = removeAll(modules, core_libraries_modules)
369 modules = removeAll(modules, non_updatable_modules)
370 props := libraryProps{}
371 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
372 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
373 props.Sdk_version = proptools.StringPtr("module_current")
374 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000375 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000376 ctx.CreateModule(java.LibraryFactory, &props)
377}
378
Anton Hansson95e89a82022-01-28 11:31:50 +0000379func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000380 // The user of this module compiles against the "core" SDK and against non-updatable modules,
381 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000382 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000383 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000384 props := libraryProps{}
385 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000386 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000387 props.Sdk_version = proptools.StringPtr("module_current")
388 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000389 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000390 ctx.CreateModule(java.LibraryFactory, &props)
391}
392
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100393func createMergedFrameworkSystemServerExportableStubs(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
394 // The user of this module compiles against the "core" SDK and against non-updatable bootclasspathModules,
395 // so remove to avoid dupes.
396 bootclasspathModules := removeAll(bootclasspath, core_libraries_modules)
397 bootclasspathModules = removeAll(bootclasspath, non_updatable_modules)
398 modules := append(
399 // Include all the module-lib APIs from the bootclasspath libraries.
400 transformArray(bootclasspathModules, "", ".stubs.exportable.module_lib"),
401 // Then add all the system-server APIs from the service-* libraries.
402 transformArray(system_server_classpath, "", ".stubs.exportable.system_server")...,
403 )
404 props := libraryProps{}
405 props.Name = proptools.StringPtr("framework-updatable-stubs-system_server_api-exportable")
406 props.Static_libs = modules
407 props.Sdk_version = proptools.StringPtr("system_server_current")
408 props.Visibility = []string{"//frameworks/base"}
409 props.Is_stubs_module = proptools.BoolPtr(true)
410 ctx.CreateModule(java.LibraryFactory, &props)
411}
412
Anton Hansson4468d7c2022-01-14 12:10:01 +0000413func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
414 props := fgProps{}
415 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
416 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
417 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800418 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000419}
420
Jihoon Kang31cf2742024-02-07 19:52:19 +0000421func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string, baseTxtModulePrefix, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100422 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000423
Anton Hansson0860aaf2021-10-08 16:48:03 +0100424 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100425 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100426 for i, f := range []string{"current.txt", "removed.txt"} {
427 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800428 TxtFilename: f,
429 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000430 BaseTxt: ":" + baseTxtModulePrefix + f,
Colin Crossc6420762023-12-07 12:38:40 -0800431 Modules: bootclasspath,
432 ModuleTag: "{.public" + tagSuffix[i],
433 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100434 })
435 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800436 TxtFilename: f,
437 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000438 BaseTxt: ":" + baseTxtModulePrefix + "system-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800439 Modules: bootclasspath,
440 ModuleTag: "{.system" + tagSuffix[i],
441 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100442 })
443 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800444 TxtFilename: f,
445 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000446 BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800447 Modules: bootclasspath,
448 ModuleTag: "{.module-lib" + tagSuffix[i],
449 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100450 })
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 + "system-server-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800455 Modules: system_server_classpath,
456 ModuleTag: "{.system-server" + tagSuffix[i],
457 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100458 })
459 }
460 for _, txt := range textFiles {
Jihoon Kang31cf2742024-02-07 19:52:19 +0000461 createMergedTxt(ctx, txt, stubsTypeSuffix, doDist)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100462 }
463}
464
465func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000466 bootclasspath := a.bootclasspath(ctx)
467 system_server_classpath := a.systemServerClasspath(ctx)
Anton Hansson07a12952022-01-12 17:28:39 +0000468 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
469 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
470 sort.Strings(bootclasspath)
471 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000472 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false)
473 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100474
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000475 createMergedPublicStubs(ctx, bootclasspath)
476 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000477 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000478 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
479 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000480
Jihoon Kang059b9492023-12-29 00:40:34 +0000481 createMergedPublicExportableStubs(ctx, bootclasspath)
482 createMergedSystemExportableStubs(ctx, bootclasspath)
483 createMergedTestExportableStubsForNonUpdatableModules(ctx)
484 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100485 createMergedFrameworkSystemServerExportableStubs(ctx, bootclasspath, system_server_classpath)
Jihoon Kang059b9492023-12-29 00:40:34 +0000486
Cole Faustdcda3702022-10-04 14:46:35 -0700487 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000488
Anton Hansson4468d7c2022-01-14 12:10:01 +0000489 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100490}
491
492func combinedApisModuleFactory() android.Module {
493 module := &CombinedApis{}
494 module.AddProperties(&module.properties)
495 android.InitAndroidModule(module)
496 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
497 return module
498}
Anton Hanssonfd316452022-01-14 11:15:52 +0000499
500// Various utility methods below.
501
502// Creates an array of ":<m><tag>" for each m in <modules>.
503func createSrcs(modules []string, tag string) []string {
504 return transformArray(modules, ":", tag)
505}
506
507// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
508func transformArray(modules []string, prefix, suffix string) []string {
509 a := make([]string, 0, len(modules))
510 for _, module := range modules {
511 a = append(a, prefix+module+suffix)
512 }
513 return a
514}
515
516func removeAll(s []string, vs []string) []string {
517 for _, v := range vs {
518 s = remove(s, v)
519 }
520 return s
521}
522
523func remove(s []string, v string) []string {
524 s2 := make([]string, 0, len(s))
525 for _, sv := range s {
526 if sv != v {
527 s2 = append(s2, sv)
528 }
529 }
530 return s2
531}