Skip to content

Commit

Permalink
Implement split_maybe_lib_args() to handle paths with spaces
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thomas Jespersen committed Oct 13, 2017
1 parent 167a97c commit a679520
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'test> TestCx<'test> {
.args(&["--unpretty", &pretty_type])
.args(&["--target", &self.config.target])
.arg("-L").arg(&aux_dir)
.args(self.split_maybe_args(&self.config.target_rustcflags))
.args(self.split_maybe_lib_args(&self.config.target_rustcflags))
.args(&self.props.compile_flags)
.envs(self.props.exec_env.clone());

Expand Down Expand Up @@ -403,7 +403,7 @@ actual:\n\
rustc.args(&["--cfg", revision]);
}

rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
rustc.args(self.split_maybe_lib_args(&self.config.target_rustcflags));
rustc.args(&self.props.compile_flags);

self.compose_and_run_compiler(rustc, Some(src))
Expand Down Expand Up @@ -1448,7 +1448,7 @@ actual:\n\
if self.props.force_host {
rustc.args(self.split_maybe_args(&self.config.host_rustcflags));
} else {
rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
rustc.args(self.split_maybe_lib_args(&self.config.target_rustcflags));
}

rustc.args(&self.props.compile_flags);
Expand Down Expand Up @@ -1524,6 +1524,25 @@ actual:\n\
}
}

// Split library arguments on "-L" to handle paths with spaces properly. Like
// split_maybe_args(), empty strings filtered out.
fn split_maybe_lib_args(&self, argstr: &Option<String>) -> Vec<String> {
if let Some(ref s) = *argstr {
s.split("-L")
.filter_map(|p| {
let p = p.trim();
if p.is_empty() { None } else { Some(p.to_owned()) }
})
.fold(Vec::new(), |mut v, arg| {
v.push("-L".to_owned());
v.push(arg);
v
})
} else {
Vec::new()
}
}

fn make_cmdline(&self, command: &Command, libpath: &str) -> String {
use util;

Expand Down

0 comments on commit a679520

Please sign in to comment.