Add exported_plugins to java.Library.

The behaviour is similar to go/be#java_library.exported_plugins. Plugins added to exported_plugins of library X are not applied to the library itself, but rather to libraries that directly depend on the library X.

Test: m checkbuild
Bug: 139740873
Change-Id: I4042bd482ad9cb12d6fbaac51f039d38b1b7a428
This commit is contained in:
Artur Satayev
2019-11-26 18:08:34 +00:00
parent 9d8dab57a5
commit 9cf4669bc4
4 changed files with 137 additions and 4 deletions

View File

@@ -332,6 +332,89 @@ func TestSimple(t *testing.T) {
}
}
func TestExportedPlugins(t *testing.T) {
type Result struct {
library string
processors string
}
var tests = []struct {
name string
extra string
results []Result
}{
{
name: "Exported plugin is not a direct plugin",
extra: `java_library { name: "exports", srcs: ["a.java"], exported_plugins: ["plugin"] }`,
results: []Result{{library: "exports", processors: "-proc:none"}},
},
{
name: "Exports plugin to dependee",
extra: `
java_library{name: "exports", exported_plugins: ["plugin"]}
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
`,
results: []Result{
{library: "foo", processors: "-processor com.android.TestPlugin"},
{library: "bar", processors: "-processor com.android.TestPlugin"},
},
},
{
name: "Exports plugin to android_library",
extra: `
java_library{name: "exports", exported_plugins: ["plugin"]}
android_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
android_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]}
`,
results: []Result{
{library: "foo", processors: "-processor com.android.TestPlugin"},
{library: "bar", processors: "-processor com.android.TestPlugin"},
},
},
{
name: "Exports plugin is not propagated via transitive deps",
extra: `
java_library{name: "exports", exported_plugins: ["plugin"]}
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]}
java_library{name: "bar", srcs: ["a.java"], static_libs: ["foo"]}
`,
results: []Result{
{library: "foo", processors: "-processor com.android.TestPlugin"},
{library: "bar", processors: "-proc:none"},
},
},
{
name: "Exports plugin appends to plugins",
extra: `
java_plugin{name: "plugin2", processor_class: "com.android.TestPlugin2"}
java_library{name: "exports", exported_plugins: ["plugin"]}
java_library{name: "foo", srcs: ["a.java"], libs: ["exports"], plugins: ["plugin2"]}
`,
results: []Result{
{library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"},
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx, _ := testJava(t, `
java_plugin {
name: "plugin",
processor_class: "com.android.TestPlugin",
}
`+test.extra)
for _, want := range test.results {
javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac")
if javac.Args["processor"] != want.processors {
t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"])
}
}
})
}
}
func TestSdkVersionByPartition(t *testing.T) {
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
java_library {