Skip to content

Commit

Permalink
Refactor command runner handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Sep 13, 2024
1 parent 652b004 commit 41f6d55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
23 changes: 4 additions & 19 deletions build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,26 +447,11 @@ impl<'a> TestRunner<'a> {
}

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);
}
Expand Down
13 changes: 13 additions & 0 deletions build_system/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -59,6 +60,18 @@ impl Compiler {
}
}
}

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 {
Expand Down

0 comments on commit 41f6d55

Please sign in to comment.