Merge "Don't implicitly pick up lint-baseline.xml" into main

This commit is contained in:
Treehugger Robot 2024-01-04 20:00:58 +00:00 committed by Gerrit Code Review
commit 5cb14e12d2
2 changed files with 7 additions and 42 deletions

View file

@ -56,7 +56,8 @@ type LintProperties struct {
// Modules that provide extra lint checks
Extra_check_modules []string
// Name of the file that lint uses as the baseline. Defaults to "lint-baseline.xml".
// The lint baseline file to use. If specified, lint warnings listed in this file will be
// suppressed during lint checks.
Baseline_filename *string
// If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false.
@ -365,19 +366,6 @@ func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleB
return manifestPath
}
func (l *linter) getBaselineFilepath(ctx android.ModuleContext) android.OptionalPath {
var lintBaseline android.OptionalPath
if lintFilename := proptools.StringDefault(l.properties.Lint.Baseline_filename, "lint-baseline.xml"); lintFilename != "" {
if String(l.properties.Lint.Baseline_filename) != "" {
// if manually specified, we require the file to exist
lintBaseline = android.OptionalPathForPath(android.PathForModuleSrc(ctx, lintFilename))
} else {
lintBaseline = android.ExistentPathForSource(ctx, ctx.ModuleDir(), lintFilename)
}
}
return lintBaseline
}
func (l *linter) lint(ctx android.ModuleContext) {
if !l.enabled() {
return
@ -518,9 +506,8 @@ func (l *linter) lint(ctx android.ModuleContext) {
cmd.FlagWithArg("--check ", checkOnly)
}
lintBaseline := l.getBaselineFilepath(ctx)
if lintBaseline.Valid() {
cmd.FlagWithInput("--baseline ", lintBaseline.Path())
if l.properties.Lint.Baseline_filename != nil {
cmd.FlagWithInput("--baseline ", android.PathForModuleSrc(ctx, *l.properties.Lint.Baseline_filename))
}
cmd.FlagWithOutput("--write-reference-baseline ", referenceBaseline)

View file

@ -21,7 +21,7 @@ import (
"android/soong/android"
)
func TestJavaLint(t *testing.T) {
func TestJavaLintDoesntUseBaselineImplicitly(t *testing.T) {
ctx, _ := testJavaWithFS(t, `
java_library {
name: "foo",
@ -40,30 +40,8 @@ func TestJavaLint(t *testing.T) {
foo := ctx.ModuleForTests("foo", "android_common")
sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto"))
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") {
t.Error("did not pass --baseline flag")
}
}
func TestJavaLintWithoutBaseline(t *testing.T) {
ctx, _ := testJavaWithFS(t, `
java_library {
name: "foo",
srcs: [
"a.java",
"b.java",
"c.java",
],
min_sdk_version: "29",
sdk_version: "system_current",
}
`, map[string][]byte{})
foo := ctx.ModuleForTests("foo", "android_common")
sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto"))
if strings.Contains(*sboxProto.Commands[0].Command, "--baseline") {
t.Error("passed --baseline flag for non existent file")
if strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") {
t.Error("Passed --baseline flag when baseline_filename was not set")
}
}