blob: b6b1a7e44510a571b979b7141883f35f4b1548cb [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 (
Liana Kazanova1ae36c82024-08-05 19:45:03 +000018 "fmt"
Anton Hansson07a12952022-01-12 17:28:39 +000019 "sort"
Liana Kazanova1ae36c82024-08-05 19:45:03 +000020 "strings"
Anton Hansson07a12952022-01-12 17:28:39 +000021
Anton Hansson0860aaf2021-10-08 16:48:03 +010022 "github.com/google/blueprint/proptools"
23
24 "android/soong/android"
25 "android/soong/genrule"
Anton Hanssoncb00f942022-01-13 09:45:12 +000026 "android/soong/java"
Anton Hansson0860aaf2021-10-08 16:48:03 +010027)
28
Anton Hansson05e944d2022-01-13 12:26:30 +000029const art = "art.module.public.api"
30const conscrypt = "conscrypt.module.public.api"
31const i18n = "i18n.module.public.api"
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000032const virtualization = "framework-virtualization"
Mark White3cc5e002023-08-07 11:18:09 +000033const location = "framework-location"
Anton Hansson09a9c4e2022-04-08 10:59:46 +010034
Anton Hansson95e89a82022-01-28 11:31:50 +000035var core_libraries_modules = []string{art, conscrypt, i18n}
Zi Wang0d6a5302023-02-16 14:54:01 -080036
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000037// 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 Ioffe5593fbb2022-12-01 14:52:34 +000043// In addition, the modules in this list are allowed to contribute to test APIs
44// stubs.
Roshan Pius96dac952023-12-07 10:54:05 -080045var non_updatable_modules = []string{virtualization, location}
Anton Hansson05e944d2022-01-13 12:26:30 +000046
Anton Hansson0860aaf2021-10-08 16:48:03 +010047// 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.
55type CombinedApisProperties struct {
Anton Hansson16ff3572022-01-11 18:36:35 +000056 // Module libraries in the bootclasspath
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000057 Bootclasspath proptools.Configurable[[]string]
Anton Hansson07a12952022-01-12 17:28:39 +000058 // Module libraries on the bootclasspath if include_nonpublic_framework_api is true.
59 Conditional_bootclasspath []string
Anton Hansson16ff3572022-01-11 18:36:35 +000060 // Module libraries in system server
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000061 System_server_classpath proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +010062}
63
64type CombinedApis struct {
65 android.ModuleBase
66
67 properties CombinedApisProperties
68}
69
70func init() {
71 registerBuildComponents(android.InitRegistrationContext)
72}
73
74func registerBuildComponents(ctx android.RegistrationContext) {
75 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
76}
77
78var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
79
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000080func (a *CombinedApis) bootclasspath(ctx android.ConfigAndErrorContext) []string {
81 return a.properties.Bootclasspath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil)
82}
83
84func (a *CombinedApis) systemServerClasspath(ctx android.ConfigAndErrorContext) []string {
85 return a.properties.System_server_classpath.GetOrDefault(a.ConfigurableEvaluator(ctx), nil)
86}
87
88func (a *CombinedApis) apiFingerprintStubDeps(ctx android.BottomUpMutatorContext) []string {
Spandan Das67b79062024-02-12 11:40:51 +000089 ret := []string{}
90 ret = append(
91 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000092 transformArray(a.bootclasspath(ctx), "", ".stubs")...,
Spandan Das67b79062024-02-12 11:40:51 +000093 )
94 ret = append(
95 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000096 transformArray(a.bootclasspath(ctx), "", ".stubs.system")...,
Spandan Das67b79062024-02-12 11:40:51 +000097 )
98 ret = append(
99 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000100 transformArray(a.bootclasspath(ctx), "", ".stubs.module_lib")...,
Spandan Das67b79062024-02-12 11:40:51 +0000101 )
102 ret = append(
103 ret,
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000104 transformArray(a.systemServerClasspath(ctx), "", ".stubs.system_server")...,
Spandan Das67b79062024-02-12 11:40:51 +0000105 )
106 return ret
107}
108
109func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000110 ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps(ctx)...)
Spandan Das67b79062024-02-12 11:40:51 +0000111}
112
Anton Hansson0860aaf2021-10-08 16:48:03 +0100113func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Spandan Das67b79062024-02-12 11:40:51 +0000114 ctx.WalkDeps(func(child, parent android.Module) bool {
115 if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" {
116 // Stubs of BCP and SSCP libraries should not have any dependencies on apps
117 // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true
118 ctx.ModuleErrorf(
119 "Module %s is not a valid dependency of the stub library %s\n."+
120 "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n",
121 child.Name(), parent.Name())
122 return false // error detected
123 }
124 return true
125 })
126
Anton Hansson0860aaf2021-10-08 16:48:03 +0100127}
128
129type genruleProps struct {
130 Name *string
131 Cmd *string
132 Dists []android.Dist
133 Out []string
134 Srcs []string
135 Tools []string
136 Visibility []string
137}
138
Anton Hanssoncb00f942022-01-13 09:45:12 +0000139type libraryProps struct {
Jihoon Kanga7073b52024-02-12 23:18:52 +0000140 Name *string
141 Sdk_version *string
142 Static_libs []string
143 Visibility []string
144 Defaults []string
145 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000146}
147
Anton Hansson4468d7c2022-01-14 12:10:01 +0000148type fgProps struct {
149 Name *string
150 Srcs []string
151 Visibility []string
152}
153
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000154type defaultsProps struct {
155 Name *string
156 Api_surface *string
157 Api_contributions []string
158 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000159 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000160}
161
Anton Hansson0860aaf2021-10-08 16:48:03 +0100162// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
163type MergedTxtDefinition struct {
164 // "current.txt" or "removed.txt"
165 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100166 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
167 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100168 // The module for the non-updatable / non-module part of the api.
169 BaseTxt string
170 // The list of modules that are relevant for this merged txt.
171 Modules []string
172 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
173 ModuleTag string
174 // public, system, module-lib or system-server
175 Scope string
176}
177
Jihoon Kang31cf2742024-02-07 19:52:19 +0000178func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100179 metalavaCmd := "$(location metalava)"
180 // Silence reflection warnings. See b/168689341
181 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100182 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100183
184 filename := txt.TxtFilename
185 if txt.Scope != "public" {
186 filename = txt.Scope + "-" + filename
187 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000188 moduleName := ctx.ModuleName() + stubsTypeSuffix + filename
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000189
Anton Hansson0860aaf2021-10-08 16:48:03 +0100190 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000191 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100192 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000193 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100194 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000195 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Jihoon Kang31cf2742024-02-07 19:52:19 +0000196 if doDist {
197 props.Dists = []android.Dist{
198 {
199 Targets: []string{"droidcore"},
200 Dir: proptools.StringPtr("api"),
201 Dest: proptools.StringPtr(filename),
202 },
203 {
204 Targets: []string{"api_txt", "sdk"},
205 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
206 Dest: proptools.StringPtr(txt.DistFilename),
207 },
208 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100209 }
210 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800211 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100212}
213
Cole Faustdcda3702022-10-04 14:46:35 -0700214func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000215 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700216 name string
217 tag string
218 modules []string
219 }{
220 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000221 name: "all-modules-public-annotations",
222 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700223 modules: modules,
224 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000225 name: "all-modules-system-annotations",
226 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700227 modules: modules,
228 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000229 name: "all-modules-module-lib-annotations",
230 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700231 modules: modules,
232 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000233 name: "all-modules-system-server-annotations",
234 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700235 modules: system_server_modules,
236 },
237 } {
238 props := fgProps{}
239 props.Name = proptools.StringPtr(i.name)
240 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800241 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700242 }
Anton Hansson74b15642022-06-23 08:27:23 +0000243}
244
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000245func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
246 props := libraryProps{}
247 props.Name = proptools.StringPtr("all-modules-public-stubs")
248 props.Static_libs = transformArray(modules, "", ".stubs")
249 props.Sdk_version = proptools.StringPtr("module_current")
250 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000251 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000252 ctx.CreateModule(java.LibraryFactory, &props)
253}
254
Jihoon Kang059b9492023-12-29 00:40:34 +0000255func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
256 props := libraryProps{}
257 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
258 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
259 props.Sdk_version = proptools.StringPtr("module_current")
260 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000261 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000262 ctx.CreateModule(java.LibraryFactory, &props)
263}
264
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000265func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000266 // First create the all-updatable-modules-system-stubs
267 {
268 updatable_modules := removeAll(modules, non_updatable_modules)
269 props := libraryProps{}
270 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
271 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
272 props.Sdk_version = proptools.StringPtr("module_current")
273 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000274 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000275 ctx.CreateModule(java.LibraryFactory, &props)
276 }
277 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
278 // into all-modules-system-stubs.
279 {
280 props := libraryProps{}
281 props.Name = proptools.StringPtr("all-modules-system-stubs")
282 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
283 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
284 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
Jihoon Kang059b9492023-12-29 00:40:34 +0000291func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
292 // First create the all-updatable-modules-system-stubs
293 {
294 updatable_modules := removeAll(modules, non_updatable_modules)
295 props := libraryProps{}
296 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
297 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
298 props.Sdk_version = proptools.StringPtr("module_current")
299 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000300 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000301 ctx.CreateModule(java.LibraryFactory, &props)
302 }
303 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
304 // into all-modules-system-stubs.
305 {
306 props := libraryProps{}
307 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
308 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
309 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
310 props.Sdk_version = proptools.StringPtr("module_current")
311 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000312 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000313 ctx.CreateModule(java.LibraryFactory, &props)
314 }
315}
316
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000317func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000318 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000319 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
320 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000321 props.Sdk_version = proptools.StringPtr("module_current")
322 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000323 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000324 ctx.CreateModule(java.LibraryFactory, &props)
325}
326
Jihoon Kang059b9492023-12-29 00:40:34 +0000327func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
328 props := libraryProps{}
329 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
330 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
331 props.Sdk_version = proptools.StringPtr("module_current")
332 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000333 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000334 ctx.CreateModule(java.LibraryFactory, &props)
335}
336
Anton Hansson95e89a82022-01-28 11:31:50 +0000337func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
338 // This module is for the "framework-all" module, which should not include the core libraries.
339 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000340 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
341 // against unstable APIs.
342 modules = removeAll(modules, non_updatable_modules)
343 // First create updatable-framework-module-impl, which contains all updatable modules.
344 // This module compiles against module_lib SDK.
345 {
346 props := libraryProps{}
347 props.Name = proptools.StringPtr("updatable-framework-module-impl")
348 props.Static_libs = transformArray(modules, "", ".impl")
349 props.Sdk_version = proptools.StringPtr("module_current")
350 props.Visibility = []string{"//frameworks/base"}
351 ctx.CreateModule(java.LibraryFactory, &props)
352 }
353
354 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
355 // and all non-updatable modules. This module compiles against hidden APIs.
356 {
357 props := libraryProps{}
358 props.Name = proptools.StringPtr("all-framework-module-impl")
359 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
360 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
361 props.Sdk_version = proptools.StringPtr("core_platform")
362 props.Visibility = []string{"//frameworks/base"}
363 ctx.CreateModule(java.LibraryFactory, &props)
364 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000365}
366
Jihoon Kang059b9492023-12-29 00:40:34 +0000367func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
368 // The user of this module compiles against the "core" SDK and against non-updatable modules,
369 // so remove to avoid dupes.
370 modules = removeAll(modules, core_libraries_modules)
371 modules = removeAll(modules, non_updatable_modules)
372 props := libraryProps{}
373 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
374 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
375 props.Sdk_version = proptools.StringPtr("module_current")
376 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000377 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000378 ctx.CreateModule(java.LibraryFactory, &props)
379}
380
Anton Hansson95e89a82022-01-28 11:31:50 +0000381func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000382 // The user of this module compiles against the "core" SDK and against non-updatable modules,
383 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000384 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000385 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000386 props := libraryProps{}
387 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000388 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000389 props.Sdk_version = proptools.StringPtr("module_current")
390 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000391 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000392 ctx.CreateModule(java.LibraryFactory, &props)
393}
394
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100395func createMergedFrameworkSystemServerExportableStubs(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
396 // The user of this module compiles against the "core" SDK and against non-updatable bootclasspathModules,
397 // so remove to avoid dupes.
398 bootclasspathModules := removeAll(bootclasspath, core_libraries_modules)
399 bootclasspathModules = removeAll(bootclasspath, non_updatable_modules)
400 modules := append(
401 // Include all the module-lib APIs from the bootclasspath libraries.
402 transformArray(bootclasspathModules, "", ".stubs.exportable.module_lib"),
403 // Then add all the system-server APIs from the service-* libraries.
404 transformArray(system_server_classpath, "", ".stubs.exportable.system_server")...,
405 )
406 props := libraryProps{}
407 props.Name = proptools.StringPtr("framework-updatable-stubs-system_server_api-exportable")
408 props.Static_libs = modules
409 props.Sdk_version = proptools.StringPtr("system_server_current")
410 props.Visibility = []string{"//frameworks/base"}
411 props.Is_stubs_module = proptools.BoolPtr(true)
412 ctx.CreateModule(java.LibraryFactory, &props)
413}
414
Anton Hansson4468d7c2022-01-14 12:10:01 +0000415func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
416 props := fgProps{}
417 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
418 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
419 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800420 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000421}
422
Jihoon Kang31cf2742024-02-07 19:52:19 +0000423func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string, baseTxtModulePrefix, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100424 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000425
Anton Hansson0860aaf2021-10-08 16:48:03 +0100426 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100427 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100428 for i, f := range []string{"current.txt", "removed.txt"} {
429 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800430 TxtFilename: f,
431 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000432 BaseTxt: ":" + baseTxtModulePrefix + f,
Colin Crossc6420762023-12-07 12:38:40 -0800433 Modules: bootclasspath,
434 ModuleTag: "{.public" + tagSuffix[i],
435 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100436 })
437 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800438 TxtFilename: f,
439 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000440 BaseTxt: ":" + baseTxtModulePrefix + "system-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800441 Modules: bootclasspath,
442 ModuleTag: "{.system" + tagSuffix[i],
443 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100444 })
445 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800446 TxtFilename: f,
447 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000448 BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800449 Modules: bootclasspath,
450 ModuleTag: "{.module-lib" + tagSuffix[i],
451 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100452 })
453 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800454 TxtFilename: f,
455 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000456 BaseTxt: ":" + baseTxtModulePrefix + "system-server-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800457 Modules: system_server_classpath,
458 ModuleTag: "{.system-server" + tagSuffix[i],
459 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100460 })
461 }
462 for _, txt := range textFiles {
Jihoon Kang31cf2742024-02-07 19:52:19 +0000463 createMergedTxt(ctx, txt, stubsTypeSuffix, doDist)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100464 }
465}
466
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000467func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
468 defaultsSdkKinds := []android.SdkKind{
469 android.SdkPublic, android.SdkSystem, android.SdkModule,
470 }
471 for _, sdkKind := range defaultsSdkKinds {
472 props := defaultsProps{}
473 props.Name = proptools.StringPtr(
474 sdkKind.DefaultJavaLibraryName() + "_contributions")
475 if sdkKind == android.SdkModule {
476 props.Name = proptools.StringPtr(
477 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
478 }
479 props.Api_surface = proptools.StringPtr(sdkKind.String())
480 apiSuffix := ""
481 if sdkKind != android.SdkPublic {
482 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
483 }
484 props.Api_contributions = transformArray(
485 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
486 props.Defaults_visibility = []string{"//visibility:public"}
487 props.Previous_api = proptools.StringPtr(":android.api.combined." + sdkKind.String() + ".latest")
488 ctx.CreateModule(java.DefaultsFactory, &props)
489 }
490}
491
492func createFullApiLibraries(ctx android.LoadHookContext) {
493 javaLibraryNames := []string{
494 "android_stubs_current",
495 "android_system_stubs_current",
496 "android_test_stubs_current",
497 "android_test_frameworks_core_stubs_current",
498 "android_module_lib_stubs_current",
499 "android_system_server_stubs_current",
500 }
501
502 for _, libraryName := range javaLibraryNames {
503 props := libraryProps{}
504 props.Name = proptools.StringPtr(libraryName)
505 staticLib := libraryName + ".from-source"
506 if ctx.Config().BuildFromTextStub() {
507 staticLib = libraryName + ".from-text"
508 }
509 props.Static_libs = []string{staticLib}
510 props.Defaults = []string{"android.jar_defaults"}
511 props.Visibility = []string{"//visibility:public"}
512 props.Is_stubs_module = proptools.BoolPtr(true)
513
514 ctx.CreateModule(java.LibraryFactory, &props)
515 }
516}
517
518func createFullExportableApiLibraries(ctx android.LoadHookContext) {
519 javaLibraryNames := []string{
520 "android_stubs_current_exportable",
521 "android_system_stubs_current_exportable",
522 "android_test_stubs_current_exportable",
523 "android_module_lib_stubs_current_exportable",
524 "android_system_server_stubs_current_exportable",
525 }
526
527 for _, libraryName := range javaLibraryNames {
528 props := libraryProps{}
529 props.Name = proptools.StringPtr(libraryName)
530 staticLib := libraryName + ".from-source"
531 props.Static_libs = []string{staticLib}
532 props.Defaults = []string{"android.jar_defaults"}
533 props.Visibility = []string{"//visibility:public"}
534 props.Is_stubs_module = proptools.BoolPtr(true)
535
536 ctx.CreateModule(java.LibraryFactory, &props)
537 }
538}
539
Anton Hansson0860aaf2021-10-08 16:48:03 +0100540func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000541 bootclasspath := a.bootclasspath(ctx)
542 system_server_classpath := a.systemServerClasspath(ctx)
Anton Hansson07a12952022-01-12 17:28:39 +0000543 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
544 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
545 sort.Strings(bootclasspath)
546 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000547 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false)
548 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100549
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000550 createMergedPublicStubs(ctx, bootclasspath)
551 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000552 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000553 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
554 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000555
Jihoon Kang059b9492023-12-29 00:40:34 +0000556 createMergedPublicExportableStubs(ctx, bootclasspath)
557 createMergedSystemExportableStubs(ctx, bootclasspath)
558 createMergedTestExportableStubsForNonUpdatableModules(ctx)
559 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100560 createMergedFrameworkSystemServerExportableStubs(ctx, bootclasspath, system_server_classpath)
Jihoon Kang059b9492023-12-29 00:40:34 +0000561
Cole Faustdcda3702022-10-04 14:46:35 -0700562 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000563
Anton Hansson4468d7c2022-01-14 12:10:01 +0000564 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000565
566 createApiContributionDefaults(ctx, bootclasspath)
567
568 createFullApiLibraries(ctx)
569
570 createFullExportableApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100571}
572
573func combinedApisModuleFactory() android.Module {
574 module := &CombinedApis{}
575 module.AddProperties(&module.properties)
576 android.InitAndroidModule(module)
577 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
578 return module
579}
Anton Hanssonfd316452022-01-14 11:15:52 +0000580
581// Various utility methods below.
582
583// Creates an array of ":<m><tag>" for each m in <modules>.
584func createSrcs(modules []string, tag string) []string {
585 return transformArray(modules, ":", tag)
586}
587
588// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
589func transformArray(modules []string, prefix, suffix string) []string {
590 a := make([]string, 0, len(modules))
591 for _, module := range modules {
592 a = append(a, prefix+module+suffix)
593 }
594 return a
595}
596
597func removeAll(s []string, vs []string) []string {
598 for _, v := range vs {
599 s = remove(s, v)
600 }
601 return s
602}
603
604func remove(s []string, v string) []string {
605 s2 := make([]string, 0, len(s))
606 for _, sv := range s {
607 if sv != v {
608 s2 = append(s2, sv)
609 }
610 }
611 return s2
612}