Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49eff1d1 authored by Paul Duffin's avatar Paul Duffin Committed by Android (Google) Code Review
Browse files

Merge changes I5459c56d,I9b5c7c74 into sc-dev

* changes:
  Remove bootclasspathApiInfo
  Fix hidden API flags in com.android.i18n
parents fa08e194 6a58cc94
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -235,12 +235,3 @@ func (p BootclasspathAPIProperties) sdkKindToStubLibs() map[android.SdkKind][]st
	m[android.SdkCorePlatform] = p.Core_platform_api.Stub_libs
	return m
}

// bootclasspathApiInfo contains paths resolved from BootclasspathAPIProperties
type bootclasspathApiInfo struct {
	// stubJarsByKind maps from the android.SdkKind to the paths containing dex stub jars for each
	// kind.
	stubJarsByKind map[android.SdkKind]android.Paths
}

var bootclasspathApiInfoProvider = blueprint.NewProvider(bootclasspathApiInfo{})
+26 −52
Original line number Diff line number Diff line
@@ -501,73 +501,47 @@ func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleCont
	return imageConfig
}

// canPerformHiddenAPIProcessing determines whether hidden API processing should be performed.
//
// A temporary workaround to avoid existing bootclasspath_fragments that do not provide the
// appropriate information needed for hidden API processing breaking the build.
// TODO(b/179354495): Remove this workaround.
func (b *BootclasspathFragmentModule) canPerformHiddenAPIProcessing(ctx android.ModuleContext) bool {
	// Hidden API processing is always enabled in tests.
	if ctx.Config().TestProductVariables != nil {
		return true
	}
	// A module that has fragments should have access to the information it needs in order to perform
	// hidden API processing.
	if len(b.properties.Fragments) != 0 {
		return true
	}

	// The art bootclasspath fragment does not depend on any other fragments but already supports
	// hidden API processing.
	imageName := proptools.String(b.properties.Image_name)
	if imageName == "art" {
		return true
	}

	// Disable it for everything else.
	return false
}

// generateHiddenAPIBuildActions generates all the hidden API related build rules.
func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module) *HiddenAPIFlagOutput {

	// A temporary workaround to avoid existing bootclasspath_fragments that do not provide the
	// appropriate information needed for hidden API processing breaking the build.
	if !b.canPerformHiddenAPIProcessing(ctx) {
		// Nothing to do.
		return nil
	}

	// Create hidden API input structure.
	input := b.createHiddenAPIFlagInput(ctx, contents)

	// Performing hidden API processing without stubs is not supported and it is unlikely to ever be
	// required as the whole point of adding something to the bootclasspath fragment is to add it to
	// the bootclasspath in order to be used by something else in the system. Without any stubs it
	// cannot do that.
	if len(input.StubDexJarsByKind) == 0 {
		return nil
	}

	// Store the information for use by other modules.
	bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: input.StubDexJarsByKind}
	ctx.SetProvider(bootclasspathApiInfoProvider, bootclasspathApiInfo)
	var output *HiddenAPIFlagOutput

	// Hidden API processing is conditional as a temporary workaround as not all
	// bootclasspath_fragments provide the appropriate information needed for hidden API processing
	// which leads to breakages of the build.
	// TODO(b/179354495): Stop hidden API processing being conditional once all bootclasspath_fragment
	//  modules have been updated to support it.
	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.
		common := ctx.Module().(commonBootclasspathFragment)
	output := common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, input)
		output = common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, input)
	}

	// Initialize a HiddenAPIInfo structure and provide it for use by other modules.
	// Initialize a HiddenAPIInfo structure.
	hiddenAPIInfo := HiddenAPIInfo{
		// The monolithic hidden API processing needs access to the flag files from all the fragments.
		// The monolithic hidden API processing needs access to the flag files that override the default
		// flags from all the fragments whether or not they actually perform their own hidden API flag
		// generation. That is because the monolithic hidden API processing uses those flag files to
		// perform its own flag generation.
		FlagFilesByCategory: input.FlagFilesByCategory,

		// Make these available for tests.
		StubDexJarsByKind: input.StubDexJarsByKind,
	}

	if output != nil {
		// The monolithic hidden API processing also needs access to all the output files produced by
		// hidden API processing of this fragment.
		HiddenAPIFlagOutput: *output,
		hiddenAPIInfo.HiddenAPIFlagOutput = *output
	}

	//  Provide it for use by other modules.
	ctx.SetProvider(HiddenAPIInfoProvider, hiddenAPIInfo)

	return output
+5 −5
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
	`)

	fragment := result.Module("myfragment", "android_common")
	info := result.ModuleProvider(fragment, bootclasspathApiInfoProvider).(bootclasspathApiInfo)
	info := result.ModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo)

	stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar"

@@ -264,17 +264,17 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
	otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar"

	// Check that SdkPublic uses public stubs for all sdk libraries.
	android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.stubJarsByKind[android.SdkPublic])
	android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.StubDexJarsByKind[android.SdkPublic])

	// Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary
	// as it does not provide system stubs.
	android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.stubJarsByKind[android.SdkSystem])
	android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.StubDexJarsByKind[android.SdkSystem])

	// Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs
	// and public stubs for myothersdklibrary as it does not provide test stubs either.
	android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.stubJarsByKind[android.SdkTest])
	android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.StubDexJarsByKind[android.SdkTest])

	// Check that SdkCorePlatform uses public stubs from the mycoreplatform library.
	corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar"
	android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.stubJarsByKind[android.SdkCorePlatform])
	android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.StubDexJarsByKind[android.SdkCorePlatform])
}
+40 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import (

	"android/soong/android"
	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

// Contains support for processing hiddenAPI in a modular fashion.
@@ -347,6 +348,9 @@ type HiddenAPIInfo struct {
	// that category.
	FlagFilesByCategory FlagFilesByCategory

	// The paths to the stub dex jars for each of the android.SdkKind in hiddenAPIRelevantSdkKinds.
	StubDexJarsByKind StubDexJarsByKind

	// The output from the hidden API processing needs to be made available to other modules.
	HiddenAPIFlagOutput
}
@@ -395,6 +399,42 @@ func newHiddenAPIFlagInput() HiddenAPIFlagInput {
	return input
}

// canPerformHiddenAPIProcessing determines whether hidden API processing should be performed.
//
// A temporary workaround to avoid existing bootclasspath_fragments that do not provide the
// appropriate information needed for hidden API processing breaking the build.
// TODO(b/179354495): Remove this workaround.
func (i *HiddenAPIFlagInput) canPerformHiddenAPIProcessing(ctx android.ModuleContext, properties bootclasspathFragmentProperties) bool {
	// Performing hidden API processing without stubs is not supported and it is unlikely to ever be
	// required as the whole point of adding something to the bootclasspath fragment is to add it to
	// the bootclasspath in order to be used by something else in the system. Without any stubs it
	// cannot do that.
	if len(i.StubDexJarsByKind) == 0 {
		return false
	}

	// Hidden API processing is always enabled in tests.
	if ctx.Config().TestProductVariables != nil {
		return true
	}

	// A module that has fragments should have access to the information it needs in order to perform
	// hidden API processing.
	if len(properties.Fragments) != 0 {
		return true
	}

	// The art bootclasspath fragment does not depend on any other fragments but already supports
	// hidden API processing.
	imageName := proptools.String(properties.Image_name)
	if imageName == "art" {
		return true
	}

	// Disable it for everything else.
	return false
}

// gatherStubLibInfo gathers information from the stub libs needed by hidden API processing from the
// dependencies added in hiddenAPIAddStubLibDependencies.
//
+16 −5
Original line number Diff line number Diff line
@@ -70,11 +70,22 @@ func newMonolithicHiddenAPIInfo(ctx android.ModuleContext, flagFilesByCategory F
// append appends all the files from the supplied info to the corresponding files in this struct.
func (i *MonolithicHiddenAPIInfo) append(other *HiddenAPIInfo) {
	i.FlagsFilesByCategory.append(other.FlagFilesByCategory)
	i.StubFlagsPaths = append(i.StubFlagsPaths, other.StubFlagsPath)
	i.AnnotationFlagsPaths = append(i.AnnotationFlagsPaths, other.AnnotationFlagsPath)
	i.MetadataPaths = append(i.MetadataPaths, other.MetadataPath)
	i.IndexPaths = append(i.IndexPaths, other.IndexPath)
	i.AllFlagsPaths = append(i.AllFlagsPaths, other.AllFlagsPath)

	// The output may not be set if the bootclasspath_fragment has not yet been updated to support
	// hidden API processing.
	// TODO(b/179354495): Switch back to append once all bootclasspath_fragment modules have been
	//  updated to support hidden API processing properly.
	appendIfNotNil := func(paths android.Paths, path android.Path) android.Paths {
		if path == nil {
			return paths
		}
		return append(paths, path)
	}
	i.StubFlagsPaths = appendIfNotNil(i.StubFlagsPaths, other.StubFlagsPath)
	i.AnnotationFlagsPaths = appendIfNotNil(i.AnnotationFlagsPaths, other.AnnotationFlagsPath)
	i.MetadataPaths = appendIfNotNil(i.MetadataPaths, other.MetadataPath)
	i.IndexPaths = appendIfNotNil(i.IndexPaths, other.IndexPath)
	i.AllFlagsPaths = appendIfNotNil(i.AllFlagsPaths, other.AllFlagsPath)
}

// dedup removes duplicates in all the paths, while maintaining the order in which they were