diff options
author | vsrs <[email protected]> | 2020-05-08 17:34:34 +0100 |
---|---|---|
committer | vsrs <[email protected]> | 2020-05-08 17:34:34 +0100 |
commit | 0ef17ef1ee9fb0ce7149176d12f4d225f6d01401 (patch) | |
tree | fa2f168120f36f8dbef5dc1e85fea0c0071639c2 /crates/ra_project_model/src/sysroot.rs | |
parent | 1be6320ea6cf7830195f80681fa0f43cc340da7e (diff) | |
parent | d3eb9d8eafbebca7da95fa8a4813b92eb5080500 (diff) |
Merge remote-tracking branch 'upstream/master' into uniformed_debug_lens
# Conflicts:
# editors/code/src/commands/runnables.ts
Diffstat (limited to 'crates/ra_project_model/src/sysroot.rs')
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 55ff5ad80..a8a196e64 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -1,14 +1,16 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use anyhow::{bail, Context, Result}; | ||
4 | use std::{ | 3 | use std::{ |
5 | env, ops, | 4 | env, ops, |
6 | path::{Path, PathBuf}, | 5 | path::{Path, PathBuf}, |
7 | process::{Command, Output}, | 6 | process::Command, |
8 | }; | 7 | }; |
9 | 8 | ||
9 | use anyhow::{bail, Result}; | ||
10 | use ra_arena::{Arena, Idx}; | 10 | use ra_arena::{Arena, Idx}; |
11 | 11 | ||
12 | use crate::output; | ||
13 | |||
12 | #[derive(Default, Debug, Clone)] | 14 | #[derive(Default, Debug, Clone)] |
13 | pub struct Sysroot { | 15 | pub struct Sysroot { |
14 | crates: Arena<SysrootCrateData>, | 16 | crates: Arena<SysrootCrateData>, |
@@ -84,43 +86,22 @@ impl Sysroot { | |||
84 | } | 86 | } |
85 | } | 87 | } |
86 | 88 | ||
87 | fn create_command_text(program: &str, args: &[&str]) -> String { | ||
88 | format!("{} {}", program, args.join(" ")) | ||
89 | } | ||
90 | |||
91 | fn run_command_in_cargo_dir(cargo_toml: &Path, program: &str, args: &[&str]) -> Result<Output> { | ||
92 | let output = Command::new(program) | ||
93 | .current_dir(cargo_toml.parent().unwrap()) | ||
94 | .args(args) | ||
95 | .output() | ||
96 | .context(format!("{} failed", create_command_text(program, args)))?; | ||
97 | if !output.status.success() { | ||
98 | match output.status.code() { | ||
99 | Some(code) => bail!( | ||
100 | "failed to run the command: '{}' exited with code {}", | ||
101 | create_command_text(program, args), | ||
102 | code | ||
103 | ), | ||
104 | None => bail!( | ||
105 | "failed to run the command: '{}' terminated by signal", | ||
106 | create_command_text(program, args) | ||
107 | ), | ||
108 | }; | ||
109 | } | ||
110 | Ok(output) | ||
111 | } | ||
112 | |||
113 | fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> { | 89 | fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> { |
114 | if let Ok(path) = env::var("RUST_SRC_PATH") { | 90 | if let Ok(path) = env::var("RUST_SRC_PATH") { |
115 | return Ok(path.into()); | 91 | return Ok(path.into()); |
116 | } | 92 | } |
117 | let rustc_output = run_command_in_cargo_dir(cargo_toml, "rustc", &["--print", "sysroot"])?; | 93 | let current_dir = cargo_toml.parent().unwrap(); |
94 | let mut rustc = Command::new(ra_toolchain::rustc()); | ||
95 | rustc.current_dir(current_dir).args(&["--print", "sysroot"]); | ||
96 | let rustc_output = output(rustc)?; | ||
118 | let stdout = String::from_utf8(rustc_output.stdout)?; | 97 | let stdout = String::from_utf8(rustc_output.stdout)?; |
119 | let sysroot_path = Path::new(stdout.trim()); | 98 | let sysroot_path = Path::new(stdout.trim()); |
120 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); | 99 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); |
121 | 100 | ||
122 | if !src_path.exists() { | 101 | if !src_path.exists() { |
123 | run_command_in_cargo_dir(cargo_toml, "rustup", &["component", "add", "rust-src"])?; | 102 | let mut rustup = Command::new(ra_toolchain::rustup()); |
103 | rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]); | ||
104 | let _output = output(rustup)?; | ||
124 | } | 105 | } |
125 | if !src_path.exists() { | 106 | if !src_path.exists() { |
126 | bail!( | 107 | bail!( |