Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1f5320e

Browse files
committed
Unify usages of path modifications and log them in verbose mode
1 parent 1dabb76 commit 1f5320e

File tree

6 files changed

+53
-69
lines changed

6 files changed

+53
-69
lines changed

src/bootstrap/src/core/build_steps/gcc.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
110110
&builder.config,
111111
builder.config.rust_info.is_managed_git_subrepository(),
112112
);
113+
builder.verbose(|| {
114+
eprintln!("GCC freshness: {source:?}");
115+
});
113116
match source {
114117
PathFreshness::LastModifiedUpstream { upstream } => {
115118
// Download from upstream CI
@@ -285,31 +288,17 @@ fn ci_gcc_root(config: &crate::Config) -> PathBuf {
285288
/// Detect whether GCC sources have been modified locally or not.
286289
#[cfg(not(test))]
287290
fn detect_gcc_freshness(config: &crate::Config, is_git: bool) -> build_helper::git::PathFreshness {
288-
use build_helper::git::{PathFreshness, check_path_modifications};
289-
290-
let freshness = if is_git {
291-
Some(
292-
check_path_modifications(
293-
Some(&config.src),
294-
&config.git_config(),
295-
&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"],
296-
config.ci_env(),
297-
)
298-
.unwrap(),
299-
)
291+
use build_helper::git::PathFreshness;
292+
293+
if is_git {
294+
config.check_path_modifications(&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"])
300295
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
301-
Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() })
296+
PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }
302297
} else {
303-
None
304-
};
305-
306-
let Some(freshness) = freshness else {
307298
eprintln!("error: could not find commit hash for downloading GCC");
308299
eprintln!("HELP: maybe your repository history is too shallow?");
309300
eprintln!("HELP: consider disabling `download-ci-gcc`");
310301
eprintln!("HELP: or fetch enough history to include one upstream commit");
311-
panic!();
312-
};
313-
314-
freshness
302+
crate::exit!(1);
303+
}
315304
}

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};
1414
use std::sync::OnceLock;
1515
use std::{env, fs};
1616

17-
use build_helper::git::{PathFreshness, check_path_modifications};
17+
use build_helper::git::PathFreshness;
1818
#[cfg(feature = "tracing")]
1919
use tracing::instrument;
2020

@@ -183,31 +183,17 @@ pub const LLVM_INVALIDATION_PATHS: &[&str] = &[
183183

184184
/// Detect whether LLVM sources have been modified locally or not.
185185
pub(crate) fn detect_llvm_freshness(config: &Config, is_git: bool) -> PathFreshness {
186-
let freshness = if is_git {
187-
Some(
188-
check_path_modifications(
189-
Some(&config.src),
190-
&config.git_config(),
191-
LLVM_INVALIDATION_PATHS,
192-
config.ci_env(),
193-
)
194-
.unwrap(),
195-
)
186+
if is_git {
187+
config.check_path_modifications(LLVM_INVALIDATION_PATHS)
196188
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
197-
Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() })
189+
PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }
198190
} else {
199-
None
200-
};
201-
202-
let Some(freshness) = freshness else {
203191
eprintln!("error: could not find commit hash for downloading LLVM");
204192
eprintln!("HELP: maybe your repository history is too shallow?");
205193
eprintln!("HELP: consider disabling `download-ci-llvm`");
206194
eprintln!("HELP: or fetch enough history to include one upstream commit");
207-
panic!();
208-
};
209-
210-
freshness
195+
crate::exit!(1);
196+
}
211197
}
212198

213199
/// Returns whether the CI-found LLVM is currently usable.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,7 +3193,11 @@ impl Config {
31933193
let commit = if self.rust_info.is_managed_git_subrepository() {
31943194
// Look for a version to compare to based on the current commit.
31953195
// Only commits merged by bors will have CI artifacts.
3196-
match self.check_modifications(&allowed_paths) {
3196+
let freshness = self.check_path_modifications(&allowed_paths);
3197+
self.verbose(|| {
3198+
eprintln!("rustc freshness: {freshness:?}");
3199+
});
3200+
match freshness {
31973201
PathFreshness::LastModifiedUpstream { upstream } => upstream,
31983202
PathFreshness::HasLocalModifications { upstream } => {
31993203
if if_unchanged {
@@ -3291,13 +3295,14 @@ impl Config {
32913295

32923296
/// Returns true if any of the `paths` have been modified locally.
32933297
pub fn has_changes_from_upstream(&self, paths: &[&str]) -> bool {
3294-
match self.check_modifications(paths) {
3298+
match self.check_path_modifications(paths) {
32953299
PathFreshness::LastModifiedUpstream { .. } => false,
32963300
PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true,
32973301
}
32983302
}
32993303

3300-
fn check_modifications(&self, paths: &[&str]) -> PathFreshness {
3304+
/// Checks whether any of the given paths have been modified w.r.t. upstream.
3305+
pub fn check_path_modifications(&self, paths: &[&str]) -> PathFreshness {
33013306
check_path_modifications(Some(&self.src), &self.git_config(), paths, CiEnv::current())
33023307
.unwrap()
33033308
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn download_ci_llvm() {
5151

5252
let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\"");
5353
if if_unchanged_config.llvm_from_ci && if_unchanged_config.is_running_on_ci {
54-
let has_changes = if_unchanged_config.has_changes_from_upstream(&["src/llvm-project"]);
54+
let has_changes = if_unchanged_config.has_changes_from_upstream(LLVM_INVALIDATION_PATHS);
5555

5656
assert!(
5757
!has_changes,

src/bootstrap/src/core/download.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,19 @@ download-rustc = false
730730
}
731731

732732
let llvm_root = self.ci_llvm_root();
733-
let llvm_sha =
734-
match detect_llvm_freshness(self, self.rust_info.is_managed_git_subrepository()) {
735-
PathFreshness::LastModifiedUpstream { upstream } => upstream,
736-
PathFreshness::HasLocalModifications { upstream } => upstream,
737-
PathFreshness::MissingUpstream => {
738-
eprintln!("No upstream commit for downloading LLVM found");
739-
crate::exit!(1);
740-
}
741-
};
733+
let llvm_freshness =
734+
detect_llvm_freshness(self, self.rust_info.is_managed_git_subrepository());
735+
self.verbose(|| {
736+
eprintln!("LLVM freshness: {llvm_freshness:?}");
737+
});
738+
let llvm_sha = match llvm_freshness {
739+
PathFreshness::LastModifiedUpstream { upstream } => upstream,
740+
PathFreshness::HasLocalModifications { upstream } => upstream,
741+
PathFreshness::MissingUpstream => {
742+
eprintln!("No upstream commit for downloading LLVM found");
743+
crate::exit!(1);
744+
}
745+
};
742746
let stamp_key = format!("{}{}", llvm_sha, self.llvm_assertions);
743747
let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm").add_stamp(stamp_key);
744748
if !llvm_stamp.is_up_to_date() && !self.dry_run() {

src/build_helper/src/git/tests.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn test_pr_ci_unchanged_anywhere() {
1010
git_test(|ctx| {
1111
let sha = ctx.create_upstream_merge(&["a"]);
1212
ctx.create_nonupstream_merge(&["b"]);
13-
let src = ctx.get_source(&["c"], CiEnv::GitHubActions);
13+
let src = ctx.check_modifications(&["c"], CiEnv::GitHubActions);
1414
assert_eq!(src, PathFreshness::LastModifiedUpstream { upstream: sha });
1515
});
1616
}
@@ -20,7 +20,7 @@ fn test_pr_ci_changed_in_pr() {
2020
git_test(|ctx| {
2121
let sha = ctx.create_upstream_merge(&["a"]);
2222
ctx.create_nonupstream_merge(&["b"]);
23-
let src = ctx.get_source(&["b"], CiEnv::GitHubActions);
23+
let src = ctx.check_modifications(&["b"], CiEnv::GitHubActions);
2424
assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
2525
});
2626
}
@@ -30,7 +30,7 @@ fn test_auto_ci_unchanged_anywhere_select_parent() {
3030
git_test(|ctx| {
3131
let sha = ctx.create_upstream_merge(&["a"]);
3232
ctx.create_upstream_merge(&["b"]);
33-
let src = ctx.get_source(&["c"], CiEnv::GitHubActions);
33+
let src = ctx.check_modifications(&["c"], CiEnv::GitHubActions);
3434
assert_eq!(src, PathFreshness::LastModifiedUpstream { upstream: sha });
3535
});
3636
}
@@ -40,7 +40,7 @@ fn test_auto_ci_changed_in_pr() {
4040
git_test(|ctx| {
4141
let sha = ctx.create_upstream_merge(&["a"]);
4242
ctx.create_upstream_merge(&["b", "c"]);
43-
let src = ctx.get_source(&["c", "d"], CiEnv::GitHubActions);
43+
let src = ctx.check_modifications(&["c", "d"], CiEnv::GitHubActions);
4444
assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
4545
});
4646
}
@@ -53,7 +53,7 @@ fn test_local_uncommitted_modifications() {
5353
ctx.modify("a");
5454

5555
assert_eq!(
56-
ctx.get_source(&["a", "d"], CiEnv::None),
56+
ctx.check_modifications(&["a", "d"], CiEnv::None),
5757
PathFreshness::HasLocalModifications { upstream: sha }
5858
);
5959
});
@@ -71,7 +71,7 @@ fn test_local_committed_modifications() {
7171
ctx.commit();
7272

7373
assert_eq!(
74-
ctx.get_source(&["a", "d"], CiEnv::None),
74+
ctx.check_modifications(&["a", "d"], CiEnv::None),
7575
PathFreshness::HasLocalModifications { upstream: sha }
7676
);
7777
});
@@ -87,7 +87,7 @@ fn test_local_committed_modifications_subdirectory() {
8787
ctx.commit();
8888

8989
assert_eq!(
90-
ctx.get_source(&["a/b"], CiEnv::None),
90+
ctx.check_modifications(&["a/b"], CiEnv::None),
9191
PathFreshness::HasLocalModifications { upstream: sha }
9292
);
9393
});
@@ -100,7 +100,7 @@ fn test_local_changes_in_head_upstream() {
100100
// even if it is currently HEAD
101101
let sha = ctx.create_upstream_merge(&["a"]);
102102
assert_eq!(
103-
ctx.get_source(&["a", "d"], CiEnv::None),
103+
ctx.check_modifications(&["a", "d"], CiEnv::None),
104104
PathFreshness::LastModifiedUpstream { upstream: sha }
105105
);
106106
});
@@ -117,7 +117,7 @@ fn test_local_changes_in_previous_upstream() {
117117
ctx.modify("d");
118118
ctx.commit();
119119
assert_eq!(
120-
ctx.get_source(&["a"], CiEnv::None),
120+
ctx.check_modifications(&["a"], CiEnv::None),
121121
PathFreshness::LastModifiedUpstream { upstream: sha }
122122
);
123123
});
@@ -135,7 +135,7 @@ fn test_local_no_upstream_commit_with_changes() {
135135
ctx.modify("d");
136136
ctx.commit();
137137
assert_eq!(
138-
ctx.get_source(&["x"], CiEnv::None),
138+
ctx.check_modifications(&["x"], CiEnv::None),
139139
PathFreshness::LastModifiedUpstream { upstream: sha }
140140
);
141141
});
@@ -144,7 +144,7 @@ fn test_local_no_upstream_commit_with_changes() {
144144
#[test]
145145
fn test_local_no_upstream_commit() {
146146
git_test(|ctx| {
147-
let src = ctx.get_source(&["c", "d"], CiEnv::None);
147+
let src = ctx.check_modifications(&["c", "d"], CiEnv::None);
148148
assert_eq!(src, PathFreshness::MissingUpstream);
149149
});
150150
}
@@ -159,15 +159,15 @@ fn test_local_changes_negative_path() {
159159
ctx.commit();
160160

161161
assert_eq!(
162-
ctx.get_source(&[":!b", ":!d"], CiEnv::None),
162+
ctx.check_modifications(&[":!b", ":!d"], CiEnv::None),
163163
PathFreshness::LastModifiedUpstream { upstream: upstream.clone() }
164164
);
165165
assert_eq!(
166-
ctx.get_source(&[":!c"], CiEnv::None),
166+
ctx.check_modifications(&[":!c"], CiEnv::None),
167167
PathFreshness::HasLocalModifications { upstream: upstream.clone() }
168168
);
169169
assert_eq!(
170-
ctx.get_source(&[":!d", ":!x"], CiEnv::None),
170+
ctx.check_modifications(&[":!d", ":!x"], CiEnv::None),
171171
PathFreshness::HasLocalModifications { upstream }
172172
);
173173
});
@@ -198,7 +198,7 @@ impl GitCtx {
198198
ctx
199199
}
200200

201-
fn get_source(&self, target_paths: &[&str], ci_env: CiEnv) -> PathFreshness {
201+
fn check_modifications(&self, target_paths: &[&str], ci_env: CiEnv) -> PathFreshness {
202202
check_path_modifications(Some(self.dir.path()), &self.git_config(), target_paths, ci_env)
203203
.unwrap()
204204
}

0 commit comments

Comments
 (0)