From dea7e4d93210fc56fee55fbbf5532da98f02d63c Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Fri, 17 Nov 2017 13:29:40 -0800 Subject: [PATCH] Autodetect files named Android.bp in tests Bug: 65683273 Test: m -j nothing # which runs unit tests Change-Id: I416530eba1f30ffe0c38609483d7e548b0a42198 --- android/testing.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/android/testing.go b/android/testing.go index e79562dae..3d5e9d930 100644 --- a/android/testing.go +++ b/android/testing.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "path/filepath" "strings" "github.com/google/blueprint" @@ -78,6 +79,25 @@ func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { return TestingModule{module} } +// MockFileSystem causes the Context to replace all reads with accesses to the provided map of +// filenames to contents stored as a byte slice. +func (ctx *TestContext) MockFileSystem(files map[string][]byte) { + // no module list file specified; find every file named Blueprints or Android.bp + pathsToParse := []string{} + for candidate := range files { + base := filepath.Base(candidate) + if base == "Blueprints" || base == "Android.bp" { + pathsToParse = append(pathsToParse, candidate) + } + } + if len(pathsToParse) < 1 { + panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", files)) + } + files[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n")) + + ctx.Context.MockFileSystem(files) +} + type TestingModule struct { module Module }