From c16d9d8946593daf3cceb53fcee063b01f71a5c3 Mon Sep 17 00:00:00 2001 From: benluiwj Date: Sat, 21 Sep 2024 11:32:32 +0800 Subject: [PATCH] minor refactor --- check_diff/src/lib.rs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/check_diff/src/lib.rs b/check_diff/src/lib.rs index 7df383afc87..33cfcf84795 100644 --- a/check_diff/src/lib.rs +++ b/check_diff/src/lib.rs @@ -1,9 +1,7 @@ use std::env; use std::io; -use std::path::Path; -use std::path::PathBuf; -use std::process::Command; -use std::process::Output; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; use tracing::info; pub enum CheckDiffError { @@ -196,12 +194,8 @@ pub fn get_cargo_version() -> Result { return Ok(cargo_version); } -pub fn get_binary_version( - binary: &PathBuf, - ld_lib_path: &String, -) -> Result { - let binary_str = pathbuf_to_str(binary)?; - let Ok(command) = Command::new(binary_str) +pub fn get_binary_version(binary: &Path, ld_lib_path: &String) -> Result { + let Ok(command) = Command::new(binary) .env("LD_LIB_PATH", ld_lib_path) .args(["--version"]) .output() @@ -222,7 +216,7 @@ pub fn get_binary_version( /// Obtains the ld_lib path and then builds rustfmt from source /// If that operation succeeds, the source is then copied to the output path specified -pub fn build_rustfmt_from_src(output_path: &PathBuf) -> Result { +pub fn build_rustfmt_from_src(binary_path: &Path) -> Result { //Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each // binary can find it's runtime dependencies. // See https://github.com/rust-lang/rustfmt/issues/5675 @@ -240,24 +234,14 @@ pub fn build_rustfmt_from_src(output_path: &PathBuf) -> Result Result<&str, CheckDiffError> { - let Some(result) = pathbuf.to_str() else { - return Err(CheckDiffError::FailedPathBuf(format!( - "Unable to convert {:?} to str", - pathbuf - ))); - }; - return Ok(result); -} - // Compiles and produces two rustfmt binaries. // One for the current master, and another for the feature branch // Parameters: