Skip to content

Add a tidy check for GCC submodule version #137683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gcc
Submodule gcc updated 29018 files
47 changes: 47 additions & 0 deletions src/tools/tidy/src/gcc_submodule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Tidy check to ensure that the commit SHA of the `src/gcc` submodule is the same as the
//! required GCC version of the GCC codegen backend.

use std::path::Path;
use std::process::Command;

pub fn check(root_path: &Path, compiler_path: &Path, bad: &mut bool) {
let cg_gcc_version_path = compiler_path.join("rustc_codegen_gcc/libgccjit.version");
let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path)
.expect(&format!("Cannot read GCC version from {}", cg_gcc_version_path.display()))
.trim()
.to_string();
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path)
.expect(&format!("Cannot read GCC version from {}", cg_gcc_version_path.display()))
.trim()
.to_string();
let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path)
.expect(&format!("Cannot read GCC version from {}", cg_gcc_version_path.display()));
let cg_gcc_version = cg_gcc_version.trim();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The to_string allocation doesn't matter here, so I would rather just keep the original.


let git_output = Command::new("git")
.current_dir(root_path)
.arg("submodule")
.arg("status")
// --cached asks for the version that is actually committed in the repository, not the one
// that is currently checked out.
.arg("--cached")
.arg("src/gcc")
.output()
.expect("Cannot determine git SHA of the src/gcc checkout");

// This can return e.g.
// -e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc
// e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be)
// +e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be)
let git_output = String::from_utf8_lossy(&git_output.stdout)
.trim()
.split_whitespace()
.next()
.unwrap_or_default()
.to_string();

// The SHA can start with + if the submodule is modified or - if it is not checked out.
let gcc_submodule_sha = git_output.trim_start_matches(&['+', '-']);
Comment on lines +29 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let git_output = String::from_utf8_lossy(&git_output.stdout)
.trim()
.split_whitespace()
.next()
.unwrap_or_default()
.to_string();
// The SHA can start with + if the submodule is modified or - if it is not checked out.
let gcc_submodule_sha = git_output.trim_start_matches(&['+', '-']);
let git_output = String::from_utf8_lossy(&git_output.stdout);
let gcc_submodule_sha = git_output
.trim()
.split_whitespace()
.next()
.and_then(|sha| sha.strip_prefix(['+','-']))
.unwrap_or_default();

if gcc_submodule_sha != cg_gcc_version {
*bad = true;
eprintln!(
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}`).
Make sure to set the src/gcc submodule to commit {cg_gcc_version}.
The GCC codegen backend commit is configured at {}."#,
cg_gcc_version_path.display(),
);
}
}
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub mod features;
pub mod fluent_alphabetical;
pub mod fluent_period;
mod fluent_used;
pub mod gcc_submodule;
pub(crate) mod iter_header;
pub mod known_bug;
pub mod mir_opt_tests;
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn main() {
check!(fluent_alphabetical, &compiler_path, bless);
check!(fluent_period, &compiler_path);
check!(target_policy, &root_path);
check!(gcc_submodule, &root_path, &compiler_path);

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