blob: f3f1af9be530c406001063a322f99d7d649a665d [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"
Roshan Pius0fa80892023-11-14 14:30:26 -080034const nfc = "framework-nfc"
Anton Hansson09a9c4e2022-04-08 10:59:46 +010035
Anton Hansson95e89a82022-01-28 11:31:50 +000036var core_libraries_modules = []string{art, conscrypt, i18n}
Zi Wang0d6a5302023-02-16 14:54:01 -080037
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000038// List of modules that are not yet updatable, and hence they can still compile
39// against hidden APIs. These modules are filtered out when building the
40// updatable-framework-module-impl (because updatable-framework-module-impl is
41// built against module_current SDK). Instead they are directly statically
42// linked into the all-framework-module-lib, which is building against hidden
43// APIs.
Nikita Ioffe5593fbb2022-12-01 14:52:34 +000044// In addition, the modules in this list are allowed to contribute to test APIs
45// stubs.
Roshan Pius0fa80892023-11-14 14:30:26 -080046var non_updatable_modules = []string{virtualization, location, nfc}
Anton Hansson05e944d2022-01-13 12:26:30 +000047
Anton Hansson0860aaf2021-10-08 16:48:03 +010048// The intention behind this soong plugin is to generate a number of "merged"
49// API-related modules that would otherwise require a large amount of very
50// similar Android.bp boilerplate to define. For example, the merged current.txt
51// API definitions (created by merging the non-updatable current.txt with all
52// the module current.txts). This simplifies the addition of new android
53// modules, by reducing the number of genrules etc a new module must be added to.
54
55// The properties of the combined_apis module type.
56type CombinedApisProperties struct {
Anton Hansson16ff3572022-01-11 18:36:35 +000057 // Module libraries in the bootclasspath
58 Bootclasspath []string
Anton Hansson07a12952022-01-12 17:28:39 +000059 // Module libraries on the bootclasspath if include_nonpublic_framework_api is true.
60 Conditional_bootclasspath []string
Anton Hansson16ff3572022-01-11 18:36:35 +000061 // Module libraries in system server
62 System_server_classpath []string
Anton Hansson0860aaf2021-10-08 16:48:03 +010063}
64
65type CombinedApis struct {
66 android.ModuleBase
67
68 properties CombinedApisProperties
69}
70
71func init() {
72 registerBuildComponents(android.InitRegistrationContext)
73}
74
75func registerBuildComponents(ctx android.RegistrationContext) {
76 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
77}
78
79var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
80
81func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
82}
83
84type genruleProps struct {
85 Name *string
86 Cmd *string
87 Dists []android.Dist
88 Out []string
89 Srcs []string
90 Tools []string
91 Visibility []string
92}
93
Anton Hanssoncb00f942022-01-13 09:45:12 +000094type libraryProps struct {
95 Name *string
96 Sdk_version *string
97 Static_libs []string
98 Visibility []string
Jihoon Kang1453baa2023-05-27 05:32:30 +000099 Defaults []string
Anton Hanssoncb00f942022-01-13 09:45:12 +0000100}
101
Anton Hansson4468d7c2022-01-14 12:10:01 +0000102type fgProps struct {
103 Name *string
104 Srcs []string
105 Visibility []string
106}
107
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000108type defaultsProps struct {
109 Name *string
110 Api_surface *string
111 Api_contributions []string
112 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000113 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000114}
115
Anton Hansson0860aaf2021-10-08 16:48:03 +0100116// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
117type MergedTxtDefinition struct {
118 // "current.txt" or "removed.txt"
119 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100120 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
121 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100122 // The module for the non-updatable / non-module part of the api.
123 BaseTxt string
124 // The list of modules that are relevant for this merged txt.
125 Modules []string
126 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
127 ModuleTag string
128 // public, system, module-lib or system-server
129 Scope string
130}
131
132func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
133 metalavaCmd := "$(location metalava)"
134 // Silence reflection warnings. See b/168689341
135 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100136 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100137
138 filename := txt.TxtFilename
139 if txt.Scope != "public" {
140 filename = txt.Scope + "-" + filename
141 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000142 moduleName := ctx.ModuleName() + "-" + filename
143
Anton Hansson0860aaf2021-10-08 16:48:03 +0100144 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000145 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100146 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000147 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100148 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000149 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100150 props.Dists = []android.Dist{
151 {
152 Targets: []string{"droidcore"},
153 Dir: proptools.StringPtr("api"),
154 Dest: proptools.StringPtr(filename),
155 },
156 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100157 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100158 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100159 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160 },
161 }
162 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800163 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100164}
165
Cole Faustdcda3702022-10-04 14:46:35 -0700166func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000167 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700168 name string
169 tag string
170 modules []string
171 }{
172 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000173 name: "all-modules-public-annotations",
174 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700175 modules: modules,
176 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000177 name: "all-modules-system-annotations",
178 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700179 modules: modules,
180 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000181 name: "all-modules-module-lib-annotations",
182 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700183 modules: modules,
184 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000185 name: "all-modules-system-server-annotations",
186 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700187 modules: system_server_modules,
188 },
189 } {
190 props := fgProps{}
191 props.Name = proptools.StringPtr(i.name)
192 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800193 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700194 }
Anton Hansson74b15642022-06-23 08:27:23 +0000195}
196
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000197func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
198 props := libraryProps{}
199 props.Name = proptools.StringPtr("all-modules-public-stubs")
200 props.Static_libs = transformArray(modules, "", ".stubs")
201 props.Sdk_version = proptools.StringPtr("module_current")
202 props.Visibility = []string{"//frameworks/base"}
203 ctx.CreateModule(java.LibraryFactory, &props)
204}
205
Jihoon Kang059b9492023-12-29 00:40:34 +0000206func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
207 props := libraryProps{}
208 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
209 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
210 props.Sdk_version = proptools.StringPtr("module_current")
211 props.Visibility = []string{"//frameworks/base"}
212 ctx.CreateModule(java.LibraryFactory, &props)
213}
214
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000215func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000216 // First create the all-updatable-modules-system-stubs
217 {
218 updatable_modules := removeAll(modules, non_updatable_modules)
219 props := libraryProps{}
220 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
221 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
222 props.Sdk_version = proptools.StringPtr("module_current")
223 props.Visibility = []string{"//frameworks/base"}
224 ctx.CreateModule(java.LibraryFactory, &props)
225 }
226 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
227 // into all-modules-system-stubs.
228 {
229 props := libraryProps{}
230 props.Name = proptools.StringPtr("all-modules-system-stubs")
231 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
232 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
233 props.Sdk_version = proptools.StringPtr("module_current")
234 props.Visibility = []string{"//frameworks/base"}
235 ctx.CreateModule(java.LibraryFactory, &props)
236 }
237}
238
Jihoon Kang059b9492023-12-29 00:40:34 +0000239func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
240 // First create the all-updatable-modules-system-stubs
241 {
242 updatable_modules := removeAll(modules, non_updatable_modules)
243 props := libraryProps{}
244 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
245 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
246 props.Sdk_version = proptools.StringPtr("module_current")
247 props.Visibility = []string{"//frameworks/base"}
248 ctx.CreateModule(java.LibraryFactory, &props)
249 }
250 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
251 // into all-modules-system-stubs.
252 {
253 props := libraryProps{}
254 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
255 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
256 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
257 props.Sdk_version = proptools.StringPtr("module_current")
258 props.Visibility = []string{"//frameworks/base"}
259 ctx.CreateModule(java.LibraryFactory, &props)
260 }
261}
262
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000263func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000264 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000265 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
266 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000267 props.Sdk_version = proptools.StringPtr("module_current")
268 props.Visibility = []string{"//frameworks/base"}
269 ctx.CreateModule(java.LibraryFactory, &props)
270}
271
Jihoon Kang059b9492023-12-29 00:40:34 +0000272func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
273 props := libraryProps{}
274 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
275 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
276 props.Sdk_version = proptools.StringPtr("module_current")
277 props.Visibility = []string{"//frameworks/base"}
278 ctx.CreateModule(java.LibraryFactory, &props)
279}
280
Anton Hansson95e89a82022-01-28 11:31:50 +0000281func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
282 // This module is for the "framework-all" module, which should not include the core libraries.
283 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000284 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
285 // against unstable APIs.
286 modules = removeAll(modules, non_updatable_modules)
287 // First create updatable-framework-module-impl, which contains all updatable modules.
288 // This module compiles against module_lib SDK.
289 {
290 props := libraryProps{}
291 props.Name = proptools.StringPtr("updatable-framework-module-impl")
292 props.Static_libs = transformArray(modules, "", ".impl")
293 props.Sdk_version = proptools.StringPtr("module_current")
294 props.Visibility = []string{"//frameworks/base"}
295 ctx.CreateModule(java.LibraryFactory, &props)
296 }
297
298 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
299 // and all non-updatable modules. This module compiles against hidden APIs.
300 {
301 props := libraryProps{}
302 props.Name = proptools.StringPtr("all-framework-module-impl")
303 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
304 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
305 props.Sdk_version = proptools.StringPtr("core_platform")
306 props.Visibility = []string{"//frameworks/base"}
307 ctx.CreateModule(java.LibraryFactory, &props)
308 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000309}
310
Jihoon Kang059b9492023-12-29 00:40:34 +0000311func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
312 // The user of this module compiles against the "core" SDK and against non-updatable modules,
313 // so remove to avoid dupes.
314 modules = removeAll(modules, core_libraries_modules)
315 modules = removeAll(modules, non_updatable_modules)
316 props := libraryProps{}
317 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
318 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
319 props.Sdk_version = proptools.StringPtr("module_current")
320 props.Visibility = []string{"//frameworks/base"}
321 ctx.CreateModule(java.LibraryFactory, &props)
322}
323
Anton Hansson95e89a82022-01-28 11:31:50 +0000324func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000325 // The user of this module compiles against the "core" SDK and against non-updatable modules,
326 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000327 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000328 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000329 props := libraryProps{}
330 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000331 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000332 props.Sdk_version = proptools.StringPtr("module_current")
333 props.Visibility = []string{"//frameworks/base"}
334 ctx.CreateModule(java.LibraryFactory, &props)
335}
336
Anton Hansson4468d7c2022-01-14 12:10:01 +0000337func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
338 props := fgProps{}
339 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
340 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
341 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800342 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000343}
344
Anton Hansson07a12952022-01-12 17:28:39 +0000345func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100346 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000347
Anton Hansson0860aaf2021-10-08 16:48:03 +0100348 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100349 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100350 for i, f := range []string{"current.txt", "removed.txt"} {
351 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800352 TxtFilename: f,
353 DistFilename: distFilename[i],
354 BaseTxt: ":non-updatable-" + f,
355 Modules: bootclasspath,
356 ModuleTag: "{.public" + tagSuffix[i],
357 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100358 })
359 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800360 TxtFilename: f,
361 DistFilename: distFilename[i],
362 BaseTxt: ":non-updatable-system-" + f,
363 Modules: bootclasspath,
364 ModuleTag: "{.system" + tagSuffix[i],
365 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100366 })
367 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800368 TxtFilename: f,
369 DistFilename: distFilename[i],
370 BaseTxt: ":non-updatable-module-lib-" + f,
371 Modules: bootclasspath,
372 ModuleTag: "{.module-lib" + tagSuffix[i],
373 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100374 })
375 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800376 TxtFilename: f,
377 DistFilename: distFilename[i],
378 BaseTxt: ":non-updatable-system-server-" + f,
379 Modules: system_server_classpath,
380 ModuleTag: "{.system-server" + tagSuffix[i],
381 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100382 })
383 }
384 for _, txt := range textFiles {
385 createMergedTxt(ctx, txt)
386 }
387}
388
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000389func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
390 defaultsSdkKinds := []android.SdkKind{
391 android.SdkPublic, android.SdkSystem, android.SdkModule,
392 }
393 for _, sdkKind := range defaultsSdkKinds {
394 props := defaultsProps{}
395 props.Name = proptools.StringPtr(
396 sdkKind.DefaultJavaLibraryName() + "_contributions")
397 if sdkKind == android.SdkModule {
398 props.Name = proptools.StringPtr(
399 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
400 }
401 props.Api_surface = proptools.StringPtr(sdkKind.String())
402 apiSuffix := ""
403 if sdkKind != android.SdkPublic {
404 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
405 }
406 props.Api_contributions = transformArray(
407 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
408 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000409 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000410 ctx.CreateModule(java.DefaultsFactory, &props)
411 }
412}
413
Jihoon Kang1453baa2023-05-27 05:32:30 +0000414func createFullApiLibraries(ctx android.LoadHookContext) {
415 javaLibraryNames := []string{
416 "android_stubs_current",
417 "android_system_stubs_current",
418 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000419 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000420 "android_module_lib_stubs_current",
421 "android_system_server_stubs_current",
422 }
423
424 for _, libraryName := range javaLibraryNames {
425 props := libraryProps{}
426 props.Name = proptools.StringPtr(libraryName)
427 staticLib := libraryName + ".from-source"
428 if ctx.Config().BuildFromTextStub() {
429 staticLib = libraryName + ".from-text"
430 }
431 props.Static_libs = []string{staticLib}
432 props.Defaults = []string{"android.jar_defaults"}
433 props.Visibility = []string{"//visibility:public"}
434
435 ctx.CreateModule(java.LibraryFactory, &props)
436 }
437}
438
Jihoon Kang059b9492023-12-29 00:40:34 +0000439func createFullExportableApiLibraries(ctx android.LoadHookContext) {
440 javaLibraryNames := []string{
441 "android_stubs_current_exportable",
442 "android_system_stubs_current_exportable",
443 "android_test_stubs_current_exportable",
444 "android_module_lib_stubs_current_exportable",
445 "android_system_server_stubs_current_exportable",
446 }
447
448 for _, libraryName := range javaLibraryNames {
449 props := libraryProps{}
450 props.Name = proptools.StringPtr(libraryName)
451 staticLib := libraryName + ".from-source"
452 props.Static_libs = []string{staticLib}
453 props.Defaults = []string{"android.jar_defaults"}
454 props.Visibility = []string{"//visibility:public"}
455
456 ctx.CreateModule(java.LibraryFactory, &props)
457 }
458}
459
Anton Hansson0860aaf2021-10-08 16:48:03 +0100460func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000461 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700462 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000463 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
464 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
465 sort.Strings(bootclasspath)
466 }
Cole Faustdcda3702022-10-04 14:46:35 -0700467 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100468
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000469 createMergedPublicStubs(ctx, bootclasspath)
470 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000471 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000472 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
473 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000474
Jihoon Kang059b9492023-12-29 00:40:34 +0000475 createMergedPublicExportableStubs(ctx, bootclasspath)
476 createMergedSystemExportableStubs(ctx, bootclasspath)
477 createMergedTestExportableStubsForNonUpdatableModules(ctx)
478 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
479
Cole Faustdcda3702022-10-04 14:46:35 -0700480 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000481
Anton Hansson4468d7c2022-01-14 12:10:01 +0000482 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000483
484 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000485
486 createFullApiLibraries(ctx)
Jihoon Kang059b9492023-12-29 00:40:34 +0000487
488 createFullExportableApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100489}
490
491func combinedApisModuleFactory() android.Module {
492 module := &CombinedApis{}
493 module.AddProperties(&module.properties)
494 android.InitAndroidModule(module)
495 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
496 return module
497}
Anton Hanssonfd316452022-01-14 11:15:52 +0000498
499// Various utility methods below.
500
501// Creates an array of ":<m><tag>" for each m in <modules>.
502func createSrcs(modules []string, tag string) []string {
503 return transformArray(modules, ":", tag)
504}
505
506// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
507func transformArray(modules []string, prefix, suffix string) []string {
508 a := make([]string, 0, len(modules))
509 for _, module := range modules {
510 a = append(a, prefix+module+suffix)
511 }
512 return a
513}
514
515func removeAll(s []string, vs []string) []string {
516 for _, v := range vs {
517 s = remove(s, v)
518 }
519 return s
520}
521
522func remove(s []string, v string) []string {
523 s2 := make([]string, 0, len(s))
524 for _, sv := range s {
525 if sv != v {
526 s2 = append(s2, sv)
527 }
528 }
529 return s2
530}