From e6da57f3e713b8b3adef209940335a8f6bfa642f Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 30 Apr 2019 21:51:55 +0100 Subject: Fix argument alias handling for -O and -C opt-level --- src/librustc/session/config.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index ad80e5d74bd..b6d3ee882b3 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -2181,10 +2181,15 @@ pub fn build_session_options_and_crate_config( TargetTriple::from_triple(host_triple()) }; 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"); + let max_o = matches.opt_positions("O").into_iter().max(); + let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { + if let Some("opt-level") = s.splitn(2, '=').next() { + Some(i) + } else { + None } + }).max(); + if max_o > max_c { OptLevel::Default } else { match cg.opt_level.as_ref().map(String::as_ref) { -- cgit 1.4.1-3-g733a5 From e8e43c9e16d78e6fe26f67ba1c4218427acc583a Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 30 Apr 2019 21:52:05 +0100 Subject: Fix argument alias handling for -g and -C debuginfo --- src/librustc/session/config.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index b6d3ee882b3..8e223170894 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -2214,10 +2214,15 @@ pub fn build_session_options_and_crate_config( } }; let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No); - let debuginfo = if matches.opt_present("g") { - if cg.debuginfo.is_some() { - early_error(error_format, "-g and -C debuginfo both provided"); + let max_g = matches.opt_positions("g").into_iter().max(); + let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { + if let Some("debuginfo") = s.splitn(2, '=').next() { + Some(i) + } else { + None } + }).max(); + let debuginfo = if max_g > max_c { DebugInfo::Full } else { match cg.debuginfo { -- cgit 1.4.1-3-g733a5 From 11b1d483b2f0e65e049c491c34a0f8573553f4b4 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 30 Apr 2019 21:52:54 +0100 Subject: Add a run-make test for command aliases --- src/test/run-make/override-aliased-flags/Makefile | 22 ++++++++++++++++++++++ src/test/run-make/override-aliased-flags/main.rs | 1 + 2 files changed, 23 insertions(+) create mode 100644 src/test/run-make/override-aliased-flags/Makefile create mode 100644 src/test/run-make/override-aliased-flags/main.rs (limited to 'src') diff --git a/src/test/run-make/override-aliased-flags/Makefile b/src/test/run-make/override-aliased-flags/Makefile new file mode 100644 index 00000000000..866060ad998 --- /dev/null +++ b/src/test/run-make/override-aliased-flags/Makefile @@ -0,0 +1,22 @@ +-include ../../run-make-fulldeps/tools.mk + +# FIXME: it would be good to check that it's actually the rightmost flags +# that are used when multiple flags are specified, but I can't think of a +# reliable way to check this. + +all: + # Test that `-O` and `-C opt-level` can be specified multiple times. + # The rightmost flag will be used over any previous flags. + $(RUSTC) -O -O main.rs + $(RUSTC) -O -C opt-level=0 main.rs + $(RUSTC) -C opt-level=0 -O main.rs + $(RUSTC) -C opt-level=0 -C opt-level=2 main.rs + $(RUSTC) -C opt-level=2 -C opt-level=0 main.rs + + # Test that `-g` and `-C debuginfo` can be specified multiple times. + # The rightmost flag will be used over any previous flags. + $(RUSTC) -g -g main.rs + $(RUSTC) -g -C debuginfo=0 main.rs + $(RUSTC) -C debuginfo=0 -g main.rs + $(RUSTC) -C debuginfo=0 -C debuginfo=2 main.rs + $(RUSTC) -C debuginfo=2 -C debuginfo=0 main.rs diff --git a/src/test/run-make/override-aliased-flags/main.rs b/src/test/run-make/override-aliased-flags/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/src/test/run-make/override-aliased-flags/main.rs @@ -0,0 +1 @@ +fn main() {} -- cgit 1.4.1-3-g733a5 From d54cf00c7712c174a6f7efe8d33ca94e2f943e5d Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 1 May 2019 23:23:35 +0100 Subject: Add comments --- src/librustc/session/config.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 8e223170894..084a5429f26 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -2181,6 +2181,12 @@ pub fn build_session_options_and_crate_config( TargetTriple::from_triple(host_triple()) }; let opt_level = { + // The `-O` and `-C opt-level` flags specify the same setting, so we want to be able + // to use them interchangeably. However, because they're technically different flags, + // we need to work out manually which should take precedence if both are supplied (i.e. + // the rightmost flag). We do this by finding the (rightmost) position of both flags and + // comparing them. Note that if a flag is not found, its position will be `None`, which + // always compared less than `Some(_)`. let max_o = matches.opt_positions("O").into_iter().max(); let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { if let Some("opt-level") = s.splitn(2, '=').next() { @@ -2213,6 +2219,9 @@ pub fn build_session_options_and_crate_config( } } }; + // The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able + // to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`) + // for more details. let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No); let max_g = matches.opt_positions("g").into_iter().max(); let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { -- cgit 1.4.1-3-g733a5 From ecd046817b44b933e17940332bda845f854fb554 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 2 May 2019 10:32:56 +0100 Subject: Update getopts to 0.2.19 --- src/bootstrap/Cargo.toml | 2 +- src/libtest/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 9a410c339bf..3151b56d8e8 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -39,7 +39,7 @@ build_helper = { path = "../build_helper" } cmake = "0.1.38" filetime = "0.2" num_cpus = "1.0" -getopts = "0.2.18" +getopts = "0.2.19" cc = "1.0.35" libc = "0.2" serde = "1.0.8" diff --git a/src/libtest/Cargo.toml b/src/libtest/Cargo.toml index 2e836b6772f..a72e4c70502 100644 --- a/src/libtest/Cargo.toml +++ b/src/libtest/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" crate-type = ["dylib", "rlib"] [dependencies] -getopts = "0.2.18" +getopts = "0.2.19" term = { path = "../libterm" } # not actually used but needed to always have proc_macro in the sysroot -- cgit 1.4.1-3-g733a5 From 12f63ecd29e234cd28e1bc94ddc518d01a518be5 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 4 May 2019 14:53:22 +0100 Subject: Move run-make test to run-make-fulldeps --- .../override-aliased-flags/Makefile | 22 ++++++++++++++++++++++ .../override-aliased-flags/main.rs | 1 + src/test/run-make/override-aliased-flags/Makefile | 22 ---------------------- src/test/run-make/override-aliased-flags/main.rs | 1 - 4 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 src/test/run-make-fulldeps/override-aliased-flags/Makefile create mode 100644 src/test/run-make-fulldeps/override-aliased-flags/main.rs delete mode 100644 src/test/run-make/override-aliased-flags/Makefile delete mode 100644 src/test/run-make/override-aliased-flags/main.rs (limited to 'src') diff --git a/src/test/run-make-fulldeps/override-aliased-flags/Makefile b/src/test/run-make-fulldeps/override-aliased-flags/Makefile new file mode 100644 index 00000000000..bea610eeb9f --- /dev/null +++ b/src/test/run-make-fulldeps/override-aliased-flags/Makefile @@ -0,0 +1,22 @@ +-include ../tools.mk + +# FIXME: it would be good to check that it's actually the rightmost flags +# that are used when multiple flags are specified, but I can't think of a +# reliable way to check this. + +all: + # Test that `-O` and `-C opt-level` can be specified multiple times. + # The rightmost flag will be used over any previous flags. + $(RUSTC) -O -O main.rs + $(RUSTC) -O -C opt-level=0 main.rs + $(RUSTC) -C opt-level=0 -O main.rs + $(RUSTC) -C opt-level=0 -C opt-level=2 main.rs + $(RUSTC) -C opt-level=2 -C opt-level=0 main.rs + + # Test that `-g` and `-C debuginfo` can be specified multiple times. + # The rightmost flag will be used over any previous flags. + $(RUSTC) -g -g main.rs + $(RUSTC) -g -C debuginfo=0 main.rs + $(RUSTC) -C debuginfo=0 -g main.rs + $(RUSTC) -C debuginfo=0 -C debuginfo=2 main.rs + $(RUSTC) -C debuginfo=2 -C debuginfo=0 main.rs diff --git a/src/test/run-make-fulldeps/override-aliased-flags/main.rs b/src/test/run-make-fulldeps/override-aliased-flags/main.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/src/test/run-make-fulldeps/override-aliased-flags/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/src/test/run-make/override-aliased-flags/Makefile b/src/test/run-make/override-aliased-flags/Makefile deleted file mode 100644 index 866060ad998..00000000000 --- a/src/test/run-make/override-aliased-flags/Makefile +++ /dev/null @@ -1,22 +0,0 @@ --include ../../run-make-fulldeps/tools.mk - -# FIXME: it would be good to check that it's actually the rightmost flags -# that are used when multiple flags are specified, but I can't think of a -# reliable way to check this. - -all: - # Test that `-O` and `-C opt-level` can be specified multiple times. - # The rightmost flag will be used over any previous flags. - $(RUSTC) -O -O main.rs - $(RUSTC) -O -C opt-level=0 main.rs - $(RUSTC) -C opt-level=0 -O main.rs - $(RUSTC) -C opt-level=0 -C opt-level=2 main.rs - $(RUSTC) -C opt-level=2 -C opt-level=0 main.rs - - # Test that `-g` and `-C debuginfo` can be specified multiple times. - # The rightmost flag will be used over any previous flags. - $(RUSTC) -g -g main.rs - $(RUSTC) -g -C debuginfo=0 main.rs - $(RUSTC) -C debuginfo=0 -g main.rs - $(RUSTC) -C debuginfo=0 -C debuginfo=2 main.rs - $(RUSTC) -C debuginfo=2 -C debuginfo=0 main.rs diff --git a/src/test/run-make/override-aliased-flags/main.rs b/src/test/run-make/override-aliased-flags/main.rs deleted file mode 100644 index f328e4d9d04..00000000000 --- a/src/test/run-make/override-aliased-flags/main.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} -- cgit 1.4.1-3-g733a5