blob: 3a598227943a77cea38e11172bc453c5c9074dc7 [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 (
35 platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"}
36 platformBootclasspathNonUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "non-updatable-boot-jar"}
37 platformBootclasspathUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "updatable-boot-jar"}
38)
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.
47 //
48 // Currently only for testing.
49 configuredModules []android.Module
Paul Duffin62d8c3b2021-04-07 20:35:11 +010050
51 // The apex:module pairs obtained from the fragments.
52 //
53 // Currently only for testing.
54 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 Duffin46169772021-04-14 15:01:56 +010069 Hidden_api HiddenAPIFlagFileProperties
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010070}
71
Paul Duffine3ecce62021-04-29 10:34:11 +010072func platformBootclasspathFactory() android.SingletonModule {
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010073 m := &platformBootclasspathModule{}
Paul Duffin62d8c3b2021-04-07 20:35:11 +010074 m.AddProperties(&m.properties)
Artur Satayev97259dc2021-04-07 15:17:14 +010075 // TODO(satayev): split systemserver and apex jars into separate configs.
76 initClasspathFragment(m)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +010077 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
78 return m
79}
80
Paul Duffin6a766452021-04-12 14:15:22 +010081var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil)
82
Artur Satayev97259dc2021-04-07 15:17:14 +010083func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
84 entries = append(entries, android.AndroidMkEntries{
85 Class: "FAKE",
86 // Need at least one output file in order for this to take effect.
87 OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
88 Include: "$(BUILD_PHONY_PACKAGE)",
89 })
90 entries = append(entries, b.classpathFragmentBase().getAndroidMkEntries()...)
91 return
Paul Duffin6a766452021-04-12 14:15:22 +010092}
93
94// Make the hidden API files available from the platform-bootclasspath module.
95func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) {
96 switch tag {
97 case "hiddenapi-flags.csv":
98 return android.Paths{b.hiddenAPIFlagsCSV}, nil
99 case "hiddenapi-index.csv":
100 return android.Paths{b.hiddenAPIIndexCSV}, nil
101 case "hiddenapi-metadata.csv":
102 return android.Paths{b.hiddenAPIMetadataCSV}, nil
103 }
104
105 return nil, fmt.Errorf("unknown tag %s", tag)
106}
107
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100108func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin74431d52021-04-21 14:10:42 +0100109 b.hiddenAPIDepsMutator(ctx)
110
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100111 if SkipDexpreoptBootJars(ctx) {
112 return
113 }
114
115 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
116 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
117 dexpreopt.RegisterToolDeps(ctx)
118}
119
Paul Duffin74431d52021-04-21 14:10:42 +0100120func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
121 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
122 return
123 }
124
125 // Add dependencies onto the stub lib modules.
126 sdkKindToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
127 hiddenAPIAddStubLibDependencies(ctx, sdkKindToStubLibModules)
128}
129
Paul Duffin4994d262021-04-22 12:08:59 +0100130func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
131 // Add dependencies on all the modules configured in the "art" boot image.
132 artImageConfig := genBootImageConfigs(ctx)[artBootImageName]
Paul Duffin01b463b2021-04-26 20:05:39 +0100133 addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000134
Paul Duffin01b463b2021-04-26 20:05:39 +0100135 // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does
136 // not include modules configured in the "art" boot image.
Paul Duffin4994d262021-04-22 12:08:59 +0100137 bootImageConfig := b.getImageConfig(ctx)
Paul Duffin01b463b2021-04-26 20:05:39 +0100138 addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathNonUpdatableBootJarDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000139
Paul Duffin4994d262021-04-22 12:08:59 +0100140 // Add dependencies on all the updatable modules.
141 updatableModules := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars
Paul Duffin01b463b2021-04-26 20:05:39 +0100142 addDependenciesOntoBootImageModules(ctx, updatableModules, platformBootclasspathUpdatableBootJarDepTag)
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100143
Paul Duffin4994d262021-04-22 12:08:59 +0100144 // Add dependencies on all the fragments.
145 b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
Paul Duffinb432df92021-03-22 22:09:42 +0000146}
147
Paul Duffin01b463b2021-04-26 20:05:39 +0100148func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) {
Paul Duffinb432df92021-03-22 22:09:42 +0000149 for i := 0; i < modules.Len(); i++ {
150 apex := modules.Apex(i)
151 name := modules.Jar(i)
152
Paul Duffin01b463b2021-04-26 20:05:39 +0100153 addDependencyOntoApexModulePair(ctx, apex, name, tag)
Paul Duffinb432df92021-03-22 22:09:42 +0000154 }
155}
156
Paul Duffine3ecce62021-04-29 10:34:11 +0100157// GenerateSingletonBuildActions does nothing and must never do anything.
158//
159// This module only implements android.SingletonModule so that it can implement
160// android.SingletonMakeVarsProvider.
161func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) {
162 // Keep empty
163}
164
165func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) {
Paul Duffin12d29b72021-04-29 13:50:01 +0100166 d.generateHiddenApiMakeVars(ctx)
Paul Duffine3ecce62021-04-29 10:34:11 +0100167}
168
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100169func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Artur Satayev97259dc2021-04-07 15:17:14 +0100170 b.classpathFragmentBase().generateAndroidBuildActions(ctx)
171
Paul Duffin01b463b2021-04-26 20:05:39 +0100172 // Gather all the dependencies from the art, updatable and non-updatable boot jars.
173 artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag)
174 nonUpdatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathNonUpdatableBootJarDepTag)
175 updatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathUpdatableBootJarDepTag)
176
177 // Concatenate them all, in order as they would appear on the bootclasspath.
178 var allModules []android.Module
179 allModules = append(allModules, artModules...)
180 allModules = append(allModules, nonUpdatableModules...)
181 allModules = append(allModules, updatableModules...)
182 b.configuredModules = allModules
183
184 // Gather all the fragments dependencies.
Paul Duffin9bacf562021-04-28 21:16:02 +0100185 b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
Paul Duffinb432df92021-03-22 22:09:42 +0000186
Paul Duffinf23bc472021-04-27 12:42:20 +0100187 // Check the configuration of the boot modules.
188 // ART modules are checked by the art-bootclasspath-fragment.
189 b.checkNonUpdatableModules(ctx, nonUpdatableModules)
190 b.checkUpdatableModules(ctx, updatableModules)
191
Paul Duffin9b381ef2021-04-08 23:01:37 +0100192 b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
Paul Duffin702210b2021-04-08 20:12:41 +0100193
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100194 // Nothing to do if skipping the dexpreopt of boot image jars.
195 if SkipDexpreoptBootJars(ctx) {
196 return
197 }
198
Paul Duffin4c094422021-04-26 20:10:48 +0100199 b.generateBootImageBuildActions(ctx, updatableModules)
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100200}
201
Paul Duffinf23bc472021-04-27 12:42:20 +0100202// checkNonUpdatableModules ensures that the non-updatable modules supplied are not part of an
203// updatable module.
204func (b *platformBootclasspathModule) checkNonUpdatableModules(ctx android.ModuleContext, modules []android.Module) {
205 for _, m := range modules {
206 apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
207 fromUpdatableApex := apexInfo.Updatable
208 if fromUpdatableApex {
209 // error: this jar is part of an updatable apex
210 ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexes)
211 } else {
212 // ok: this jar is part of the platform or a non-updatable apex
213 }
214 }
215}
216
217// checkUpdatableModules ensures that the updatable modules supplied are not from the platform.
218func (b *platformBootclasspathModule) checkUpdatableModules(ctx android.ModuleContext, modules []android.Module) {
219 for _, m := range modules {
220 apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
221 fromUpdatableApex := apexInfo.Updatable
222 if fromUpdatableApex {
223 // ok: this jar is part of an updatable apex
224 } else {
225 name := ctx.OtherModuleName(m)
226 if apexInfo.IsForPlatform() {
227 // error: this jar is part of the platform
228 ctx.ModuleErrorf("module %q from platform is not allowed in the updatable boot jars list", name)
229 } else {
230 // TODO(b/177892522): Treat this as an error.
231 // Cannot do that at the moment because framework-wifi and framework-tethering are in the
232 // PRODUCT_UPDATABLE_BOOT_JARS but not marked as updatable in AOSP.
233 }
234 }
235 }
236}
237
Paul Duffinbb7f1ac2021-03-29 22:18:45 +0100238func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
239 return defaultBootImageConfig(ctx)
240}
Paul Duffin702210b2021-04-08 20:12:41 +0100241
Paul Duffind504c3a2021-04-30 08:10:21 +0100242// hiddenAPISupportingModule encapsulates the information provided by any module that contributes to
243// the hidden API processing.
244type hiddenAPISupportingModule struct {
245 module android.Module
246
247 bootDexJar android.Path
248 flagsCSV android.Path
249 indexCSV android.Path
250 metadataCSV android.Path
251}
252
Paul Duffin702210b2021-04-08 20:12:41 +0100253// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin9b381ef2021-04-08 23:01:37 +0100254func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) {
Paul Duffin702210b2021-04-08 20:12:41 +0100255
Paul Duffin90b8ad32021-04-13 12:25:01 +0100256 // Save the paths to the monolithic files for retrieval via OutputFiles().
257 b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
258 b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
259 b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
Paul Duffin6a766452021-04-12 14:15:22 +0100260
Paul Duffin0b659862021-04-13 13:02:29 +0100261 // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance
262 // optimization that can be used to reduce the incremental build time but as its name suggests it
263 // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
Vishnu Nair0dbd02a2021-04-30 00:24:07 +0000264 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
Paul Duffin0b659862021-04-13 13:02:29 +0100265 paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
266 for _, path := range paths {
267 ctx.Build(pctx, android.BuildParams{
268 Rule: android.Touch,
269 Output: path,
270 })
271 }
272 return
273 }
274
Paul Duffind504c3a2021-04-30 08:10:21 +0100275 // nilPathHandler will check the supplied path and if it is nil then it will either immediately
276 // report an error, or it will defer the error reporting until it is actually used, depending
277 // whether missing dependencies are allowed.
278 var nilPathHandler func(path android.Path, name string, module android.Module) android.Path
279 if ctx.Config().AllowMissingDependencies() {
280 nilPathHandler = func(path android.Path, name string, module android.Module) android.Path {
281 if path == nil {
282 outputPath := android.PathForModuleOut(ctx, "missing", module.Name(), name)
283 path = outputPath
284
285 // Create an error rule that pretends to create the output file but will actually fail if it
286 // is run.
287 ctx.Build(pctx, android.BuildParams{
288 Rule: android.ErrorRule,
289 Output: outputPath,
290 Args: map[string]string{
291 "error": fmt.Sprintf("missing hidden API file: %s for %s", name, module),
292 },
293 })
294 }
295 return path
296 }
297 } else {
298 nilPathHandler = func(path android.Path, name string, module android.Module) android.Path {
299 if path == nil {
300 ctx.ModuleErrorf("module %s does not provide a %s file", module, name)
301 }
302 return path
303 }
304 }
305
Paul Duffin1ba24672021-04-12 23:26:14 +0100306 hiddenAPISupportingModules := []hiddenAPISupportingModule{}
Paul Duffin702210b2021-04-08 20:12:41 +0100307 for _, module := range modules {
Paul Duffind504c3a2021-04-30 08:10:21 +0100308 if h, ok := module.(hiddenAPIIntf); ok {
309 hiddenAPISupportingModule := hiddenAPISupportingModule{
310 module: module,
311 bootDexJar: nilPathHandler(h.bootDexJar(), "bootDexJar", module),
312 flagsCSV: nilPathHandler(h.flagsCSV(), "flagsCSV", module),
313 indexCSV: nilPathHandler(h.indexCSV(), "indexCSV", module),
314 metadataCSV: nilPathHandler(h.metadataCSV(), "metadataCSV", module),
Paul Duffin1ba24672021-04-12 23:26:14 +0100315 }
316
Paul Duffind504c3a2021-04-30 08:10:21 +0100317 // If any errors were reported when trying to populate the hiddenAPISupportingModule struct
318 // then don't add it to the list.
Paul Duffin1ba24672021-04-12 23:26:14 +0100319 if ctx.Failed() {
320 continue
321 }
322
Paul Duffind504c3a2021-04-30 08:10:21 +0100323 hiddenAPISupportingModules = append(hiddenAPISupportingModules, hiddenAPISupportingModule)
Paul Duffin49775402021-04-30 08:58:12 +0100324 } else if _, ok := module.(*DexImport); ok {
325 // Ignore this for the purposes of hidden API processing
Paul Duffin702210b2021-04-08 20:12:41 +0100326 } else {
Paul Duffin1ba24672021-04-12 23:26:14 +0100327 ctx.ModuleErrorf("module %s of type %s does not support hidden API processing", module, ctx.OtherModuleType(module))
Paul Duffin702210b2021-04-08 20:12:41 +0100328 }
329 }
330
Paul Duffin1ba24672021-04-12 23:26:14 +0100331 moduleSpecificFlagsPaths := android.Paths{}
332 for _, module := range hiddenAPISupportingModules {
Paul Duffind504c3a2021-04-30 08:10:21 +0100333 moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, module.flagsCSV)
Paul Duffin1ba24672021-04-12 23:26:14 +0100334 }
335
Paul Duffin9b381ef2021-04-08 23:01:37 +0100336 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
337 for _, fragment := range fragments {
338 if ctx.OtherModuleHasProvider(fragment, hiddenAPIFlagFileInfoProvider) {
339 info := ctx.OtherModuleProvider(fragment, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
340 flagFileInfo.append(info)
341 }
342 }
343
344 // Store the information for testing.
345 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
Paul Duffin702210b2021-04-08 20:12:41 +0100346
347 outputPath := hiddenAPISingletonPaths(ctx).flags
348 baseFlagsPath := hiddenAPISingletonPaths(ctx).stubFlags
Paul Duffin9b381ef2021-04-08 23:01:37 +0100349 ruleToGenerateHiddenApiFlags(ctx, outputPath, baseFlagsPath, moduleSpecificFlagsPaths, flagFileInfo)
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100350
Paul Duffin74431d52021-04-21 14:10:42 +0100351 b.generateHiddenAPIStubFlagsRules(ctx, hiddenAPISupportingModules)
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100352 b.generateHiddenAPIIndexRules(ctx, hiddenAPISupportingModules)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100353 b.generatedHiddenAPIMetadataRules(ctx, hiddenAPISupportingModules)
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100354}
355
Paul Duffin74431d52021-04-21 14:10:42 +0100356func (b *platformBootclasspathModule) generateHiddenAPIStubFlagsRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
357 bootDexJars := android.Paths{}
358 for _, module := range modules {
Paul Duffind504c3a2021-04-30 08:10:21 +0100359 bootDexJars = append(bootDexJars, module.bootDexJar)
Paul Duffin74431d52021-04-21 14:10:42 +0100360 }
361
362 sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx)
363
364 outputPath := hiddenAPISingletonPaths(ctx).stubFlags
365 rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths)
366 rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags")
367}
368
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100369func (b *platformBootclasspathModule) generateHiddenAPIIndexRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
370 indexes := android.Paths{}
371 for _, module := range modules {
Paul Duffind504c3a2021-04-30 08:10:21 +0100372 indexes = append(indexes, module.indexCSV)
Paul Duffin00b2bfd2021-04-12 17:24:36 +0100373 }
374
375 rule := android.NewRuleBuilder(pctx, ctx)
376 rule.Command().
377 BuiltTool("merge_csv").
378 Flag("--key_field signature").
379 FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties").
380 FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index).
381 Inputs(indexes)
382 rule.Build("platform-bootclasspath-monolithic-hiddenapi-index", "monolithic hidden API index")
Paul Duffin702210b2021-04-08 20:12:41 +0100383}
Paul Duffin85dee5d2021-04-13 00:14:38 +0100384
385func (b *platformBootclasspathModule) generatedHiddenAPIMetadataRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
386 metadataCSVFiles := android.Paths{}
387 for _, module := range modules {
Paul Duffind504c3a2021-04-30 08:10:21 +0100388 metadataCSVFiles = append(metadataCSVFiles, module.metadataCSV)
Paul Duffin85dee5d2021-04-13 00:14:38 +0100389 }
390
391 rule := android.NewRuleBuilder(pctx, ctx)
392
393 outputPath := hiddenAPISingletonPaths(ctx).metadata
394
395 rule.Command().
396 BuiltTool("merge_csv").
397 Flag("--key_field signature").
398 FlagWithOutput("--output=", outputPath).
399 Inputs(metadataCSVFiles)
400
401 rule.Build("platform-bootclasspath-monolithic-hiddenapi-metadata", "monolithic hidden API metadata")
402}
Paul Duffinad19d382021-04-26 16:44:00 +0100403
Paul Duffin12d29b72021-04-29 13:50:01 +0100404// generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g.
405// veridex and run-appcompat.
406func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) {
407 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
408 return
409 }
410 // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
411 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String())
412}
413
Paul Duffinad19d382021-04-26 16:44:00 +0100414// generateBootImageBuildActions generates ninja rules related to the boot image creation.
Paul Duffin4c094422021-04-26 20:10:48 +0100415func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, updatableModules []android.Module) {
Paul Duffinad19d382021-04-26 16:44:00 +0100416 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
417 // GenerateSingletonBuildActions method as it cannot create it for itself.
418 dexpreopt.GetGlobalSoongConfig(ctx)
419
420 imageConfig := b.getImageConfig(ctx)
421 if imageConfig == nil {
422 return
423 }
424
425 global := dexpreopt.GetGlobalConfig(ctx)
426 if !shouldBuildBootImages(ctx.Config(), global) {
427 return
428 }
429
430 // Generate the framework profile rule
431 bootFrameworkProfileRule(ctx, imageConfig)
Paul Duffin4c094422021-04-26 20:10:48 +0100432
433 // Generate the updatable bootclasspath packages rule.
434 generateUpdatableBcpPackagesRule(ctx, imageConfig, updatableModules)
Paul Duffinf7a55922021-04-26 23:09:15 +0100435
436 dumpOatRules(ctx, imageConfig)
Paul Duffinad19d382021-04-26 16:44:00 +0100437}