diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index bf532d9ccf9ed..b036238b0219d 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1113,42 +1113,30 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let target = matches.opt_str("target").unwrap_or( host_triple().to_string()); let opt_level = { - if matches.opt_present("O") { - if cg.opt_level.is_some() { - early_error(error_format, "-O and -C opt-level both provided"); - } - OptLevel::Default - } else { - match cg.opt_level { - None => OptLevel::No, - Some(0) => OptLevel::No, - Some(1) => OptLevel::Less, - Some(2) => OptLevel::Default, - Some(3) => OptLevel::Aggressive, - Some(arg) => { - early_error(error_format, &format!("optimization level needs to be \ - between 0-3 (instead was `{}`)", - arg)); - } + match cg.opt_level { + None => OptLevel::No, + Some(0) => OptLevel::No, + Some(1) => OptLevel::Less, + Some(2) => OptLevel::Default, + Some(3) => OptLevel::Aggressive, + Some(arg) => { + early_error(error_format, &format!("optimization level needs to be \ + between 0-3 (instead was `{}`)", + arg)); } } }; let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No); let gc = debugging_opts.gc; - let debuginfo = if matches.opt_present("g") { - if cg.debuginfo.is_some() { - early_error(error_format, "-g and -C debuginfo both provided"); - } - FullDebugInfo - } else { + let debuginfo = { match cg.debuginfo { None | Some(0) => NoDebugInfo, Some(1) => LimitedDebugInfo, Some(2) => FullDebugInfo, Some(arg) => { early_error(error_format, &format!("debug info level needs to be between \ - 0-2 (instead was `{}`)", - arg)); + 0-2 (instead was `{}`)", + arg)); } } }; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index d8d1cf5a026b6..64bb72eb68d6a 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -159,7 +159,7 @@ pub fn run_compiler<'a>(args: &[String], } }} - let matches = match handle_options(args) { + let matches = match handle_options(args.to_vec()) { Some(matches) => matches, None => return (Ok(()), None), }; @@ -870,9 +870,9 @@ fn print_flag_list(cmdline_opt: &str, /// /// So with all that in mind, the comments below have some more detail about the /// contortions done here to get things to work out correctly. -pub fn handle_options(args: &[String]) -> Option { +pub fn handle_options(mut args: Vec) -> Option { // Throw away the first argument, the name of the binary - let args = &args[1..]; + let _binary = args.remove(0); if args.is_empty() { // user did not write `-v` nor `-Z unstable-options`, so do not @@ -881,6 +881,16 @@ pub fn handle_options(args: &[String]) -> Option { return None; } + // Replace -O and -g with their equivalent -C options. + for i in 0..args.len() { + if args[i] == "-O" { + args[i] = "-Copt-level=2".to_string(); + } + if args[i] == "-g" { + args[i] = "-Cdebuginfo=2".to_string(); + } + } + // Parse with *all* options defined in the compiler, we don't worry about // option stability here we just want to parse as much as possible. let all_groups: Vec = config::rustc_optgroups() diff --git a/src/test/run-make/multiple-options-parsing/Makefile b/src/test/run-make/multiple-options-parsing/Makefile new file mode 100644 index 0000000000000..35444f32413a2 --- /dev/null +++ b/src/test/run-make/multiple-options-parsing/Makefile @@ -0,0 +1,14 @@ +-include ../tools.mk + +# Test that -O and -g can be used multiple times, together with their equivalent -C options. + +all: + $(RUSTC) -O -O dummy.rs + $(RUSTC) -O -C opt-level=2 dummy.rs + $(RUSTC) -C opt-level=2 -O dummy.rs + $(RUSTC) -C opt-level=2 -C opt-level=2 dummy.rs + + $(RUSTC) -g -g dummy.rs + $(RUSTC) -g -C debuginfo=2 dummy.rs + $(RUSTC) -C debuginfo=2 -g dummy.rs + $(RUSTC) -C debuginfo=2 -C debuginfo=2 dummy.rs diff --git a/src/test/run-make/multiple-options-parsing/dummy.rs b/src/test/run-make/multiple-options-parsing/dummy.rs new file mode 100644 index 0000000000000..e06c0a5ec2a4c --- /dev/null +++ b/src/test/run-make/multiple-options-parsing/dummy.rs @@ -0,0 +1,11 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {}