Skip to content

Commit 46d98ba

Browse files
committed
Refactor change detection for rustdoc and download-rustc
1 parent f6648f2 commit 46d98ba

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

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

Lines changed: 6 additions & 15 deletions
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)]
@@ -602,20 +602,11 @@ impl Step for Rustdoc {
602602
)
603603
.unwrap();
604604

605-
let librustdoc_src = builder.config.src.join("src/librustdoc");
606-
let rustdoc_src = builder.config.src.join("src/tools/rustdoc");
607-
608-
// FIXME: The change detection logic here is quite similar to `Config::download_ci_rustc_commit`.
609-
// It would be better to unify them.
610-
let has_changes = !git(Some(&builder.config.src))
611-
.allow_failure()
612-
.run_always()
613-
.args(["diff-index", "--quiet", &commit])
614-
.arg("--")
615-
.arg(librustdoc_src)
616-
.arg(rustdoc_src)
617-
.run(builder);
618-
605+
let dirs = vec![
606+
builder.config.src.join("src/librustdoc"),
607+
builder.config.src.join("src/tools/rustdoc"),
608+
];
609+
let has_changes = builder.config.check_for_changes(&dirs, &commit);
619610
if !has_changes {
620611
let precompiled_rustdoc = builder
621612
.config

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,20 @@ impl Config {
29032903

29042904
Some(commit.to_string())
29052905
}
2906+
2907+
/// Check for changes in specified directories since a given commit.
2908+
/// Returns true if changes exist, false if no changes
2909+
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool {
2910+
let mut git = helpers::git(Some(&self.src));
2911+
git.args(["diff-index", "--quiet", commit]);
2912+
if !dirs.is_empty() {
2913+
git.arg("--");
2914+
for dir in dirs {
2915+
git.arg(dir);
2916+
}
2917+
}
2918+
!t!(git.as_command_mut().status()).success()
2919+
}
29062920
}
29072921

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

0 commit comments

Comments
 (0)