Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cfc54ea

Browse files
committedOct 7, 2024··
Simplify check_for_changes function
1 parent 2919483 commit cfc54ea

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed
 

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ impl Step for Rustdoc {
583583
.unwrap();
584584

585585
let dirs = vec![PathBuf::from("src/librustdoc"), PathBuf::from("src/tools/rustdoc")];
586-
587-
if let Some(false) = builder.config.check_for_changes(&dirs, &commit, "rustdoc", true) {
586+
let has_changes = builder.config.check_for_changes(&dirs, &commit);
587+
if !has_changes {
588588
let precompiled_rustdoc = builder
589589
.config
590590
.ci_rustc_dir()

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

+20-37
Original file line numberDiff line numberDiff line change
@@ -2726,17 +2726,25 @@ impl Config {
27262726
}
27272727

27282728
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())
2729+
let has_changes = self.check_for_changes(&dirs, &commit);
2730+
2731+
if has_changes {
2732+
if if_unchanged {
2733+
if self.is_verbose() {
2734+
println!(
2735+
"WARNING: saw changes to compiler/ or library/ since {commit}; \
2736+
ignoring `download-rustc`"
2737+
);
2738+
}
2739+
return None;
27362740
}
2737-
Some(false) => Some(commit.to_string()),
2738-
None => None,
2741+
println!(
2742+
"WARNING: `download-rustc` is enabled, but there are changes to \
2743+
compiler/ or library/"
2744+
);
27392745
}
2746+
2747+
Some(commit.to_string())
27402748
}
27412749

27422750
fn parse_download_ci_llvm(
@@ -2836,42 +2844,17 @@ impl Config {
28362844
}
28372845

28382846
/// 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+
/// Returns true if changes exist, false if no changes
2848+
pub fn check_for_changes(&self, dirs: &[PathBuf], commit: &str) -> bool {
28472849
let mut git = helpers::git(Some(&self.src));
28482850
git.args(["diff-index", "--quiet", commit]);
2849-
28502851
if !dirs.is_empty() {
28512852
git.arg("--");
28522853
for dir in dirs {
28532854
git.arg(self.src.join(dir));
28542855
}
28552856
}
2856-
2857-
let has_changes = !t!(git.as_command_mut().status()).success();
2858-
2859-
if has_changes {
2860-
if if_unchanged {
2861-
if self.is_verbose() {
2862-
println!(
2863-
"WARNING: saw changes to one of {:?} since {}; \
2864-
ignoring `{}`",
2865-
dirs, commit, option_name
2866-
);
2867-
}
2868-
None
2869-
} else {
2870-
Some(true)
2871-
}
2872-
} else {
2873-
Some(false)
2874-
}
2857+
!t!(git.as_command_mut().status()).success()
28752858
}
28762859
}
28772860

0 commit comments

Comments
 (0)
Please sign in to comment.