Skip to content

Replace -O and -g with -C before handling options #32399

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
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
38 changes: 13 additions & 25 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
};
Expand Down
16 changes: 13 additions & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down Expand Up @@ -870,9 +870,9 @@ fn print_flag_list<T>(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<getopts::Matches> {
pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
// 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
Expand All @@ -881,6 +881,16 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
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<getopts::OptGroup> = config::rustc_optgroups()
Expand Down
14 changes: 14 additions & 0 deletions src/test/run-make/multiple-options-parsing/Makefile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions src/test/run-make/multiple-options-parsing/dummy.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {}