Stop exporting systemserverclasspath_fragment when targeting S

Previously, when targeting the S release the generated sdk snapshot
would contain prebuilt_systemserverclasspath_fragment modules even
though they were only added in T.

This allows SdkMemberTypes to specify the set of target build releases
they support and ignores them when targeting an unsupported target
build release.

Test: m nothing
      packages/modules/common/build/mainline_modules_sdks.sh
      # Check that the for-S-build snapshots do not include SSCPFs.
Bug: 237718221
Change-Id: I2df08c2fcebf9b866695d691572a9d3783758b17
This commit is contained in:
Paul Duffin 2022-07-01 15:56:06 +00:00
parent e3cf1abefc
commit f861df7907
5 changed files with 82 additions and 7 deletions

View file

@ -661,6 +661,10 @@ type SdkMemberType interface {
// an Android.bp file.
RequiresBpProperty() bool
// SupportedBuildReleases returns the string representation of a set of target build releases that
// support this member type.
SupportedBuildReleases() string
// UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
// false otherwise.
UsableWithSdkAndSdkSnapshot() bool
@ -773,6 +777,11 @@ type SdkMemberTypeBase struct {
// property to be specifiable in an Android.bp file.
BpPropertyNotRequired bool
// The name of the first targeted build release.
//
// If not specified then it is assumed to be available on all targeted build releases.
SupportedBuildReleaseSpecification string
SupportsSdk bool
HostOsDependent bool
@ -793,6 +802,10 @@ func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
return !b.BpPropertyNotRequired
}
func (b *SdkMemberTypeBase) SupportedBuildReleases() string {
return b.SupportedBuildReleaseSpecification
}
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
return b.SupportsSdk
}

View file

@ -164,6 +164,9 @@ var (
android.SdkMemberTypeBase{
PropertyName: "java_systemserver_libs",
SupportsSdk: true,
// This was only added in Tiramisu.
SupportedBuildReleaseSpecification: "Tiramisu+",
},
func(ctx android.SdkMemberContext, j *Library) android.Path {
// Java systemserver libs are only provided in the SDK to provide access to their dex

View file

@ -28,6 +28,9 @@ func init() {
SdkMemberTypeBase: android.SdkMemberTypeBase{
PropertyName: "systemserverclasspath_fragments",
SupportsSdk: true,
// This was only added in Tiramisu.
SupportedBuildReleaseSpecification: "Tiramisu+",
},
})
}

View file

@ -22,13 +22,16 @@ import (
"android/soong/java"
)
func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedSdkSnapshot string) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
java.PrepareForTestWithJavaDefaultModules,
java.PrepareForTestWithJavaSdkLibraryFiles,
java.FixtureWithLastReleaseApis("mysdklibrary"),
dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
android.FixtureModifyEnv(func(env map[string]string) {
env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease
}),
prepareForSdkTestWithApex,
android.FixtureWithRootAndroidBp(`
@ -83,7 +86,34 @@ func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
).RunTest(t)
CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
checkAndroidBpContents(expectedSdkSnapshot),
)
}
func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
t.Run("target-s", func(t *testing.T) {
testSnapshotWithSystemServerClasspathFragment(t, "S", `
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
name: "mysdklibrary",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
shared_library: false,
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
current_api: "sdk_library/public/mysdklibrary.txt",
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
sdk_version: "current",
},
}
`)
})
t.Run("target-t", func(t *testing.T) {
testSnapshotWithSystemServerClasspathFragment(t, "Tiramisu", `
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
@ -120,6 +150,6 @@ prebuilt_systemserverclasspath_fragment {
"mysdklibrary",
],
}
`),
)
`)
})
}

View file

@ -239,7 +239,7 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) {
// Finally, the member type slices are concatenated together to form a single slice. The order in
// which they are concatenated is the order in which the member types were registered in the
// android.SdkMemberTypesRegistry.
func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) []*sdkMember {
func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, targetBuildRelease *buildRelease, memberVariantDeps []sdkMemberVariantDep) []*sdkMember {
byType := make(map[android.SdkMemberType][]*sdkMember)
byName := make(map[string]*sdkMember)
@ -268,13 +268,39 @@ func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, mem
}
var members []*sdkMember
for _, memberListProperty := range s.memberTypeListProperties() {
membersOfType := byType[memberListProperty.memberType]
memberType := memberListProperty.memberType
if !isMemberTypeSupportedByTargetBuildRelease(memberType, targetBuildRelease) {
continue
}
membersOfType := byType[memberType]
members = append(members, membersOfType...)
}
return members
}
// isMemberTypeSupportedByTargetBuildRelease returns true if the member type is supported by the
// target build release.
func isMemberTypeSupportedByTargetBuildRelease(memberType android.SdkMemberType, targetBuildRelease *buildRelease) bool {
supportedByTargetBuildRelease := true
supportedBuildReleases := memberType.SupportedBuildReleases()
if supportedBuildReleases == "" {
supportedBuildReleases = "S+"
}
set, err := parseBuildReleaseSet(supportedBuildReleases)
if err != nil {
panic(fmt.Errorf("member type %s has invalid supported build releases %q: %s",
memberType.SdkPropertyName(), supportedBuildReleases, err))
}
if !set.contains(targetBuildRelease) {
supportedByTargetBuildRelease = false
}
return supportedByTargetBuildRelease
}
func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
for _, v := range variants {
if v == newVariant {
@ -401,7 +427,7 @@ be unnecessary as every module in the sdk already has its own licenses property.
// Group the variants for each member module together and then group the members of each member
// type together.
members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps)
members := s.groupMemberVariantsByMemberThenType(ctx, targetBuildRelease, memberVariantDeps)
// Create the prebuilt modules for each of the member modules.
traits := s.gatherTraits()