blob: 5ca24de1b46acb29603439978194363f411eaeb7 [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"
Harshit Mahajan989825d2024-10-09 12:42:55 +000031const platformCrashrecovery = "framework-platformcrashrecovery"
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.
Harshit Mahajan989825d2024-10-09 12:42:55 +000043var non_updatable_modules = []string{virtualization, location, platformCrashrecovery}
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) apiFingerprintStubDeps(ctx android.BottomUpMutatorContext) []string {
Cole Faustb1fc07e2024-09-05 11:37:57 -070079 bootClasspath := a.properties.Bootclasspath.GetOrDefault(ctx, nil)
80 systemServerClasspath := a.properties.System_server_classpath.GetOrDefault(ctx, nil)
81 var ret []string
Spandan Das67b79062024-02-12 11:40:51 +000082 ret = append(
83 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070084 transformArray(bootClasspath, "", ".stubs")...,
Spandan Das67b79062024-02-12 11:40:51 +000085 )
86 ret = append(
87 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070088 transformArray(bootClasspath, "", ".stubs.system")...,
Spandan Das67b79062024-02-12 11:40:51 +000089 )
90 ret = append(
91 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070092 transformArray(bootClasspath, "", ".stubs.module_lib")...,
Spandan Das67b79062024-02-12 11:40:51 +000093 )
94 ret = append(
95 ret,
Cole Faustb1fc07e2024-09-05 11:37:57 -070096 transformArray(systemServerClasspath, "", ".stubs.system_server")...,
Spandan Das67b79062024-02-12 11:40:51 +000097 )
98 return ret
99}
100
101func (a *CombinedApis) DepsMutator(ctx android.BottomUpMutatorContext) {
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000102 ctx.AddDependency(ctx.Module(), nil, a.apiFingerprintStubDeps(ctx)...)
Spandan Das67b79062024-02-12 11:40:51 +0000103}
104
Anton Hansson0860aaf2021-10-08 16:48:03 +0100105func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Spandan Das67b79062024-02-12 11:40:51 +0000106 ctx.WalkDeps(func(child, parent android.Module) bool {
107 if _, ok := child.(java.AndroidLibraryDependency); ok && child.Name() != "framework-res" {
108 // Stubs of BCP and SSCP libraries should not have any dependencies on apps
109 // This check ensures that we do not run into circular dependencies when UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT=true
110 ctx.ModuleErrorf(
111 "Module %s is not a valid dependency of the stub library %s\n."+
112 "If this dependency has been added via `libs` of java_sdk_library, please move it to `impl_only_libs`\n",
113 child.Name(), parent.Name())
114 return false // error detected
115 }
116 return true
117 })
118
Anton Hansson0860aaf2021-10-08 16:48:03 +0100119}
120
121type genruleProps struct {
122 Name *string
123 Cmd *string
124 Dists []android.Dist
125 Out []string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700126 Srcs proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +0100127 Tools []string
128 Visibility []string
129}
130
Anton Hanssoncb00f942022-01-13 09:45:12 +0000131type libraryProps struct {
Jihoon Kanga7073b52024-02-12 23:18:52 +0000132 Name *string
133 Sdk_version *string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700134 Static_libs proptools.Configurable[[]string]
Jihoon Kanga7073b52024-02-12 23:18:52 +0000135 Visibility []string
136 Defaults []string
137 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000138}
139
Anton Hansson4468d7c2022-01-14 12:10:01 +0000140type fgProps struct {
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700141 Name *string
142 Srcs proptools.Configurable[[]string]
143 Device_common_srcs proptools.Configurable[[]string]
144 Visibility []string
Anton Hansson4468d7c2022-01-14 12:10:01 +0000145}
146
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000147type defaultsProps struct {
148 Name *string
149 Api_surface *string
150 Api_contributions []string
151 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000152 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000153}
154
Anton Hansson0860aaf2021-10-08 16:48:03 +0100155// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
156type MergedTxtDefinition struct {
157 // "current.txt" or "removed.txt"
158 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100159 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
160 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100161 // The module for the non-updatable / non-module part of the api.
162 BaseTxt string
163 // The list of modules that are relevant for this merged txt.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700164 Modules proptools.Configurable[[]string]
Anton Hansson0860aaf2021-10-08 16:48:03 +0100165 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
166 ModuleTag string
167 // public, system, module-lib or system-server
168 Scope string
169}
170
Jihoon Kang31cf2742024-02-07 19:52:19 +0000171func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100172 metalavaCmd := "$(location metalava)"
173 // Silence reflection warnings. See b/168689341
174 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100175 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100176
177 filename := txt.TxtFilename
178 if txt.Scope != "public" {
179 filename = txt.Scope + "-" + filename
180 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000181 moduleName := ctx.ModuleName() + stubsTypeSuffix + filename
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000182
Anton Hansson0860aaf2021-10-08 16:48:03 +0100183 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000184 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100185 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000186 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100187 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700188 props.Srcs = proptools.NewSimpleConfigurable([]string{txt.BaseTxt})
189 props.Srcs.Append(createSrcs(txt.Modules, txt.ModuleTag))
Jihoon Kang31cf2742024-02-07 19:52:19 +0000190 if doDist {
191 props.Dists = []android.Dist{
192 {
193 Targets: []string{"droidcore"},
194 Dir: proptools.StringPtr("api"),
195 Dest: proptools.StringPtr(filename),
196 },
197 {
198 Targets: []string{"api_txt", "sdk"},
199 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
200 Dest: proptools.StringPtr(txt.DistFilename),
201 },
202 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100203 }
204 props.Visibility = []string{"//visibility:public"}
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700205 ctx.CreateModule(java.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100206}
207
Cole Faustb1fc07e2024-09-05 11:37:57 -0700208func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules proptools.Configurable[[]string]) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000209 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700210 name string
211 tag string
Cole Faustb1fc07e2024-09-05 11:37:57 -0700212 modules proptools.Configurable[[]string]
Cole Faustdcda3702022-10-04 14:46:35 -0700213 }{
214 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000215 name: "all-modules-public-annotations",
216 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700217 modules: modules,
218 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000219 name: "all-modules-system-annotations",
220 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700221 modules: modules,
222 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000223 name: "all-modules-module-lib-annotations",
224 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700225 modules: modules,
226 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000227 name: "all-modules-system-server-annotations",
228 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700229 modules: system_server_modules,
230 },
231 } {
232 props := fgProps{}
233 props.Name = proptools.StringPtr(i.name)
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700234 props.Device_common_srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800235 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700236 }
Anton Hansson74b15642022-06-23 08:27:23 +0000237}
238
Cole Faustb1fc07e2024-09-05 11:37:57 -0700239func createMergedPublicStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
240 modules = modules.Clone()
241 transformConfigurableArray(modules, "", ".stubs")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000242 props := libraryProps{}
243 props.Name = proptools.StringPtr("all-modules-public-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700244 props.Static_libs = modules
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000245 props.Sdk_version = proptools.StringPtr("module_current")
246 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000247 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000248 ctx.CreateModule(java.LibraryFactory, &props)
249}
250
Cole Faustb1fc07e2024-09-05 11:37:57 -0700251func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
252 modules = modules.Clone()
253 transformConfigurableArray(modules, "", ".stubs.exportable")
Jihoon Kang059b9492023-12-29 00:40:34 +0000254 props := libraryProps{}
255 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700256 props.Static_libs = modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000257 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
Cole Faustb1fc07e2024-09-05 11:37:57 -0700263func createMergedSystemStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000264 // First create the all-updatable-modules-system-stubs
265 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700266 updatable_modules := modules.Clone()
267 removeAll(updatable_modules, non_updatable_modules)
268 transformConfigurableArray(updatable_modules, "", ".stubs.system")
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000269 props := libraryProps{}
270 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700271 props.Static_libs = updatable_modules
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000272 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 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700280 static_libs := transformArray(non_updatable_modules, "", ".stubs.system")
281 static_libs = append(static_libs, "all-updatable-modules-system-stubs")
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000282 props := libraryProps{}
283 props.Name = proptools.StringPtr("all-modules-system-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700284 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000285 props.Sdk_version = proptools.StringPtr("module_current")
286 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000287 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000288 ctx.CreateModule(java.LibraryFactory, &props)
289 }
290}
291
Cole Faustb1fc07e2024-09-05 11:37:57 -0700292func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Jihoon Kang059b9492023-12-29 00:40:34 +0000293 // First create the all-updatable-modules-system-stubs
294 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700295 updatable_modules := modules.Clone()
296 removeAll(updatable_modules, non_updatable_modules)
297 transformConfigurableArray(updatable_modules, "", ".stubs.exportable.system")
Jihoon Kang059b9492023-12-29 00:40:34 +0000298 props := libraryProps{}
299 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700300 props.Static_libs = updatable_modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000301 props.Sdk_version = proptools.StringPtr("module_current")
302 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000303 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000304 ctx.CreateModule(java.LibraryFactory, &props)
305 }
306 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
307 // into all-modules-system-stubs.
308 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700309 static_libs := transformArray(non_updatable_modules, "", ".stubs.exportable.system")
310 static_libs = append(static_libs, "all-updatable-modules-system-stubs-exportable")
Jihoon Kang059b9492023-12-29 00:40:34 +0000311 props := libraryProps{}
312 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700313 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Jihoon Kang059b9492023-12-29 00:40:34 +0000314 props.Sdk_version = proptools.StringPtr("module_current")
315 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000316 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000317 ctx.CreateModule(java.LibraryFactory, &props)
318 }
319}
320
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000321func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000322 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000323 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700324 props.Static_libs = proptools.NewSimpleConfigurable(transformArray(non_updatable_modules, "", ".stubs.test"))
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000325 props.Sdk_version = proptools.StringPtr("module_current")
326 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000327 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000328 ctx.CreateModule(java.LibraryFactory, &props)
329}
330
Jihoon Kang059b9492023-12-29 00:40:34 +0000331func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
332 props := libraryProps{}
333 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700334 props.Static_libs = proptools.NewSimpleConfigurable(transformArray(non_updatable_modules, "", ".stubs.exportable.test"))
Jihoon Kang059b9492023-12-29 00:40:34 +0000335 props.Sdk_version = proptools.StringPtr("module_current")
336 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000337 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000338 ctx.CreateModule(java.LibraryFactory, &props)
339}
340
Cole Faustb1fc07e2024-09-05 11:37:57 -0700341func createMergedFrameworkImpl(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
342 modules = modules.Clone()
Anton Hansson95e89a82022-01-28 11:31:50 +0000343 // This module is for the "framework-all" module, which should not include the core libraries.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700344 removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000345 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
346 // against unstable APIs.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700347 removeAll(modules, non_updatable_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000348 // First create updatable-framework-module-impl, which contains all updatable modules.
349 // This module compiles against module_lib SDK.
350 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700351 transformConfigurableArray(modules, "", ".impl")
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000352 props := libraryProps{}
353 props.Name = proptools.StringPtr("updatable-framework-module-impl")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700354 props.Static_libs = modules
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000355 props.Sdk_version = proptools.StringPtr("module_current")
356 props.Visibility = []string{"//frameworks/base"}
357 ctx.CreateModule(java.LibraryFactory, &props)
358 }
359
360 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
361 // and all non-updatable modules. This module compiles against hidden APIs.
362 {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700363 static_libs := transformArray(non_updatable_modules, "", ".impl")
364 static_libs = append(static_libs, "updatable-framework-module-impl")
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000365 props := libraryProps{}
366 props.Name = proptools.StringPtr("all-framework-module-impl")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700367 props.Static_libs = proptools.NewSimpleConfigurable(static_libs)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000368 props.Sdk_version = proptools.StringPtr("core_platform")
369 props.Visibility = []string{"//frameworks/base"}
370 ctx.CreateModule(java.LibraryFactory, &props)
371 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000372}
373
Cole Faustb1fc07e2024-09-05 11:37:57 -0700374func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
375 modules = modules.Clone()
Jihoon Kang059b9492023-12-29 00:40:34 +0000376 // The user of this module compiles against the "core" SDK and against non-updatable modules,
377 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700378 removeAll(modules, core_libraries_modules)
379 removeAll(modules, non_updatable_modules)
380 transformConfigurableArray(modules, "", ".stubs.exportable.module_lib")
Jihoon Kang059b9492023-12-29 00:40:34 +0000381 props := libraryProps{}
382 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700383 props.Static_libs = modules
Jihoon Kang059b9492023-12-29 00:40:34 +0000384 props.Sdk_version = proptools.StringPtr("module_current")
385 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000386 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000387 ctx.CreateModule(java.LibraryFactory, &props)
388}
389
Cole Faustb1fc07e2024-09-05 11:37:57 -0700390func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
391 modules = modules.Clone()
Mark White3cc5e002023-08-07 11:18:09 +0000392 // The user of this module compiles against the "core" SDK and against non-updatable modules,
393 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700394 removeAll(modules, core_libraries_modules)
395 removeAll(modules, non_updatable_modules)
396 transformConfigurableArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000397 props := libraryProps{}
398 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700399 props.Static_libs = modules
Anton Hanssoncb00f942022-01-13 09:45:12 +0000400 props.Sdk_version = proptools.StringPtr("module_current")
401 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000402 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000403 ctx.CreateModule(java.LibraryFactory, &props)
404}
405
Cole Faustb1fc07e2024-09-05 11:37:57 -0700406func createMergedFrameworkSystemServerExportableStubs(ctx android.LoadHookContext, bootclasspath, system_server_classpath proptools.Configurable[[]string]) {
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100407 // The user of this module compiles against the "core" SDK and against non-updatable bootclasspathModules,
408 // so remove to avoid dupes.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700409 bootclasspathModules := bootclasspath.Clone()
410 removeAll(bootclasspathModules, core_libraries_modules)
411 removeAll(bootclasspathModules, non_updatable_modules)
412 transformConfigurableArray(bootclasspathModules, "", ".stubs.exportable.module_lib")
413
414 system_server_classpath = system_server_classpath.Clone()
415 transformConfigurableArray(system_server_classpath, "", ".stubs.exportable.system_server")
416
417 // Include all the module-lib APIs from the bootclasspath libraries.
418 // Then add all the system-server APIs from the service-* libraries.
419 bootclasspathModules.Append(system_server_classpath)
420
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100421 props := libraryProps{}
422 props.Name = proptools.StringPtr("framework-updatable-stubs-system_server_api-exportable")
Cole Faustb1fc07e2024-09-05 11:37:57 -0700423 props.Static_libs = bootclasspathModules
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100424 props.Sdk_version = proptools.StringPtr("system_server_current")
425 props.Visibility = []string{"//frameworks/base"}
426 props.Is_stubs_module = proptools.BoolPtr(true)
427 ctx.CreateModule(java.LibraryFactory, &props)
428}
429
Cole Faustb1fc07e2024-09-05 11:37:57 -0700430func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules proptools.Configurable[[]string]) {
Anton Hansson4468d7c2022-01-14 12:10:01 +0000431 props := fgProps{}
Jihoon Kange4553d02024-11-07 19:40:30 +0000432 props.Name = proptools.StringPtr("all-modules-public-stubs-source-exportable")
433 transformConfigurableArray(modules, "", ".stubs.source")
434 props.Device_common_srcs = createSrcs(modules, "{.exportable}")
Anton Hansson4468d7c2022-01-14 12:10:01 +0000435 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800436 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000437}
438
Cole Faustb1fc07e2024-09-05 11:37:57 -0700439func createMergedTxts(
440 ctx android.LoadHookContext,
441 bootclasspath proptools.Configurable[[]string],
442 system_server_classpath proptools.Configurable[[]string],
443 baseTxtModulePrefix string,
444 stubsTypeSuffix string,
445 doDist bool,
446) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100447 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000448
Anton Hansson0860aaf2021-10-08 16:48:03 +0100449 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100450 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100451 for i, f := range []string{"current.txt", "removed.txt"} {
452 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800453 TxtFilename: f,
454 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000455 BaseTxt: ":" + baseTxtModulePrefix + f,
Colin Crossc6420762023-12-07 12:38:40 -0800456 Modules: bootclasspath,
457 ModuleTag: "{.public" + tagSuffix[i],
458 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100459 })
460 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800461 TxtFilename: f,
462 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000463 BaseTxt: ":" + baseTxtModulePrefix + "system-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800464 Modules: bootclasspath,
465 ModuleTag: "{.system" + tagSuffix[i],
466 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100467 })
468 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800469 TxtFilename: f,
470 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000471 BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800472 Modules: bootclasspath,
473 ModuleTag: "{.module-lib" + tagSuffix[i],
474 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100475 })
476 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800477 TxtFilename: f,
478 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000479 BaseTxt: ":" + baseTxtModulePrefix + "system-server-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800480 Modules: system_server_classpath,
481 ModuleTag: "{.system-server" + tagSuffix[i],
482 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100483 })
484 }
485 for _, txt := range textFiles {
Jihoon Kang31cf2742024-02-07 19:52:19 +0000486 createMergedTxt(ctx, txt, stubsTypeSuffix, doDist)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100487 }
488}
489
490func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700491 bootclasspath := a.properties.Bootclasspath.Clone()
492 system_server_classpath := a.properties.System_server_classpath.Clone()
Anton Hansson07a12952022-01-12 17:28:39 +0000493 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
Cole Faustb1fc07e2024-09-05 11:37:57 -0700494 bootclasspath.AppendSimpleValue(a.properties.Conditional_bootclasspath)
Anton Hansson07a12952022-01-12 17:28:39 +0000495 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000496 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false)
497 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100498
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000499 createMergedPublicStubs(ctx, bootclasspath)
500 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000501 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000502 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
503 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000504
Jihoon Kang059b9492023-12-29 00:40:34 +0000505 createMergedPublicExportableStubs(ctx, bootclasspath)
506 createMergedSystemExportableStubs(ctx, bootclasspath)
507 createMergedTestExportableStubsForNonUpdatableModules(ctx)
508 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
Paul Duffinfb5e07d2024-05-02 14:51:41 +0100509 createMergedFrameworkSystemServerExportableStubs(ctx, bootclasspath, system_server_classpath)
Jihoon Kang059b9492023-12-29 00:40:34 +0000510
Cole Faustdcda3702022-10-04 14:46:35 -0700511 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000512
Anton Hansson4468d7c2022-01-14 12:10:01 +0000513 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100514}
515
516func combinedApisModuleFactory() android.Module {
517 module := &CombinedApis{}
518 module.AddProperties(&module.properties)
Cole Faustfbc4f882024-10-07 16:35:00 -0700519 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100520 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
521 return module
522}
Anton Hanssonfd316452022-01-14 11:15:52 +0000523
524// Various utility methods below.
525
526// Creates an array of ":<m><tag>" for each m in <modules>.
Cole Faustb1fc07e2024-09-05 11:37:57 -0700527func createSrcs(modules proptools.Configurable[[]string], tag string) proptools.Configurable[[]string] {
528 result := modules.Clone()
529 transformConfigurableArray(result, ":", tag)
530 return result
Anton Hanssonfd316452022-01-14 11:15:52 +0000531}
532
533// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
534func transformArray(modules []string, prefix, suffix string) []string {
535 a := make([]string, 0, len(modules))
536 for _, module := range modules {
537 a = append(a, prefix+module+suffix)
538 }
539 return a
540}
541
Cole Faustb1fc07e2024-09-05 11:37:57 -0700542// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
543func transformConfigurableArray(modules proptools.Configurable[[]string], prefix, suffix string) {
544 modules.AddPostProcessor(func(s []string) []string {
545 return transformArray(s, prefix, suffix)
546 })
547}
548
549func removeAll(s proptools.Configurable[[]string], vs []string) {
550 s.AddPostProcessor(func(s []string) []string {
551 a := make([]string, 0, len(s))
552 for _, module := range s {
553 if !slices.Contains(vs, module) {
554 a = append(a, module)
555 }
556 }
557 return a
558 })
Anton Hanssonfd316452022-01-14 11:15:52 +0000559}
560
561func remove(s []string, v string) []string {
562 s2 := make([]string, 0, len(s))
563 for _, sv := range s {
564 if sv != v {
565 s2 = append(s2, sv)
566 }
567 }
568 return s2
569}