Skip to content

Commit

Permalink
Move the git revision logic to a crate (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Oct 20, 2022
1 parent f72b92b commit 125e251
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 46 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ autobins = false
build = "build.rs"

[build-dependencies]
serde = "1.0.82"
serde_derive = "1.0.82"
serde_json = "1.0.82"
crate-git-revision = "0.0.2"

[[bin]]
name = "soroban"
Expand Down
42 changes: 1 addition & 41 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
use serde_derive::{Deserialize, Serialize};
use std::{fs::read_to_string, process::Command, str};

fn main() {
println!("cargo:rerun-if-changed=.");

let mut git_sha: Option<String> = None;

if let Ok(vcs_info) = read_to_string(".cargo_vcs_info.json") {
let vcs_info: Result<CargoVcsInfo, _> = serde_json::from_str(&vcs_info);
if let Ok(vcs_info) = vcs_info {
git_sha = Some(vcs_info.git.sha1);
}
}

if git_sha.is_none() {
if let Ok(git_describe) = Command::new("git")
.arg("describe")
.arg("--always")
.arg("--exclude='*'")
.arg("--long")
.arg("--dirty")
.output()
.map(|o| o.stdout)
{
git_sha = str::from_utf8(&git_describe).ok().map(str::to_string);
}
}

if let Some(git_sha) = git_sha {
println!("cargo:rustc-env=GIT_SHA={}", git_sha);
}
}

#[derive(Serialize, Deserialize, Default)]
struct CargoVcsInfo {
git: CargoVcsInfoGit,
}

#[derive(Serialize, Deserialize, Default)]
struct CargoVcsInfoGit {
sha1: String,
crate_git_revision::init();
}
4 changes: 2 additions & 2 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use soroban_env_host::meta;
use std::fmt::Debug;

const GIT_SHA: Option<&str> = option_env!("GIT_SHA");
const GIT_REVISION: &str = env!("GIT_REVISION");

#[derive(Parser, Debug)]
pub struct Cmd;
Expand All @@ -13,7 +13,7 @@ impl Cmd {
println!(
"soroban-cli {} ({})",
env!("CARGO_PKG_VERSION"),
GIT_SHA.unwrap_or_default(),
GIT_REVISION,
);
println!("soroban-env-interface-version: {}", meta::INTERFACE_VERSION);
}
Expand Down

0 comments on commit 125e251

Please sign in to comment.