Flag to control if generated SDK prebuilts are preferred.

This is needed because:
- the SDK prebuilt drop is being automated, including the Android.bp
- We want to control the prefer flag on a per-module level

It augments the existing SOONG_SDK_SNAPSHOT_PREFER which now overrides
this new flag when set to true.

Bug: 188427719
Test: m nothing
Change-Id: Ieb5ab9fab53a34c615345b7a9d19cadf713eec26
This commit is contained in:
Mathew Inwood
2021-05-20 11:00:12 +01:00
parent 22fd032ccb
commit d0b99cea0a
3 changed files with 79 additions and 5 deletions

View File

@@ -662,3 +662,68 @@ sdk_snapshot {
)
})
}
// Ensure that sdk prebuilt_prefer works correctly.
func TestSnapshot_PrebuiltPreferTrue(t *testing.T) {
bp := `
sdk {
name: "mysdk",
java_header_libs: ["myjavalib"],
prebuilts_prefer: true,
}
java_library {
name: "myjavalib",
srcs: ["Test.java"],
system_modules: "none",
sdk_version: "none",
compile_dex: true,
host_supported: true,
}
`
preparer := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
android.FixtureWithRootAndroidBp(bp),
)
checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
}
t.Run("prefer=true", func(t *testing.T) {
result := android.GroupFixturePreparers(
preparer,
).RunTest(t)
checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
CheckSnapshot(t, result, "mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_import {
name: "mysdk_myjavalib@current",
sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
}
java_import {
name: "myjavalib",
prefer: true,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
jars: ["java/myjavalib.jar"],
}
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
java_header_libs: ["mysdk_myjavalib@current"],
}
`),
)
})
}