Merge "Add `provides_uses_library` example to TestUsesLibrary check."

This commit is contained in:
Ulyana Trafimovich 2021-03-02 13:46:49 +00:00 committed by Gerrit Code Review
commit 71284b60ae
1 changed files with 33 additions and 5 deletions

View File

@ -2290,17 +2290,33 @@ func TestUsesLibraries(t *testing.T) {
sdk_version: "current",
}
// A library that has to use "provides_uses_lib", because:
// - it is not an SDK library
// - its library name is different from its module name
java_library {
name: "non-sdk-lib",
provides_uses_lib: "com.non.sdk.lib",
installable: true,
srcs: ["a.java"],
}
android_app {
name: "app",
srcs: ["a.java"],
libs: ["qux", "quuz.stubs"],
libs: [
"qux",
"quuz.stubs"
],
static_libs: [
"static-runtime-helper",
// statically linked component libraries should not pull their SDK libraries,
// so "fred" should not be added to class loader context
"fred.stubs",
],
uses_libs: ["foo"],
uses_libs: [
"foo",
"non-sdk-lib"
],
sdk_version: "current",
optional_uses_libs: [
"bar",
@ -2312,7 +2328,11 @@ func TestUsesLibraries(t *testing.T) {
name: "prebuilt",
apk: "prebuilts/apk/app.apk",
certificate: "platform",
uses_libs: ["foo", "android.test.runner"],
uses_libs: [
"foo",
"non-sdk-lib",
"android.test.runner"
],
optional_uses_libs: [
"bar",
"baz",
@ -2337,8 +2357,10 @@ func TestUsesLibraries(t *testing.T) {
`--uses-library qux ` +
`--uses-library quuz ` +
`--uses-library foo ` + // TODO(b/132357300): "foo" should not be passed to manifest_fixer
`--uses-library non-sdk-lib ` + // TODO(b/132357300): "non-sdk-lib" should not be passed to manifest_fixer
`--uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer
`--uses-library runtime-library`
`--uses-library runtime-library ` +
`--uses-library com.non.sdk.lib` // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer
if actualManifestFixerArgs != expectManifestFixerArgs {
t.Errorf("unexpected manifest_fixer args:\n\texpect: %q\n\tactual: %q",
expectManifestFixerArgs, actualManifestFixerArgs)
@ -2347,9 +2369,11 @@ func TestUsesLibraries(t *testing.T) {
// Test that all libraries are verified (library order matters).
verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command
verifyArgs := `--uses-library foo ` +
`--uses-library non-sdk-lib ` + // TODO(b/132357300): "non-sdk-lib" should not be here
`--uses-library qux ` +
`--uses-library quuz ` +
`--uses-library runtime-library ` +
`--uses-library com.non.sdk.lib ` +
`--optional-uses-library bar ` +
`--optional-uses-library baz `
if !strings.Contains(verifyCmd, verifyArgs) {
@ -2358,7 +2382,9 @@ func TestUsesLibraries(t *testing.T) {
// Test that all libraries are verified for an APK (library order matters).
verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command
verifyApkReqLibs := `uses_library_names="foo android.test.runner"`
// TODO(b/132357300): "non-sdk-lib" should not be here
// TODO(b/132357300): "com.non.sdk.lib" should be here
verifyApkReqLibs := `uses_library_names="foo non-sdk-lib android.test.runner"`
verifyApkOptLibs := `optional_uses_library_names="bar baz"`
if !strings.Contains(verifyApkCmd, verifyApkReqLibs) {
t.Errorf("wanted %q in %q", verifyApkReqLibs, verifyApkCmd)
@ -2373,6 +2399,7 @@ func TestUsesLibraries(t *testing.T) {
`PCL[/system/framework/qux.jar]#` +
`PCL[/system/framework/quuz.jar]#` +
`PCL[/system/framework/foo.jar]#` +
`PCL[/system/framework/non-sdk-lib.jar]#` +
`PCL[/system/framework/bar.jar]#` +
`PCL[/system/framework/runtime-library.jar]`
if !strings.Contains(cmd, w) {
@ -2402,6 +2429,7 @@ func TestUsesLibraries(t *testing.T) {
cmd = prebuilt.Rule("dexpreopt").RuleParams.Command
if w := `--target-context-for-sdk any` +
` PCL[/system/framework/foo.jar]` +
`#PCL[/system/framework/non-sdk-lib.jar]` +
`#PCL[/system/framework/android.test.runner.jar]` +
`#PCL[/system/framework/bar.jar] `; !strings.Contains(cmd, w) {
t.Errorf("wanted %q in %q", w, cmd)