summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-10-31 13:45:40 +0800
committerMartin Nordholts <enselic@gmail.com>2023-11-02 17:54:57 +0100
commit28d947fd8be77946d9e281ec0c794a1c2df929de (patch)
tree855c6372e0bbd79c619ced368ba23b1dd490e775
parentb000db8f32af8f8d608184ac5ec3413b46d0bf5b (diff)
Use anyhow in build script
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml3
-rw-r--r--build.rs13
3 files changed, 17 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8bd4f6c9..70370f84 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index 4d6a5acf..d8e7ffe5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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
diff --git a/build.rs b/build.rs
index cf0375bf..43543904 100644
--- a/build.rs
+++ b/build.rs
@@ -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();