Skip to content

Commit 851a284

Browse files
committed
Allow runner params
1 parent 058e805 commit 851a284

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

src/cargo/ops/cargo_rustc/compilation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct Compilation<'cfg> {
5454

5555
config: &'cfg Config,
5656

57-
target_runner: LazyCell<Option<PathBuf>>,
57+
target_runner: LazyCell<Option<(PathBuf, Vec<String>)>>,
5858
}
5959

6060
impl<'cfg> Compilation<'cfg> {
@@ -94,18 +94,19 @@ impl<'cfg> Compilation<'cfg> {
9494
self.fill_env(process(cmd), pkg, true)
9595
}
9696

97-
fn target_runner(&self) -> CargoResult<&Option<PathBuf>> {
97+
fn target_runner(&self) -> CargoResult<&Option<(PathBuf, Vec<String>)>> {
9898
self.target_runner.get_or_try_init(|| {
9999
let key = format!("target.{}.runner", self.target);
100-
Ok(self.config.get_path(&key)?.map(|v| v.val))
100+
Ok(self.config.get_path_and_args(&key)?.map(|v| v.val))
101101
})
102102
}
103103

104104
/// See `process`.
105105
pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
106106
-> CargoResult<ProcessBuilder> {
107-
let builder = if let &Some(ref runner) = self.target_runner()? {
107+
let builder = if let &Some((ref runner, ref args)) = self.target_runner()? {
108108
let mut builder = process(runner);
109+
builder.args(args);
109110
builder.arg(cmd);
110111
builder
111112
} else {

src/cargo/util/config.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,40 @@ impl Config {
215215
}
216216
}
217217

218+
fn string_to_path(&self, value: String, definition: &Definition) -> PathBuf {
219+
let is_path = value.contains('/') ||
220+
(cfg!(windows) && value.contains('\\'));
221+
if is_path {
222+
definition.root(self).join(value)
223+
} else {
224+
// A pathless name
225+
PathBuf::from(value)
226+
}
227+
}
228+
218229
pub fn get_path(&self, key: &str) -> CargoResult<Option<Value<PathBuf>>> {
219230
if let Some(val) = self.get_string(key)? {
220-
let is_path = val.val.contains('/') ||
221-
(cfg!(windows) && val.val.contains('\\'));
222-
let path = if is_path {
223-
val.definition.root(self).join(val.val)
224-
} else {
225-
// A pathless name
226-
PathBuf::from(val.val)
227-
};
228231
Ok(Some(Value {
229-
val: path,
230-
definition: val.definition,
232+
val: self.string_to_path(val.val, &val.definition),
233+
definition: val.definition
231234
}))
232235
} else {
233236
Ok(None)
234237
}
235238
}
236239

240+
pub fn get_path_and_args(&self, key: &str) -> CargoResult<Option<Value<(PathBuf, Vec<String>)>>> {
241+
if let Some(mut val) = self.get_list_or_split_string(key)? {
242+
if !val.val.is_empty() {
243+
return Ok(Some(Value {
244+
val: (self.string_to_path(val.val.remove(0), &val.definition), val.val),
245+
definition: val.definition
246+
}));
247+
}
248+
}
249+
Ok(None)
250+
}
251+
237252
pub fn get_list(&self, key: &str)
238253
-> CargoResult<Option<Value<Vec<(String, PathBuf)>>>> {
239254
match self.get(key)? {

tests/tool-paths.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn custom_runner() {
140140
.file("benches/bench.rs", "")
141141
.file(".cargo/config", &format!(r#"
142142
[target.{}]
143-
runner = "nonexistent-runner"
143+
runner = "nonexistent-runner -r"
144144
"#, target));
145145

146146
foo.build();
@@ -149,15 +149,15 @@ fn custom_runner() {
149149
execs().with_stderr_contains(&format!("\
150150
[COMPILING] foo v0.0.1 ({url})
151151
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
152-
[RUNNING] `nonexistent-runner target[/]debug[/]foo[EXE] --param`
152+
[RUNNING] `nonexistent-runner -r target[/]debug[/]foo[EXE] --param`
153153
", url = foo.url())));
154154

155155
assert_that(foo.cargo("test").args(&["--test", "test", "--verbose", "--", "--param"]),
156156
execs().with_stderr_contains(&format!("\
157157
[COMPILING] foo v0.0.1 ({url})
158158
[RUNNING] `rustc [..]`
159159
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
160-
[RUNNING] `nonexistent-runner [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param`
160+
[RUNNING] `nonexistent-runner -r [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param`
161161
", url = foo.url())));
162162

163163
assert_that(foo.cargo("bench").args(&["--bench", "bench", "--verbose", "--", "--param"]),
@@ -166,6 +166,6 @@ fn custom_runner() {
166166
[RUNNING] `rustc [..]`
167167
[RUNNING] `rustc [..]`
168168
[FINISHED] release [optimized] target(s) in [..]
169-
[RUNNING] `nonexistent-runner [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench`
169+
[RUNNING] `nonexistent-runner -r [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench`
170170
", url = foo.url())));
171171
}

0 commit comments

Comments
 (0)