Skip to content

Commit d3221b0

Browse files
committed
fix: Only parse git revision, don't use the tag for version
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.
1 parent d6b6ad8 commit d3221b0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

helix-term/build.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
use std::borrow::Cow;
12
use std::process::Command;
23

34
fn main() {
45
let git_hash = Command::new("git")
5-
.args(&["describe", "--dirty"])
6+
.args(&["rev-parse", "HEAD"])
67
.output()
7-
.map(|x| String::from_utf8(x.stdout).ok())
88
.ok()
9-
.flatten()
10-
.unwrap_or_else(|| String::from(env!("CARGO_PKG_VERSION")));
11-
println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", git_hash);
9+
.and_then(|x| String::from_utf8(x.stdout).ok());
10+
11+
let version: Cow<_> = match git_hash {
12+
Some(git_hash) => format!("{} ({})", env!("CARGO_PKG_VERSION"), &git_hash[..8]).into(),
13+
None => env!("CARGO_PKG_VERSION").into(),
14+
};
15+
16+
println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
1217
}

0 commit comments

Comments
 (0)