From eb352d0fcde3def0950e5f9520f658e0f5d51fe4 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Wed, 20 Dec 2023 08:07:03 +1100 Subject: [PATCH] Remove which dependency. --- prost-build/Cargo.toml | 1 - prost-build/src/lib.rs | 31 ++++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/prost-build/Cargo.toml b/prost-build/Cargo.toml index f439f4fc1..611c8a5d2 100644 --- a/prost-build/Cargo.toml +++ b/prost-build/Cargo.toml @@ -32,7 +32,6 @@ prost-types = { version = "0.12.3", path = "../prost-types", default-features = tempfile = "3" once_cell = "1.17.1" regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] } -which = "4" prettyplease = { version = "0.2", optional = true } syn = { version = "2", features = ["full"], optional = true } diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index f8aa05687..2e9bd34b6 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -1124,12 +1124,16 @@ impl Config { debug!("Running: {:?}", cmd); - let output = cmd.output().map_err(|error| { - Error::new( - error.kind(), - format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, error), - ) - })?; + let output = match cmd.output() { + Err(err) if ErrorKind::NotFound == err.kind() => { + panic!("{}", protoc_not_found()); + } + Err(err) => return Err(Error::new( + err.kind(), + format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, err), + )), + Ok(output) => output, + }; if !output.status.success() { return Err(Error::new( @@ -1495,6 +1499,12 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> { /// Returns the path to the `protoc` binary. pub fn protoc_from_env() -> PathBuf { + env::var_os("PROTOC") + .map(PathBuf::from) + .unwrap_or(PathBuf::from("protoc")) +} + +pub fn protoc_not_found() -> String { let os_specific_hint = if cfg!(target_os = "macos") { "You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases" } else if cfg!(target_os = "linux") { @@ -1507,18 +1517,13 @@ pub fn protoc_from_env() -> PathBuf { this knowledge. If `protoc` is installed and this crate had trouble finding it, you can set the `PROTOC` environment variable with the specific path to your installed `protoc` binary."; - let msg = format!( + format!( "{}{} For more information: https://docs.rs/prost-build/#sourcing-protoc ", error_msg, os_specific_hint - ); - - env::var_os("PROTOC") - .map(PathBuf::from) - .or_else(|| which::which("protoc").ok()) - .expect(&msg) + ) } /// Returns the path to the Protobuf include directory.