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:
@@ -895,3 +895,222 @@ my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
|
||||
snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
|
||||
)
|
||||
}
|
||||
|
||||
func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string,
|
||||
expectedSdkSnapshot string,
|
||||
expectedCopyRules string,
|
||||
expectedStubFlagsInputs []string,
|
||||
suffix string) {
|
||||
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForSdkTestWithJava,
|
||||
java.PrepareForTestWithJavaDefaultModules,
|
||||
java.PrepareForTestWithJavaSdkLibraryFiles,
|
||||
java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"),
|
||||
java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"),
|
||||
prepareForSdkTestWithApex,
|
||||
|
||||
// Add a platform_bootclasspath that depends on the fragment.
|
||||
fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
|
||||
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease,
|
||||
}),
|
||||
|
||||
android.FixtureWithRootAndroidBp(`
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
apexes: ["myapex"],
|
||||
}
|
||||
|
||||
apex {
|
||||
name: "myapex",
|
||||
key: "myapex.key",
|
||||
min_sdk_version: "S",
|
||||
bootclasspath_fragments: ["mybootclasspathfragment"],
|
||||
}
|
||||
|
||||
bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
apex_available: ["myapex"],
|
||||
contents: [
|
||||
"mysdklibrary",
|
||||
"mynewsdklibrary",
|
||||
],
|
||||
|
||||
hidden_api: {
|
||||
split_packages: [],
|
||||
},
|
||||
}
|
||||
|
||||
java_sdk_library {
|
||||
name: "mysdklibrary",
|
||||
apex_available: ["myapex"],
|
||||
srcs: ["Test.java"],
|
||||
shared_library: false,
|
||||
public: {enabled: true},
|
||||
min_sdk_version: "S",
|
||||
}
|
||||
|
||||
java_sdk_library {
|
||||
name: "mynewsdklibrary",
|
||||
apex_available: ["myapex"],
|
||||
srcs: ["Test.java"],
|
||||
compile_dex: true,
|
||||
public: {enabled: true},
|
||||
min_sdk_version: "Tiramisu",
|
||||
permitted_packages: ["mynewsdklibrary"],
|
||||
}
|
||||
`),
|
||||
).RunTest(t)
|
||||
|
||||
bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common")
|
||||
rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv")
|
||||
android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", expectedStubFlagsInputs, rule.Implicits)
|
||||
|
||||
CheckSnapshot(t, result, "mysdk", "",
|
||||
checkAndroidBpContents(expectedSdkSnapshot),
|
||||
checkAllCopyRules(expectedCopyRules),
|
||||
)
|
||||
}
|
||||
|
||||
func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) {
|
||||
t.Run("target S build", func(t *testing.T) {
|
||||
expectedSnapshot := `
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
prebuilt_bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["myapex"],
|
||||
contents: ["mysdklibrary"],
|
||||
hidden_api: {
|
||||
annotation_flags: "hiddenapi/annotation-flags.csv",
|
||||
metadata: "hiddenapi/metadata.csv",
|
||||
index: "hiddenapi/index.csv",
|
||||
stub_flags: "hiddenapi/stub-flags.csv",
|
||||
all_flags: "hiddenapi/all-flags.csv",
|
||||
},
|
||||
}
|
||||
|
||||
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",
|
||||
},
|
||||
}
|
||||
`
|
||||
expectedCopyRules := `
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv
|
||||
.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
|
||||
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
|
||||
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
|
||||
`
|
||||
|
||||
// On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part
|
||||
// of the snapshot.
|
||||
expectedStubFlagsInputs := []string{
|
||||
"out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar",
|
||||
"out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar",
|
||||
}
|
||||
|
||||
testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S",
|
||||
expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot")
|
||||
})
|
||||
|
||||
t.Run("target-Tiramisu-build", func(t *testing.T) {
|
||||
expectedSnapshot := `
|
||||
// This is auto-generated. DO NOT EDIT.
|
||||
|
||||
prebuilt_bootclasspath_fragment {
|
||||
name: "mybootclasspathfragment",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["myapex"],
|
||||
contents: [
|
||||
"mysdklibrary",
|
||||
"mynewsdklibrary",
|
||||
],
|
||||
hidden_api: {
|
||||
annotation_flags: "hiddenapi/annotation-flags.csv",
|
||||
metadata: "hiddenapi/metadata.csv",
|
||||
index: "hiddenapi/index.csv",
|
||||
signature_patterns: "hiddenapi/signature-patterns.csv",
|
||||
filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
|
||||
filtered_flags: "hiddenapi/filtered-flags.csv",
|
||||
},
|
||||
}
|
||||
|
||||
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",
|
||||
},
|
||||
}
|
||||
|
||||
java_sdk_library_import {
|
||||
name: "mynewsdklibrary",
|
||||
prefer: false,
|
||||
visibility: ["//visibility:public"],
|
||||
apex_available: ["myapex"],
|
||||
shared_library: true,
|
||||
compile_dex: true,
|
||||
permitted_packages: ["mynewsdklibrary"],
|
||||
public: {
|
||||
jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"],
|
||||
stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"],
|
||||
current_api: "sdk_library/public/mynewsdklibrary.txt",
|
||||
removed_api: "sdk_library/public/mynewsdklibrary-removed.txt",
|
||||
sdk_version: "current",
|
||||
},
|
||||
}
|
||||
`
|
||||
expectedCopyRules := `
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
|
||||
.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
|
||||
.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
|
||||
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
|
||||
.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
|
||||
.intermediates/mynewsdklibrary.stubs/android_common/javac/mynewsdklibrary.stubs.jar -> sdk_library/public/mynewsdklibrary-stubs.jar
|
||||
.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt
|
||||
.intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt
|
||||
`
|
||||
|
||||
// On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as
|
||||
// they are both part of the snapshot.
|
||||
expectedStubFlagsInputs := []string{
|
||||
"out/soong/.intermediates/mynewsdklibrary.stubs/android_common/dex/mynewsdklibrary.stubs.jar",
|
||||
"out/soong/.intermediates/mynewsdklibrary/android_common/aligned/mynewsdklibrary.jar",
|
||||
"out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar",
|
||||
"out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar",
|
||||
}
|
||||
|
||||
testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu",
|
||||
expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "")
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user