Move filesystem into Config

The filesystem object was available through ModuleContext.Fs(), but
gives too much access to the filesystem without enforicing correct
dependencies.  In order to support sandboxing the soong_build
process move the filesystem into the Config.  The next change will
make it private.

Bug: 146437378
Test: all Soong tests
Change-Id: I5d3ae9108f120fd335b21efd612aefa078378813
This commit is contained in:
Colin Cross
2019-12-13 20:41:13 -08:00
parent 572aeed6a4
commit 98be1bb00f
42 changed files with 765 additions and 793 deletions

View File

@@ -16,7 +16,6 @@ package android
import (
"fmt"
"path/filepath"
"regexp"
"strings"
"testing"
@@ -68,7 +67,11 @@ func (ctx *TestContext) PostDepsMutators(f RegisterMutatorFunc) {
ctx.postDeps = append(ctx.postDeps, f)
}
func (ctx *TestContext) Register() {
func (ctx *TestContext) Register(config Config) {
ctx.SetFs(config.fs)
if config.mockBpList != "" {
ctx.SetModuleListFile(config.mockBpList)
}
registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps)
ctx.RegisterSingletonType("env", EnvSingleton)
@@ -132,25 +135,6 @@ func (ctx *TestContext) SingletonForTests(name string) TestingSingleton {
"\nall singletons: %v", name, allSingletonNames))
}
// 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 testBuildProvider interface {
BuildParamsForTests() []BuildParams
RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams