Skip to content

Commit

Permalink
Reimplement git version generation ourselves
Browse files Browse the repository at this point in the history
This allows us to remove two dependency crates
  • Loading branch information
faho committed Mar 2, 2024
1 parent a1e46a9 commit 2a4e776
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
31 changes: 5 additions & 26 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -34,7 +34,6 @@ num-traits = "0.2.15"
once_cell = "1.17.0"
rand = { version = "0.8.5", features = ["small_rng"] }
widestring = "1.0.2"
git-version = "0.3"
terminfo = { git = "https://github.com/meh/rust-terminfo", rev = "870327dd79beaecf50db09a15931d5ee1de2a24d" }

[dev-dependencies]
Expand Down
26 changes: 26 additions & 0 deletions build.rs
Expand Up @@ -24,6 +24,8 @@ fn main() {
.unwrap(),
);

rsconf::set_env_value("FISH_BUILD_VERSION", &get_version(build_dir));

rsconf::rebuild_if_path_changed("src/libc.c");
cc::Build::new()
.file("src/libc.c")
Expand Down Expand Up @@ -193,3 +195,27 @@ fn setup_paths() {
rsconf::set_env_value("DOCDIR", docdir.to_str().unwrap());
rsconf::rebuild_if_env_changed("DOCDIR");
}

fn get_version(build_dir: &str) -> String {
use std::fs::read_to_string;
use std::process::Command;

if let Ok(var) = std::env::var("FISH_BUILD_VERSION") {
return var;
}

let path = PathBuf::from(build_dir).join("version");
if let Ok(strver) = read_to_string(path) {
return strver.to_string();
}

let args = &["describe", "--always", "--dirty=-dirty"];
if let Ok(output) = Command::new("git").args(args).output() {
let rev = String::from_utf8_lossy(&output.stdout).trim().to_string();
if !rev.is_empty() {
return rev;
}
}

"unknown".to_string()
}
5 changes: 1 addition & 4 deletions src/lib.rs
Expand Up @@ -22,10 +22,7 @@
#![allow(clippy::too_many_arguments)]
#![allow(clippy::uninlined_format_args)]

pub const BUILD_VERSION: &str = match option_env!("FISH_BUILD_VERSION") {
Some(v) => v,
None => git_version::git_version!(args = ["--always", "--dirty=-dirty"], fallback = "unknown"),
};
pub const BUILD_VERSION: &str = env!("FISH_BUILD_VERSION");

#[macro_use]
pub mod common;
Expand Down

0 comments on commit 2a4e776

Please sign in to comment.