Skip to content

Implement split_maybe_lib_args() to handle paths with spaces #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I have a path like "-L Ooh-La-La"? Or even if you incorporating spaces in your split, " -L " is also legal in a path.

This will also act weird if people have their own non--L stuff in target_rustcflags.

.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