Skip to content

Commit

Permalink
sui: fix build script to accept GIT_REVISION envvar set when building…
Browse files Browse the repository at this point in the history
… docker
  • Loading branch information
bmwill committed Jun 22, 2022
1 parent 444be74 commit 1ac6005
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
24 changes: 5 additions & 19 deletions crates/sui/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,20 @@ use std::{env, process::Command};

/// Save revision info to environment variable
fn main() {
if env::var("GIT_REV").is_err() {
if env::var("GIT_REVISION").is_err() {
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(&["describe", "--always", "--dirty"])
.output()
.unwrap();
if !output.status.success() {
panic!(
"failed to run git command: {:?}",
"failed to run git command: {}",
output.stderr.escape_ascii()
);
}
let mut git_rev = String::from_utf8(output.stdout).unwrap().trim().to_owned();
let 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);
println!("cargo:rustc-env=GIT_REVISION={}", git_rev);
println!("cargo:rerun-if-changed=build.rs");
}
}
4 changes: 2 additions & 2 deletions crates/sui/src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async fn try_main() -> Result<(), anyhow::Error> {
.with_env()
.init();

if let Some(git_rev) = std::option_env!("GIT_REV") {
if let Some(git_rev) = std::option_env!("GIT_REVISION") {
debug!("Wallet built at git revision {git_rev}");
}

Expand Down Expand Up @@ -134,7 +134,7 @@ async fn try_main() -> Result<(), anyhow::Error> {
.get_long_version()
.unwrap_or_else(|| app.get_version().unwrap_or("unknown"))
.to_owned();
if let Some(git_rev) = std::option_env!("GIT_REV") {
if let Some(git_rev) = std::option_env!("GIT_REVISION") {
version.push('-');
version.push_str(git_rev);
}
Expand Down

0 comments on commit 1ac6005

Please sign in to comment.