Skip to content

Commit f719239

Browse files
committed
move optimize-tests flag handling from bootstrap to compiletest
1 parent 125f33a commit f719239

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

src/bootstrap/test.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1363,16 +1363,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13631363
if let Some(ref npm) = builder.config.npm {
13641364
cmd.arg("--npm").arg(npm);
13651365
}
1366-
1367-
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1368-
if !is_rustdoc && mode != "ui" {
1369-
if builder.config.rust_optimize_tests {
1370-
flags.push("-O".to_string());
1371-
}
1372-
}
13731366
if builder.config.rust_optimize_tests {
13741367
cmd.arg("--optimize-tests");
13751368
}
1369+
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
13761370
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
13771371
flags.push(builder.config.cmd.rustc_args().join(" "));
13781372

src/tools/compiletest/src/common.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ pub struct Config {
269269
/// Flags to pass to the compiler when building for the target
270270
pub target_rustcflags: Option<String>,
271271

272-
/// Whether tests should be optimized.
273-
/// Currently only provides a default for UI-tests that are run-pass.
274-
/// Other tests are controlled by rustcflags or the testfiles themselves.
272+
/// Whether tests should be optimized by default. Individual test-suites and test files may
273+
/// override this setting.
275274
pub optimize_tests: bool,
276275

277276
/// What panic strategy the target is built with. Unwind supports Abort, but

src/tools/compiletest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
102102
)
103103
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
104104
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
105-
.optflag("", "optimize-tests", "build UI tests with optimization enabled")
105+
.optflag("", "optimize-tests", "run tests with optimizations enabled")
106106
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
107107
.optflag("", "verbose", "run tests verbosely, showing all output")
108108
.optflag(

src/tools/compiletest/src/runtest.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,31 @@ impl<'test> TestCx<'test> {
18621862
}
18631863
}
18641864

1865+
if self.config.optimize_tests && !is_rustdoc {
1866+
match self.config.mode {
1867+
Ui => {
1868+
// If optimize-tests is true we still only want to optimize tests that actually get
1869+
// executed and that don't specify their own optimization levels.
1870+
// Note: aux libs don't have a pass-mode, so they won't get optimized
1871+
// unless compile-flags are set in the aux file.
1872+
if self.config.optimize_tests
1873+
&& self.props.pass_mode(&self.config) == Some(PassMode::Run)
1874+
&& !self
1875+
.props
1876+
.compile_flags
1877+
.iter()
1878+
.any(|arg| arg == "-O" || arg.contains("opt-level"))
1879+
{
1880+
rustc.arg("-O");
1881+
}
1882+
}
1883+
DebugInfo => { /* debuginfo tests must be unoptimized */ }
1884+
_ => {
1885+
rustc.arg("-O");
1886+
}
1887+
}
1888+
}
1889+
18651890
match self.config.mode {
18661891
Incremental => {
18671892
// If we are extracting and matching errors in the new
@@ -1875,18 +1900,6 @@ impl<'test> TestCx<'test> {
18751900
rustc.arg("-Zdeduplicate-diagnostics=no");
18761901
}
18771902
Ui => {
1878-
// If optimize-tests is true we still only want to optimize tests that actually get
1879-
// executed and that don't specify their own optimization levels
1880-
if self.config.optimize_tests
1881-
&& self.props.pass_mode(&self.config) == Some(PassMode::Run)
1882-
&& !self
1883-
.props
1884-
.compile_flags
1885-
.iter()
1886-
.any(|arg| arg == "-O" || arg.contains("opt-level"))
1887-
{
1888-
rustc.arg("-O");
1889-
}
18901903
if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) {
18911904
rustc.args(&["--error-format", "json"]);
18921905
rustc.args(&["--json", "future-incompat"]);

0 commit comments

Comments
 (0)