Skip to content

Commit 089341b

Browse files
committed
Replace -O and -g with -C before handling options
1 parent a111297 commit 089341b

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

src/librustc/session/config.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,42 +1113,30 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11131113
let target = matches.opt_str("target").unwrap_or(
11141114
host_triple().to_string());
11151115
let opt_level = {
1116-
if matches.opt_present("O") {
1117-
if cg.opt_level.is_some() {
1118-
early_error(error_format, "-O and -C opt-level both provided");
1119-
}
1120-
OptLevel::Default
1121-
} else {
1122-
match cg.opt_level {
1123-
None => OptLevel::No,
1124-
Some(0) => OptLevel::No,
1125-
Some(1) => OptLevel::Less,
1126-
Some(2) => OptLevel::Default,
1127-
Some(3) => OptLevel::Aggressive,
1128-
Some(arg) => {
1129-
early_error(error_format, &format!("optimization level needs to be \
1130-
between 0-3 (instead was `{}`)",
1131-
arg));
1132-
}
1116+
match cg.opt_level {
1117+
None => OptLevel::No,
1118+
Some(0) => OptLevel::No,
1119+
Some(1) => OptLevel::Less,
1120+
Some(2) => OptLevel::Default,
1121+
Some(3) => OptLevel::Aggressive,
1122+
Some(arg) => {
1123+
early_error(error_format, &format!("optimization level needs to be \
1124+
between 0-3 (instead was `{}`)",
1125+
arg));
11331126
}
11341127
}
11351128
};
11361129
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
11371130
let gc = debugging_opts.gc;
1138-
let debuginfo = if matches.opt_present("g") {
1139-
if cg.debuginfo.is_some() {
1140-
early_error(error_format, "-g and -C debuginfo both provided");
1141-
}
1142-
FullDebugInfo
1143-
} else {
1131+
let debuginfo = {
11441132
match cg.debuginfo {
11451133
None | Some(0) => NoDebugInfo,
11461134
Some(1) => LimitedDebugInfo,
11471135
Some(2) => FullDebugInfo,
11481136
Some(arg) => {
11491137
early_error(error_format, &format!("debug info level needs to be between \
1150-
0-2 (instead was `{}`)",
1151-
arg));
1138+
0-2 (instead was `{}`)",
1139+
arg));
11521140
}
11531141
}
11541142
};

src/librustc_driver/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn run_compiler<'a>(args: &[String],
159159
}
160160
}}
161161

162-
let matches = match handle_options(args) {
162+
let matches = match handle_options(args.to_vec()) {
163163
Some(matches) => matches,
164164
None => return (Ok(()), None),
165165
};
@@ -870,9 +870,9 @@ fn print_flag_list<T>(cmdline_opt: &str,
870870
///
871871
/// So with all that in mind, the comments below have some more detail about the
872872
/// contortions done here to get things to work out correctly.
873-
pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
873+
pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
874874
// Throw away the first argument, the name of the binary
875-
let args = &args[1..];
875+
let _binary = args.remove(0);
876876

877877
if args.is_empty() {
878878
// user did not write `-v` nor `-Z unstable-options`, so do not
@@ -881,6 +881,16 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
881881
return None;
882882
}
883883

884+
// Replace -O and -g with their equivalent -C options.
885+
for i in 0..args.len() {
886+
if args[i] == "-O" {
887+
args[i] = "-Copt-level=2".to_string();
888+
}
889+
if args[i] == "-g" {
890+
args[i] = "-Cdebuginfo=2".to_string();
891+
}
892+
}
893+
884894
// Parse with *all* options defined in the compiler, we don't worry about
885895
// option stability here we just want to parse as much as possible.
886896
let all_groups: Vec<getopts::OptGroup> = config::rustc_optgroups()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
3+
# Test that -O and -g can be used multiple times, together with their equivalent -C options.
4+
5+
all:
6+
$(RUSTC) -O -O dummy.rs
7+
$(RUSTC) -O -C opt-level=2 dummy.rs
8+
$(RUSTC) -C opt-level=2 -O dummy.rs
9+
$(RUSTC) -C opt-level=2 -C opt-level=2 dummy.rs
10+
11+
$(RUSTC) -g -g dummy.rs
12+
$(RUSTC) -g -C debuginfo=2 dummy.rs
13+
$(RUSTC) -C debuginfo=2 -g dummy.rs
14+
$(RUSTC) -C debuginfo=2 -C debuginfo=2 dummy.rs
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {}

0 commit comments

Comments
 (0)