Use java_sdk_library in bootclasspath_fragment contents as stubs

A java_sdk_library specified in the bootclasspath_fragment contents
must be providing APIs for the bootclasspath_fragment and so must be
treated as if they were specified in the stub_libs. This avoids having
to specify them in both contents and stub_libs.

Bug: 179354495
Test: m nothing
Change-Id: I535065ee1a79b439e2676f35e06a75d4626adcaf
This commit is contained in:
Paul Duffin
2021-05-13 21:25:05 +01:00
parent dfa1083fee
commit 34827d4c0e
4 changed files with 48 additions and 12 deletions

View File

@@ -91,6 +91,9 @@ func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
type BootclasspathFragmentCoverageAffectedProperties struct { type BootclasspathFragmentCoverageAffectedProperties struct {
// The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library. // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
// //
// A java_sdk_library specified here will also be treated as if it was specified on the stub_libs
// property.
//
// The order of this list matters as it is the order that is used in the bootclasspath. // The order of this list matters as it is the order that is used in the bootclasspath.
Contents []string Contents []string
@@ -453,7 +456,7 @@ func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleCont
func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module) { func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module) {
// Convert the kind specific lists of modules into kind specific lists of jars. // Convert the kind specific lists of modules into kind specific lists of jars.
stubJarsByKind := hiddenAPIGatherStubLibDexJarPaths(ctx) stubJarsByKind := hiddenAPIGatherStubLibDexJarPaths(ctx, contents)
// Store the information for use by other modules. // Store the information for use by other modules.
bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: stubJarsByKind} bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: stubJarsByKind}

View File

@@ -204,7 +204,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
prepareForTestWithBootclasspathFragment, prepareForTestWithBootclasspathFragment,
PrepareForTestWithJavaSdkLibraryFiles, PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("mysdklibrary", "mycoreplatform"), FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
).RunTestWithBp(t, ` ).RunTestWithBp(t, `
bootclasspath_fragment { bootclasspath_fragment {
name: "myfragment", name: "myfragment",
@@ -212,7 +212,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
api: { api: {
stub_libs: [ stub_libs: [
"mystublib", "mystublib",
"mysdklibrary", "myothersdklibrary",
], ],
}, },
core_platform_api: { core_platform_api: {
@@ -236,6 +236,13 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
system: {enabled: true}, system: {enabled: true},
} }
java_sdk_library {
name: "myothersdklibrary",
srcs: ["a.java"],
shared_library: false,
public: {enabled: true},
}
java_sdk_library { java_sdk_library {
name: "mycoreplatform", name: "mycoreplatform",
srcs: ["a.java"], srcs: ["a.java"],
@@ -249,16 +256,23 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar" stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar"
// Check that SdkPublic uses public stubs. // Stubs jars for mysdklibrary
publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar" publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar"
android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{stubsJar, publicStubsJar}, info.stubJarsByKind[android.SdkPublic])
// Check that SdkSystem uses system stubs.
systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.system/android_common/dex/mysdklibrary.stubs.system.jar" systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.system/android_common/dex/mysdklibrary.stubs.system.jar"
android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{stubsJar, systemStubsJar}, info.stubJarsByKind[android.SdkSystem])
// Check that SdkTest also uses system stubs as the mysdklibrary does not provide test stubs. // Stubs jars for myothersdklibrary
android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{stubsJar, systemStubsJar}, info.stubJarsByKind[android.SdkTest]) 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])
// 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])
// 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])
// 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"

View File

@@ -123,8 +123,21 @@ func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, sdkKind
// hiddenAPIGatherStubLibDexJarPaths gathers the paths to the dex jars from the dependencies added // hiddenAPIGatherStubLibDexJarPaths gathers the paths to the dex jars from the dependencies added
// in hiddenAPIAddStubLibDependencies. // in hiddenAPIAddStubLibDependencies.
func hiddenAPIGatherStubLibDexJarPaths(ctx android.ModuleContext) map[android.SdkKind]android.Paths { func hiddenAPIGatherStubLibDexJarPaths(ctx android.ModuleContext, contents []android.Module) map[android.SdkKind]android.Paths {
m := map[android.SdkKind]android.Paths{} m := map[android.SdkKind]android.Paths{}
// If the contents includes any java_sdk_library modules then add them to the stubs.
for _, module := range contents {
if _, ok := module.(SdkLibraryDependency); ok {
for _, kind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkTest} {
dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, kind)
if dexJar != nil {
m[kind] = append(m[kind], dexJar)
}
}
}
}
ctx.VisitDirectDepsIf(isActiveModule, func(module android.Module) { ctx.VisitDirectDepsIf(isActiveModule, func(module android.Module) {
tag := ctx.OtherModuleDependencyTag(module) tag := ctx.OtherModuleDependencyTag(module)
if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok { if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok {
@@ -135,6 +148,12 @@ func hiddenAPIGatherStubLibDexJarPaths(ctx android.ModuleContext) map[android.Sd
} }
} }
}) })
// Normalize the paths, i.e. remove duplicates and sort.
for k, v := range m {
m[k] = android.SortedUniquePaths(v)
}
return m return m
} }

View File

@@ -377,7 +377,7 @@ func (b *platformBootclasspathModule) generateHiddenAPIStubFlagsRules(ctx androi
bootDexJars = append(bootDexJars, module.bootDexJar) bootDexJars = append(bootDexJars, module.bootDexJar)
} }
sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx) sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx, nil)
outputPath := hiddenAPISingletonPaths(ctx).stubFlags outputPath := hiddenAPISingletonPaths(ctx).stubFlags
rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths) rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths)