blob: 8df6dab715efc1aea6eaccca15d89e6611633894 [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"
Zi Wang0d6a5302023-02-16 14:54:01 -080025 "android/soong/bazel"
Anton Hansson0860aaf2021-10-08 16:48:03 +010026 "android/soong/genrule"
Anton Hanssoncb00f942022-01-13 09:45:12 +000027 "android/soong/java"
Anton Hansson0860aaf2021-10-08 16:48:03 +010028)
29
Anton Hansson05e944d2022-01-13 12:26:30 +000030const art = "art.module.public.api"
31const conscrypt = "conscrypt.module.public.api"
32const i18n = "i18n.module.public.api"
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000033const virtualization = "framework-virtualization"
Mark White3cc5e002023-08-07 11:18:09 +000034const location = "framework-location"
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.
Mark White3cc5e002023-08-07 11:18:09 +000046var non_updatable_modules = []string{virtualization, location}
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
Zi Wang0d6a5302023-02-16 14:54:01 -080067 android.BazelModuleBase
Anton Hansson0860aaf2021-10-08 16:48:03 +010068
69 properties CombinedApisProperties
70}
71
72func init() {
73 registerBuildComponents(android.InitRegistrationContext)
74}
75
76func registerBuildComponents(ctx android.RegistrationContext) {
77 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
78}
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
Zi Wang0d6a5302023-02-16 14:54:01 -0800117type Bazel_module struct {
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000118 Label *string
Zi Wang0d6a5302023-02-16 14:54:01 -0800119 Bp2build_available *bool
120}
121type bazelProperties struct {
122 *Bazel_module
123}
124
125var bp2buildNotAvailable = bazelProperties{
126 &Bazel_module{
127 Bp2build_available: proptools.BoolPtr(false),
128 },
129}
130
Anton Hansson0860aaf2021-10-08 16:48:03 +0100131// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
132type MergedTxtDefinition struct {
133 // "current.txt" or "removed.txt"
134 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100135 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
136 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100137 // The module for the non-updatable / non-module part of the api.
138 BaseTxt string
139 // The list of modules that are relevant for this merged txt.
140 Modules []string
141 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
142 ModuleTag string
143 // public, system, module-lib or system-server
144 Scope string
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000145 // True if there is a bp2build definition for this module
146 Bp2buildDefined bool
Anton Hansson0860aaf2021-10-08 16:48:03 +0100147}
148
149func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
150 metalavaCmd := "$(location metalava)"
151 // Silence reflection warnings. See b/168689341
152 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100153 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100154
155 filename := txt.TxtFilename
156 if txt.Scope != "public" {
157 filename = txt.Scope + "-" + filename
158 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000159 moduleName := ctx.ModuleName() + "-" + filename
160
Anton Hansson0860aaf2021-10-08 16:48:03 +0100161 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000162 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100163 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000164 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100165 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000166 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100167 props.Dists = []android.Dist{
168 {
169 Targets: []string{"droidcore"},
170 Dir: proptools.StringPtr("api"),
171 Dest: proptools.StringPtr(filename),
172 },
173 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100174 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100175 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100176 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100177 },
178 }
179 props.Visibility = []string{"//visibility:public"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000180 bazelProps := bazelProperties{
181 &Bazel_module{
182 Bp2build_available: proptools.BoolPtr(false),
183 },
184 }
185 if txt.Bp2buildDefined {
186 moduleDir := ctx.ModuleDir()
187 if moduleDir == android.Bp2BuildTopLevel {
188 moduleDir = ""
189 }
190 label := fmt.Sprintf("//%s:%s", moduleDir, moduleName)
191 bazelProps.Label = &label
192 }
193 ctx.CreateModule(genrule.GenRuleFactory, &props, &bazelProps)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100194}
195
Cole Faustdcda3702022-10-04 14:46:35 -0700196func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000197 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700198 name string
199 tag string
200 modules []string
201 }{
202 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000203 name: "all-modules-public-annotations",
204 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700205 modules: modules,
206 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000207 name: "all-modules-system-annotations",
208 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700209 modules: modules,
210 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000211 name: "all-modules-module-lib-annotations",
212 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700213 modules: modules,
214 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000215 name: "all-modules-system-server-annotations",
216 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700217 modules: system_server_modules,
218 },
219 } {
220 props := fgProps{}
221 props.Name = proptools.StringPtr(i.name)
222 props.Srcs = createSrcs(i.modules, i.tag)
Zi Wang0d6a5302023-02-16 14:54:01 -0800223 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Cole Faustdcda3702022-10-04 14:46:35 -0700224 }
Anton Hansson74b15642022-06-23 08:27:23 +0000225}
226
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000227func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
228 props := libraryProps{}
229 props.Name = proptools.StringPtr("all-modules-public-stubs")
230 props.Static_libs = transformArray(modules, "", ".stubs")
231 props.Sdk_version = proptools.StringPtr("module_current")
232 props.Visibility = []string{"//frameworks/base"}
233 ctx.CreateModule(java.LibraryFactory, &props)
234}
235
236func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000237 // First create the all-updatable-modules-system-stubs
238 {
239 updatable_modules := removeAll(modules, non_updatable_modules)
240 props := libraryProps{}
241 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
242 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
243 props.Sdk_version = proptools.StringPtr("module_current")
244 props.Visibility = []string{"//frameworks/base"}
245 ctx.CreateModule(java.LibraryFactory, &props)
246 }
247 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
248 // into all-modules-system-stubs.
249 {
250 props := libraryProps{}
251 props.Name = proptools.StringPtr("all-modules-system-stubs")
252 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
253 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
254 props.Sdk_version = proptools.StringPtr("module_current")
255 props.Visibility = []string{"//frameworks/base"}
256 ctx.CreateModule(java.LibraryFactory, &props)
257 }
258}
259
260func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000261 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000262 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
263 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000264 props.Sdk_version = proptools.StringPtr("module_current")
265 props.Visibility = []string{"//frameworks/base"}
266 ctx.CreateModule(java.LibraryFactory, &props)
267}
268
Anton Hansson95e89a82022-01-28 11:31:50 +0000269func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
270 // This module is for the "framework-all" module, which should not include the core libraries.
271 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000272 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
273 // against unstable APIs.
274 modules = removeAll(modules, non_updatable_modules)
275 // First create updatable-framework-module-impl, which contains all updatable modules.
276 // This module compiles against module_lib SDK.
277 {
278 props := libraryProps{}
279 props.Name = proptools.StringPtr("updatable-framework-module-impl")
280 props.Static_libs = transformArray(modules, "", ".impl")
281 props.Sdk_version = proptools.StringPtr("module_current")
282 props.Visibility = []string{"//frameworks/base"}
283 ctx.CreateModule(java.LibraryFactory, &props)
284 }
285
286 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
287 // and all non-updatable modules. This module compiles against hidden APIs.
288 {
289 props := libraryProps{}
290 props.Name = proptools.StringPtr("all-framework-module-impl")
291 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
292 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
293 props.Sdk_version = proptools.StringPtr("core_platform")
294 props.Visibility = []string{"//frameworks/base"}
295 ctx.CreateModule(java.LibraryFactory, &props)
296 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000297}
298
299func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000300 // The user of this module compiles against the "core" SDK and against non-updatable modules,
301 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000302 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000303 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000304 props := libraryProps{}
305 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000306 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000307 props.Sdk_version = proptools.StringPtr("module_current")
308 props.Visibility = []string{"//frameworks/base"}
309 ctx.CreateModule(java.LibraryFactory, &props)
310}
311
Anton Hansson4468d7c2022-01-14 12:10:01 +0000312func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
313 props := fgProps{}
314 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
315 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
316 props.Visibility = []string{"//frameworks/base"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800317 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000318}
319
Anton Hansson07a12952022-01-12 17:28:39 +0000320func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100321 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000322
Anton Hansson0860aaf2021-10-08 16:48:03 +0100323 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100324 distFilename := []string{"android.txt", "android-removed.txt"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000325 bp2BuildDefined := []bool{true, false}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100326 for i, f := range []string{"current.txt", "removed.txt"} {
327 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000328 TxtFilename: f,
329 DistFilename: distFilename[i],
330 BaseTxt: ":non-updatable-" + f,
331 Modules: bootclasspath,
332 ModuleTag: "{.public" + tagSuffix[i],
333 Scope: "public",
334 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100335 })
336 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000337 TxtFilename: f,
338 DistFilename: distFilename[i],
339 BaseTxt: ":non-updatable-system-" + f,
340 Modules: bootclasspath,
341 ModuleTag: "{.system" + tagSuffix[i],
342 Scope: "system",
343 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100344 })
345 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000346 TxtFilename: f,
347 DistFilename: distFilename[i],
348 BaseTxt: ":non-updatable-module-lib-" + f,
349 Modules: bootclasspath,
350 ModuleTag: "{.module-lib" + tagSuffix[i],
351 Scope: "module-lib",
352 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100353 })
354 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000355 TxtFilename: f,
356 DistFilename: distFilename[i],
357 BaseTxt: ":non-updatable-system-server-" + f,
358 Modules: system_server_classpath,
359 ModuleTag: "{.system-server" + tagSuffix[i],
360 Scope: "system-server",
361 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100362 })
363 }
364 for _, txt := range textFiles {
365 createMergedTxt(ctx, txt)
366 }
367}
368
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000369func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
370 defaultsSdkKinds := []android.SdkKind{
371 android.SdkPublic, android.SdkSystem, android.SdkModule,
372 }
373 for _, sdkKind := range defaultsSdkKinds {
374 props := defaultsProps{}
375 props.Name = proptools.StringPtr(
376 sdkKind.DefaultJavaLibraryName() + "_contributions")
377 if sdkKind == android.SdkModule {
378 props.Name = proptools.StringPtr(
379 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
380 }
381 props.Api_surface = proptools.StringPtr(sdkKind.String())
382 apiSuffix := ""
383 if sdkKind != android.SdkPublic {
384 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
385 }
386 props.Api_contributions = transformArray(
387 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
388 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000389 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000390 ctx.CreateModule(java.DefaultsFactory, &props)
391 }
392}
393
Jihoon Kang1453baa2023-05-27 05:32:30 +0000394func createFullApiLibraries(ctx android.LoadHookContext) {
395 javaLibraryNames := []string{
396 "android_stubs_current",
397 "android_system_stubs_current",
398 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000399 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000400 "android_module_lib_stubs_current",
401 "android_system_server_stubs_current",
402 }
403
404 for _, libraryName := range javaLibraryNames {
405 props := libraryProps{}
406 props.Name = proptools.StringPtr(libraryName)
407 staticLib := libraryName + ".from-source"
408 if ctx.Config().BuildFromTextStub() {
409 staticLib = libraryName + ".from-text"
410 }
411 props.Static_libs = []string{staticLib}
412 props.Defaults = []string{"android.jar_defaults"}
413 props.Visibility = []string{"//visibility:public"}
414
415 ctx.CreateModule(java.LibraryFactory, &props)
416 }
417}
418
Anton Hansson0860aaf2021-10-08 16:48:03 +0100419func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000420 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700421 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000422 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
423 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
424 sort.Strings(bootclasspath)
425 }
Cole Faustdcda3702022-10-04 14:46:35 -0700426 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100427
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000428 createMergedPublicStubs(ctx, bootclasspath)
429 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000430 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000431 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
432 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000433
Cole Faustdcda3702022-10-04 14:46:35 -0700434 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000435
Anton Hansson4468d7c2022-01-14 12:10:01 +0000436 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000437
438 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000439
440 createFullApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100441}
442
443func combinedApisModuleFactory() android.Module {
444 module := &CombinedApis{}
445 module.AddProperties(&module.properties)
446 android.InitAndroidModule(module)
447 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
Zi Wang0d6a5302023-02-16 14:54:01 -0800448 android.InitBazelModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100449 return module
450}
Anton Hanssonfd316452022-01-14 11:15:52 +0000451
Zi Wang0d6a5302023-02-16 14:54:01 -0800452type bazelCombinedApisAttributes struct {
453 Scope bazel.StringAttribute
454 Base bazel.LabelAttribute
455 Deps bazel.LabelListAttribute
456}
457
458// combined_apis bp2build converter
Chris Parsons52f9ad02023-09-13 21:30:55 +0000459func (a *CombinedApis) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Zi Wang0d6a5302023-02-16 14:54:01 -0800460 basePrefix := "non-updatable"
Zi Wang0d6a5302023-02-16 14:54:01 -0800461 scopeToSuffix := map[string]string{
462 "public": "-current.txt",
463 "system": "-system-current.txt",
464 "module-lib": "-module-lib-current.txt",
465 "system-server": "-system-server-current.txt",
466 }
467
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000468 for scopeName, suffix := range scopeToSuffix {
Zi Wang0d6a5302023-02-16 14:54:01 -0800469 name := a.Name() + suffix
470
471 var scope bazel.StringAttribute
472 scope.SetValue(scopeName)
473
474 var base bazel.LabelAttribute
475 base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
476
477 var deps bazel.LabelListAttribute
478 classpath := a.properties.Bootclasspath
479 if scopeName == "system-server" {
480 classpath = a.properties.System_server_classpath
481 }
482 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
483
484 attrs := bazelCombinedApisAttributes{
485 Scope: scope,
486 Base: base,
487 Deps: deps,
488 }
489 props := bazel.BazelTargetModuleProperties{
490 Rule_class: "merged_txts",
491 Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
492 }
493 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
494 }
495}
496
Anton Hanssonfd316452022-01-14 11:15:52 +0000497// Various utility methods below.
498
499// Creates an array of ":<m><tag>" for each m in <modules>.
500func createSrcs(modules []string, tag string) []string {
501 return transformArray(modules, ":", tag)
502}
503
504// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
505func transformArray(modules []string, prefix, suffix string) []string {
506 a := make([]string, 0, len(modules))
507 for _, module := range modules {
508 a = append(a, prefix+module+suffix)
509 }
510 return a
511}
512
513func removeAll(s []string, vs []string) []string {
514 for _, v := range vs {
515 s = remove(s, v)
516 }
517 return s
518}
519
520func remove(s []string, v string) []string {
521 s2 := make([]string, 0, len(s))
522 for _, sv := range s {
523 if sv != v {
524 s2 = append(s2, sv)
525 }
526 }
527 return s2
528}