_aix_support.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """Shared AIX support functions."""
  2. import sys
  3. import sysconfig
  4. try:
  5. import subprocess
  6. except ImportError: # pragma: no cover
  7. # _aix_support is used in distutils by setup.py to build C extensions,
  8. # before subprocess dependencies like _posixsubprocess are available.
  9. import _bootsubprocess as subprocess
  10. def _aix_tag(vrtl, bd):
  11. # type: (List[int], int) -> str
  12. # Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
  13. _sz = 32 if sys.maxsize == (2**31-1) else 64
  14. _bd = bd if bd != 0 else 9988
  15. # vrtl[version, release, technology_level]
  16. return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], _bd, _sz)
  17. # extract version, release and technology level from a VRMF string
  18. def _aix_vrtl(vrmf):
  19. # type: (str) -> List[int]
  20. v, r, tl = vrmf.split(".")[:3]
  21. return [int(v[-1]), int(r), int(tl)]
  22. def _aix_bos_rte():
  23. # type: () -> Tuple[str, int]
  24. """
  25. Return a Tuple[str, int] e.g., ['7.1.4.34', 1806]
  26. The fileset bos.rte represents the current AIX run-time level. It's VRMF and
  27. builddate reflect the current ABI levels of the runtime environment.
  28. If no builddate is found give a value that will satisfy pep425 related queries
  29. """
  30. # All AIX systems to have lslpp installed in this location
  31. out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
  32. out = out.decode("utf-8")
  33. out = out.strip().split(":") # type: ignore
  34. _bd = int(out[-1]) if out[-1] != '' else 9988
  35. return (str(out[2]), _bd)
  36. def aix_platform():
  37. # type: () -> str
  38. """
  39. AIX filesets are identified by four decimal values: V.R.M.F.
  40. V (version) and R (release) can be retrieved using ``uname``
  41. Since 2007, starting with AIX 5.3 TL7, the M value has been
  42. included with the fileset bos.rte and represents the Technology
  43. Level (TL) of AIX. The F (Fix) value also increases, but is not
  44. relevant for comparing releases and binary compatibility.
  45. For binary compatibility the so-called builddate is needed.
  46. Again, the builddate of an AIX release is associated with bos.rte.
  47. AIX ABI compatibility is described as guaranteed at: https://www.ibm.com/\
  48. support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html
  49. For pep425 purposes the AIX platform tag becomes:
  50. "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize)
  51. e.g., "aix-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit
  52. and, "aix-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit
  53. """
  54. vrmf, bd = _aix_bos_rte()
  55. return _aix_tag(_aix_vrtl(vrmf), bd)
  56. # extract vrtl from the BUILD_GNU_TYPE as an int
  57. def _aix_bgt():
  58. # type: () -> List[int]
  59. gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
  60. if not gnu_type:
  61. raise ValueError("BUILD_GNU_TYPE is not defined")
  62. return _aix_vrtl(vrmf=gnu_type)
  63. def aix_buildtag():
  64. # type: () -> str
  65. """
  66. Return the platform_tag of the system Python was built on.
  67. """
  68. # AIX_BUILDDATE is defined by configure with:
  69. # lslpp -Lcq bos.rte | awk -F: '{ print $NF }'
  70. build_date = sysconfig.get_config_var("AIX_BUILDDATE")
  71. try:
  72. build_date = int(build_date)
  73. except (ValueError, TypeError):
  74. raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
  75. f"{build_date!r}")
  76. return _aix_tag(_aix_bgt(), build_date)