From 1f5320e57bae9d2fd4cfa5bbad0c59651e356ee7 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Fri, 21 Mar 2025 22:27:13 +0100 Subject: Unify usages of path modifications and log them in verbose mode --- src/bootstrap/src/core/build_steps/gcc.rs | 31 ++++++++++-------------------- src/bootstrap/src/core/build_steps/llvm.rs | 26 ++++++------------------- src/bootstrap/src/core/config/config.rs | 11 ++++++++--- src/bootstrap/src/core/config/tests.rs | 2 +- src/bootstrap/src/core/download.rs | 22 ++++++++++++--------- 5 files changed, 38 insertions(+), 54 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs index 94abbb35ac5..339eec18406 100644 --- a/src/bootstrap/src/core/build_steps/gcc.rs +++ b/src/bootstrap/src/core/build_steps/gcc.rs @@ -110,6 +110,9 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option { // Download from upstream CI @@ -285,31 +288,17 @@ fn ci_gcc_root(config: &crate::Config) -> PathBuf { /// Detect whether GCC sources have been modified locally or not. #[cfg(not(test))] fn detect_gcc_freshness(config: &crate::Config, is_git: bool) -> build_helper::git::PathFreshness { - use build_helper::git::{PathFreshness, check_path_modifications}; - - let freshness = if is_git { - Some( - check_path_modifications( - Some(&config.src), - &config.git_config(), - &["src/gcc", "src/bootstrap/download-ci-gcc-stamp"], - config.ci_env(), - ) - .unwrap(), - ) + use build_helper::git::PathFreshness; + + if is_git { + config.check_path_modifications(&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"]) } else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) { - Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }) + PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() } } else { - None - }; - - let Some(freshness) = freshness else { eprintln!("error: could not find commit hash for downloading GCC"); eprintln!("HELP: maybe your repository history is too shallow?"); eprintln!("HELP: consider disabling `download-ci-gcc`"); eprintln!("HELP: or fetch enough history to include one upstream commit"); - panic!(); - }; - - freshness + crate::exit!(1); + } } diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 6e695ee1e7c..1a6247c42d7 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -14,7 +14,7 @@ use std::path::{Path, PathBuf}; use std::sync::OnceLock; use std::{env, fs}; -use build_helper::git::{PathFreshness, check_path_modifications}; +use build_helper::git::PathFreshness; #[cfg(feature = "tracing")] use tracing::instrument; @@ -183,31 +183,17 @@ pub const LLVM_INVALIDATION_PATHS: &[&str] = &[ /// Detect whether LLVM sources have been modified locally or not. pub(crate) fn detect_llvm_freshness(config: &Config, is_git: bool) -> PathFreshness { - let freshness = if is_git { - Some( - check_path_modifications( - Some(&config.src), - &config.git_config(), - LLVM_INVALIDATION_PATHS, - config.ci_env(), - ) - .unwrap(), - ) + if is_git { + config.check_path_modifications(LLVM_INVALIDATION_PATHS) } else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) { - Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }) + PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() } } else { - None - }; - - let Some(freshness) = freshness else { eprintln!("error: could not find commit hash for downloading LLVM"); eprintln!("HELP: maybe your repository history is too shallow?"); eprintln!("HELP: consider disabling `download-ci-llvm`"); eprintln!("HELP: or fetch enough history to include one upstream commit"); - panic!(); - }; - - freshness + crate::exit!(1); + } } /// Returns whether the CI-found LLVM is currently usable. diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index a2d13cffbff..be9afba454e 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -3193,7 +3193,11 @@ impl Config { let commit = if self.rust_info.is_managed_git_subrepository() { // Look for a version to compare to based on the current commit. // Only commits merged by bors will have CI artifacts. - match self.check_modifications(&allowed_paths) { + let freshness = self.check_path_modifications(&allowed_paths); + self.verbose(|| { + eprintln!("rustc freshness: {freshness:?}"); + }); + match freshness { PathFreshness::LastModifiedUpstream { upstream } => upstream, PathFreshness::HasLocalModifications { upstream } => { if if_unchanged { @@ -3291,13 +3295,14 @@ impl Config { /// Returns true if any of the `paths` have been modified locally. pub fn has_changes_from_upstream(&self, paths: &[&str]) -> bool { - match self.check_modifications(paths) { + match self.check_path_modifications(paths) { PathFreshness::LastModifiedUpstream { .. } => false, PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true, } } - fn check_modifications(&self, paths: &[&str]) -> PathFreshness { + /// Checks whether any of the given paths have been modified w.r.t. upstream. + pub fn check_path_modifications(&self, paths: &[&str]) -> PathFreshness { check_path_modifications(Some(&self.src), &self.git_config(), paths, CiEnv::current()) .unwrap() } diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index ee345595ce3..affabd49720 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -51,7 +51,7 @@ fn download_ci_llvm() { let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\""); if if_unchanged_config.llvm_from_ci && if_unchanged_config.is_running_on_ci { - let has_changes = if_unchanged_config.has_changes_from_upstream(&["src/llvm-project"]); + let has_changes = if_unchanged_config.has_changes_from_upstream(LLVM_INVALIDATION_PATHS); assert!( !has_changes, diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 0051b874729..57a674c1dd7 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -730,15 +730,19 @@ download-rustc = false } let llvm_root = self.ci_llvm_root(); - let llvm_sha = - match detect_llvm_freshness(self, self.rust_info.is_managed_git_subrepository()) { - PathFreshness::LastModifiedUpstream { upstream } => upstream, - PathFreshness::HasLocalModifications { upstream } => upstream, - PathFreshness::MissingUpstream => { - eprintln!("No upstream commit for downloading LLVM found"); - crate::exit!(1); - } - }; + let llvm_freshness = + detect_llvm_freshness(self, self.rust_info.is_managed_git_subrepository()); + self.verbose(|| { + eprintln!("LLVM freshness: {llvm_freshness:?}"); + }); + let llvm_sha = match llvm_freshness { + PathFreshness::LastModifiedUpstream { upstream } => upstream, + PathFreshness::HasLocalModifications { upstream } => upstream, + PathFreshness::MissingUpstream => { + eprintln!("No upstream commit for downloading LLVM found"); + crate::exit!(1); + } + }; let stamp_key = format!("{}{}", llvm_sha, self.llvm_assertions); let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm").add_stamp(stamp_key); if !llvm_stamp.is_up_to_date() && !self.dry_run() { -- cgit 1.4.1-3-g733a5