summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-02-03 10:41:36 -0500
committerAndrew Gallant <jamslam@gmail.com>2018-02-04 10:40:20 -0500
commit68dac7c4b0743a6a08f89f915957e23b8e3f3441 (patch)
treed4d174b4648430e07b4568a6a74565c845ad6695 /build.rs
parent35350470942920574e58170c1ab9d419f68af6da (diff)
build: add git hash
This commit makes the git hash ripgrep was built with available for use in the version string. We also do a few minor touchups in build.rs and src/app.rs.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/build.rs b/build.rs
index 3c16b532..01b3d18e 100644
--- a/build.rs
+++ b/build.rs
@@ -5,6 +5,7 @@ extern crate lazy_static;
use std::env;
use std::fs;
+use std::process;
use clap::Shell;
@@ -13,14 +14,34 @@ use clap::Shell;
mod app;
fn main() {
+ // OUT_DIR is set by Cargo and it's where any additional build artifacts
+ // are written.
let outdir = match env::var_os("OUT_DIR") {
- None => return,
Some(outdir) => outdir,
+ None => {
+ eprintln!(
+ "OUT_DIR environment variable not defined. \
+ Please file a bug: \
+ https://github.com/BurntSushi/ripgrep/issues/new");
+ process::exit(1);
+ }
};
fs::create_dir_all(&outdir).unwrap();
+ // Use clap to build completion files.
let mut app = app::app();
app.gen_completions("rg", Shell::Bash, &outdir);
app.gen_completions("rg", Shell::Fish, &outdir);
app.gen_completions("rg", Shell::PowerShell, &outdir);
+ // Note that we do not use clap's support for zsh. Instead, zsh completions
+ // are manually maintained in `complete/_rg`.
+
+ // Make the current git hash available to the build.
+ let result = process::Command::new("git")
+ .args(&["rev-parse", "--short=10", "HEAD"])
+ .output();
+ if let Ok(output) = result {
+ let hash = String::from_utf8_lossy(&output.stdout);
+ println!("cargo:rustc-env=RIPGREP_BUILD_GIT_HASH={}", hash);
+ }
}