Skip to content

rustc: filter out empty linker args #10749

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

Merged
merged 1 commit into from
Dec 1, 2013
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,12 @@ pub mod write {
~"-o", object.as_str().unwrap().to_owned(),
assembly.as_str().unwrap().to_owned()];

debug!("{} {}", cc, args.connect(" "));
debug!("{} '{}'", cc, args.connect("' '"));
let prog = run::process_output(cc, args);

if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
sess.note(format!("{} arguments: {}", cc, args.connect(" ")));
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
let mut cc_args = sess.targ_cfg.target_strs.cc_args.clone();
cc_args.push_all_move(link_args(sess, dylib, obj_filename, out_filename));
if (sess.opts.debugging_opts & session::print_link_args) != 0 {
println!("{} link args: {}", cc_prog, cc_args.connect(" "));
println!("{} link args: '{}'", cc_prog, cc_args.connect("' '"));
}

// May have not found libraries in the right formats.
Expand All @@ -1073,7 +1073,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,

if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}", cc_prog, cc_args.connect(" ")));
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}
Expand Down
8 changes: 7 additions & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,13 @@ pub fn build_session_options(binary: @str,
let ar = matches.opt_str("ar");
let linker = matches.opt_str("linker");
let linker_args = matches.opt_strs("link-args").flat_map( |a| {
a.split(' ').map(|arg| arg.to_owned()).collect()
a.split(' ').filter_map(|arg| {
if arg.is_empty() {
None
} else {
Some(arg.to_owned())
}
}).collect()
});

let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter);
Expand Down
6 changes: 6 additions & 0 deletions src/test/run-make/prune-link-args/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-include ../tools.mk
# Notice the space in the end, this emulates the output of pkg-config
RUSTC_FLAGS = --link-args "-lc "
Copy link
Member

Choose a reason for hiding this comment

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

This can also just be a normal run-pass test, using the compile-flags directive (docs), i.e.

<license block>

// Notice the space at the end, this emulates the output of pkg-config
// compile-flags:--linkargs "-lc "

fn main() {}

I'd guess that that is nicer than adding a Makefile etc, but I don't really know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that's much easier. Thanks, I'll update!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I tried that. Guess who has a problem with quoted comand line parameters: the test runner. I'm not sure if it's worth it to fix that or if the current makefile test suffices.


all:
$(RUSTC) $(RUSTC_FLAGS) empty.rs
1 change: 1 addition & 0 deletions src/test/run-make/prune-link-args/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() { }