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`
This commit is contained in:
bors 2023-07-27 17:45:11 +00:00
commit 0eb5efc7ae
8 changed files with 22 additions and 31 deletions

View File

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

View File

@ -430,10 +430,6 @@ impl Step for Rustfmt {
&[],
);
if builder.config.cmd.bless() {
cargo.env("BLESS", "1");
}
let dir = testdir(builder, compiler.host);
t!(fs::create_dir_all(&dir));
cargo.env("RUSTFMT_TEST_DIR", dir);
@ -633,10 +629,6 @@ impl Step for Miri {
cargo.env("MIRI_SYSROOT", &miri_sysroot);
cargo.env("MIRI_HOST_SYSROOT", sysroot);
cargo.env("MIRI", &miri);
// propagate --bless
if builder.config.cmd.bless() {
cargo.env("MIRI_BLESS", "Gesundheit");
}
// Set the target.
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
@ -654,8 +646,8 @@ impl Step for Miri {
cargo.env("MIRIFLAGS", "-O -Zmir-opt-level=4 -Cdebug-assertions=yes");
// Optimizations can change backtraces
cargo.env("MIRI_SKIP_UI_CHECKS", "1");
// `MIRI_SKIP_UI_CHECKS` and `MIRI_BLESS` are incompatible
cargo.env_remove("MIRI_BLESS");
// `MIRI_SKIP_UI_CHECKS` and `RUSTC_BLESS` are incompatible
cargo.env_remove("RUSTC_BLESS");
// Optimizations can change error locations and remove UB so don't run `fail` tests.
cargo.args(&["tests/pass", "tests/panic"]);
@ -799,11 +791,6 @@ impl Step for Clippy {
cargo.add_rustc_lib_path(builder, compiler);
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
// propagate --bless
if builder.config.cmd.bless() {
cargo.env("BLESS", "Gesundheit");
}
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
#[allow(deprecated)] // Clippy reports errors if it blessed the outputs
@ -2245,9 +2232,11 @@ fn prepare_cargo_test(
) -> Command {
let mut cargo = cargo.into();
// If bless is passed, give downstream crates a way to use it
if builder.config.cmd.bless() {
cargo.env("RUSTC_BLESS", "1");
// Propegate `--bless` if it has not already been set/unset
// Any tools that want to use this should bless if `RUSTC_BLESS` is set to
// anything other than `0`.
if builder.config.cmd.bless() && !cargo.get_envs().any(|v| v.0 == "RUSTC_BLESS") {
cargo.env("RUSTC_BLESS", "Gesundheit");
}
// Pass in some standard flags then iterate over the graph we've discovered

View File

@ -115,7 +115,9 @@ fn base_config(test_dir: &str) -> compiletest::Config {
mode: TestMode::Yolo,
stderr_filters: vec![],
stdout_filters: vec![],
output_conflict_handling: if var_os("BLESS").is_some() || env::args().any(|arg| arg == "--bless") {
// FIXME(tgross35): deduplicate bless env once clippy can update
output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0")
|| env::args().any(|arg| arg == "--bless") {
compiletest::OutputConflictHandling::Bless
} else {
compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())

View File

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

View File

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

View File

@ -8,8 +8,8 @@ and the working directory to contain the cargo-miri-test project.
import difflib
import os
import re
import sys
import subprocess
import sys
CGREEN = '\33[32m'
CBOLD = '\33[1m'
@ -37,7 +37,8 @@ def normalize_stderr(str):
return str
def check_output(actual, path, name):
if 'MIRI_BLESS' in os.environ:
if os.environ.get("RUSTC_BLESS", "0") != "0":
# Write the output only if bless is set
open(path, mode='w').write(actual)
return True
expected = open(path).read()

View File

@ -72,13 +72,14 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
program.args.push(flag);
}
let bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v !="0");
let skip_ui_checks = env::var_os("MIRI_SKIP_UI_CHECKS").is_some();
let output_conflict_handling = match (env::var_os("MIRI_BLESS").is_some(), skip_ui_checks) {
let output_conflict_handling = match (bless, skip_ui_checks) {
(false, false) => OutputConflictHandling::Error("./miri bless".into()),
(true, false) => OutputConflictHandling::Bless,
(false, true) => OutputConflictHandling::Ignore,
(true, true) => panic!("cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
(true, true) => panic!("cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"),
};
let mut config = Config {

View File

@ -838,11 +838,9 @@ fn handle_result(
// Ignore LF and CRLF difference for Windows.
if !string_eq_ignore_newline_repr(&fmt_text, &text) {
if let Some(bless) = std::env::var_os("BLESS") {
if bless != "0" {
std::fs::write(file_name, fmt_text).unwrap();
continue;
}
if std::env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
std::fs::write(file_name, fmt_text).unwrap();
continue;
}
let diff = make_diff(&text, &fmt_text, DIFF_CONTEXT_SIZE);
assert!(