Skip to content

Commit 1abf419

Browse files
committed
Unify usages of path modifications and log them in verbose mode
1 parent 64b0472 commit 1abf419

File tree

5 files changed

+57
-73
lines changed

5 files changed

+57
-73
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
112112
&builder.config,
113113
builder.config.rust_info.is_managed_git_subrepository(),
114114
);
115+
builder.verbose(|| {
116+
eprintln!("GCC freshness: {source:?}");
117+
});
115118
match source {
116119
PathFreshness::LastModifiedUpstream { upstream } => {
117120
// Download from upstream CI
@@ -287,31 +290,17 @@ fn ci_gcc_root(config: &crate::Config) -> PathBuf {
287290
/// Detect whether GCC sources have been modified locally or not.
288291
#[cfg(not(test))]
289292
fn detect_gcc_freshness(config: &crate::Config, is_git: bool) -> build_helper::git::PathFreshness {
290-
use build_helper::git::{PathFreshness, check_path_modifications};
291-
292-
let freshness = if is_git {
293-
Some(
294-
check_path_modifications(
295-
Some(&config.src),
296-
&config.git_config(),
297-
&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"],
298-
CiEnv::current(),
299-
)
300-
.unwrap(),
301-
)
293+
use build_helper::git::PathFreshness;
294+
295+
if is_git {
296+
config.check_path_modifications(&["src/gcc", "src/bootstrap/download-ci-gcc-stamp"])
302297
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
303-
Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() })
298+
PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }
304299
} else {
305-
None
306-
};
307-
308-
let Some(freshness) = freshness else {
309300
eprintln!("error: could not find commit hash for downloading GCC");
310301
eprintln!("HELP: maybe your repository history is too shallow?");
311302
eprintln!("HELP: consider disabling `download-ci-gcc`");
312303
eprintln!("HELP: or fetch enough history to include one upstream commit");
313-
panic!();
314-
};
315-
316-
freshness
304+
crate::exit!(1);
305+
}
317306
}

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::sync::OnceLock;
1515
use std::{env, fs};
1616

1717
use build_helper::ci::CiEnv;
18-
use build_helper::git::{PathFreshness, check_path_modifications};
18+
use build_helper::git::PathFreshness;
1919
#[cfg(feature = "tracing")]
2020
use tracing::instrument;
2121

@@ -176,36 +176,22 @@ pub fn prebuilt_llvm_config(
176176

177177
/// Detect whether LLVM sources have been modified locally or not.
178178
pub(crate) fn detect_llvm_freshness(config: &Config, is_git: bool) -> PathFreshness {
179-
let freshness = if is_git {
180-
Some(
181-
check_path_modifications(
182-
Some(&config.src),
183-
&config.git_config(),
184-
&[
185-
"src/llvm-project",
186-
"src/bootstrap/download-ci-llvm-stamp",
187-
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
188-
"src/version",
189-
],
190-
CiEnv::current(),
191-
)
192-
.unwrap(),
193-
)
179+
if is_git {
180+
config.check_path_modifications(&[
181+
"src/llvm-project",
182+
"src/bootstrap/download-ci-llvm-stamp",
183+
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
184+
"src/version",
185+
])
194186
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
195-
Some(PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() })
187+
PathFreshness::LastModifiedUpstream { upstream: info.sha.trim().to_owned() }
196188
} else {
197-
None
198-
};
199-
200-
let Some(freshness) = freshness else {
201189
eprintln!("error: could not find commit hash for downloading LLVM");
202190
eprintln!("HELP: maybe your repository history is too shallow?");
203191
eprintln!("HELP: consider disabling `download-ci-llvm`");
204192
eprintln!("HELP: or fetch enough history to include one upstream commit");
205-
panic!();
206-
};
207-
208-
freshness
193+
crate::exit!(1);
194+
}
209195
}
210196

211197
/// 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
@@ -3043,7 +3043,11 @@ impl Config {
30433043
let commit = if self.rust_info.is_managed_git_subrepository() {
30443044
// Look for a version to compare to based on the current commit.
30453045
// Only commits merged by bors will have CI artifacts.
3046-
match self.check_modifications(&allowed_paths) {
3046+
let freshness = self.check_path_modifications(&allowed_paths);
3047+
self.verbose(|| {
3048+
eprintln!("rustc freshness: {freshness:?}");
3049+
});
3050+
match freshness {
30473051
PathFreshness::LastModifiedUpstream { upstream } => upstream,
30483052
PathFreshness::HasLocalModifications { upstream } => {
30493053
if if_unchanged {
@@ -3127,13 +3131,14 @@ impl Config {
31273131

31283132
/// Returns true if any of the `paths` have been modified locally.
31293133
pub fn has_changes_from_upstream(&self, paths: &[&str]) -> bool {
3130-
match self.check_modifications(paths) {
3134+
match self.check_path_modifications(paths) {
31313135
PathFreshness::LastModifiedUpstream { .. } => false,
31323136
PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true,
31333137
}
31343138
}
31353139

3136-
fn check_modifications(&self, paths: &[&str]) -> PathFreshness {
3140+
/// Checks whether any of the given paths have been modified w.r.t. upstream.
3141+
pub fn check_path_modifications(&self, paths: &[&str]) -> PathFreshness {
31373142
check_path_modifications(Some(&self.src), &self.git_config(), paths, CiEnv::current())
31383143
.unwrap()
31393144
}

src/bootstrap/src/core/download.rs

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

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