Forbid bypassing updatability lint checks.

Test: lint_test.go
Bug: 182349282
Change-Id: Iac7c01493b449c2ddd6df6c68f8a74dfe72dfd7a
This commit is contained in:
Jaewoong Jung
2021-04-21 14:01:55 -07:00
parent 4949557d50
commit 79e6f6bfcc
3 changed files with 89 additions and 1 deletions

View File

@@ -82,6 +82,7 @@ bootstrap_go_package {
"java_test.go",
"jdeps_test.go",
"kotlin_test.go",
"lint_test.go",
"platform_bootclasspath_test.go",
"platform_compat_config_test.go",
"plugin_test.go",

View File

@@ -26,6 +26,10 @@ import (
"android/soong/remoteexec"
)
// lint checks automatically enforced for modules that have different min_sdk_version than
// sdk_version
var updatabilityChecks = []string{"NewApi"}
type LintProperties struct {
// Controls for running Android Lint on the module.
Lint struct {
@@ -298,7 +302,17 @@ func (l *linter) lint(ctx android.ModuleContext) {
}
if l.minSdkVersion != l.compileSdkVersion {
l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, "NewApi")
l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...)
_, filtered := android.FilterList(l.properties.Lint.Warning_checks, updatabilityChecks)
if len(filtered) != 0 {
ctx.PropertyErrorf("lint.warning_checks",
"Can't treat %v checks as warnings if min_sdk_version is different from sdk_version.", filtered)
}
_, filtered = android.FilterList(l.properties.Lint.Disabled_checks, updatabilityChecks)
if len(filtered) != 0 {
ctx.PropertyErrorf("lint.disabled_checks",
"Can't disable %v checks if min_sdk_version is different from sdk_version.", filtered)
}
}
extraLintCheckModules := ctx.GetDirectDepsWithTag(extraLintCheckTag)

73
java/lint_test.go Normal file
View File

@@ -0,0 +1,73 @@
// Copyright 2021 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package java
import (
"testing"
"android/soong/android"
)
func TestJavaLintBypassUpdatableChecks(t *testing.T) {
testCases := []struct {
name string
bp string
error string
}{
{
name: "warning_checks",
bp: `
java_library {
name: "foo",
srcs: [
"a.java",
],
min_sdk_version: "29",
sdk_version: "current",
lint: {
warning_checks: ["NewApi"],
},
}
`,
error: "lint.warning_checks: Can't treat \\[NewApi\\] checks as warnings if min_sdk_version is different from sdk_version.",
},
{
name: "disable_checks",
bp: `
java_library {
name: "foo",
srcs: [
"a.java",
],
min_sdk_version: "29",
sdk_version: "current",
lint: {
disabled_checks: ["NewApi"],
},
}
`,
error: "lint.disabled_checks: Can't disable \\[NewApi\\] checks if min_sdk_version is different from sdk_version.",
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.error)
android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules).
ExtendWithErrorHandler(errorHandler).
RunTestWithBp(t, testCase.bp)
})
}
}