blob: 692d38fe21a2d32a11ad2066ae8b3d383a9a4ed4 [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"
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.
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000045var non_updatable_modules = []string{virtualization}
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
Zi Wang0d6a5302023-02-16 14:54:01 -080066 android.BazelModuleBase
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)
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
Zi Wang0d6a5302023-02-16 14:54:01 -0800116type Bazel_module struct {
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000117 Label *string
Zi Wang0d6a5302023-02-16 14:54:01 -0800118 Bp2build_available *bool
119}
120type bazelProperties struct {
121 *Bazel_module
122}
123
124var bp2buildNotAvailable = bazelProperties{
125 &Bazel_module{
126 Bp2build_available: proptools.BoolPtr(false),
127 },
128}
129
Anton Hansson0860aaf2021-10-08 16:48:03 +0100130// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
131type MergedTxtDefinition struct {
132 // "current.txt" or "removed.txt"
133 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100134 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
135 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100136 // The module for the non-updatable / non-module part of the api.
137 BaseTxt string
138 // The list of modules that are relevant for this merged txt.
139 Modules []string
140 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
141 ModuleTag string
142 // public, system, module-lib or system-server
143 Scope string
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000144 // True if there is a bp2build definition for this module
145 Bp2buildDefined bool
Anton Hansson0860aaf2021-10-08 16:48:03 +0100146}
147
148func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
149 metalavaCmd := "$(location metalava)"
150 // Silence reflection warnings. See b/168689341
151 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100152 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100153
154 filename := txt.TxtFilename
155 if txt.Scope != "public" {
156 filename = txt.Scope + "-" + filename
157 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000158 moduleName := ctx.ModuleName() + "-" + filename
159
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000161 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100162 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000163 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100164 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000165 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100166 props.Dists = []android.Dist{
167 {
168 Targets: []string{"droidcore"},
169 Dir: proptools.StringPtr("api"),
170 Dest: proptools.StringPtr(filename),
171 },
172 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100173 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100174 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100175 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100176 },
177 }
178 props.Visibility = []string{"//visibility:public"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000179 bazelProps := bazelProperties{
180 &Bazel_module{
181 Bp2build_available: proptools.BoolPtr(false),
182 },
183 }
184 if txt.Bp2buildDefined {
185 moduleDir := ctx.ModuleDir()
186 if moduleDir == android.Bp2BuildTopLevel {
187 moduleDir = ""
188 }
189 label := fmt.Sprintf("//%s:%s", moduleDir, moduleName)
190 bazelProps.Label = &label
191 }
192 ctx.CreateModule(genrule.GenRuleFactory, &props, &bazelProps)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100193}
194
Cole Faustdcda3702022-10-04 14:46:35 -0700195func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000196 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700197 name string
198 tag string
199 modules []string
200 }{
201 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000202 name: "all-modules-public-annotations",
203 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700204 modules: modules,
205 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000206 name: "all-modules-system-annotations",
207 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700208 modules: modules,
209 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000210 name: "all-modules-module-lib-annotations",
211 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700212 modules: modules,
213 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000214 name: "all-modules-system-server-annotations",
215 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700216 modules: system_server_modules,
217 },
218 } {
219 props := fgProps{}
220 props.Name = proptools.StringPtr(i.name)
221 props.Srcs = createSrcs(i.modules, i.tag)
Zi Wang0d6a5302023-02-16 14:54:01 -0800222 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Cole Faustdcda3702022-10-04 14:46:35 -0700223 }
Anton Hansson74b15642022-06-23 08:27:23 +0000224}
225
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000226func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
227 props := libraryProps{}
228 props.Name = proptools.StringPtr("all-modules-public-stubs")
229 props.Static_libs = transformArray(modules, "", ".stubs")
230 props.Sdk_version = proptools.StringPtr("module_current")
231 props.Visibility = []string{"//frameworks/base"}
232 ctx.CreateModule(java.LibraryFactory, &props)
233}
234
235func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000236 // First create the all-updatable-modules-system-stubs
237 {
238 updatable_modules := removeAll(modules, non_updatable_modules)
239 props := libraryProps{}
240 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
241 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
242 props.Sdk_version = proptools.StringPtr("module_current")
243 props.Visibility = []string{"//frameworks/base"}
244 ctx.CreateModule(java.LibraryFactory, &props)
245 }
246 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
247 // into all-modules-system-stubs.
248 {
249 props := libraryProps{}
250 props.Name = proptools.StringPtr("all-modules-system-stubs")
251 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
252 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
253 props.Sdk_version = proptools.StringPtr("module_current")
254 props.Visibility = []string{"//frameworks/base"}
255 ctx.CreateModule(java.LibraryFactory, &props)
256 }
257}
258
259func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000260 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000261 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
262 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000263 props.Sdk_version = proptools.StringPtr("module_current")
264 props.Visibility = []string{"//frameworks/base"}
265 ctx.CreateModule(java.LibraryFactory, &props)
266}
267
Anton Hansson95e89a82022-01-28 11:31:50 +0000268func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
269 // This module is for the "framework-all" module, which should not include the core libraries.
270 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000271 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
272 // against unstable APIs.
273 modules = removeAll(modules, non_updatable_modules)
274 // First create updatable-framework-module-impl, which contains all updatable modules.
275 // This module compiles against module_lib SDK.
276 {
277 props := libraryProps{}
278 props.Name = proptools.StringPtr("updatable-framework-module-impl")
279 props.Static_libs = transformArray(modules, "", ".impl")
280 props.Sdk_version = proptools.StringPtr("module_current")
281 props.Visibility = []string{"//frameworks/base"}
282 ctx.CreateModule(java.LibraryFactory, &props)
283 }
284
285 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
286 // and all non-updatable modules. This module compiles against hidden APIs.
287 {
288 props := libraryProps{}
289 props.Name = proptools.StringPtr("all-framework-module-impl")
290 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
291 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
292 props.Sdk_version = proptools.StringPtr("core_platform")
293 props.Visibility = []string{"//frameworks/base"}
294 ctx.CreateModule(java.LibraryFactory, &props)
295 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000296}
297
298func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Anton Hanssoncb00f942022-01-13 09:45:12 +0000299 // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000300 modules = removeAll(modules, core_libraries_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000301 props := libraryProps{}
302 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000303 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000304 props.Sdk_version = proptools.StringPtr("module_current")
305 props.Visibility = []string{"//frameworks/base"}
306 ctx.CreateModule(java.LibraryFactory, &props)
307}
308
Anton Hansson4468d7c2022-01-14 12:10:01 +0000309func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
310 props := fgProps{}
311 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
312 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
313 props.Visibility = []string{"//frameworks/base"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800314 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000315}
316
Anton Hansson07a12952022-01-12 17:28:39 +0000317func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100318 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000319
Anton Hansson0860aaf2021-10-08 16:48:03 +0100320 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100321 distFilename := []string{"android.txt", "android-removed.txt"}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000322 bp2BuildDefined := []bool{true, false}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100323 for i, f := range []string{"current.txt", "removed.txt"} {
324 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000325 TxtFilename: f,
326 DistFilename: distFilename[i],
327 BaseTxt: ":non-updatable-" + f,
328 Modules: bootclasspath,
329 ModuleTag: "{.public" + tagSuffix[i],
330 Scope: "public",
331 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100332 })
333 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000334 TxtFilename: f,
335 DistFilename: distFilename[i],
336 BaseTxt: ":non-updatable-system-" + f,
337 Modules: bootclasspath,
338 ModuleTag: "{.system" + tagSuffix[i],
339 Scope: "system",
340 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100341 })
342 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000343 TxtFilename: f,
344 DistFilename: distFilename[i],
345 BaseTxt: ":non-updatable-module-lib-" + f,
346 Modules: bootclasspath,
347 ModuleTag: "{.module-lib" + tagSuffix[i],
348 Scope: "module-lib",
349 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100350 })
351 textFiles = append(textFiles, MergedTxtDefinition{
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000352 TxtFilename: f,
353 DistFilename: distFilename[i],
354 BaseTxt: ":non-updatable-system-server-" + f,
355 Modules: system_server_classpath,
356 ModuleTag: "{.system-server" + tagSuffix[i],
357 Scope: "system-server",
358 Bp2buildDefined: bp2BuildDefined[i],
Anton Hansson0860aaf2021-10-08 16:48:03 +0100359 })
360 }
361 for _, txt := range textFiles {
362 createMergedTxt(ctx, txt)
363 }
364}
365
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000366func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
367 defaultsSdkKinds := []android.SdkKind{
368 android.SdkPublic, android.SdkSystem, android.SdkModule,
369 }
370 for _, sdkKind := range defaultsSdkKinds {
371 props := defaultsProps{}
372 props.Name = proptools.StringPtr(
373 sdkKind.DefaultJavaLibraryName() + "_contributions")
374 if sdkKind == android.SdkModule {
375 props.Name = proptools.StringPtr(
376 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
377 }
378 props.Api_surface = proptools.StringPtr(sdkKind.String())
379 apiSuffix := ""
380 if sdkKind != android.SdkPublic {
381 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
382 }
383 props.Api_contributions = transformArray(
384 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
385 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000386 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000387 ctx.CreateModule(java.DefaultsFactory, &props)
388 }
389}
390
Jihoon Kang1453baa2023-05-27 05:32:30 +0000391func createFullApiLibraries(ctx android.LoadHookContext) {
392 javaLibraryNames := []string{
393 "android_stubs_current",
394 "android_system_stubs_current",
395 "android_test_stubs_current",
396 "android_module_lib_stubs_current",
397 "android_system_server_stubs_current",
398 }
399
400 for _, libraryName := range javaLibraryNames {
401 props := libraryProps{}
402 props.Name = proptools.StringPtr(libraryName)
403 staticLib := libraryName + ".from-source"
404 if ctx.Config().BuildFromTextStub() {
405 staticLib = libraryName + ".from-text"
406 }
407 props.Static_libs = []string{staticLib}
408 props.Defaults = []string{"android.jar_defaults"}
409 props.Visibility = []string{"//visibility:public"}
410
411 ctx.CreateModule(java.LibraryFactory, &props)
412 }
413}
414
Anton Hansson0860aaf2021-10-08 16:48:03 +0100415func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000416 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700417 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000418 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
419 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
420 sort.Strings(bootclasspath)
421 }
Cole Faustdcda3702022-10-04 14:46:35 -0700422 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100423
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000424 createMergedPublicStubs(ctx, bootclasspath)
425 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000426 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000427 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
428 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000429
Cole Faustdcda3702022-10-04 14:46:35 -0700430 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000431
Anton Hansson4468d7c2022-01-14 12:10:01 +0000432 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000433
434 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000435
436 createFullApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100437}
438
439func combinedApisModuleFactory() android.Module {
440 module := &CombinedApis{}
441 module.AddProperties(&module.properties)
442 android.InitAndroidModule(module)
443 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
Zi Wang0d6a5302023-02-16 14:54:01 -0800444 android.InitBazelModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100445 return module
446}
Anton Hanssonfd316452022-01-14 11:15:52 +0000447
Zi Wang0d6a5302023-02-16 14:54:01 -0800448type bazelCombinedApisAttributes struct {
449 Scope bazel.StringAttribute
450 Base bazel.LabelAttribute
451 Deps bazel.LabelListAttribute
452}
453
454// combined_apis bp2build converter
Chris Parsons52f9ad02023-09-13 21:30:55 +0000455func (a *CombinedApis) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Zi Wang0d6a5302023-02-16 14:54:01 -0800456 basePrefix := "non-updatable"
Zi Wang0d6a5302023-02-16 14:54:01 -0800457 scopeToSuffix := map[string]string{
458 "public": "-current.txt",
459 "system": "-system-current.txt",
460 "module-lib": "-module-lib-current.txt",
461 "system-server": "-system-server-current.txt",
462 }
463
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000464 for scopeName, suffix := range scopeToSuffix {
Zi Wang0d6a5302023-02-16 14:54:01 -0800465 name := a.Name() + suffix
466
467 var scope bazel.StringAttribute
468 scope.SetValue(scopeName)
469
470 var base bazel.LabelAttribute
471 base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
472
473 var deps bazel.LabelListAttribute
474 classpath := a.properties.Bootclasspath
475 if scopeName == "system-server" {
476 classpath = a.properties.System_server_classpath
477 }
478 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
479
480 attrs := bazelCombinedApisAttributes{
481 Scope: scope,
482 Base: base,
483 Deps: deps,
484 }
485 props := bazel.BazelTargetModuleProperties{
486 Rule_class: "merged_txts",
487 Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
488 }
489 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
490 }
491}
492
Anton Hanssonfd316452022-01-14 11:15:52 +0000493// Various utility methods below.
494
495// Creates an array of ":<m><tag>" for each m in <modules>.
496func createSrcs(modules []string, tag string) []string {
497 return transformArray(modules, ":", tag)
498}
499
500// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
501func transformArray(modules []string, prefix, suffix string) []string {
502 a := make([]string, 0, len(modules))
503 for _, module := range modules {
504 a = append(a, prefix+module+suffix)
505 }
506 return a
507}
508
509func removeAll(s []string, vs []string) []string {
510 for _, v := range vs {
511 s = remove(s, v)
512 }
513 return s
514}
515
516func remove(s []string, v string) []string {
517 s2 := make([]string, 0, len(s))
518 for _, sv := range s {
519 if sv != v {
520 s2 = append(s2, sv)
521 }
522 }
523 return s2
524}