Skip to content

Commit 955691a

Browse files
Merge pull request #178 from FrameworkComputer/versions-os-tool
--versions: Add OS and tool version
2 parents 16cb1b2 + df72eb6 commit 955691a

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework_lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ env_logger = "0.11"
5050
clap = { version = "4.5", features = ["derive", "cargo"] }
5151
clap-num = { version = "1.2.0" }
5252
clap-verbosity-flag = { version = "2.2.1" }
53+
windows-version = "0.1.4"
5354

5455
[target.'cfg(unix)'.dependencies]
5556
libc = "0.2.155"

framework_lib/src/commandline/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use crate::ec_binary;
4949
use crate::esrt;
5050
#[cfg(feature = "rusb")]
5151
use crate::inputmodule::check_inputmodule_version;
52+
use crate::os_specific;
5253
use crate::power;
5354
use crate::smbios;
5455
use crate::smbios::ConfigDigit0;
@@ -461,6 +462,8 @@ fn print_stylus_battery_level() {
461462
}
462463

463464
fn print_versions(ec: &CrosEc) {
465+
println!("Tool Version: {}", built_info::PKG_VERSION);
466+
println!("OS Version: {}", os_specific::get_os_version());
464467
println!("Mainboard Hardware");
465468
if let Some(ver) = smbios::get_product_name() {
466469
println!(" Type: {}", ver);

framework_lib/src/os_specific.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@
33
#[cfg(not(feature = "uefi"))]
44
use std::{thread, time};
55

6+
#[cfg(feature = "uefi")]
7+
use alloc::string::{String, ToString};
8+
9+
// Could report the implemented UEFI spec version
10+
// But that's not very useful. Just look at the BIOS version
11+
// But at least it's useful to see that the tool was run on UEFI
12+
#[cfg(feature = "uefi")]
13+
pub fn get_os_version() -> String {
14+
"UEFI".to_string()
15+
}
16+
17+
#[cfg(target_family = "windows")]
18+
pub fn get_os_version() -> String {
19+
let ver = windows_version::OsVersion::current();
20+
format!("{}.{}.{}.{}", ver.major, ver.minor, ver.pack, ver.build)
21+
}
22+
23+
#[cfg(target_family = "unix")]
24+
pub fn get_os_version() -> String {
25+
if let Ok(uts) = nix::sys::utsname::uname() {
26+
// uname -a without hostname
27+
format!(
28+
"{} {} {} {}",
29+
uts.sysname().to_string_lossy(),
30+
uts.release().to_string_lossy(),
31+
uts.version().to_string_lossy(),
32+
uts.machine().to_string_lossy(),
33+
)
34+
} else {
35+
"Unknown".to_string()
36+
}
37+
}
38+
639
/// Sleep a number of microseconds
740
pub fn sleep(micros: u64) {
841
#[cfg(not(feature = "uefi"))]

0 commit comments

Comments
 (0)