blob: 71b1e10d2f4780dbd003ee59c8744d487826ea40 [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"
Roshan Pius0fa80892023-11-14 14:30:26 -080035const nfc = "framework-nfc"
Anton Hansson09a9c4e2022-04-08 10:59:46 +010036
Anton Hansson95e89a82022-01-28 11:31:50 +000037var core_libraries_modules = []string{art, conscrypt, i18n}
Zi Wang0d6a5302023-02-16 14:54:01 -080038
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000039// List of modules that are not yet updatable, and hence they can still compile
40// against hidden APIs. These modules are filtered out when building the
41// updatable-framework-module-impl (because updatable-framework-module-impl is
42// built against module_current SDK). Instead they are directly statically
43// linked into the all-framework-module-lib, which is building against hidden
44// APIs.
Nikita Ioffe5593fbb2022-12-01 14:52:34 +000045// In addition, the modules in this list are allowed to contribute to test APIs
46// stubs.
Roshan Pius0fa80892023-11-14 14:30:26 -080047var non_updatable_modules = []string{virtualization, location, nfc}
Anton Hansson05e944d2022-01-13 12:26:30 +000048
Anton Hansson0860aaf2021-10-08 16:48:03 +010049// The intention behind this soong plugin is to generate a number of "merged"
50// API-related modules that would otherwise require a large amount of very
51// similar Android.bp boilerplate to define. For example, the merged current.txt
52// API definitions (created by merging the non-updatable current.txt with all
53// the module current.txts). This simplifies the addition of new android
54// modules, by reducing the number of genrules etc a new module must be added to.
55
56// The properties of the combined_apis module type.
57type CombinedApisProperties struct {
Anton Hansson16ff3572022-01-11 18:36:35 +000058 // Module libraries in the bootclasspath
59 Bootclasspath []string
Anton Hansson07a12952022-01-12 17:28:39 +000060 // Module libraries on the bootclasspath if include_nonpublic_framework_api is true.
61 Conditional_bootclasspath []string
Anton Hansson16ff3572022-01-11 18:36:35 +000062 // Module libraries in system server
63 System_server_classpath []string
Anton Hansson0860aaf2021-10-08 16:48:03 +010064}
65
66type CombinedApis struct {
67 android.ModuleBase
Zi Wang0d6a5302023-02-16 14:54:01 -080068 android.BazelModuleBase
Anton Hansson0860aaf2021-10-08 16:48:03 +010069
70 properties CombinedApisProperties
71}
72
73func init() {
74 registerBuildComponents(android.InitRegistrationContext)
75}
76
77func registerBuildComponents(ctx android.RegistrationContext) {
78 ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory)
79}
80
81var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
82
83func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
84}
85
86type genruleProps struct {
87 Name *string
88 Cmd *string
89 Dists []android.Dist
90 Out []string
91 Srcs []string
92 Tools []string
93 Visibility []string
94}
95
Anton Hanssoncb00f942022-01-13 09:45:12 +000096type libraryProps struct {
97 Name *string
98 Sdk_version *string
99 Static_libs []string
100 Visibility []string
Jihoon Kang1453baa2023-05-27 05:32:30 +0000101 Defaults []string
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
Zi Wang0d6a5302023-02-16 14:54:01 -0800118type Bazel_module struct {
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000119 Label *string
Zi Wang0d6a5302023-02-16 14:54:01 -0800120 Bp2build_available *bool
121}
122type bazelProperties struct {
123 *Bazel_module
124}
125
126var bp2buildNotAvailable = bazelProperties{
127 &Bazel_module{
128 Bp2build_available: proptools.BoolPtr(false),
129 },
130}
131
Anton Hansson0860aaf2021-10-08 16:48:03 +0100132// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
133type MergedTxtDefinition struct {
134 // "current.txt" or "removed.txt"
135 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100136 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
137 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100138 // The module for the non-updatable / non-module part of the api.
139 BaseTxt string
140 // The list of modules that are relevant for this merged txt.
141 Modules []string
142 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
143 ModuleTag string
144 // public, system, module-lib or system-server
145 Scope string
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000146 // True if there is a bp2build definition for this module
147 Bp2buildDefined bool
Anton Hansson0860aaf2021-10-08 16:48:03 +0100148}
149
150func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
151 metalavaCmd := "$(location metalava)"
152 // Silence reflection warnings. See b/168689341
153 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100154 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100155
156 filename := txt.TxtFilename
157 if txt.Scope != "public" {
158 filename = txt.Scope + "-" + filename
159 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000160 moduleName := ctx.ModuleName() + "-" + filename
161
Anton Hansson0860aaf2021-10-08 16:48:03 +0100162 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000163 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100164 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000165 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100166 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000167 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100168 props.Dists = []android.Dist{
169 {
170 Targets: []string{"droidcore"},
171 Dir: proptools.StringPtr("api"),
172 Dest: proptools.StringPtr(filename),
173 },
174 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100175 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100176 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100177 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100178 },
179 }
180 props.Visibility = []string{"//visibility:public"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000181 bazelProps := bazelProperties{
182 &Bazel_module{
183 Bp2build_available: proptools.BoolPtr(false),
184 },
185 }
186 if txt.Bp2buildDefined {
187 moduleDir := ctx.ModuleDir()
188 if moduleDir == android.Bp2BuildTopLevel {
189 moduleDir = ""
190 }
191 label := fmt.Sprintf("//%s:%s", moduleDir, moduleName)
192 bazelProps.Label = &label
193 }
194 ctx.CreateModule(genrule.GenRuleFactory, &props, &bazelProps)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100195}
196
Cole Faustdcda3702022-10-04 14:46:35 -0700197func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000198 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700199 name string
200 tag string
201 modules []string
202 }{
203 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000204 name: "all-modules-public-annotations",
205 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700206 modules: modules,
207 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000208 name: "all-modules-system-annotations",
209 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700210 modules: modules,
211 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000212 name: "all-modules-module-lib-annotations",
213 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700214 modules: modules,
215 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000216 name: "all-modules-system-server-annotations",
217 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700218 modules: system_server_modules,
219 },
220 } {
221 props := fgProps{}
222 props.Name = proptools.StringPtr(i.name)
223 props.Srcs = createSrcs(i.modules, i.tag)
Zi Wang0d6a5302023-02-16 14:54:01 -0800224 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Cole Faustdcda3702022-10-04 14:46:35 -0700225 }
Anton Hansson74b15642022-06-23 08:27:23 +0000226}
227
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000228func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
229 props := libraryProps{}
230 props.Name = proptools.StringPtr("all-modules-public-stubs")
231 props.Static_libs = transformArray(modules, "", ".stubs")
232 props.Sdk_version = proptools.StringPtr("module_current")
233 props.Visibility = []string{"//frameworks/base"}
234 ctx.CreateModule(java.LibraryFactory, &props)
235}
236
237func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000238 // First create the all-updatable-modules-system-stubs
239 {
240 updatable_modules := removeAll(modules, non_updatable_modules)
241 props := libraryProps{}
242 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
243 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
244 props.Sdk_version = proptools.StringPtr("module_current")
245 props.Visibility = []string{"//frameworks/base"}
246 ctx.CreateModule(java.LibraryFactory, &props)
247 }
248 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
249 // into all-modules-system-stubs.
250 {
251 props := libraryProps{}
252 props.Name = proptools.StringPtr("all-modules-system-stubs")
253 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
254 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
255 props.Sdk_version = proptools.StringPtr("module_current")
256 props.Visibility = []string{"//frameworks/base"}
257 ctx.CreateModule(java.LibraryFactory, &props)
258 }
259}
260
261func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000262 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000263 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
264 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000265 props.Sdk_version = proptools.StringPtr("module_current")
266 props.Visibility = []string{"//frameworks/base"}
267 ctx.CreateModule(java.LibraryFactory, &props)
268}
269
Anton Hansson95e89a82022-01-28 11:31:50 +0000270func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
271 // This module is for the "framework-all" module, which should not include the core libraries.
272 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000273 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
274 // against unstable APIs.
275 modules = removeAll(modules, non_updatable_modules)
276 // First create updatable-framework-module-impl, which contains all updatable modules.
277 // This module compiles against module_lib SDK.
278 {
279 props := libraryProps{}
280 props.Name = proptools.StringPtr("updatable-framework-module-impl")
281 props.Static_libs = transformArray(modules, "", ".impl")
282 props.Sdk_version = proptools.StringPtr("module_current")
283 props.Visibility = []string{"//frameworks/base"}
284 ctx.CreateModule(java.LibraryFactory, &props)
285 }
286
287 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
288 // and all non-updatable modules. This module compiles against hidden APIs.
289 {
290 props := libraryProps{}
291 props.Name = proptools.StringPtr("all-framework-module-impl")
292 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
293 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
294 props.Sdk_version = proptools.StringPtr("core_platform")
295 props.Visibility = []string{"//frameworks/base"}
296 ctx.CreateModule(java.LibraryFactory, &props)
297 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000298}
299
300func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000301 // The user of this module compiles against the "core" SDK and against non-updatable modules,
302 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000303 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000304 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000305 props := libraryProps{}
306 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000307 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000308 props.Sdk_version = proptools.StringPtr("module_current")
309 props.Visibility = []string{"//frameworks/base"}
310 ctx.CreateModule(java.LibraryFactory, &props)
311}
312
Anton Hansson4468d7c2022-01-14 12:10:01 +0000313func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
314 props := fgProps{}
315 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
316 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
317 props.Visibility = []string{"//frameworks/base"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800318 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000319}
320
Anton Hansson07a12952022-01-12 17:28:39 +0000321func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100322 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000323
Anton Hansson0860aaf2021-10-08 16:48:03 +0100324 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100325 distFilename := []string{"android.txt", "android-removed.txt"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000326 bp2BuildDefined := []bool{true, false}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100327 for i, f := range []string{"current.txt", "removed.txt"} {
328 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000329 TxtFilename: f,
330 DistFilename: distFilename[i],
331 BaseTxt: ":non-updatable-" + f,
332 Modules: bootclasspath,
333 ModuleTag: "{.public" + tagSuffix[i],
334 Scope: "public",
335 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100336 })
337 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000338 TxtFilename: f,
339 DistFilename: distFilename[i],
340 BaseTxt: ":non-updatable-system-" + f,
341 Modules: bootclasspath,
342 ModuleTag: "{.system" + tagSuffix[i],
343 Scope: "system",
344 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100345 })
346 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000347 TxtFilename: f,
348 DistFilename: distFilename[i],
349 BaseTxt: ":non-updatable-module-lib-" + f,
350 Modules: bootclasspath,
351 ModuleTag: "{.module-lib" + tagSuffix[i],
352 Scope: "module-lib",
353 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100354 })
355 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000356 TxtFilename: f,
357 DistFilename: distFilename[i],
358 BaseTxt: ":non-updatable-system-server-" + f,
359 Modules: system_server_classpath,
360 ModuleTag: "{.system-server" + tagSuffix[i],
361 Scope: "system-server",
362 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100363 })
364 }
365 for _, txt := range textFiles {
366 createMergedTxt(ctx, txt)
367 }
368}
369
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000370func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
371 defaultsSdkKinds := []android.SdkKind{
372 android.SdkPublic, android.SdkSystem, android.SdkModule,
373 }
374 for _, sdkKind := range defaultsSdkKinds {
375 props := defaultsProps{}
376 props.Name = proptools.StringPtr(
377 sdkKind.DefaultJavaLibraryName() + "_contributions")
378 if sdkKind == android.SdkModule {
379 props.Name = proptools.StringPtr(
380 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
381 }
382 props.Api_surface = proptools.StringPtr(sdkKind.String())
383 apiSuffix := ""
384 if sdkKind != android.SdkPublic {
385 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
386 }
387 props.Api_contributions = transformArray(
388 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
389 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000390 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000391 ctx.CreateModule(java.DefaultsFactory, &props)
392 }
393}
394
Jihoon Kang1453baa2023-05-27 05:32:30 +0000395func createFullApiLibraries(ctx android.LoadHookContext) {
396 javaLibraryNames := []string{
397 "android_stubs_current",
398 "android_system_stubs_current",
399 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000400 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000401 "android_module_lib_stubs_current",
402 "android_system_server_stubs_current",
403 }
404
405 for _, libraryName := range javaLibraryNames {
406 props := libraryProps{}
407 props.Name = proptools.StringPtr(libraryName)
408 staticLib := libraryName + ".from-source"
409 if ctx.Config().BuildFromTextStub() {
410 staticLib = libraryName + ".from-text"
411 }
412 props.Static_libs = []string{staticLib}
413 props.Defaults = []string{"android.jar_defaults"}
414 props.Visibility = []string{"//visibility:public"}
415
416 ctx.CreateModule(java.LibraryFactory, &props)
417 }
418}
419
Anton Hansson0860aaf2021-10-08 16:48:03 +0100420func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000421 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700422 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000423 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
424 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
425 sort.Strings(bootclasspath)
426 }
Cole Faustdcda3702022-10-04 14:46:35 -0700427 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100428
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000429 createMergedPublicStubs(ctx, bootclasspath)
430 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000431 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000432 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
433 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000434
Cole Faustdcda3702022-10-04 14:46:35 -0700435 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000436
Anton Hansson4468d7c2022-01-14 12:10:01 +0000437 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000438
439 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000440
441 createFullApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100442}
443
444func combinedApisModuleFactory() android.Module {
445 module := &CombinedApis{}
446 module.AddProperties(&module.properties)
447 android.InitAndroidModule(module)
448 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
Zi Wang0d6a5302023-02-16 14:54:01 -0800449 android.InitBazelModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100450 return module
451}
Anton Hanssonfd316452022-01-14 11:15:52 +0000452
Zi Wang0d6a5302023-02-16 14:54:01 -0800453type bazelCombinedApisAttributes struct {
454 Scope bazel.StringAttribute
455 Base bazel.LabelAttribute
456 Deps bazel.LabelListAttribute
457}
458
459// combined_apis bp2build converter
Chris Parsons52f9ad02023-09-13 21:30:55 +0000460func (a *CombinedApis) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Zi Wang0d6a5302023-02-16 14:54:01 -0800461 basePrefix := "non-updatable"
Zi Wang0d6a5302023-02-16 14:54:01 -0800462 scopeToSuffix := map[string]string{
463 "public": "-current.txt",
464 "system": "-system-current.txt",
465 "module-lib": "-module-lib-current.txt",
466 "system-server": "-system-server-current.txt",
467 }
468
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000469 for scopeName, suffix := range scopeToSuffix {
Zi Wang0d6a5302023-02-16 14:54:01 -0800470 name := a.Name() + suffix
471
472 var scope bazel.StringAttribute
473 scope.SetValue(scopeName)
474
475 var base bazel.LabelAttribute
476 base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
477
478 var deps bazel.LabelListAttribute
479 classpath := a.properties.Bootclasspath
480 if scopeName == "system-server" {
481 classpath = a.properties.System_server_classpath
482 }
483 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
484
485 attrs := bazelCombinedApisAttributes{
486 Scope: scope,
487 Base: base,
488 Deps: deps,
489 }
490 props := bazel.BazelTargetModuleProperties{
491 Rule_class: "merged_txts",
492 Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
493 }
494 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
495 }
496}
497
Anton Hanssonfd316452022-01-14 11:15:52 +0000498// Various utility methods below.
499
500// Creates an array of ":<m><tag>" for each m in <modules>.
501func createSrcs(modules []string, tag string) []string {
502 return transformArray(modules, ":", tag)
503}
504
505// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
506func transformArray(modules []string, prefix, suffix string) []string {
507 a := make([]string, 0, len(modules))
508 for _, module := range modules {
509 a = append(a, prefix+module+suffix)
510 }
511 return a
512}
513
514func removeAll(s []string, vs []string) []string {
515 for _, v := range vs {
516 s = remove(s, v)
517 }
518 return s
519}
520
521func remove(s []string, v string) []string {
522 s2 := make([]string, 0, len(s))
523 for _, sv := range s {
524 if sv != v {
525 s2 = append(s2, sv)
526 }
527 }
528 return s2
529}