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
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user