blob: 78dcaf471468d6abd715842431b4832ea09a9c67 [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 {
Jihoon Kangdaa35302024-02-12 23:18:52 +000096 Name *string
97 Sdk_version *string
98 Static_libs []string
99 Visibility []string
100 Defaults []string
101 Is_stubs_module *bool
Anton Hanssoncb00f942022-01-13 09:45:12 +0000102}
103
Anton Hansson4468d7c2022-01-14 12:10:01 +0000104type fgProps struct {
105 Name *string
106 Srcs []string
107 Visibility []string
108}
109
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000110type defaultsProps struct {
111 Name *string
112 Api_surface *string
113 Api_contributions []string
114 Defaults_visibility []string
Jihoon Kang471a05b2023-08-01 06:37:17 +0000115 Previous_api *string
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000116}
117
Anton Hansson0860aaf2021-10-08 16:48:03 +0100118// Struct to pass parameters for the various merged [current|removed].txt file modules we create.
119type MergedTxtDefinition struct {
120 // "current.txt" or "removed.txt"
121 TxtFilename string
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100122 // Filename in the new dist dir. "android.txt" or "android-removed.txt"
123 DistFilename string
Anton Hansson0860aaf2021-10-08 16:48:03 +0100124 // The module for the non-updatable / non-module part of the api.
125 BaseTxt string
126 // The list of modules that are relevant for this merged txt.
127 Modules []string
128 // The output tag for each module to use.e.g. {.public.api.txt} for current.txt
129 ModuleTag string
130 // public, system, module-lib or system-server
131 Scope string
132}
133
Jihoon Kang31cf2742024-02-07 19:52:19 +0000134func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100135 metalavaCmd := "$(location metalava)"
136 // Silence reflection warnings. See b/168689341
137 metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100138 metalavaCmd += " --quiet merge-signatures --format=v2 "
Anton Hansson0860aaf2021-10-08 16:48:03 +0100139
140 filename := txt.TxtFilename
141 if txt.Scope != "public" {
142 filename = txt.Scope + "-" + filename
143 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000144 moduleName := ctx.ModuleName() + stubsTypeSuffix + filename
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000145
Anton Hansson0860aaf2021-10-08 16:48:03 +0100146 props := genruleProps{}
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000147 props.Name = proptools.StringPtr(moduleName)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100148 props.Tools = []string{"metalava"}
Anton Hansson16ff3572022-01-11 18:36:35 +0000149 props.Out = []string{filename}
Paul Duffinf3b1fc42023-08-14 22:03:06 +0100150 props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)")
Anton Hanssonfd316452022-01-14 11:15:52 +0000151 props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...)
Jihoon Kang31cf2742024-02-07 19:52:19 +0000152 if doDist {
153 props.Dists = []android.Dist{
154 {
155 Targets: []string{"droidcore"},
156 Dir: proptools.StringPtr("api"),
157 Dest: proptools.StringPtr(filename),
158 },
159 {
160 Targets: []string{"api_txt", "sdk"},
161 Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"),
162 Dest: proptools.StringPtr(txt.DistFilename),
163 },
164 }
Anton Hansson0860aaf2021-10-08 16:48:03 +0100165 }
166 props.Visibility = []string{"//visibility:public"}
Colin Crossc6420762023-12-07 12:38:40 -0800167 ctx.CreateModule(genrule.GenRuleFactory, &props)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100168}
169
Cole Faustdcda3702022-10-04 14:46:35 -0700170func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000171 for _, i := range []struct {
Cole Faustdcda3702022-10-04 14:46:35 -0700172 name string
173 tag string
174 modules []string
175 }{
176 {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000177 name: "all-modules-public-annotations",
178 tag: "{.public.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700179 modules: modules,
180 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000181 name: "all-modules-system-annotations",
182 tag: "{.system.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700183 modules: modules,
184 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000185 name: "all-modules-module-lib-annotations",
186 tag: "{.module-lib.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700187 modules: modules,
188 }, {
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000189 name: "all-modules-system-server-annotations",
190 tag: "{.system-server.annotations.zip}",
Cole Faustdcda3702022-10-04 14:46:35 -0700191 modules: system_server_modules,
192 },
193 } {
194 props := fgProps{}
195 props.Name = proptools.StringPtr(i.name)
196 props.Srcs = createSrcs(i.modules, i.tag)
Colin Crossc6420762023-12-07 12:38:40 -0800197 ctx.CreateModule(android.FileGroupFactory, &props)
Cole Faustdcda3702022-10-04 14:46:35 -0700198 }
Anton Hansson74b15642022-06-23 08:27:23 +0000199}
200
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000201func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) {
202 props := libraryProps{}
203 props.Name = proptools.StringPtr("all-modules-public-stubs")
204 props.Static_libs = transformArray(modules, "", ".stubs")
205 props.Sdk_version = proptools.StringPtr("module_current")
206 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000207 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000208 ctx.CreateModule(java.LibraryFactory, &props)
209}
210
Jihoon Kang059b9492023-12-29 00:40:34 +0000211func createMergedPublicExportableStubs(ctx android.LoadHookContext, modules []string) {
212 props := libraryProps{}
213 props.Name = proptools.StringPtr("all-modules-public-stubs-exportable")
214 props.Static_libs = transformArray(modules, "", ".stubs.exportable")
215 props.Sdk_version = proptools.StringPtr("module_current")
216 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000217 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000218 ctx.CreateModule(java.LibraryFactory, &props)
219}
220
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000221func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) {
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000222 // First create the all-updatable-modules-system-stubs
223 {
224 updatable_modules := removeAll(modules, non_updatable_modules)
225 props := libraryProps{}
226 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs")
227 props.Static_libs = transformArray(updatable_modules, "", ".stubs.system")
228 props.Sdk_version = proptools.StringPtr("module_current")
229 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000230 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000231 ctx.CreateModule(java.LibraryFactory, &props)
232 }
233 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
234 // into all-modules-system-stubs.
235 {
236 props := libraryProps{}
237 props.Name = proptools.StringPtr("all-modules-system-stubs")
238 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system")
239 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs")
240 props.Sdk_version = proptools.StringPtr("module_current")
241 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000242 props.Is_stubs_module = proptools.BoolPtr(true)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000243 ctx.CreateModule(java.LibraryFactory, &props)
244 }
245}
246
Jihoon Kang059b9492023-12-29 00:40:34 +0000247func createMergedSystemExportableStubs(ctx android.LoadHookContext, modules []string) {
248 // First create the all-updatable-modules-system-stubs
249 {
250 updatable_modules := removeAll(modules, non_updatable_modules)
251 props := libraryProps{}
252 props.Name = proptools.StringPtr("all-updatable-modules-system-stubs-exportable")
253 props.Static_libs = transformArray(updatable_modules, "", ".stubs.exportable.system")
254 props.Sdk_version = proptools.StringPtr("module_current")
255 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000256 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000257 ctx.CreateModule(java.LibraryFactory, &props)
258 }
259 // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules
260 // into all-modules-system-stubs.
261 {
262 props := libraryProps{}
263 props.Name = proptools.StringPtr("all-modules-system-stubs-exportable")
264 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.system")
265 props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs-exportable")
266 props.Sdk_version = proptools.StringPtr("module_current")
267 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000268 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000269 ctx.CreateModule(java.LibraryFactory, &props)
270 }
271}
272
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000273func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) {
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000274 props := libraryProps{}
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000275 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs")
276 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test")
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000277 props.Sdk_version = proptools.StringPtr("module_current")
278 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000279 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000280 ctx.CreateModule(java.LibraryFactory, &props)
281}
282
Jihoon Kang059b9492023-12-29 00:40:34 +0000283func createMergedTestExportableStubsForNonUpdatableModules(ctx android.LoadHookContext) {
284 props := libraryProps{}
285 props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs-exportable")
286 props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.exportable.test")
287 props.Sdk_version = proptools.StringPtr("module_current")
288 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000289 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000290 ctx.CreateModule(java.LibraryFactory, &props)
291}
292
Anton Hansson95e89a82022-01-28 11:31:50 +0000293func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) {
294 // This module is for the "framework-all" module, which should not include the core libraries.
295 modules = removeAll(modules, core_libraries_modules)
Nikita Ioffed3f0a6f2022-11-15 11:26:53 +0000296 // Remove the modules that belong to non-updatable APEXes since those are allowed to compile
297 // against unstable APIs.
298 modules = removeAll(modules, non_updatable_modules)
299 // First create updatable-framework-module-impl, which contains all updatable modules.
300 // This module compiles against module_lib SDK.
301 {
302 props := libraryProps{}
303 props.Name = proptools.StringPtr("updatable-framework-module-impl")
304 props.Static_libs = transformArray(modules, "", ".impl")
305 props.Sdk_version = proptools.StringPtr("module_current")
306 props.Visibility = []string{"//frameworks/base"}
307 ctx.CreateModule(java.LibraryFactory, &props)
308 }
309
310 // Now create all-framework-module-impl, which contains updatable-framework-module-impl
311 // and all non-updatable modules. This module compiles against hidden APIs.
312 {
313 props := libraryProps{}
314 props.Name = proptools.StringPtr("all-framework-module-impl")
315 props.Static_libs = transformArray(non_updatable_modules, "", ".impl")
316 props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl")
317 props.Sdk_version = proptools.StringPtr("core_platform")
318 props.Visibility = []string{"//frameworks/base"}
319 ctx.CreateModule(java.LibraryFactory, &props)
320 }
Anton Hansson95e89a82022-01-28 11:31:50 +0000321}
322
Jihoon Kang059b9492023-12-29 00:40:34 +0000323func createMergedFrameworkModuleLibExportableStubs(ctx android.LoadHookContext, modules []string) {
324 // The user of this module compiles against the "core" SDK and against non-updatable modules,
325 // so remove to avoid dupes.
326 modules = removeAll(modules, core_libraries_modules)
327 modules = removeAll(modules, non_updatable_modules)
328 props := libraryProps{}
329 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api-exportable")
330 props.Static_libs = transformArray(modules, "", ".stubs.exportable.module_lib")
331 props.Sdk_version = proptools.StringPtr("module_current")
332 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000333 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000334 ctx.CreateModule(java.LibraryFactory, &props)
335}
336
Anton Hansson95e89a82022-01-28 11:31:50 +0000337func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) {
Mark White3cc5e002023-08-07 11:18:09 +0000338 // The user of this module compiles against the "core" SDK and against non-updatable modules,
339 // so remove to avoid dupes.
Anton Hansson95e89a82022-01-28 11:31:50 +0000340 modules = removeAll(modules, core_libraries_modules)
Mark White3cc5e002023-08-07 11:18:09 +0000341 modules = removeAll(modules, non_updatable_modules)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000342 props := libraryProps{}
343 props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api")
Anton Hanssonfd316452022-01-14 11:15:52 +0000344 props.Static_libs = transformArray(modules, "", ".stubs.module_lib")
Anton Hanssoncb00f942022-01-13 09:45:12 +0000345 props.Sdk_version = proptools.StringPtr("module_current")
346 props.Visibility = []string{"//frameworks/base"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000347 props.Is_stubs_module = proptools.BoolPtr(true)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000348 ctx.CreateModule(java.LibraryFactory, &props)
349}
350
Anton Hansson4468d7c2022-01-14 12:10:01 +0000351func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) {
352 props := fgProps{}
353 props.Name = proptools.StringPtr("all-modules-public-stubs-source")
354 props.Srcs = createSrcs(modules, "{.public.stubs.source}")
355 props.Visibility = []string{"//frameworks/base"}
Colin Crossc6420762023-12-07 12:38:40 -0800356 ctx.CreateModule(android.FileGroupFactory, &props)
Anton Hansson4468d7c2022-01-14 12:10:01 +0000357}
358
Jihoon Kang31cf2742024-02-07 19:52:19 +0000359func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string, baseTxtModulePrefix, stubsTypeSuffix string, doDist bool) {
Anton Hansson0860aaf2021-10-08 16:48:03 +0100360 var textFiles []MergedTxtDefinition
Anton Hansson16ff3572022-01-11 18:36:35 +0000361
Anton Hansson0860aaf2021-10-08 16:48:03 +0100362 tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
Anton Hansson09a9c4e2022-04-08 10:59:46 +0100363 distFilename := []string{"android.txt", "android-removed.txt"}
Anton Hansson0860aaf2021-10-08 16:48:03 +0100364 for i, f := range []string{"current.txt", "removed.txt"} {
365 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800366 TxtFilename: f,
367 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000368 BaseTxt: ":" + baseTxtModulePrefix + f,
Colin Crossc6420762023-12-07 12:38:40 -0800369 Modules: bootclasspath,
370 ModuleTag: "{.public" + tagSuffix[i],
371 Scope: "public",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100372 })
373 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800374 TxtFilename: f,
375 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000376 BaseTxt: ":" + baseTxtModulePrefix + "system-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800377 Modules: bootclasspath,
378 ModuleTag: "{.system" + tagSuffix[i],
379 Scope: "system",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100380 })
381 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800382 TxtFilename: f,
383 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000384 BaseTxt: ":" + baseTxtModulePrefix + "module-lib-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800385 Modules: bootclasspath,
386 ModuleTag: "{.module-lib" + tagSuffix[i],
387 Scope: "module-lib",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100388 })
389 textFiles = append(textFiles, MergedTxtDefinition{
Colin Crossc6420762023-12-07 12:38:40 -0800390 TxtFilename: f,
391 DistFilename: distFilename[i],
Jihoon Kang31cf2742024-02-07 19:52:19 +0000392 BaseTxt: ":" + baseTxtModulePrefix + "system-server-" + f,
Colin Crossc6420762023-12-07 12:38:40 -0800393 Modules: system_server_classpath,
394 ModuleTag: "{.system-server" + tagSuffix[i],
395 Scope: "system-server",
Anton Hansson0860aaf2021-10-08 16:48:03 +0100396 })
397 }
398 for _, txt := range textFiles {
Jihoon Kang31cf2742024-02-07 19:52:19 +0000399 createMergedTxt(ctx, txt, stubsTypeSuffix, doDist)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100400 }
401}
402
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000403func createApiContributionDefaults(ctx android.LoadHookContext, modules []string) {
404 defaultsSdkKinds := []android.SdkKind{
405 android.SdkPublic, android.SdkSystem, android.SdkModule,
406 }
407 for _, sdkKind := range defaultsSdkKinds {
408 props := defaultsProps{}
409 props.Name = proptools.StringPtr(
410 sdkKind.DefaultJavaLibraryName() + "_contributions")
411 if sdkKind == android.SdkModule {
412 props.Name = proptools.StringPtr(
413 sdkKind.DefaultJavaLibraryName() + "_contributions_full")
414 }
415 props.Api_surface = proptools.StringPtr(sdkKind.String())
416 apiSuffix := ""
417 if sdkKind != android.SdkPublic {
418 apiSuffix = "." + strings.ReplaceAll(sdkKind.String(), "-", "_")
419 }
420 props.Api_contributions = transformArray(
421 modules, "", fmt.Sprintf(".stubs.source%s.api.contribution", apiSuffix))
422 props.Defaults_visibility = []string{"//visibility:public"}
Jihoon Kang471a05b2023-08-01 06:37:17 +0000423 props.Previous_api = proptools.StringPtr(":android.api.public.latest")
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000424 ctx.CreateModule(java.DefaultsFactory, &props)
425 }
426}
427
Jihoon Kang1453baa2023-05-27 05:32:30 +0000428func createFullApiLibraries(ctx android.LoadHookContext) {
429 javaLibraryNames := []string{
430 "android_stubs_current",
431 "android_system_stubs_current",
432 "android_test_stubs_current",
Mark Whitee35b1382023-08-12 01:31:26 +0000433 "android_test_frameworks_core_stubs_current",
Jihoon Kang1453baa2023-05-27 05:32:30 +0000434 "android_module_lib_stubs_current",
435 "android_system_server_stubs_current",
436 }
437
438 for _, libraryName := range javaLibraryNames {
439 props := libraryProps{}
440 props.Name = proptools.StringPtr(libraryName)
441 staticLib := libraryName + ".from-source"
442 if ctx.Config().BuildFromTextStub() {
443 staticLib = libraryName + ".from-text"
444 }
445 props.Static_libs = []string{staticLib}
446 props.Defaults = []string{"android.jar_defaults"}
447 props.Visibility = []string{"//visibility:public"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000448 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000449
450 ctx.CreateModule(java.LibraryFactory, &props)
451 }
452}
453
Jihoon Kang059b9492023-12-29 00:40:34 +0000454func createFullExportableApiLibraries(ctx android.LoadHookContext) {
455 javaLibraryNames := []string{
456 "android_stubs_current_exportable",
457 "android_system_stubs_current_exportable",
458 "android_test_stubs_current_exportable",
459 "android_module_lib_stubs_current_exportable",
460 "android_system_server_stubs_current_exportable",
461 }
462
463 for _, libraryName := range javaLibraryNames {
464 props := libraryProps{}
465 props.Name = proptools.StringPtr(libraryName)
466 staticLib := libraryName + ".from-source"
467 props.Static_libs = []string{staticLib}
468 props.Defaults = []string{"android.jar_defaults"}
469 props.Visibility = []string{"//visibility:public"}
Jihoon Kangdaa35302024-02-12 23:18:52 +0000470 props.Is_stubs_module = proptools.BoolPtr(true)
Jihoon Kang059b9492023-12-29 00:40:34 +0000471
472 ctx.CreateModule(java.LibraryFactory, &props)
473 }
474}
475
Anton Hansson0860aaf2021-10-08 16:48:03 +0100476func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
Anton Hansson07a12952022-01-12 17:28:39 +0000477 bootclasspath := a.properties.Bootclasspath
Cole Faustdcda3702022-10-04 14:46:35 -0700478 system_server_classpath := a.properties.System_server_classpath
Anton Hansson07a12952022-01-12 17:28:39 +0000479 if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") {
480 bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...)
481 sort.Strings(bootclasspath)
482 }
Jihoon Kang31cf2742024-02-07 19:52:19 +0000483 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-", "-", false)
484 createMergedTxts(ctx, bootclasspath, system_server_classpath, "non-updatable-exportable-", "-exportable-", true)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100485
Anton Hanssonc6e9d2f2022-01-25 15:53:43 +0000486 createMergedPublicStubs(ctx, bootclasspath)
487 createMergedSystemStubs(ctx, bootclasspath)
Nikita Ioffe5593fbb2022-12-01 14:52:34 +0000488 createMergedTestStubsForNonUpdatableModules(ctx)
Anton Hansson95e89a82022-01-28 11:31:50 +0000489 createMergedFrameworkModuleLibStubs(ctx, bootclasspath)
490 createMergedFrameworkImpl(ctx, bootclasspath)
Anton Hanssoncb00f942022-01-13 09:45:12 +0000491
Jihoon Kang059b9492023-12-29 00:40:34 +0000492 createMergedPublicExportableStubs(ctx, bootclasspath)
493 createMergedSystemExportableStubs(ctx, bootclasspath)
494 createMergedTestExportableStubsForNonUpdatableModules(ctx)
495 createMergedFrameworkModuleLibExportableStubs(ctx, bootclasspath)
496
Cole Faustdcda3702022-10-04 14:46:35 -0700497 createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath)
Anton Hanssoncc18e032022-01-12 14:45:22 +0000498
Anton Hansson4468d7c2022-01-14 12:10:01 +0000499 createPublicStubsSourceFilegroup(ctx, bootclasspath)
Jihoon Kang1e4ac1d2023-04-07 18:50:38 +0000500
501 createApiContributionDefaults(ctx, bootclasspath)
Jihoon Kang1453baa2023-05-27 05:32:30 +0000502
503 createFullApiLibraries(ctx)
Jihoon Kang059b9492023-12-29 00:40:34 +0000504
505 createFullExportableApiLibraries(ctx)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100506}
507
508func combinedApisModuleFactory() android.Module {
509 module := &CombinedApis{}
510 module.AddProperties(&module.properties)
511 android.InitAndroidModule(module)
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000512 android.InitDefaultableModule(module)
Anton Hansson0860aaf2021-10-08 16:48:03 +0100513 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
514 return module
515}
Anton Hanssonfd316452022-01-14 11:15:52 +0000516
517// Various utility methods below.
518
519// Creates an array of ":<m><tag>" for each m in <modules>.
520func createSrcs(modules []string, tag string) []string {
521 return transformArray(modules, ":", tag)
522}
523
524// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
525func transformArray(modules []string, prefix, suffix string) []string {
526 a := make([]string, 0, len(modules))
527 for _, module := range modules {
528 a = append(a, prefix+module+suffix)
529 }
530 return a
531}
532
533func removeAll(s []string, vs []string) []string {
534 for _, v := range vs {
535 s = remove(s, v)
536 }
537 return s
538}
539
540func remove(s []string, v string) []string {
541 s2 := make([]string, 0, len(s))
542 for _, sv := range s {
543 if sv != v {
544 s2 = append(s2, sv)
545 }
546 }
547 return s2
548}
Harshit Mahajanb52adbc2023-12-15 21:56:42 +0000549
550// Defaults
551type CombinedApisModuleDefaults struct {
552 android.ModuleBase
553 android.DefaultsModuleBase
554}
555
556func CombinedApisModuleDefaultsFactory() android.Module {
557 module := &CombinedApisModuleDefaults{}
558 module.AddProperties(&CombinedApisProperties{})
559 android.InitDefaultsModule(module)
560 return module
561}