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/android/paths_test.go b/android/paths_test.go
index a8560a1..5ff5f99 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -241,8 +241,12 @@
return false
}
+func pathTestConfig(buildDir string) Config {
+ return TestConfig(buildDir, nil, "", nil)
+}
+
func TestPathForModuleInstall(t *testing.T) {
- testConfig := TestConfig("", nil)
+ testConfig := pathTestConfig("")
hostTarget := Target{Os: Linux}
deviceTarget := Target{Os: Android}
@@ -579,18 +583,19 @@
}
func TestDirectorySortedPaths(t *testing.T) {
- config := TestConfig("out", nil)
-
- ctx := PathContextForTesting(config, map[string][]byte{
- "a.txt": nil,
- "a/txt": nil,
- "a/b/c": nil,
- "a/b/d": nil,
- "b": nil,
- "b/b.txt": nil,
- "a/a.txt": nil,
+ config := TestConfig("out", nil, "", map[string][]byte{
+ "Android.bp": nil,
+ "a.txt": nil,
+ "a/txt": nil,
+ "a/b/c": nil,
+ "a/b/d": nil,
+ "b": nil,
+ "b/b.txt": nil,
+ "a/a.txt": nil,
})
+ ctx := PathContextForTesting(config)
+
makePaths := func() Paths {
return Paths{
PathForSource(ctx, "a.txt"),
@@ -754,7 +759,7 @@
t.Run(f.name, func(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- testConfig := TestConfig(test.buildDir, nil)
+ testConfig := pathTestConfig(test.buildDir)
ctx := &configErrorWrapper{config: testConfig}
_, err := f.f(ctx, test.src)
if len(ctx.errors) > 0 {
@@ -886,7 +891,6 @@
func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSrcTestCase) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- config := TestConfig(buildDir, nil)
ctx := NewTestContext()
ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
@@ -920,9 +924,9 @@
"foo/src_special/$": nil,
}
- ctx.MockFileSystem(mockFS)
+ config := TestConfig(buildDir, nil, "", mockFS)
- ctx.Register()
+ ctx.Register(config)
_, errs := ctx.ParseFileList(".", []string{"fg/Android.bp", "foo/Android.bp", "ofp/Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -1097,14 +1101,6 @@
}
func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
- config := TestConfig(buildDir, nil)
- config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
-
- ctx := NewTestContext()
- ctx.SetAllowMissingDependencies(true)
-
- ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
-
bp := `
test {
name: "foo",
@@ -1121,13 +1117,16 @@
}
`
- mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- }
+ config := TestConfig(buildDir, nil, bp, nil)
+ config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
- ctx.MockFileSystem(mockFS)
+ ctx := NewTestContext()
+ ctx.SetAllowMissingDependencies(true)
- ctx.Register()
+ ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
+
+ ctx.Register(config)
+
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -1160,7 +1159,7 @@
func ExampleOutputPath_ReplaceExtension() {
ctx := &configErrorWrapper{
- config: TestConfig("out", nil),
+ config: TestConfig("out", nil, "", nil),
}
p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art")
p2 := p.ReplaceExtension(ctx, "oat")
@@ -1174,7 +1173,7 @@
func ExampleOutputPath_FileInSameDir() {
ctx := &configErrorWrapper{
- config: TestConfig("out", nil),
+ config: TestConfig("out", nil, "", nil),
}
p := PathForOutput(ctx, "system/framework").Join(ctx, "boot.art")
p2 := p.InSameDir(ctx, "oat", "arm", "boot.vdex")