aboutsummaryrefslogtreecommitdiffstats
path: root/android/sh_binary.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/sh_binary.go')
-rw-r--r--android/sh_binary.go75
1 files changed, 58 insertions, 17 deletions
diff --git a/android/sh_binary.go b/android/sh_binary.go
index cf415c56..ba0c8be7 100644
--- a/android/sh_binary.go
+++ b/android/sh_binary.go
@@ -16,7 +16,6 @@ package android
import (
"fmt"
- "io"
"strings"
)
@@ -30,6 +29,7 @@ func init() {
RegisterModuleType("sh_binary", ShBinaryFactory)
RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
RegisterModuleType("sh_test", ShTestFactory)
+ RegisterModuleType("sh_test_host", ShTestHostFactory)
}
type shBinaryProperties struct {
@@ -58,6 +58,10 @@ type TestProperties struct {
// the name of the test configuration (for example "AndroidTest.xml") that should be
// installed with the module.
Test_config *string `android:"arch_variant"`
+
+ // list of files or filegroup modules that provide data that should be installed alongside
+ // the test.
+ Data []string `android:"path,arch_variant"`
}
type ShBinary struct {
@@ -73,6 +77,8 @@ type ShTest struct {
ShBinary
testProperties TestProperties
+
+ data Paths
}
func (s *ShBinary) DepsMutator(ctx BottomUpMutatorContext) {
@@ -122,30 +128,54 @@ func (s *ShBinary) GenerateAndroidBuildActions(ctx ModuleContext) {
})
}
-func (s *ShBinary) AndroidMk() AndroidMkData {
- return AndroidMkData{
+func (s *ShBinary) AndroidMkEntries() AndroidMkEntries {
+ return AndroidMkEntries{
Class: "EXECUTABLES",
OutputFile: OptionalPathForPath(s.outputFilePath),
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
- Extra: []AndroidMkExtraFunc{
- func(w io.Writer, outputFile Path) {
- fmt.Fprintln(w, "LOCAL_MODULE_RELATIVE_PATH :=", String(s.properties.Sub_dir))
- fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX :=")
- fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", s.outputFilePath.Rel())
+ ExtraEntries: []AndroidMkExtraEntriesFunc{
+ func(entries *AndroidMkEntries) {
+ s.customAndroidMkEntries(entries)
},
},
}
}
-func (s *ShTest) AndroidMk() AndroidMkData {
- data := s.ShBinary.AndroidMk()
- data.Class = "NATIVE_TESTS"
- data.Extra = append(data.Extra, func(w io.Writer, outputFile Path) {
- fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
- strings.Join(s.testProperties.Test_suites, " "))
- fmt.Fprintln(w, "LOCAL_TEST_CONFIG :=", String(s.testProperties.Test_config))
- })
- return data
+func (s *ShBinary) customAndroidMkEntries(entries *AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_RELATIVE_PATH", String(s.properties.Sub_dir))
+ entries.SetString("LOCAL_MODULE_SUFFIX", "")
+ entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
+}
+
+func (s *ShTest) GenerateAndroidBuildActions(ctx ModuleContext) {
+ s.ShBinary.GenerateAndroidBuildActions(ctx)
+
+ s.data = PathsForModuleSrc(ctx, s.testProperties.Data)
+}
+
+func (s *ShTest) AndroidMkEntries() AndroidMkEntries {
+ return AndroidMkEntries{
+ Class: "NATIVE_TESTS",
+ OutputFile: OptionalPathForPath(s.outputFilePath),
+ Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
+ ExtraEntries: []AndroidMkExtraEntriesFunc{
+ func(entries *AndroidMkEntries) {
+ s.customAndroidMkEntries(entries)
+
+ entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
+ entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config))
+ for _, d := range s.data {
+ rel := d.Rel()
+ path := d.String()
+ if !strings.HasSuffix(path, rel) {
+ panic(fmt.Errorf("path %q does not end with %q", path, rel))
+ }
+ path = strings.TrimSuffix(path, rel)
+ entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
+ }
+ },
+ },
+ }
}
func InitShBinaryModule(s *ShBinary) {
@@ -170,6 +200,7 @@ func ShBinaryHostFactory() Module {
return module
}
+// sh_test defines a shell script based test module.
func ShTestFactory() Module {
module := &ShTest{}
InitShBinaryModule(&module.ShBinary)
@@ -178,3 +209,13 @@ func ShTestFactory() Module {
InitAndroidArchModule(module, HostAndDeviceSupported, MultilibFirst)
return module
}
+
+// sh_test_host defines a shell script based test module that runs on a host.
+func ShTestHostFactory() Module {
+ module := &ShTest{}
+ InitShBinaryModule(&module.ShBinary)
+ module.AddProperties(&module.testProperties)
+
+ InitAndroidArchModule(module, HostSupported, MultilibFirst)
+ return module
+}