Merge "Move test data installation to Soong" into main

This commit is contained in:
Colin Cross 2023-12-01 18:56:01 +00:00 committed by Gerrit Code Review
commit 0d5dd390c6
17 changed files with 165 additions and 161 deletions

View file

@ -540,6 +540,10 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
a.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", base.katiSymlinks.InstallPaths().Paths())
}
if len(base.testData) > 0 {
a.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(base.testData)...)
}
if am, ok := mod.(ApexModule); ok {
a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform())
}
@ -936,10 +940,13 @@ func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
// A utility func to format LOCAL_TEST_DATA outputs. See the comments on DataPath to understand how
// to use this func.
func AndroidMkDataPaths(data []DataPath) []string {
func androidMkDataPaths(data []DataPath) []string {
var testFiles []string
for _, d := range data {
rel := d.SrcPath.Rel()
if d.WithoutRel {
rel = d.SrcPath.Base()
}
path := d.SrcPath.String()
// LOCAL_TEST_DATA requires the rel portion of the path to be removed from the path.
if !strings.HasSuffix(path, rel) {

View file

@ -50,7 +50,14 @@ func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
outputFiles = PathsIfNonNil(outputFiles...)
}
isContainer := isContainerFromFileExtensions(base.installFiles, outputFiles)
// Only pass the last installed file to isContainerFromFileExtensions so a *.zip file in test data
// doesn't mark the whole module as a container.
var installFiles InstallPaths
if len(base.installFiles) > 0 {
installFiles = InstallPaths{base.installFiles[len(base.installFiles)-1]}
}
isContainer := isContainerFromFileExtensions(installFiles, outputFiles)
var allDepMetadataFiles Paths
var allDepMetadataArgs []string

View file

@ -1115,6 +1115,7 @@ type ModuleBase struct {
// to Make to convert to ninja rules so that Make can add additional dependencies.
katiInstalls katiInstalls
katiSymlinks katiInstalls
testData []DataPath
// The files to copy to the dist as explicitly specified in the .bp file.
distFiles TaggedDistFiles
@ -2065,6 +2066,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
m.katiInstalls = append(m.katiInstalls, ctx.katiInstalls...)
m.katiSymlinks = append(m.katiSymlinks, ctx.katiSymlinks...)
m.testData = append(m.testData, ctx.testData...)
} else if ctx.Config().AllowMissingDependencies() {
// If the module is not enabled it will not create any build rules, nothing will call
// ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled

View file

@ -153,6 +153,15 @@ type ModuleContext interface {
// for which IsInstallDepNeeded returns true.
InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
// InstallTestData creates rules to install test data (e.g. data files used during a test) into
// the installPath directory.
//
// The installed files will be returned by FilesToInstall(), and the PackagingSpec for the
// installed files will be returned by PackagingSpecs() on this module or by
// TransitivePackagingSpecs() on modules that depend on this module through dependency tags
// for which IsInstallDepNeeded returns true.
InstallTestData(installPath InstallPath, data []DataPath) InstallPaths
// PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
// the rule to copy the file. This is useful to define how a module would be packaged
// without installing it into the global installation directories.
@ -213,6 +222,8 @@ type moduleContext struct {
katiInstalls []katiInstall
katiSymlinks []katiInstall
testData []DataPath
// For tests
buildParams []BuildParams
ruleParams map[blueprint.Rule]blueprint.RuleParams
@ -452,17 +463,17 @@ func (m *moduleContext) skipInstall() bool {
func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
deps ...InstallPath) InstallPath {
return m.installFile(installPath, name, srcPath, deps, false, nil)
return m.installFile(installPath, name, srcPath, deps, false, true, nil)
}
func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
deps ...InstallPath) InstallPath {
return m.installFile(installPath, name, srcPath, deps, true, nil)
return m.installFile(installPath, name, srcPath, deps, true, true, nil)
}
func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path,
extraZip Path, deps ...InstallPath) InstallPath {
return m.installFile(installPath, name, srcPath, deps, false, &extraFilesZip{
return m.installFile(installPath, name, srcPath, deps, false, true, &extraFilesZip{
zip: extraZip,
dir: installPath,
})
@ -488,10 +499,12 @@ func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, e
}
func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath,
executable bool, extraZip *extraFilesZip) InstallPath {
executable bool, hooks bool, extraZip *extraFilesZip) InstallPath {
fullInstallPath := installPath.Join(m, name)
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
if hooks {
m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
}
if !m.skipInstall() {
deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList())...)
@ -647,6 +660,19 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str
return fullInstallPath
}
func (m *moduleContext) InstallTestData(installPath InstallPath, data []DataPath) InstallPaths {
m.testData = append(m.testData, data...)
ret := make(InstallPaths, 0, len(data))
for _, d := range data {
relPath := d.ToRelativeInstallPath()
installed := m.installFile(installPath, relPath, d.SrcPath, nil, false, false, nil)
ret = append(ret, installed)
}
return ret
}
func (m *moduleContext) CheckbuildFile(srcPath Path) {
m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
}

View file

@ -2208,10 +2208,15 @@ type DataPath struct {
SrcPath Path
// The install path of the data file, relative to the install root.
RelativeInstallPath string
// If WithoutRel is true, use SrcPath.Base() instead of SrcPath.Rel() as the filename.
WithoutRel bool
}
func (d *DataPath) ToRelativeInstallPath() string {
relPath := d.SrcPath.Rel()
if d.WithoutRel {
relPath = d.SrcPath.Base()
}
if d.RelativeInstallPath != "" {
relPath = filepath.Join(d.RelativeInstallPath, relPath)
}

View file

@ -175,15 +175,6 @@ func androidMkWriteExtraTestConfigs(extraTestConfigs android.Paths, entries *and
}
}
func AndroidMkWriteTestData(data []android.DataPath, entries *android.AndroidMkEntries) {
testFiles := android.AndroidMkDataPaths(data)
if len(testFiles) > 0 {
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.AddStrings("LOCAL_TEST_DATA", testFiles...)
})
}
}
func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string {
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
var result []string
@ -379,11 +370,6 @@ func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entr
entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
}
})
dataPaths := []android.DataPath{}
for _, srcPath := range benchmark.data {
dataPaths = append(dataPaths, android.DataPath{SrcPath: srcPath})
}
AndroidMkWriteTestData(dataPaths, entries)
}
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
@ -411,40 +397,16 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
})
AndroidMkWriteTestData(test.data, entries)
androidMkWriteExtraTestConfigs(test.extraTestConfigs, entries)
}
func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
ctx.subAndroidMk(entries, fuzz.binaryDecorator)
var fuzzFiles []string
for _, d := range fuzz.fuzzPackagedModule.Corpus {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
}
for _, d := range fuzz.fuzzPackagedModule.Data {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
}
if fuzz.fuzzPackagedModule.Dictionary != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
}
if fuzz.fuzzPackagedModule.Config != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
}
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
if len(fuzzFiles) > 0 {
entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
}
if fuzz.installedSharedDeps != nil {
// TOOD: move to install dep
entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
}
})

View file

@ -106,6 +106,7 @@ type fuzzBinary struct {
fuzzPackagedModule fuzz.FuzzPackagedModule
installedSharedDeps []string
sharedLibraries android.RuleBuilderInstalls
data []android.DataPath
}
func (fuzz *fuzzBinary) fuzzBinary() bool {
@ -231,16 +232,10 @@ func SharedLibrarySymbolsInstallLocation(libraryBase string, fuzzDir string, arc
}
func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
installBase := "fuzz"
fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.dir64 = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.install(ctx, file)
fuzzBin.fuzzPackagedModule = PackageFuzzModule(ctx, fuzzBin.fuzzPackagedModule, pctx)
installBase := "fuzz"
// Grab the list of required shared libraries.
fuzzBin.sharedLibraries, _ = CollectAllSharedDependencies(ctx)
@ -256,34 +251,35 @@ func (fuzzBin *fuzzBinary) install(ctx ModuleContext, file android.Path) {
SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
}
}
for _, d := range fuzzBin.fuzzPackagedModule.Corpus {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, RelativeInstallPath: "corpus", WithoutRel: true})
}
for _, d := range fuzzBin.fuzzPackagedModule.Data {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, RelativeInstallPath: "data"})
}
if d := fuzzBin.fuzzPackagedModule.Dictionary; d != nil {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, WithoutRel: true})
}
if d := fuzzBin.fuzzPackagedModule.Config; d != nil {
fuzzBin.data = append(fuzzBin.data, android.DataPath{SrcPath: d, WithoutRel: true})
}
fuzzBin.binaryDecorator.baseInstaller.dir = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.dir64 = filepath.Join(
installBase, ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzzBin.binaryDecorator.baseInstaller.installTestData(ctx, fuzzBin.data)
fuzzBin.binaryDecorator.baseInstaller.install(ctx, file)
}
func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPackagedModule, pctx android.PackageContext) fuzz.FuzzPackagedModule {
fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Corpus)
intermediateDir := android.PathForModuleOut(ctx, "corpus")
// Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Corpus {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: intermediateDir.Join(ctx, entry.Base()),
Input: entry,
})
}
fuzzPackagedModule.CorpusIntermediateDir = intermediateDir
fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data)
intermediateDir = android.PathForModuleOut(ctx, "data")
// Create one rule per file to avoid MAX_ARG_STRLEN hardlimit.
for _, entry := range fuzzPackagedModule.Data {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: intermediateDir.Join(ctx, entry.Rel()),
Input: entry,
})
}
fuzzPackagedModule.DataIntermediateDir = intermediateDir
if fuzzPackagedModule.FuzzProperties.Dictionary != nil {
fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzzPackagedModule.FuzzProperties.Dictionary)

View file

@ -59,6 +59,8 @@ type baseInstaller struct {
relative string
location installLocation
installDeps android.InstallPaths
path android.InstallPath
}
@ -97,7 +99,12 @@ func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPat
}
func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file, installer.installDeps...)
}
func (installer *baseInstaller) installTestData(ctx ModuleContext, data []android.DataPath) {
installedData := ctx.InstallTestData(installer.installDir(ctx), data)
installer.installDeps = append(installer.installDeps, installedData...)
}
func (installer *baseInstaller) everInstallable() bool {

View file

@ -424,6 +424,8 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
if ctx.Host() && test.gtest() && test.Properties.Test_options.Unit_test == nil {
test.Properties.Test_options.Unit_test = proptools.BoolPtr(true)
}
test.binaryDecorator.baseInstaller.installTestData(ctx, test.data)
test.binaryDecorator.baseInstaller.install(ctx, file)
}
@ -584,7 +586,7 @@ type BenchmarkProperties struct {
type benchmarkDecorator struct {
*binaryDecorator
Properties BenchmarkProperties
data android.Paths
data []android.DataPath
testConfig android.Path
}
@ -605,7 +607,9 @@ func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps
}
func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
for _, d := range android.PathsForModuleSrc(ctx, benchmark.Properties.Data) {
benchmark.data = append(benchmark.data, android.DataPath{SrcPath: d})
}
var configs []tradefed.Config
if Bool(benchmark.Properties.Require_root) {
@ -623,6 +627,7 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
benchmark.binaryDecorator.baseInstaller.installTestData(ctx, benchmark.data)
benchmark.binaryDecorator.baseInstaller.install(ctx, file)
}

View file

@ -399,13 +399,11 @@ type FuzzProperties struct {
}
type FuzzPackagedModule struct {
FuzzProperties FuzzProperties
Dictionary android.Path
Corpus android.Paths
CorpusIntermediateDir android.Path
Config android.Path
Data android.Paths
DataIntermediateDir android.Path
FuzzProperties FuzzProperties
Dictionary android.Path
Corpus android.Paths
Config android.Path
Data android.Paths
}
func GetFramework(ctx android.LoadHookContext, lang Lang) Framework {

View file

@ -188,8 +188,6 @@ func (p *PythonTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext
panic(fmt.Errorf("unknown python test runner '%s', should be 'tradefed' or 'mobly'", runner))
}
p.installedDest = ctx.InstallFile(installDir(ctx, "nativetest", "nativetest64", ctx.ModuleName()), p.installSource.Base(), p.installSource)
for _, dataSrcPath := range android.PathsForModuleSrc(ctx, p.testProperties.Data) {
p.data = append(p.data, android.DataPath{SrcPath: dataSrcPath})
}
@ -206,6 +204,11 @@ func (p *PythonTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext
p.data = append(p.data, android.DataPath{SrcPath: javaDataSrcPath})
}
}
installDir := installDir(ctx, "nativetest", "nativetest64", ctx.ModuleName())
installedData := ctx.InstallTestData(installDir, p.data)
p.installedDest = ctx.InstallFile(installDir, p.installSource.Base(), p.installSource, installedData...)
ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
@ -227,8 +230,6 @@ func (p *PythonTestModule) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(p.binaryProperties.Auto_gen_config, true))
entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
p.testProperties.Test_options.SetAndroidMkEntries(entries)
})

View file

@ -18,7 +18,6 @@ import (
"path/filepath"
"android/soong/android"
"android/soong/cc"
)
type AndroidMkContext interface {
@ -114,8 +113,6 @@ func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidM
test.Properties.Test_options.SetAndroidMkEntries(entries)
})
cc.AndroidMkWriteTestData(test.data, ret)
}
func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
@ -216,33 +213,9 @@ func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.Andro
func (fuzz *fuzzDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
ctx.SubAndroidMk(ret, fuzz.binaryDecorator)
var fuzzFiles []string
for _, d := range fuzz.fuzzPackagedModule.Corpus {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.CorpusIntermediateDir.String())+":corpus/"+d.Base())
}
for _, d := range fuzz.fuzzPackagedModule.Data {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.DataIntermediateDir.String())+":data/"+d.Rel())
}
if fuzz.fuzzPackagedModule.Dictionary != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Dictionary.String())+":"+fuzz.fuzzPackagedModule.Dictionary.Base())
}
if fuzz.fuzzPackagedModule.Config != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.fuzzPackagedModule.Config.String())+":config.json")
}
ret.ExtraEntries = append(ret.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext,
entries *android.AndroidMkEntries) {
entries.SetBool("LOCAL_IS_FUZZ_TARGET", true)
if len(fuzzFiles) > 0 {
entries.AddStrings("LOCAL_TEST_DATA", fuzzFiles...)
}
if fuzz.installedSharedDeps != nil {
entries.AddStrings("LOCAL_FUZZ_INSTALLED_SHARED_DEPS", fuzz.installedSharedDeps...)
}

View file

@ -239,6 +239,8 @@ type baseCompiler struct {
distFile android.OptionalPath
installDeps android.InstallPaths
// unstripped output file.
unstrippedOutputFile android.Path
@ -538,7 +540,12 @@ func (compiler *baseCompiler) nativeCoverage() bool {
func (compiler *baseCompiler) install(ctx ModuleContext) {
path := ctx.RustModule().OutputFile()
compiler.path = ctx.InstallFile(compiler.installDir(ctx), path.Path().Base(), path.Path())
compiler.path = ctx.InstallFile(compiler.installDir(ctx), path.Path().Base(), path.Path(), compiler.installDeps...)
}
func (compiler *baseCompiler) installTestData(ctx ModuleContext, data []android.DataPath) {
installedData := ctx.InstallTestData(compiler.installDir(ctx), data)
compiler.installDeps = append(compiler.installDeps, installedData...)
}
func (compiler *baseCompiler) getStem(ctx ModuleContext) string {

View file

@ -15,12 +15,11 @@
package rust
import (
"path/filepath"
"android/soong/android"
"android/soong/cc"
"android/soong/fuzz"
"android/soong/rust/config"
"path/filepath"
)
func init() {
@ -131,12 +130,6 @@ func (fuzzer *fuzzDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep
}
func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
fuzz.binaryDecorator.baseCompiler.dir = filepath.Join(
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzz.binaryDecorator.baseCompiler.dir64 = filepath.Join(
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzz.binaryDecorator.baseCompiler.install(ctx)
fuzz.fuzzPackagedModule = cc.PackageFuzzModule(ctx, fuzz.fuzzPackagedModule, pctx)
installBase := "fuzz"
@ -157,4 +150,30 @@ func (fuzz *fuzzDecorator) install(ctx ModuleContext) {
cc.SharedLibrarySymbolsInstallLocation(install, installBase, ctx.Arch().ArchType.String()))
}
}
var fuzzData []android.DataPath
for _, d := range fuzz.fuzzPackagedModule.Corpus {
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, RelativeInstallPath: "corpus", WithoutRel: true})
}
for _, d := range fuzz.fuzzPackagedModule.Data {
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, RelativeInstallPath: "data"})
}
if d := fuzz.fuzzPackagedModule.Dictionary; d != nil {
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, WithoutRel: true})
}
if d := fuzz.fuzzPackagedModule.Config; d != nil {
fuzzData = append(fuzzData, android.DataPath{SrcPath: d, WithoutRel: true})
}
fuzz.binaryDecorator.baseCompiler.dir = filepath.Join(
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzz.binaryDecorator.baseCompiler.dir64 = filepath.Join(
"fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName())
fuzz.binaryDecorator.baseCompiler.installTestData(ctx, fuzzData)
fuzz.binaryDecorator.baseCompiler.install(ctx)
}

View file

@ -189,6 +189,7 @@ func (test *testDecorator) install(ctx ModuleContext) {
if ctx.Host() && test.Properties.Test_options.Unit_test == nil {
test.Properties.Test_options.Unit_test = proptools.BoolPtr(true)
}
test.binaryDecorator.installTestData(ctx, test.data)
test.binaryDecorator.install(ctx)
}

View file

@ -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...)
}

View file

@ -135,7 +135,7 @@ func TestShTest_dataModules(t *testing.T) {
if arch == "darwin_x86_64" {
libExt = ".dylib"
}
relocated := variant.Output("relocated/lib64/libbar" + libExt)
relocated := variant.Output(filepath.Join("out/soong/.intermediates/foo", arch, "relocated/lib64/libbar"+libExt))
expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
@ -204,18 +204,19 @@ func TestShTestHost_dataDeviceModules(t *testing.T) {
`)
buildOS := config.BuildOS.String()
variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
variant := buildOS + "_x86_64"
foo := ctx.ModuleForTests("foo", variant)
relocated := variant.Output("relocated/lib64/libbar.so")
relocated := foo.Output(filepath.Join("out/soong/.intermediates/foo", variant, "relocated/lib64/libbar.so"))
expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so"
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
mod := variant.Module().(*ShTest)
mod := foo.Module().(*ShTest)
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedData := []string{
"out/soong/.intermediates/bar/android_arm64_armv8-a/:bar",
// libbar has been relocated, and so has a variant that matches the host arch.
"out/soong/.intermediates/foo/" + buildOS + "_x86_64/relocated/:lib64/libbar.so",
"out/soong/.intermediates/foo/" + variant + "/relocated/:lib64/libbar.so",
}
actualData := entries.EntryMap["LOCAL_TEST_DATA"]
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)