Exclude unsupported libraries from sdk snapshot

When an sdk snapshot is targeted at release X then it cannot include
bootclasspath fragment libraries which are not present in that build as
otherwise it causes build failures. It should also not include any
unsupported libraries, i.e. libraries that cannot work on that release.

This change causes sdk snapshot to exclude libraries that have a
    min_sdk_version > target build release

It also ensures that hidden API flags do not include any information
from excluded libraries.

Bug: 240406019
Test: BUILD_NUMBER=fixed packages/modules/common/build/mainline_modules_sdks.sh
      # Ran the previous command with and without this change to make
      # sure that this change excludes framework-connectivity-t library from the
      # tethering sdk snapshot for S, including from the hidden API flag files.
Change-Id: I57969b85a12e9e5a3fc76c055b260cec5d5f7d7f
This commit is contained in:
Paul Duffin
2022-07-26 23:53:00 +00:00
parent 887efdd779
commit 1938dba8b6
7 changed files with 354 additions and 41 deletions

View File

@@ -257,7 +257,7 @@ type commonBootclasspathFragment interface {
// Returns a *HiddenAPIOutput containing the paths for the generated files. Returns nil if the
// module cannot contribute to hidden API processing, e.g. because it is a prebuilt module in a
// versioned sdk.
produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput
produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput
// produceBootImageFiles will attempt to produce rules to create the boot image files at the paths
// predefined in the bootImageConfig.
@@ -761,7 +761,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.
// Delegate the production of the hidden API all-flags.csv file to a module type specific method.
common := ctx.Module().(commonBootclasspathFragment)
output := common.produceHiddenAPIOutput(ctx, contents, input)
output := common.produceHiddenAPIOutput(ctx, contents, fragments, input)
// If the source or prebuilts module does not provide a signature patterns file then generate one
// from the flags.
@@ -769,7 +769,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.
// their own.
if output.SignaturePatternsPath == nil {
output.SignaturePatternsPath = buildRuleSignaturePatternsFile(
ctx, output.AllFlagsPath, []string{"*"}, nil, nil)
ctx, output.AllFlagsPath, []string{"*"}, nil, nil, "")
}
// Initialize a HiddenAPIInfo structure.
@@ -863,7 +863,7 @@ func (b *BootclasspathFragmentModule) isTestFragment() bool {
func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput, bootDexInfoByModule bootDexInfoByModule, suffix string) HiddenAPIFlagOutput {
// Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the
// paths to the created files.
flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input)
flagOutput := hiddenAPIFlagRulesForBootclasspathFragment(ctx, bootDexInfoByModule, contents, input, suffix)
// If the module specifies split_packages or package_prefixes then use those to generate the
// signature patterns.
@@ -872,7 +872,7 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod
singlePackages := input.SinglePackages
if splitPackages != nil || packagePrefixes != nil || singlePackages != nil {
flagOutput.SignaturePatternsPath = buildRuleSignaturePatternsFile(
ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages)
ctx, flagOutput.AllFlagsPath, splitPackages, packagePrefixes, singlePackages, suffix)
} else if !b.isTestFragment() {
ctx.ModuleErrorf(`Must specify at least one of the split_packages, package_prefixes and single_packages properties
If this is a new bootclasspath_fragment or you are unsure what to do add the
@@ -889,7 +889,7 @@ func (b *BootclasspathFragmentModule) generateHiddenApiFlagRules(ctx android.Mod
// produceHiddenAPIOutput produces the hidden API all-flags.csv file (and supporting files)
// for the fragment as well as encoding the flags in the boot dex jars.
func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput {
func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput {
// Gather information about the boot dex files for the boot libraries provided by this fragment.
bootDexInfoByModule := extractBootDexInfoFromModules(ctx, contents)
@@ -905,7 +905,41 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC
EncodedBootDexFilesByModule: encodedBootDexFilesByModule,
}
flagFilesByCategory := input.FlagFilesByCategory
// Get the ApiLevel associated with SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE, defaulting to current
// if not set.
config := ctx.Config()
targetApiLevel := android.ApiLevelOrPanic(ctx,
config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", "current"))
// Filter the contents list to remove any modules that do not support the target build release.
// The current build release supports all the modules.
contentsForSdkSnapshot := []android.Module{}
for _, module := range contents {
// If the module has a min_sdk_version that is higher than the target build release then it will
// not work on the target build release and so must not be included in the sdk snapshot.
minApiLevel := android.MinApiLevelForSdkSnapshot(ctx, module)
if minApiLevel.GreaterThan(targetApiLevel) {
continue
}
contentsForSdkSnapshot = append(contentsForSdkSnapshot, module)
}
var flagFilesByCategory FlagFilesByCategory
if len(contentsForSdkSnapshot) != len(contents) {
// The sdk snapshot has different contents to the runtime fragment so it is not possible to
// reuse the hidden API information generated for the fragment. So, recompute that information
// for the sdk snapshot.
filteredInput := b.createHiddenAPIFlagInput(ctx, contentsForSdkSnapshot, fragments)
// Gather information about the boot dex files for the boot libraries provided by this fragment.
filteredBootDexInfoByModule := extractBootDexInfoFromModules(ctx, contentsForSdkSnapshot)
flagOutput = b.generateHiddenApiFlagRules(ctx, contentsForSdkSnapshot, filteredInput, filteredBootDexInfoByModule, "-for-sdk-snapshot")
flagFilesByCategory = filteredInput.FlagFilesByCategory
} else {
// The sdk snapshot has the same contents as the runtime fragment so reuse that information.
flagFilesByCategory = input.FlagFilesByCategory
}
// Make the information available for the sdk snapshot.
ctx.SetProvider(HiddenAPIInfoForSdkProvider, HiddenAPIInfoForSdk{
@@ -1219,7 +1253,7 @@ func (module *PrebuiltBootclasspathFragmentModule) Name() string {
}
// produceHiddenAPIOutput returns a path to the prebuilt all-flags.csv or nil if none is specified.
func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput {
func (module *PrebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput {
pathForOptionalSrc := func(src *string, defaultPath android.Path) android.Path {
if src == nil {
return defaultPath