Merge "Move common test_options properties into the android package"

This commit is contained in:
Zhenhuang Wang
2022-08-17 15:22:18 +00:00
committed by Gerrit Code Review
11 changed files with 93 additions and 59 deletions

View File

@@ -936,6 +936,20 @@ type distProperties struct {
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 @@ func InitAndroidModule(m Module) {
// 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 @@ func productVariableConfigEnableLabels(ctx *topDownMutatorContext) []bazel.Label
//
// 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.

View File

@@ -911,3 +911,45 @@ func TestSortedUniqueNamedPaths(t *testing.T) {
})
}
}
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)
})
}
}