Skip to content

Commit db1c8f0

Browse files
committed
Add --versions to show version tool information
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 9792f71 commit db1c8f0

File tree

8 files changed

+490
-20
lines changed

8 files changed

+490
-20
lines changed

Cargo.lock

+424-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[workspace]
2+
# Make sure new resolver is used to avoid unifying dependency features between
3+
# runtime and build dependencies.
4+
# See: https://github.com/rust-lang/cargo/issues/2589
5+
resolver = "2"
26

37
members = [
48
# Linux and Windows tool to inspect and customize the system

framework_lib/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name = "framework_lib"
33
version = "0.1.0"
44
edition = "2021"
5-
-rust-version = "1.61"
5+
rust-version = "1.61"
6+
build = "build.rs"
67

78
[features]
89
default = ["linux"]
@@ -25,6 +26,9 @@ cros_ec_driver = []
2526
# Chromium EC driver by DHowett
2627
win_driver = []
2728

29+
[build-dependencies]
30+
built = { version = "0.5", no-default-features = true, features = ["chrono", "git2"] }
31+
2832
[dependencies]
2933
lazy_static = "1.4.0"
3034
regex = { version = "1.6.0", optional = true } # TODO: Can update to 1.7.0

framework_lib/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
built::write_built_file().expect("Failed to acquire build-time information");
3+
}

framework_lib/src/commandline/clap_std.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ struct ClapCli {
1313
#[command(flatten)]
1414
verbosity: clap_verbosity_flag::Verbosity,
1515

16-
/// List current firmware versions version
16+
/// List current firmware versions
1717
#[arg(long)]
1818
versions: bool,
1919

20+
/// Show tool version information (Add -vv for more details)
21+
#[arg(long)]
22+
version: bool,
23+
2024
/// Display the UEFI ESRT table
2125
#[arg(long)]
2226
esrt: bool,
@@ -103,6 +107,7 @@ pub fn parse(args: &[String]) -> Cli {
103107
Cli {
104108
verbosity: args.verbosity.log_level_filter(),
105109
versions: args.versions,
110+
version: args.version,
106111
esrt: args.esrt,
107112
power: args.power,
108113
pdports: args.pdports,

framework_lib/src/commandline/mod.rs

+39
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use alloc::string::String;
77
use alloc::string::ToString;
88
use alloc::vec::Vec;
9+
use log::Level;
910

1011
#[cfg(not(feature = "uefi"))]
1112
pub mod clap_std;
@@ -17,6 +18,7 @@ use std::fs;
1718

1819
#[cfg(not(feature = "uefi"))]
1920
use crate::audio_card::check_synaptics_fw_version;
21+
use crate::built_info;
2022
use crate::capsule;
2123
use crate::capsule_content::{
2224
find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version,
@@ -61,6 +63,7 @@ pub enum ConsoleArg {
6163
pub struct Cli {
6264
pub verbosity: log::LevelFilter,
6365
pub versions: bool,
66+
pub version: bool,
6467
pub esrt: bool,
6568
pub power: bool,
6669
pub pdports: bool,
@@ -171,6 +174,38 @@ fn print_dp_hdmi_details() {
171174
};
172175
}
173176

177+
fn print_tool_version() {
178+
let q = "?".to_string();
179+
println!("Tool Version Information");
180+
println!(" Version: {}", built_info::PKG_VERSION);
181+
println!(" Built At: {}", built_info::BUILT_TIME_UTC);
182+
println!(
183+
" Git Commit: {}",
184+
built_info::GIT_COMMIT_HASH.unwrap_or(&q)
185+
);
186+
println!(
187+
" Git Dirty: {}",
188+
built_info::GIT_DIRTY
189+
.map(|x| x.to_string())
190+
.unwrap_or(q.clone())
191+
);
192+
193+
if log_enabled!(Level::Info) {
194+
println!(
195+
" Built on CI: {:?}",
196+
built_info::CI_PLATFORM.unwrap_or("None")
197+
);
198+
println!(
199+
" Git ref: {:?}",
200+
built_info::GIT_HEAD_REF.unwrap_or(&q)
201+
);
202+
println!(" rustc Ver: {}", built_info::RUSTC_VERSION);
203+
println!(" Features {:?}", built_info::FEATURES);
204+
println!(" DEBUG: {}", built_info::DEBUG);
205+
println!(" Target OS: {}", built_info::CFG_OS);
206+
}
207+
}
208+
174209
fn print_versions(ec: &CrosEc) {
175210
println!("UEFI BIOS");
176211
if let Some(smbios) = get_smbios() {
@@ -326,6 +361,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
326361
return 2;
327362
} else if args.versions {
328363
print_versions(&ec);
364+
} else if args.version {
365+
print_tool_version();
329366
} else if args.esrt {
330367
print_esrt();
331368
} else if args.intrusion {
@@ -528,6 +565,8 @@ Options:
528565
-b Print output one screen at a time
529566
-v, --verbose... More output per occurrence
530567
-q, --quiet... Less output per occurrence
568+
--versions List current firmware versions
569+
--version Show tool version information (Add -vv for more detailed information)
531570
--esrt Display the UEFI ESRT table
532571
--power Show current power status (battery and AC)
533572
--pdports Show information about USB-C PD prots

framework_lib/src/commandline/uefi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub fn parse(args: &[String]) -> Cli {
5656
verbosity: log::LevelFilter::Error,
5757
paginate: false,
5858
versions: false,
59+
version: false,
5960
esrt: false,
6061
power: false,
6162
pdports: false,
@@ -101,6 +102,9 @@ pub fn parse(args: &[String]) -> Cli {
101102
} else if arg == "--versions" {
102103
cli.versions = true;
103104
found_an_option = true;
105+
} else if arg == "--version" {
106+
cli.version = true;
107+
found_an_option = true;
104108
} else if arg == "-b" {
105109
cli.paginate = true;
106110
found_an_option = true;

framework_lib/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ pub mod smbios;
3535
#[cfg(feature = "uefi")]
3636
pub mod uefi;
3737
mod util;
38+
39+
pub mod built_info {
40+
// The file has been placed there by the build script.
41+
include!(concat!(env!("OUT_DIR"), "/built.rs"));
42+
}

0 commit comments

Comments
 (0)