blob: 3632fa891df9d4e969e5f4a62256d7b359df1d82 [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 (
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +000018 "fmt"
Anton Hansson07a12952022-01-12 17:28:39 +000019 "sort"
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +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
57 Bootclasspath []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
61 System_server_classpath []string
Anton Hansson0860aaf2021-10-08 16:48:03 +010062}
63
64type CombinedApis struct {
65 android.ModuleBase
Harshit Mahajanb52adbc2023-12-15 21:56:42 +000066 android.DefaultableModuleBase
Anton Hansson0860aaf2021-10-08 16:48:03 +010067
68 properties CombinedApisProperties
69}
70
71func init() {
72 registerBuildComponents(android.InitRegistrationContext)
73}
74
75func registerBuildComponents(ctx android.RegistrationContext) {
76 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +000077 ctx.RegisterModuleType("combined_apis_defaults", CombinedApisModuleDefaultsFactory)
Anton Hansson0860aaf2021-10-08 16:48:03 +010078}
79
80var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
81
82func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
83}
84
85type genruleProps struct {
86 Name *string
87 Cmd *string
88 Dists []android.Dist
89 Out []string
90 Srcs []string
91 Tools []string
92 Visibility []string
93}
94
Anton Hanssoncb00f942022-01-13 09:45:12 +000095type libraryProps struct {
Jihoon Kanga7073b52024-02-12 23:18:52 +000096 Name *string
97 Sdk_version *string
98 Static_libs []string
99 Visibility []string
100 Defaults []string
101 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000102}
103
Anton Hansson4468d7c2022-01-14 12:10:01 +0000104type fgProps struct {
105 Name *string
106 Srcs []string
107 Visibility []string
108}
109
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000110type defaultsProps struct {
111 Name *string
112 Api_surface *string
113 Api_contributions []string
114 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000115 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000116}
117
Anton Hansson0860aaf2021-10-08 16:48:03 +0100118// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
119type MergedTxtDefinition struct {
120 // "current.txt" or "removed.txt"
121 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100122 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
123 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100124 // The module for the non-updatable / non-module part of the api.
125 BaseTxt string
126 // The list of modules that are relevant for this merged txt.
127 Modules []string
128 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
129 ModuleTag string
130 // public, system, module-lib or system-server
131 Scope string
132}
133
134func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
135 metalavaCmd := "$(location metalava)"
136 // Silence reflection warnings. See b/168689341
137 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100138 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100139
140 filename := txt.TxtFilename
141 if txt.Scope != "public" {
142 filename = txt.Scope + "-" + filename
143 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000144 moduleName := ctx.ModuleName() + "-" + filename
145
Anton Hansson0860aaf2021-10-08 16:48:03 +0100146 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000147 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100148 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000149 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100150 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000151 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100152 props.Dists = []android.Dist{
153 {
154 Targets: []string{"droidcore"},
155 Dir: proptools.StringPtr("api"),
156 Dest: proptools.StringPtr(filename),
157 },
158 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100159 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100161 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100162 },
163 }
164 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800165 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100166}
167
Cole Faustdcda3702022-10-04 14:46:35 -0700168func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000169 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700170 name string
171 tag string
172 modules []string
173 }{
174 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000175 name: "all-modules-public-annotations",
176 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700177 modules: modules,
178 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000179 name: "all-modules-system-annotations",
180 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700181 modules: modules,
182 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000183 name: "all-modules-module-lib-annotations",
184 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700185 modules: modules,
186 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000187 name: "all-modules-system-server-annotations",
188 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700189 modules: system_server_modules,
190 },
191 } {
192 props := fgProps{}
193 props.Name = proptools.StringPtr(i.name)
194 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800195 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700196 }
Anton Hansson74b15642022-06-23 08:27:23 +0000197}
198
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000199func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
200 props := libraryProps{}
201 props.Name = proptools.StringPtr("all-modules-public-stubs")
202 props.Static_libs = transformArray(modules, "", ".stubs")
203 props.Sdk_version = proptools.StringPtr("module_current")
204 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000205 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000206 ctx.CreateModule(java.LibraryFactory, &props)
207}
208
Jihoon Kang059b9492023-12-29 00:40:34 +0000209func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
210 props := libraryProps{}
211 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
212 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
213 props.Sdk_version = proptools.StringPtr("module_current")
214 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000215 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000216 ctx.CreateModule(java.LibraryFactory, &props)
217}
218
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000219func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000220 // First create the all-updatable-modules-system-stubs
221 {
222 updatable_modules := removeAll(modules, non_updatable_modules)
223 props := libraryProps{}
224 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
225 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
226 props.Sdk_version = proptools.StringPtr("module_current")
227 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000228 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000229 ctx.CreateModule(java.LibraryFactory, &props)
230 }
231 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
232 // into all-modules-system-stubs.
233 {
234 props := libraryProps{}
235 props.Name = proptools.StringPtr("all-modules-system-stubs")
236 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
237 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
238 props.Sdk_version = proptools.StringPtr("module_current")
239 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000240 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000241 ctx.CreateModule(java.LibraryFactory, &props)
242 }
243}
244
Jihoon Kang059b9492023-12-29 00:40:34 +0000245func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
246 // First create the all-updatable-modules-system-stubs
247 {
248 updatable_modules := removeAll(modules, non_updatable_modules)
249 props := libraryProps{}
250 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
251 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
252 props.Sdk_version = proptools.StringPtr("module_current")
253 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000254 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000255 ctx.CreateModule(java.LibraryFactory, &props)
256 }
257 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
258 // into all-modules-system-stubs.
259 {
260 props := libraryProps{}
261 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
262 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
263 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
264 props.Sdk_version = proptools.StringPtr("module_current")
265 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000266 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000267 ctx.CreateModule(java.LibraryFactory, &props)
268 }
269}
270
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000271func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000272 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000273 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
274 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000275 props.Sdk_version = proptools.StringPtr("module_current")
276 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000277 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000278 ctx.CreateModule(java.LibraryFactory, &props)
279}
280
Jihoon Kang059b9492023-12-29 00:40:34 +0000281func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
282 props := libraryProps{}
283 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
284 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
285 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)
Jihoon Kang059b9492023-12-29 00:40:34 +0000288 ctx.CreateModule(java.LibraryFactory, &props)
289}
290
Anton Hansson95e89a82022-01-28 11:31:50 +0000291func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
292 // This module is for the "framework-all" module, which should not include the core libraries.
293 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000294 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
295 // against unstable APIs.
296 modules = removeAll(modules, non_updatable_modules)
297 // First create updatable-framework-module-impl, which contains all updatable modules.
298 // This module compiles against module_lib SDK.
299 {
300 props := libraryProps{}
301 props.Name = proptools.StringPtr("updatable-framework-module-impl")
302 props.Static_libs = transformArray(modules, "", ".impl")
303 props.Sdk_version = proptools.StringPtr("module_current")
304 props.Visibility = []string{"//frameworks/base"}
305 ctx.CreateModule(java.LibraryFactory, &props)
306 }
307
308 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
309 // and all non-updatable modules. This module compiles against hidden APIs.
310 {
311 props := libraryProps{}
312 props.Name = proptools.StringPtr("all-framework-module-impl")
313 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
314 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
315 props.Sdk_version = proptools.StringPtr("core_platform")
316 props.Visibility = []string{"//frameworks/base"}
317 ctx.CreateModule(java.LibraryFactory, &props)
318 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000319}
320
Jihoon Kang059b9492023-12-29 00:40:34 +0000321func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
322 // The user of this module compiles against the "core" SDK and against non-updatable modules,
323 // so remove to avoid dupes.
324 modules = removeAll(modules, core_libraries_modules)
325 modules = removeAll(modules, non_updatable_modules)
326 props := libraryProps{}
327 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
328 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
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 createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000336 // The user of this module compiles against the "core" SDK and against non-updatable modules,
337 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000338 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000339 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000340 props := libraryProps{}
341 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000342 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000343 props.Sdk_version = proptools.StringPtr("module_current")
344 props.Visibility = []string{"//frameworks/base"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000345 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000346 ctx.CreateModule(java.LibraryFactory, &props)
347}
348
Anton Hansson4468d7c2022-01-14 12:10:01 +0000349func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
350 props := fgProps{}
351 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
352 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
353 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800354 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000355}
356
Anton Hansson07a12952022-01-12 17:28:39 +0000357func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100358 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000359
Anton Hansson0860aaf2021-10-08 16:48:03 +0100360 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100361 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100362 for i, f := range []string{"current.txt", "removed.txt"} {
363 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800364 TxtFilename: f,
365 DistFilename: distFilename[i],
366 BaseTxt: ":non-updatable-" + f,
367 Modules: bootclasspath,
368 ModuleTag: "{.public" + tagSuffix[i],
369 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100370 })
371 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800372 TxtFilename: f,
373 DistFilename: distFilename[i],
374 BaseTxt: ":non-updatable-system-" + f,
375 Modules: bootclasspath,
376 ModuleTag: "{.system" + tagSuffix[i],
377 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100378 })
379 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800380 TxtFilename: f,
381 DistFilename: distFilename[i],
382 BaseTxt: ":non-updatable-module-lib-" + f,
383 Modules: bootclasspath,
384 ModuleTag: "{.module-lib" + tagSuffix[i],
385 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100386 })
387 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800388 TxtFilename: f,
389 DistFilename: distFilename[i],
390 BaseTxt: ":non-updatable-system-server-" + f,
391 Modules: system_server_classpath,
392 ModuleTag: "{.system-server" + tagSuffix[i],
393 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100394 })
395 }
396 for _, txt := range textFiles {
397 createMergedTxt(ctx, txt)
398 }
399}
400
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000401func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
402 defaultsSdkKinds := []android.SdkKind{
403 android.SdkPublic, android.SdkSystem, android.SdkModule,
404 }
405 for _, sdkKind := range defaultsSdkKinds {
406 props := defaultsProps{}
407 props.Name = proptools.StringPtr(
408 sdkKind.DefaultJavaLibraryName() + "_contributions")
409 if sdkKind == android.SdkModule {
410 props.Name = proptools.StringPtr(
411 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
412 }
413 props.Api_surface = proptools.StringPtr(sdkKind.String())
414 apiSuffix := ""
415 if sdkKind != android.SdkPublic {
416 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
417 }
418 props.Api_contributions = transformArray(
419 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
420 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000421 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000422 ctx.CreateModule(java.DefaultsFactory, &props)
423 }
424}
425
Jihoon Kang1453baa2023-05-27 05:32:30 +0000426func createFullApiLibraries(ctx android.LoadHookContext) {
427 javaLibraryNames := []string{
428 "android_stubs_current",
429 "android_system_stubs_current",
430 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000431 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000432 "android_module_lib_stubs_current",
433 "android_system_server_stubs_current",
434 }
435
436 for _, libraryName := range javaLibraryNames {
437 props := libraryProps{}
438 props.Name = proptools.StringPtr(libraryName)
439 staticLib := libraryName + ".from-source"
440 if ctx.Config().BuildFromTextStub() {
441 staticLib = libraryName + ".from-text"
442 }
443 props.Static_libs = []string{staticLib}
444 props.Defaults = []string{"android.jar_defaults"}
445 props.Visibility = []string{"//visibility:public"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000446 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000447
448 ctx.CreateModule(java.LibraryFactory, &props)
449 }
450}
451
Jihoon Kang059b9492023-12-29 00:40:34 +0000452func createFullExportableApiLibraries(ctx android.LoadHookContext) {
453 javaLibraryNames := []string{
454 "android_stubs_current_exportable",
455 "android_system_stubs_current_exportable",
456 "android_test_stubs_current_exportable",
457 "android_module_lib_stubs_current_exportable",
458 "android_system_server_stubs_current_exportable",
459 }
460
461 for _, libraryName := range javaLibraryNames {
462 props := libraryProps{}
463 props.Name = proptools.StringPtr(libraryName)
464 staticLib := libraryName + ".from-source"
465 props.Static_libs = []string{staticLib}
466 props.Defaults = []string{"android.jar_defaults"}
467 props.Visibility = []string{"//visibility:public"}
Jihoon Kanga7073b52024-02-12 23:18:52 +0000468 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000469
470 ctx.CreateModule(java.LibraryFactory, &props)
471 }
472}
473
Anton Hansson0860aaf2021-10-08 16:48:03 +0100474func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000475 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700476 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000477 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
478 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
479 sort.Strings(bootclasspath)
480 }
Cole Faustdcda3702022-10-04 14:46:35 -0700481 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100482
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000483 createMergedPublicStubs(ctx, bootclasspath)
484 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000485 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000486 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
487 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000488
Jihoon Kang059b9492023-12-29 00:40:34 +0000489 createMergedPublicExportableStubs(ctx, bootclasspath)
490 createMergedSystemExportableStubs(ctx, bootclasspath)
491 createMergedTestExportableStubsForNonUpdatableModules(ctx)
492 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
493
Cole Faustdcda3702022-10-04 14:46:35 -0700494 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000495
Anton Hansson4468d7c2022-01-14 12:10:01 +0000496 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000497
498 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000499
500 createFullApiLibraries(ctx)
Jihoon Kang059b9492023-12-29 00:40:34 +0000501
502 createFullExportableApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100503}
504
505func combinedApisModuleFactory() android.Module {
506 module := &CombinedApis{}
507 module.AddProperties(&module.properties)
508 android.InitAndroidModule(module)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000509 android.InitDefaultableModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100510 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
511 return module
512}
Anton Hanssonfd316452022-01-14 11:15:52 +0000513
514// Various utility methods below.
515
516// Creates an array of ":<m><tag>" for each m in <modules>.
517func createSrcs(modules []string, tag string) []string {
518 return transformArray(modules, ":", tag)
519}
520
521// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
522func transformArray(modules []string, prefix, suffix string) []string {
523 a := make([]string, 0, len(modules))
524 for _, module := range modules {
525 a = append(a, prefix+module+suffix)
526 }
527 return a
528}
529
530func removeAll(s []string, vs []string) []string {
531 for _, v := range vs {
532 s = remove(s, v)
533 }
534 return s
535}
536
537func remove(s []string, v string) []string {
538 s2 := make([]string, 0, len(s))
539 for _, sv := range s {
540 if sv != v {
541 s2 = append(s2, sv)
542 }
543 }
544 return s2
545}
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000546
547// Defaults
548type CombinedApisModuleDefaults struct {
549 android.ModuleBase
550 android.DefaultsModuleBase
551}
552
553func CombinedApisModuleDefaultsFactory() android.Module {
554 module := &CombinedApisModuleDefaults{}
555 module.AddProperties(&CombinedApisProperties{})
556 android.InitDefaultsModule(module)
557 return module
558}