Merge "Avoid passing around []hiddenAPIModule" am: 881baf5573

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1736224

Change-Id: Ia794359e5a581d6b8b705d213eb17fae51454504
This commit is contained in:
Paul Duffin
2021-06-14 22:19:04 +00:00
committed by Automerger Merge Worker
3 changed files with 41 additions and 36 deletions

View File

@@ -140,7 +140,7 @@ type commonBootclasspathFragment interface {
// produceHiddenAPIAllFlagsFile produces the all-flags.csv and intermediate files. // produceHiddenAPIAllFlagsFile produces the all-flags.csv and intermediate files.
// //
// Updates the supplied hiddenAPIInfo with the paths to the generated files set. // Updates the supplied hiddenAPIInfo with the paths to the generated files set.
produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIFlagOutput
} }
var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil) var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
@@ -465,7 +465,7 @@ func (b *BootclasspathFragmentModule) populateApexContentInfoDexJars(ctx android
if unencodedDex == nil { if unencodedDex == nil {
// This is an error. Sometimes Soong will report the error directly, other times it will // This is an error. Sometimes Soong will report the error directly, other times it will
// defer the error reporting to happen only when trying to use the missing file in ninja. // defer the error reporting to happen only when trying to use the missing file in ninja.
// Either way it is handled by extractBootDexJarsFromHiddenAPIModules which must have been // Either way it is handled by extractBootDexJarsFromModules which must have been
// called before this as it generates the flags that are used to encode these files. // called before this as it generates the flags that are used to encode these files.
continue continue
} }
@@ -561,12 +561,9 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.
// TODO(b/179354495): Stop hidden API processing being conditional once all bootclasspath_fragment // TODO(b/179354495): Stop hidden API processing being conditional once all bootclasspath_fragment
// modules have been updated to support it. // modules have been updated to support it.
if input.canPerformHiddenAPIProcessing(ctx, b.properties) { if input.canPerformHiddenAPIProcessing(ctx, b.properties) {
// Get the content modules that contribute to the hidden API processing.
hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, contents)
// Delegate the production of the hidden API all-flags.csv file to a module type specific method. // Delegate the production of the hidden API all-flags.csv file to a module type specific method.
common := ctx.Module().(commonBootclasspathFragment) common := ctx.Module().(commonBootclasspathFragment)
output = common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, input) output = common.produceHiddenAPIAllFlagsFile(ctx, contents, input)
} }
// Initialize a HiddenAPIInfo structure. // Initialize a HiddenAPIInfo structure.
@@ -620,7 +617,7 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul
// produceHiddenAPIAllFlagsFile produces the hidden API all-flags.csv file (and supporting files) // produceHiddenAPIAllFlagsFile produces the hidden API all-flags.csv file (and supporting files)
// for the fragment. // for the fragment.
func (b *BootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput { func (b *BootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIFlagOutput {
// Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the
// paths to the created files. // paths to the created files.
return hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx, contents, input) return hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx, contents, input)
@@ -841,7 +838,7 @@ func (module *prebuiltBootclasspathFragmentModule) Name() string {
// produceHiddenAPIAllFlagsFile returns a path to the prebuilt all-flags.csv or nil if none is // produceHiddenAPIAllFlagsFile returns a path to the prebuilt all-flags.csv or nil if none is
// specified. // specified.
func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, _ HiddenAPIFlagInput) *HiddenAPIFlagOutput { func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []android.Module, _ HiddenAPIFlagInput) *HiddenAPIFlagOutput {
pathForOptionalSrc := func(src *string) android.Path { pathForOptionalSrc := func(src *string) android.Path {
if src == nil { if src == nil {
// TODO(b/179354495): Fail if this is not provided once prebuilts have been updated. // TODO(b/179354495): Fail if this is not provided once prebuilts have been updated.

View File

@@ -679,11 +679,11 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st
// * metadata.csv // * metadata.csv
// * index.csv // * index.csv
// * all-flags.csv // * all-flags.csv
func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput { func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIFlagOutput {
hiddenApiSubDir := "modular-hiddenapi" hiddenApiSubDir := "modular-hiddenapi"
// Gather the dex files for the boot libraries provided by this fragment. // Gather the dex files for the boot libraries provided by this fragment.
bootDexJars := extractBootDexJarsFromHiddenAPIModules(ctx, contents) bootDexJars := extractBootDexJarsFromModules(ctx, contents)
// Generate the stub-flags.csv. // Generate the stub-flags.csv.
stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv")
@@ -691,7 +691,7 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
rule.Build("modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags") rule.Build("modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags")
// Extract the classes jars from the contents. // Extract the classes jars from the contents.
classesJars := extractClassJarsFromHiddenAPIModules(ctx, contents) classesJars := extractClassesJarsFromModules(contents)
// Generate the set of flags from the annotations in the source code. // Generate the set of flags from the annotations in the source code.
annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv")
@@ -746,26 +746,15 @@ func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedT
return android.OptionalPathForPath(output) return android.OptionalPathForPath(output)
} }
// gatherHiddenAPIModuleFromContents gathers the hiddenAPIModule from the supplied contents. // extractBootDexJarsFromModules extracts the boot dex jars from the supplied modules.
func gatherHiddenAPIModuleFromContents(ctx android.ModuleContext, contents []android.Module) []hiddenAPIModule { func extractBootDexJarsFromModules(ctx android.ModuleContext, contents []android.Module) android.Paths {
hiddenAPIModules := []hiddenAPIModule{}
for _, module := range contents {
if hiddenAPI, ok := module.(hiddenAPIModule); ok {
hiddenAPIModules = append(hiddenAPIModules, hiddenAPI)
} else if _, ok := module.(*DexImport); ok {
// Ignore this for the purposes of hidden API processing
} else {
ctx.ModuleErrorf("module %s does not implement hiddenAPIModule", module)
}
}
return hiddenAPIModules
}
// extractBootDexJarsFromHiddenAPIModules extracts the boot dex jars from the supplied modules.
func extractBootDexJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths {
bootDexJars := android.Paths{} bootDexJars := android.Paths{}
for _, module := range contents { for _, module := range contents {
bootDexJar := module.bootDexJar() hiddenAPIModule := hiddenAPIModuleFromModule(ctx, module)
if hiddenAPIModule == nil {
continue
}
bootDexJar := hiddenAPIModule.bootDexJar()
if bootDexJar == nil { if bootDexJar == nil {
if ctx.Config().AlwaysUsePrebuiltSdks() { if ctx.Config().AlwaysUsePrebuiltSdks() {
// TODO(b/179354495): Remove this workaround when it is unnecessary. // TODO(b/179354495): Remove this workaround when it is unnecessary.
@@ -793,15 +782,36 @@ func extractBootDexJarsFromHiddenAPIModules(ctx android.ModuleContext, contents
return bootDexJars return bootDexJars
} }
// extractClassJarsFromHiddenAPIModules extracts the class jars from the supplied modules. func hiddenAPIModuleFromModule(ctx android.BaseModuleContext, module android.Module) hiddenAPIModule {
func extractClassJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths { if hiddenAPIModule, ok := module.(hiddenAPIModule); ok {
return hiddenAPIModule
} else if _, ok := module.(*DexImport); ok {
// Ignore this for the purposes of hidden API processing
} else {
ctx.ModuleErrorf("module %s does not implement hiddenAPIModule", module)
}
return nil
}
// extractClassesJarsFromModules extracts the class jars from the supplied modules.
func extractClassesJarsFromModules(contents []android.Module) android.Paths {
classesJars := android.Paths{} classesJars := android.Paths{}
for _, module := range contents { for _, module := range contents {
classesJars = append(classesJars, module.classesJars()...) classesJars = append(classesJars, retrieveClassesJarsFromModule(module)...)
} }
return classesJars return classesJars
} }
// retrieveClassesJarsFromModule retrieves the classes jars from the supplied module.
func retrieveClassesJarsFromModule(module android.Module) android.Paths {
if hiddenAPIModule, ok := module.(hiddenAPIModule); ok {
return hiddenAPIModule.classesJars()
}
return nil
}
// deferReportingMissingBootDexJar returns true if a missing boot dex jar should not be reported by // deferReportingMissingBootDexJar returns true if a missing boot dex jar should not be reported by
// Soong but should instead only be reported in ninja if the file is actually built. // Soong but should instead only be reported in ninja if the file is actually built.
func deferReportingMissingBootDexJar(ctx android.ModuleContext, module android.Module) bool { func deferReportingMissingBootDexJar(ctx android.ModuleContext, module android.Module) bool {

View File

@@ -290,16 +290,14 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.
// Use the flag files from this module and all the fragments. // Use the flag files from this module and all the fragments.
input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory
hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, modules)
// Generate the monolithic stub-flags.csv file. // Generate the monolithic stub-flags.csv file.
bootDexJars := extractBootDexJarsFromHiddenAPIModules(ctx, hiddenAPIModules) bootDexJars := extractBootDexJarsFromModules(ctx, modules)
stubFlags := hiddenAPISingletonPaths(ctx).stubFlags stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, stubFlags, bootDexJars, input) rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, stubFlags, bootDexJars, input)
rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags") rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags")
// Extract the classes jars from the contents. // Extract the classes jars from the contents.
classesJars := extractClassJarsFromHiddenAPIModules(ctx, hiddenAPIModules) classesJars := extractClassesJarsFromModules(modules)
// Generate the annotation-flags.csv file from all the module annotations. // Generate the annotation-flags.csv file from all the module annotations.
annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags.csv") annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags.csv")