Add needs-git-hash header to compiletest

This header can be used for tests which check the output of `--version --verbose` commands.
This commit is contained in:
Erik Hofmayer 2023-04-06 22:48:52 +02:00
parent 28d27fd164
commit d535af3625
5 changed files with 24 additions and 0 deletions

View File

@ -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}"));
}

View File

@ -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<String>,

View File

@ -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([':', ' ']) {

View File

@ -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();

View File

@ -159,6 +159,7 @@ pub fn parse_config(args: Vec<String>) -> 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(),