Refactor command runner handling

This commit is contained in:
bjorn3 2024-09-13 16:38:05 +00:00
parent 652b00430d
commit 41f6d55398
2 changed files with 17 additions and 19 deletions

View File

@ -447,26 +447,11 @@ fn run_rustc<I, S>(&self, args: I)
}
fn run_out_command(&self, name: &str, args: &[&str]) {
let mut full_cmd = vec![];
let mut cmd = self
.target_compiler
.run_with_runner(BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name));
// Prepend the RUN_WRAPPER's
if !self.target_compiler.runner.is_empty() {
full_cmd.extend(self.target_compiler.runner.iter().cloned());
}
full_cmd.push(
BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
);
for arg in args {
full_cmd.push(arg.to_string());
}
let mut cmd_iter = full_cmd.into_iter();
let first = cmd_iter.next().unwrap();
let mut cmd = Command::new(first);
cmd.args(cmd_iter);
cmd.args(args);
spawn_and_wait(cmd);
}

View File

@ -1,3 +1,4 @@
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::sync::atomic::{AtomicBool, Ordering};
@ -59,6 +60,18 @@ pub(crate) fn set_cross_linker_and_runner(&mut self) {
}
}
}
pub(crate) fn run_with_runner(&self, program: impl AsRef<OsStr>) -> Command {
if self.runner.is_empty() {
Command::new(program)
} else {
let mut runner_iter = self.runner.iter();
let mut cmd = Command::new(runner_iter.next().unwrap());
cmd.args(runner_iter);
cmd.arg(program);
cmd
}
}
}
pub(crate) struct CargoProject {