summaryrefslogtreecommitdiff
path: root/sh/sh_binary.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2023-11-15 12:39:40 -0800
committer Colin Cross <ccross@android.com> 2023-11-30 13:38:49 -0800
commit5c1d5fb21b19d6bcc8b0f83bc68124c21b31fabc (patch)
tree5cf196863f57dfc7ae817cf9ede98cf53126559f /sh/sh_binary.go
parent312634eb0fd02c2e084a6925c4f00e5fc00fca54 (diff)
Move test data installation to Soong
To generate module-info.json in Soong for b/309006256 Soong needs to know the test data paths. Moving test data installation into Soong will also help later for test suite packaging. Add ModuleContext.InstallTestData that installs the files listed in a []DataPath alongside the test. The files will also be passed to Make to allow it to continue packaging them into the test suites for now. Update the module types that are producing LOCAL_TEST_DATA entries in their Android.mk files to go through InstallTestData instead. Bug: 311428265 Test: atest --host toybox-gtests --test-timeout=120000 Change-Id: Ia8b964f86e584ea464667fd86a48d754d118bead
Diffstat (limited to 'sh/sh_binary.go')
-rw-r--r--sh/sh_binary.go47
1 files changed, 17 insertions, 30 deletions
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index 1bebc60be..6b40e3c67 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -17,7 +17,6 @@ package sh
import (
"fmt"
"path/filepath"
- "sort"
"strings"
"android/soong/testing"
@@ -174,7 +173,7 @@ type ShTest struct {
installDir android.InstallPath
- data android.Paths
+ data []android.DataPath
testConfig android.Path
dataModules map[string]android.Path
@@ -360,10 +359,21 @@ func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, pat
return
}
s.dataModules[relPath] = path
+ s.data = append(s.data, android.DataPath{SrcPath: path})
}
func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
s.ShBinary.generateAndroidBuildActions(ctx)
+
+ expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
+ // Emulate the data property for java_data dependencies.
+ for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) {
+ expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)
+ }
+ for _, d := range expandedData {
+ s.data = append(s.data, android.DataPath{SrcPath: d})
+ }
+
testDir := "nativetest"
if ctx.Target().Arch.ArchType.Multilib == "lib64" {
testDir = "nativetest64"
@@ -380,15 +390,6 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else {
s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
}
- s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
-
- expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
-
- // Emulate the data property for java_data dependencies.
- for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) {
- expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)
- }
- s.data = expandedData
var configs []tradefed.Config
if Bool(s.testProperties.Require_root) {
@@ -437,7 +438,7 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if _, exist := s.dataModules[relPath]; exist {
return
}
- relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath)
+ relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: cc.OutputFile().Path(),
@@ -453,6 +454,10 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
}
})
+
+ installedData := ctx.InstallTestData(s.installDir, s.data)
+ s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath, installedData...)
+
ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
@@ -473,24 +478,6 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
if s.testConfig != nil {
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
}
- 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)
- }
- relPaths := make([]string, 0)
- for relPath, _ := range s.dataModules {
- relPaths = append(relPaths, relPath)
- }
- sort.Strings(relPaths)
- for _, relPath := range relPaths {
- dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath)
- entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath)
- }
if s.testProperties.Data_bins != nil {
entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...)
}