forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::{env, process::Command}; | ||
|
||
/// Save revision info to environment variable | ||
fn main() { | ||
if env::var("GIT_REV").is_err() { | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "--short", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
if !output.status.success() { | ||
panic!( | ||
"failed to run git command: {:?}", | ||
output.stderr.escape_ascii() | ||
); | ||
} | ||
let mut git_rev = String::from_utf8(output.stdout).unwrap().trim().to_owned(); | ||
|
||
let output = Command::new("git") | ||
.args(&["diff-index", "--name-only", "HEAD", "--"]) | ||
.output() | ||
.unwrap(); | ||
if !output.status.success() { | ||
panic!( | ||
"failed to run git command: {:?}", | ||
output.stderr.escape_ascii() | ||
); | ||
} | ||
if !output.stdout.is_empty() { | ||
git_rev.push_str("-dirty"); | ||
} | ||
|
||
println!("cargo:rustc-env=GIT_REV={}", git_rev); | ||
} | ||
} |
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