Skip to content

build-helper: clippy fixes #143770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build_helper/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum CiEnv {
impl CiEnv {
/// Obtains the current CI environment.
pub fn current() -> CiEnv {
if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") {
if std::env::var("GITHUB_ACTIONS").is_ok_and(|e| e == "true") {
CiEnv::GitHubActions
} else {
CiEnv::None
Expand Down
32 changes: 16 additions & 16 deletions src/build_helper/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct GitConfig<'a> {
pub fn output_result(cmd: &mut Command) -> Result<String, String> {
let output = match cmd.stderr(Stdio::inherit()).output() {
Ok(status) => status,
Err(e) => return Err(format!("failed to run command: {:?}: {}", cmd, e)),
Err(e) => return Err(format!("failed to run command: {cmd:?}: {e}")),
};
if !output.status.success() {
return Err(format!(
Expand Down Expand Up @@ -62,22 +62,22 @@ pub enum PathFreshness {
/// The function behaves differently in CI and outside CI.
///
/// - Outside CI, we want to find out if `target_paths` were modified in some local commit on
/// top of the latest upstream commit that is available in local git history.
/// If not, we try to find the most recent upstream commit (which we assume are commits
/// made by bors) that modified `target_paths`.
/// We don't want to simply take the latest master commit to avoid changing the output of
/// this function frequently after rebasing on the latest master branch even if `target_paths`
/// were not modified upstream in the meantime. In that case we would be redownloading CI
/// artifacts unnecessarily.
/// top of the latest upstream commit that is available in local git history.
/// If not, we try to find the most recent upstream commit (which we assume are commits
/// made by bors) that modified `target_paths`.
/// We don't want to simply take the latest master commit to avoid changing the output of
/// this function frequently after rebasing on the latest master branch even if `target_paths`
/// were not modified upstream in the meantime. In that case we would be redownloading CI
/// artifacts unnecessarily.
///
/// - In CI, we use a shallow clone of depth 2, i.e., we fetch only a single parent commit
/// (which will be the most recent bors merge commit) and do not have access
/// to the full git history. Luckily, we only need to distinguish between two situations:
/// 1) The current PR made modifications to `target_paths`.
/// In that case, a build is typically necessary.
/// 2) The current PR did not make modifications to `target_paths`.
/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
/// redownloading.
/// (which will be the most recent bors merge commit) and do not have access
/// to the full git history. Luckily, we only need to distinguish between two situations:
/// 1) The current PR made modifications to `target_paths`.
/// In that case, a build is typically necessary.
/// 2) The current PR did not make modifications to `target_paths`.
/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
/// redownloading.
pub fn check_path_modifications(
git_dir: &Path,
config: &GitConfig<'_>,
Expand Down Expand Up @@ -232,7 +232,7 @@ pub fn get_closest_upstream_commit(
"--author-date-order",
&format!("--author={}", config.git_merge_commit_email),
"-n1",
&base,
base,
]);

let output = output_result(&mut git)?.trim().to_owned();
Expand Down
2 changes: 1 addition & 1 deletion src/build_helper/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl BuildStep {
} => {
let full_name = format!("{parent_name}-{kind}");
let children: Vec<_> =
children.into_iter().filter_map(|s| parse(s, &full_name)).collect();
children.iter().filter_map(|s| parse(s, &full_name)).collect();
let children_duration = children.iter().map(|c| c.duration).sum::<Duration>();
Some(BuildStep {
r#type: kind.to_string(),
Expand Down
15 changes: 7 additions & 8 deletions src/build_helper/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@ macro_rules! exit {
pub fn detail_exit(code: i32, is_test: bool) -> ! {
// if in test and code is an error code, panic with status code provided
if is_test {
panic!("status code: {}", code);
panic!("status code: {code}");
} else {
// otherwise,exit with provided status code
// otherwise, exit with provided status code
std::process::exit(code);
}
}

pub fn fail(s: &str) -> ! {
eprintln!("\n\n{}\n\n", s);
eprintln!("\n\n{s}\n\n");
detail_exit(1, cfg!(test));
}

pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> Result<(), ()> {
let status = match cmd.status() {
Ok(status) => status,
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nerror: {e}")),
};
if !status.success() {
if print_cmd_on_fail {
println!(
"\n\ncommand did not execute successfully: {:?}\n\
expected success, got: {}\n\n",
cmd, status
"\n\ncommand did not execute successfully: {cmd:?}\n\
expected success, got: {status}\n\n"
);
}
Err(())
Expand All @@ -60,7 +59,7 @@ pub fn parse_gitmodules(target_dir: &Path) -> Vec<String> {
for line in BufReader::new(file).lines().map_while(Result::ok) {
let line = line.trim();
if line.starts_with("path") {
let actual_path = line.split(' ').last().expect("Couldn't get value of path");
let actual_path = line.split(' ').next_back().expect("Couldn't get value of path");
submodules_paths.push(actual_path.to_owned());
}
}
Expand Down
Loading