_shared_with_waf.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. """
  12. Code to be shared by PyInstaller and the bootloader/wscript file.
  13. This code must not assume that either PyInstaller or any of its dependencies
  14. installed. i.e. The only imports allowed in here are standard library ones.
  15. Within reason, it is preferable that this file should still run under Python
  16. 2.7 as many compiler docker images still have only Python 2 installed.
  17. """
  18. import platform
  19. import re
  20. def _pyi_machine(machine, system):
  21. # type: (str, str) -> str
  22. """Choose an intentionally simplified architecture identifier to be used in
  23. the bootloader's directory name.
  24. Args:
  25. machine:
  26. The output of ``platform.machine()`` or any known architecture
  27. alias or shorthand that may be used by a C compiler.
  28. system:
  29. The output of ``platform.system()`` on the target machine.
  30. Returns:
  31. Either a string tag or, on platforms that don't need an architecture
  32. tag, ``None``.
  33. Ideally we'd just use ``platform.machine()`` directly but that makes cross
  34. compiling the bootloader almost impossible because you need to know at
  35. compile time exactly what ``platform.machine()`` will be at run time based
  36. only on the machine name alias or shorthand reported by the C compiler at
  37. build time. Rather, use a loose differentiation and trust that anyone
  38. mixing armv6l with armv6h knows what their doing.
  39. """
  40. # See the corresponding tests in tests/unit/test_compat.py for examples.
  41. if platform.machine() == "sw_64":
  42. # This explicitly inhibits cross compiling the bootloader for or on
  43. # a SunWay machine.
  44. return "sw_64"
  45. if system != "Linux":
  46. # No architecture specifier for anything par Linux.
  47. # - Windows only has one 32 and one 64 bit architecture but lots of
  48. # aliases for each so it's both pointless and painful to give Windows
  49. # an architecture specifier.
  50. # - macOS is on two 64 bit architectures but they are merged into one
  51. # "universal2" bootloader.
  52. # - BSD supports a wide range of architectures but according to PyPI's
  53. # download statistics, every one of our BSD users are on x86_64.
  54. # This may change in the distant future.
  55. return
  56. if machine.startswith(("arm", "aarch")):
  57. # ARM has a huge number of similar and aliased subversions.
  58. # e.g. armv5, armv6l armv8h, aarch64
  59. return "arm"
  60. if machine in ("x86_64", "x64", "x86"):
  61. return "intel"
  62. if re.fullmatch("i[1-6]86", machine):
  63. return "intel"
  64. if machine.startswith(("ppc", "powerpc")):
  65. # PowerPC comes in 64 vs 32 bit and little vs big endian variants.
  66. return "ppc"
  67. # Machines with no known aliases :)
  68. if machine in ("s390x", "mips"):
  69. return machine
  70. # Unknown architectures are allowed by default but will all be placed under
  71. # one directory. In theory, trying to have multiple unknown architectures
  72. # in one copy of PyInstaller will not work but that should be sufficiently
  73. # unlikely to ever happen.
  74. return "unknown"