Skip to content

Commit

Permalink
wallet: log git revision on start
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Apr 22, 2022
1 parent 249a5ff commit 96611e0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
37 changes: 37 additions & 0 deletions sui/build.rs
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);
}
}
37 changes: 24 additions & 13 deletions sui/src/bin/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::io::Write;
use std::io::{stderr, stdout};
use std::ops::Deref;
use std::path::PathBuf;

use async_trait::async_trait;
use clap::*;
use colored::Colorize;

use sui::shell::{
install_shell_plugins, AsyncHandler, CacheKey, CommandStructure, CompletionCache, Shell,
use std::{
io::{stderr, stdout, Write},
ops::Deref,
path::PathBuf,
};
use sui::{
shell::{
install_shell_plugins, AsyncHandler, CacheKey, CommandStructure, CompletionCache, Shell,
},
sui_config_dir,
wallet_commands::*,
SUI_WALLET_CONFIG,
};
use sui::wallet_commands::*;
use sui::{sui_config_dir, SUI_WALLET_CONFIG};
use tracing::debug;

const SUI: &str = " _____ _ _ __ ____ __
/ ___/__ __(_) | | / /___ _/ / /__ / /_
Expand Down Expand Up @@ -54,6 +57,9 @@ async fn main() -> Result<(), anyhow::Error> {
};
#[allow(unused)]
let guard = telemetry_subscribers::init(config);
if let Ok(git_rev) = std::env::var("GIT_REV") {
debug!("Wallet built at git revision {git_rev}");
}

let mut app: Command = ClientOpt::command();
app = app.no_binary_name(false);
Expand All @@ -79,10 +85,15 @@ async fn main() -> Result<(), anyhow::Error> {
if options.interactive {
let app: Command = WalletCommands::command();
writeln!(out, "{}", SUI.cyan().bold())?;
let version = app
let mut version = app
.get_long_version()
.unwrap_or_else(|| app.get_version().unwrap_or("unknown"));
writeln!(out, "--- sui wallet {} ---", version)?;
.unwrap_or_else(|| app.get_version().unwrap_or("unknown"))
.to_owned();
if let Ok(git_rev) = std::env::var("GIT_REV") {
version.push('-');
version.push_str(&git_rev);
}
writeln!(out, "--- sui wallet {version} ---")?;
writeln!(out)?;
writeln!(out, "{}", context.config.deref())?;
writeln!(out, "Welcome to the Sui interactive shell.")?;
Expand Down

0 comments on commit 96611e0

Please sign in to comment.