add plugins to javaLibraryAttributes

Test: go test ./bp2build
Change-Id: I8e4c3f373c62c60ea5013cd8c585915a366c1f81
This commit is contained in:
Sam Delmerico
2022-03-18 14:11:07 +00:00
parent 5f83b491b4
commit 77267c7d9c
2 changed files with 33 additions and 2 deletions

View File

@@ -22,11 +22,15 @@ import (
"android/soong/java" "android/soong/java"
) )
func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) { func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
t.Helper() t.Helper()
(&tc).moduleTypeUnderTest = "java_library" (&tc).moduleTypeUnderTest = "java_library"
(&tc).moduleTypeUnderTestFactory = java.LibraryFactory (&tc).moduleTypeUnderTestFactory = java.LibraryFactory
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) runBp2BuildTestCase(t, registrationCtxFunc, tc)
}
func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) {
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
} }
func TestJavaLibrary(t *testing.T) { func TestJavaLibrary(t *testing.T) {
@@ -129,3 +133,26 @@ java_library {
expectedBazelTargets: []string{}, expectedBazelTargets: []string{},
}) })
} }
func TestJavaLibraryPlugins(t *testing.T) {
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, bp2buildTestCase{
blueprint: `java_library {
name: "java-lib-1",
plugins: ["java-plugin-1"],
bazel_module: { bp2build_available: true },
}
java_plugin {
name: "java-plugin-1",
srcs: ["a.java"],
bazel_module: { bp2build_available: false },
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-1", attrNameToString{
"plugins": `[":java-plugin-1"]`,
}),
},
}, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_plugin", java.PluginFactory)
})
}

View File

@@ -2026,6 +2026,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
type javaCommonAttributes struct { type javaCommonAttributes struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Plugins bazel.LabelListAttribute
Javacopts bazel.StringListAttribute Javacopts bazel.StringListAttribute
} }
@@ -2061,6 +2062,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
commonAttrs := &javaCommonAttributes{ commonAttrs := &javaCommonAttributes{
Srcs: srcPartitions[javaSrcPartition], Srcs: srcPartitions[javaSrcPartition],
Plugins: bazel.MakeLabelListAttribute(
android.BazelLabelForModuleDeps(ctx, m.properties.Plugins),
),
} }
if m.properties.Javacflags != nil { if m.properties.Javacflags != nil {