diff options
author | Craig Disselkoen <[email protected]> | 2020-05-05 22:07:10 +0100 |
---|---|---|
committer | Craig Disselkoen <[email protected]> | 2020-05-06 00:12:56 +0100 |
commit | 303b444dbb66019fc916dd350e54f7675aa3007f (patch) | |
tree | 163086a232e07ed91452122da5346383adaca58f | |
parent | 5aa1bba107ef434e61c3136120b9478a307d67a9 (diff) |
pull function out into new crate ra_env; use in ra_flycheck as well
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | crates/ra_env/Cargo.toml | 9 | ||||
-rw-r--r-- | crates/ra_env/src/lib.rs (renamed from crates/ra_project_model/src/find_executables.rs) | 2 | ||||
-rw-r--r-- | crates/ra_flycheck/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_flycheck/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_project_model/Cargo.toml | 5 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 5 |
9 files changed, 31 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock index b2d4569b3..28424b7d4 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1000,6 +1000,14 @@ dependencies = [ | |||
1000 | ] | 1000 | ] |
1001 | 1001 | ||
1002 | [[package]] | 1002 | [[package]] |
1003 | name = "ra_env" | ||
1004 | version = "0.1.0" | ||
1005 | dependencies = [ | ||
1006 | "anyhow", | ||
1007 | "dirs", | ||
1008 | ] | ||
1009 | |||
1010 | [[package]] | ||
1003 | name = "ra_flycheck" | 1011 | name = "ra_flycheck" |
1004 | version = "0.1.0" | 1012 | version = "0.1.0" |
1005 | dependencies = [ | 1013 | dependencies = [ |
@@ -1009,6 +1017,7 @@ dependencies = [ | |||
1009 | "jod-thread", | 1017 | "jod-thread", |
1010 | "log", | 1018 | "log", |
1011 | "lsp-types", | 1019 | "lsp-types", |
1020 | "ra_env", | ||
1012 | "serde_json", | 1021 | "serde_json", |
1013 | ] | 1022 | ] |
1014 | 1023 | ||
@@ -1209,11 +1218,11 @@ version = "0.1.0" | |||
1209 | dependencies = [ | 1218 | dependencies = [ |
1210 | "anyhow", | 1219 | "anyhow", |
1211 | "cargo_metadata", | 1220 | "cargo_metadata", |
1212 | "dirs", | ||
1213 | "log", | 1221 | "log", |
1214 | "ra_arena", | 1222 | "ra_arena", |
1215 | "ra_cfg", | 1223 | "ra_cfg", |
1216 | "ra_db", | 1224 | "ra_db", |
1225 | "ra_env", | ||
1217 | "ra_proc_macro", | 1226 | "ra_proc_macro", |
1218 | "rustc-hash", | 1227 | "rustc-hash", |
1219 | "serde", | 1228 | "serde", |
diff --git a/crates/ra_env/Cargo.toml b/crates/ra_env/Cargo.toml new file mode 100644 index 000000000..7fed446a7 --- /dev/null +++ b/crates/ra_env/Cargo.toml | |||
@@ -0,0 +1,9 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_env" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | |||
7 | [dependencies] | ||
8 | anyhow = "1.0.26" | ||
9 | dirs = "2.0" | ||
diff --git a/crates/ra_project_model/src/find_executables.rs b/crates/ra_env/src/lib.rs index 9b020d3da..cb9fbf80c 100644 --- a/crates/ra_project_model/src/find_executables.rs +++ b/crates/ra_env/src/lib.rs | |||
@@ -13,7 +13,7 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<Strin | |||
13 | // 1) Appropriate environment variable (erroring if this is set but not a usable executable) | 13 | // 1) Appropriate environment variable (erroring if this is set but not a usable executable) |
14 | // example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc | 14 | // example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc |
15 | // 2) `<executable_name>` | 15 | // 2) `<executable_name>` |
16 | // example: for cargo, this tries just `cargo`, which will succeed if `cargo` in on the $PATH | 16 | // example: for cargo, this tries just `cargo`, which will succeed if `cargo` is on the $PATH |
17 | // 3) `~/.cargo/bin/<executable_name>` | 17 | // 3) `~/.cargo/bin/<executable_name>` |
18 | // example: for cargo, this tries ~/.cargo/bin/cargo | 18 | // example: for cargo, this tries ~/.cargo/bin/cargo |
19 | // It seems that this is a reasonable place to try for cargo, rustc, and rustup | 19 | // It seems that this is a reasonable place to try for cargo, rustc, and rustup |
diff --git a/crates/ra_flycheck/Cargo.toml b/crates/ra_flycheck/Cargo.toml index 3d5093264..d0f7fb2dc 100644 --- a/crates/ra_flycheck/Cargo.toml +++ b/crates/ra_flycheck/Cargo.toml | |||
@@ -14,6 +14,7 @@ log = "0.4.8" | |||
14 | cargo_metadata = "0.9.1" | 14 | cargo_metadata = "0.9.1" |
15 | serde_json = "1.0.48" | 15 | serde_json = "1.0.48" |
16 | jod-thread = "0.1.1" | 16 | jod-thread = "0.1.1" |
17 | ra_env = { path = "../ra_env" } | ||
17 | 18 | ||
18 | [dev-dependencies] | 19 | [dev-dependencies] |
19 | insta = "0.16.0" | 20 | insta = "0.16.0" |
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index f27252949..d8b727b0e 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs | |||
@@ -4,7 +4,6 @@ | |||
4 | mod conv; | 4 | mod conv; |
5 | 5 | ||
6 | use std::{ | 6 | use std::{ |
7 | env, | ||
8 | io::{self, BufRead, BufReader}, | 7 | io::{self, BufRead, BufReader}, |
9 | path::PathBuf, | 8 | path::PathBuf, |
10 | process::{Command, Stdio}, | 9 | process::{Command, Stdio}, |
@@ -17,6 +16,7 @@ use lsp_types::{ | |||
17 | CodeAction, CodeActionOrCommand, Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, | 16 | CodeAction, CodeActionOrCommand, Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, |
18 | WorkDoneProgressEnd, WorkDoneProgressReport, | 17 | WorkDoneProgressEnd, WorkDoneProgressReport, |
19 | }; | 18 | }; |
19 | use ra_env::get_path_for_executable; | ||
20 | 20 | ||
21 | use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic}; | 21 | use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic}; |
22 | 22 | ||
@@ -216,7 +216,7 @@ impl FlycheckThread { | |||
216 | 216 | ||
217 | let mut cmd = match &self.config { | 217 | let mut cmd = match &self.config { |
218 | FlycheckConfig::CargoCommand { command, all_targets, all_features, extra_args } => { | 218 | FlycheckConfig::CargoCommand { command, all_targets, all_features, extra_args } => { |
219 | let mut cmd = Command::new(cargo_binary()); | 219 | let mut cmd = Command::new(get_path_for_executable("cargo").unwrap()); |
220 | cmd.arg(command); | 220 | cmd.arg(command); |
221 | cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]); | 221 | cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]); |
222 | cmd.arg(self.workspace_root.join("Cargo.toml")); | 222 | cmd.arg(self.workspace_root.join("Cargo.toml")); |
@@ -337,7 +337,3 @@ fn run_cargo( | |||
337 | 337 | ||
338 | Ok(()) | 338 | Ok(()) |
339 | } | 339 | } |
340 | |||
341 | fn cargo_binary() -> String { | ||
342 | env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()) | ||
343 | } | ||
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index 91958ed94..626478468 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -14,13 +14,12 @@ rustc-hash = "1.1.0" | |||
14 | cargo_metadata = "0.9.1" | 14 | cargo_metadata = "0.9.1" |
15 | 15 | ||
16 | ra_arena = { path = "../ra_arena" } | 16 | ra_arena = { path = "../ra_arena" } |
17 | ra_db = { path = "../ra_db" } | ||
18 | ra_cfg = { path = "../ra_cfg" } | 17 | ra_cfg = { path = "../ra_cfg" } |
18 | ra_db = { path = "../ra_db" } | ||
19 | ra_env = { path = "../ra_env" } | ||
19 | ra_proc_macro = { path = "../ra_proc_macro" } | 20 | ra_proc_macro = { path = "../ra_proc_macro" } |
20 | 21 | ||
21 | serde = { version = "1.0.106", features = ["derive"] } | 22 | serde = { version = "1.0.106", features = ["derive"] } |
22 | serde_json = "1.0.48" | 23 | serde_json = "1.0.48" |
23 | 24 | ||
24 | anyhow = "1.0.26" | 25 | anyhow = "1.0.26" |
25 | |||
26 | dirs = "2.0" | ||
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index c7350d1e0..4027f020f 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -7,11 +7,11 @@ use std::{ | |||
7 | process::Command, | 7 | process::Command, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use super::find_executables::get_path_for_executable; | ||
11 | use anyhow::{Context, Result}; | 10 | use anyhow::{Context, Result}; |
12 | use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId}; | 11 | use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId}; |
13 | use ra_arena::{Arena, Idx}; | 12 | use ra_arena::{Arena, Idx}; |
14 | use ra_db::Edition; | 13 | use ra_db::Edition; |
14 | use ra_env::get_path_for_executable; | ||
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
16 | 16 | ||
17 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo | 17 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 5028b6b6d..e4b86f1e2 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | mod cargo_workspace; | 3 | mod cargo_workspace; |
4 | mod find_executables; | ||
5 | mod json_project; | 4 | mod json_project; |
6 | mod sysroot; | 5 | mod sysroot; |
7 | 6 | ||
@@ -15,6 +14,7 @@ use std::{ | |||
15 | use anyhow::{bail, Context, Result}; | 14 | use anyhow::{bail, Context, Result}; |
16 | use ra_cfg::CfgOptions; | 15 | use ra_cfg::CfgOptions; |
17 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; | 16 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; |
17 | use ra_env::get_path_for_executable; | ||
18 | use rustc_hash::FxHashMap; | 18 | use rustc_hash::FxHashMap; |
19 | use serde_json::from_reader; | 19 | use serde_json::from_reader; |
20 | 20 | ||
@@ -559,7 +559,7 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { | |||
559 | 559 | ||
560 | match (|| -> Result<String> { | 560 | match (|| -> Result<String> { |
561 | // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. | 561 | // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. |
562 | let mut cmd = Command::new("rustc"); | 562 | let mut cmd = Command::new(get_path_for_executable("rustc")?); |
563 | cmd.args(&["--print", "cfg", "-O"]); | 563 | cmd.args(&["--print", "cfg", "-O"]); |
564 | if let Some(target) = target { | 564 | if let Some(target) = target { |
565 | cmd.args(&["--target", target.as_str()]); | 565 | cmd.args(&["--target", target.as_str()]); |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 8d68032b2..516e0472d 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use super::find_executables::get_path_for_executable; | ||
4 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
5 | use std::{ | 4 | use std::{ |
6 | env, ops, | 5 | env, ops, |
@@ -9,6 +8,7 @@ use std::{ | |||
9 | }; | 8 | }; |
10 | 9 | ||
11 | use ra_arena::{Arena, Idx}; | 10 | use ra_arena::{Arena, Idx}; |
11 | use ra_env::get_path_for_executable; | ||
12 | 12 | ||
13 | #[derive(Default, Debug, Clone)] | 13 | #[derive(Default, Debug, Clone)] |
14 | pub struct Sysroot { | 14 | pub struct Sysroot { |
@@ -122,7 +122,8 @@ fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> { | |||
122 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); | 122 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); |
123 | 123 | ||
124 | if !src_path.exists() { | 124 | if !src_path.exists() { |
125 | run_command_in_cargo_dir(cargo_toml, "rustup", &["component", "add", "rust-src"])?; | 125 | let rustup = get_path_for_executable("rustup")?; |
126 | run_command_in_cargo_dir(cargo_toml, &rustup, &["component", "add", "rust-src"])?; | ||
126 | } | 127 | } |
127 | if !src_path.exists() { | 128 | if !src_path.exists() { |
128 | bail!( | 129 | bail!( |