Adds a more readable version numbering

This commit is contained in:
Dandaedre 2024-07-30 21:05:32 +02:00
parent bb0cdffaee
commit 02d92e4a99
1 changed files with 30 additions and 34 deletions

View File

@ -90,45 +90,41 @@ pub(super) fn make_file(args: &MakeConfig) -> BuilderParseResult {
}
}
macro_rules! exec_cmd {
($cmd:expr, $args:expr) => {
{
let mut cmd = Command::new($cmd);
cmd.args($args);
match cmd.output() {
Ok(v) => from_utf8(&v.stdout)
.expect("Couldn't parse the git tag result")
.to_owned(),
Err(e) => {
println!(
"[ERRR] An error has occured while trying to retrieve the Ravenous Version\n {:#?}",
e
);
"Unknown".to_string()
}
}
}
};
}
/// Ask git for the current version
fn get_build_version() -> String {
let mut cmd = Command::new("git");
cmd.args(["describe", "--tags"]);
let tag = exec_cmd!("git", ["describe", "--tags", "--abbrev=0"]).replace("\n", "");
let tag = match cmd.output() {
Ok(v) => from_utf8(&v.stdout)
.expect("Couldn't parse the git tag result")
.to_owned(),
Err(e) => {
println!(
"[ERRR] An error has occured while trying to retrieve the Ravenous Version\n {:#?}",
e
);
"Unknown".to_string()
}
};
let hsh = exec_cmd!("git", ["rev-parse", "--short", "HEAD"]).replace("\n", "");
let mut cmd = Command::new("git");
cmd.args(["rev-parse", "--short", "HEAD"]);
let hsh = match cmd.output() {
Ok(v) => from_utf8(&v.stdout)
.expect("Couldn't parse the git tag result")
.to_uppercase()
.to_owned(),
Err(e) => {
println!(
"[ERRR] An error has occured while trying to retrieve the Ravenous Version\n {:#?}",
e
);
"Unknown".to_string()
}
};
format!(
"Version: {} ({})",
tag.replace("\n", ""),
hsh.replace("\n", "")
// let thsh = exec_cmd!("git", ["show-ref", tag.as_str(), "-s"]);
let vnmbr = exec_cmd!(
"git",
["rev-list", format!("{}..HEAD", tag).as_str(), "--count"]
)
.replace("\n", "");
format!("Version: {}r{} ({})", tag, vnmbr, hsh)
}
/// Clear the list of keys (for now only warn)