aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Disselkoen <[email protected]>2020-05-05 22:07:10 +0100
committerCraig Disselkoen <[email protected]>2020-05-06 00:12:56 +0100
commit303b444dbb66019fc916dd350e54f7675aa3007f (patch)
tree163086a232e07ed91452122da5346383adaca58f
parent5aa1bba107ef434e61c3136120b9478a307d67a9 (diff)
pull function out into new crate ra_env; use in ra_flycheck as well
-rw-r--r--Cargo.lock11
-rw-r--r--crates/ra_env/Cargo.toml9
-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.toml1
-rw-r--r--crates/ra_flycheck/src/lib.rs8
-rw-r--r--crates/ra_project_model/Cargo.toml5
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs4
-rw-r--r--crates/ra_project_model/src/sysroot.rs5
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]]
1003name = "ra_env"
1004version = "0.1.0"
1005dependencies = [
1006 "anyhow",
1007 "dirs",
1008]
1009
1010[[package]]
1003name = "ra_flycheck" 1011name = "ra_flycheck"
1004version = "0.1.0" 1012version = "0.1.0"
1005dependencies = [ 1013dependencies = [
@@ -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"
1209dependencies = [ 1218dependencies = [
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]
2edition = "2018"
3name = "ra_env"
4version = "0.1.0"
5authors = ["rust-analyzer developers"]
6
7[dependencies]
8anyhow = "1.0.26"
9dirs = "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"
14cargo_metadata = "0.9.1" 14cargo_metadata = "0.9.1"
15serde_json = "1.0.48" 15serde_json = "1.0.48"
16jod-thread = "0.1.1" 16jod-thread = "0.1.1"
17ra_env = { path = "../ra_env" }
17 18
18[dev-dependencies] 19[dev-dependencies]
19insta = "0.16.0" 20insta = "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 @@
4mod conv; 4mod conv;
5 5
6use std::{ 6use 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};
19use ra_env::get_path_for_executable;
20 20
21use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic}; 21use 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
341fn 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"
14cargo_metadata = "0.9.1" 14cargo_metadata = "0.9.1"
15 15
16ra_arena = { path = "../ra_arena" } 16ra_arena = { path = "../ra_arena" }
17ra_db = { path = "../ra_db" }
18ra_cfg = { path = "../ra_cfg" } 17ra_cfg = { path = "../ra_cfg" }
18ra_db = { path = "../ra_db" }
19ra_env = { path = "../ra_env" }
19ra_proc_macro = { path = "../ra_proc_macro" } 20ra_proc_macro = { path = "../ra_proc_macro" }
20 21
21serde = { version = "1.0.106", features = ["derive"] } 22serde = { version = "1.0.106", features = ["derive"] }
22serde_json = "1.0.48" 23serde_json = "1.0.48"
23 24
24anyhow = "1.0.26" 25anyhow = "1.0.26"
25
26dirs = "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
10use super::find_executables::get_path_for_executable;
11use anyhow::{Context, Result}; 10use anyhow::{Context, Result};
12use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId}; 11use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId};
13use ra_arena::{Arena, Idx}; 12use ra_arena::{Arena, Idx};
14use ra_db::Edition; 13use ra_db::Edition;
14use ra_env::get_path_for_executable;
15use rustc_hash::FxHashMap; 15use 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
3mod cargo_workspace; 3mod cargo_workspace;
4mod find_executables;
5mod json_project; 4mod json_project;
6mod sysroot; 5mod sysroot;
7 6
@@ -15,6 +14,7 @@ use std::{
15use anyhow::{bail, Context, Result}; 14use anyhow::{bail, Context, Result};
16use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
17use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; 16use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
17use ra_env::get_path_for_executable;
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use serde_json::from_reader; 19use 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
3use super::find_executables::get_path_for_executable;
4use anyhow::{bail, Context, Result}; 3use anyhow::{bail, Context, Result};
5use std::{ 4use std::{
6 env, ops, 5 env, ops,
@@ -9,6 +8,7 @@ use std::{
9}; 8};
10 9
11use ra_arena::{Arena, Idx}; 10use ra_arena::{Arena, Idx};
11use ra_env::get_path_for_executable;
12 12
13#[derive(Default, Debug, Clone)] 13#[derive(Default, Debug, Clone)]
14pub struct Sysroot { 14pub 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!(