Merge "Add HiddenAPIScope to replace use of SdkKind" am: e09a6692de

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

Change-Id: Ief229f426fccd1d5abd5a5d2b8a4676593d46559
This commit is contained in:
Paul Duffin 2021-06-25 11:14:48 +00:00 committed by Automerger Merge Worker
commit 7f5954a225
6 changed files with 182 additions and 113 deletions

View file

@ -216,9 +216,9 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
`, `,
) )
checkSdkKindStubs := func(message string, info java.HiddenAPIInfo, kind android.SdkKind, expectedPaths ...string) { checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
t.Helper() t.Helper()
android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, kind), expectedPaths, info.TransitiveStubDexJarsByKind[kind]) android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, info.TransitiveStubDexJarsByScope[apiScope])
} }
// Check stub dex paths exported by art. // Check stub dex paths exported by art.
@ -229,10 +229,10 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar" bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
checkSdkKindStubs("art", artInfo, android.SdkPublic, bazPublicStubs) checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
checkSdkKindStubs("art", artInfo, android.SdkSystem, bazSystemStubs) checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
checkSdkKindStubs("art", artInfo, android.SdkTest, bazTestStubs) checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
checkSdkKindStubs("art", artInfo, android.SdkCorePlatform) checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
// Check stub dex paths exported by other. // Check stub dex paths exported by other.
otherFragment := result.Module("other-bootclasspath-fragment", "android_common") otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
@ -241,10 +241,10 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
checkSdkKindStubs("other", otherInfo, android.SdkPublic, bazPublicStubs, fooPublicStubs) checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
checkSdkKindStubs("other", otherInfo, android.SdkSystem, bazSystemStubs, fooSystemStubs) checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
checkSdkKindStubs("other", otherInfo, android.SdkTest, bazTestStubs, fooSystemStubs) checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
checkSdkKindStubs("other", otherInfo, android.SdkCorePlatform) checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
} }
func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) { func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {

View file

@ -227,13 +227,13 @@ type BootclasspathAPIProperties struct {
Core_platform_api BootclasspathNestedAPIProperties Core_platform_api BootclasspathNestedAPIProperties
} }
// sdkKindToStubLibs calculates the stub library modules for each relevant android.SdkKind from the // apiScopeToStubLibs calculates the stub library modules for each relevant *HiddenAPIScope from the
// Stub_libs properties. // Stub_libs properties.
func (p BootclasspathAPIProperties) sdkKindToStubLibs() map[android.SdkKind][]string { func (p BootclasspathAPIProperties) apiScopeToStubLibs() map[*HiddenAPIScope][]string {
m := map[android.SdkKind][]string{} m := map[*HiddenAPIScope][]string{}
for _, kind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkTest} { for _, apiScope := range hiddenAPISdkLibrarySupportedScopes {
m[kind] = p.Api.Stub_libs m[apiScope] = p.Api.Stub_libs
} }
m[android.SdkCorePlatform] = p.Core_platform_api.Stub_libs m[CorePlatformHiddenAPIScope] = p.Core_platform_api.Stub_libs
return m return m
} }

View file

@ -121,6 +121,7 @@ type bootclasspathFragmentProperties struct {
BootclasspathFragmentCoverageAffectedProperties BootclasspathFragmentCoverageAffectedProperties
Coverage BootclasspathFragmentCoverageAffectedProperties Coverage BootclasspathFragmentCoverageAffectedProperties
// Hidden API related properties.
Hidden_api HiddenAPIFlagFileProperties Hidden_api HiddenAPIFlagFileProperties
// Properties that allow a fragment to depend on other fragments. This is needed for hidden API // Properties that allow a fragment to depend on other fragments. This is needed for hidden API
@ -378,7 +379,7 @@ func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpM
func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) { func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
// Add dependencies onto all the modules that provide the API stubs for classes on this // Add dependencies onto all the modules that provide the API stubs for classes on this
// bootclasspath fragment. // bootclasspath fragment.
hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs()) hiddenAPIAddStubLibDependencies(ctx, b.properties.apiScopeToStubLibs())
if SkipDexpreoptBootJars(ctx) { if SkipDexpreoptBootJars(ctx) {
return return
@ -595,7 +596,7 @@ func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.
// Other bootclasspath_fragments that depend on this need the transitive set of stub dex jars // Other bootclasspath_fragments that depend on this need the transitive set of stub dex jars
// from this to resolve any references from their code to classes provided by this fragment // from this to resolve any references from their code to classes provided by this fragment
// and the fragments this depends upon. // and the fragments this depends upon.
TransitiveStubDexJarsByKind: input.transitiveStubDexJarsByKind(), TransitiveStubDexJarsByScope: input.transitiveStubDexJarsByScope(),
} }
// The monolithic hidden API processing also needs access to all the output files produced by // The monolithic hidden API processing also needs access to all the output files produced by
@ -640,7 +641,7 @@ func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.Modul
input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api)
// Store the stub dex jars from this module's fragment dependencies. // Store the stub dex jars from this module's fragment dependencies.
input.DependencyStubDexJarsByKind = dependencyHiddenApiInfo.TransitiveStubDexJarsByKind input.DependencyStubDexJarsByScope = dependencyHiddenApiInfo.TransitiveStubDexJarsByScope
return input return input
} }

View file

@ -245,17 +245,17 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar" otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs/android_common/dex/myothersdklibrary.stubs.jar"
// Check that SdkPublic uses public stubs for all sdk libraries. // Check that SdkPublic uses public stubs for all sdk libraries.
android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByKind[android.SdkPublic]) android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope[PublicHiddenAPIScope])
// Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary // Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary
// as it does not provide system stubs. // as it does not provide system stubs.
android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByKind[android.SdkSystem]) android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope[SystemHiddenAPIScope])
// Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs // 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. // 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.TransitiveStubDexJarsByKind[android.SdkTest]) android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope[TestHiddenAPIScope])
// Check that SdkCorePlatform uses public stubs from the mycoreplatform library. // Check that SdkCorePlatform uses public stubs from the mycoreplatform library.
corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar" corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar"
android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.TransitiveStubDexJarsByKind[android.SdkCorePlatform]) android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.TransitiveStubDexJarsByScope[CorePlatformHiddenAPIScope])
} }

View file

@ -25,9 +25,97 @@ import (
// Contains support for processing hiddenAPI in a modular fashion. // Contains support for processing hiddenAPI in a modular fashion.
// HiddenAPIScope encapsulates all the information that the hidden API processing needs about API
// scopes, i.e. what is called android.SdkKind and apiScope. It does not just use those as they do
// not provide the information needed by hidden API processing.
type HiddenAPIScope struct {
// The name of the scope, used for debug purposes.
name string
// The corresponding android.SdkKind, used for retrieving paths from java_sdk_library* modules.
sdkKind android.SdkKind
// The option needed to passed to "hiddenapi list".
hiddenAPIListOption string
}
// initHiddenAPIScope initializes the scope.
func initHiddenAPIScope(apiScope *HiddenAPIScope) *HiddenAPIScope {
return apiScope
}
func (l *HiddenAPIScope) String() string {
return fmt.Sprintf("HiddenAPIScope{%s}", l.name)
}
var (
PublicHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{
name: "public",
sdkKind: android.SdkPublic,
hiddenAPIListOption: "--public-stub-classpath",
})
SystemHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{
name: "system",
sdkKind: android.SdkSystem,
hiddenAPIListOption: "--system-stub-classpath",
})
TestHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{
name: "test",
sdkKind: android.SdkTest,
hiddenAPIListOption: "--test-stub-classpath",
})
CorePlatformHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{
name: "core-platform",
sdkKind: android.SdkCorePlatform,
hiddenAPIListOption: "--core-platform-stub-classpath",
})
// hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden
// API processing.
//
// These are roughly in order from narrowest API surface to widest. Widest means the API stubs
// with the biggest API surface, e.g. test is wider than system is wider than public.
//
// Core platform is considered wider than system because those modules that provide core platform
// APIs either do not have any system APIs at all, or if they do it is because the core platform
// API is being converted to system APIs. In either case the system API is a subset of core
// platform API.
//
// This is not strictly in order from narrowest to widest as the Test API is wider than system but
// is neither wider or narrower than the core platform API. However, this works well enough at the
// moment.
// TODO(b/191644675): Correctly reflect the sub/superset relationships between APIs.
hiddenAPIScopes = []*HiddenAPIScope{
PublicHiddenAPIScope,
SystemHiddenAPIScope,
TestHiddenAPIScope,
CorePlatformHiddenAPIScope,
}
// The HiddenAPIScope instances that are supported by a java_sdk_library.
//
// CorePlatformHiddenAPIScope is not used as the java_sdk_library does not have special support
// for core_platform API, instead it is implemented as a customized form of PublicHiddenAPIScope.
hiddenAPISdkLibrarySupportedScopes = []*HiddenAPIScope{
PublicHiddenAPIScope,
SystemHiddenAPIScope,
TestHiddenAPIScope,
}
// The HiddenAPIScope instances that are supported by the `hiddenapi list`.
hiddenAPIFlagScopes = []*HiddenAPIScope{
PublicHiddenAPIScope,
SystemHiddenAPIScope,
TestHiddenAPIScope,
CorePlatformHiddenAPIScope,
}
)
type hiddenAPIStubsDependencyTag struct { type hiddenAPIStubsDependencyTag struct {
blueprint.BaseDependencyTag blueprint.BaseDependencyTag
sdkKind android.SdkKind
// The api scope for which this dependency was added.
apiScope *HiddenAPIScope
} }
func (b hiddenAPIStubsDependencyTag) ExcludeFromApexContents() { func (b hiddenAPIStubsDependencyTag) ExcludeFromApexContents() {
@ -65,24 +153,9 @@ var _ android.ReplaceSourceWithPrebuilt = hiddenAPIStubsDependencyTag{}
var _ android.ExcludeFromApexContentsTag = hiddenAPIStubsDependencyTag{} var _ android.ExcludeFromApexContentsTag = hiddenAPIStubsDependencyTag{}
var _ android.SdkMemberTypeDependencyTag = hiddenAPIStubsDependencyTag{} var _ android.SdkMemberTypeDependencyTag = hiddenAPIStubsDependencyTag{}
// hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden
// API processing.
//
// These are in order from narrowest API surface to widest. Widest means the API stubs with the
// biggest API surface, e.g. test is wider than system is wider than public. Core platform is
// considered wider than test even though it has no relationship with test because the libraries
// that provide core platform API don't provide test. While the core platform API is being converted
// to a system API the system API is still a subset of core platform.
var hiddenAPIRelevantSdkKinds = []android.SdkKind{
android.SdkPublic,
android.SdkSystem,
android.SdkTest,
android.SdkCorePlatform,
}
// hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs // hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs
// needed to produce the hidden API monolithic stub flags file. // needed to produce the hidden API monolithic stub flags file.
func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[android.SdkKind][]string { func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[*HiddenAPIScope][]string {
var publicStubModules []string var publicStubModules []string
var systemStubModules []string var systemStubModules []string
var testStubModules []string var testStubModules []string
@ -115,22 +188,22 @@ func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[android
testStubModules = append(testStubModules, "jacoco-stubs") testStubModules = append(testStubModules, "jacoco-stubs")
} }
m := map[android.SdkKind][]string{} m := map[*HiddenAPIScope][]string{}
m[android.SdkPublic] = publicStubModules m[PublicHiddenAPIScope] = publicStubModules
m[android.SdkSystem] = systemStubModules m[SystemHiddenAPIScope] = systemStubModules
m[android.SdkTest] = testStubModules m[TestHiddenAPIScope] = testStubModules
m[android.SdkCorePlatform] = corePlatformStubModules m[CorePlatformHiddenAPIScope] = corePlatformStubModules
return m return m
} }
// hiddenAPIAddStubLibDependencies adds dependencies onto the modules specified in // hiddenAPIAddStubLibDependencies adds dependencies onto the modules specified in
// sdkKindToStubLibModules. It adds them in a well known order and uses an SdkKind specific tag to // apiScopeToStubLibModules. It adds them in a well known order and uses a HiddenAPIScope specific
// identify the source of the dependency. // tag to identify the source of the dependency.
func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, sdkKindToStubLibModules map[android.SdkKind][]string) { func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, apiScopeToStubLibModules map[*HiddenAPIScope][]string) {
module := ctx.Module() module := ctx.Module()
for _, sdkKind := range hiddenAPIRelevantSdkKinds { for _, apiScope := range hiddenAPIScopes {
modules := sdkKindToStubLibModules[sdkKind] modules := apiScopeToStubLibModules[apiScope]
ctx.AddDependency(module, hiddenAPIStubsDependencyTag{sdkKind: sdkKind}, modules...) ctx.AddDependency(module, hiddenAPIStubsDependencyTag{apiScope: apiScope}, modules...)
} }
} }
@ -153,13 +226,6 @@ func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.
return dexJar return dexJar
} }
var sdkKindToHiddenapiListOption = map[android.SdkKind]string{
android.SdkPublic: "public-stub-classpath",
android.SdkSystem: "system-stub-classpath",
android.SdkTest: "test-stub-classpath",
android.SdkCorePlatform: "core-platform-stub-classpath",
}
// ruleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file. // ruleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file.
// //
// The rule is initialized but not built so that the caller can modify it and select an appropriate // The rule is initialized but not built so that the caller can modify it and select an appropriate
@ -172,11 +238,11 @@ func ruleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, outputPath
// Find the widest API stubs provided by the fragments on which this depends, if any. // Find the widest API stubs provided by the fragments on which this depends, if any.
var dependencyStubDexJars android.Paths var dependencyStubDexJars android.Paths
for i := len(hiddenAPIRelevantSdkKinds) - 1; i >= 0; i-- { for i := len(hiddenAPIScopes) - 1; i >= 0; i-- {
kind := hiddenAPIRelevantSdkKinds[i] apiScope := hiddenAPIScopes[i]
stubsForKind := input.DependencyStubDexJarsByKind[kind] stubsForAPIScope := input.DependencyStubDexJarsByScope[apiScope]
if len(stubsForKind) != 0 { if len(stubsForAPIScope) != 0 {
dependencyStubDexJars = stubsForKind dependencyStubDexJars = stubsForAPIScope
break break
} }
} }
@ -187,16 +253,17 @@ func ruleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, outputPath
FlagForEachInput("--dependency-stub-dex=", dependencyStubDexJars). FlagForEachInput("--dependency-stub-dex=", dependencyStubDexJars).
FlagForEachInput("--boot-dex=", bootDexJars) FlagForEachInput("--boot-dex=", bootDexJars)
// Iterate over the sdk kinds in a fixed order. // Iterate over the api scopes in a fixed order.
for _, sdkKind := range hiddenAPIRelevantSdkKinds { for _, apiScope := range hiddenAPIFlagScopes {
// Merge in the stub dex jar paths for this kind from the fragments on which it depends. They // Merge in the stub dex jar paths for this api scope from the fragments on which it depends.
// will be needed to resolve dependencies from this fragment's stubs to classes in the other // They will be needed to resolve dependencies from this fragment's stubs to classes in the
// fragment's APIs. // other fragment's APIs.
dependencyPaths := input.DependencyStubDexJarsByKind[sdkKind] var paths android.Paths
paths := append(dependencyPaths, input.StubDexJarsByKind[sdkKind]...) paths = append(paths, input.DependencyStubDexJarsByScope[apiScope]...)
paths = append(paths, input.StubDexJarsByScope[apiScope]...)
if len(paths) > 0 { if len(paths) > 0 {
option := sdkKindToHiddenapiListOption[sdkKind] option := apiScope.hiddenAPIListOption
command.FlagWithInputList("--"+option+"=", paths, ":") command.FlagWithInputList(option+"=", paths, ":")
} }
} }
@ -377,8 +444,8 @@ type HiddenAPIInfo struct {
// that category. // that category.
FlagFilesByCategory FlagFilesByCategory FlagFilesByCategory FlagFilesByCategory
// The paths to the stub dex jars for each of the android.SdkKind in hiddenAPIRelevantSdkKinds. // The paths to the stub dex jars for each of the *HiddenAPIScope in hiddenAPIScopes.
TransitiveStubDexJarsByKind StubDexJarsByKind TransitiveStubDexJarsByScope StubDexJarsByScope
// The output from the hidden API processing needs to be made available to other modules. // The output from the hidden API processing needs to be made available to other modules.
HiddenAPIFlagOutput HiddenAPIFlagOutput
@ -386,8 +453,8 @@ type HiddenAPIInfo struct {
func newHiddenAPIInfo() *HiddenAPIInfo { func newHiddenAPIInfo() *HiddenAPIInfo {
info := HiddenAPIInfo{ info := HiddenAPIInfo{
FlagFilesByCategory: FlagFilesByCategory{}, FlagFilesByCategory: FlagFilesByCategory{},
TransitiveStubDexJarsByKind: StubDexJarsByKind{}, TransitiveStubDexJarsByScope: StubDexJarsByScope{},
} }
return &info return &info
} }
@ -398,33 +465,33 @@ func (i *HiddenAPIInfo) mergeFromFragmentDeps(ctx android.ModuleContext, fragmen
for _, fragment := range fragments { for _, fragment := range fragments {
if ctx.OtherModuleHasProvider(fragment, HiddenAPIInfoProvider) { if ctx.OtherModuleHasProvider(fragment, HiddenAPIInfoProvider) {
info := ctx.OtherModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo) info := ctx.OtherModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo)
i.TransitiveStubDexJarsByKind.append(info.TransitiveStubDexJarsByKind) i.TransitiveStubDexJarsByScope.append(info.TransitiveStubDexJarsByScope)
} }
} }
// Dedup and sort paths. // Dedup and sort paths.
i.TransitiveStubDexJarsByKind.dedupAndSort() i.TransitiveStubDexJarsByScope.dedupAndSort()
} }
var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{})
// StubDexJarsByKind maps an android.SdkKind to the paths to stub dex jars appropriate for that // StubDexJarsByScope maps a *HiddenAPIScope to the paths to stub dex jars appropriate for that
// level. See hiddenAPIRelevantSdkKinds for a list of the acceptable android.SdkKind values. // scope. See hiddenAPIScopes for a list of the acceptable *HiddenAPIScope values.
type StubDexJarsByKind map[android.SdkKind]android.Paths type StubDexJarsByScope map[*HiddenAPIScope]android.Paths
// append appends the supplied kind specific stub dex jar pargs to the corresponding kind in this // append appends the API scope specific stub dex jar args to the corresponding scope in this
// map. // map.
func (s StubDexJarsByKind) append(other StubDexJarsByKind) { func (s StubDexJarsByScope) append(other StubDexJarsByScope) {
for _, kind := range hiddenAPIRelevantSdkKinds { for _, scope := range hiddenAPIScopes {
s[kind] = append(s[kind], other[kind]...) s[scope] = append(s[scope], other[scope]...)
} }
} }
// dedupAndSort removes duplicates in the stub dex jar paths and sorts them into a consistent and // dedupAndSort removes duplicates in the stub dex jar paths and sorts them into a consistent and
// deterministic order. // deterministic order.
func (s StubDexJarsByKind) dedupAndSort() { func (s StubDexJarsByScope) dedupAndSort() {
for kind, paths := range s { for apiScope, paths := range s {
s[kind] = android.SortedUniquePaths(paths) s[apiScope] = android.SortedUniquePaths(paths)
} }
} }
@ -435,14 +502,14 @@ type HiddenAPIFlagInput struct {
// from the stub dex files. // from the stub dex files.
FlagFilesByCategory FlagFilesByCategory FlagFilesByCategory FlagFilesByCategory
// StubDexJarsByKind contains the stub dex jars for different android.SdkKind and which determine // StubDexJarsByScope contains the stub dex jars for different *HiddenAPIScope and which determine
// the initial flags for each dex member. // the initial flags for each dex member.
StubDexJarsByKind StubDexJarsByKind StubDexJarsByScope StubDexJarsByScope
// DependencyStubDexJarsByKind contains the stub dex jars provided by the fragments on which this // DependencyStubDexJarsByScope contains the stub dex jars provided by the fragments on which this
// depends. It is the result of merging HiddenAPIInfo.TransitiveStubDexJarsByKind from each // depends. It is the result of merging HiddenAPIInfo.TransitiveStubDexJarsByScope from each
// fragment on which this depends. // fragment on which this depends.
DependencyStubDexJarsByKind StubDexJarsByKind DependencyStubDexJarsByScope StubDexJarsByScope
// RemovedTxtFiles is the list of removed.txt files provided by java_sdk_library modules that are // RemovedTxtFiles is the list of removed.txt files provided by java_sdk_library modules that are
// specified in the bootclasspath_fragment's stub_libs and contents properties. // specified in the bootclasspath_fragment's stub_libs and contents properties.
@ -452,8 +519,9 @@ type HiddenAPIFlagInput struct {
// newHiddenAPIFlagInput creates a new initialize HiddenAPIFlagInput struct. // newHiddenAPIFlagInput creates a new initialize HiddenAPIFlagInput struct.
func newHiddenAPIFlagInput() HiddenAPIFlagInput { func newHiddenAPIFlagInput() HiddenAPIFlagInput {
input := HiddenAPIFlagInput{ input := HiddenAPIFlagInput{
FlagFilesByCategory: FlagFilesByCategory{}, FlagFilesByCategory: FlagFilesByCategory{},
StubDexJarsByKind: StubDexJarsByKind{}, StubDexJarsByScope: StubDexJarsByScope{},
DependencyStubDexJarsByScope: StubDexJarsByScope{},
} }
return input return input
@ -469,7 +537,7 @@ func (i *HiddenAPIFlagInput) canPerformHiddenAPIProcessing(ctx android.ModuleCon
// required as the whole point of adding something to the bootclasspath fragment is to add it to // 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 // the bootclasspath in order to be used by something else in the system. Without any stubs it
// cannot do that. // cannot do that.
if len(i.StubDexJarsByKind) == 0 { if len(i.StubDexJarsByScope) == 0 {
return false return false
} }
@ -500,14 +568,15 @@ func (i *HiddenAPIFlagInput) canPerformHiddenAPIProcessing(ctx android.ModuleCon
// //
// That includes paths to the stub dex jars as well as paths to the *removed.txt files. // That includes paths to the stub dex jars as well as paths to the *removed.txt files.
func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, contents []android.Module) { func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, contents []android.Module) {
addFromModule := func(ctx android.ModuleContext, module android.Module, kind android.SdkKind) { addFromModule := func(ctx android.ModuleContext, module android.Module, apiScope *HiddenAPIScope) {
dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, kind) sdkKind := apiScope.sdkKind
dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, sdkKind)
if dexJar != nil { if dexJar != nil {
i.StubDexJarsByKind[kind] = append(i.StubDexJarsByKind[kind], dexJar) i.StubDexJarsByScope[apiScope] = append(i.StubDexJarsByScope[apiScope], dexJar)
} }
if sdkLibrary, ok := module.(SdkLibraryDependency); ok { if sdkLibrary, ok := module.(SdkLibraryDependency); ok {
removedTxtFile := sdkLibrary.SdkRemovedTxtFile(ctx, kind) removedTxtFile := sdkLibrary.SdkRemovedTxtFile(ctx, sdkKind)
i.RemovedTxtFiles = append(i.RemovedTxtFiles, removedTxtFile.AsPaths()...) i.RemovedTxtFiles = append(i.RemovedTxtFiles, removedTxtFile.AsPaths()...)
} }
} }
@ -515,11 +584,9 @@ func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, conten
// If the contents includes any java_sdk_library modules then add them to the stubs. // If the contents includes any java_sdk_library modules then add them to the stubs.
for _, module := range contents { for _, module := range contents {
if _, ok := module.(SdkLibraryDependency); ok { if _, ok := module.(SdkLibraryDependency); ok {
// Add information for every possible kind needed by hidden API. SdkCorePlatform is not used // Add information for every possible API scope needed by hidden API.
// as the java_sdk_library does not have special support for core_platform API, instead it is for _, apiScope := range hiddenAPISdkLibrarySupportedScopes {
// implemented as a customized form of SdkPublic. addFromModule(ctx, module, apiScope)
for _, kind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkTest} {
addFromModule(ctx, module, kind)
} }
} }
} }
@ -527,13 +594,14 @@ func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, conten
ctx.VisitDirectDeps(func(module android.Module) { ctx.VisitDirectDeps(func(module android.Module) {
tag := ctx.OtherModuleDependencyTag(module) tag := ctx.OtherModuleDependencyTag(module)
if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok { if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok {
kind := hiddenAPIStubsTag.sdkKind apiScope := hiddenAPIStubsTag.apiScope
addFromModule(ctx, module, kind) addFromModule(ctx, module, apiScope)
} }
}) })
// Normalize the paths, i.e. remove duplicates and sort. // Normalize the paths, i.e. remove duplicates and sort.
i.StubDexJarsByKind.dedupAndSort() i.StubDexJarsByScope.dedupAndSort()
i.DependencyStubDexJarsByScope.dedupAndSort()
i.RemovedTxtFiles = android.SortedUniquePaths(i.RemovedTxtFiles) i.RemovedTxtFiles = android.SortedUniquePaths(i.RemovedTxtFiles)
} }
@ -546,9 +614,9 @@ func (i *HiddenAPIFlagInput) extractFlagFilesFromProperties(ctx android.ModuleCo
} }
} }
func (i *HiddenAPIFlagInput) transitiveStubDexJarsByKind() StubDexJarsByKind { func (i *HiddenAPIFlagInput) transitiveStubDexJarsByScope() StubDexJarsByScope {
transitive := i.DependencyStubDexJarsByKind transitive := i.DependencyStubDexJarsByScope
transitive.append(i.StubDexJarsByKind) transitive.append(i.StubDexJarsByScope)
return transitive return transitive
} }

View file

@ -119,8 +119,8 @@ func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpM
} }
// Add dependencies onto the stub lib modules. // Add dependencies onto the stub lib modules.
sdkKindToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
hiddenAPIAddStubLibDependencies(ctx, sdkKindToStubLibModules) hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules)
} }
func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {