aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_env/src/lib.rs12
-rw-r--r--crates/ra_project_model/src/sysroot.rs5
2 files changed, 9 insertions, 8 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
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs
index 516e0472d..ed374f241 100644
--- a/crates/ra_project_model/src/sysroot.rs
+++ b/crates/ra_project_model/src/sysroot.rs
@@ -89,9 +89,10 @@ fn create_command_text(program: &str, args: &[&str]) -> String {
89 format!("{} {}", program, args.join(" ")) 89 format!("{} {}", program, args.join(" "))
90} 90}
91 91
92fn run_command_in_cargo_dir(cargo_toml: &Path, program: &str, args: &[&str]) -> Result<Output> { 92fn run_command_in_cargo_dir(cargo_toml: impl AsRef<Path>, program: impl AsRef<Path>, args: &[&str]) -> Result<Output> {
93 let program = program.as_ref().as_os_str().to_str().expect("Invalid Unicode in path");
93 let output = Command::new(program) 94 let output = Command::new(program)
94 .current_dir(cargo_toml.parent().unwrap()) 95 .current_dir(cargo_toml.as_ref().parent().unwrap())
95 .args(args) 96 .args(args)
96 .output() 97 .output()
97 .context(format!("{} failed", create_command_text(program, args)))?; 98 .context(format!("{} failed", create_command_text(program, args)))?;