aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_env
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_env')
-rw-r--r--crates/ra_env/src/lib.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/ra_env/src/lib.rs b/crates/ra_env/src/lib.rs
index 8d6aa9268..a1c4239be 100644
--- a/crates/ra_env/src/lib.rs
+++ b/crates/ra_env/src/lib.rs
@@ -4,15 +4,15 @@
4 4
5use anyhow::{Error, Result}; 5use anyhow::{Error, Result};
6use std::env; 6use std::env;
7use std::path::Path; 7use std::path::{Path, PathBuf};
8use std::process::Command; 8use std::process::Command;
9 9
10/// Return a `String` to use for the given executable. 10/// Return a `PathBuf` to use for the given executable.
11/// 11///
12/// E.g., `get_path_for_executable("cargo")` may return just `cargo` if that 12/// E.g., `get_path_for_executable("cargo")` may return just `cargo` if that
13/// gives a valid Cargo executable; or it may return a full path to a valid 13/// gives a valid Cargo executable; or it may return a full path to a valid
14/// Cargo. 14/// Cargo.
15pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<String> { 15pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<PathBuf> {
16 // The current implementation checks three places for an executable to use: 16 // The current implementation checks three places for an executable to use:
17 // 1) Appropriate environment variable (erroring if this is set but not a usable executable) 17 // 1) Appropriate environment variable (erroring if this is set but not a usable executable)
18 // example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc 18 // example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc
@@ -25,7 +25,7 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<Strin
25 let env_var = executable_name.to_ascii_uppercase(); 25 let env_var = executable_name.to_ascii_uppercase();
26 if let Ok(path) = env::var(&env_var) { 26 if let Ok(path) = env::var(&env_var) {
27 if is_valid_executable(&path) { 27 if is_valid_executable(&path) {
28 Ok(path) 28 Ok(path.into())
29 } else { 29 } else {
30 Err(Error::msg(format!( 30 Err(Error::msg(format!(
31 "`{}` environment variable points to something that's not a valid executable", 31 "`{}` environment variable points to something that's not a valid executable",
@@ -34,14 +34,14 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<Strin
34 } 34 }
35 } else { 35 } else {
36 if is_valid_executable(executable_name) { 36 if is_valid_executable(executable_name) {
37 return Ok(executable_name.to_owned()); 37 return Ok(executable_name.into());
38 } 38 }
39 if let Some(mut path) = dirs::home_dir() { 39 if let Some(mut path) = dirs::home_dir() {
40 path.push(".cargo"); 40 path.push(".cargo");
41 path.push("bin"); 41 path.push("bin");
42 path.push(executable_name); 42 path.push(executable_name);
43 if is_valid_executable(&path) { 43 if is_valid_executable(&path) {
44 return Ok(path.into_os_string().into_string().expect("Invalid Unicode in path")); 44 return Ok(path);
45 } 45 }
46 } 46 }
47 // This error message may also be caused by $PATH or $CARGO/$RUSTC/etc not being set correctly 47 // This error message may also be caused by $PATH or $CARGO/$RUSTC/etc not being set correctly