diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-11-22 22:30:13 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-22 22:30:13 +0000 |
commit | b06ad36c1f8a669302d2e41051018688f553b3c7 (patch) | |
tree | e6d03c63b6e7716aae1d4e428996f324002456e5 | |
parent | 5c986c3dc3865c22197d4730e1c2c3d5596bb836 (diff) | |
parent | dea7e4d93210fc56fee55fbbf5532da98f02d63c (diff) | |
download | build_soong-b06ad36c1f8a669302d2e41051018688f553b3c7.tar.gz build_soong-b06ad36c1f8a669302d2e41051018688f553b3c7.tar.bz2 build_soong-b06ad36c1f8a669302d2e41051018688f553b3c7.zip |
Merge "Autodetect files named Android.bp in tests"
-rw-r--r-- | android/testing.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/android/testing.go b/android/testing.go index e79562da..3d5e9d93 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 } |