2017-04-01 18:08:15 +02:00
|
|
|
# -*- mode: python; -*-
|
|
|
|
"""
|
|
|
|
Support code related to OS detection in general. System specific facilities or customization
|
|
|
|
hooks live in mongo_platform_<PLATFORM>.py files.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2022-11-18 19:16:38 +01:00
|
|
|
import platform
|
2017-04-01 18:08:15 +02:00
|
|
|
|
|
|
|
# --- OS identification ---
|
|
|
|
#
|
|
|
|
# This needs to precede the options section so that we can only offer some options on certain
|
|
|
|
# operating systems.
|
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-04-01 18:08:15 +02:00
|
|
|
# This function gets the running OS as identified by Python
|
|
|
|
# It should only be used to set up defaults for options/variables, because
|
|
|
|
# its value could potentially be overridden by setting TARGET_OS on the
|
|
|
|
# command-line. Treat this output as the value of HOST_OS
|
|
|
|
def get_running_os_name():
|
|
|
|
running_os = os.sys.platform
|
2024-05-19 01:51:20 +02:00
|
|
|
if running_os.startswith("linux"):
|
|
|
|
running_os = "linux"
|
|
|
|
elif running_os.startswith("freebsd"):
|
|
|
|
running_os = "freebsd"
|
|
|
|
elif running_os.startswith("openbsd"):
|
|
|
|
running_os = "openbsd"
|
|
|
|
elif running_os == "sunos5":
|
|
|
|
running_os = "solaris"
|
|
|
|
elif running_os == "win32":
|
|
|
|
running_os = "windows"
|
|
|
|
elif running_os == "darwin":
|
|
|
|
running_os = "macOS"
|
2017-04-01 18:08:15 +02:00
|
|
|
else:
|
2024-05-19 01:51:20 +02:00
|
|
|
running_os = "unknown"
|
2017-04-01 18:08:15 +02:00
|
|
|
return running_os
|
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-04-01 18:08:15 +02:00
|
|
|
def env_get_os_name_wrapper(self):
|
2024-05-19 01:51:20 +02:00
|
|
|
return self["TARGET_OS"]
|
2017-04-01 18:08:15 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-04-01 18:08:15 +02:00
|
|
|
def is_os_raw(target_os, os_list_to_check):
|
2024-05-19 01:51:20 +02:00
|
|
|
darwin_os_list = ["macOS", "tvOS", "tvOS-sim", "iOS", "iOS-sim", "watchOS", "watchOS-sim"]
|
|
|
|
linux_os_list = ["android", "linux"]
|
|
|
|
posix_os_list = ["openbsd", "freebsd", "solaris", "emscripten"] + darwin_os_list + linux_os_list
|
2018-01-25 19:44:59 +01:00
|
|
|
|
|
|
|
os_families = {
|
2019-02-19 16:50:57 +01:00
|
|
|
"darwin": darwin_os_list,
|
|
|
|
"posix": posix_os_list,
|
|
|
|
"linux": linux_os_list,
|
2018-01-25 19:44:59 +01:00
|
|
|
}
|
2017-04-01 18:08:15 +02:00
|
|
|
|
2018-01-25 19:44:59 +01:00
|
|
|
for os in os_list_to_check:
|
2019-02-19 16:50:57 +01:00
|
|
|
if os == target_os or (os in os_families and target_os in os_families[os]):
|
2018-01-25 19:44:59 +01:00
|
|
|
return True
|
|
|
|
return False
|
2017-04-01 18:08:15 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-04-01 18:08:15 +02:00
|
|
|
# This function tests the running OS as identified by Python
|
|
|
|
# It should only be used to set up defaults for options/variables, because
|
|
|
|
# its value could potentially be overridden by setting TARGET_OS on the
|
|
|
|
# command-line. Treat this output as the value of HOST_OS
|
|
|
|
def is_running_os(*os_list):
|
|
|
|
return is_os_raw(get_running_os_name(), os_list)
|
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-04-01 18:08:15 +02:00
|
|
|
def env_os_is_wrapper(self, *os_list):
|
2024-05-19 01:51:20 +02:00
|
|
|
return is_os_raw(self["TARGET_OS"], os_list)
|
2022-11-18 19:16:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def is_arm_processor():
|
|
|
|
arch = platform.machine().lower()
|
|
|
|
|
|
|
|
if "arm" in arch or "aarch64" in arch:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|