diff options
author | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-10-31 13:45:40 +0800 |
---|---|---|
committer | Martin Nordholts <enselic@gmail.com> | 2023-11-02 17:54:57 +0100 |
commit | 28d947fd8be77946d9e281ec0c794a1c2df929de (patch) | |
tree | 855c6372e0bbd79c619ced368ba23b1dd490e775 | |
parent | b000db8f32af8f8d608184ac5ec3413b46d0bf5b (diff) |
Use anyhow in build script
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | build.rs | 13 |
3 files changed, 17 insertions, 6 deletions
@@ -75,6 +75,12 @@ dependencies = [ ] [[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] name = "assert_cmd" version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -106,6 +112,7 @@ name = "bat" version = "0.24.0" dependencies = [ "ansi_colours", + "anyhow", "assert_cmd", "bincode", "bugreport", @@ -98,6 +98,9 @@ tempfile = "3.8.1" [target.'cfg(unix)'.dev-dependencies] nix = { version = "0.26.4", default-features = false, features = ["term"] } +[build-dependencies] +anyhow = "1.0.75" + [build-dependencies.clap] version = "4.4.6" optional = true @@ -4,9 +4,8 @@ fn main() {} #[cfg(feature = "application")] -fn main() -> Result<(), Box<dyn std::error::Error>> { +fn main() -> anyhow::Result<()> { use std::collections::HashMap; - use std::error::Error; use std::fs; use std::path::Path; @@ -21,7 +20,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { variables: &HashMap<&str, &str>, in_file: &str, out_file: impl AsRef<Path>, - ) -> Result<(), Box<dyn Error>> { + ) -> anyhow::Result<()> { let mut content = fs::read_to_string(in_file)?; for (variable_name, value) in variables { @@ -40,9 +39,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { variables.insert("PROJECT_EXECUTABLE_UPPERCASE", &executable_name_uppercase); variables.insert("PROJECT_VERSION", PROJECT_VERSION); - let out_dir_env = std::env::var_os("BAT_ASSETS_GEN_DIR") - .or_else(|| std::env::var_os("OUT_DIR")) - .expect("BAT_ASSETS_GEN_DIR or OUT_DIR to be set in build.rs"); + let Some(out_dir_env) = + std::env::var_os("BAT_ASSETS_GEN_DIR").or_else(|| std::env::var_os("OUT_DIR")) + else { + anyhow::bail!("BAT_ASSETS_GEN_DIR or OUT_DIR should be set for build.rs"); + }; let out_dir = Path::new(&out_dir_env); fs::create_dir_all(out_dir.join("assets/manual")).unwrap(); |