Separate monolithic hidden API processing from hiddenAPIFlagFileInfo

The hiddenAPIFlagFileInfo was being used for both the input and output
of bootclasspath_fragment and platform_bootclasspath and also to pass
information around to various hidden API rule methods. Supporting
multiple different uses in this way made it hard to reason about.

This change creates a separate structure for use by the
platform_bootclasspath. Follow up changes will split out other
functionality into separate types.

Bug: 179354495
Test: m com.android.art com.android.ipsec com.android.os.statsd com.android.conscrypt
      - verify that this does not change the contents of the apex files
Merged-In: Ia5c5f65ae5645486c42819c669a8601588217f88
Change-Id: Ia5c5f65ae5645486c42819c669a8601588217f88
(cherry picked from commit 438eb57a27)
This commit is contained in:
Paul Duffin
2021-05-21 16:58:23 +01:00
parent b40610ad00
commit 9e3b906581
6 changed files with 138 additions and 37 deletions

View File

@@ -261,10 +261,10 @@ type HiddenAPIFlagFileProperties struct {
}
func (p *HiddenAPIFlagFileProperties) hiddenAPIFlagFileInfo(ctx android.ModuleContext) hiddenAPIFlagFileInfo {
info := hiddenAPIFlagFileInfo{categoryToPaths: map[*hiddenAPIFlagFileCategory]android.Paths{}}
info := hiddenAPIFlagFileInfo{FlagFilesByCategory: FlagFilesByCategory{}}
for _, category := range hiddenAPIFlagFileCategories {
paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p))
info.categoryToPaths[category] = paths
info.FlagFilesByCategory[category] = paths
}
return info
}
@@ -365,6 +365,24 @@ var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{
},
}
// FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category.
type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths
// append appends the supplied flags files to the corresponding category in this map.
func (s FlagFilesByCategory) append(other FlagFilesByCategory) {
for _, category := range hiddenAPIFlagFileCategories {
s[category] = append(s[category], other[category]...)
}
}
// dedup removes duplicates in the flag files, while maintaining the order in which they were
// appended.
func (s FlagFilesByCategory) dedup() {
for category, paths := range s {
s[category] = android.FirstUniquePaths(paths)
}
}
// hiddenAPIFlagFileInfo contains paths resolved from HiddenAPIFlagFileProperties and also generated
// by hidden API processing.
//
@@ -372,9 +390,9 @@ var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{
// for a module to collate the files from the fragments it depends upon. That is why the fields are
// all Paths even though they are initialized with a single path.
type hiddenAPIFlagFileInfo struct {
// categoryToPaths maps from the flag file category to the paths containing information for that
// category.
categoryToPaths map[*hiddenAPIFlagFileCategory]android.Paths
// FlagFilesByCategory maps from the flag file category to the paths containing information for
// that category.
FlagFilesByCategory FlagFilesByCategory
// The paths to the generated stub-flags.csv files.
StubFlagsPaths android.Paths
@@ -392,17 +410,6 @@ type hiddenAPIFlagFileInfo struct {
AllFlagsPaths android.Paths
}
func (i *hiddenAPIFlagFileInfo) append(other hiddenAPIFlagFileInfo) {
for _, category := range hiddenAPIFlagFileCategories {
i.categoryToPaths[category] = append(i.categoryToPaths[category], other.categoryToPaths[category]...)
}
i.StubFlagsPaths = append(i.StubFlagsPaths, other.StubFlagsPaths...)
i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPaths...)
i.MetadataPaths = append(i.MetadataPaths, other.MetadataPaths...)
i.IndexPaths = append(i.IndexPaths, other.IndexPaths...)
i.AllFlagsPaths = append(i.AllFlagsPaths, other.AllFlagsPaths...)
}
var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{})
// pathForValidation creates a path of the same type as the supplied type but with a name of
@@ -428,14 +435,14 @@ func pathForValidation(ctx android.PathContext, path android.WritablePath) andro
//
// flagFileInfo is a struct containing paths to files that augment the information provided by
// the annotationFlags.
func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, baseFlagsPath android.Path, annotationFlags android.Path, flagFileInfo *hiddenAPIFlagFileInfo) {
func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, baseFlagsPath android.Path, annotationFlags android.Path, flagFilesByCategory FlagFilesByCategory, allFlagsPaths android.Paths) {
// The file which is used to record that the flags file is valid.
var validFile android.WritablePath
// If there are flag files that have been generated by fragments on which this depends then use
// them to validate the flag file generated by the rules created by this method.
if allFlagsPaths := flagFileInfo.AllFlagsPaths; len(allFlagsPaths) > 0 {
if len(allFlagsPaths) > 0 {
// The flags file generated by the rule created by this method needs to be validated to ensure
// that it is consistent with the flag files generated by the individual fragments.
@@ -463,7 +470,7 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st
// Add the options for the different categories of flag files.
for _, category := range hiddenAPIFlagFileCategories {
paths := flagFileInfo.categoryToPaths[category]
paths := flagFilesByCategory[category]
for _, path := range paths {
category.commandMutator(command, path)
}
@@ -530,7 +537,7 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
// Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex
// files.
outputPath := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv")
buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", outputPath, stubFlagsCSV, annotationFlagsCSV, flagFileInfo)
buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", outputPath, stubFlagsCSV, annotationFlagsCSV, flagFileInfo.FlagFilesByCategory, nil)
// Store the paths in the info for use by other modules and sdk snapshot generation.
flagFileInfo.StubFlagsPaths = android.Paths{stubFlagsCSV}