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
This commit is contained in:
Cole Faust
2023-01-24 11:48:08 -08:00
parent 3420d978cf
commit 5c503d1c43
11 changed files with 295 additions and 96 deletions

View File

@@ -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 {