Skip to content

Commit

Permalink
fix: Only parse git revision, don't use the tag for version
Browse files Browse the repository at this point in the history
If building from source and the source is contained in a larger
repository, we'd contain the wrong version. It's also easy to
accidentally have a newer tag that would change the version.
  • Loading branch information
archseer committed Feb 2, 2022
1 parent d6b6ad8 commit d3221b0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions helix-term/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use std::borrow::Cow;
use std::process::Command;

fn main() {
let git_hash = Command::new("git")
.args(&["describe", "--dirty"])
.args(&["rev-parse", "HEAD"])
.output()
.map(|x| String::from_utf8(x.stdout).ok())
.ok()
.flatten()
.unwrap_or_else(|| String::from(env!("CARGO_PKG_VERSION")));
println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", git_hash);
.and_then(|x| String::from_utf8(x.stdout).ok());

let version: Cow<_> = match git_hash {
Some(git_hash) => format!("{} ({})", env!("CARGO_PKG_VERSION"), &git_hash[..8]).into(),
None => env!("CARGO_PKG_VERSION").into(),
};

println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
}

0 comments on commit d3221b0

Please sign in to comment.