Add lint.strict_updatability_linting

The flag prevents developers from skipping updatability lint checks with
baseline files

Test: lint_test.go & manual
Bug: 182349282
Change-Id: Ia74a2b83c7ef686124128bdf16f7b85a919d9e8d
This commit is contained in:
Jaewoong Jung 2021-04-21 16:17:25 -07:00
parent 11623b6052
commit 48de883834
2 changed files with 39 additions and 0 deletions

View File

@ -57,6 +57,9 @@ type LintProperties struct {
// Name of the file that lint uses as the baseline. Defaults to "lint-baseline.xml".
Baseline_filename *string
// If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false.
Strict_updatability_linting *bool
}
}
@ -257,6 +260,13 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks)
if BoolDefault(l.properties.Lint.Strict_updatability_linting, false) {
if baselinePath := l.getBaselineFilepath(ctx); baselinePath.Valid() {
cmd.FlagWithInput("--baseline ", baselinePath.Path())
cmd.FlagForEachArg("--disallowed_issues ", updatabilityChecks)
}
}
return lintPaths{
projectXML: projectXMLPath,
configXML: configXMLPath,

View File

@ -173,3 +173,32 @@ func TestJavaLintBypassUpdatableChecks(t *testing.T) {
})
}
}
func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
bp := `
java_library {
name: "foo",
srcs: [
"a.java",
],
min_sdk_version: "29",
sdk_version: "current",
lint: {
strict_updatability_linting: true,
},
}
`
fs := android.MockFS{
"lint-baseline.xml": nil,
}
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, fs.AddToFixture()).
RunTestWithBp(t, bp)
foo := result.ModuleForTests("foo", "android_common")
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
if !strings.Contains(*sboxProto.Commands[0].Command,
"--baseline lint-baseline.xml --disallowed_issues NewApi") {
t.Error("did not restrict baselining NewApi")
}
}