summaryrefslogtreecommitdiff
path: root/python/python.go
diff options
context:
space:
mode:
author Dan Willemsen <dwillemsen@google.com> 2023-08-15 22:17:03 -0400
committer Dan Willemsen <dwillemsen@google.com> 2023-08-16 21:47:03 -0400
commit339a63f04469ebf69a0b3ca729243eefd838a572 (patch)
treef8a1d4d1dbfe1c61acacacbcb5120fb9e1a66562 /python/python.go
parentd89ee08bbfc12de7de402eb22ab5da6436f283c4 (diff)
Prepare soong for python 3.11
Due to upstream changes in python path calculations, I'm simplifying the python launcher to work more like a standard python distribution. This is effectively changing the stdlib path from `internal/stdlib` to `internal/python3.10` (or `3.11`, etc). This allows us to specify the zip file as PYTHONHOME, set PYTHONPLATLIBDIR to `internal` and use the default detection after that. That does mean during upgrades that the stdlib pkg path will change, so move the source vs prebuilt calculation from the Android.bp into Soong to choose which stdlib module to pick up (with the corresponding `pkg_path`) Bug: 278602456 Test: treehugger with python3.10 Test: a python3.11 source + 3.10 prebuilt build Test: a python3.11 source+prebuilt build Change-Id: I8b02e7b22a1f1d1e02819ae1a31a99cdc985542c
Diffstat (limited to 'python/python.go')
-rw-r--r--python/python.go36
1 files changed, 32 insertions, 4 deletions
diff --git a/python/python.go b/python/python.go
index 8fde638b4..6c837a888 100644
--- a/python/python.go
+++ b/python/python.go
@@ -169,6 +169,7 @@ type pythonDependency interface {
getDataPathMappings() []pathMapping
getSrcsZip() android.Path
getPrecompiledSrcsZip() android.Path
+ getPkgPath() string
}
// getSrcsPathMappings gets this module's path mapping of src source path : runfiles destination
@@ -191,6 +192,11 @@ func (p *PythonLibraryModule) getPrecompiledSrcsZip() android.Path {
return p.precompiledSrcsZip
}
+// getPkgPath returns the pkg_path value
+func (p *PythonLibraryModule) getPkgPath() string {
+ return String(p.properties.Pkg_path)
+}
+
func (p *PythonLibraryModule) getBaseProperties() *BaseProperties {
return &p.properties
}
@@ -370,7 +376,20 @@ func (p *PythonLibraryModule) AddDepsOnPythonLauncherAndStdlib(ctx android.Botto
launcherSharedLibDeps = append(launcherSharedLibDeps, "libc++")
case pyVersion3:
- stdLib = "py3-stdlib"
+ var prebuiltStdLib bool
+ if targetForDeps.Os.Bionic() {
+ prebuiltStdLib = false
+ } else if ctx.Config().VendorConfig("cpython3").Bool("force_build_host") {
+ prebuiltStdLib = false
+ } else {
+ prebuiltStdLib = true
+ }
+
+ if prebuiltStdLib {
+ stdLib = "py3-stdlib-prebuilt"
+ } else {
+ stdLib = "py3-stdlib"
+ }
launcherModule = "py3-launcher"
if autorun {
@@ -461,14 +480,19 @@ func (p *PythonLibraryModule) genModulePathMappings(ctx android.ModuleContext, p
destToPySrcs := make(map[string]string)
destToPyData := make(map[string]string)
+ // Disable path checks for the stdlib, as it includes a "." in the version string
+ isInternal := proptools.BoolDefault(p.properties.Is_internal, false)
+
for _, s := range expandedSrcs {
if s.Ext() != pyExt && s.Ext() != protoExt {
ctx.PropertyErrorf("srcs", "found non (.py|.proto) file: %q!", s.String())
continue
}
runfilesPath := filepath.Join(pkgPath, s.Rel())
- if err := isValidPythonPath(runfilesPath); err != nil {
- ctx.PropertyErrorf("srcs", err.Error())
+ if !isInternal {
+ if err := isValidPythonPath(runfilesPath); err != nil {
+ ctx.PropertyErrorf("srcs", err.Error())
+ }
}
if !checkForDuplicateOutputPath(ctx, destToPySrcs, runfilesPath, s.String(), p.Name(), p.Name()) {
p.srcsPathMappings = append(p.srcsPathMappings, pathMapping{dest: runfilesPath, src: s})
@@ -591,13 +615,16 @@ func (p *PythonLibraryModule) precompileSrcs(ctx android.ModuleContext) android.
// "cross compiling" for device here purely by virtue of host and device python bytecode
// being the same.
var stdLib android.Path
+ var stdLibPkg string
var launcher android.Path
- if ctx.ModuleName() == "py3-stdlib" || ctx.ModuleName() == "py2-stdlib" {
+ if proptools.BoolDefault(p.properties.Is_internal, false) {
stdLib = p.srcsZip
+ stdLibPkg = p.getPkgPath()
} else {
ctx.VisitDirectDepsWithTag(hostStdLibTag, func(module android.Module) {
if dep, ok := module.(pythonDependency); ok {
stdLib = dep.getPrecompiledSrcsZip()
+ stdLibPkg = dep.getPkgPath()
}
})
}
@@ -636,6 +663,7 @@ func (p *PythonLibraryModule) precompileSrcs(ctx android.ModuleContext) android.
Description: "Precompile the python sources of " + ctx.ModuleName(),
Args: map[string]string{
"stdlibZip": stdLib.String(),
+ "stdlibPkg": stdLibPkg,
"launcher": launcher.String(),
"ldLibraryPath": strings.Join(ldLibraryPath, ":"),
},