From d535af36258f81e542d963aac49ed2f9e5323dcd Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Thu, 6 Apr 2023 22:48:52 +0200 Subject: [PATCH] Add needs-git-hash header to compiletest This header can be used for tests which check the output of `--version --verbose` commands. --- src/bootstrap/test.rs | 4 ++++ src/tools/compiletest/src/common.rs | 3 +++ src/tools/compiletest/src/header/needs.rs | 5 +++++ src/tools/compiletest/src/header/tests.rs | 10 ++++++++++ src/tools/compiletest/src/main.rs | 2 ++ 5 files changed, 24 insertions(+) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index aedf1ecab13..cbdacfc5f80 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1804,6 +1804,10 @@ fn run(self, builder: &Builder<'_>) { cmd.arg("--channel").arg(&builder.config.channel); + if !builder.config.ignore_git { + cmd.arg("--git-hash"); + } + if let Some(commit) = builder.config.download_rustc_commit() { cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}")); } diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index d2f494942cf..3f36cc5bbcc 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -303,6 +303,9 @@ pub struct Config { /// The current Rust channel pub channel: String, + /// Whether adding git commit information such as the commit hash has been enabled for building + pub git_hash: bool, + /// The default Rust edition pub edition: Option, diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index 35d6179abaa..81179480ed8 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -115,6 +115,11 @@ pub(super) fn handle_needs( condition: cache.x86_64_dlltool, ignore_reason: "ignored when dlltool for x86_64 is not present", }, + Need { + name: "needs-git-hash", + condition: config.git_hash, + ignore_reason: "ignored when git hashes have been omitted for building", + }, ]; let (name, comment) = match ln.split_once([':', ' ']) { diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 9af7bd5e201..362fba11697 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -251,6 +251,16 @@ fn debugger() { assert!(check_ignore(&config, "// ignore-lldb")); } +#[test] +fn git_hash() { + let mut config = config(); + config.git_hash = false; + assert!(check_ignore(&config, "// needs-git-hash")); + + config.git_hash = true; + assert!(!check_ignore(&config, "// needs-git-hash")); +} + #[test] fn sanitizers() { let mut config = config(); diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 4a2b9de8aee..c4bef998f31 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -159,6 +159,7 @@ pub fn parse_config(args: Vec) -> Config { .optflag("", "nocapture", "") .optflag("h", "help", "show this message") .reqopt("", "channel", "current Rust channel", "CHANNEL") + .optflag("", "git-hash", "run tests which rely on commit version being compiled into the binaries") .optopt("", "edition", "default Rust edition", "EDITION"); let (argv0, args_) = args.split_first().unwrap(); @@ -302,6 +303,7 @@ fn make_absolute(path: PathBuf) -> PathBuf { rustfix_coverage: matches.opt_present("rustfix-coverage"), has_tidy, channel: matches.opt_str("channel").unwrap(), + git_hash: matches.opt_present("git-hash"), edition: matches.opt_str("edition"), cc: matches.opt_str("cc").unwrap(),