From 28d27fd1644b75a6bbd3f7ff85169cfd374e8022 Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Wed, 5 Apr 2023 21:37:15 +0200 Subject: [PATCH 1/6] Set git info env variables when building tools This should fix issue #107094. --- src/bootstrap/tool.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index d1fd2e8c42cb0..9736256f91122 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -319,6 +319,12 @@ pub fn prepare_tool_cargo( cargo.env("CFG_VERSION", builder.rust_version()); cargo.env("CFG_RELEASE_NUM", &builder.version); cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel()); + if let Some(ref ver_date) = builder.rust_info().commit_date() { + cargo.env("CFG_VER_DATE", ver_date); + } + if let Some(ref ver_hash) = builder.rust_info().sha() { + cargo.env("CFG_VER_HASH", ver_hash); + } let info = GitInfo::new(builder.config.omit_git_hash, &dir); if let Some(sha) = info.sha() { From d535af36258f81e542d963aac49ed2f9e5323dcd Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Thu, 6 Apr 2023 22:48:52 +0200 Subject: [PATCH 2/6] 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 aedf1ecab13c4..cbdacfc5f80be 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1804,6 +1804,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the 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 d2f494942cf9b..3f36cc5bbcc91 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 35d6179abaa6b..81179480ed810 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 9af7bd5e20145..362fba11697be 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 4a2b9de8aee6b..c4bef998f3171 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 @@ pub fn parse_config(args: Vec) -> Config { 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(), From 135e6201fc3dc61bcee1d4186f233570edbbbb8c Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Fri, 7 Apr 2023 19:45:37 +0200 Subject: [PATCH 3/6] Add regression test for issue 107094 --- tests/run-make/issue-107094/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 tests/run-make/issue-107094/Makefile diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile new file mode 100755 index 0000000000000..7bbaf31a7771d --- /dev/null +++ b/tests/run-make/issue-107094/Makefile @@ -0,0 +1,7 @@ +# needs-git-hash + +include ../tools.mk + +all: + $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" + $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" From 550df4d34b4398a232058641980c1a5619fe152e Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Fri, 7 Apr 2023 20:58:07 +0200 Subject: [PATCH 4/6] Change mode of Makefile of test for issue 107094 --- tests/run-make/issue-107094/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 tests/run-make/issue-107094/Makefile diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile old mode 100755 new mode 100644 From bfa87984d272f06b5a3af6ed3030dcdaa53d9cab Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Sun, 9 Apr 2023 12:27:41 +0200 Subject: [PATCH 5/6] Fix error due to renaming of ignore_git --- src/bootstrap/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index cbdacfc5f80be..3814dc63ed4dc 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1804,7 +1804,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the cmd.arg("--channel").arg(&builder.config.channel); - if !builder.config.ignore_git { + if !builder.config.omit_git_hash { cmd.arg("--git-hash"); } From 0a763c92f214501ccd0460fdddfbb49d21fe9b2e Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Mon, 17 Apr 2023 18:53:52 +0200 Subject: [PATCH 6/6] Make commit-date pattern more specific in test for issue 107094 --- tests/run-make/issue-107094/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile index 7bbaf31a7771d..d614e3e1055c0 100644 --- a/tests/run-make/issue-107094/Makefile +++ b/tests/run-make/issue-107094/Makefile @@ -3,5 +3,5 @@ include ../tools.mk all: - $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" - $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" + $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" + $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}"