From cbab16feafcd828c813a1c4926eade67f464cff9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 25 Apr 2024 08:55:39 +0000 Subject: [PATCH 1/2] Test RUSTC_OVERRIDE_VERSION_STRING --- src/tools/compiletest/src/header.rs | 1 + tests/ui/feature-gates/version_check.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/ui/feature-gates/version_check.rs diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 0208ed34ac182..cde3e3295c631 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -330,6 +330,7 @@ impl TestProps { pub fn from_file(testfile: &Path, revision: Option<&str>, config: &Config) -> Self { let mut props = TestProps::new(); props.load_from(testfile, revision, config); + props.exec_env.push(("RUSTC".to_string(), config.rustc_path.display().to_string())); match (props.pass_mode, props.fail_mode) { (None, None) if config.mode == Mode::Ui => props.fail_mode = Some(FailMode::Check), diff --git a/tests/ui/feature-gates/version_check.rs b/tests/ui/feature-gates/version_check.rs new file mode 100644 index 0000000000000..093fda3fbe570 --- /dev/null +++ b/tests/ui/feature-gates/version_check.rs @@ -0,0 +1,17 @@ +//@ run-pass +//@ only-linux +//@ only-x86 +// FIXME: this should be more like //@ needs-subprocesses +use std::process::Command; + +fn main() { + let signalled_version = "Ceci n'est pas une rustc"; + let version = Command::new(std::env::var_os("RUSTC").unwrap()) + .env("RUSTC_OVERRIDE_VERSION_STRING", signalled_version) + .arg("--version") + .output() + .unwrap() + .stdout; + let version = std::str::from_utf8(&version).unwrap().strip_prefix("rustc ").unwrap().trim_end(); + assert_ne!(version, signalled_version); +} From 92f263b7926537d086bcb6bfac33fe2b93e44aa1 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 25 Apr 2024 15:29:51 +0000 Subject: [PATCH 2/2] Make RUSTC_OVERRIDE_VERSION_STRING overwrite the rendered version output, too --- compiler/rustc_driver_impl/src/lib.rs | 9 +++++++++ tests/ui/feature-gates/version_check.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index d9633d69f1d45..627a0ebb4e5e3 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -909,6 +909,15 @@ pub fn version_at_macro_invocation( ) { let verbose = matches.opt_present("verbose"); + let mut version = version; + let mut release = release; + let tmp; + if let Ok(force_version) = std::env::var("RUSTC_OVERRIDE_VERSION_STRING") { + tmp = force_version; + version = &tmp; + release = &tmp; + } + safe_println!("{binary} {version}"); if verbose { diff --git a/tests/ui/feature-gates/version_check.rs b/tests/ui/feature-gates/version_check.rs index 093fda3fbe570..e212dc74fd123 100644 --- a/tests/ui/feature-gates/version_check.rs +++ b/tests/ui/feature-gates/version_check.rs @@ -13,5 +13,5 @@ fn main() { .unwrap() .stdout; let version = std::str::from_utf8(&version).unwrap().strip_prefix("rustc ").unwrap().trim_end(); - assert_ne!(version, signalled_version); + assert_eq!(version, signalled_version); }