aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfunkill2 <[email protected]>2019-03-18 19:18:54 +0000
committerfunkill2 <[email protected]>2019-03-18 19:18:54 +0000
commit69edc10f3529add3de65b62a7304d3fc258c7a62 (patch)
treefc171e22b9698f7f238740cf2e2d3bdbf6f7d962
parent9c2177026f5fac8464a610a426a974cf691b2a89 (diff)
set code less generic
-rw-r--r--crates/tools/src/main.rs74
1 files changed, 24 insertions, 50 deletions
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index 6583b700c..0c3339685 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -5,6 +5,7 @@ use tools::{
5 generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, 5 generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
6 Overwrite, Result, run_fuzzer, 6 Overwrite, Result, run_fuzzer,
7}; 7};
8use std::{path::{PathBuf}, env};
8 9
9fn main() -> Result<()> { 10fn main() -> Result<()> {
10 let matches = App::new("tasks") 11 let matches = App::new("tasks")
@@ -18,7 +19,9 @@ fn main() -> Result<()> {
18 .get_matches(); 19 .get_matches();
19 match matches.subcommand_name().expect("Subcommand must be specified") { 20 match matches.subcommand_name().expect("Subcommand must be specified") {
20 "install-code" => { 21 "install-code" => {
21 setup_environment()?; 22 if cfg!(target_os = "macos") {
23 fix_path_for_mac()?;
24 }
22 install_code_extension()?; 25 install_code_extension()?;
23 } 26 }
24 "gen-tests" => gen_tests(Overwrite)?, 27 "gen-tests" => gen_tests(Overwrite)?,
@@ -31,14 +34,6 @@ fn main() -> Result<()> {
31 Ok(()) 34 Ok(())
32} 35}
33 36
34fn setup_environment() -> Result<()> {
35 if cfg!(target_os = "macos") {
36 vscode_path_helpers::append_vscode_path()?;
37 }
38
39 Ok(())
40}
41
42fn install_code_extension() -> Result<()> { 37fn install_code_extension() -> Result<()> {
43 run("cargo install --path crates/ra_lsp_server --force", ".")?; 38 run("cargo install --path crates/ra_lsp_server --force", ".")?;
44 if cfg!(windows) { 39 if cfg!(windows) {
@@ -75,28 +70,8 @@ fn verify_installed_extensions() -> Result<()> {
75 Ok(()) 70 Ok(())
76} 71}
77 72
78#[cfg(target_os = "macos")] 73fn fix_path_for_mac() -> Result<()> {
79mod vscode_path_helpers { 74 let mut vscode_path: Vec<PathBuf> = {
80 use super::Result;
81 use std::{path::{PathBuf}, env};
82 use failure::bail;
83
84 pub(crate) fn append_vscode_path() -> Result<()> {
85 let vars = match env::var_os("PATH") {
86 Some(path) => path,
87 None => bail!("Could not get PATH variable from env."),
88 };
89
90 let vscode_path = get_vscode_path()?;
91 let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
92 paths.push(vscode_path);
93 let new_paths = env::join_paths(paths)?;
94 env::set_var("PATH", &new_paths);
95
96 Ok(())
97 }
98
99 fn get_vscode_path() -> Result<PathBuf> {
100 const COMMON_APP_PATH: &str = 75 const COMMON_APP_PATH: &str =
101 r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin"; 76 r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin";
102 const ROOT_DIR: &str = ""; 77 const ROOT_DIR: &str = "";
@@ -105,26 +80,25 @@ mod vscode_path_helpers {
105 Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), 80 Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
106 }; 81 };
107 82
108 for dir in [ROOT_DIR, &home_dir].iter() { 83 [ROOT_DIR, &home_dir]
109 let path = String::from(dir.clone()) + COMMON_APP_PATH; 84 .iter()
110 let path = PathBuf::from(path); 85 .map(|dir| String::from(dir.clone()) + COMMON_APP_PATH)
111 if path.exists() { 86 .map(PathBuf::from)
112 return Ok(path); 87 .filter(|path| path.exists())
113 } 88 .collect()
114 } 89 };
115 90
116 bail!( 91 if !vscode_path.is_empty() {
117 "Could not find Visual Studio Code application. Please make sure you \ 92 let vars = match env::var_os("PATH") {
118 have Visual Studio Code installed and try again or install extension \ 93 Some(path) => path,
119 manually." 94 None => bail!("Could not get PATH variable from env."),
120 ) 95 };
121 }
122}
123 96
124#[cfg(not(target_os = "macos"))] 97 let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
125mod vscode_path_helpers { 98 paths.append(&mut vscode_path);
126 use super::Result; 99 let new_paths = env::join_paths(paths)?;
127 pub(crate) fn append_vscode_path() -> Result<()> { 100 env::set_var("PATH", &new_paths);
128 Ok(())
129 } 101 }
102
103 Ok(())
130} 104}