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/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 5446bdc..9d4c1aa 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -52,8 +52,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("android_app", java.AndroidAppFactory)
@@ -82,13 +81,23 @@
ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
- ctx.Register()
+ ctx.Register(config)
- bp += java.GatherRequiredDepsForTest()
+ return ctx
+}
+
+func run(t *testing.T, ctx *android.TestContext, config android.Config) {
+ t.Helper()
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ android.FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ android.FailIfErrored(t, errs)
+}
+
+func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
bp += cc.GatherRequiredDepsForTest(android.Android)
mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
"a.java": nil,
"b.java": nil,
"c.java": nil,
@@ -134,21 +143,7 @@
mockFS[k] = v
}
- ctx.MockFileSystem(mockFS)
-
- return ctx
-}
-
-func run(t *testing.T, ctx *android.TestContext, config android.Config) {
- t.Helper()
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
-}
-
-func testConfig(env map[string]string) android.Config {
- config := java.TestConfig(buildDir, env)
+ config := java.TestConfig(buildDir, env, bp, mockFS)
config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
@@ -160,8 +155,8 @@
func test(t *testing.T, bp string) *android.TestContext {
t.Helper()
- config := testConfig(nil)
- ctx := testContext(config, bp, nil)
+ config := testConfig(nil, bp, nil)
+ ctx := testContext(config)
run(t, ctx, config)
return ctx