You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.3 KiB

  1. From: https://github.com/giampaolo/psutil/pull/2068/commits/9a5cb2b71d301a63ea765f02a196fd046e769685
  2. From 9a5cb2b71d301a63ea765f02a196fd046e769685 Mon Sep 17 00:00:00 2001
  3. From: "Sergey V. Lobanov" <sergey@lobanov.in>
  4. Date: Mon, 31 Jan 2022 17:48:14 +0300
  5. Subject: [PATCH] Add cross-platform build ability
  6. Currently it is not possible to build psutil on MacOS for Linux
  7. target using external toolchain. It fails due to build script
  8. detects build host OS and changes build logic according to detected
  9. OS.
  10. This patch allows to redefine os.name and sys.platform using ENV
  11. vars TARGET_OS_NAME and TARGET_SYS_PLATFORM. If these variables
  12. are not defined then os.name and sys.platform is used as it does
  13. currently.
  14. Using this patch it is possible to compile psutil on MacOS with
  15. OpenWrt GCC Toolchain (OpenWrt is Linux).
  16. Signed-off-by: Sergey V. Lobanov <sergey@lobanov.in>
  17. ---
  18. psutil/_common.py | 23 ++++++++++++++---------
  19. 1 file changed, 14 insertions(+), 9 deletions(-)
  20. --- a/psutil/_common.py
  21. +++ b/psutil/_common.py
  22. @@ -81,17 +81,22 @@ __all__ = [
  23. # ===================================================================
  24. -POSIX = os.name == "posix"
  25. -WINDOWS = os.name == "nt"
  26. -LINUX = sys.platform.startswith("linux")
  27. -MACOS = sys.platform.startswith("darwin")
  28. +# Allow to redefine os.name and sys.platform if build OS and target
  29. +# OS are different (e.g. build OS is MacOS, target OS is Linux)
  30. +target_os_name = os.getenv('TARGET_OS_NAME', os.name)
  31. +target_sys_platform = os.getenv('TARGET_SYS_PLATFORM', sys.platform)
  32. +
  33. +POSIX = target_os_name == "posix"
  34. +WINDOWS = target_os_name == "nt"
  35. +LINUX = target_sys_platform.startswith("linux")
  36. +MACOS = target_sys_platform.startswith("darwin")
  37. OSX = MACOS # deprecated alias
  38. -FREEBSD = sys.platform.startswith(("freebsd", "midnightbsd"))
  39. -OPENBSD = sys.platform.startswith("openbsd")
  40. -NETBSD = sys.platform.startswith("netbsd")
  41. +FREEBSD = target_sys_platform.startswith(("freebsd", "midnightbsd"))
  42. +OPENBSD = target_sys_platform.startswith("openbsd")
  43. +NETBSD = target_sys_platform.startswith("netbsd")
  44. BSD = FREEBSD or OPENBSD or NETBSD
  45. -SUNOS = sys.platform.startswith(("sunos", "solaris"))
  46. -AIX = sys.platform.startswith("aix")
  47. +SUNOS = target_sys_platform.startswith(("sunos", "solaris"))
  48. +AIX = target_sys_platform.startswith("aix")
  49. # ===================================================================