bpo-39936: _aix_support uses _bootsubprocess (GH-18970)

AIX: Fix _aix_support module when the subprocess is not available,
when building Python from scratch. It now uses new private
_bootsubprocess module, rather than having two implementations
depending if subprocess is available or not. So
_aix_support.aix_platform() result is now the same if subprocess is
available or not.
This commit is contained in:
Victor Stinner 2020-03-12 23:15:34 +01:00 committed by GitHub
parent 1ae9cde4b2
commit c846ef004d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 35 deletions

View File

@ -1,35 +1,20 @@
"""Shared AIX support functions.""" """Shared AIX support functions."""
import sys import sys
from sysconfig import get_config_var import sysconfig
# subprocess is not necessarily available early in the build process
# if not available, the config_vars are also definitely not available
# supply substitutes to bootstrap the build
try: try:
import subprocess import subprocess
_have_subprocess = True
_tmp_bd = get_config_var("AIX_BUILDDATE")
_bgt = get_config_var("BUILD_GNU_TYPE")
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
_have_subprocess = False # _aix_support is used in distutils by setup.py to build C extensions,
_tmp_bd = None # before subprocess dependencies like _posixsubprocess are available.
_bgt = "powerpc-ibm-aix6.1.7.0" import _bootsubprocess as subprocess
# if get_config_var("AIX_BUILDDATE") was unknown, provide a substitute,
# impossible builddate to specify 'unknown'
_MISSING_BD = 9898
try:
_bd = int(_tmp_bd)
except TypeError:
_bd = _MISSING_BD
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
_sz = 32 if sys.maxsize == (2**31-1) else 64
def _aix_tag(vrtl, bd): def _aix_tag(vrtl, bd):
# type: (List[int], int) -> str # type: (List[int], int) -> str
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
_sz = 32 if sys.maxsize == (2**31-1) else 64
# vrtl[version, release, technology_level] # vrtl[version, release, technology_level]
return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], bd, _sz) return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], bd, _sz)
@ -48,17 +33,12 @@ def _aix_bosmp64():
The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate
reflect the current ABI levels of the runtime environment. reflect the current ABI levels of the runtime environment.
""" """
if _have_subprocess: # We expect all AIX systems to have lslpp installed in this location
# We expect all AIX systems to have lslpp installed in this location out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"])
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"]) out = out.decode("utf-8")
out = out.decode("utf-8").strip().split(":") # type: ignore out = out.strip().split(":") # type: ignore
# Use str() and int() to help mypy see types # Use str() and int() to help mypy see types
return str(out[2]), int(out[-1]) return (str(out[2]), int(out[-1]))
else:
from os import uname
osname, host, release, version, machine = uname()
return "{}.{}.0.0".format(version, release), _MISSING_BD
def aix_platform(): def aix_platform():
@ -87,8 +67,10 @@ def aix_platform():
# extract vrtl from the BUILD_GNU_TYPE as an int # extract vrtl from the BUILD_GNU_TYPE as an int
def _aix_bgt(): def _aix_bgt():
# type: () -> List[int] # type: () -> List[int]
assert _bgt gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
return _aix_vrtl(vrmf=_bgt) if not gnu_type:
raise ValueError("BUILD_GNU_TYPE is not defined")
return _aix_vrtl(vrmf=gnu_type)
def aix_buildtag(): def aix_buildtag():
@ -96,4 +78,12 @@ def aix_buildtag():
""" """
Return the platform_tag of the system Python was built on. Return the platform_tag of the system Python was built on.
""" """
return _aix_tag(_aix_bgt(), _bd) # AIX_BUILDDATE is defined by configure with:
# lslpp -Lcq bos.mp64 | awk -F: '{ print $NF }'
build_date = sysconfig.get_config_var("AIX_BUILDDATE")
try:
build_date = int(build_date)
except (ValueError, TypeError):
raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
f"{build_date!r}")
return _aix_tag(_aix_bgt(), build_date)

View File

@ -0,0 +1,5 @@
AIX: Fix _aix_support module when the subprocess is not available, when
building Python from scratch. It now uses new private _bootsubprocess
module, rather than having two implementations depending if subprocess is
available or not. So _aix_support.aix_platform() result is now the same if
subprocess is available or not.