diff options
Diffstat (limited to 'xtask/src/install.rs')
-rw-r--r-- | xtask/src/install.rs | 118 |
1 files changed, 46 insertions, 72 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 99e1eddb1..00bbabce4 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | use std::{env, path::PathBuf, str}; | 3 | use std::{env, path::PathBuf, str}; |
4 | 4 | ||
5 | use anyhow::{Context, Result}; | 5 | use anyhow::{bail, format_err, Context, Result}; |
6 | 6 | ||
7 | use crate::cmd::{run, run_with_output, Cmd}; | 7 | use crate::not_bash::{ls, pushd, rm, run}; |
8 | 8 | ||
9 | // Latest stable, feel free to send a PR if this lags behind. | 9 | // Latest stable, feel free to send a PR if this lags behind. |
10 | const REQUIRED_RUST_VERSION: u32 = 41; | 10 | const REQUIRED_RUST_VERSION: u32 = 41; |
@@ -55,7 +55,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
55 | const ROOT_DIR: &str = ""; | 55 | const ROOT_DIR: &str = ""; |
56 | let home_dir = match env::var("HOME") { | 56 | let home_dir = match env::var("HOME") { |
57 | Ok(home) => home, | 57 | Ok(home) => home, |
58 | Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e), | 58 | Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), |
59 | }; | 59 | }; |
60 | 60 | ||
61 | [ROOT_DIR, &home_dir] | 61 | [ROOT_DIR, &home_dir] |
@@ -69,7 +69,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
69 | if !vscode_path.is_empty() { | 69 | if !vscode_path.is_empty() { |
70 | let vars = match env::var_os("PATH") { | 70 | let vars = match env::var_os("PATH") { |
71 | Some(path) => path, | 71 | Some(path) => path, |
72 | None => anyhow::bail!("Could not get PATH variable from env."), | 72 | None => bail!("Could not get PATH variable from env."), |
73 | }; | 73 | }; |
74 | 74 | ||
75 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | 75 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); |
@@ -82,84 +82,61 @@ fn fix_path_for_mac() -> Result<()> { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | 84 | fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { |
85 | let npm_version = Cmd { | 85 | let _dir = pushd("./editors/code"); |
86 | unix: r"npm --version", | ||
87 | windows: r"cmd.exe /c npm --version", | ||
88 | work_dir: "./editors/code", | ||
89 | } | ||
90 | .run(); | ||
91 | |||
92 | if npm_version.is_err() { | ||
93 | eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin") | ||
94 | } | ||
95 | 86 | ||
96 | Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" } | 87 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { |
97 | .run()?; | 88 | ["code", "code-insiders", "codium", "code-oss"] |
98 | Cmd { | 89 | .iter() |
99 | unix: r"npm run package --scripts-prepend-node-path", | 90 | .copied() |
100 | windows: r"cmd.exe /c npm run package", | 91 | .find(|bin| f(bin)) |
101 | work_dir: "./editors/code", | 92 | .ok_or_else(|| { |
102 | } | 93 | format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") |
103 | .run()?; | 94 | }) |
95 | }; | ||
104 | 96 | ||
105 | let code_binary = ["code", "code-insiders", "codium", "code-oss"].iter().find(|bin| { | 97 | let installed_extensions; |
106 | Cmd { | 98 | if cfg!(unix) { |
107 | unix: &format!("{} --version", bin), | 99 | run!("npm --version").context("`npm` is required to build the VS Code plugin")?; |
108 | windows: &format!("cmd.exe /c {}.cmd --version", bin), | 100 | run!("npm install")?; |
109 | work_dir: "./editors/code", | ||
110 | } | ||
111 | .run() | ||
112 | .is_ok() | ||
113 | }); | ||
114 | 101 | ||
115 | let code_binary = match code_binary { | 102 | let vsix_pkg = { |
116 | Some(it) => it, | 103 | rm("*.vsix")?; |
117 | None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), | 104 | run!("npm run package --scripts-prepend-node-path")?; |
118 | }; | 105 | ls("*.vsix")?.pop().unwrap() |
106 | }; | ||
119 | 107 | ||
120 | Cmd { | 108 | let code = find_code(|bin| run!("{} --version", bin).is_ok())?; |
121 | unix: &format!(r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force", code_binary), | 109 | run!("{} --install-extension {} --force", code, vsix_pkg.display())?; |
122 | windows: &format!( | 110 | installed_extensions = run!("{} --list-extensions", code; echo = false)?; |
123 | r"cmd.exe /c {}.cmd --install-extension ./rust-analyzer-0.1.0.vsix --force", | 111 | } else { |
124 | code_binary | 112 | run!("cmd.exe /c npm --version") |
125 | ), | 113 | .context("`npm` is required to build the VS Code plugin")?; |
126 | work_dir: "./editors/code", | 114 | run!("cmd.exe /c npm install")?; |
127 | } | 115 | |
128 | .run()?; | 116 | let vsix_pkg = { |
117 | rm("*.vsix")?; | ||
118 | run!("cmd.exe /c npm run package")?; | ||
119 | ls("*.vsix")?.pop().unwrap() | ||
120 | }; | ||
129 | 121 | ||
130 | let installed_extensions = Cmd { | 122 | let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?; |
131 | unix: &format!(r"{} --list-extensions", code_binary), | 123 | run!(r"cmd.exe /c {}.cmd --install-extension {} --force", code, vsix_pkg.display())?; |
132 | windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), | 124 | installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?; |
133 | work_dir: ".", | ||
134 | } | 125 | } |
135 | .run_with_output()?; | ||
136 | 126 | ||
137 | if !installed_extensions.contains("rust-analyzer") { | 127 | if !installed_extensions.contains("rust-analyzer") { |
138 | anyhow::bail!( | 128 | bail!( |
139 | "Could not install the Visual Studio Code extension. \ | 129 | "Could not install the Visual Studio Code extension. \ |
140 | Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again." | 130 | Please make sure you have at least NodeJS 12.x together with the latest version of VS Code installed and try again." |
141 | ); | 131 | ); |
142 | } | 132 | } |
143 | 133 | ||
144 | if installed_extensions.contains("ra-lsp") { | ||
145 | Cmd { | ||
146 | unix: &format!(r"{} --uninstall-extension matklad.ra-lsp", code_binary), | ||
147 | windows: &format!( | ||
148 | r"cmd.exe /c {}.cmd --uninstall-extension matklad.ra-lsp", | ||
149 | code_binary | ||
150 | ), | ||
151 | work_dir: "./editors/code", | ||
152 | } | ||
153 | .run()?; | ||
154 | } | ||
155 | |||
156 | Ok(()) | 134 | Ok(()) |
157 | } | 135 | } |
158 | 136 | ||
159 | fn install_server(opts: ServerOpt) -> Result<()> { | 137 | fn install_server(opts: ServerOpt) -> Result<()> { |
160 | let mut old_rust = false; | 138 | let mut old_rust = false; |
161 | if let Ok(stdout) = run_with_output("cargo --version", ".") { | 139 | if let Ok(stdout) = run!("cargo --version") { |
162 | println!("{}", stdout); | ||
163 | if !check_version(&stdout, REQUIRED_RUST_VERSION) { | 140 | if !check_version(&stdout, REQUIRED_RUST_VERSION) { |
164 | old_rust = true; | 141 | old_rust = true; |
165 | } | 142 | } |
@@ -172,20 +149,17 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
172 | ) | 149 | ) |
173 | } | 150 | } |
174 | 151 | ||
175 | let res = if opts.jemalloc { | 152 | let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" }; |
176 | run("cargo install --path crates/ra_lsp_server --locked --force --features jemalloc", ".") | 153 | let res = run!("cargo install --path crates/ra_lsp_server --locked --force {}", jemalloc); |
177 | } else { | ||
178 | run("cargo install --path crates/ra_lsp_server --locked --force", ".") | ||
179 | }; | ||
180 | 154 | ||
181 | if res.is_err() && old_rust { | 155 | if res.is_err() && old_rust { |
182 | eprintln!( | 156 | eprintln!( |
183 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 157 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", |
184 | REQUIRED_RUST_VERSION, | 158 | REQUIRED_RUST_VERSION, |
185 | ) | 159 | ); |
186 | } | 160 | } |
187 | 161 | ||
188 | res | 162 | res.map(drop) |
189 | } | 163 | } |
190 | 164 | ||
191 | fn check_version(version_output: &str, min_minor_version: u32) -> bool { | 165 | fn check_version(version_output: &str, min_minor_version: u32) -> bool { |