From 9f63090a4c951cb97c443d3a41c0c0d953999b59 Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Wed, 15 Nov 2017 14:49:48 -0800 Subject: [PATCH] Support files named Android.bp in tests Bug: 65683273 Test: m -j nothing # which runs unit tests Change-Id: I00862cd9673719424a2b18e347c7f9fe84be2857 --- context.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/context.go b/context.go index c7264a1..ab5efee 100644 --- a/context.go +++ b/context.go @@ -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)