Skip to content

Commit d535af3

Browse files
committed
Add needs-git-hash header to compiletest
This header can be used for tests which check the output of `--version --verbose` commands.
1 parent 28d27fd commit d535af3

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

src/bootstrap/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
18041804

18051805
cmd.arg("--channel").arg(&builder.config.channel);
18061806

1807+
if !builder.config.ignore_git {
1808+
cmd.arg("--git-hash");
1809+
}
1810+
18071811
if let Some(commit) = builder.config.download_rustc_commit() {
18081812
cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
18091813
}

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ pub struct Config {
303303
/// The current Rust channel
304304
pub channel: String,
305305

306+
/// Whether adding git commit information such as the commit hash has been enabled for building
307+
pub git_hash: bool,
308+
306309
/// The default Rust edition
307310
pub edition: Option<String>,
308311

src/tools/compiletest/src/header/needs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ pub(super) fn handle_needs(
115115
condition: cache.x86_64_dlltool,
116116
ignore_reason: "ignored when dlltool for x86_64 is not present",
117117
},
118+
Need {
119+
name: "needs-git-hash",
120+
condition: config.git_hash,
121+
ignore_reason: "ignored when git hashes have been omitted for building",
122+
},
118123
];
119124

120125
let (name, comment) = match ln.split_once([':', ' ']) {

src/tools/compiletest/src/header/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ fn debugger() {
251251
assert!(check_ignore(&config, "// ignore-lldb"));
252252
}
253253

254+
#[test]
255+
fn git_hash() {
256+
let mut config = config();
257+
config.git_hash = false;
258+
assert!(check_ignore(&config, "// needs-git-hash"));
259+
260+
config.git_hash = true;
261+
assert!(!check_ignore(&config, "// needs-git-hash"));
262+
}
263+
254264
#[test]
255265
fn sanitizers() {
256266
let mut config = config();

src/tools/compiletest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
159159
.optflag("", "nocapture", "")
160160
.optflag("h", "help", "show this message")
161161
.reqopt("", "channel", "current Rust channel", "CHANNEL")
162+
.optflag("", "git-hash", "run tests which rely on commit version being compiled into the binaries")
162163
.optopt("", "edition", "default Rust edition", "EDITION");
163164

164165
let (argv0, args_) = args.split_first().unwrap();
@@ -302,6 +303,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
302303
rustfix_coverage: matches.opt_present("rustfix-coverage"),
303304
has_tidy,
304305
channel: matches.opt_str("channel").unwrap(),
306+
git_hash: matches.opt_present("git-hash"),
305307
edition: matches.opt_str("edition"),
306308

307309
cc: matches.opt_str("cc").unwrap(),

0 commit comments

Comments
 (0)