blob: b975c55c5af99c94976a449f630a8c00898cc3b7 [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"
25 "android/soong/genrule"
Anton Hanssoncb00f942022-01-13 09:45:12 +000026 "android/soong/java"
Anton Hansson0860aaf2021-10-08 16:48:03 +010027)
28
Anton Hansson05e944d2022-01-13 12:26:30 +000029const art = "art.module.public.api"
30const conscrypt = "conscrypt.module.public.api"
31const i18n = "i18n.module.public.api"
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +000032const virtualization = "framework-virtualization"
Mark White3cc5e002023-08-07 11:18:09 +000033const location = "framework-location"
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.
Roshan Pius96dac952023-12-07 10:54:05 -080045var non_updatable_modules = []string{virtualization, location}
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
Harshit Mahajanb52adbc2023-12-15 21:56:42 +000066 android.DefaultableModuleBase
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)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +000077 ctx.RegisterModuleType("combined_apis_defaults", CombinedApisModuleDefaultsFactory)
Anton Hansson0860aaf2021-10-08 16:48:03 +010078}
79
80var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents)
81
82func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) {
83}
84
85type genruleProps struct {
86 Name *string
87 Cmd *string
88 Dists []android.Dist
89 Out []string
90 Srcs []string
91 Tools []string
92 Visibility []string
93}
94
Anton Hanssoncb00f942022-01-13 09:45:12 +000095type libraryProps struct {
96 Name *string
97 Sdk_version *string
98 Static_libs []string
99 Visibility []string
Jihoon Kang1453baa2023-05-27 05:32:30 +0000100 Defaults []string
Anton Hanssoncb00f942022-01-13 09:45:12 +0000101}
102
Anton Hansson4468d7c2022-01-14 12:10:01 +0000103type fgProps struct {
104 Name *string
105 Srcs []string
106 Visibility []string
107}
108
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000109type defaultsProps struct {
110 Name *string
111 Api_surface *string
112 Api_contributions []string
113 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000114 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000115}
116
Anton Hansson0860aaf2021-10-08 16:48:03 +0100117// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
118type MergedTxtDefinition struct {
119 // "current.txt" or "removed.txt"
120 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100121 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
122 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100123 // The module for the non-updatable / non-module part of the api.
124 BaseTxt string
125 // The list of modules that are relevant for this merged txt.
126 Modules []string
127 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
128 ModuleTag string
129 // public, system, module-lib or system-server
130 Scope string
131}
132
133func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
134 metalavaCmd := "$(location metalava)"
135 // Silence reflection warnings. See b/168689341
136 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100137 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100138
139 filename := txt.TxtFilename
140 if txt.Scope != "public" {
141 filename = txt.Scope + "-" + filename
142 }
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000143 moduleName := ctx.ModuleName() + "-" + filename
144
Anton Hansson0860aaf2021-10-08 16:48:03 +0100145 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000146 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100147 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000148 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100149 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000150 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100151 props.Dists = []android.Dist{
152 {
153 Targets: []string{"droidcore"},
154 Dir: proptools.StringPtr("api"),
155 Dest: proptools.StringPtr(filename),
156 },
157 {
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100158 Targets: []string{"api_txt", "sdk"},
Anton Hansson0860aaf2021-10-08 16:48:03 +0100159 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100160 Dest: proptools.StringPtr(txt.DistFilename),
Anton Hansson0860aaf2021-10-08 16:48:03 +0100161 },
162 }
163 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800164 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100165}
166
Cole Faustdcda3702022-10-04 14:46:35 -0700167func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000168 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700169 name string
170 tag string
171 modules []string
172 }{
173 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000174 name: "all-modules-public-annotations",
175 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700176 modules: modules,
177 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000178 name: "all-modules-system-annotations",
179 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700180 modules: modules,
181 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000182 name: "all-modules-module-lib-annotations",
183 tag: "{.module-lib.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-server-annotations",
187 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700188 modules: system_server_modules,
189 },
190 } {
191 props := fgProps{}
192 props.Name = proptools.StringPtr(i.name)
193 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800194 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700195 }
Anton Hansson74b15642022-06-23 08:27:23 +0000196}
197
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000198func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
199 props := libraryProps{}
200 props.Name = proptools.StringPtr("all-modules-public-stubs")
201 props.Static_libs = transformArray(modules, "", ".stubs")
202 props.Sdk_version = proptools.StringPtr("module_current")
203 props.Visibility = []string{"//frameworks/base"}
204 ctx.CreateModule(java.LibraryFactory, &props)
205}
206
207func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000208 // First create the all-updatable-modules-system-stubs
209 {
210 updatable_modules := removeAll(modules, non_updatable_modules)
211 props := libraryProps{}
212 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
213 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
214 props.Sdk_version = proptools.StringPtr("module_current")
215 props.Visibility = []string{"//frameworks/base"}
216 ctx.CreateModule(java.LibraryFactory, &props)
217 }
218 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
219 // into all-modules-system-stubs.
220 {
221 props := libraryProps{}
222 props.Name = proptools.StringPtr("all-modules-system-stubs")
223 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
224 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
225 props.Sdk_version = proptools.StringPtr("module_current")
226 props.Visibility = []string{"//frameworks/base"}
227 ctx.CreateModule(java.LibraryFactory, &props)
228 }
229}
230
231func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000232 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000233 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
234 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000235 props.Sdk_version = proptools.StringPtr("module_current")
236 props.Visibility = []string{"//frameworks/base"}
237 ctx.CreateModule(java.LibraryFactory, &props)
238}
239
Anton Hansson95e89a82022-01-28 11:31:50 +0000240func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
241 // This module is for the "framework-all" module, which should not include the core libraries.
242 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000243 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
244 // against unstable APIs.
245 modules = removeAll(modules, non_updatable_modules)
246 // First create updatable-framework-module-impl, which contains all updatable modules.
247 // This module compiles against module_lib SDK.
248 {
249 props := libraryProps{}
250 props.Name = proptools.StringPtr("updatable-framework-module-impl")
251 props.Static_libs = transformArray(modules, "", ".impl")
252 props.Sdk_version = proptools.StringPtr("module_current")
253 props.Visibility = []string{"//frameworks/base"}
254 ctx.CreateModule(java.LibraryFactory, &props)
255 }
256
257 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
258 // and all non-updatable modules. This module compiles against hidden APIs.
259 {
260 props := libraryProps{}
261 props.Name = proptools.StringPtr("all-framework-module-impl")
262 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
263 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
264 props.Sdk_version = proptools.StringPtr("core_platform")
265 props.Visibility = []string{"//frameworks/base"}
266 ctx.CreateModule(java.LibraryFactory, &props)
267 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000268}
269
270func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000271 // The user of this module compiles against the "core" SDK and against non-updatable modules,
272 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000273 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000274 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000275 props := libraryProps{}
276 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000277 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000278 props.Sdk_version = proptools.StringPtr("module_current")
279 props.Visibility = []string{"//frameworks/base"}
280 ctx.CreateModule(java.LibraryFactory, &props)
281}
282
Anton Hansson4468d7c2022-01-14 12:10:01 +0000283func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
284 props := fgProps{}
285 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
286 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
287 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800288 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000289}
290
Anton Hansson07a12952022-01-12 17:28:39 +0000291func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100292 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000293
Anton Hansson0860aaf2021-10-08 16:48:03 +0100294 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100295 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100296 for i, f := range []string{"current.txt", "removed.txt"} {
297 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800298 TxtFilename: f,
299 DistFilename: distFilename[i],
300 BaseTxt: ":non-updatable-" + f,
301 Modules: bootclasspath,
302 ModuleTag: "{.public" + tagSuffix[i],
303 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100304 })
305 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800306 TxtFilename: f,
307 DistFilename: distFilename[i],
308 BaseTxt: ":non-updatable-system-" + f,
309 Modules: bootclasspath,
310 ModuleTag: "{.system" + tagSuffix[i],
311 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100312 })
313 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800314 TxtFilename: f,
315 DistFilename: distFilename[i],
316 BaseTxt: ":non-updatable-module-lib-" + f,
317 Modules: bootclasspath,
318 ModuleTag: "{.module-lib" + tagSuffix[i],
319 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100320 })
321 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800322 TxtFilename: f,
323 DistFilename: distFilename[i],
324 BaseTxt: ":non-updatable-system-server-" + f,
325 Modules: system_server_classpath,
326 ModuleTag: "{.system-server" + tagSuffix[i],
327 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100328 })
329 }
330 for _, txt := range textFiles {
331 createMergedTxt(ctx, txt)
332 }
333}
334
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000335func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
336 defaultsSdkKinds := []android.SdkKind{
337 android.SdkPublic, android.SdkSystem, android.SdkModule,
338 }
339 for _, sdkKind := range defaultsSdkKinds {
340 props := defaultsProps{}
341 props.Name = proptools.StringPtr(
342 sdkKind.DefaultJavaLibraryName() + "_contributions")
343 if sdkKind == android.SdkModule {
344 props.Name = proptools.StringPtr(
345 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
346 }
347 props.Api_surface = proptools.StringPtr(sdkKind.String())
348 apiSuffix := ""
349 if sdkKind != android.SdkPublic {
350 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
351 }
352 props.Api_contributions = transformArray(
353 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
354 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000355 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000356 ctx.CreateModule(java.DefaultsFactory, &props)
357 }
358}
359
Jihoon Kang1453baa2023-05-27 05:32:30 +0000360func createFullApiLibraries(ctx android.LoadHookContext) {
361 javaLibraryNames := []string{
362 "android_stubs_current",
363 "android_system_stubs_current",
364 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000365 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000366 "android_module_lib_stubs_current",
367 "android_system_server_stubs_current",
368 }
369
370 for _, libraryName := range javaLibraryNames {
371 props := libraryProps{}
372 props.Name = proptools.StringPtr(libraryName)
373 staticLib := libraryName + ".from-source"
374 if ctx.Config().BuildFromTextStub() {
375 staticLib = libraryName + ".from-text"
376 }
377 props.Static_libs = []string{staticLib}
378 props.Defaults = []string{"android.jar_defaults"}
379 props.Visibility = []string{"//visibility:public"}
380
381 ctx.CreateModule(java.LibraryFactory, &props)
382 }
383}
384
Anton Hansson0860aaf2021-10-08 16:48:03 +0100385func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000386 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700387 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000388 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
389 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
390 sort.Strings(bootclasspath)
391 }
Cole Faustdcda3702022-10-04 14:46:35 -0700392 createMergedTxts(ctx, bootclasspath, system_server_classpath)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100393
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000394 createMergedPublicStubs(ctx, bootclasspath)
395 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000396 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000397 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
398 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000399
Cole Faustdcda3702022-10-04 14:46:35 -0700400 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000401
Anton Hansson4468d7c2022-01-14 12:10:01 +0000402 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000403
404 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000405
406 createFullApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100407}
408
409func combinedApisModuleFactory() android.Module {
410 module := &CombinedApis{}
411 module.AddProperties(&module.properties)
412 android.InitAndroidModule(module)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000413 android.InitDefaultableModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100414 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
415 return module
416}
Anton Hanssonfd316452022-01-14 11:15:52 +0000417
418// Various utility methods below.
419
420// Creates an array of ":<m><tag>" for each m in <modules>.
421func createSrcs(modules []string, tag string) []string {
422 return transformArray(modules, ":", tag)
423}
424
425// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
426func transformArray(modules []string, prefix, suffix string) []string {
427 a := make([]string, 0, len(modules))
428 for _, module := range modules {
429 a = append(a, prefix+module+suffix)
430 }
431 return a
432}
433
434func removeAll(s []string, vs []string) []string {
435 for _, v := range vs {
436 s = remove(s, v)
437 }
438 return s
439}
440
441func remove(s []string, v string) []string {
442 s2 := make([]string, 0, len(s))
443 for _, sv := range s {
444 if sv != v {
445 s2 = append(s2, sv)
446 }
447 }
448 return s2
449}
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000450
451// Defaults
452type CombinedApisModuleDefaults struct {
453 android.ModuleBase
454 android.DefaultsModuleBase
455}
456
457func CombinedApisModuleDefaultsFactory() android.Module {
458 module := &CombinedApisModuleDefaults{}
459 module.AddProperties(&CombinedApisProperties{})
460 android.InitDefaultsModule(module)
461 return module
462}