Skip to content

Commit 7823503

Browse files
committed
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.
1 parent 2af87ea commit 7823503

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

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
@@ -117,6 +117,7 @@ fn main() {
117117
check!(fluent_alphabetical, &compiler_path, bless);
118118
check!(fluent_period, &compiler_path);
119119
check!(target_policy, &root_path);
120+
check!(gcc_submodule, &root_path, &compiler_path);
120121

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

0 commit comments

Comments
 (0)