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/rust/rust_test.go b/rust/rust_test.go
index 01b89db..3be9ee7 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -51,6 +51,19 @@
os.Exit(run())
}
+func testConfig(bp string) android.Config {
+ bp = bp + GatherRequiredDepsForTest()
+
+ fs := map[string][]byte{
+ "foo.rs": nil,
+ "src/bar.rs": nil,
+ "liby.so": nil,
+ "libz.so": nil,
+ }
+
+ return android.TestArchConfig(buildDir, nil, bp, fs)
+}
+
func testRust(t *testing.T, bp string) *android.TestContext {
// TODO (b/140435149)
if runtime.GOOS != "linux" {
@@ -58,11 +71,11 @@
}
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := testConfig(bp)
t.Helper()
- ctx := CreateTestContext(bp)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
@@ -79,10 +92,10 @@
}
t.Helper()
- config := android.TestArchConfig(buildDir, nil)
+ config := testConfig(bp)
- ctx := CreateTestContext(bp)
- ctx.Register()
+ ctx := CreateTestContext()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
if len(errs) > 0 {
diff --git a/rust/testing.go b/rust/testing.go
index 2067f82..1dd16cf 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -162,7 +162,7 @@
return bp
}
-func CreateTestContext(bp string) *android.TestContext {
+func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
ctx.RegisterModuleType("cc_object", cc.ObjectFactory)
@@ -193,17 +193,6 @@
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel()
})
- bp = bp + GatherRequiredDepsForTest()
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.rs": nil,
- "src/bar.rs": nil,
- "liby.so": nil,
- "libz.so": nil,
- }
-
- ctx.MockFileSystem(mockFS)
return ctx
}