blob: d794e511bd0a8620d71a7e1b94df8484539a3812 [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 (
18 "android/soong/android"
19 "android/soong/dexpreopt"
20)
21
22func init() {
23 registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext)
24}
25
26func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000027 ctx.RegisterParallelSingletonModuleType("platform_bootclasspath", platformBootclasspathFactory)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010028}
29
Paul Duffin01b463b2021-04-26 20:05:39 +010030// The tags used for the dependencies between the platform bootclasspath and any configured boot
31// jars.
32var (
satayevd604b212021-07-21 14:23:52 +010033 platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"}
34 platformBootclasspathBootJarDepTag = bootclasspathDependencyTag{name: "platform-boot-jar"}
35 platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag{name: "apex-boot-jar"}
Paul Duffin01b463b2021-04-26 20:05:39 +010036)
Paul Duffinb432df92021-03-22 22:09:42 +000037
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010038type platformBootclasspathModule struct {
Paul Duffine3ecce62021-04-29 10:34:11 +010039 android.SingletonModuleBase
Artur Satayev97259dc2021-04-07 15:17:14 +010040 ClasspathFragmentBase
Paul Duffinb432df92021-03-22 22:09:42 +000041
Paul Duffin62d8c3b2021-04-07 20:35:11 +010042 properties platformBootclasspathProperties
43
Paul Duffinb432df92021-03-22 22:09:42 +000044 // The apex:module pairs obtained from the configured modules.
Paul Duffinb432df92021-03-22 22:09:42 +000045 configuredModules []android.Module
Paul Duffin62d8c3b2021-04-07 20:35:11 +010046
47 // The apex:module pairs obtained from the fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +010048 fragments []android.Module
Paul Duffin6a766452021-04-12 14:15:22 +010049
50 // Path to the monolithic hiddenapi-flags.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010051 hiddenAPIFlagsCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010052
53 // Path to the monolithic hiddenapi-index.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010054 hiddenAPIIndexCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010055
56 // Path to the monolithic hiddenapi-unsupported.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010057 hiddenAPIMetadataCSV android.OutputPath
Paul Duffin62d8c3b2021-04-07 20:35:11 +010058}
59
Paul Duffin62d8c3b2021-04-07 20:35:11 +010060type platformBootclasspathProperties struct {
Paul Duffinb67d8782021-04-22 11:49:41 +010061 BootclasspathFragmentsDepsProperties
Paul Duffin702210b2021-04-08 20:12:41 +010062
Paul Duffin9b61abb2022-07-27 16:16:54 +000063 HiddenAPIFlagFileProperties
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010064}
65
Paul Duffine3ecce62021-04-29 10:34:11 +010066func platformBootclasspathFactory() android.SingletonModule {
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010067 m := &platformBootclasspathModule{}
Paul Duffin62d8c3b2021-04-07 20:35:11 +010068 m.AddProperties(&m.properties)
satayev95e9c5b2021-04-29 11:50:26 +010069 initClasspathFragment(m, BOOTCLASSPATH)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010070 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
71 return m
72}
73
Artur Satayev97259dc2021-04-07 15:17:14 +010074func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
75 entries = append(entries, android.AndroidMkEntries{
76 Class: "FAKE",
77 // Need at least one output file in order for this to take effect.
78 OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
79 Include: "$(BUILD_PHONY_PACKAGE)",
80 })
satayev128ce2f2021-05-06 13:21:15 +010081 entries = append(entries, b.classpathFragmentBase().androidMkEntries()...)
Artur Satayev97259dc2021-04-07 15:17:14 +010082 return
Paul Duffin6a766452021-04-12 14:15:22 +010083}
84
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010085func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Spandan Das64c9e0c2023-12-20 20:13:34 +000086 // Create a dependency on all_apex_contributions to determine the selected mainline module
87 ctx.AddDependency(ctx.Module(), apexContributionsMetadataDepTag, "all_apex_contributions")
88
Paul Duffin74431d52021-04-21 14:10:42 +010089 b.hiddenAPIDepsMutator(ctx)
90
Jiakai Zhangbc698cd2023-05-08 16:28:38 +000091 if !dexpreopt.IsDex2oatNeeded(ctx) {
Qiao Yang8d8c6602023-05-05 15:03:24 +000092 return
93 }
94
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010095 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
96 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
97 dexpreopt.RegisterToolDeps(ctx)
98}
99
Paul Duffin74431d52021-04-21 14:10:42 +0100100func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
Pratyushfaec4db2023-07-20 11:19:04 +0000101 if ctx.Config().DisableHiddenApiChecks() {
Paul Duffin74431d52021-04-21 14:10:42 +0100102 return
103 }
104
105 // Add dependencies onto the stub lib modules.
Paul Duffin31fad802021-06-18 18:14:25 +0100106 apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
107 hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules)
Paul Duffin74431d52021-04-21 14:10:42 +0100108}
109
Paul Duffin4994d262021-04-22 12:08:59 +0100110func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100111 // Add dependencies on all the ART jars.
112 global := dexpreopt.GetGlobalConfig(ctx)
Spandan Das64c9e0c2023-12-20 20:13:34 +0000113 addDependenciesOntoSelectedBootImageApexes(ctx, "com.android.art")
114 // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100115 addDependenciesOntoBootImageModules(ctx, global.ArtApexJars, platformBootclasspathArtBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000116
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100117 // Add dependencies on all the non-updatable jars, which are on the platform or in non-updatable
118 // APEXes.
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100119 addDependenciesOntoBootImageModules(ctx, b.platformJars(ctx), platformBootclasspathBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000120
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100121 // Add dependencies on all the updatable jars, except the ART jars.
satayevd604b212021-07-21 14:23:52 +0100122 apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
Spandan Das64c9e0c2023-12-20 20:13:34 +0000123 apexes := []string{}
124 for i := 0; i < apexJars.Len(); i++ {
125 apexes = append(apexes, apexJars.Apex(i))
126 }
127 addDependenciesOntoSelectedBootImageApexes(ctx, android.FirstUniqueStrings(apexes)...)
128 // TODO: b/308174306 - Remove the mechanism of depending on the java_sdk_library(_import) directly
satayevd604b212021-07-21 14:23:52 +0100129 addDependenciesOntoBootImageModules(ctx, apexJars, platformBootclasspathApexBootJarDepTag)
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100130
Paul Duffin4994d262021-04-22 12:08:59 +0100131 // Add dependencies on all the fragments.
132 b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
Paul Duffinb432df92021-03-22 22:09:42 +0000133}
134
Paul Duffin01b463b2021-04-26 20:05:39 +0100135func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) {
Paul Duffinb432df92021-03-22 22:09:42 +0000136 for i := 0; i < modules.Len(); i++ {
137 apex := modules.Apex(i)
138 name := modules.Jar(i)
139
Paul Duffin01b463b2021-04-26 20:05:39 +0100140 addDependencyOntoApexModulePair(ctx, apex, name, tag)
Paul Duffinb432df92021-03-22 22:09:42 +0000141 }
142}
143
Paul Duffine3ecce62021-04-29 10:34:11 +0100144// GenerateSingletonBuildActions does nothing and must never do anything.
145//
146// This module only implements android.SingletonModule so that it can implement
147// android.SingletonMakeVarsProvider.
148func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) {
149 // Keep empty
150}
151
152func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) {
Paul Duffin12d29b72021-04-29 13:50:01 +0100153 d.generateHiddenApiMakeVars(ctx)
Paul Duffine3ecce62021-04-29 10:34:11 +0100154}
155
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100156func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevd604b212021-07-21 14:23:52 +0100157 // Gather all the dependencies from the art, platform, and apex boot jars.
Paul Duffin01b463b2021-04-26 20:05:39 +0100158 artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag)
satayevd604b212021-07-21 14:23:52 +0100159 platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathBootJarDepTag)
160 apexModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathApexBootJarDepTag)
Paul Duffin01b463b2021-04-26 20:05:39 +0100161
162 // Concatenate them all, in order as they would appear on the bootclasspath.
163 var allModules []android.Module
164 allModules = append(allModules, artModules...)
satayevd604b212021-07-21 14:23:52 +0100165 allModules = append(allModules, platformModules...)
166 allModules = append(allModules, apexModules...)
Paul Duffin01b463b2021-04-26 20:05:39 +0100167 b.configuredModules = allModules
168
Anton Hansson57162c52023-09-20 13:41:30 +0000169 var transitiveSrcFiles android.Paths
170 for _, module := range allModules {
Colin Cross7727c7f2024-07-18 15:36:32 -0700171 if depInfo, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
172 if depInfo.TransitiveSrcFiles != nil {
173 transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...)
174 }
Anton Hansson57162c52023-09-20 13:41:30 +0000175 }
176 }
177 jarArgs := resourcePathsToJarArgs(transitiveSrcFiles)
178 jarArgs = append(jarArgs, "-srcjar") // Move srcfiles to the right package
mrziwang444762b2024-06-27 09:58:58 -0700179 srcjar := android.PathForModuleOut(ctx, ctx.ModuleName()+"-transitive.srcjar").OutputPath
180 TransformResourcesToJar(ctx, srcjar, jarArgs, transitiveSrcFiles)
Anton Hansson57162c52023-09-20 13:41:30 +0000181
Paul Duffin01b463b2021-04-26 20:05:39 +0100182 // Gather all the fragments dependencies.
Paul Duffin9bacf562021-04-28 21:16:02 +0100183 b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000184
Paul Duffinf23bc472021-04-27 12:42:20 +0100185 // Check the configuration of the boot modules.
186 // ART modules are checked by the art-bootclasspath-fragment.
satayevd604b212021-07-21 14:23:52 +0100187 b.checkPlatformModules(ctx, platformModules)
188 b.checkApexModules(ctx, apexModules)
Paul Duffinf23bc472021-04-27 12:42:20 +0100189
satayev013485b2021-05-06 23:38:10 +0100190 b.generateClasspathProtoBuildActions(ctx)
191
Paul Duffinc8ead412021-06-07 19:28:15 +0100192 bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
193 buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
mrziwang444762b2024-06-27 09:58:58 -0700194
195 ctx.SetOutputFiles(android.Paths{b.hiddenAPIFlagsCSV}, "hiddenapi-flags.csv")
196 ctx.SetOutputFiles(android.Paths{b.hiddenAPIIndexCSV}, "hiddenapi-index.csv")
197 ctx.SetOutputFiles(android.Paths{b.hiddenAPIMetadataCSV}, "hiddenapi-metadata.csv")
198 ctx.SetOutputFiles(android.Paths{srcjar}, ".srcjar")
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100199}
200
satayev013485b2021-05-06 23:38:10 +0100201// Generate classpaths.proto config
202func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +0100203 configuredJars := b.configuredJars(ctx)
satayev013485b2021-05-06 23:38:10 +0100204 // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
satayevb3090502021-06-15 17:49:10 +0100205 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
206 b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
Inseob Kimdd532492024-04-30 17:22:58 +0900207 b.classpathFragmentBase().installClasspathProto(ctx)
satayev013485b2021-05-06 23:38:10 +0100208}
209
satayev142ed272021-06-15 16:21:17 +0100210func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +0100211 // Include all non APEX jars
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100212 jars := b.platformJars(ctx)
satayevb3090502021-06-15 17:49:10 +0100213
214 // Include jars from APEXes that don't populate their classpath proto config.
satayevd604b212021-07-21 14:23:52 +0100215 remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
satayevb3090502021-06-15 17:49:10 +0100216 for _, fragment := range b.fragments {
Colin Cross313aa542023-12-13 13:47:44 -0800217 info, _ := android.OtherModuleProvider(ctx, fragment, ClasspathFragmentProtoContentInfoProvider)
satayevb3090502021-06-15 17:49:10 +0100218 if info.ClasspathFragmentProtoGenerated {
219 remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents)
220 }
221 }
222 for i := 0; i < remainingJars.Len(); i++ {
223 jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i))
224 }
225
226 return jars
satayev013485b2021-05-06 23:38:10 +0100227}
228
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100229func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList {
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100230 global := dexpreopt.GetGlobalConfig(ctx)
231 return global.BootJars.RemoveList(global.ArtApexJars)
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100232}
233
satayevd604b212021-07-21 14:23:52 +0100234// checkPlatformModules ensures that the non-updatable modules supplied are not part of an
235// apex module.
236func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) {
237 // TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here.
Paul Duffinf23bc472021-04-27 12:42:20 +0100238 for _, m := range modules {
Colin Cross313aa542023-12-13 13:47:44 -0800239 apexInfo, _ := android.OtherModuleProvider(ctx, m, android.ApexInfoProvider)
Paul Duffinf23bc472021-04-27 12:42:20 +0100240 fromUpdatableApex := apexInfo.Updatable
241 if fromUpdatableApex {
242 // error: this jar is part of an updatable apex
Jiakai Zhangc08c1622023-05-10 18:38:34 +0100243 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 +0100244 } else {
245 // ok: this jar is part of the platform or a non-updatable apex
246 }
247 }
248}
249
satayevd604b212021-07-21 14:23:52 +0100250// checkApexModules ensures that the apex modules supplied are not from the platform.
251func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext, modules []android.Module) {
Paul Duffinf23bc472021-04-27 12:42:20 +0100252 for _, m := range modules {
Colin Cross313aa542023-12-13 13:47:44 -0800253 apexInfo, _ := android.OtherModuleProvider(ctx, m, android.ApexInfoProvider)
Paul Duffinf23bc472021-04-27 12:42:20 +0100254 fromUpdatableApex := apexInfo.Updatable
255 if fromUpdatableApex {
256 // ok: this jar is part of an updatable apex
257 } else {
258 name := ctx.OtherModuleName(m)
259 if apexInfo.IsForPlatform() {
Paul Duffin7487a7a2021-05-19 09:36:09 +0100260 // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will
261 // include platform variants of a prebuilt module due to workarounds elsewhere. In that case
262 // do not treat this as an error.
263 // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment
264 // modules is complete.
265 if !ctx.Config().AlwaysUsePrebuiltSdks() {
266 // error: this jar is part of the platform
satayevd604b212021-07-21 14:23:52 +0100267 ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name)
Paul Duffin7487a7a2021-05-19 09:36:09 +0100268 }
Paul Duffinf23bc472021-04-27 12:42:20 +0100269 } else {
270 // TODO(b/177892522): Treat this as an error.
271 // Cannot do that at the moment because framework-wifi and framework-tethering are in the
satayevd604b212021-07-21 14:23:52 +0100272 // PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP.
Paul Duffinf23bc472021-04-27 12:42:20 +0100273 }
274 }
275 }
276}
277
Paul Duffin702210b2021-04-08 20:12:41 +0100278// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffinc8ead412021-06-07 19:28:15 +0100279func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
Spandan Dasa90db962024-05-20 18:37:17 +0000280 createEmptyHiddenApiFiles := func() {
281 paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
282 for _, path := range paths {
283 ctx.Build(pctx, android.BuildParams{
284 Rule: android.Touch,
285 Output: path,
286 })
287 }
288 }
Paul Duffin702210b2021-04-08 20:12:41 +0100289
Paul Duffin90b8ad32021-04-13 12:25:01 +0100290 // Save the paths to the monolithic files for retrieval via OutputFiles().
291 b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
292 b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
293 b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
Paul Duffin6a766452021-04-12 14:15:22 +0100294
Adrian Roose95a15e2021-06-21 16:03:11 +0200295 bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules)
296
Pratyushfaec4db2023-07-20 11:19:04 +0000297 // Don't run any hiddenapi rules if hidden api checks are disabled. This is a performance
Paul Duffin0b659862021-04-13 13:02:29 +0100298 // optimization that can be used to reduce the incremental build time but as its name suggests it
299 // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
Pratyushfaec4db2023-07-20 11:19:04 +0000300 if ctx.Config().DisableHiddenApiChecks() {
Spandan Dasa90db962024-05-20 18:37:17 +0000301 createEmptyHiddenApiFiles()
Adrian Roose95a15e2021-06-21 16:03:11 +0200302 return bootDexJarByModule
Paul Duffin0b659862021-04-13 13:02:29 +0100303 }
304
Paul Duffin89f570a2021-06-16 01:42:33 +0100305 // Construct a list of ClasspathElement objects from the modules and fragments.
306 classpathElements := CreateClasspathElements(ctx, modules, fragments)
307
308 monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements)
309
310 // Extract the classes jars only from those libraries that do not have corresponding fragments as
311 // the fragments will have already provided the flags that are needed.
312 classesJars := monolithicInfo.ClassesJars
313
Spandan Das81fe4d12024-05-15 18:43:47 +0000314 if len(classesJars) == 0 {
315 // This product does not include any monolithic jars. Monolithic hiddenapi flag generation is not required.
Spandan Dasa90db962024-05-20 18:37:17 +0000316 // However, generate an empty file so that the dist tags in f/b/boot/Android.bp can be resolved, and `m dist` works.
317 createEmptyHiddenApiFiles()
Spandan Das81fe4d12024-05-15 18:43:47 +0000318 return bootDexJarByModule
319 }
320
Paul Duffin4539a372021-06-23 23:20:43 +0100321 // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
Paul Duffin1352f7c2021-05-21 22:18:49 +0100322 input := newHiddenAPIFlagInput()
323
324 // Gather stub library information from the dependencies on modules provided by
325 // hiddenAPIComputeMonolithicStubLibModules.
326 input.gatherStubLibInfo(ctx, nil)
327
328 // Use the flag files from this module and all the fragments.
329 input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory
Paul Duffin74431d52021-04-21 14:10:42 +0100330
Paul Duffin537ea3d2021-05-14 10:38:00 +0100331 // Generate the monolithic stub-flags.csv file.
Paul Duffin537ea3d2021-05-14 10:38:00 +0100332 stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
Paul Duffin67b9d612021-07-21 17:38:47 +0100333 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 +0100334
Paul Duffin537ea3d2021-05-14 10:38:00 +0100335 // Generate the annotation-flags.csv file from all the module annotations.
Paul Duffind061d402021-06-07 21:36:01 +0100336 annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv")
337 buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100338
Paul Duffind061d402021-06-07 21:36:01 +0100339 // Generate the monolithic hiddenapi-flags.csv file.
340 //
341 // Use annotation flags generated directly from the classes jars as well as annotation flag files
342 // provided by prebuilts.
343 allAnnotationFlagFiles := android.Paths{annotationFlags}
344 allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100345 allFlags := hiddenAPISingletonPaths(ctx).flags
Paul Duffin67b9d612021-07-21 17:38:47 +0100346 buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.FlagSubsets, android.OptionalPath{})
Paul Duffin537ea3d2021-05-14 10:38:00 +0100347
348 // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations
349 // in the source code.
Paul Duffind061d402021-06-07 21:36:01 +0100350 intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv")
351 buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100352
Paul Duffind061d402021-06-07 21:36:01 +0100353 // Generate the monolithic hiddenapi-metadata.csv file.
354 //
355 // Use metadata files generated directly from the classes jars as well as metadata files provided
356 // by prebuilts.
357 //
358 // This has the side effect of ensuring that the output file uses | quotes just in case that is
359 // important for the tools that consume the metadata file.
360 allMetadataFlagFiles := android.Paths{intermediateMetadataCSV}
361 allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100362 metadataCSV := hiddenAPISingletonPaths(ctx).metadata
Paul Duffind061d402021-06-07 21:36:01 +0100363 b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100364
Paul Duffind061d402021-06-07 21:36:01 +0100365 // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the
366 // classes jars.
367 intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv")
368 buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV)
369
370 // Generate the monolithic hiddenapi-index.csv file.
371 //
372 // Use index files generated directly from the classes jars as well as index files provided
373 // by prebuilts.
374 allIndexFlagFiles := android.Paths{intermediateIndexCSV}
375 allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100376 indexCSV := hiddenAPISingletonPaths(ctx).index
Paul Duffind061d402021-06-07 21:36:01 +0100377 b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV)
Paul Duffinc8ead412021-06-07 19:28:15 +0100378
379 return bootDexJarByModule
Paul Duffin74431d52021-04-21 14:10:42 +0100380}
381
Paul Duffin438eb572021-05-21 16:58:23 +0100382// createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for
383// testing.
Paul Duffin89f570a2021-06-16 01:42:33 +0100384func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo {
Paul Duffin1352f7c2021-05-21 22:18:49 +0100385 // Create a temporary input structure in which to collate information provided directly by this
386 // module, either through properties or direct dependencies.
387 temporaryInput := newHiddenAPIFlagInput()
388
389 // Create paths to the flag files specified in the properties.
Paul Duffin9b61abb2022-07-27 16:16:54 +0000390 temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties)
Paul Duffin1352f7c2021-05-21 22:18:49 +0100391
392 // Create the monolithic info, by starting with the flag files specified on this and then merging
393 // in information from all the fragment dependencies of this.
Paul Duffin89f570a2021-06-16 01:42:33 +0100394 monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements)
Paul Duffin438eb572021-05-21 16:58:23 +0100395
396 // Store the information for testing.
Colin Cross40213022023-12-13 15:19:49 -0800397 android.SetProvider(ctx, MonolithicHiddenAPIInfoProvider, monolithicInfo)
Paul Duffin438eb572021-05-21 16:58:23 +0100398 return monolithicInfo
399}
400
Paul Duffin537ea3d2021-05-14 10:38:00 +0100401func (b *platformBootclasspathModule) buildRuleMergeCSV(ctx android.ModuleContext, desc string, inputPaths android.Paths, outputPath android.WritablePath) {
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100402 rule := android.NewRuleBuilder(pctx, ctx)
403 rule.Command().
404 BuiltTool("merge_csv").
405 Flag("--key_field signature").
Paul Duffin85dee5d2021-04-13 00:14:38 +0100406 FlagWithOutput("--output=", outputPath).
Paul Duffin537ea3d2021-05-14 10:38:00 +0100407 Inputs(inputPaths)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100408
Paul Duffin537ea3d2021-05-14 10:38:00 +0100409 rule.Build(desc, desc)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100410}
Paul Duffinad19d382021-04-26 16:44:00 +0100411
Paul Duffin12d29b72021-04-29 13:50:01 +0100412// generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g.
413// veridex and run-appcompat.
414func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) {
415 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
416 return
417 }
418 // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
419 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String())
420}