diff options
author | Colin Cross <ccross@android.com> | 2019-12-13 20:41:13 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-12-18 08:19:10 -0800 |
commit | 98be1bb00f0fb10e195f26fd2a19952d701a1950 (patch) | |
tree | abc06a5a4184a6607755d32f927d886c1d099249 /python | |
parent | 572aeed6a4211d7433cd59fe9c83f34b2fee4f99 (diff) | |
download | build_soong-98be1bb00f0fb10e195f26fd2a19952d701a1950.tar.gz build_soong-98be1bb00f0fb10e195f26fd2a19952d701a1950.tar.bz2 build_soong-98be1bb00f0fb10e195f26fd2a19952d701a1950.zip |
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
Diffstat (limited to 'python')
-rw-r--r-- | python/python_test.go | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/python/python_test.go b/python/python_test.go index ba5e7fad..1245ca18 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -28,6 +28,8 @@ import ( "android/soong/android" ) +var buildDir string + type pyModule struct { name string actualVersion string @@ -50,7 +52,7 @@ var ( noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!" badSrcFileExtErr = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!" badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!" - bpFile = "Blueprints" + bpFile = "Android.bp" data = []struct { desc string @@ -71,7 +73,7 @@ var ( }, errors: []string{ fmt.Sprintf(noSrcFileErr, - "dir/Blueprints:1:1", "lib1", "PY3"), + "dir/Android.bp:1:1", "lib1", "PY3"), }, }, { @@ -90,7 +92,7 @@ var ( }, errors: []string{ fmt.Sprintf(badSrcFileExtErr, - "dir/Blueprints:3:11", "lib1", "PY3", "dir/file1.exe"), + "dir/Android.bp:3:11", "lib1", "PY3", "dir/file1.exe"), }, }, { @@ -113,7 +115,7 @@ var ( }, errors: []string{ fmt.Sprintf(badDataFileExtErr, - "dir/Blueprints:6:11", "lib1", "PY3", "dir/file2.py"), + "dir/Android.bp:6:11", "lib1", "PY3", "dir/file2.py"), }, }, { @@ -149,9 +151,9 @@ var ( }, errors: []string{ fmt.Sprintf(pkgPathErrTemplate, - "dir/Blueprints:11:15", "lib2", "PY3", "a/c/../../../"), + "dir/Android.bp:11:15", "lib2", "PY3", "a/c/../../../"), fmt.Sprintf(pkgPathErrTemplate, - "dir/Blueprints:19:15", "lib3", "PY3", "/a/c/../../"), + "dir/Android.bp:19:15", "lib3", "PY3", "/a/c/../../"), }, }, { @@ -174,11 +176,11 @@ var ( "dir/-e/f/file1.py": nil, }, errors: []string{ - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"), - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/.file1.py", ".file1"), - fmt.Sprintf(badIdentifierErrTemplate, "dir/Blueprints:4:11", + fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11", "lib1", "PY3", "a/b/c/123/file1.py", "123"), }, }, @@ -211,7 +213,7 @@ var ( "dir/file1.py": nil, }, errors: []string{ - fmt.Sprintf(dupRunfileErrTemplate, "dir/Blueprints:9:6", + fmt.Sprintf(dupRunfileErrTemplate, "dir/Android.bp:9:6", "lib2", "PY3", "a/b/c/file1.py", "lib2", "dir/file1.py", "lib1", "dir/c/file1.py"), }, @@ -324,10 +326,9 @@ var ( ) func TestPythonModule(t *testing.T) { - config, buildDir := setupBuildEnv(t) - defer tearDownBuildEnv(buildDir) for _, d := range data { t.Run(d.desc, func(t *testing.T) { + config := android.TestConfig(buildDir, nil, "", d.mockFiles) ctx := android.NewTestContext() ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("version_split", versionSplitMutator()).Parallel() @@ -336,8 +337,7 @@ func TestPythonModule(t *testing.T) { ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory) ctx.RegisterModuleType("python_defaults", defaultsFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) - ctx.Register() - ctx.MockFileSystem(d.mockFiles) + ctx.Register(config) _, testErrs := ctx.ParseBlueprintsFiles(bpFile) android.FailIfErrored(t, testErrs) _, actErrs := ctx.PrepareBuildActions(config) @@ -425,17 +425,25 @@ func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, varian return } -func setupBuildEnv(t *testing.T) (config android.Config, buildDir string) { - buildDir, err := ioutil.TempDir("", buildNamePrefix) +func setUp() { + var err error + buildDir, err = ioutil.TempDir("", "soong_python_test") if err != nil { - t.Fatal(err) + panic(err) } - - config = android.TestConfig(buildDir, nil) - - return } -func tearDownBuildEnv(buildDir string) { +func tearDown() { os.RemoveAll(buildDir) } + +func TestMain(m *testing.M) { + run := func() int { + setUp() + defer tearDown() + + return m.Run() + } + + os.Exit(run()) +} |