diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 8119618da57..0890915b20e 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -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(); } @@ -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. @@ -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(); } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 7d13cb2da65..5d991d30051 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -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); diff --git a/src/test/run-make/prune-link-args/Makefile b/src/test/run-make/prune-link-args/Makefile new file mode 100644 index 00000000000..53699e0dd98 --- /dev/null +++ b/src/test/run-make/prune-link-args/Makefile @@ -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 " + +all: + $(RUSTC) $(RUSTC_FLAGS) empty.rs diff --git a/src/test/run-make/prune-link-args/empty.rs b/src/test/run-make/prune-link-args/empty.rs new file mode 100644 index 00000000000..45590d86ba6 --- /dev/null +++ b/src/test/run-make/prune-link-args/empty.rs @@ -0,0 +1 @@ +fn main() { }