blob: fa2be21db09fae0b7db5924b716e0dd0723eb777 [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 {
96 Name *string
97 Sdk_version *string
98 Static_libs []string
99 Visibility []string
Jihoon Kang1453baa2023-05-27 05:32:30 +0000100 Defaults []string
Anton Hanssoncb00f942022-01-13 09:45:12 +0000101}
102
Anton Hansson4468d7c2022-01-14 12:10:01 +0000103type fgProps struct {
104 Name *string
105 Srcs []string
106 Visibility []string
107}
108
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000109type defaultsProps struct {
110 Name *string
111 Api_surface *string
112 Api_contributions []string
113 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000114 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000115}
116
Anton Hansson0860aaf2021-10-08 16:48:03 +0100117// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
118type MergedTxtDefinition struct {
119 // "current.txt" or "removed.txt"
120 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100121 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
122 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100123 // The module for the non-updatable / non-module part of the api.
124 BaseTxt string
125 // The list of modules that are relevant for this merged txt.
126 Modules []string
127 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
128 ModuleTag string
129 // public, system, module-lib or system-server
130 Scope string
131}
132
133func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
134 metalavaCmd := "$(location metalava)"
135 // Silence reflection warnings. See b/168689341
136 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100137 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100138
139 filename := txt.TxtFilename
140 if txt.Scope != "public" {
141 filename = txt.Scope + "-" + filename
142 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000143 moduleName := ctx.ModuleName() + "-" + filename
144
Anton Hansson0860aaf2021-10-08 16:48:03 +0100145 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000146 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100147 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000148 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100149 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000150 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100151 props.Dists = []android.Dist{
152 {
153 Targets: []string{"droidcore"},
154 Dir: proptools.StringPtr("api"),
155 Dest: proptools.StringPtr(filename),
156 },
157 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100158 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100159 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100160 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100161 },
162 }
163 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800164 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100165}
166
Cole Faustdcda3702022-10-04 14:46:35 -0700167func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000168 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700169 name string
170 tag string
171 modules []string
172 }{
173 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000174 name: "all-modules-public-annotations",
175 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700176 modules: modules,
177 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000178 name: "all-modules-system-annotations",
179 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700180 modules: modules,
181 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000182 name: "all-modules-module-lib-annotations",
183 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700184 modules: modules,
185 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000186 name: "all-modules-system-server-annotations",
187 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700188 modules: system_server_modules,
189 },
190 } {
191 props := fgProps{}
192 props.Name = proptools.StringPtr(i.name)
193 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800194 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700195 }
Anton Hansson74b15642022-06-23 08:27:23 +0000196}
197
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000198func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
199 props := libraryProps{}
200 props.Name = proptools.StringPtr("all-modules-public-stubs")
201 props.Static_libs = transformArray(modules, "", ".stubs")
202 props.Sdk_version = proptools.StringPtr("module_current")
203 props.Visibility = []string{"//frameworks/base"}
204 ctx.CreateModule(java.LibraryFactory, &props)
205}
206
Jihoon Kang059b9492023-12-29 00:40:34 +0000207func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
208 props := libraryProps{}
209 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
210 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
211 props.Sdk_version = proptools.StringPtr("module_current")
212 props.Visibility = []string{"//frameworks/base"}
213 ctx.CreateModule(java.LibraryFactory, &props)
214}
215
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000216func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000217 // First create the all-updatable-modules-system-stubs
218 {
219 updatable_modules := removeAll(modules, non_updatable_modules)
220 props := libraryProps{}
221 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
222 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
223 props.Sdk_version = proptools.StringPtr("module_current")
224 props.Visibility = []string{"//frameworks/base"}
225 ctx.CreateModule(java.LibraryFactory, &props)
226 }
227 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
228 // into all-modules-system-stubs.
229 {
230 props := libraryProps{}
231 props.Name = proptools.StringPtr("all-modules-system-stubs")
232 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
233 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
234 props.Sdk_version = proptools.StringPtr("module_current")
235 props.Visibility = []string{"//frameworks/base"}
236 ctx.CreateModule(java.LibraryFactory, &props)
237 }
238}
239
Jihoon Kang059b9492023-12-29 00:40:34 +0000240func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
241 // First create the all-updatable-modules-system-stubs
242 {
243 updatable_modules := removeAll(modules, non_updatable_modules)
244 props := libraryProps{}
245 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
246 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
247 props.Sdk_version = proptools.StringPtr("module_current")
248 props.Visibility = []string{"//frameworks/base"}
249 ctx.CreateModule(java.LibraryFactory, &props)
250 }
251 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
252 // into all-modules-system-stubs.
253 {
254 props := libraryProps{}
255 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
256 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
257 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
258 props.Sdk_version = proptools.StringPtr("module_current")
259 props.Visibility = []string{"//frameworks/base"}
260 ctx.CreateModule(java.LibraryFactory, &props)
261 }
262}
263
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000264func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000265 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000266 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
267 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000268 props.Sdk_version = proptools.StringPtr("module_current")
269 props.Visibility = []string{"//frameworks/base"}
270 ctx.CreateModule(java.LibraryFactory, &props)
271}
272
Jihoon Kang059b9492023-12-29 00:40:34 +0000273func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
274 props := libraryProps{}
275 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
276 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
277 props.Sdk_version = proptools.StringPtr("module_current")
278 props.Visibility = []string{"//frameworks/base"}
279 ctx.CreateModule(java.LibraryFactory, &props)
280}
281
Anton Hansson95e89a82022-01-28 11:31:50 +0000282func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
283 // This module is for the "framework-all" module, which should not include the core libraries.
284 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000285 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
286 // against unstable APIs.
287 modules = removeAll(modules, non_updatable_modules)
288 // First create updatable-framework-module-impl, which contains all updatable modules.
289 // This module compiles against module_lib SDK.
290 {
291 props := libraryProps{}
292 props.Name = proptools.StringPtr("updatable-framework-module-impl")
293 props.Static_libs = transformArray(modules, "", ".impl")
294 props.Sdk_version = proptools.StringPtr("module_current")
295 props.Visibility = []string{"//frameworks/base"}
296 ctx.CreateModule(java.LibraryFactory, &props)
297 }
298
299 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
300 // and all non-updatable modules. This module compiles against hidden APIs.
301 {
302 props := libraryProps{}
303 props.Name = proptools.StringPtr("all-framework-module-impl")
304 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
305 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
306 props.Sdk_version = proptools.StringPtr("core_platform")
307 props.Visibility = []string{"//frameworks/base"}
308 ctx.CreateModule(java.LibraryFactory, &props)
309 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000310}
311
Jihoon Kang059b9492023-12-29 00:40:34 +0000312func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
313 // The user of this module compiles against the "core" SDK and against non-updatable modules,
314 // so remove to avoid dupes.
315 modules = removeAll(modules, core_libraries_modules)
316 modules = removeAll(modules, non_updatable_modules)
317 props := libraryProps{}
318 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
319 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
320 props.Sdk_version = proptools.StringPtr("module_current")
321 props.Visibility = []string{"//frameworks/base"}
322 ctx.CreateModule(java.LibraryFactory, &props)
323}
324
Anton Hansson95e89a82022-01-28 11:31:50 +0000325func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000326 // The user of this module compiles against the "core" SDK and against non-updatable modules,
327 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000328 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000329 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000330 props := libraryProps{}
331 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000332 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000333 props.Sdk_version = proptools.StringPtr("module_current")
334 props.Visibility = []string{"//frameworks/base"}
335 ctx.CreateModule(java.LibraryFactory, &props)
336}
337
Anton Hansson4468d7c2022-01-14 12:10:01 +0000338func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
339 props := fgProps{}
340 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
341 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
342 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800343 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000344}
345
Anton Hansson07a12952022-01-12 17:28:39 +0000346func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100347 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000348
Anton Hansson0860aaf2021-10-08 16:48:03 +0100349 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100350 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100351 for i, f := range []string{"current.txt", "removed.txt"} {
352 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800353 TxtFilename: f,
354 DistFilename: distFilename[i],
355 BaseTxt: ":non-updatable-" + f,
356 Modules: bootclasspath,
357 ModuleTag: "{.public" + tagSuffix[i],
358 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100359 })
360 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800361 TxtFilename: f,
362 DistFilename: distFilename[i],
363 BaseTxt: ":non-updatable-system-" + f,
364 Modules: bootclasspath,
365 ModuleTag: "{.system" + tagSuffix[i],
366 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100367 })
368 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800369 TxtFilename: f,
370 DistFilename: distFilename[i],
371 BaseTxt: ":non-updatable-module-lib-" + f,
372 Modules: bootclasspath,
373 ModuleTag: "{.module-lib" + tagSuffix[i],
374 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100375 })
376 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800377 TxtFilename: f,
378 DistFilename: distFilename[i],
379 BaseTxt: ":non-updatable-system-server-" + f,
380 Modules: system_server_classpath,
381 ModuleTag: "{.system-server" + tagSuffix[i],
382 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100383 })
384 }
385 for _, txt := range textFiles {
386 createMergedTxt(ctx, txt)
387 }
388}
389
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000390func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
391 defaultsSdkKinds := []android.SdkKind{
392 android.SdkPublic, android.SdkSystem, android.SdkModule,
393 }
394 for _, sdkKind := range defaultsSdkKinds {
395 props := defaultsProps{}
396 props.Name = proptools.StringPtr(
397 sdkKind.DefaultJavaLibraryName() + "_contributions")
398 if sdkKind == android.SdkModule {
399 props.Name = proptools.StringPtr(
400 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
401 }
402 props.Api_surface = proptools.StringPtr(sdkKind.String())
403 apiSuffix := ""
404 if sdkKind != android.SdkPublic {
405 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
406 }
407 props.Api_contributions = transformArray(
408 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
409 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000410 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000411 ctx.CreateModule(java.DefaultsFactory, &props)
412 }
413}
414
Jihoon Kang1453baa2023-05-27 05:32:30 +0000415func createFullApiLibraries(ctx android.LoadHookContext) {
416 javaLibraryNames := []string{
417 "android_stubs_current",
418 "android_system_stubs_current",
419 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000420 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000421 "android_module_lib_stubs_current",
422 "android_system_server_stubs_current",
423 }
424
425 for _, libraryName := range javaLibraryNames {
426 props := libraryProps{}
427 props.Name = proptools.StringPtr(libraryName)
428 staticLib := libraryName + ".from-source"
429 if ctx.Config().BuildFromTextStub() {
430 staticLib = libraryName + ".from-text"
431 }
432 props.Static_libs = []string{staticLib}
433 props.Defaults = []string{"android.jar_defaults"}
434 props.Visibility = []string{"//visibility:public"}
435
436 ctx.CreateModule(java.LibraryFactory, &props)
437 }
438}
439
Jihoon Kang059b9492023-12-29 00:40:34 +0000440func createFullExportableApiLibraries(ctx android.LoadHookContext) {
441 javaLibraryNames := []string{
442 "android_stubs_current_exportable",
443 "android_system_stubs_current_exportable",
444 "android_test_stubs_current_exportable",
445 "android_module_lib_stubs_current_exportable",
446 "android_system_server_stubs_current_exportable",
447 }
448
449 for _, libraryName := range javaLibraryNames {
450 props := libraryProps{}
451 props.Name = proptools.StringPtr(libraryName)
452 staticLib := libraryName + ".from-source"
453 props.Static_libs = []string{staticLib}
454 props.Defaults = []string{"android.jar_defaults"}
455 props.Visibility = []string{"//visibility:public"}
456
457 ctx.CreateModule(java.LibraryFactory, &props)
458 }
459}
460
Anton Hansson0860aaf2021-10-08 16:48:03 +0100461func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000462 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700463 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000464 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
465 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
466 sort.Strings(bootclasspath)
467 }
Cole Faustdcda3702022-10-04 14:46:35 -0700468 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100469
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000470 createMergedPublicStubs(ctx, bootclasspath)
471 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000472 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000473 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
474 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000475
Jihoon Kang059b9492023-12-29 00:40:34 +0000476 createMergedPublicExportableStubs(ctx, bootclasspath)
477 createMergedSystemExportableStubs(ctx, bootclasspath)
478 createMergedTestExportableStubsForNonUpdatableModules(ctx)
479 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
480
Cole Faustdcda3702022-10-04 14:46:35 -0700481 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000482
Anton Hansson4468d7c2022-01-14 12:10:01 +0000483 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000484
485 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000486
487 createFullApiLibraries(ctx)
Jihoon Kang059b9492023-12-29 00:40:34 +0000488
489 createFullExportableApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100490}
491
492func combinedApisModuleFactory() android.Module {
493 module := &CombinedApis{}
494 module.AddProperties(&module.properties)
495 android.InitAndroidModule(module)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000496 android.InitDefaultableModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100497 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
498 return module
499}
Anton Hanssonfd316452022-01-14 11:15:52 +0000500
501// Various utility methods below.
502
503// Creates an array of ":<m><tag>" for each m in <modules>.
504func createSrcs(modules []string, tag string) []string {
505 return transformArray(modules, ":", tag)
506}
507
508// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
509func transformArray(modules []string, prefix, suffix string) []string {
510 a := make([]string, 0, len(modules))
511 for _, module := range modules {
512 a = append(a, prefix+module+suffix)
513 }
514 return a
515}
516
517func removeAll(s []string, vs []string) []string {
518 for _, v := range vs {
519 s = remove(s, v)
520 }
521 return s
522}
523
524func remove(s []string, v string) []string {
525 s2 := make([]string, 0, len(s))
526 for _, sv := range s {
527 if sv != v {
528 s2 = append(s2, sv)
529 }
530 }
531 return s2
532}
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000533
534// Defaults
535type CombinedApisModuleDefaults struct {
536 android.ModuleBase
537 android.DefaultsModuleBase
538}
539
540func CombinedApisModuleDefaultsFactory() android.Module {
541 module := &CombinedApisModuleDefaults{}
542 module.AddProperties(&CombinedApisProperties{})
543 android.InitDefaultsModule(module)
544 return module
545}