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 d57e8b2c2a)
Merged-In: I1356749a669dc80a7725605d7159da27c9a211b4
This commit is contained in:
Cole Faust
2022-08-11 11:59:04 -07:00
committed by Chidera Olibie
parent fd1f4d5b9e
commit 2bb9c554b1
4 changed files with 11 additions and 7 deletions

View File

@@ -1086,7 +1086,7 @@ func AndroidTestFactory() android.Module {
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true module.Module.dexpreopter.isTest = true
module.Module.linter.test = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
module.addHostAndDeviceProperties() module.addHostAndDeviceProperties()
module.AddProperties( module.AddProperties(
@@ -1138,7 +1138,7 @@ func AndroidTestHelperAppFactory() android.Module {
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
module.appProperties.AlwaysPackageNativeLibs = true module.appProperties.AlwaysPackageNativeLibs = true
module.Module.dexpreopter.isTest = true module.Module.dexpreopter.isTest = true
module.Module.linter.test = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
module.addHostAndDeviceProperties() module.addHostAndDeviceProperties()
module.AddProperties( module.AddProperties(

View File

@@ -1251,7 +1251,7 @@ func TestFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true module.Module.dexpreopter.isTest = true
module.Module.linter.test = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
android.InitSdkAwareModule(module) android.InitSdkAwareModule(module)
InitJavaModule(module, android.HostAndDeviceSupported) InitJavaModule(module, android.HostAndDeviceSupported)
@@ -1267,7 +1267,7 @@ func TestHelperLibraryFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.properties.Installable = proptools.BoolPtr(true)
module.Module.dexpreopter.isTest = true module.Module.dexpreopter.isTest = true
module.Module.linter.test = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
InitJavaModule(module, android.HostAndDeviceSupported) InitJavaModule(module, android.HostAndDeviceSupported)
return module return module

View File

@@ -60,6 +60,11 @@ type LintProperties struct {
// If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false. // If true, baselining updatability lint checks (e.g. NewApi) is prohibited. Defaults to false.
Strict_updatability_linting *bool 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 @@ type linter struct {
classpath android.Paths classpath android.Paths
classes android.Path classes android.Path
extraLintCheckJars android.Paths extraLintCheckJars android.Paths
test bool
library bool library bool
minSdkVersion android.ApiLevel minSdkVersion android.ApiLevel
targetSdkVersion android.ApiLevel targetSdkVersion android.ApiLevel
@@ -228,7 +232,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru
if l.library { if l.library {
cmd.Flag("--library") cmd.Flag("--library")
} }
if l.test { if proptools.BoolDefault(l.properties.Lint.Test, false) {
cmd.Flag("--test") cmd.Flag("--test")
} }
if l.manifest != nil { if l.manifest != nil {

View File

@@ -354,7 +354,7 @@ func RobolectricTestFactory() android.Module {
&module.testProperties) &module.testProperties)
module.Module.dexpreopter.isTest = true 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"} module.testProperties.Test_suites = []string{"robolectric-tests"}