Support files named Android.bp in tests

Bug: 65683273
Test: m -j nothing # which runs unit tests

Change-Id: I00862cd9673719424a2b18e347c7f9fe84be2857
This commit is contained in:
Jeff Gaston 2017-11-15 14:49:48 -08:00
parent 7ab9124b27
commit 9f63090a4c

View file

@ -40,6 +40,7 @@ import (
var ErrBuildActionsNotReady = errors.New("build actions are not ready")
const maxErrors = 10
const MockModuleListFile = "bplist"
// A Context contains all the state needed to parse a set of Blueprints files
// and generate a Ninja file. The process of generating a Ninja file proceeds
@ -798,17 +799,23 @@ loop:
// MockFileSystem causes the Context to replace all reads with accesses to the provided map of
// filenames to contents stored as a byte slice.
func (c *Context) MockFileSystem(files map[string][]byte) {
// find every file named "Blueprints"
pathsToParse := []string{}
for candidate := range files {
if filepath.Base(candidate) == "Blueprints" {
pathsToParse = append(pathsToParse, candidate)
// look for a module list file
_, ok := files[MockModuleListFile]
if !ok {
// no module list file specified; find every file named Blueprints
pathsToParse := []string{}
for candidate := range files {
if filepath.Base(candidate) == "Blueprints" {
pathsToParse = append(pathsToParse, candidate)
}
}
if len(pathsToParse) < 1 {
panic(fmt.Sprintf("No Blueprints files found in mock filesystem: %v\n", files))
}
// put the list of Blueprints files into a list file
files[MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n"))
}
// put the list of Blueprints files into a list file
listFile := "bplist"
files[listFile] = []byte(strings.Join(pathsToParse, "\n"))
c.SetModuleListFile(listFile)
c.SetModuleListFile(MockModuleListFile)
// mock the filesystem
c.fs = pathtools.MockFs(files)