Skip to content

Commit 578a8d8

Browse files
authored
Rollup merge of rust-lang#109981 - duckymirror:issue-107094, r=albertlarsan68
Set commit information environment variables when building tools This fixes rust-lang#107094. ~I'm trying to add a regression test for this issue.~ **Update**: I've added a test and a new test header `needs-git-hash` which makes sure it doesn't run when commit hashes are ignored (`bootstrap`'s `ignore-git` option).
2 parents 7f92747 + 0a763c9 commit 578a8d8

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-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.omit_git_hash {
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/bootstrap/tool.rs

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ pub fn prepare_tool_cargo(
194194
cargo.env("CFG_VERSION", builder.rust_version());
195195
cargo.env("CFG_RELEASE_NUM", &builder.version);
196196
cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
197+
if let Some(ref ver_date) = builder.rust_info().commit_date() {
198+
cargo.env("CFG_VER_DATE", ver_date);
199+
}
200+
if let Some(ref ver_hash) = builder.rust_info().sha() {
201+
cargo.env("CFG_VER_HASH", ver_hash);
202+
}
197203

198204
let info = GitInfo::new(builder.config.omit_git_hash, &dir);
199205
if let Some(sha) = info.sha() {

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(),

tests/run-make/issue-107094/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# needs-git-hash
2+
3+
include ../tools.mk
4+
5+
all:
6+
$(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}"
7+
$(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}"

0 commit comments

Comments
 (0)