Skip to content

Commit

Permalink
Get proper git SHA when TRAVIS_COMMIT is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
autozimu committed Aug 31, 2018
1 parent f75b4c1 commit 2e3b4b7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use std::fs::read_to_string;

fn main() {
let git_hash = option_env!("TRAVIS_COMMIT")
.map(|s| s.into())
.unwrap_or_else(|| read_to_string(".git/refs/heads/next").unwrap_or_default());
.map(ToOwned::to_owned)
.unwrap_or_else(|| {
let stdout = std::process::Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
.expect("Failed to get git commit SHA")
.stdout;
String::from_utf8(stdout).expect("Failed to construct string")
});

println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}

0 comments on commit 2e3b4b7

Please sign in to comment.