Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit hash to version info, if present #957

Merged
merged 3 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions helix-term/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::process::Command;

fn main() {
AloeareV marked this conversation as resolved.
Show resolved Hide resolved
let git_hash = Command::new("git")
.args(&["describe", "--dirty"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also want to use "rev-parse", "--short", "HEAD" so we only get the SHA

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought @pickfire 's comment here:

#922 (comment)

made sense. It seems like dirty-ness and distance from release could be really useful info. Is there a constraint somewhere else that makes such a string difficult to work with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that for my first draft, and then changed to describe --dirty after reading @pickfire's comment on the issue. Would be no problem to switch back, if we're not concerned about version including knowledge of dirty state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's okay, but describe always uses the latest available tag. We'll have to be careful because if the code is built after a new tag is accidentally added then the version info will be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worthwhile to use a specific process/tool to enforce that the version can't use any tag except the actual release tag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this actually happened in the latest release (it builds as v0.5 on latest master because the release points to a commit before I rebased against master). I'd still rather see we only pull the SHA and use the crate version.

.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);
}
4 changes: 2 additions & 2 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ FLAGS:
-V, --version Prints version information
",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
env!("VERSION_AND_GIT_HASH"),
env!("CARGO_PKG_AUTHORS"),
env!("CARGO_PKG_DESCRIPTION"),
logpath.display(),
Expand All @@ -81,7 +81,7 @@ FLAGS:
}

if args.display_version {
println!("helix {}", env!("CARGO_PKG_VERSION"));
println!("helix {}", env!("VERSION_AND_GIT_HASH"));
std::process::exit(0);
}

Expand Down