Skip to content

Commit e29f129

Browse files
committed
Add a bootstrap setting and compiletest flag for --new-output-capture
1 parent 5d71a8a commit e29f129

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

bootstrap.example.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@
473473
# when the stage 0 compiler is actually built from in-tree sources.
474474
#build.compiletest-allow-stage0 = false
475475

476+
# Whether to enable or disable the new output-capture implementation in compiletest.
477+
# This setting will be removed when the "old" output-capture implementation is removed.
478+
#build.compiletest-new-output-capture = false
479+
476480
# Whether to use the precompiled stage0 libtest with compiletest.
477481
#build.compiletest-use-stage0-libtest = true
478482

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,10 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
19551955
if builder.config.cmd.no_capture() {
19561956
cmd.arg("--no-capture");
19571957
}
1958+
cmd.args([
1959+
"--new-output-capture",
1960+
if builder.build.config.compiletest_new_output_capture { "on" } else { "off" },
1961+
]);
19581962

19591963
let compare_mode =
19601964
builder.config.cmd.compare_mode().or_else(|| {

src/bootstrap/src/core/config/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ pub struct Config {
307307
/// sources.
308308
pub compiletest_allow_stage0: bool,
309309

310+
/// Whether to enable or disable the new output-capture implementation in compiletest.
311+
pub compiletest_new_output_capture: bool,
312+
310313
/// Whether to use the precompiled stage0 libtest with compiletest.
311314
pub compiletest_use_stage0_libtest: bool,
312315

@@ -479,6 +482,7 @@ impl Config {
479482
optimized_compiler_builtins: build_optimized_compiler_builtins,
480483
jobs: build_jobs,
481484
compiletest_diff_tool: build_compiletest_diff_tool,
485+
compiletest_new_output_capture: build_compiletest_new_output_capture,
482486
compiletest_use_stage0_libtest: build_compiletest_use_stage0_libtest,
483487
tidy_extra_checks: build_tidy_extra_checks,
484488
ccache: build_ccache,
@@ -1152,6 +1156,7 @@ impl Config {
11521156
compiler_docs: build_compiler_docs.unwrap_or(false),
11531157
compiletest_allow_stage0: build_compiletest_allow_stage0.unwrap_or(false),
11541158
compiletest_diff_tool: build_compiletest_diff_tool,
1159+
compiletest_new_output_capture: build_compiletest_new_output_capture.unwrap_or(false),
11551160
compiletest_use_stage0_libtest: build_compiletest_use_stage0_libtest.unwrap_or(true),
11561161
config: toml_path,
11571162
configure_args: build_configure_args.unwrap_or_default(),

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ define_config! {
6969
jobs: Option<u32> = "jobs",
7070
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
7171
compiletest_allow_stage0: Option<bool> = "compiletest-allow-stage0",
72+
compiletest_new_output_capture: Option<bool> = "compiletest-new-output-capture",
7273
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
7374
tidy_extra_checks: Option<String> = "tidy-extra-checks",
7475
ccache: Option<StringOrBool> = "ccache",

src/tools/compiletest/src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ pub struct Config {
667667
/// to avoid `!nocapture` double-negatives.
668668
pub nocapture: bool,
669669

670+
/// True if the experimental new output-capture implementation should be
671+
/// used, avoiding the need for `#![feature(internal_output_capture)]`.
672+
pub new_output_capture: bool,
673+
670674
/// Needed both to construct [`build_helper::git::GitConfig`].
671675
pub nightly_branch: String,
672676
pub git_merge_commit_email: String,
@@ -784,6 +788,7 @@ impl Config {
784788
builtin_cfg_names: Default::default(),
785789
supported_crate_types: Default::default(),
786790
nocapture: Default::default(),
791+
new_output_capture: Default::default(),
787792
nightly_branch: Default::default(),
788793
git_merge_commit_email: Default::default(),
789794
profiler_runtime: Default::default(),

src/tools/compiletest/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ pub fn parse_config(args: Vec<String>) -> Config {
178178
// FIXME: Temporarily retained so we can point users to `--no-capture`
179179
.optflag("", "nocapture", "")
180180
.optflag("", "no-capture", "don't capture stdout/stderr of tests")
181+
// New-output-capture needs to be `optmulti` so that the value passed
182+
// by bootstrap can be overridden explicitly if desired
183+
// (e.g. `x test ui -- --new-output-capture=on`).
184+
.optmulti(
185+
"N",
186+
"new-output-capture",
187+
"enables or disables the new output-capture implementation",
188+
"off|on",
189+
)
181190
.optflag("", "profiler-runtime", "is the profiler runtime enabled for this target")
182191
.optflag("h", "help", "show this message")
183192
.reqopt("", "channel", "current Rust channel", "CHANNEL")
@@ -462,6 +471,16 @@ pub fn parse_config(args: Vec<String>) -> Config {
462471
supported_crate_types: OnceLock::new(),
463472

464473
nocapture: matches.opt_present("no-capture"),
474+
new_output_capture: {
475+
// Ignore all but the last occurrence, so that an explicit override
476+
// (e.g. `x test ui -- --new-output-capture=on`) takes precedence
477+
// over whatever was passed by bootstrap.
478+
let values = matches.opt_strs("new-output-capture");
479+
// New-output-capture currently defaults to off.
480+
let value = values.last().map(String::as_str).unwrap_or("off");
481+
parse_bool_option(value)
482+
.unwrap_or_else(|| panic!("unknown `--new-output-capture` value `{value}` given"))
483+
},
465484

466485
nightly_branch: matches.opt_str("nightly-branch").unwrap(),
467486
git_merge_commit_email: matches.opt_str("git-merge-commit-email").unwrap(),
@@ -477,6 +496,14 @@ pub fn parse_config(args: Vec<String>) -> Config {
477496
}
478497
}
479498

499+
fn parse_bool_option(value: &str) -> Option<bool> {
500+
match value {
501+
"off" | "no" | "n" | "false" => Some(false),
502+
"on" | "yes" | "y" | "true" => Some(true),
503+
_ => None,
504+
}
505+
}
506+
480507
pub fn opt_str(maybestr: &Option<String>) -> &str {
481508
match *maybestr {
482509
None => "(none)",

0 commit comments

Comments
 (0)