Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify macOS as OS X or Mac OS X on appropriate version ranges #1425

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl System {
SystemInner::kernel_version()
}

/// Returns the system version (e.g. for MacOS this will return 15.1 rather than the kernel
/// Returns the system version (e.g. for macOS this will return 15.1 rather than the kernel
/// version).
///
/// | example platform | value of `System::os_version()` |
Expand All @@ -753,7 +753,7 @@ impl System {
/// |---|---|
/// | linux laptop | "Linux 24.04 Ubuntu" |
/// | android phone | "Android 15 Pixel 9 Pro" |
/// | apple laptop | "MacOS 15.1.1 Sequoia" |
/// | apple laptop | "macOS 15.1.1 Sequoia" |
/// | windows server | "Windows Server 2022 Datacenter" |
///
/// **Important**: this information is computed every time this function is called.
Expand Down Expand Up @@ -1338,7 +1338,7 @@ impl Process {
///
/// This value has limitations though. Depending on the operating system and type of process,
/// this value might be a good indicator of the total memory that the process will be using over
/// its lifetime. However, for example, in the version 14 of MacOS this value is in the order of
/// its lifetime. However, for example, in the version 14 of macOS this value is in the order of
/// the hundreds of gigabytes for every process, and thus not very informative. Moreover, if a
/// process maps into memory a very large file, this value will increase accordingly, even if
/// the process is not actively using the memory.
Expand Down
2 changes: 1 addition & 1 deletion src/unix/apple/macos/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use libc::c_char;
))]
use libc::kern_return_t;

// Note: IOKit is only available on MacOS up until very recent iOS versions: https://developer.apple.com/documentation/iokit
// Note: IOKit is only available on macOS up until very recent iOS versions: https://developer.apple.com/documentation/iokit

#[cfg(any(
feature = "system",
Expand Down
64 changes: 33 additions & 31 deletions src/unix/apple/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,39 +396,41 @@ impl SystemInner {
pub(crate) fn long_os_version() -> Option<String> {
#[cfg(target_os = "macos")]
{
let mut long_name = "MacOS".to_owned();
if let Some(os_version) = Self::os_version() {
long_name.push(' ');
long_name.push_str(&os_version);
if let Some(friendly_name) = match os_version.as_str() {
f_n if f_n.starts_with("15") => Some("Sequoia"),
f_n if f_n.starts_with("14") => Some("Sonoma"),
f_n if f_n.starts_with("13") => Some("Ventura"),
f_n if f_n.starts_with("12") => Some("Monterey"),
f_n if f_n.starts_with("11") | f_n.starts_with("10.16") => Some("Big Sur"),
f_n if f_n.starts_with("10.15") => Some("Catalina"),
f_n if f_n.starts_with("10.14") => Some("Mojave"),
f_n if f_n.starts_with("10.13") => Some("High Sierra"),
f_n if f_n.starts_with("10.12") => Some("Sierra"),
f_n if f_n.starts_with("10.11") => Some("El Capitan"),
f_n if f_n.starts_with("10.10") => Some("Yosemite"),
f_n if f_n.starts_with("10.9") => Some("Mavericks"),
f_n if f_n.starts_with("10.8") => Some("Mountain Lion"),
f_n if f_n.starts_with("10.7") => Some("Lion"),
f_n if f_n.starts_with("10.6") => Some("Snow Leopard"),
f_n if f_n.starts_with("10.5") => Some("Leopard"),
f_n if f_n.starts_with("10.4") => Some("Tiger"),
f_n if f_n.starts_with("10.3") => Some("Panther"),
f_n if f_n.starts_with("10.2") => Some("Jaguar"),
f_n if f_n.starts_with("10.1") => Some("Puma"),
f_n if f_n.starts_with("10.0") => Some("Cheetah"),
_ => None,
} {
long_name.push(' ');
long_name.push_str(friendly_name);
let Some(os_version) = Self::os_version() else {
return Some("macOS".to_owned());
};
// https://en.wikipedia.org/wiki/MacOS_version_history
for (version_prefix, macos_spelling, friendly_name) in [
("15", "macOS", "Sequoia"),
("14", "macOS", "Sonoma"),
("13", "macOS", "Ventura"),
("12", "macOS", "Monterey"),
("11", "macOS", "Big Sur"),
// Big Sur identifies itself as 10.16 in some situations.
// https://en.wikipedia.org/wiki/MacOS_Big_Sur#Development_history
("10.16", "macOS", "Big Sur"),
("10.15", "macOS", "Catalina"),
("10.14", "macOS", "Mojave"),
("10.13", "macOS", "High Sierra"),
("10.12", "macOS", "Sierra"),
("10.11", "OS X", "El Capitan"),
("10.10", "OS X", "Yosemite"),
("10.9", "OS X", "Mavericks"),
("10.8", "OS X", "Mountain Lion"),
("10.7", "Mac OS X", "Lion"),
("10.6", "Mac OS X", "Snow Leopard"),
("10.5", "Mac OS X", "Leopard"),
("10.4", "Mac OS X", "Tiger"),
("10.3", "Mac OS X", "Panther"),
("10.2", "Mac OS X", "Jaguar"),
("10.1", "Mac OS X", "Puma"),
("10.0", "Mac OS X", "Cheetah"),
] {
if os_version.starts_with(version_prefix) {
return Some(format!("{macos_spelling} {os_version} {friendly_name}"));
}
}
Some(long_name)
Some(format!("macOS {os_version}"))
}

#[cfg(target_os = "ios")]
Expand Down
Loading