Skip to content

Commit 41f6d55

Browse files
committed
Refactor command runner handling
1 parent 652b004 commit 41f6d55

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

build_system/tests.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -447,26 +447,11 @@ impl<'a> TestRunner<'a> {
447447
}
448448

449449
fn run_out_command(&self, name: &str, args: &[&str]) {
450-
let mut full_cmd = vec![];
450+
let mut cmd = self
451+
.target_compiler
452+
.run_with_runner(BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name));
451453

452-
// Prepend the RUN_WRAPPER's
453-
if !self.target_compiler.runner.is_empty() {
454-
full_cmd.extend(self.target_compiler.runner.iter().cloned());
455-
}
456-
457-
full_cmd.push(
458-
BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
459-
);
460-
461-
for arg in args {
462-
full_cmd.push(arg.to_string());
463-
}
464-
465-
let mut cmd_iter = full_cmd.into_iter();
466-
let first = cmd_iter.next().unwrap();
467-
468-
let mut cmd = Command::new(first);
469-
cmd.args(cmd_iter);
454+
cmd.args(args);
470455

471456
spawn_and_wait(cmd);
472457
}

build_system/utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::OsStr;
12
use std::path::{Path, PathBuf};
23
use std::process::{self, Command};
34
use std::sync::atomic::{AtomicBool, Ordering};
@@ -59,6 +60,18 @@ impl Compiler {
5960
}
6061
}
6162
}
63+
64+
pub(crate) fn run_with_runner(&self, program: impl AsRef<OsStr>) -> Command {
65+
if self.runner.is_empty() {
66+
Command::new(program)
67+
} else {
68+
let mut runner_iter = self.runner.iter();
69+
let mut cmd = Command::new(runner_iter.next().unwrap());
70+
cmd.args(runner_iter);
71+
cmd.arg(program);
72+
cmd
73+
}
74+
}
6275
}
6376

6477
pub(crate) struct CargoProject {

0 commit comments

Comments
 (0)