blob: 36baf7e78c5e1fe15ed49bfac7691f60da5079c1 [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 (
Paul Duffin6a766452021-04-12 14:15:22 +010018 "fmt"
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) {
Paul Duffine3ecce62021-04-29 10:34:11 +010029 ctx.RegisterSingletonModuleType("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.
34var (
satayevd604b212021-07-21 14:23:52 +010035 platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"}
36 platformBootclasspathBootJarDepTag = bootclasspathDependencyTag{name: "platform-boot-jar"}
37 platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag{name: "apex-boot-jar"}
Paul Duffin01b463b2021-04-26 20:05:39 +010038)
Paul Duffinb432df92021-03-22 22:09:42 +000039
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010040type platformBootclasspathModule struct {
Paul Duffine3ecce62021-04-29 10:34:11 +010041 android.SingletonModuleBase
Artur Satayev97259dc2021-04-07 15:17:14 +010042 ClasspathFragmentBase
Paul Duffinb432df92021-03-22 22:09:42 +000043
Paul Duffin62d8c3b2021-04-07 20:35:11 +010044 properties platformBootclasspathProperties
45
Paul Duffinb432df92021-03-22 22:09:42 +000046 // The apex:module pairs obtained from the configured modules.
Paul Duffinb432df92021-03-22 22:09:42 +000047 configuredModules []android.Module
Paul Duffin62d8c3b2021-04-07 20:35:11 +010048
49 // The apex:module pairs obtained from the fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +010050 fragments []android.Module
Paul Duffin6a766452021-04-12 14:15:22 +010051
52 // Path to the monolithic hiddenapi-flags.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010053 hiddenAPIFlagsCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010054
55 // Path to the monolithic hiddenapi-index.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010056 hiddenAPIIndexCSV android.OutputPath
Paul Duffin6a766452021-04-12 14:15:22 +010057
58 // Path to the monolithic hiddenapi-unsupported.csv file.
Paul Duffin0b659862021-04-13 13:02:29 +010059 hiddenAPIMetadataCSV android.OutputPath
Paul Duffin62d8c3b2021-04-07 20:35:11 +010060}
61
Paul Duffin62d8c3b2021-04-07 20:35:11 +010062type platformBootclasspathProperties struct {
Paul Duffinb67d8782021-04-22 11:49:41 +010063 BootclasspathFragmentsDepsProperties
Paul Duffin702210b2021-04-08 20:12:41 +010064
Paul Duffin46169772021-04-14 15:01:56 +010065 Hidden_api HiddenAPIFlagFileProperties
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010066}
67
Paul Duffine3ecce62021-04-29 10:34:11 +010068func platformBootclasspathFactory() android.SingletonModule {
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010069 m := &platformBootclasspathModule{}
Paul Duffin62d8c3b2021-04-07 20:35:11 +010070 m.AddProperties(&m.properties)
satayev95e9c5b2021-04-29 11:50:26 +010071 // TODO(satayev): split apex jars into separate configs.
72 initClasspathFragment(m, BOOTCLASSPATH)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010073 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
74 return m
75}
76
Paul Duffin6a766452021-04-12 14:15:22 +010077var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil)
78
Artur Satayev97259dc2021-04-07 15:17:14 +010079func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
80 entries = append(entries, android.AndroidMkEntries{
81 Class: "FAKE",
82 // Need at least one output file in order for this to take effect.
83 OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
84 Include: "$(BUILD_PHONY_PACKAGE)",
85 })
satayev128ce2f2021-05-06 13:21:15 +010086 entries = append(entries, b.classpathFragmentBase().androidMkEntries()...)
Artur Satayev97259dc2021-04-07 15:17:14 +010087 return
Paul Duffin6a766452021-04-12 14:15:22 +010088}
89
90// Make the hidden API files available from the platform-bootclasspath module.
91func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) {
92 switch tag {
93 case "hiddenapi-flags.csv":
94 return android.Paths{b.hiddenAPIFlagsCSV}, nil
95 case "hiddenapi-index.csv":
96 return android.Paths{b.hiddenAPIIndexCSV}, nil
97 case "hiddenapi-metadata.csv":
98 return android.Paths{b.hiddenAPIMetadataCSV}, nil
99 }
100
101 return nil, fmt.Errorf("unknown tag %s", tag)
102}
103
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100104func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin74431d52021-04-21 14:10:42 +0100105 b.hiddenAPIDepsMutator(ctx)
106
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100107 if SkipDexpreoptBootJars(ctx) {
108 return
109 }
110
111 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
112 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
113 dexpreopt.RegisterToolDeps(ctx)
114}
115
Paul Duffin74431d52021-04-21 14:10:42 +0100116func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
117 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
118 return
119 }
120
121 // Add dependencies onto the stub lib modules.
Paul Duffin31fad802021-06-18 18:14:25 +0100122 apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
123 hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules)
Paul Duffin74431d52021-04-21 14:10:42 +0100124}
125
Paul Duffin4994d262021-04-22 12:08:59 +0100126func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
127 // Add dependencies on all the modules configured in the "art" boot image.
128 artImageConfig := genBootImageConfigs(ctx)[artBootImageName]
Paul Duffin01b463b2021-04-26 20:05:39 +0100129 addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000130
Paul Duffin01b463b2021-04-26 20:05:39 +0100131 // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does
132 // not include modules configured in the "art" boot image.
Paul Duffin4994d262021-04-22 12:08:59 +0100133 bootImageConfig := b.getImageConfig(ctx)
satayevd604b212021-07-21 14:23:52 +0100134 addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000135
satayevd604b212021-07-21 14:23:52 +0100136 // Add dependencies on all the apex jars.
137 apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
138 addDependenciesOntoBootImageModules(ctx, apexJars, platformBootclasspathApexBootJarDepTag)
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100139
Paul Duffin4994d262021-04-22 12:08:59 +0100140 // Add dependencies on all the fragments.
141 b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
Paul Duffinb432df92021-03-22 22:09:42 +0000142}
143
Paul Duffin01b463b2021-04-26 20:05:39 +0100144func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) {
Paul Duffinb432df92021-03-22 22:09:42 +0000145 for i := 0; i < modules.Len(); i++ {
146 apex := modules.Apex(i)
147 name := modules.Jar(i)
148
Paul Duffin01b463b2021-04-26 20:05:39 +0100149 addDependencyOntoApexModulePair(ctx, apex, name, tag)
Paul Duffinb432df92021-03-22 22:09:42 +0000150 }
151}
152
Paul Duffine3ecce62021-04-29 10:34:11 +0100153// GenerateSingletonBuildActions does nothing and must never do anything.
154//
155// This module only implements android.SingletonModule so that it can implement
156// android.SingletonMakeVarsProvider.
157func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) {
158 // Keep empty
159}
160
161func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) {
Paul Duffin12d29b72021-04-29 13:50:01 +0100162 d.generateHiddenApiMakeVars(ctx)
Paul Duffine3ecce62021-04-29 10:34:11 +0100163}
164
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100165func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevd604b212021-07-21 14:23:52 +0100166 // Gather all the dependencies from the art, platform, and apex boot jars.
Paul Duffin01b463b2021-04-26 20:05:39 +0100167 artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag)
satayevd604b212021-07-21 14:23:52 +0100168 platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathBootJarDepTag)
169 apexModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathApexBootJarDepTag)
Paul Duffin01b463b2021-04-26 20:05:39 +0100170
171 // Concatenate them all, in order as they would appear on the bootclasspath.
172 var allModules []android.Module
173 allModules = append(allModules, artModules...)
satayevd604b212021-07-21 14:23:52 +0100174 allModules = append(allModules, platformModules...)
175 allModules = append(allModules, apexModules...)
Paul Duffin01b463b2021-04-26 20:05:39 +0100176 b.configuredModules = allModules
177
178 // Gather all the fragments dependencies.
Paul Duffin9bacf562021-04-28 21:16:02 +0100179 b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000180
Paul Duffinf23bc472021-04-27 12:42:20 +0100181 // Check the configuration of the boot modules.
182 // ART modules are checked by the art-bootclasspath-fragment.
satayevd604b212021-07-21 14:23:52 +0100183 b.checkPlatformModules(ctx, platformModules)
184 b.checkApexModules(ctx, apexModules)
Paul Duffinf23bc472021-04-27 12:42:20 +0100185
satayev013485b2021-05-06 23:38:10 +0100186 b.generateClasspathProtoBuildActions(ctx)
187
Paul Duffinc8ead412021-06-07 19:28:15 +0100188 bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
189 buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
Paul Duffin702210b2021-04-08 20:12:41 +0100190
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100191 // Nothing to do if skipping the dexpreopt of boot image jars.
192 if SkipDexpreoptBootJars(ctx) {
193 return
194 }
195
satayevd604b212021-07-21 14:23:52 +0100196 b.generateBootImageBuildActions(ctx, platformModules, apexModules)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100197}
198
satayev013485b2021-05-06 23:38:10 +0100199// Generate classpaths.proto config
200func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +0100201 configuredJars := b.configuredJars(ctx)
satayev013485b2021-05-06 23:38:10 +0100202 // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
satayevb3090502021-06-15 17:49:10 +0100203 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
204 b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +0100205}
206
satayev142ed272021-06-15 16:21:17 +0100207func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +0100208 // Include all non APEX jars
209 jars := b.getImageConfig(ctx).modules
210
211 // Include jars from APEXes that don't populate their classpath proto config.
satayevd604b212021-07-21 14:23:52 +0100212 remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
satayevb3090502021-06-15 17:49:10 +0100213 for _, fragment := range b.fragments {
214 info := ctx.OtherModuleProvider(fragment, ClasspathFragmentProtoContentInfoProvider).(ClasspathFragmentProtoContentInfo)
215 if info.ClasspathFragmentProtoGenerated {
216 remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents)
217 }
218 }
219 for i := 0; i < remainingJars.Len(); i++ {
220 jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i))
221 }
222
223 return jars
satayev013485b2021-05-06 23:38:10 +0100224}
225
satayevd604b212021-07-21 14:23:52 +0100226// checkPlatformModules ensures that the non-updatable modules supplied are not part of an
227// apex module.
228func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) {
229 // TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here.
Paul Duffinf23bc472021-04-27 12:42:20 +0100230 for _, m := range modules {
231 apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
232 fromUpdatableApex := apexInfo.Updatable
233 if fromUpdatableApex {
234 // error: this jar is part of an updatable apex
Jiyong Parkab50b072021-05-12 17:13:56 +0900235 ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexVariants)
Paul Duffinf23bc472021-04-27 12:42:20 +0100236 } else {
237 // ok: this jar is part of the platform or a non-updatable apex
238 }
239 }
240}
241
satayevd604b212021-07-21 14:23:52 +0100242// checkApexModules ensures that the apex modules supplied are not from the platform.
243func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext, modules []android.Module) {
Paul Duffinf23bc472021-04-27 12:42:20 +0100244 for _, m := range modules {
245 apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
246 fromUpdatableApex := apexInfo.Updatable
247 if fromUpdatableApex {
248 // ok: this jar is part of an updatable apex
249 } else {
250 name := ctx.OtherModuleName(m)
251 if apexInfo.IsForPlatform() {
Paul Duffin7487a7a2021-05-19 09:36:09 +0100252 // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will
253 // include platform variants of a prebuilt module due to workarounds elsewhere. In that case
254 // do not treat this as an error.
255 // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment
256 // modules is complete.
257 if !ctx.Config().AlwaysUsePrebuiltSdks() {
258 // error: this jar is part of the platform
satayevd604b212021-07-21 14:23:52 +0100259 ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name)
Paul Duffin7487a7a2021-05-19 09:36:09 +0100260 }
Paul Duffinf23bc472021-04-27 12:42:20 +0100261 } else {
262 // TODO(b/177892522): Treat this as an error.
263 // Cannot do that at the moment because framework-wifi and framework-tethering are in the
satayevd604b212021-07-21 14:23:52 +0100264 // PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP.
Paul Duffinf23bc472021-04-27 12:42:20 +0100265 }
266 }
267 }
268}
269
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100270func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
271 return defaultBootImageConfig(ctx)
272}
Paul Duffin702210b2021-04-08 20:12:41 +0100273
274// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffinc8ead412021-06-07 19:28:15 +0100275func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
Paul Duffin702210b2021-04-08 20:12:41 +0100276
Paul Duffin90b8ad32021-04-13 12:25:01 +0100277 // Save the paths to the monolithic files for retrieval via OutputFiles().
278 b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
279 b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
280 b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
Paul Duffin6a766452021-04-12 14:15:22 +0100281
Adrian Roose95a15e2021-06-21 16:03:11 +0200282 bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules)
283
Paul Duffin0b659862021-04-13 13:02:29 +0100284 // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance
285 // optimization that can be used to reduce the incremental build time but as its name suggests it
286 // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
Vishnu Nair0dbd02a2021-04-30 00:24:07 +0000287 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
Paul Duffin0b659862021-04-13 13:02:29 +0100288 paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
289 for _, path := range paths {
290 ctx.Build(pctx, android.BuildParams{
291 Rule: android.Touch,
292 Output: path,
293 })
294 }
Adrian Roose95a15e2021-06-21 16:03:11 +0200295 return bootDexJarByModule
Paul Duffin0b659862021-04-13 13:02:29 +0100296 }
297
Paul Duffin89f570a2021-06-16 01:42:33 +0100298 // Construct a list of ClasspathElement objects from the modules and fragments.
299 classpathElements := CreateClasspathElements(ctx, modules, fragments)
300
301 monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements)
302
303 // Extract the classes jars only from those libraries that do not have corresponding fragments as
304 // the fragments will have already provided the flags that are needed.
305 classesJars := monolithicInfo.ClassesJars
306
Paul Duffin4539a372021-06-23 23:20:43 +0100307 // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
Paul Duffin1352f7c2021-05-21 22:18:49 +0100308 input := newHiddenAPIFlagInput()
309
310 // Gather stub library information from the dependencies on modules provided by
311 // hiddenAPIComputeMonolithicStubLibModules.
312 input.gatherStubLibInfo(ctx, nil)
313
314 // Use the flag files from this module and all the fragments.
315 input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory
Paul Duffin74431d52021-04-21 14:10:42 +0100316
Paul Duffin537ea3d2021-05-14 10:38:00 +0100317 // Generate the monolithic stub-flags.csv file.
Paul Duffin537ea3d2021-05-14 10:38:00 +0100318 stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
Paul Duffin67b9d612021-07-21 17:38:47 +0100319 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 +0100320
Paul Duffin537ea3d2021-05-14 10:38:00 +0100321 // Generate the annotation-flags.csv file from all the module annotations.
Paul Duffind061d402021-06-07 21:36:01 +0100322 annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv")
323 buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100324
Paul Duffind061d402021-06-07 21:36:01 +0100325 // Generate the monolithic hiddenapi-flags.csv file.
326 //
327 // Use annotation flags generated directly from the classes jars as well as annotation flag files
328 // provided by prebuilts.
329 allAnnotationFlagFiles := android.Paths{annotationFlags}
330 allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100331 allFlags := hiddenAPISingletonPaths(ctx).flags
Paul Duffin67b9d612021-07-21 17:38:47 +0100332 buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.FlagSubsets, android.OptionalPath{})
Paul Duffin537ea3d2021-05-14 10:38:00 +0100333
334 // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations
335 // in the source code.
Paul Duffind061d402021-06-07 21:36:01 +0100336 intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv")
337 buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100338
Paul Duffind061d402021-06-07 21:36:01 +0100339 // Generate the monolithic hiddenapi-metadata.csv file.
340 //
341 // Use metadata files generated directly from the classes jars as well as metadata files provided
342 // by prebuilts.
343 //
344 // This has the side effect of ensuring that the output file uses | quotes just in case that is
345 // important for the tools that consume the metadata file.
346 allMetadataFlagFiles := android.Paths{intermediateMetadataCSV}
347 allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100348 metadataCSV := hiddenAPISingletonPaths(ctx).metadata
Paul Duffind061d402021-06-07 21:36:01 +0100349 b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100350
Paul Duffind061d402021-06-07 21:36:01 +0100351 // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the
352 // classes jars.
353 intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv")
354 buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV)
355
356 // Generate the monolithic hiddenapi-index.csv file.
357 //
358 // Use index files generated directly from the classes jars as well as index files provided
359 // by prebuilts.
360 allIndexFlagFiles := android.Paths{intermediateIndexCSV}
361 allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...)
Paul Duffin537ea3d2021-05-14 10:38:00 +0100362 indexCSV := hiddenAPISingletonPaths(ctx).index
Paul Duffind061d402021-06-07 21:36:01 +0100363 b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV)
Paul Duffinc8ead412021-06-07 19:28:15 +0100364
365 return bootDexJarByModule
Paul Duffin74431d52021-04-21 14:10:42 +0100366}
367
Paul Duffin438eb572021-05-21 16:58:23 +0100368// createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for
369// testing.
Paul Duffin89f570a2021-06-16 01:42:33 +0100370func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo {
Paul Duffin1352f7c2021-05-21 22:18:49 +0100371 // Create a temporary input structure in which to collate information provided directly by this
372 // module, either through properties or direct dependencies.
373 temporaryInput := newHiddenAPIFlagInput()
374
375 // Create paths to the flag files specified in the properties.
376 temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api)
377
378 // Create the monolithic info, by starting with the flag files specified on this and then merging
379 // in information from all the fragment dependencies of this.
Paul Duffin89f570a2021-06-16 01:42:33 +0100380 monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements)
Paul Duffin438eb572021-05-21 16:58:23 +0100381
382 // Store the information for testing.
Paul Duffin524c82c2021-06-09 14:39:28 +0100383 ctx.SetProvider(MonolithicHiddenAPIInfoProvider, monolithicInfo)
Paul Duffin438eb572021-05-21 16:58:23 +0100384 return monolithicInfo
385}
386
Paul Duffin537ea3d2021-05-14 10:38:00 +0100387func (b *platformBootclasspathModule) buildRuleMergeCSV(ctx android.ModuleContext, desc string, inputPaths android.Paths, outputPath android.WritablePath) {
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100388 rule := android.NewRuleBuilder(pctx, ctx)
389 rule.Command().
390 BuiltTool("merge_csv").
391 Flag("--key_field signature").
Paul Duffin85dee5d2021-04-13 00:14:38 +0100392 FlagWithOutput("--output=", outputPath).
Paul Duffin537ea3d2021-05-14 10:38:00 +0100393 Inputs(inputPaths)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100394
Paul Duffin537ea3d2021-05-14 10:38:00 +0100395 rule.Build(desc, desc)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100396}
Paul Duffinad19d382021-04-26 16:44:00 +0100397
Paul Duffin12d29b72021-04-29 13:50:01 +0100398// generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g.
399// veridex and run-appcompat.
400func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) {
401 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
402 return
403 }
404 // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
405 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String())
406}
407
Paul Duffinad19d382021-04-26 16:44:00 +0100408// generateBootImageBuildActions generates ninja rules related to the boot image creation.
satayevd604b212021-07-21 14:23:52 +0100409func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, platformModules, apexModules []android.Module) {
Paul Duffinad19d382021-04-26 16:44:00 +0100410 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
411 // GenerateSingletonBuildActions method as it cannot create it for itself.
412 dexpreopt.GetGlobalSoongConfig(ctx)
413
414 imageConfig := b.getImageConfig(ctx)
415 if imageConfig == nil {
416 return
417 }
418
419 global := dexpreopt.GetGlobalConfig(ctx)
420 if !shouldBuildBootImages(ctx.Config(), global) {
421 return
422 }
423
424 // Generate the framework profile rule
425 bootFrameworkProfileRule(ctx, imageConfig)
Paul Duffin4c094422021-04-26 20:10:48 +0100426
Paul Duffin3bc8e212021-07-16 14:00:37 +0100427 // If always using prebuilt sdks then do not generate the updatable-bcp-packages.txt file as it
428 // will break because the prebuilts do not yet specify a permitted_packages property.
429 // TODO(b/193889859): Remove when the prebuilts have been updated.
430 if !ctx.Config().AlwaysUsePrebuiltSdks() {
431 // Generate the updatable bootclasspath packages rule.
satayevd604b212021-07-21 14:23:52 +0100432 generateUpdatableBcpPackagesRule(ctx, imageConfig, apexModules)
Paul Duffin3bc8e212021-07-16 14:00:37 +0100433 }
Paul Duffinf7a55922021-04-26 23:09:15 +0100434
satayevd604b212021-07-21 14:23:52 +0100435 // Copy platform module dex jars to their predefined locations.
436 platformBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, platformModules)
437 copyBootJarsToPredefinedLocations(ctx, platformBootDexJarsByModule, imageConfig.dexPathsByModule)
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100438
satayevd604b212021-07-21 14:23:52 +0100439 // Copy apex module dex jars to their predefined locations.
440 config := GetApexBootConfig(ctx)
441 apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules)
442 copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule)
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100443
Paul Duffin2fc82ad2021-04-29 23:36:12 +0100444 // Build a profile for the image config and then use that to build the boot image.
445 profile := bootImageProfileRule(ctx, imageConfig)
Paul Duffin56afb272021-07-01 22:04:22 +0100446
Paul Duffina56be7d2021-07-02 13:00:43 +0100447 // Build boot image files for the android variants.
448 androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
449
450 // Zip the android variant boot image files up.
451 buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFilesByArch)
452
453 // Build boot image files for the host variants. There are use directly by ART host side tests.
454 buildBootImageVariantsForBuildOs(ctx, imageConfig, profile)
Paul Duffin2fc82ad2021-04-29 23:36:12 +0100455
Paul Duffinf7a55922021-04-26 23:09:15 +0100456 dumpOatRules(ctx, imageConfig)
Paul Duffinad19d382021-04-26 16:44:00 +0100457}