Skip to content

Commit ac8a7d1

Browse files
committed
Refactor change detection for rustdoc and download-rustc
1 parent 6a3c45e commit ac8a7d1

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)]
@@ -585,20 +585,8 @@ impl Step for Rustdoc {
585585
)
586586
.unwrap();
587587

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

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

+18-9
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ impl Config {
24212421

24222422
let disable_ci_rustc_if_incompatible =
24232423
env::var_os("DISABLE_CI_RUSTC_IF_INCOMPATIBLE")
2424-
.is_some_and(|s| s == "1" || s == "true");
2424+
.is_some_and(|s| s == "1" || s == "true");
24252425

24262426
if disable_ci_rustc_if_incompatible && res.is_err() {
24272427
println!("WARNING: download-rustc is disabled with `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` env.");
@@ -2733,14 +2733,9 @@ impl Config {
27332733
crate::exit!(1);
27342734
}
27352735

2736-
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2737-
let has_changes = !t!(helpers::git(Some(&self.src))
2738-
.args(["diff-index", "--quiet", &commit])
2739-
.arg("--")
2740-
.args([self.src.join("compiler"), self.src.join("library")])
2741-
.as_command_mut()
2742-
.status())
2743-
.success();
2736+
let dirs = vec![PathBuf::from("compiler"), PathBuf::from("library")];
2737+
let has_changes = self.check_for_changes(&dirs, &commit);
2738+
27442739
if has_changes {
27452740
if if_unchanged {
27462741
if self.is_verbose() {
@@ -2855,6 +2850,20 @@ impl Config {
28552850

28562851
Some(commit.to_string())
28572852
}
2853+
2854+
/// Check for changes in specified directories since a given commit.
2855+
/// Returns true if changes exist, false if no changes
2856+
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool {
2857+
let mut git = helpers::git(Some(&self.src));
2858+
git.args(["diff-index", "--quiet", commit]);
2859+
if !dirs.is_empty() {
2860+
git.arg("--");
2861+
for dir in dirs {
2862+
git.arg(self.src.join(dir));
2863+
}
2864+
}
2865+
!t!(git.as_command_mut().status()).success()
2866+
}
28582867
}
28592868

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

0 commit comments

Comments
 (0)