Skip to content

Commit a263eab

Browse files
committed
bootstrap: Print why if-unchanged isn't downloading rustc
Example output: ``` $ x b compiler Building bootstrap Finished `dev` profile [unoptimized] target(s) in 0.02s NOTE: detected 3 modifications that could affect a build of rustc - src/bootstrap/src/core/config/config.rs - src/bootstrap/src/core/download.rs - src/build_helper/src/git.rs skipping rustc download due to `download-rustc = 'if-unchanged'` Building stage1 compiler artifacts (stage0 -> stage1, aarch64-apple-darwin) Finished `release` profile [optimized] target(s) in 0.72s Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`) Build completed successfully in 0:00:05 ```
1 parent fd0c901 commit a263eab

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,11 +2237,7 @@ pub fn download_ci_rustc_commit<'a>(
22372237
});
22382238
match freshness {
22392239
PathFreshness::LastModifiedUpstream { upstream } => upstream,
2240-
PathFreshness::HasLocalModifications { upstream } => {
2241-
if if_unchanged {
2242-
return None;
2243-
}
2244-
2240+
PathFreshness::HasLocalModifications { upstream, modifications } => {
22452241
if dwn_ctx.is_running_on_ci() {
22462242
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
22472243
eprintln!(
@@ -2250,6 +2246,24 @@ pub fn download_ci_rustc_commit<'a>(
22502246
return None;
22512247
}
22522248

2249+
eprintln!(
2250+
"NOTE: detected {} modifications that could affect a build of rustc",
2251+
modifications.len()
2252+
);
2253+
for file in modifications.iter().take(10) {
2254+
eprintln!("- {}", file.display());
2255+
}
2256+
if modifications.len() > 10 {
2257+
eprintln!("- ...");
2258+
}
2259+
2260+
if if_unchanged {
2261+
eprintln!("skipping rustc download due to `download-rustc = 'if-unchanged'`");
2262+
return None;
2263+
} else {
2264+
eprintln!("downloading anyway due to `download-rustc = true`");
2265+
}
2266+
22532267
upstream
22542268
}
22552269
PathFreshness::MissingUpstream => {

src/bootstrap/src/core/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl Config {
266266
});
267267
let llvm_sha = match llvm_freshness {
268268
PathFreshness::LastModifiedUpstream { upstream } => upstream,
269-
PathFreshness::HasLocalModifications { upstream } => upstream,
269+
PathFreshness::HasLocalModifications { upstream, modifications: _ } => upstream,
270270
PathFreshness::MissingUpstream => {
271271
eprintln!("error: could not find commit hash for downloading LLVM");
272272
eprintln!("HELP: maybe your repository history is too shallow?");

src/build_helper/src/git.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::Path;
1+
use std::path::{Path, PathBuf};
22
use std::process::{Command, Stdio};
33

44
use crate::ci::CiEnv;
@@ -38,7 +38,7 @@ pub enum PathFreshness {
3838
/// "Local" essentially means "not-upstream" here.
3939
/// `upstream` is the latest upstream merge commit that made modifications to the
4040
/// set of paths.
41-
HasLocalModifications { upstream: String },
41+
HasLocalModifications { upstream: String, modifications: Vec<PathBuf> },
4242
/// No upstream commit was found.
4343
/// This should not happen in most reasonable circumstances, but one never knows.
4444
MissingUpstream,
@@ -134,21 +134,34 @@ pub fn check_path_modifications(
134134
// However, that should be equivalent to checking if something has changed
135135
// from the latest upstream commit *that modified `target_paths`*, and
136136
// with this approach we do not need to invoke git an additional time.
137-
if has_changed_since(git_dir, &upstream_sha, target_paths) {
138-
Ok(PathFreshness::HasLocalModifications { upstream: upstream_sha })
137+
let modifications = changes_since(git_dir, &upstream_sha, target_paths)?;
138+
if !modifications.is_empty() {
139+
Ok(PathFreshness::HasLocalModifications { upstream: upstream_sha, modifications })
139140
} else {
140141
Ok(PathFreshness::LastModifiedUpstream { upstream: upstream_sha })
141142
}
142143
}
143144

144145
/// Returns true if any of the passed `paths` have changed since the `base` commit.
145-
pub fn has_changed_since(git_dir: &Path, base: &str, paths: &[&str]) -> bool {
146+
pub fn changes_since(git_dir: &Path, base: &str, paths: &[&str]) -> Result<Vec<PathBuf>, String> {
147+
use std::io::BufRead;
148+
146149
run_git_diff_index(Some(git_dir), |cmd| {
147-
cmd.args(["--quiet", base, "--"]).args(paths);
150+
cmd.args([base, "--name-only", "--"]).args(paths);
151+
152+
let output = cmd.stderr(Stdio::inherit()).output().expect("cannot run git diff-index");
153+
if !output.status.success() {
154+
return Err(format!("failed to run: {cmd:?}: {:?}", output.status));
155+
}
148156

149-
// Exit code 0 => no changes
150-
// Exit code 1 => some changes were detected
151-
!cmd.status().expect("cannot run git diff-index").success()
157+
output
158+
.stdout
159+
.lines()
160+
.map(|res| match res {
161+
Ok(line) => Ok(PathBuf::from(line)),
162+
Err(e) => Err(format!("invalid UTF-8 in diff-index: {e:?}")),
163+
})
164+
.collect()
152165
})
153166
}
154167

0 commit comments

Comments
 (0)