_shared_with_waf.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 installed. I.e., the only imports allowed
  14. in here are standard library ones. Within reason, it is preferable that this file should still run under Python 2.7 as
  15. many compiler docker images still have only Python 2 installed.
  16. """
  17. import platform
  18. import re
  19. def _pyi_machine(machine, system):
  20. # type: (str, str) -> str
  21. """
  22. Choose an intentionally simplified architecture identifier to be used in the bootloader's directory name.
  23. Args:
  24. machine:
  25. The output of ``platform.machine()`` or any known architecture alias or shorthand that may be used by a
  26. C compiler.
  27. system:
  28. The output of ``platform.system()`` on the target machine.
  29. Returns:
  30. Either a string tag or, on platforms that don't need an architecture tag, ``None``.
  31. Ideally, we would just use ``platform.machine()`` directly, but that makes cross-compiling the bootloader almost
  32. impossible, because you need to know at compile time exactly what ``platform.machine()`` will be at run time, based
  33. only on the machine name alias or shorthand reported by the C compiler at the build time. Rather, use a loose
  34. differentiation, and trust that anyone mixing armv6l with armv6h knows what they are doing.
  35. """
  36. # See the corresponding tests in tests/unit/test_compat.py for examples.
  37. if platform.machine() == "sw_64" or platform.machine() == "loongarch64":
  38. # This explicitly inhibits cross compiling the bootloader for or on SunWay and LoongArch machine.
  39. return platform.machine()
  40. if system != "Linux":
  41. # No architecture specifier for anything par Linux.
  42. # - Windows only has one 32 and one 64 bit architecture, but lots of aliases for each so it is both pointless
  43. # and painful to give Windows an architecture specifier.
  44. # - macOS is on two 64 bit architectures, but they are merged into one "universal2" bootloader.
  45. # - BSD supports a wide range of architectures, but according to PyPI's download statistics, every one of our
  46. # BSD users are on x86_64. This may change in the distant future.
  47. return
  48. if machine.startswith(("arm", "aarch")):
  49. # ARM has a huge number of similar and aliased sub-versions, such as armv5, armv6l armv8h, aarch64.
  50. return "arm"
  51. if machine in ("x86_64", "x64", "x86"):
  52. return "intel"
  53. if re.fullmatch("i[1-6]86", machine):
  54. return "intel"
  55. if machine.startswith(("ppc", "powerpc")):
  56. # PowerPC comes in 64 vs 32 bit and little vs big endian variants.
  57. return "ppc"
  58. if machine in ("mips64", "mips"):
  59. return "mips"
  60. # Machines with no known aliases :)
  61. if machine in ("s390x",):
  62. return machine
  63. # Unknown architectures are allowed by default, but will all be placed under one directory. In theory, trying to
  64. # have multiple unknown architectures in one copy of PyInstaller will not work, but that should be sufficiently
  65. # unlikely to ever happen.
  66. return "unknown"