From dae9d0c93b50a4fbda0be925b6889613edb2baa1 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Wed, 16 Mar 2022 15:13:30 +0100 Subject: [PATCH] Make build step only use git info when not building a tagged release --- build.rs | 44 +++++++++++++++++++++----------------------- src/main.rs | 1 - 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/build.rs b/build.rs index 02b3add..e94d031 100644 --- a/build.rs +++ b/build.rs @@ -9,29 +9,6 @@ fn is_hidden(entry: &DirEntry) -> bool { } fn main() { - // Build version number using the current git commit id - let out = Command::new("git").arg("rev-list") - .args(["HEAD", "-1"]) - .output() - .expect("failed to run `git rev-list HEAD -1`"); - let owned_gitrev = String::from_utf8(out.stdout) - .expect("git rev-list output was not valid UTF8"); - let gitrev = owned_gitrev.trim(); - let abbrev = match gitrev.len(){ - 0 => "unknown", - _ => &gitrev[0..9], - }; - println!("cargo:rustc-env=CARGO_PKG_VERSION_GITREV={}", gitrev); - - let out = Command::new("git").arg("log") - .args(["-1", "--format=%as"]) - .output() - .expect("failed to run `git log -1 --format=\"format:%as\"`"); - let commit_date = String::from_utf8(out.stdout) - .expect("git log output was not valid UTF8"); - let commit_date = commit_date.trim(); - println!("cargo:rustc-env=BFFH_GIT_COMMIT_DATE={}", commit_date); - let mut compile_command = ::capnpc::CompilerCommand::new(); // Set parent module of all generated schema files. @@ -77,6 +54,27 @@ fn main() { version = env!("CARGO_PKG_VERSION"), rustc = rustc_version) } else { + // Build version number using the current git commit id + let out = Command::new("git").arg("rev-list") + .args(["HEAD", "-1"]) + .output() + .expect("failed to run `git rev-list HEAD -1`"); + let owned_gitrev = String::from_utf8(out.stdout) + .expect("git rev-list output was not valid UTF8"); + let gitrev = owned_gitrev.trim(); + let abbrev = match gitrev.len(){ + 0 => "unknown", + _ => &gitrev[0..9], + }; + + let out = Command::new("git").arg("log") + .args(["-1", "--format=%as"]) + .output() + .expect("failed to run `git log -1 --format=\"format:%as\"`"); + let commit_date = String::from_utf8(out.stdout) + .expect("git log output was not valid UTF8"); + let commit_date = commit_date.trim(); + format!("BFFH {version} ({gitrev} {date}) [{rustc}]", version=env!("CARGO_PKG_VERSION"), gitrev=abbrev, diff --git a/src/main.rs b/src/main.rs index f5453f1..03ccc14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,6 @@ use crate::config::{ActorConn, Config, InitiatorConn}; const RELEASE: &'static str = env!("BFFHD_RELEASE_STRING"); const VERSION: &'static str = env!("CARGO_PKG_VERSION"); -const GITREV: &'static str = env!("CARGO_PKG_VERSION_GITREV"); fn main() { use clap::{crate_version, crate_description, crate_name};