From 5c503d1c434603370c442fbe29f330cc3f77e439 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 24 Jan 2023 11:48:08 -0800 Subject: Precompile python sources This signifigantly improves the startup time of soong-built python binaries. For example, running `m apexer && time out/host/linux-x86/bin/apexer` gives 0.734s before this cl, and 0.094s after. Fixes: 259718110 Test: Presubmits Change-Id: Ib19e83e2c60c39a849525be117279c318de3afa7 --- python/python_test.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'python/python_test.go') diff --git a/python/python_test.go b/python/python_test.go index 6f4223a7c..75a6a899b 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -18,10 +18,10 @@ import ( "fmt" "os" "path/filepath" - "regexp" "testing" "android/soong/android" + "android/soong/cc" ) type pyModule struct { @@ -33,8 +33,10 @@ type pyModule struct { } var ( - buildNamePrefix = "soong_python_test" - moduleVariantErrTemplate = "%s: module %q variant %q: " + buildNamePrefix = "soong_python_test" + // We allow maching almost anything before the actual variant so that the os/arch variant + // is matched. + moduleVariantErrTemplate = `%s: module %q variant "[a-zA-Z0-9_]*%s": ` pkgPathErrTemplate = moduleVariantErrTemplate + "pkg_path: %q must be a relative path contained in par file." badIdentifierErrTemplate = moduleVariantErrTemplate + @@ -323,17 +325,26 @@ func TestPythonModule(t *testing.T) { if d.desc != "module with duplicate runfile path" { continue } - errorPatterns := make([]string, len(d.errors)) - for i, s := range d.errors { - errorPatterns[i] = regexp.QuoteMeta(s) - } + d.mockFiles[filepath.Join("common", bpFile)] = []byte(` +python_library { + name: "py3-stdlib", + host_supported: true, +} +cc_binary { + name: "py3-launcher", + host_supported: true, +} +`) t.Run(d.desc, func(t *testing.T) { result := android.GroupFixturePreparers( android.PrepareForTestWithDefaults, + android.PrepareForTestWithArchMutator, + android.PrepareForTestWithAllowMissingDependencies, + cc.PrepareForTestWithCcDefaultModules, PrepareForTestWithPythonBuildComponents, d.mockFiles.AddToFixture(), - ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(errorPatterns)). + ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(d.errors)). RunTest(t) if len(result.Errs) > 0 { -- cgit v1.2.3-59-g8ed1b