blob: af817b5666cd5aa33946acfb54d73785187dff9e [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
99}
100
Anton Hansson4468d7c2022-01-14 12:10:01 +0000101type fgProps struct {
102 Name *string
103 Srcs []string
104 Visibility []string
105}
106
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000107type defaultsProps struct {
108 Name *string
109 Api_surface *string
110 Api_contributions []string
111 Defaults_visibility []string
112}
113
Zi Wang0d6a5302023-02-16 14:54:01 -0800114type Bazel_module struct {
115 Bp2build_available *bool
116}
117type bazelProperties struct {
118 *Bazel_module
119}
120
121var bp2buildNotAvailable = bazelProperties{
122 &Bazel_module{
123 Bp2build_available: proptools.BoolPtr(false),
124 },
125}
126
Anton Hansson0860aaf2021-10-08 16:48:03 +0100127// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
128type MergedTxtDefinition struct {
129 // "current.txt" or "removed.txt"
130 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100131 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
132 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100133 // The module for the non-updatable / non-module part of the api.
134 BaseTxt string
135 // The list of modules that are relevant for this merged txt.
136 Modules []string
137 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
138 ModuleTag string
139 // public, system, module-lib or system-server
140 Scope string
141}
142
143func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
144 metalavaCmd := "$(location metalava)"
145 // Silence reflection warnings. See b/168689341
146 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
147 metalavaCmd += " --quiet --no-banner --format=v2 "
148
149 filename := txt.TxtFilename
150 if txt.Scope != "public" {
151 filename = txt.Scope + "-" + filename
152 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100153 props := genruleProps{}
154 props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename)
155 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000156 props.Out = []string{filename}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100157 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000158 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100159 props.Dists = []android.Dist{
160 {
161 Targets: []string{"droidcore"},
162 Dir: proptools.StringPtr("api"),
163 Dest: proptools.StringPtr(filename),
164 },
165 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100166 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100167 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100168 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100169 },
170 }
171 props.Visibility = []string{"//visibility:public"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800172 ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100173}
174
Cole Faustdcda3702022-10-04 14:46:35 -0700175func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000176 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700177 name string
178 tag string
179 modules []string
180 }{
181 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000182 name: "all-modules-public-annotations",
183 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700184 modules: modules,
185 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000186 name: "all-modules-system-annotations",
187 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700188 modules: modules,
189 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000190 name: "all-modules-module-lib-annotations",
191 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700192 modules: modules,
193 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000194 name: "all-modules-system-server-annotations",
195 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700196 modules: system_server_modules,
197 },
198 } {
199 props := fgProps{}
200 props.Name = proptools.StringPtr(i.name)
201 props.Srcs = createSrcs(i.modules, i.tag)
Zi Wang0d6a5302023-02-16 14:54:01 -0800202 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Cole Faustdcda3702022-10-04 14:46:35 -0700203 }
Anton Hansson74b15642022-06-23 08:27:23 +0000204}
205
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000206func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
207 props := libraryProps{}
208 props.Name = proptools.StringPtr("all-modules-public-stubs")
209 props.Static_libs = transformArray(modules, "", ".stubs")
210 props.Sdk_version = proptools.StringPtr("module_current")
211 props.Visibility = []string{"//frameworks/base"}
212 ctx.CreateModule(java.LibraryFactory, &props)
213}
214
215func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000216 // First create the all-updatable-modules-system-stubs
217 {
218 updatable_modules := removeAll(modules, non_updatable_modules)
219 props := libraryProps{}
220 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
221 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
222 props.Sdk_version = proptools.StringPtr("module_current")
223 props.Visibility = []string{"//frameworks/base"}
224 ctx.CreateModule(java.LibraryFactory, &props)
225 }
226 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
227 // into all-modules-system-stubs.
228 {
229 props := libraryProps{}
230 props.Name = proptools.StringPtr("all-modules-system-stubs")
231 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
232 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
233 props.Sdk_version = proptools.StringPtr("module_current")
234 props.Visibility = []string{"//frameworks/base"}
235 ctx.CreateModule(java.LibraryFactory, &props)
236 }
237}
238
239func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000240 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000241 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
242 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000243 props.Sdk_version = proptools.StringPtr("module_current")
244 props.Visibility = []string{"//frameworks/base"}
245 ctx.CreateModule(java.LibraryFactory, &props)
246}
247
Anton Hansson95e89a82022-01-28 11:31:50 +0000248func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
249 // This module is for the "framework-all" module, which should not include the core libraries.
250 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000251 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
252 // against unstable APIs.
253 modules = removeAll(modules, non_updatable_modules)
254 // First create updatable-framework-module-impl, which contains all updatable modules.
255 // This module compiles against module_lib SDK.
256 {
257 props := libraryProps{}
258 props.Name = proptools.StringPtr("updatable-framework-module-impl")
259 props.Static_libs = transformArray(modules, "", ".impl")
260 props.Sdk_version = proptools.StringPtr("module_current")
261 props.Visibility = []string{"//frameworks/base"}
262 ctx.CreateModule(java.LibraryFactory, &props)
263 }
264
265 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
266 // and all non-updatable modules. This module compiles against hidden APIs.
267 {
268 props := libraryProps{}
269 props.Name = proptools.StringPtr("all-framework-module-impl")
270 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
271 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
272 props.Sdk_version = proptools.StringPtr("core_platform")
273 props.Visibility = []string{"//frameworks/base"}
274 ctx.CreateModule(java.LibraryFactory, &props)
275 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000276}
277
278func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Anton Hanssoncb00f942022-01-13 09:45:12 +0000279 // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000280 modules = removeAll(modules, core_libraries_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000281 props := libraryProps{}
282 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000283 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000284 props.Sdk_version = proptools.StringPtr("module_current")
285 props.Visibility = []string{"//frameworks/base"}
286 ctx.CreateModule(java.LibraryFactory, &props)
287}
288
Anton Hansson4468d7c2022-01-14 12:10:01 +0000289func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
290 props := fgProps{}
291 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
292 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
293 props.Visibility = []string{"//frameworks/base"}
Zi Wang0d6a5302023-02-16 14:54:01 -0800294 ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000295}
296
Anton Hansson07a12952022-01-12 17:28:39 +0000297func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100298 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000299
Anton Hansson0860aaf2021-10-08 16:48:03 +0100300 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100301 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100302 for i, f := range []string{"current.txt", "removed.txt"} {
303 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100304 TxtFilename: f,
305 DistFilename: distFilename[i],
306 BaseTxt: ":non-updatable-" + f,
307 Modules: bootclasspath,
308 ModuleTag: "{.public" + tagSuffix[i],
309 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100310 })
311 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100312 TxtFilename: f,
313 DistFilename: distFilename[i],
314 BaseTxt: ":non-updatable-system-" + f,
315 Modules: bootclasspath,
316 ModuleTag: "{.system" + tagSuffix[i],
317 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100318 })
319 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100320 TxtFilename: f,
321 DistFilename: distFilename[i],
322 BaseTxt: ":non-updatable-module-lib-" + f,
323 Modules: bootclasspath,
324 ModuleTag: "{.module-lib" + tagSuffix[i],
325 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100326 })
327 textFiles = append(textFiles, MergedTxtDefinition{
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100328 TxtFilename: f,
329 DistFilename: distFilename[i],
330 BaseTxt: ":non-updatable-system-server-" + f,
331 Modules: system_server_classpath,
332 ModuleTag: "{.system-server" + tagSuffix[i],
333 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100334 })
335 }
336 for _, txt := range textFiles {
337 createMergedTxt(ctx, txt)
338 }
339}
340
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000341func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
342 defaultsSdkKinds := []android.SdkKind{
343 android.SdkPublic, android.SdkSystem, android.SdkModule,
344 }
345 for _, sdkKind := range defaultsSdkKinds {
346 props := defaultsProps{}
347 props.Name = proptools.StringPtr(
348 sdkKind.DefaultJavaLibraryName() + "_contributions")
349 if sdkKind == android.SdkModule {
350 props.Name = proptools.StringPtr(
351 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
352 }
353 props.Api_surface = proptools.StringPtr(sdkKind.String())
354 apiSuffix := ""
355 if sdkKind != android.SdkPublic {
356 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
357 }
358 props.Api_contributions = transformArray(
359 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
360 props.Defaults_visibility = []string{"//visibility:public"}
361 ctx.CreateModule(java.DefaultsFactory, &props)
362 }
363}
364
Anton Hansson0860aaf2021-10-08 16:48:03 +0100365func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000366 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700367 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000368 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
369 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
370 sort.Strings(bootclasspath)
371 }
Cole Faustdcda3702022-10-04 14:46:35 -0700372 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100373
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000374 createMergedPublicStubs(ctx, bootclasspath)
375 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000376 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000377 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
378 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000379
Cole Faustdcda3702022-10-04 14:46:35 -0700380 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000381
Anton Hansson4468d7c2022-01-14 12:10:01 +0000382 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000383
384 createApiContributionDefaults(ctx, bootclasspath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100385}
386
387func combinedApisModuleFactory() android.Module {
388 module := &CombinedApis{}
389 module.AddProperties(&module.properties)
390 android.InitAndroidModule(module)
391 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
Zi Wang0d6a5302023-02-16 14:54:01 -0800392 android.InitBazelModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100393 return module
394}
Anton Hanssonfd316452022-01-14 11:15:52 +0000395
Zi Wang0d6a5302023-02-16 14:54:01 -0800396type bazelCombinedApisAttributes struct {
397 Scope bazel.StringAttribute
398 Base bazel.LabelAttribute
399 Deps bazel.LabelListAttribute
400}
401
402// combined_apis bp2build converter
403func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
404 basePrefix := "non-updatable"
Zi Wang0d6a5302023-02-16 14:54:01 -0800405 scopeToSuffix := map[string]string{
406 "public": "-current.txt",
407 "system": "-system-current.txt",
408 "module-lib": "-module-lib-current.txt",
409 "system-server": "-system-server-current.txt",
410 }
411
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000412 for scopeName, suffix := range scopeToSuffix {
Zi Wang0d6a5302023-02-16 14:54:01 -0800413 name := a.Name() + suffix
414
415 var scope bazel.StringAttribute
416 scope.SetValue(scopeName)
417
418 var base bazel.LabelAttribute
419 base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
420
421 var deps bazel.LabelListAttribute
422 classpath := a.properties.Bootclasspath
423 if scopeName == "system-server" {
424 classpath = a.properties.System_server_classpath
425 }
426 deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
427
428 attrs := bazelCombinedApisAttributes{
429 Scope: scope,
430 Base: base,
431 Deps: deps,
432 }
433 props := bazel.BazelTargetModuleProperties{
434 Rule_class: "merged_txts",
435 Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
436 }
437 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
438 }
439}
440
Anton Hanssonfd316452022-01-14 11:15:52 +0000441// Various utility methods below.
442
443// Creates an array of ":<m><tag>" for each m in <modules>.
444func createSrcs(modules []string, tag string) []string {
445 return transformArray(modules, ":", tag)
446}
447
448// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
449func transformArray(modules []string, prefix, suffix string) []string {
450 a := make([]string, 0, len(modules))
451 for _, module := range modules {
452 a = append(a, prefix+module+suffix)
453 }
454 return a
455}
456
457func removeAll(s []string, vs []string) []string {
458 for _, v := range vs {
459 s = remove(s, v)
460 }
461 return s
462}
463
464func remove(s []string, v string) []string {
465 s2 := make([]string, 0, len(s))
466 for _, sv := range s {
467 if sv != v {
468 s2 = append(s2, sv)
469 }
470 }
471 return s2
472}