Merge "support errorprone javacflags" am: ef03b3d8ba

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2029264

Change-Id: Ifbecefada5ac477c465bda832c2b1cbdf0264e47
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2022-04-05 19:48:06 +00:00 committed by Automerger Merge Worker
commit 9f677ae8c7
2 changed files with 74 additions and 4 deletions

View file

@ -30,6 +30,7 @@ func runJavaLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2buildTest
}
func runJavaLibraryTestCase(t *testing.T, tc bp2buildTestCase) {
t.Helper()
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
}
@ -156,3 +157,65 @@ java_plugin {
ctx.RegisterModuleType("java_plugin", java.PluginFactory)
})
}
func TestJavaLibraryErrorproneJavacflagsEnabledManually(t *testing.T) {
runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
javacflags: ["-Xsuper-fast"],
errorprone: {
enabled: true,
javacflags: ["-Xep:SpeedLimit:OFF"],
},
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-1", attrNameToString{
"javacopts": `[
"-Xsuper-fast",
"-Xep:SpeedLimit:OFF",
]`,
"srcs": `["a.java"]`,
}),
},
})
}
func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledByDefault(t *testing.T) {
runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
javacflags: ["-Xsuper-fast"],
errorprone: {
javacflags: ["-Xep:SpeedLimit:OFF"],
},
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-1", attrNameToString{
"javacopts": `["-Xsuper-fast"]`,
"srcs": `["a.java"]`,
}),
},
})
}
func TestJavaLibraryErrorproneJavacflagsErrorproneDisabledManually(t *testing.T) {
runJavaLibraryTestCase(t, bp2buildTestCase{
blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
javacflags: ["-Xsuper-fast"],
errorprone: {
enabled: false,
javacflags: ["-Xep:SpeedLimit:OFF"],
},
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-1", attrNameToString{
"javacopts": `["-Xsuper-fast"]`,
"srcs": `["a.java"]`,
}),
},
})
}

View file

@ -2060,15 +2060,22 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
protoSrcPartition: android.ProtoSrcLabelPartition,
})
var javacopts []string
if m.properties.Javacflags != nil {
javacopts = append(javacopts, m.properties.Javacflags...)
}
epEnabled := m.properties.Errorprone.Enabled
//TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
if Bool(epEnabled) {
javacopts = append(javacopts, m.properties.Errorprone.Javacflags...)
}
commonAttrs := &javaCommonAttributes{
Srcs: srcPartitions[javaSrcPartition],
Plugins: bazel.MakeLabelListAttribute(
android.BazelLabelForModuleDeps(ctx, m.properties.Plugins),
),
}
if m.properties.Javacflags != nil {
commonAttrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
Javacopts: bazel.MakeStringListAttribute(javacopts),
}
depLabels := &javaDependencyLabels{}