|
| 1 | +"""Shared AIX support functions.""" |
| 2 | + |
| 3 | +import sys |
| 4 | +from sysconfig import get_config_var |
| 5 | + |
| 6 | +# subprocess is not necessarily available early in the build process |
| 7 | +# if not available, the config_vars are also definitely not available |
| 8 | +# supply substitutes to bootstrap the build |
| 9 | +try: |
| 10 | + import subprocess |
| 11 | + _have_subprocess = True |
| 12 | + _tmp_bd = get_config_var("AIX_BUILDDATE") |
| 13 | + _bgt = get_config_var("BUILD_GNU_TYPE") |
| 14 | +except ImportError: # pragma: no cover |
| 15 | + _have_subprocess = False |
| 16 | + _tmp_bd = None |
| 17 | + _bgt = "powerpc-ibm-aix6.1.7.0" |
| 18 | + |
| 19 | +# if get_config_var("AIX_BUILDDATE") was unknown, provide a substitute, |
| 20 | +# impossible builddate to specify 'unknown' |
| 21 | +_MISSING_BD = 9898 |
| 22 | +try: |
| 23 | + _bd = int(_tmp_bd) |
| 24 | +except TypeError: |
| 25 | + _bd = _MISSING_BD |
| 26 | + |
| 27 | +# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default) |
| 28 | +_sz = 32 if sys.maxsize == (2**31-1) else 64 |
| 29 | + |
| 30 | + |
| 31 | +def _aix_tag(vrtl, bd): |
| 32 | + # type: (List[int], int) -> str |
| 33 | + # vrtl[version, release, technology_level] |
| 34 | + return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], bd, _sz) |
| 35 | + |
| 36 | + |
| 37 | +# extract version, release and technology level from a VRMF string |
| 38 | +def _aix_vrtl(vrmf): |
| 39 | + # type: (str) -> List[int] |
| 40 | + v, r, tl = vrmf.split(".")[:3] |
| 41 | + return [int(v[-1]), int(r), int(tl)] |
| 42 | + |
| 43 | + |
| 44 | +def _aix_bosmp64(): |
| 45 | + # type: () -> Tuple[str, int] |
| 46 | + """ |
| 47 | + Return a Tuple[str, int] e.g., ['7.1.4.34', 1806] |
| 48 | + The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate |
| 49 | + reflect the current ABI levels of the runtime environment. |
| 50 | + """ |
| 51 | + if _have_subprocess: |
| 52 | + # We expect all AIX systems to have lslpp installed in this location |
| 53 | + out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"]) |
| 54 | + out = out.decode("utf-8").strip().split(":") # type: ignore |
| 55 | + # Use str() and int() to help mypy see types |
| 56 | + return str(out[2]), int(out[-1]) |
| 57 | + else: |
| 58 | + from os import uname |
| 59 | + |
| 60 | + osname, host, release, version, machine = uname() |
| 61 | + return "{}.{}.0.0".format(version, release), _MISSING_BD |
| 62 | + |
| 63 | + |
| 64 | +def aix_platform(): |
| 65 | + # type: () -> str |
| 66 | + """ |
| 67 | + AIX filesets are identified by four decimal values: V.R.M.F. |
| 68 | + V (version) and R (release) can be retreived using ``uname`` |
| 69 | + Since 2007, starting with AIX 5.3 TL7, the M value has been |
| 70 | + included with the fileset bos.mp64 and represents the Technology |
| 71 | + Level (TL) of AIX. The F (Fix) value also increases, but is not |
| 72 | + relevant for comparing releases and binary compatibility. |
| 73 | + For binary compatibility the so-called builddate is needed. |
| 74 | + Again, the builddate of an AIX release is associated with bos.mp64. |
| 75 | + AIX ABI compatibility is described as guaranteed at: https://www.ibm.com/\ |
| 76 | + support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html |
| 77 | +
|
| 78 | + For pep425 purposes the AIX platform tag becomes: |
| 79 | + "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize) |
| 80 | + e.g., "aix-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit |
| 81 | + and, "aix-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit |
| 82 | + """ |
| 83 | + vrmf, bd = _aix_bosmp64() |
| 84 | + return _aix_tag(_aix_vrtl(vrmf), bd) |
| 85 | + |
| 86 | + |
| 87 | +# extract vrtl from the BUILD_GNU_TYPE as an int |
| 88 | +def _aix_bgt(): |
| 89 | + # type: () -> List[int] |
| 90 | + assert _bgt |
| 91 | + return _aix_vrtl(vrmf=_bgt) |
| 92 | + |
| 93 | + |
| 94 | +def aix_buildtag(): |
| 95 | + # type: () -> str |
| 96 | + """ |
| 97 | + Return the platform_tag of the system Python was built on. |
| 98 | + """ |
| 99 | + return _aix_tag(_aix_bgt(), _bd) |
0 commit comments