Skip to content

Commit 635963f

Browse files
committed
Refactor change detection for rustdoc and download-rustc
1 parent 6f4ae0f commit 635963f

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
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)]
@@ -585,20 +585,11 @@ 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![
589+
builder.config.src.join("src/librustdoc"),
590+
builder.config.src.join("src/tools/rustdoc"),
591+
];
592+
let has_changes = builder.config.check_for_changes(&dirs, &commit);
602593
if !has_changes {
603594
let precompiled_rustdoc = builder
604595
.config

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,13 +2763,9 @@ impl Config {
27632763
}
27642764

27652765
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2766-
let has_changes = !t!(helpers::git(Some(&self.src))
2767-
.args(["diff-index", "--quiet", &commit])
2768-
.arg("--")
2769-
.args([self.src.join("compiler"), self.src.join("library")])
2770-
.as_command_mut()
2771-
.status())
2772-
.success();
2766+
let dirs = vec![self.src.join("compiler"), self.src.join("library")];
2767+
let has_changes = self.check_for_changes(&dirs, &commit);
2768+
27732769
if has_changes {
27742770
if if_unchanged {
27752771
if self.is_verbose() {
@@ -2884,6 +2880,20 @@ impl Config {
28842880

28852881
Some(commit.to_string())
28862882
}
2883+
2884+
/// Check for changes in specified directories since a given commit.
2885+
/// Returns true if changes exist, false if no changes
2886+
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool {
2887+
let mut git = helpers::git(Some(&self.src));
2888+
git.args(["diff-index", "--quiet", commit]);
2889+
if !dirs.is_empty() {
2890+
git.arg("--");
2891+
for dir in dirs {
2892+
git.arg(dir);
2893+
}
2894+
}
2895+
!t!(git.as_command_mut().status()).success()
2896+
}
28872897
}
28882898

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

0 commit comments

Comments
 (0)