build: a bit of clean-up

This does just a smidge of polishing in the build script source code.
This commit is contained in:
Andrew Gallant 2023-10-14 09:31:19 -04:00
parent 92c81b1225
commit 5b88515faf

View File

@ -1,12 +1,14 @@
use std::env; use std::{
use std::fs::{self, File}; env,
use std::io::{self, Read, Write}; fs::{self, File},
use std::path::Path; io::{self, Read, Write},
use std::process; path::Path,
process,
};
use clap::Shell; use clap::Shell;
use app::{RGArg, RGArgKind}; use crate::app::{RGArg, RGArgKind};
#[allow(dead_code)] #[allow(dead_code)]
#[path = "crates/core/app.rs"] #[path = "crates/core/app.rs"]
@ -15,16 +17,13 @@ mod app;
fn main() { fn main() {
// OUT_DIR is set by Cargo and it's where any additional build artifacts // OUT_DIR is set by Cargo and it's where any additional build artifacts
// are written. // are written.
let outdir = match env::var_os("OUT_DIR") { let Some(outdir) = env::var_os("OUT_DIR") else {
Some(outdir) => outdir,
None => {
eprintln!( eprintln!(
"OUT_DIR environment variable not defined. \ "OUT_DIR environment variable not defined. \
Please file a bug: \ Please file a bug: \
https://github.com/BurntSushi/ripgrep/issues/new" https://github.com/BurntSushi/ripgrep/issues/new"
); );
process::exit(1); process::exit(1);
}
}; };
fs::create_dir_all(&outdir).unwrap(); fs::create_dir_all(&outdir).unwrap();
@ -79,17 +78,16 @@ fn set_windows_exe_options() {
} }
fn git_revision_hash() -> Option<String> { fn git_revision_hash() -> Option<String> {
let result = process::Command::new("git") let output = process::Command::new("git")
.args(&["rev-parse", "--short=10", "HEAD"]) .args(&["rev-parse", "--short=10", "HEAD"])
.output(); .output()
result.ok().and_then(|output| { .ok()?;
let v = String::from_utf8_lossy(&output.stdout).trim().to_string(); let v = String::from_utf8_lossy(&output.stdout).trim().to_string();
if v.is_empty() { if v.is_empty() {
None None
} else { } else {
Some(v) Some(v)
} }
})
} }
fn generate_man_page<P: AsRef<Path>>(outdir: P) -> io::Result<()> { fn generate_man_page<P: AsRef<Path>>(outdir: P) -> io::Result<()> {