Skip to content

Commit a679520

Browse files
author
Thomas Jespersen
committed
Implement split_maybe_lib_args() to handle paths with spaces
When using `link_deps()` full paths are added to target_rustcflags, which doesn't work well with split_maybe_args(), as it splits on space. Fixes #81
1 parent 167a97c commit a679520

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/runtest.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'test> TestCx<'test> {
347347
.args(&["--unpretty", &pretty_type])
348348
.args(&["--target", &self.config.target])
349349
.arg("-L").arg(&aux_dir)
350-
.args(self.split_maybe_args(&self.config.target_rustcflags))
350+
.args(self.split_maybe_lib_args(&self.config.target_rustcflags))
351351
.args(&self.props.compile_flags)
352352
.envs(self.props.exec_env.clone());
353353

@@ -403,7 +403,7 @@ actual:\n\
403403
rustc.args(&["--cfg", revision]);
404404
}
405405

406-
rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
406+
rustc.args(self.split_maybe_lib_args(&self.config.target_rustcflags));
407407
rustc.args(&self.props.compile_flags);
408408

409409
self.compose_and_run_compiler(rustc, Some(src))
@@ -1448,7 +1448,7 @@ actual:\n\
14481448
if self.props.force_host {
14491449
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
14501450
} else {
1451-
rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
1451+
rustc.args(self.split_maybe_lib_args(&self.config.target_rustcflags));
14521452
}
14531453

14541454
rustc.args(&self.props.compile_flags);
@@ -1524,6 +1524,25 @@ actual:\n\
15241524
}
15251525
}
15261526

1527+
// Split library arguments on "-L" to handle paths with spaces properly. Like
1528+
// split_maybe_args(), empty strings filtered out.
1529+
fn split_maybe_lib_args(&self, argstr: &Option<String>) -> Vec<String> {
1530+
if let Some(ref s) = *argstr {
1531+
s.split("-L")
1532+
.filter_map(|p| {
1533+
let p = p.trim();
1534+
if p.is_empty() { None } else { Some(p.to_owned()) }
1535+
})
1536+
.fold(Vec::new(), |mut v, arg| {
1537+
v.push("-L".to_owned());
1538+
v.push(arg);
1539+
v
1540+
})
1541+
} else {
1542+
Vec::new()
1543+
}
1544+
}
1545+
15271546
fn make_cmdline(&self, command: &Command, libpath: &str) -> String {
15281547
use util;
15291548

0 commit comments

Comments
 (0)