Add lint test property
Some libraries are only used for tests, but
are not test module types. These modules get warnings
about @VisibleForTesting usages when they really
shouldn't. Expose a test flag that module authors
can use to make lint treat a module as test code.
Bug: 235339747
Test: Manually tested applying it to SystemUI-tests
Change-Id: I1356749a669dc80a7725605d7159da27c9a211b4
diff --git a/java/app.go b/java/app.go
index 3c8fcd3..7a45855 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1055,7 +1055,7 @@
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true
- module.Module.linter.test = true
+ module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
module.addHostAndDeviceProperties()
module.AddProperties(
@@ -1108,7 +1108,7 @@
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true
- module.Module.linter.test = true
+ module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
module.addHostAndDeviceProperties()
module.AddProperties(
diff --git a/java/java.go b/java/java.go
index 481c625..77ab402 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1262,7 +1262,7 @@
module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true
- module.Module.linter.test = true
+ module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
android.InitSdkAwareModule(module)
InitJavaModule(module, android.HostAndDeviceSupported)
@@ -1278,7 +1278,7 @@
module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true
- module.Module.linter.test = true
+ module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
InitJavaModule(module, android.HostAndDeviceSupported)
return module
diff --git a/java/lint.go b/java/lint.go
index c27ca98..8f14bbe 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -61,6 +61,11 @@
// If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false.
Strict_updatability_linting *bool
+
+ // Treat the code in this module as test code for @VisibleForTesting enforcement.
+ // This will be true by default for test module types, false otherwise.
+ // If soong gets support for testonly, this flag should be replaced with that.
+ Test *bool
}
}
@@ -74,7 +79,6 @@
classpath android.Paths
classes android.Path
extraLintCheckJars android.Paths
- test bool
library bool
minSdkVersion int
targetSdkVersion int
@@ -229,7 +233,7 @@
if l.library {
cmd.Flag("--library")
}
- if l.test {
+ if proptools.BoolDefault(l.properties.Lint.Test, false) {
cmd.Flag("--test")
}
if l.manifest != nil {
diff --git a/java/robolectric.go b/java/robolectric.go
index f719521..71ffdb1 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -23,6 +23,7 @@
"android/soong/android"
"android/soong/java/config"
"android/soong/tradefed"
+ "github.com/google/blueprint/proptools"
)
func init() {
@@ -344,7 +345,7 @@
&module.testProperties)
module.Module.dexpreopter.isTest = true
- module.Module.linter.test = true
+ module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
module.testProperties.Test_suites = []string{"robolectric-tests"}