Skip to content

Commit 57c439e

Browse files
committed
Refactor change detection for rustdoc and download-rustc
1 parent c87004a commit 57c439e

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/bootstrap/src/core/build_steps/tool.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun,
1010
use crate::core::config::TargetSelection;
1111
use crate::utils::channel::GitInfo;
1212
use crate::utils::exec::{BootstrapCommand, command};
13-
use crate::utils::helpers::{add_dylib_path, exe, git, t};
13+
use crate::utils::helpers::{add_dylib_path, exe, t};
1414
use crate::{Compiler, Kind, Mode, gha};
1515

1616
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -582,20 +582,8 @@ impl Step for Rustdoc {
582582
)
583583
.unwrap();
584584

585-
let librustdoc_src = builder.config.src.join("src/librustdoc");
586-
let rustdoc_src = builder.config.src.join("src/tools/rustdoc");
587-
588-
// FIXME: The change detection logic here is quite similar to `Config::download_ci_rustc_commit`.
589-
// It would be better to unify them.
590-
let has_changes = !git(Some(&builder.config.src))
591-
.allow_failure()
592-
.run_always()
593-
.args(["diff-index", "--quiet", &commit])
594-
.arg("--")
595-
.arg(librustdoc_src)
596-
.arg(rustdoc_src)
597-
.run(builder);
598-
585+
let dirs = vec![PathBuf::from("src/librustdoc"), PathBuf::from("src/tools/rustdoc")];
586+
let has_changes = builder.config.check_for_changes(&dirs, &commit);
599587
if !has_changes {
600588
let precompiled_rustdoc = builder
601589
.config

src/bootstrap/src/core/config/config.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ impl Config {
24132413

24142414
let disable_ci_rustc_if_incompatible =
24152415
env::var_os("DISABLE_CI_RUSTC_IF_INCOMPATIBLE")
2416-
.is_some_and(|s| s == "1" || s == "true");
2416+
.is_some_and(|s| s == "1" || s == "true");
24172417

24182418
if disable_ci_rustc_if_incompatible && res.is_err() {
24192419
println!("WARNING: download-rustc is disabled with `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` env.");
@@ -2725,14 +2725,9 @@ impl Config {
27252725
crate::exit!(1);
27262726
}
27272727

2728-
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2729-
let has_changes = !t!(helpers::git(Some(&self.src))
2730-
.args(["diff-index", "--quiet", &commit])
2731-
.arg("--")
2732-
.args([self.src.join("compiler"), self.src.join("library")])
2733-
.as_command_mut()
2734-
.status())
2735-
.success();
2728+
let dirs = vec![PathBuf::from("compiler"), PathBuf::from("library")];
2729+
let has_changes = self.check_for_changes(&dirs, &commit);
2730+
27362731
if has_changes {
27372732
if if_unchanged {
27382733
if self.is_verbose() {
@@ -2847,6 +2842,20 @@ impl Config {
28472842

28482843
Some(commit.to_string())
28492844
}
2845+
2846+
/// Check for changes in specified directories since a given commit.
2847+
/// Returns true if changes exist, false if no changes
2848+
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool {
2849+
let mut git = helpers::git(Some(&self.src));
2850+
git.args(["diff-index", "--quiet", commit]);
2851+
if !dirs.is_empty() {
2852+
git.arg("--");
2853+
for dir in dirs {
2854+
git.arg(self.src.join(dir));
2855+
}
2856+
}
2857+
!t!(git.as_command_mut().status()).success()
2858+
}
28502859
}
28512860

28522861
/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.

0 commit comments

Comments
 (0)