Skip to content

Commit

Permalink
Merge pull request #161 from benesch/catalina-build
Browse files Browse the repository at this point in the history
Avoid use of undefined std::process::Command behavior
  • Loading branch information
benesch authored Oct 22, 2019
2 parents 1bbe3f1 + 7f0bf05 commit d07c040
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions rdkafka-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,21 @@ macro_rules! println_stderr(
} }
);

fn run_command_or_fail(dir: &str, cmd: &str, args: &[&str]) {
println_stderr!("Running command: \"{} {}\" in dir: {}", cmd, args.join(" "), dir);
fn run_command_or_fail<P>(dir: &str, cmd: P, args: &[&str])
where
P: AsRef<Path>,
{
let cmd = cmd.as_ref();
let cmd = if cmd.components().count() > 1 && cmd.is_relative() {
// If `cmd` is a relative path (and not a bare command that should be
// looked up in PATH), absolutize it relative to `dir`, as otherwise the
// behavior of std::process::Command is undefined.
// https://github.com/rust-lang/rust/issues/37868
PathBuf::from(dir).join(cmd).canonicalize().expect("canonicalization failed")
} else {
PathBuf::from(cmd)
};
println_stderr!("Running command: \"{} {}\" in dir: {}", cmd.display(), args.join(" "), dir);
let ret = Command::new(cmd).current_dir(dir).args(args).status();
match ret.map(|status| (status.success(), status.code())) {
Ok((true, _)) => { return },
Expand Down

0 comments on commit d07c040

Please sign in to comment.