Skip to content

Commit

Permalink
Better error messages in build.rs (#2173)
Browse files Browse the repository at this point in the history
* Better error messages in build.rs

* Use anyhow instead of assert
  • Loading branch information
emilk committed May 22, 2023
1 parent acfd7dc commit 79983a0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/re_build_build_info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ pub fn export_env_vars() {

fn rerun_if_changed(path: &str) {
// Make sure the file exists, otherwise we'll be rebuilding all the time.
assert!(std::path::Path::new(path).exists(), "Failed to find {path}");
assert!(
std::path::Path::new(path).exists(),
"Failed to find {path:?}"
);
println!("cargo:rerun-if-changed={path}");
}

Expand All @@ -96,6 +99,14 @@ fn run_command(cmd: &str, args: &[&str]) -> anyhow::Result<String> {
.args(args)
.output()
.with_context(|| format!("running '{cmd}'"))?;

anyhow::ensure!(
output.status.success(),
"Failed to run '{cmd} {args:?}':\n{}\n{}\n",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);

Ok(String::from_utf8(output.stdout)?.trim().to_owned())
}

Expand Down

0 comments on commit 79983a0

Please sign in to comment.