|
| 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 | +} |
0 commit comments