diff options
Diffstat (limited to 'crates/ra_project_model/src/sysroot.rs')
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 55ff5ad80..11c26ad89 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -8,6 +8,7 @@ use std::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | use ra_arena::{Arena, Idx}; | 10 | use ra_arena::{Arena, Idx}; |
11 | use ra_env::get_path_for_executable; | ||
11 | 12 | ||
12 | #[derive(Default, Debug, Clone)] | 13 | #[derive(Default, Debug, Clone)] |
13 | pub struct Sysroot { | 14 | pub struct Sysroot { |
@@ -88,9 +89,14 @@ fn create_command_text(program: &str, args: &[&str]) -> String { | |||
88 | format!("{} {}", program, args.join(" ")) | 89 | format!("{} {}", program, args.join(" ")) |
89 | } | 90 | } |
90 | 91 | ||
91 | fn run_command_in_cargo_dir(cargo_toml: &Path, program: &str, args: &[&str]) -> Result<Output> { | 92 | fn run_command_in_cargo_dir( |
93 | cargo_toml: impl AsRef<Path>, | ||
94 | program: impl AsRef<Path>, | ||
95 | args: &[&str], | ||
96 | ) -> Result<Output> { | ||
97 | let program = program.as_ref().as_os_str().to_str().expect("Invalid Unicode in path"); | ||
92 | let output = Command::new(program) | 98 | let output = Command::new(program) |
93 | .current_dir(cargo_toml.parent().unwrap()) | 99 | .current_dir(cargo_toml.as_ref().parent().unwrap()) |
94 | .args(args) | 100 | .args(args) |
95 | .output() | 101 | .output() |
96 | .context(format!("{} failed", create_command_text(program, args)))?; | 102 | .context(format!("{} failed", create_command_text(program, args)))?; |
@@ -114,13 +120,15 @@ fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> { | |||
114 | if let Ok(path) = env::var("RUST_SRC_PATH") { | 120 | if let Ok(path) = env::var("RUST_SRC_PATH") { |
115 | return Ok(path.into()); | 121 | return Ok(path.into()); |
116 | } | 122 | } |
117 | let rustc_output = run_command_in_cargo_dir(cargo_toml, "rustc", &["--print", "sysroot"])?; | 123 | let rustc = get_path_for_executable("rustc")?; |
124 | let rustc_output = run_command_in_cargo_dir(cargo_toml, &rustc, &["--print", "sysroot"])?; | ||
118 | let stdout = String::from_utf8(rustc_output.stdout)?; | 125 | let stdout = String::from_utf8(rustc_output.stdout)?; |
119 | let sysroot_path = Path::new(stdout.trim()); | 126 | let sysroot_path = Path::new(stdout.trim()); |
120 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); | 127 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); |
121 | 128 | ||
122 | if !src_path.exists() { | 129 | if !src_path.exists() { |
123 | run_command_in_cargo_dir(cargo_toml, "rustup", &["component", "add", "rust-src"])?; | 130 | let rustup = get_path_for_executable("rustup")?; |
131 | run_command_in_cargo_dir(cargo_toml, &rustup, &["component", "add", "rust-src"])?; | ||
124 | } | 132 | } |
125 | if !src_path.exists() { | 133 | if !src_path.exists() { |
126 | bail!( | 134 | bail!( |