Introduce NewApi lint checks
We are enabling NewApi lint check where the min sdk != compile sdk. At the same time, we are introducing baseline files for existing projects that fail this check in order to keep the build running. At the very least we stop introducing new problems and teams might realise of risks in their projects they were not aware of. Bug: 150847901 Test: m lint-check Change-Id: Icfa5eb98cc6b6708149f0c52fac8fc1440d9c3b0 Merged-In: Icfa5eb98cc6b6708149f0c52fac8fc1440d9c3b0
This commit is contained in:
@@ -1261,6 +1261,14 @@ func TestJavaLintUsesCorrectBpConfig(t *testing.T) {
|
|||||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") {
|
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") {
|
||||||
t.Error("did not use the correct file for baseline")
|
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, "--error_check SomeCheck") {
|
||||||
|
t.Error("should combine NewApi errors with SomeCheck errors")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratedSources(t *testing.T) {
|
func TestGeneratedSources(t *testing.T) {
|
||||||
|
42
java/lint.go
42
java/lint.go
@@ -57,24 +57,25 @@ type LintProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type linter struct {
|
type linter struct {
|
||||||
name string
|
name string
|
||||||
manifest android.Path
|
manifest android.Path
|
||||||
mergedManifest android.Path
|
mergedManifest android.Path
|
||||||
srcs android.Paths
|
srcs android.Paths
|
||||||
srcJars android.Paths
|
srcJars android.Paths
|
||||||
resources android.Paths
|
resources android.Paths
|
||||||
classpath android.Paths
|
classpath android.Paths
|
||||||
classes android.Path
|
classes android.Path
|
||||||
extraLintCheckJars android.Paths
|
extraLintCheckJars android.Paths
|
||||||
test bool
|
test bool
|
||||||
library bool
|
library bool
|
||||||
minSdkVersion string
|
minSdkVersion string
|
||||||
targetSdkVersion string
|
targetSdkVersion string
|
||||||
compileSdkVersion string
|
compileSdkVersion string
|
||||||
javaLanguageLevel string
|
javaLanguageLevel string
|
||||||
kotlinLanguageLevel string
|
kotlinLanguageLevel string
|
||||||
outputs lintOutputs
|
outputs lintOutputs
|
||||||
properties LintProperties
|
properties LintProperties
|
||||||
|
extraMainlineLintErrors []string
|
||||||
|
|
||||||
reports android.Paths
|
reports android.Paths
|
||||||
|
|
||||||
@@ -246,6 +247,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
|
|||||||
cmd.FlagWithInput("@",
|
cmd.FlagWithInput("@",
|
||||||
android.PathForSource(ctx, "build/soong/java/lint_defaults.txt"))
|
android.PathForSource(ctx, "build/soong/java/lint_defaults.txt"))
|
||||||
|
|
||||||
|
cmd.FlagForEachArg("--error_check ", l.extraMainlineLintErrors)
|
||||||
cmd.FlagForEachArg("--disable_check ", l.properties.Lint.Disabled_checks)
|
cmd.FlagForEachArg("--disable_check ", l.properties.Lint.Disabled_checks)
|
||||||
cmd.FlagForEachArg("--warning_check ", l.properties.Lint.Warning_checks)
|
cmd.FlagForEachArg("--warning_check ", l.properties.Lint.Warning_checks)
|
||||||
cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
|
cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks)
|
||||||
@@ -282,6 +284,10 @@ func (l *linter) lint(ctx android.ModuleContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if l.minSdkVersion != l.compileSdkVersion {
|
||||||
|
l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, "NewApi")
|
||||||
|
}
|
||||||
|
|
||||||
extraLintCheckModules := ctx.GetDirectDepsWithTag(extraLintCheckTag)
|
extraLintCheckModules := ctx.GetDirectDepsWithTag(extraLintCheckTag)
|
||||||
for _, extraLintCheckModule := range extraLintCheckModules {
|
for _, extraLintCheckModule := range extraLintCheckModules {
|
||||||
if ctx.OtherModuleHasProvider(extraLintCheckModule, JavaInfoProvider) {
|
if ctx.OtherModuleHasProvider(extraLintCheckModule, JavaInfoProvider) {
|
||||||
|
Reference in New Issue
Block a user