Make build step only use git info when not building a tagged release

This commit is contained in:
Nadja Reitzenstein 2022-03-16 15:13:30 +01:00
parent cc2b43a9f2
commit dae9d0c93b
2 changed files with 21 additions and 24 deletions

View File

@ -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,

View File

@ -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};