diff options
-rw-r--r-- | java/app.go | 4 | ||||
-rw-r--r-- | java/fuzz.go | 2 | ||||
-rw-r--r-- | java/java.go | 4 | ||||
-rw-r--r-- | java/lint.go | 12 | ||||
-rw-r--r-- | java/lint_test.go | 47 | ||||
-rw-r--r-- | java/ravenwood.go | 2 | ||||
-rw-r--r-- | java/robolectric.go | 3 |
7 files changed, 66 insertions, 8 deletions
diff --git a/java/app.go b/java/app.go index 12705b0a5..31c338f4a 100644 --- a/java/app.go +++ b/java/app.go @@ -1698,7 +1698,7 @@ func AndroidTestFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.addHostAndDeviceProperties() module.AddProperties( @@ -1756,7 +1756,7 @@ func AndroidTestHelperAppFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.addHostAndDeviceProperties() module.AddProperties( diff --git a/java/fuzz.go b/java/fuzz.go index 79cd042d8..5973957a2 100644 --- a/java/fuzz.go +++ b/java/fuzz.go @@ -63,7 +63,7 @@ func JavaFuzzFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.Module.sourceProperties.Test_only = proptools.BoolPtr(true) module.Module.sourceProperties.Top_level_test_target = true diff --git a/java/java.go b/java/java.go index 25be93b46..48ba8def2 100644 --- a/java/java.go +++ b/java/java.go @@ -1781,7 +1781,7 @@ func TestFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.Module.sourceProperties.Test_only = proptools.BoolPtr(true) module.Module.sourceProperties.Top_level_test_target = true @@ -1798,7 +1798,7 @@ func TestHelperLibraryFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.Module.sourceProperties.Test_only = proptools.BoolPtr(true) InitJavaModule(module, android.HostAndDeviceSupported) diff --git a/java/lint.go b/java/lint.go index 9c6b93b45..cee25a8d5 100644 --- a/java/lint.go +++ b/java/lint.go @@ -69,6 +69,11 @@ type LintProperties struct { // If soong gets support for testonly, this flag should be replaced with that. Test *bool + // Same as the regular Test property, but set by internal soong code based on if the module + // type is a test module type. This will act as the default value for the test property, + // but can be overridden by the user. + Test_module_type *bool `blueprint:"mutated"` + // Whether to ignore the exit code of Android lint. This is the --exit_code // option. Defaults to false. Suppress_exit_code *bool @@ -257,7 +262,12 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru if l.library { cmd.Flag("--library") } - if proptools.BoolDefault(l.properties.Lint.Test, false) { + + test := proptools.BoolDefault(l.properties.Lint.Test_module_type, false) + if l.properties.Lint.Test != nil { + test = *l.properties.Lint.Test + } + if test { cmd.Flag("--test") } if l.manifest != nil { diff --git a/java/lint_test.go b/java/lint_test.go index afe3914ff..617dc54cd 100644 --- a/java/lint_test.go +++ b/java/lint_test.go @@ -276,3 +276,50 @@ func TestCantControlCheckSeverityWithFlags(t *testing.T) { ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("Don't use --disable, --enable, or --check in the flags field, instead use the dedicated disabled_checks, warning_checks, error_checks, or fatal_checks fields")). RunTestWithBp(t, bp) } + +// b/358643466 +func TestNotTestViaDefault(t *testing.T) { + bp := ` + java_defaults { + name: "mydefaults", + lint: { + test: false, + }, + } + android_test { + name: "foo", + srcs: [ + "a.java", + ], + min_sdk_version: "29", + sdk_version: "current", + defaults: ["mydefaults"], + } + android_test { + name: "foo2", + srcs: [ + "a.java", + ], + min_sdk_version: "29", + sdk_version: "current", + } + ` + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) + ctx := result.TestContext + + foo := ctx.ModuleForTests("foo", "android_common") + sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx, foo.Output("lint.sbox.textproto")) + command := *sboxProto.Commands[0].Command + + if strings.Contains(command, "--test") { + t.Fatalf("Expected command to not contain --test") + } + + foo2 := ctx.ModuleForTests("foo2", "android_common") + sboxProto2 := android.RuleBuilderSboxProtoForTests(t, ctx, foo2.Output("lint.sbox.textproto")) + command2 := *sboxProto2.Commands[0].Command + + if !strings.Contains(command2, "--test") { + t.Fatalf("Expected command to contain --test") + } +} diff --git a/java/ravenwood.go b/java/ravenwood.go index 4c43a9ffb..84d6a9f41 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -110,7 +110,7 @@ func ravenwoodTestFactory() android.Module { module.AddProperties(&module.testProperties, &module.ravenwoodTestProperties) module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.testProperties.Test_suites = []string{ "general-tests", diff --git a/java/robolectric.go b/java/robolectric.go index 0c11b1c72..29aa2f02d 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/java/config" "android/soong/tradefed" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -295,7 +296,7 @@ func RobolectricTestFactory() android.Module { &module.testProperties) module.Module.dexpreopter.isTest = true - module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + module.Module.linter.properties.Lint.Test_module_type = proptools.BoolPtr(true) module.testProperties.Test_suites = []string{"robolectric-tests"} |