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
(cherry picked from commit d57e8b2c2a55359c86def86a06dfdc7f7678d3c3)
Merged-In: I1356749a669dc80a7725605d7159da27c9a211b4
diff --git a/java/app.go b/java/app.go
index 4c7f017..c3a33ff 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1086,7 +1086,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(
@@ -1138,7 +1138,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 5a3a2e0..a07565c 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1251,7 +1251,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)
@@ -1267,7 +1267,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 426a2af..fdc9dbd 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -60,6 +60,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
}
}
@@ -73,7 +78,6 @@
classpath android.Paths
classes android.Path
extraLintCheckJars android.Paths
- test bool
library bool
minSdkVersion android.ApiLevel
targetSdkVersion android.ApiLevel
@@ -228,7 +232,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 80be046..999da6f 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -354,7 +354,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"}