Move common test_options properties into the android package
Multiple modules (e.g. java, cc, python, rust) define the `test_options`
field. Extract the common properties in test_options to share across
different test rules.
Bug: 240928948
Test: `refreshmod` and diff with original module-info.json
Change-Id: I404a7a157b4ccaa53d800ee2217559ff695bd825
diff --git a/android/module.go b/android/module.go
index 450dba9..a75a3cc 100644
--- a/android/module.go
+++ b/android/module.go
@@ -936,6 +936,20 @@
Dists []Dist `android:"arch_variant"`
}
+// CommonTestOptions represents the common `test_options` properties in
+// Android.bp.
+type CommonTestOptions struct {
+ // If the test is a hostside (no device required) unittest that shall be run
+ // during presubmit check.
+ Unit_test *bool
+}
+
+// SetAndroidMkEntries sets AndroidMkEntries according to the value of base
+// `test_options`.
+func (t *CommonTestOptions) SetAndroidMkEntries(entries *AndroidMkEntries) {
+ entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
+}
+
// The key to use in TaggedDistFiles when a Dist structure does not specify a
// tag property. This intentionally does not use "" as the default because that
// would mean that an empty tag would have a different meaning when used in a dist
@@ -1095,7 +1109,7 @@
// property structs for architecture-specific versions of generic properties tagged with
// `android:"arch_variant"`.
//
-// InitAndroidModule should not be called if InitAndroidArchModule was called.
+// InitAndroidModule should not be called if InitAndroidArchModule was called.
func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
InitAndroidModule(m)
@@ -1336,30 +1350,30 @@
//
// For example:
//
-// import (
-// "android/soong/android"
-// )
+// import (
+// "android/soong/android"
+// )
//
-// type myModule struct {
-// android.ModuleBase
-// properties struct {
-// MyProperty string
-// }
-// }
+// type myModule struct {
+// android.ModuleBase
+// properties struct {
+// MyProperty string
+// }
+// }
//
-// func NewMyModule() android.Module {
-// m := &myModule{}
-// m.AddProperties(&m.properties)
-// android.InitAndroidModule(m)
-// return m
-// }
+// func NewMyModule() android.Module {
+// m := &myModule{}
+// m.AddProperties(&m.properties)
+// android.InitAndroidModule(m)
+// return m
+// }
//
-// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
-// // Get the CPU architecture for the current build variant.
-// variantArch := ctx.Arch()
+// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+// // Get the CPU architecture for the current build variant.
+// variantArch := ctx.Arch()
//
-// // ...
-// }
+// // ...
+// }
type ModuleBase struct {
// Putting the curiously recurring thing pointing to the thing that contains
// the thing pattern to good use.
diff --git a/android/module_test.go b/android/module_test.go
index 77ef146..835ab4c 100644
--- a/android/module_test.go
+++ b/android/module_test.go
@@ -911,3 +911,45 @@
})
}
}
+
+func TestProcessCommonTestOptions(t *testing.T) {
+ tests := []struct {
+ name string
+ testOptions CommonTestOptions
+ expected map[string][]string
+ }{
+ {
+ name: "empty",
+ testOptions: CommonTestOptions{},
+ expected: map[string][]string{},
+ },
+ {
+ name: "is unit test",
+ testOptions: CommonTestOptions{
+ Unit_test: boolPtr(true),
+ },
+ expected: map[string][]string{
+ "LOCAL_IS_UNIT_TEST": []string{"true"},
+ },
+ },
+ {
+ name: "is not unit test",
+ testOptions: CommonTestOptions{
+ Unit_test: boolPtr(false),
+ },
+ expected: map[string][]string{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ actualEntries := AndroidMkEntries{
+ EntryMap: map[string][]string{},
+ }
+ tt.testOptions.SetAndroidMkEntries(&actualEntries)
+ actual := actualEntries.EntryMap
+ t.Logf("actual: %v", actual)
+ t.Logf("expected: %v", tt.expected)
+ AssertDeepEquals(t, "TestProcessCommonTestOptions ", tt.expected, actual)
+ })
+ }
+}