Skip to content

--versions: Add OS and tool version #178

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ env_logger = "0.11"
clap = { version = "4.5", features = ["derive", "cargo"] }
clap-num = { version = "1.2.0" }
clap-verbosity-flag = { version = "2.2.1" }
windows-version = "0.1.4"

[target.'cfg(unix)'.dependencies]
libc = "0.2.155"
Expand Down
3 changes: 3 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use crate::ec_binary;
use crate::esrt;
#[cfg(feature = "rusb")]
use crate::inputmodule::check_inputmodule_version;
use crate::os_specific;
use crate::power;
use crate::smbios;
use crate::smbios::ConfigDigit0;
Expand Down Expand Up @@ -374,6 +375,8 @@ fn print_stylus_battery_level() {
}

fn print_versions(ec: &CrosEc) {
println!("Tool Version: {}", built_info::PKG_VERSION);
println!("OS Version: {}", os_specific::get_os_version());
println!("Mainboard Hardware");
if let Some(ver) = smbios::get_product_name() {
println!(" Type: {}", ver);
Expand Down
33 changes: 33 additions & 0 deletions framework_lib/src/os_specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
#[cfg(not(feature = "uefi"))]
use std::{thread, time};

#[cfg(feature = "uefi")]
use alloc::string::{String, ToString};

// Could report the implemented UEFI spec version
// But that's not very useful. Just look at the BIOS version
// But at least it's useful to see that the tool was run on UEFI
#[cfg(feature = "uefi")]
pub fn get_os_version() -> String {
"UEFI".to_string()
}

#[cfg(target_family = "windows")]
pub fn get_os_version() -> String {
let ver = windows_version::OsVersion::current();
format!("{}.{}.{}.{}", ver.major, ver.minor, ver.pack, ver.build)
}

#[cfg(target_family = "unix")]
pub fn get_os_version() -> String {
if let Ok(uts) = nix::sys::utsname::uname() {
// uname -a without hostname
format!(
"{} {} {} {}",
uts.sysname().to_string_lossy(),
uts.release().to_string_lossy(),
uts.version().to_string_lossy(),
uts.machine().to_string_lossy(),
)
} else {
"Unknown".to_string()
}
}

/// Sleep a number of microseconds
pub fn sleep(micros: u64) {
#[cfg(not(feature = "uefi"))]
Expand Down
Loading