blob: c568a45de5d0f1b108e8f0c7a1eeba13221dd208 [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
113}
114
Zi Wang0d6a5302023-02-16 14:54:01 -0800115type Bazel_module struct {
116 Bp2build_available *bool
117}
118type bazelProperties struct {
119 *Bazel_module
120}
121
122var bp2buildNotAvailable = bazelProperties{
123 &Bazel_module{
124 Bp2build_available: proptools.BoolPtr(false),
125 },
126}
127
Anton Hansson0860aaf2021-10-08 16:48:03 +0100128// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
129type MergedTxtDefinition struct {
130 // "current.txt" or "removed.txt"
131 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100132 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
133 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100134 // The module for the non-updatable / non-module part of the api.
135 BaseTxt string
136 // The list of modules that are relevant for this merged txt.
137 Modules []string
138 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
139 ModuleTag string
140 // public, system, module-lib or system-server
141 Scope string
142}
143
144func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
145 metalavaCmd := "$(location metalava)"
146 // Silence reflection warnings. See b/168689341
147 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
148 metalavaCmd += " --quiet --no-banner --format=v2 "
149
150 filename := txt.TxtFilename
151 if txt.Scope != "public" {
152 filename = txt.Scope + "-" + filename
153 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100154 props := genruleProps{}
155 props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename)
156 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000157 props.Out = []string{filename}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100158 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000159 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100160 props.Dists = []android.Dist{
161 {
162 Targets: []string{"droidcore"},
163 Dir: proptools.StringPtr("api"),
164 Dest: proptools.StringPtr(filename),
165 },
166 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100167 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100168 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100169 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100170 },
171 }
172 props.Visibility = []string{"//visibility:public"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800173 ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100174}
175
Cole Faustdcda3702022-10-04 14:46:35 -0700176func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000177 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700178 name string
179 tag string
180 modules []string
181 }{
182 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000183 name: "all-modules-public-annotations",
184 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700185 modules: modules,
186 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000187 name: "all-modules-system-annotations",
188 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700189 modules: modules,
190 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000191 name: "all-modules-module-lib-annotations",
192 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700193 modules: modules,
194 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000195 name: "all-modules-system-server-annotations",
196 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700197 modules: system_server_modules,
198 },
199 } {
200 props := fgProps{}
201 props.Name = proptools.StringPtr(i.name)
202 props.Srcs = createSrcs(i.modules, i.tag)
Zi Wang0d6a5302023-02-16 14:54:01 -0800203 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Cole Faustdcda3702022-10-04 14:46:35 -0700204 }
Anton Hansson74b15642022-06-23 08:27:23 +0000205}
206
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000207func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
208 props := libraryProps{}
209 props.Name = proptools.StringPtr("all-modules-public-stubs")
210 props.Static_libs = transformArray(modules, "", ".stubs")
211 props.Sdk_version = proptools.StringPtr("module_current")
212 props.Visibility = []string{"//frameworks/base"}
213 ctx.CreateModule(java.LibraryFactory, &props)
214}
215
216func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000217 // First create the all-updatable-modules-system-stubs
218 {
219 updatable_modules := removeAll(modules, non_updatable_modules)
220 props := libraryProps{}
221 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
222 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
223 props.Sdk_version = proptools.StringPtr("module_current")
224 props.Visibility = []string{"//frameworks/base"}
225 ctx.CreateModule(java.LibraryFactory, &props)
226 }
227 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
228 // into all-modules-system-stubs.
229 {
230 props := libraryProps{}
231 props.Name = proptools.StringPtr("all-modules-system-stubs")
232 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
233 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
234 props.Sdk_version = proptools.StringPtr("module_current")
235 props.Visibility = []string{"//frameworks/base"}
236 ctx.CreateModule(java.LibraryFactory, &props)
237 }
238}
239
240func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000241 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000242 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
243 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000244 props.Sdk_version = proptools.StringPtr("module_current")
245 props.Visibility = []string{"//frameworks/base"}
246 ctx.CreateModule(java.LibraryFactory, &props)
247}
248
Anton Hansson95e89a82022-01-28 11:31:50 +0000249func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
250 // This module is for the "framework-all" module, which should not include the core libraries.
251 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000252 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
253 // against unstable APIs.
254 modules = removeAll(modules, non_updatable_modules)
255 // First create updatable-framework-module-impl, which contains all updatable modules.
256 // This module compiles against module_lib SDK.
257 {
258 props := libraryProps{}
259 props.Name = proptools.StringPtr("updatable-framework-module-impl")
260 props.Static_libs = transformArray(modules, "", ".impl")
261 props.Sdk_version = proptools.StringPtr("module_current")
262 props.Visibility = []string{"//frameworks/base"}
263 ctx.CreateModule(java.LibraryFactory, &props)
264 }
265
266 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
267 // and all non-updatable modules. This module compiles against hidden APIs.
268 {
269 props := libraryProps{}
270 props.Name = proptools.StringPtr("all-framework-module-impl")
271 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
272 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
273 props.Sdk_version = proptools.StringPtr("core_platform")
274 props.Visibility = []string{"//frameworks/base"}
275 ctx.CreateModule(java.LibraryFactory, &props)
276 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000277}
278
279func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Anton Hanssoncb00f942022-01-13 09:45:12 +0000280 // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000281 modules = removeAll(modules, core_libraries_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000282 props := libraryProps{}
283 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000284 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000285 props.Sdk_version = proptools.StringPtr("module_current")
286 props.Visibility = []string{"//frameworks/base"}
287 ctx.CreateModule(java.LibraryFactory, &props)
288}
289
Anton Hansson4468d7c2022-01-14 12:10:01 +0000290func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
291 props := fgProps{}
292 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
293 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
294 props.Visibility = []string{"//frameworks/base"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800295 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000296}
297
Anton Hansson07a12952022-01-12 17:28:39 +0000298func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100299 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000300
Anton Hansson0860aaf2021-10-08 16:48:03 +0100301 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100302 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100303 for i, f := range []string{"current.txt", "removed.txt"} {
304 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100305 TxtFilename: f,
306 DistFilename: distFilename[i],
307 BaseTxt: ":non-updatable-" + f,
308 Modules: bootclasspath,
309 ModuleTag: "{.public" + tagSuffix[i],
310 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100311 })
312 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100313 TxtFilename: f,
314 DistFilename: distFilename[i],
315 BaseTxt: ":non-updatable-system-" + f,
316 Modules: bootclasspath,
317 ModuleTag: "{.system" + tagSuffix[i],
318 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100319 })
320 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100321 TxtFilename: f,
322 DistFilename: distFilename[i],
323 BaseTxt: ":non-updatable-module-lib-" + f,
324 Modules: bootclasspath,
325 ModuleTag: "{.module-lib" + tagSuffix[i],
326 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100327 })
328 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100329 TxtFilename: f,
330 DistFilename: distFilename[i],
331 BaseTxt: ":non-updatable-system-server-" + f,
332 Modules: system_server_classpath,
333 ModuleTag: "{.system-server" + tagSuffix[i],
334 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100335 })
336 }
337 for _, txt := range textFiles {
338 createMergedTxt(ctx, txt)
339 }
340}
341
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000342func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
343 defaultsSdkKinds := []android.SdkKind{
344 android.SdkPublic, android.SdkSystem, android.SdkModule,
345 }
346 for _, sdkKind := range defaultsSdkKinds {
347 props := defaultsProps{}
348 props.Name = proptools.StringPtr(
349 sdkKind.DefaultJavaLibraryName() + "_contributions")
350 if sdkKind == android.SdkModule {
351 props.Name = proptools.StringPtr(
352 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
353 }
354 props.Api_surface = proptools.StringPtr(sdkKind.String())
355 apiSuffix := ""
356 if sdkKind != android.SdkPublic {
357 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
358 }
359 props.Api_contributions = transformArray(
360 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
361 props.Defaults_visibility = []string{"//visibility:public"}
362 ctx.CreateModule(java.DefaultsFactory, &props)
363 }
364}
365
Jihoon Kang1453baa2023-05-27 05:32:30 +0000366func createFullApiLibraries(ctx android.LoadHookContext) {
367 javaLibraryNames := []string{
368 "android_stubs_current",
369 "android_system_stubs_current",
370 "android_test_stubs_current",
371 "android_module_lib_stubs_current",
372 "android_system_server_stubs_current",
373 }
374
375 for _, libraryName := range javaLibraryNames {
376 props := libraryProps{}
377 props.Name = proptools.StringPtr(libraryName)
378 staticLib := libraryName + ".from-source"
379 if ctx.Config().BuildFromTextStub() {
380 staticLib = libraryName + ".from-text"
381 }
382 props.Static_libs = []string{staticLib}
383 props.Defaults = []string{"android.jar_defaults"}
384 props.Visibility = []string{"//visibility:public"}
385
386 ctx.CreateModule(java.LibraryFactory, &props)
387 }
388}
389
Anton Hansson0860aaf2021-10-08 16:48:03 +0100390func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000391 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700392 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000393 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
394 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
395 sort.Strings(bootclasspath)
396 }
Cole Faustdcda3702022-10-04 14:46:35 -0700397 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100398
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000399 createMergedPublicStubs(ctx, bootclasspath)
400 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000401 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000402 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
403 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000404
Cole Faustdcda3702022-10-04 14:46:35 -0700405 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000406
Anton Hansson4468d7c2022-01-14 12:10:01 +0000407 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000408
409 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000410
411 createFullApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100412}
413
414func combinedApisModuleFactory() android.Module {
415 module := &CombinedApis{}
416 module.AddProperties(&module.properties)
417 android.InitAndroidModule(module)
418 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
Zi Wang0d6a5302023-02-16 14:54:01 -0800419 android.InitBazelModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100420 return module
421}
Anton Hanssonfd316452022-01-14 11:15:52 +0000422
Zi Wang0d6a5302023-02-16 14:54:01 -0800423type bazelCombinedApisAttributes struct {
424 Scope bazel.StringAttribute
425 Base bazel.LabelAttribute
426 Deps bazel.LabelListAttribute
427}
428
429// combined_apis bp2build converter
430func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
431 basePrefix := "non-updatable"
Zi Wang0d6a5302023-02-16 14:54:01 -0800432 scopeToSuffix := map[string]string{
433 "public": "-current.txt",
434 "system": "-system-current.txt",
435 "module-lib": "-module-lib-current.txt",
436 "system-server": "-system-server-current.txt",
437 }
438
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000439 for scopeName, suffix := range scopeToSuffix {
Zi Wang0d6a5302023-02-16 14:54:01 -0800440 name := a.Name() + suffix
441
442 var scope bazel.StringAttribute
443 scope.SetValue(scopeName)
444
445 var base bazel.LabelAttribute
446 base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
447
448 var deps bazel.LabelListAttribute
449 classpath := a.properties.Bootclasspath
450 if scopeName == "system-server" {
451 classpath = a.properties.System_server_classpath
452 }
453 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
454
455 attrs := bazelCombinedApisAttributes{
456 Scope: scope,
457 Base: base,
458 Deps: deps,
459 }
460 props := bazel.BazelTargetModuleProperties{
461 Rule_class: "merged_txts",
462 Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
463 }
464 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
465 }
466}
467
Anton Hanssonfd316452022-01-14 11:15:52 +0000468// Various utility methods below.
469
470// Creates an array of ":<m><tag>" for each m in <modules>.
471func createSrcs(modules []string, tag string) []string {
472 return transformArray(modules, ":", tag)
473}
474
475// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
476func transformArray(modules []string, prefix, suffix string) []string {
477 a := make([]string, 0, len(modules))
478 for _, module := range modules {
479 a = append(a, prefix+module+suffix)
480 }
481 return a
482}
483
484func removeAll(s []string, vs []string) []string {
485 for _, v := range vs {
486 s = remove(s, v)
487 }
488 return s
489}
490
491func remove(s []string, v string) []string {
492 s2 := make([]string, 0, len(s))
493 for _, sv := range s {
494 if sv != v {
495 s2 = append(s2, sv)
496 }
497 }
498 return s2
499}