From 77267c7d9c998ebe8b651bfd0e82edbca21d16eb Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Fri, 18 Mar 2022 14:11:07 +0000 Subject: [PATCH] add plugins to javaLibraryAttributes Test: go test ./bp2build Change-Id: I8e4c3f373c62c60ea5013cd8c585915a366c1f81 --- bp2build/java_library_conversion_test.go | 31 ++++++++++++++++++++++-- java/java.go | 4 +++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go index cf811ed67..2f6bce20f 100644 --- a/bp2build/java_library_conversion_test.go +++ b/bp2build/java_library_conversion_test.go @@ -22,11 +22,15 @@ import ( "android/soong/java" ) -func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) { +func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { t.Helper() (&tc).moduleTypeUnderTest = "java_library" (&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) { @@ -129,3 +133,26 @@ java_library { 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) + }) +} diff --git a/java/java.go b/java/java.go index 831d60731..1b6e559b3 100644 --- a/java/java.go +++ b/java/java.go @@ -2026,6 +2026,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, type javaCommonAttributes struct { Srcs bazel.LabelListAttribute + Plugins bazel.LabelListAttribute Javacopts bazel.StringListAttribute } @@ -2061,6 +2062,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) commonAttrs := &javaCommonAttributes{ Srcs: srcPartitions[javaSrcPartition], + Plugins: bazel.MakeLabelListAttribute( + android.BazelLabelForModuleDeps(ctx, m.properties.Plugins), + ), } if m.properties.Javacflags != nil {