Skip to content

Commit 0eb5efc

Browse files
committed
Auto merge of #113298 - tgross35:update-bless-envs, r=oli-obk
Unite bless environment variables under `RUST_BLESS` Currently, Clippy and Miri both use an environment variable to indicate that output should be blessed, but they use different variable names. In order to improve consistency, this patch applies the following changes: - Rename the variable `MIRI_BLESS` (as used in the Miri subtree) to `RUST_BLESS` - Rename the variable `BLESS` (as used in the Clippy subtree) to `RUST_BLESS` - Move emitting `RUST_BLESS` into `prepare_cargo_test` so it is always available (I need this for a WIP PR) --- I prefer something like `RUST_BLESS` to `BLESS` just for a lower chance of conflict (not super common but other tools [do use `BLESS`](https://grep.app/search?q=%22BLESS%22&case=true&words=true&filter[lang][0]=Text&filter[lang][1]=Rust&filter[lang][2]=Python&filter[lang][3]=C%2B%2B&filter[lang][4]=Markdown&filter[lang][5]=C&filter[lang][6]=JSON)), but I can change it to whatever is preferred. Original discussion: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/BLESS.20env.20var.3A.20rename.20to.20CLIPPY_BLESS r? `@oli-obk` cc `@flip1995`
2 parents 9339f44 + 9439e02 commit 0eb5efc

File tree

8 files changed

+22
-31
lines changed

8 files changed

+22
-31
lines changed

compiler/rustc_errors/src/markdown/tests/term.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn test_wrapping_write() {
6363
#[test]
6464
fn test_output() {
6565
// Capture `--bless` when run via ./x
66-
let bless = std::env::var("RUSTC_BLESS").unwrap_or_default() == "1";
66+
let bless = std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
6767
let ast = MdStream::parse_str(INPUT);
6868
let bufwtr = BufferWriter::stderr(ColorChoice::Always);
6969
let mut buffer = bufwtr.buffer();

src/bootstrap/test.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,6 @@ impl Step for Rustfmt {
430430
&[],
431431
);
432432

433-
if builder.config.cmd.bless() {
434-
cargo.env("BLESS", "1");
435-
}
436-
437433
let dir = testdir(builder, compiler.host);
438434
t!(fs::create_dir_all(&dir));
439435
cargo.env("RUSTFMT_TEST_DIR", dir);
@@ -633,10 +629,6 @@ impl Step for Miri {
633629
cargo.env("MIRI_SYSROOT", &miri_sysroot);
634630
cargo.env("MIRI_HOST_SYSROOT", sysroot);
635631
cargo.env("MIRI", &miri);
636-
// propagate --bless
637-
if builder.config.cmd.bless() {
638-
cargo.env("MIRI_BLESS", "Gesundheit");
639-
}
640632

641633
// Set the target.
642634
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
@@ -654,8 +646,8 @@ impl Step for Miri {
654646
cargo.env("MIRIFLAGS", "-O -Zmir-opt-level=4 -Cdebug-assertions=yes");
655647
// Optimizations can change backtraces
656648
cargo.env("MIRI_SKIP_UI_CHECKS", "1");
657-
// `MIRI_SKIP_UI_CHECKS` and `MIRI_BLESS` are incompatible
658-
cargo.env_remove("MIRI_BLESS");
649+
// `MIRI_SKIP_UI_CHECKS` and `RUSTC_BLESS` are incompatible
650+
cargo.env_remove("RUSTC_BLESS");
659651
// Optimizations can change error locations and remove UB so don't run `fail` tests.
660652
cargo.args(&["tests/pass", "tests/panic"]);
661653

@@ -799,11 +791,6 @@ impl Step for Clippy {
799791
cargo.add_rustc_lib_path(builder, compiler);
800792
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
801793

802-
// propagate --bless
803-
if builder.config.cmd.bless() {
804-
cargo.env("BLESS", "Gesundheit");
805-
}
806-
807794
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
808795

809796
#[allow(deprecated)] // Clippy reports errors if it blessed the outputs
@@ -2245,9 +2232,11 @@ fn prepare_cargo_test(
22452232
) -> Command {
22462233
let mut cargo = cargo.into();
22472234

2248-
// If bless is passed, give downstream crates a way to use it
2249-
if builder.config.cmd.bless() {
2250-
cargo.env("RUSTC_BLESS", "1");
2235+
// Propegate `--bless` if it has not already been set/unset
2236+
// Any tools that want to use this should bless if `RUSTC_BLESS` is set to
2237+
// anything other than `0`.
2238+
if builder.config.cmd.bless() && !cargo.get_envs().any(|v| v.0 == "RUSTC_BLESS") {
2239+
cargo.env("RUSTC_BLESS", "Gesundheit");
22512240
}
22522241

22532242
// Pass in some standard flags then iterate over the graph we've discovered

src/tools/clippy/tests/compile-test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ fn base_config(test_dir: &str) -> compiletest::Config {
115115
mode: TestMode::Yolo,
116116
stderr_filters: vec![],
117117
stdout_filters: vec![],
118-
output_conflict_handling: if var_os("BLESS").is_some() || env::args().any(|arg| arg == "--bless") {
118+
// FIXME(tgross35): deduplicate bless env once clippy can update
119+
output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0")
120+
|| env::args().any(|arg| arg == "--bless") {
119121
compiletest::OutputConflictHandling::Bless
120122
} else {
121123
compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())

src/tools/miri/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ Moreover, Miri recognizes some environment variables:
482482
purpose.
483483
* `MIRI_NO_STD` (recognized by `cargo miri` and the test suite) makes sure that the target's
484484
sysroot is built without libstd. This allows testing and running no_std programs.
485-
* `MIRI_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
485+
* `RUSTC_BLESS` (recognized by the test suite and `cargo-miri-test/run-test.py`): overwrite all
486486
`stderr` and `stdout` files instead of checking whether the output matches.
487487
* `MIRI_SKIP_UI_CHECKS` (recognized by the test suite): don't check whether the
488488
`stderr` or `stdout` files match the actual output.

src/tools/miri/miri

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ test|bless)
303303
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
304304
find_sysroot
305305
if [ "$COMMAND" = "bless" ]; then
306-
export MIRI_BLESS="Gesundheit"
306+
export RUSTC_BLESS="Gesundheit"
307307
fi
308308
# Then test, and let caller control flags.
309309
# Only in root project as `cargo-miri` has no tests.

src/tools/miri/test-cargo-miri/run-test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import difflib
99
import os
1010
import re
11-
import sys
1211
import subprocess
12+
import sys
1313

1414
CGREEN = '\33[32m'
1515
CBOLD = '\33[1m'
@@ -37,7 +37,8 @@ def normalize_stderr(str):
3737
return str
3838

3939
def check_output(actual, path, name):
40-
if 'MIRI_BLESS' in os.environ:
40+
if os.environ.get("RUSTC_BLESS", "0") != "0":
41+
# Write the output only if bless is set
4142
open(path, mode='w').write(actual)
4243
return True
4344
expected = open(path).read()

src/tools/miri/tests/compiletest.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
7272
program.args.push(flag);
7373
}
7474

75+
let bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v !="0");
7576
let skip_ui_checks = env::var_os("MIRI_SKIP_UI_CHECKS").is_some();
7677

77-
let output_conflict_handling = match (env::var_os("MIRI_BLESS").is_some(), skip_ui_checks) {
78+
let output_conflict_handling = match (bless, skip_ui_checks) {
7879
(false, false) => OutputConflictHandling::Error("./miri bless".into()),
7980
(true, false) => OutputConflictHandling::Bless,
8081
(false, true) => OutputConflictHandling::Ignore,
81-
(true, true) => panic!("cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
82+
(true, true) => panic!("cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
8283
};
8384

8485
let mut config = Config {

src/tools/rustfmt/src/test/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,9 @@ fn handle_result(
838838

839839
// Ignore LF and CRLF difference for Windows.
840840
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
841-
if let Some(bless) = std::env::var_os("BLESS") {
842-
if bless != "0" {
843-
std::fs::write(file_name, fmt_text).unwrap();
844-
continue;
845-
}
841+
if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
842+
std::fs::write(file_name, fmt_text).unwrap();
843+
continue;
846844
}
847845
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
848846
assert!(

0 commit comments

Comments
 (0)