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/cc/testing.go b/cc/testing.go
index 417ea4a..93f27cd 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -249,9 +249,41 @@
return ret
}
-func CreateTestContext(bp string, fs map[string][]byte,
- os android.OsType) *android.TestContext {
+func TestConfig(buildDir string, os android.OsType, env map[string]string,
+ bp string, fs map[string][]byte) android.Config {
+ // add some modules that are required by the compiler and/or linker
+ bp = bp + GatherRequiredDepsForTest(os)
+
+ mockFS := map[string][]byte{
+ "foo.c": nil,
+ "foo.lds": nil,
+ "bar.c": nil,
+ "baz.c": nil,
+ "baz.o": nil,
+ "a.proto": nil,
+ "b.aidl": nil,
+ "sub/c.aidl": nil,
+ "my_include": nil,
+ "foo.map.txt": nil,
+ "liba.so": nil,
+ }
+
+ for k, v := range fs {
+ mockFS[k] = v
+ }
+
+ var config android.Config
+ if os == android.Fuchsia {
+ config = android.TestArchConfigFuchsia(buildDir, env, bp, mockFS)
+ } else {
+ config = android.TestArchConfig(buildDir, env, bp, mockFS)
+ }
+
+ return config
+}
+
+func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_defaults", defaultsFactory)
ctx.RegisterModuleType("cc_binary", BinaryFactory)
@@ -283,29 +315,5 @@
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
- // add some modules that are required by the compiler and/or linker
- bp = bp + GatherRequiredDepsForTest(os)
-
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "foo.c": nil,
- "foo.lds": nil,
- "bar.c": nil,
- "baz.c": nil,
- "baz.o": nil,
- "a.proto": nil,
- "b.aidl": nil,
- "sub/c.aidl": nil,
- "my_include": nil,
- "foo.map.txt": nil,
- "liba.so": nil,
- }
-
- for k, v := range fs {
- mockFS[k] = v
- }
-
- ctx.MockFileSystem(mockFS)
-
return ctx
}