Give lint the correct api levels database for the current module
Before this change, lint was always working off of the public
api database. Now, it will have the system, module-lib, or
system-server databases if the current module is compiling
against those SDKs.
This means that a lot more methods are going to start being
checked for NewApi issues.
Bug: 193460475
Test: Errorprone presubmit
Change-Id: I3eb2c617cd61554cd2a3f9d15fd40b3ec91f961d
diff --git a/java/lint_test.go b/java/lint_test.go
index 1ab416c..ec901aa 100644
--- a/java/lint_test.go
+++ b/java/lint_test.go
@@ -113,8 +113,9 @@
t.Error("did not use the correct file for baseline")
}
- if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") {
- t.Error("should check NewApi errors")
+ if !strings.Contains(*sboxProto.Commands[0].Command, "--warning_check NewApi") {
+ // TODO(b/268261262): Change this to check for --error_check
+ t.Error("should check NewApi warnings")
}
if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check SomeCheck") {
@@ -222,8 +223,35 @@
//}
func TestJavaLintDatabaseSelectionFull(t *testing.T) {
- testCases := []string{
- "current", "core_platform", "system_current", "S", "30", "10000",
+ testCases := []struct {
+ sdk_version string
+ expected_file string
+ }{
+ {
+ "current",
+ "api_versions_public.xml",
+ }, {
+ "core_platform",
+ "api_versions_public.xml",
+ }, {
+ "system_current",
+ "api_versions_system.xml",
+ }, {
+ "module_current",
+ "api_versions_module_lib.xml",
+ }, {
+ "system_server_current",
+ "api_versions_system_server.xml",
+ }, {
+ "S",
+ "api_versions_public.xml",
+ }, {
+ "30",
+ "api_versions_public.xml",
+ }, {
+ "10000",
+ "api_versions_public.xml",
+ },
}
bp := `
java_library {
@@ -239,7 +267,7 @@
}
`
for _, testCase := range testCases {
- thisBp := strings.Replace(bp, "XXX", testCase, 1)
+ thisBp := strings.Replace(bp, "XXX", testCase.sdk_version, 1)
result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, FixtureWithPrebuiltApis(map[string][]string{
"30": {"foo"},
@@ -249,49 +277,8 @@
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") {
+ if !strings.Contains(*sboxProto.Commands[0].Command, "/"+testCase.expected_file) {
t.Error("did not use full api database for case", testCase)
}
}
-
-}
-
-func TestJavaLintDatabaseSelectionPublicFiltered(t *testing.T) {
- testCases := []string{
- "module_current", "system_server_current",
- }
- 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).
- 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("did not use public-filtered lint api database for case", testCase)
- }
- if strings.Contains(*sboxProto.Commands[0].Command,
- "/api_versions.xml") {
- t.Error("used full api database for case", testCase)
- }
- }
}