diff options
author | 2023-01-24 11:48:08 -0800 | |
---|---|---|
committer | 2023-01-27 15:43:38 -0800 | |
commit | 5c503d1c434603370c442fbe29f330cc3f77e439 (patch) | |
tree | cb25cdf667a9995bbf0674d774fadb1e7d8cc0bd /python/binary.go | |
parent | 3420d978cf2d5fe614f12256595ff67be2ee6f98 (diff) |
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
Diffstat (limited to 'python/binary.go')
-rw-r--r-- | python/binary.go | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/python/binary.go b/python/binary.go index 95eb2c66c..75135f345 100644 --- a/python/binary.go +++ b/python/binary.go @@ -21,8 +21,6 @@ import ( "path/filepath" "strings" - "github.com/google/blueprint" - "android/soong/android" ) @@ -109,14 +107,14 @@ func (p *PythonBinaryModule) GenerateAndroidBuildActions(ctx android.ModuleConte } func (p *PythonBinaryModule) buildBinary(ctx android.ModuleContext) { - depsSrcsZips := p.collectPathsFromTransitiveDeps(ctx) + embeddedLauncher := p.isEmbeddedLauncherEnabled() + depsSrcsZips := p.collectPathsFromTransitiveDeps(ctx, embeddedLauncher) main := "" if p.autorun() { main = p.getPyMainFile(ctx, p.srcsPathMappings) } var launcherPath android.OptionalPath - embeddedLauncher := p.isEmbeddedLauncherEnabled() if embeddedLauncher { ctx.VisitDirectDepsWithTag(launcherTag, func(m android.Module) { if provider, ok := m.(IntermPathProvider); ok { @@ -128,9 +126,16 @@ func (p *PythonBinaryModule) buildBinary(ctx android.ModuleContext) { } }) } + srcsZips := make(android.Paths, 0, len(depsSrcsZips)+1) + if embeddedLauncher { + srcsZips = append(srcsZips, p.precompiledSrcsZip) + } else { + srcsZips = append(srcsZips, p.srcsZip) + } + srcsZips = append(srcsZips, depsSrcsZips...) p.installSource = registerBuildActionForParFile(ctx, embeddedLauncher, launcherPath, p.getHostInterpreterName(ctx, p.properties.Actual_version), - main, p.getStem(ctx), append(android.Paths{p.srcsZip}, depsSrcsZips...)) + main, p.getStem(ctx), srcsZips) var sharedLibs []string // if embedded launcher is enabled, we need to collect the shared library dependencies of the @@ -170,64 +175,8 @@ func (p *PythonBinaryModule) AndroidMkEntries() []android.AndroidMkEntries { func (p *PythonBinaryModule) DepsMutator(ctx android.BottomUpMutatorContext) { p.PythonLibraryModule.DepsMutator(ctx) - versionVariation := []blueprint.Variation{ - {"python_version", p.properties.Actual_version}, - } - - // If this module will be installed and has an embedded launcher, we need to add dependencies for: - // * standard library - // * launcher - // * shared dependencies of the launcher if p.isEmbeddedLauncherEnabled() { - var stdLib string - var launcherModule string - // Add launcher shared lib dependencies. Ideally, these should be - // derived from the `shared_libs` property of the launcher. However, we - // cannot read the property at this stage and it will be too late to add - // dependencies later. - launcherSharedLibDeps := []string{ - "libsqlite", - } - // Add launcher-specific dependencies for bionic - if ctx.Target().Os.Bionic() { - launcherSharedLibDeps = append(launcherSharedLibDeps, "libc", "libdl", "libm") - } - if ctx.Target().Os == android.LinuxMusl && !ctx.Config().HostStaticBinaries() { - launcherSharedLibDeps = append(launcherSharedLibDeps, "libc_musl") - } - - switch p.properties.Actual_version { - case pyVersion2: - stdLib = "py2-stdlib" - - launcherModule = "py2-launcher" - if p.autorun() { - launcherModule = "py2-launcher-autorun" - } - - launcherSharedLibDeps = append(launcherSharedLibDeps, "libc++") - - case pyVersion3: - stdLib = "py3-stdlib" - - launcherModule = "py3-launcher" - if p.autorun() { - launcherModule = "py3-launcher-autorun" - } - if ctx.Config().HostStaticBinaries() && ctx.Target().Os == android.LinuxMusl { - launcherModule += "-static" - } - - if ctx.Device() { - launcherSharedLibDeps = append(launcherSharedLibDeps, "liblog") - } - default: - panic(fmt.Errorf("unknown Python Actual_version: %q for module: %q.", - p.properties.Actual_version, ctx.ModuleName())) - } - ctx.AddVariationDependencies(versionVariation, pythonLibTag, stdLib) - ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule) - ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, launcherSharedLibDeps...) + p.AddDepsOnPythonLauncherAndStdlib(ctx, pythonLibTag, launcherTag, launcherSharedLibTag, p.autorun(), ctx.Target()) } } |