From 94e9c4cd64f9f30e46be5a149f90205d7096c104 Mon Sep 17 00:00:00 2001 From: binarycat Date: Sun, 25 Aug 2024 13:25:27 -0400 Subject: [PATCH 1/3] warn the user if the upstream master branch is old fixes https://github.com/rust-lang/rust/issues/129528 --- src/bootstrap/src/core/build_steps/format.rs | 5 +-- src/tools/build_helper/src/git.rs | 34 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs index 8c52df78ab6..1e78583476a 100644 --- a/src/bootstrap/src/core/build_steps/format.rs +++ b/src/bootstrap/src/core/build_steps/format.rs @@ -7,7 +7,7 @@ use std::sync::Mutex; use build_helper::ci::CiEnv; -use build_helper::git::get_git_modified_files; +use build_helper::git::{get_git_modified_files, warn_old_master_branch}; use ignore::WalkBuilder; use crate::core::builder::Builder; @@ -93,7 +93,8 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result>, Str if !verify_rustfmt_version(build) { return Ok(None); } - + warn_old_master_branch(&build.config.git_config(), &build.config.src) + .map_err(|e| e.to_string())?; get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"]) } diff --git a/src/tools/build_helper/src/git.rs b/src/tools/build_helper/src/git.rs index da84569c778..cc48a8964a3 100644 --- a/src/tools/build_helper/src/git.rs +++ b/src/tools/build_helper/src/git.rs @@ -159,3 +159,37 @@ pub fn get_git_untracked_files( .collect(); Ok(Some(files)) } + +/// Print a warning if the branch returned from `updated_master_branch` is old +/// +/// For certain configurations of git repository, this remote will not be +/// updated when running `git pull`. +/// +/// This can result in formatting thousands of files instead of a dozen, +/// so we should warn the user something is wrong. +pub fn warn_old_master_branch( + config: &GitConfig<'_>, + git_dir: &Path, +) -> Result<(), Box> { + use std::time::Duration; + const WARN_AFTER: Duration = Duration::from_secs(60 * 60 * 24 * 10); + let updated_master = updated_master_branch(config, Some(git_dir))?; + let branch_path = git_dir.join(".git/refs/remotes").join(&updated_master); + match std::fs::metadata(branch_path) { + Ok(meta) => { + if meta.modified()?.elapsed()? > WARN_AFTER { + eprintln!("warning: {updated_master} has not been updated in 10 days"); + } else { + return Ok(()); + } + } + Err(err) => { + eprintln!("warning: unable to check if {updated_master} is old due to error: {err}") + } + } + eprintln!( + "warning: {updated_master} is used to determine if files have been modified\n\ + warning: if it is not updated, this may cause files to be needlessly reformatted" + ); + Ok(()) +} From cea707d96033d5e14d3c2b287b0bedd2847db680 Mon Sep 17 00:00:00 2001 From: binarycat Date: Tue, 27 Aug 2024 16:31:40 -0400 Subject: [PATCH 2/3] emit old upstream warning no matter the build step --- src/bootstrap/src/core/build_steps/format.rs | 4 +--- src/bootstrap/src/core/sanity.rs | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs index 1e78583476a..91fbc57429a 100644 --- a/src/bootstrap/src/core/build_steps/format.rs +++ b/src/bootstrap/src/core/build_steps/format.rs @@ -7,7 +7,7 @@ use std::sync::Mutex; use build_helper::ci::CiEnv; -use build_helper::git::{get_git_modified_files, warn_old_master_branch}; +use build_helper::git::get_git_modified_files; use ignore::WalkBuilder; use crate::core::builder::Builder; @@ -93,8 +93,6 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result>, Str if !verify_rustfmt_version(build) { return Ok(None); } - warn_old_master_branch(&build.config.git_config(), &build.config.src) - .map_err(|e| e.to_string())?; get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"]) } diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index c42d4c56c38..37b88ca4fa5 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -15,6 +15,8 @@ use std::path::PathBuf; use std::{env, fs}; +use build_helper::git::warn_old_master_branch; + #[cfg(not(feature = "bootstrap-self-test"))] use crate::builder::Builder; use crate::builder::Kind; @@ -379,4 +381,8 @@ pub fn check(build: &mut Build) { if let Some(ref s) = build.config.ccache { cmd_finder.must_have(s); } + + warn_old_master_branch(&build.config.git_config(), &build.config.src) + .map_err(|e| e.to_string()) + .unwrap(); } From 3743cdb0e2d93f61c934c8fc73aa13dc8e9b8ab1 Mon Sep 17 00:00:00 2001 From: binarycat Date: Tue, 27 Aug 2024 19:15:46 -0400 Subject: [PATCH 3/3] downgrade git error to a warning, and skip UX check in CI --- src/bootstrap/src/core/sanity.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 37b88ca4fa5..cb076624820 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -382,7 +382,13 @@ pub fn check(build: &mut Build) { cmd_finder.must_have(s); } - warn_old_master_branch(&build.config.git_config(), &build.config.src) - .map_err(|e| e.to_string()) - .unwrap(); + // this warning is useless in CI, + // and CI probably won't have the right branches anyway. + if !build_helper::ci::CiEnv::is_ci() { + if let Err(e) = warn_old_master_branch(&build.config.git_config(), &build.config.src) + .map_err(|e| e.to_string()) + { + eprintln!("unable to check if upstream branch is old: {e}"); + } + } }