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
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 07de999..ea49e08 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -51,8 +51,7 @@
os.Exit(run())
}
-func testContext(config android.Config, bp string,
- fs map[string][]byte) *android.TestContext {
+func testContext(config android.Config) *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
@@ -61,8 +60,12 @@
ctx.RegisterModuleType("genrule_defaults", defaultsFactory)
ctx.RegisterModuleType("tool", toolFactory)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.Register()
+ ctx.Register(config)
+ return ctx
+}
+
+func testConfig(bp string, fs map[string][]byte) android.Config {
bp += `
tool {
name: "tool",
@@ -104,7 +107,6 @@
`
mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
"tool": nil,
"tool_file1": nil,
"tool_file2": nil,
@@ -119,9 +121,7 @@
mockFS[k] = v
}
- ctx.MockFileSystem(mockFS)
-
- return ctx
+ return android.TestArchConfig(buildDir, nil, bp, mockFS)
}
func TestGenruleCmd(t *testing.T) {
@@ -461,15 +461,15 @@
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := "genrule {\n"
bp += "name: \"gen\",\n"
bp += test.prop
bp += "}\n"
+ config := testConfig(bp, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(test.allowMissingDependencies)
- ctx := testContext(config, bp, nil)
+ ctx := testContext(config)
ctx.SetAllowMissingDependencies(test.allowMissingDependencies)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
@@ -546,14 +546,14 @@
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := "gensrcs {\n"
bp += `name: "gen",` + "\n"
bp += `output_extension: "h",` + "\n"
bp += test.prop
bp += "}\n"
- ctx := testContext(config, bp, nil)
+ config := testConfig(bp, nil)
+ ctx := testContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
@@ -595,7 +595,6 @@
}
func TestGenruleDefaults(t *testing.T) {
- config := android.TestArchConfig(buildDir, nil)
bp := `
genrule_defaults {
name: "gen_defaults1",
@@ -613,7 +612,8 @@
defaults: ["gen_defaults1", "gen_defaults2"],
}
`
- ctx := testContext(config, bp, nil)
+ config := testConfig(bp, nil)
+ ctx := testContext(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if errs == nil {
_, errs = ctx.PrepareBuildActions(config)