Use trimmed lint database for mainline modules

Lint's NewApi checks currently produce a lot of false positive findings.
The filtered lint database removes information of classes defined by
mainline modules which are the cases that might become a false positive.

This commit updates soong to use this database instead of the normal one
when linting mainline modules.

Test: m lint-check
Fixes: 186478867
Change-Id: Ica646081b9189303c393b36b2f02914d69eee291
Merged-In: Ica646081b9189303c393b36b2f02914d69eee291
This commit is contained in:
Pedro Loureiro
2021-06-08 18:11:21 +00:00
parent 0e4f95a656
commit f1be9ba5a4
3 changed files with 118 additions and 17 deletions

View File

@@ -219,3 +219,72 @@ func TestJavaLintStrictUpdatabilityLinting(t *testing.T) {
t.Error("did not restrict baselining NewApi")
}
}
func TestJavaLintDatabaseSelectionFull(t *testing.T) {
testCases := []string{
"current", "core_platform", "system_current", "S", "30", "10000",
}
bp := `
java_library {
name: "foo",
srcs: [
"a.java",
],
min_sdk_version: "29",
sdk_version: "XXX",
lint: {
strict_updatability_linting: true,
},
}
`
for _, testCase := range testCases {
thisBp := strings.Replace(bp, "XXX", testCase, 1)
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, FixtureWithPrebuiltApis(map[string][]string{
"30": {"foo"},
"10000": {"foo"},
})).
RunTestWithBp(t, thisBp)
foo := result.ModuleForTests("foo", "android_common")
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
if strings.Contains(*sboxProto.Commands[0].Command,
"/api_versions_public_filtered.xml") {
t.Error("used public-filtered lint api database for case", testCase)
}
if !strings.Contains(*sboxProto.Commands[0].Command,
"/api_versions.xml") {
t.Error("did not use full api database for case", testCase)
}
}
}
func TestJavaLintDatabaseSelectionPublicFiltered(t *testing.T) {
bp := `
java_library {
name: "foo",
srcs: [
"a.java",
],
min_sdk_version: "29",
sdk_version: "module_current",
lint: {
strict_updatability_linting: true,
},
}
`
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules).
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,
"/api_versions_public_filtered.xml") {
t.Error("did not use public-filtered lint api database", *sboxProto.Commands[0].Command)
}
if strings.Contains(*sboxProto.Commands[0].Command,
"/api_versions.xml") {
t.Error("used full api database")
}
}