Skip to content

Commit 4bbd21b

Browse files
authored
Rollup merge of #137683 - Kobzol:tidy-gcc-submodule, r=GuillaumeGomez
Add a tidy check for GCC submodule version To make sure that it stays in sync with the required GCC version of the GCC codegen backend. The check should succeed on CI, although it will fail after #137660, until the next GCC sync. r? `@GuillaumeGomez`
2 parents 5c54aa7 + 796a9ee commit 4bbd21b

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/gcc

Submodule gcc updated 29018 files

src/tools/tidy/src/gcc_submodule.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Tidy check to ensure that the commit SHA of the `src/gcc` submodule is the same as the
2+
//! required GCC version of the GCC codegen backend.
3+
4+
use std::path::Path;
5+
use std::process::Command;
6+
7+
pub fn check(root_path: &Path, compiler_path: &Path, bad: &mut bool) {
8+
let cg_gcc_version_path = compiler_path.join("rustc_codegen_gcc/libgccjit.version");
9+
let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path)
10+
.expect(&format!("Cannot read GCC version from {}", cg_gcc_version_path.display()))
11+
.trim()
12+
.to_string();
13+
14+
let git_output = Command::new("git")
15+
.current_dir(root_path)
16+
.arg("submodule")
17+
.arg("status")
18+
// --cached asks for the version that is actually committed in the repository, not the one
19+
// that is currently checked out.
20+
.arg("--cached")
21+
.arg("src/gcc")
22+
.output()
23+
.expect("Cannot determine git SHA of the src/gcc checkout");
24+
25+
// This can return e.g.
26+
// -e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc
27+
// e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be)
28+
// +e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be)
29+
let git_output = String::from_utf8_lossy(&git_output.stdout)
30+
.trim()
31+
.split_whitespace()
32+
.next()
33+
.unwrap_or_default()
34+
.to_string();
35+
36+
// The SHA can start with + if the submodule is modified or - if it is not checked out.
37+
let gcc_submodule_sha = git_output.trim_start_matches(&['+', '-']);
38+
if gcc_submodule_sha != cg_gcc_version {
39+
*bad = true;
40+
eprintln!(
41+
r#"Commit SHA of the src/gcc submodule (`{gcc_submodule_sha}`) does not match the required GCC version of the GCC codegen backend (`{cg_gcc_version}`).
42+
Make sure to set the src/gcc submodule to commit {cg_gcc_version}.
43+
The GCC codegen backend commit is configured at {}."#,
44+
cg_gcc_version_path.display(),
45+
);
46+
}
47+
}

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub mod features;
7575
pub mod fluent_alphabetical;
7676
pub mod fluent_period;
7777
mod fluent_used;
78+
pub mod gcc_submodule;
7879
pub(crate) mod iter_header;
7980
pub mod known_bug;
8081
pub mod mir_opt_tests;

src/tools/tidy/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ fn main() {
116116
check!(fluent_alphabetical, &compiler_path, bless);
117117
check!(fluent_period, &compiler_path);
118118
check!(target_policy, &root_path);
119+
check!(gcc_submodule, &root_path, &compiler_path);
119120

120121
// Checks that only make sense for the std libs.
121122
check!(pal, &library_path);

0 commit comments

Comments
 (0)