-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get proper git SHA when TRAVIS_COMMIT is not available.
- Loading branch information
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |