blob: 3b05b16e3cc93d0d3607709ae3526c4df9a6c005 [file] [log] [blame]
Paul Duffinbb7f1ac2021-03-29 22:18:45 +01001// Copyright 2021 Google Inc. All rights reserved.
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 java
16
17import (
Colin Crossc5f4de52025-01-09 16:04:41 -080018 "github.com/google/blueprint"
19
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010020 "android/soong/android"
21 "android/soong/dexpreopt"
22)
23
24func init() {
25 registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext)
26}
27
28func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) {
Cole Faust4bc45d82024-11-04 15:56:34 -080029 ctx.RegisterModuleType("platform_bootclasspath", platformBootclasspathFactory)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010030}
31
Paul Duffin01b463b2021-04-26 20:05:39 +010032// The tags used for the dependencies between the platform bootclasspath and any configured boot
33// jars.
Colin Crossc5f4de52025-01-09 16:04:41 -080034type platformBootclasspathImplLibDepTagType struct {
35 blueprint.BaseDependencyTag
36}
37
38func (p platformBootclasspathImplLibDepTagType) ExcludeFromVisibilityEnforcement() {}
39
40var platformBootclasspathImplLibDepTag platformBootclasspathImplLibDepTagType
41
42var _ android.ExcludeFromVisibilityEnforcementTag = platformBootclasspathImplLibDepTag
43
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010044type platformBootclasspathModule struct {
Cole Faust4bc45d82024-11-04 15:56:34 -080045 android.ModuleBase
Artur Satayev97259dc2021-04-07 15:17:14 +010046 ClasspathFragmentBase
Paul Duffinb432df92021-03-22 22:09:42 +000047
Paul Duffin62d8c3b2021-04-07 20:35:11 +010048 properties platformBootclasspathProperties
49
Paul Duffinb432df92021-03-22 22:09:42 +000050 // The apex:module pairs obtained from the configured modules.
Paul Duffinb432df92021-03-22 22:09:42 +000051 configuredModules []android.Module
Paul Duffin62d8c3b2021-04-07 20:35:11 +010052
53 // The apex:module pairs obtained from the fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +010054 fragments []android.Module
Paul Duffin6a766452021-04-12 14:15:22 +010055
56 // Path to the monolithic hiddenapi-flags.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010057 hiddenAPIFlagsCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010058
59 // Path to the monolithic hiddenapi-index.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010060 hiddenAPIIndexCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010061
62 // Path to the monolithic hiddenapi-unsupported.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010063 hiddenAPIMetadataCSV android.OutputPath
Paul Duffin62d8c3b2021-04-07 20:35:11 +010064}
65
Paul Duffin62d8c3b2021-04-07 20:35:11 +010066type platformBootclasspathProperties struct {
Paul Duffinb67d8782021-04-22 11:49:41 +010067 BootclasspathFragmentsDepsProperties
Paul Duffin702210b2021-04-08 20:12:41 +010068
Paul Duffin9b61abb2022-07-27 16:16:54 +000069 HiddenAPIFlagFileProperties
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010070}
71
Cole Faust4bc45d82024-11-04 15:56:34 -080072func platformBootclasspathFactory() android.Module {
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010073 m := &platformBootclasspathModule{}
Paul Duffin62d8c3b2021-04-07 20:35:11 +010074 m.AddProperties(&m.properties)
satayev95e9c5b2021-04-29 11:50:26 +010075 initClasspathFragment(m, BOOTCLASSPATH)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010076 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
77 return m
78}
79
Artur Satayev97259dc2021-04-07 15:17:14 +010080func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
81 entries = append(entries, android.AndroidMkEntries{
82 Class: "FAKE",
83 // Need at least one output file in order for this to take effect.
84 OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
85 Include: "$(BUILD_PHONY_PACKAGE)",
86 })
satayev128ce2f2021-05-06 13:21:15 +010087 entries = append(entries, b.classpathFragmentBase().androidMkEntries()...)
Artur Satayev97259dc2021-04-07 15:17:14 +010088 return
Paul Duffin6a766452021-04-12 14:15:22 +010089}
90
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010091func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Spandan Das64c9e0c2023-12-20 20:13:34 +000092 // Create a dependency on all_apex_contributions to determine the selected mainline module
93 ctx.AddDependency(ctx.Module(), apexContributionsMetadataDepTag, "all_apex_contributions")
94
Paul Duffin74431d52021-04-21 14:10:42 +010095 b.hiddenAPIDepsMutator(ctx)
96
Colin Crossd8d8b852024-12-20 16:32:37 -080097 if dexpreopt.IsDex2oatNeeded(ctx) {
98 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
99 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
100 dexpreopt.RegisterToolDeps(ctx)
Qiao Yang8d8c6602023-05-05 15:03:24 +0000101 }
102
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100103 // Add dependencies on all the ART jars.
104 global := dexpreopt.GetGlobalConfig(ctx)
Spandan Das64c9e0c2023-12-20 20:13:34 +0000105 addDependenciesOntoSelectedBootImageApexes(ctx, "com.android.art")
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000106
107 var bootImageModuleNames []string
108
Spandan Das64c9e0c2023-12-20 20:13:34 +0000109 // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
Colin Crossd8d8b852024-12-20 16:32:37 -0800110 addDependenciesOntoBootImageModules(ctx, global.ArtApexJars, artBootJar)
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000111 bootImageModuleNames = append(bootImageModuleNames, global.ArtApexJars.CopyOfJars()...)
Paul Duffinb432df92021-03-22 22:09:42 +0000112
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100113 // Add dependencies on all the non-updatable jars, which are on the platform or in non-updatable
114 // APEXes.
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000115 platformJars := b.platformJars(ctx)
Colin Crossd8d8b852024-12-20 16:32:37 -0800116 addDependenciesOntoBootImageModules(ctx, platformJars, platformBootJar)
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000117 bootImageModuleNames = append(bootImageModuleNames, platformJars.CopyOfJars()...)
Paul Duffinb432df92021-03-22 22:09:42 +0000118
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100119 // Add dependencies on all the updatable jars, except the ART jars.
satayevd604b212021-07-21 14:23:52 +0100120 apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
Spandan Das64c9e0c2023-12-20 20:13:34 +0000121 apexes := []string{}
122 for i := 0; i < apexJars.Len(); i++ {
123 apexes = append(apexes, apexJars.Apex(i))
124 }
125 addDependenciesOntoSelectedBootImageApexes(ctx, android.FirstUniqueStrings(apexes)...)
126 // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
Colin Crossd8d8b852024-12-20 16:32:37 -0800127 addDependenciesOntoBootImageModules(ctx, apexJars, apexBootJar)
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000128 bootImageModuleNames = append(bootImageModuleNames, apexJars.CopyOfJars()...)
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100129
Paul Duffin4994d262021-04-22 12:08:59 +0100130 // Add dependencies on all the fragments.
131 b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000132
133 for _, bootImageModuleName := range bootImageModuleNames {
134 implLibName := implLibraryModuleName(bootImageModuleName)
135 if ctx.OtherModuleExists(implLibName) {
136 ctx.AddFarVariationDependencies(nil, platformBootclasspathImplLibDepTag, implLibName)
137 }
138 }
Paul Duffinb432df92021-03-22 22:09:42 +0000139}
140
Colin Crossd8d8b852024-12-20 16:32:37 -0800141func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
142 if ctx.Config().DisableHiddenApiChecks() {
143 return
144 }
145
146 // Add dependencies onto the stub lib modules.
147 apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
148 hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules)
149}
150
151func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tagType bootclasspathDependencyTagType) {
Paul Duffinb432df92021-03-22 22:09:42 +0000152 for i := 0; i < modules.Len(); i++ {
153 apex := modules.Apex(i)
154 name := modules.Jar(i)
155
Colin Crossd8d8b852024-12-20 16:32:37 -0800156 addDependencyOntoApexModulePair(ctx, apex, name, tagType)
Paul Duffinb432df92021-03-22 22:09:42 +0000157 }
158}
159
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100160func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevd604b212021-07-21 14:23:52 +0100161 // Gather all the dependencies from the art, platform, and apex boot jars.
Colin Crossd8d8b852024-12-20 16:32:37 -0800162 artModules := gatherApexModulePairDepsWithTag(ctx, artBootJar)
163 platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootJar)
164 apexModules := gatherApexModulePairDepsWithTag(ctx, apexBootJar)
Paul Duffin01b463b2021-04-26 20:05:39 +0100165
166 // Concatenate them all, in order as they would appear on the bootclasspath.
167 var allModules []android.Module
168 allModules = append(allModules, artModules...)
satayevd604b212021-07-21 14:23:52 +0100169 allModules = append(allModules, platformModules...)
170 allModules = append(allModules, apexModules...)
Paul Duffin01b463b2021-04-26 20:05:39 +0100171 b.configuredModules = allModules
172
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000173 // Do not add implLibModule to allModules as the impl lib is only used to collect the
174 // transitive source files
175 var implLibModule []android.Module
Jihoon Kang2b133702025-01-09 07:54:41 +0000176 ctx.VisitDirectDepsWithTag(platformBootclasspathImplLibDepTag, func(m android.Module) {
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000177 implLibModule = append(implLibModule, m)
178 })
179
Anton Hansson57162c52023-09-20 13:41:30 +0000180 var transitiveSrcFiles android.Paths
Jihoon Kanga6d0aa82024-09-24 00:34:49 +0000181 for _, module := range append(allModules, implLibModule...) {
Colin Cross7727c7f2024-07-18 15:36:32 -0700182 if depInfo, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
Colin Crossa14fb6a2024-10-23 16:57:06 -0700183 transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
Anton Hansson57162c52023-09-20 13:41:30 +0000184 }
185 }
186 jarArgs := resourcePathsToJarArgs(transitiveSrcFiles)
187 jarArgs = append(jarArgs, "-srcjar") // Move srcfiles to the right package
Cole Faust4e9f5922024-11-13 16:09:23 -0800188 srcjar := android.PathForModuleOut(ctx, ctx.ModuleName()+"-transitive.srcjar")
mrziwang444762b2024-06-27 09:58:58 -0700189 TransformResourcesToJar(ctx, srcjar, jarArgs, transitiveSrcFiles)
Anton Hansson57162c52023-09-20 13:41:30 +0000190
Paul Duffin01b463b2021-04-26 20:05:39 +0100191 // Gather all the fragments dependencies.
Colin Crossd8d8b852024-12-20 16:32:37 -0800192 b.fragments = gatherApexModulePairDepsWithTag(ctx, fragment)
Paul Duffinb432df92021-03-22 22:09:42 +0000193
Paul Duffinf23bc472021-04-27 12:42:20 +0100194 // Check the configuration of the boot modules.
195 // ART modules are checked by the art-bootclasspath-fragment.
satayevd604b212021-07-21 14:23:52 +0100196 b.checkPlatformModules(ctx, platformModules)
197 b.checkApexModules(ctx, apexModules)
Paul Duffinf23bc472021-04-27 12:42:20 +0100198
satayev013485b2021-05-06 23:38:10 +0100199 b.generateClasspathProtoBuildActions(ctx)
200
Paul Duffinc8ead412021-06-07 19:28:15 +0100201 bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
202 buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
mrziwang444762b2024-06-27 09:58:58 -0700203
204 ctx.SetOutputFiles(android.Paths{b.hiddenAPIFlagsCSV}, "hiddenapi-flags.csv")
205 ctx.SetOutputFiles(android.Paths{b.hiddenAPIIndexCSV}, "hiddenapi-index.csv")
206 ctx.SetOutputFiles(android.Paths{b.hiddenAPIMetadataCSV}, "hiddenapi-metadata.csv")
207 ctx.SetOutputFiles(android.Paths{srcjar}, ".srcjar")
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100208}
209
satayev013485b2021-05-06 23:38:10 +0100210// Generate classpaths.proto config
211func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +0100212 configuredJars := b.configuredJars(ctx)
satayev013485b2021-05-06 23:38:10 +0100213 // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
satayevb3090502021-06-15 17:49:10 +0100214 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
215 b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
Inseob Kimdd532492024-04-30 17:22:58 +0900216 b.classpathFragmentBase().installClasspathProto(ctx)
satayev013485b2021-05-06 23:38:10 +0100217}
218
satayev142ed272021-06-15 16:21:17 +0100219func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +0100220 // Include all non APEX jars
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100221 jars := b.platformJars(ctx)
satayevb3090502021-06-15 17:49:10 +0100222
223 // Include jars from APEXes that don't populate their classpath proto config.
satayevd604b212021-07-21 14:23:52 +0100224 remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
satayevb3090502021-06-15 17:49:10 +0100225 for _, fragment := range b.fragments {
Colin Cross313aa542023-12-13 13:47:44 -0800226 info, _ := android.OtherModuleProvider(ctx, fragment, ClasspathFragmentProtoContentInfoProvider)
satayevb3090502021-06-15 17:49:10 +0100227 if info.ClasspathFragmentProtoGenerated {
228 remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents)
229 }
230 }
231 for i := 0; i < remainingJars.Len(); i++ {
232 jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i))
233 }
234
235 return jars
satayev013485b2021-05-06 23:38:10 +0100236}
237
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100238func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList {
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100239 global := dexpreopt.GetGlobalConfig(ctx)
240 return global.BootJars.RemoveList(global.ArtApexJars)
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100241}
242
satayevd604b212021-07-21 14:23:52 +0100243// checkPlatformModules ensures that the non-updatable modules supplied are not part of an
244// apex module.
245func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) {
246 // TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here.
Paul Duffinf23bc472021-04-27 12:42:20 +0100247 for _, m := range modules {
Colin Cross313aa542023-12-13 13:47:44 -0800248 apexInfo, _ := android.OtherModuleProvider(ctx, m, android.ApexInfoProvider)
Paul Duffinf23bc472021-04-27 12:42:20 +0100249 fromUpdatableApex := apexInfo.Updatable
250 if fromUpdatableApex {
251 // error: this jar is part of an updatable apex
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100252 ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants)
Paul Duffinf23bc472021-04-27 12:42:20 +0100253 } else {
254 // ok: this jar is part of the platform or a non-updatable apex
255 }
256 }
257}
258
satayevd604b212021-07-21 14:23:52 +0100259// checkApexModules ensures that the apex modules supplied are not from the platform.
260func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext, modules []android.Module) {
Paul Duffinf23bc472021-04-27 12:42:20 +0100261 for _, m := range modules {
Colin Cross313aa542023-12-13 13:47:44 -0800262 apexInfo, _ := android.OtherModuleProvider(ctx, m, android.ApexInfoProvider)
Paul Duffinf23bc472021-04-27 12:42:20 +0100263 fromUpdatableApex := apexInfo.Updatable
264 if fromUpdatableApex {
265 // ok: this jar is part of an updatable apex
266 } else {
267 name := ctx.OtherModuleName(m)
268 if apexInfo.IsForPlatform() {
Paul Duffin7487a7a2021-05-19 09:36:09 +0100269 // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will
270 // include platform variants of a prebuilt module due to workarounds elsewhere. In that case
271 // do not treat this as an error.
272 // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment
273 // modules is complete.
274 if !ctx.Config().AlwaysUsePrebuiltSdks() {
275 // error: this jar is part of the platform
Colin Crossd8d8b852024-12-20 16:32:37 -0800276 if ctx.Config().AllowMissingDependencies() {
277 ctx.AddMissingDependencies([]string{"module_" + name + "_from_platform_is_not_allowed_in_the_apex_boot_jars_list"})
278 } else {
279 ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name)
280 }
Paul Duffin7487a7a2021-05-19 09:36:09 +0100281 }
Paul Duffinf23bc472021-04-27 12:42:20 +0100282 } else {
283 // TODO(b/177892522): Treat this as an error.
284 // Cannot do that at the moment because framework-wifi and framework-tethering are in the
satayevd604b212021-07-21 14:23:52 +0100285 // PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP.
Paul Duffinf23bc472021-04-27 12:42:20 +0100286 }
287 }
288 }
289}
290
Paul Duffin702210b2021-04-08 20:12:41 +0100291// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffinc8ead412021-06-07 19:28:15 +0100292func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
Spandan Dasa90db962024-05-20 18:37:17 +0000293 createEmptyHiddenApiFiles := func() {
294 paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
295 for _, path := range paths {
296 ctx.Build(pctx, android.BuildParams{
297 Rule: android.Touch,
298 Output: path,
299 })
300 }
301 }
Paul Duffin702210b2021-04-08 20:12:41 +0100302
Paul Duffin90b8ad32021-04-13 12:25:01 +0100303 // Save the paths to the monolithic files for retrieval via OutputFiles().
304 b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
305 b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
306 b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
Paul Duffin6a766452021-04-12 14:15:22 +0100307
Adrian Roose95a15e2021-06-21 16:03:11 +0200308 bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules)
309
Pratyushfaec4db2023-07-20 11:19:04 +0000310 // Don't run any hiddenapi rules if hidden api checks are disabled. This is a performance
Paul Duffin0b659862021-04-13 13:02:29 +0100311 // optimization that can be used to reduce the incremental build time but as its name suggests it
312 // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
Pratyushfaec4db2023-07-20 11:19:04 +0000313 if ctx.Config().DisableHiddenApiChecks() {
Spandan Dasa90db962024-05-20 18:37:17 +0000314 createEmptyHiddenApiFiles()
Adrian Roose95a15e2021-06-21 16:03:11 +0200315 return bootDexJarByModule
Paul Duffin0b659862021-04-13 13:02:29 +0100316 }
317
Paul Duffin89f570a2021-06-16 01:42:33 +0100318 // Construct a list of ClasspathElement objects from the modules and fragments.
319 classpathElements := CreateClasspathElements(ctx, modules, fragments)
320
321 monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements)
322
323 // Extract the classes jars only from those libraries that do not have corresponding fragments as
324 // the fragments will have already provided the flags that are needed.
325 classesJars := monolithicInfo.ClassesJars
326
Spandan Das81fe4d12024-05-15 18:43:47 +0000327 if len(classesJars) == 0 {
328 // This product does not include any monolithic jars. Monolithic hiddenapi flag generation is not required.
Spandan Dasa90db962024-05-20 18:37:17 +0000329 // However, generate an empty file so that the dist tags in f/b/boot/Android.bp can be resolved, and `m dist` works.
330 createEmptyHiddenApiFiles()
Spandan Das81fe4d12024-05-15 18:43:47 +0000331 return bootDexJarByModule
332 }
333
Paul Duffin4539a372021-06-23 23:20:43 +0100334 // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
Paul Duffin1352f7c2021-05-21 22:18:49 +0100335 input := newHiddenAPIFlagInput()
336
337 // Gather stub library information from the dependencies on modules provided by
338 // hiddenAPIComputeMonolithicStubLibModules.
339 input.gatherStubLibInfo(ctx, nil)
340
341 // Use the flag files from this module and all the fragments.
342 input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory
Paul Duffin74431d52021-04-21 14:10:42 +0100343
Paul Duffin537ea3d2021-05-14 10:38:00 +0100344 // Generate the monolithic stub-flags.csv file.
Paul Duffin537ea3d2021-05-14 10:38:00 +0100345 stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
Paul Duffin67b9d612021-07-21 17:38:47 +0100346 buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags", stubFlags, bootDexJarByModule.bootDexJars(), input, monolithicInfo.StubFlagSubsets)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100347
Paul Duffin537ea3d2021-05-14 10:38:00 +0100348 // Generate the annotation-flags.csv file from all the module annotations.
Paul Duffind061d402021-06-07 21:36:01 +0100349 annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv")
350 buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100351
Paul Duffind061d402021-06-07 21:36:01 +0100352 // Generate the monolithic hiddenapi-flags.csv file.
353 //
354 // Use annotation flags generated directly from the classes jars as well as annotation flag files
355 // provided by prebuilts.
356 allAnnotationFlagFiles := android.Paths{annotationFlags}
357 allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100358 allFlags := hiddenAPISingletonPaths(ctx).flags
Paul Duffin67b9d612021-07-21 17:38:47 +0100359 buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.FlagSubsets, android.OptionalPath{})
Paul Duffin537ea3d2021-05-14 10:38:00 +0100360
361 // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations
362 // in the source code.
Paul Duffind061d402021-06-07 21:36:01 +0100363 intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv")
364 buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100365
Paul Duffind061d402021-06-07 21:36:01 +0100366 // Generate the monolithic hiddenapi-metadata.csv file.
367 //
368 // Use metadata files generated directly from the classes jars as well as metadata files provided
369 // by prebuilts.
370 //
371 // This has the side effect of ensuring that the output file uses | quotes just in case that is
372 // important for the tools that consume the metadata file.
373 allMetadataFlagFiles := android.Paths{intermediateMetadataCSV}
374 allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100375 metadataCSV := hiddenAPISingletonPaths(ctx).metadata
Paul Duffind061d402021-06-07 21:36:01 +0100376 b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100377
Paul Duffind061d402021-06-07 21:36:01 +0100378 // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the
379 // classes jars.
380 intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv")
381 buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV)
382
383 // Generate the monolithic hiddenapi-index.csv file.
384 //
385 // Use index files generated directly from the classes jars as well as index files provided
386 // by prebuilts.
387 allIndexFlagFiles := android.Paths{intermediateIndexCSV}
388 allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100389 indexCSV := hiddenAPISingletonPaths(ctx).index
Paul Duffind061d402021-06-07 21:36:01 +0100390 b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV)
Paul Duffinc8ead412021-06-07 19:28:15 +0100391
392 return bootDexJarByModule
Paul Duffin74431d52021-04-21 14:10:42 +0100393}
394
Paul Duffin438eb572021-05-21 16:58:23 +0100395// createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for
396// testing.
Paul Duffin89f570a2021-06-16 01:42:33 +0100397func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo {
Paul Duffin1352f7c2021-05-21 22:18:49 +0100398 // Create a temporary input structure in which to collate information provided directly by this
399 // module, either through properties or direct dependencies.
400 temporaryInput := newHiddenAPIFlagInput()
401
402 // Create paths to the flag files specified in the properties.
Paul Duffin9b61abb2022-07-27 16:16:54 +0000403 temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties)
Paul Duffin1352f7c2021-05-21 22:18:49 +0100404
405 // Create the monolithic info, by starting with the flag files specified on this and then merging
406 // in information from all the fragment dependencies of this.
Paul Duffin89f570a2021-06-16 01:42:33 +0100407 monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements)
Paul Duffin438eb572021-05-21 16:58:23 +0100408
409 // Store the information for testing.
Colin Cross40213022023-12-13 15:19:49 -0800410 android.SetProvider(ctx, MonolithicHiddenAPIInfoProvider, monolithicInfo)
Paul Duffin438eb572021-05-21 16:58:23 +0100411 return monolithicInfo
412}
413
Paul Duffin537ea3d2021-05-14 10:38:00 +0100414func (b *platformBootclasspathModule) buildRuleMergeCSV(ctx android.ModuleContext, desc string, inputPaths android.Paths, outputPath android.WritablePath) {
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100415 rule := android.NewRuleBuilder(pctx, ctx)
416 rule.Command().
417 BuiltTool("merge_csv").
418 Flag("--key_field signature").
Paul Duffin85dee5d2021-04-13 00:14:38 +0100419 FlagWithOutput("--output=", outputPath).
Paul Duffin537ea3d2021-05-14 10:38:00 +0100420 Inputs(inputPaths)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100421
Paul Duffin537ea3d2021-05-14 10:38:00 +0100422 rule.Build(desc, desc)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100423}