Skip to content

Commit da6754f

Browse files
committed
Refactor change detection for rustdoc and download-rustc
1 parent 7608018 commit da6754f

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

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

+7-16
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,21 +585,12 @@ 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-
602-
if !has_changes {
588+
let dirs = vec![
589+
PathBuf::from("src/librustdoc"),
590+
PathBuf::from("src/tools/rustdoc"),
591+
];
592+
593+
if let Some(false) = builder.config.check_for_changes(&dirs, &commit, "rustdoc", true) {
603594
let precompiled_rustdoc = builder
604595
.config
605596
.ci_rustc_dir()

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

+46-23
Original file line numberDiff line numberDiff line change
@@ -2725,31 +2725,18 @@ 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();
2736-
if has_changes {
2737-
if if_unchanged {
2738-
if self.verbose > 0 {
2739-
println!(
2740-
"WARNING: saw changes to compiler/ or library/ since {commit}; \
2741-
ignoring `download-rustc`"
2742-
);
2743-
}
2744-
return None;
2728+
let dirs = vec![PathBuf::from("compiler"), PathBuf::from("library")];
2729+
match self.check_for_changes(&dirs, &commit, "download-rustc", if_unchanged) {
2730+
Some(true) => {
2731+
println!(
2732+
"WARNING: `download-rustc` is enabled, but there are changes to \
2733+
compiler/ or library/"
2734+
);
2735+
Some(commit.to_string())
27452736
}
2746-
println!(
2747-
"WARNING: `download-rustc` is enabled, but there are changes to \
2748-
compiler/ or library/"
2749-
);
2737+
Some(false) => Some(commit.to_string()),
2738+
None => None,
27502739
}
2751-
2752-
Some(commit.to_string())
27532740
}
27542741

27552742
fn parse_download_ci_llvm(
@@ -2847,6 +2834,42 @@ impl Config {
28472834

28482835
Some(commit.to_string())
28492836
}
2837+
2838+
/// Check for changes in specified directories since a given commit.
2839+
/// Returns Some(true) if changes exist, Some(false) if no changes, None if check should be ignored.
2840+
pub fn check_for_changes(
2841+
&self,
2842+
dirs: &[PathBuf],
2843+
commit: &str,
2844+
option_name: &str,
2845+
if_unchanged: bool,
2846+
) -> Option<bool> {
2847+
let mut git = helpers::git(Some(&self.src));
2848+
git.args(["diff-index", "--quiet", commit, "--"]);
2849+
2850+
for dir in dirs {
2851+
git.arg(self.src.join(dir));
2852+
}
2853+
2854+
let has_changes = !t!(git.as_command_mut().status()).success();
2855+
2856+
if has_changes {
2857+
if if_unchanged {
2858+
if self.verbose > 0 {
2859+
println!(
2860+
"WARNING: saw changes to one of {:?} since {}; \
2861+
ignoring `{}`",
2862+
dirs, commit, option_name
2863+
);
2864+
}
2865+
None
2866+
} else {
2867+
Some(true)
2868+
}
2869+
} else {
2870+
Some(false)
2871+
}
2872+
}
28502873
}
28512874

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

0 commit comments

Comments
 (0)