Merge "Add support for lint baseline files"
This commit is contained in:
@@ -127,7 +127,6 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config
|
||||
}
|
||||
|
||||
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
||||
|
||||
return ctx, config
|
||||
}
|
||||
|
||||
@@ -1179,6 +1178,110 @@ func TestIncludeSrcs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestJavaLint(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{
|
||||
"lint-baseline.xml": nil,
|
||||
})
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "android_common")
|
||||
rule := foo.Rule("lint")
|
||||
|
||||
if !strings.Contains(rule.RuleParams.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")
|
||||
rule := foo.Rule("lint")
|
||||
|
||||
if strings.Contains(rule.RuleParams.Command, "--baseline") {
|
||||
t.Error("passed --baseline flag for non existent file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) {
|
||||
config := testConfig(
|
||||
nil,
|
||||
`
|
||||
java_library {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
],
|
||||
min_sdk_version: "29",
|
||||
sdk_version: "system_current",
|
||||
lint: {
|
||||
baseline_filename: "mybaseline.xml",
|
||||
},
|
||||
}
|
||||
`, map[string][]byte{
|
||||
"build/soong/java/lint_defaults.txt": nil,
|
||||
"prebuilts/cmdline-tools/tools/bin/lint": nil,
|
||||
"prebuilts/cmdline-tools/tools/lib/lint-classpath.jar": nil,
|
||||
"framework/aidl": nil,
|
||||
"a.java": nil,
|
||||
"AndroidManifest.xml": nil,
|
||||
"build/make/target/product/security": nil,
|
||||
})
|
||||
config.TestAllowNonExistentPaths = false
|
||||
testJavaErrorWithConfig(t,
|
||||
"source path \"mybaseline.xml\" does not exist",
|
||||
config,
|
||||
)
|
||||
}
|
||||
|
||||
func TestJavaLintUsesCorrectBpConfig(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",
|
||||
lint: {
|
||||
error_checks: ["SomeCheck"],
|
||||
baseline_filename: "mybaseline.xml",
|
||||
},
|
||||
}
|
||||
`, map[string][]byte{
|
||||
"mybaseline.xml": nil,
|
||||
})
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "android_common")
|
||||
rule := foo.Rule("lint")
|
||||
|
||||
if !strings.Contains(rule.RuleParams.Command, "--baseline mybaseline.xml") {
|
||||
t.Error("did not use the correct file for baseline")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratedSources(t *testing.T) {
|
||||
ctx, _ := testJavaWithFS(t, `
|
||||
java_library {
|
||||
|
18
java/lint.go
18
java/lint.go
@@ -19,6 +19,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
@@ -46,6 +48,9 @@ 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".
|
||||
Baseline_filename *string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,6 +349,19 @@ func (l *linter) lint(ctx android.ModuleContext) {
|
||||
cmd.FlagWithArg("--check ", checkOnly)
|
||||
}
|
||||
|
||||
if lintFilename := proptools.StringDefault(l.properties.Lint.Baseline_filename, "lint-baseline.xml"); lintFilename != "" {
|
||||
var lintBaseline android.OptionalPath
|
||||
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)
|
||||
}
|
||||
if lintBaseline.Valid() {
|
||||
cmd.FlagWithInput("--baseline ", lintBaseline.Path())
|
||||
}
|
||||
}
|
||||
|
||||
cmd.Text("|| (").Text("cat").Input(text).Text("; exit 7)").Text(")")
|
||||
|
||||
rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String())
|
||||
|
Reference in New Issue
Block a user