diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/tools/src/lib.rs | 36 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 21 |
2 files changed, 45 insertions, 12 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 3c23ed76e..1e29c63d4 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -2,7 +2,7 @@ use std::{ | |||
2 | fs, | 2 | fs, |
3 | collections::HashMap, | 3 | collections::HashMap, |
4 | path::{Path, PathBuf}, | 4 | path::{Path, PathBuf}, |
5 | process::{Command, Stdio}, | 5 | process::{Command, Output, Stdio}, |
6 | io::{Error, ErrorKind} | 6 | io::{Error, ErrorKind} |
7 | }; | 7 | }; |
8 | 8 | ||
@@ -80,15 +80,14 @@ pub fn project_root() -> PathBuf { | |||
80 | } | 80 | } |
81 | 81 | ||
82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | 82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { |
83 | eprintln!("\nwill run: {}", cmdline); | 83 | do_run(cmdline, dir, |c| { |
84 | let project_dir = project_root().join(dir); | 84 | c.stdout(Stdio::inherit()); |
85 | let mut args = cmdline.split_whitespace(); | 85 | }) |
86 | let exec = args.next().unwrap(); | 86 | .map(|_| ()) |
87 | let status = Command::new(exec).args(args).current_dir(project_dir).status()?; | 87 | } |
88 | if !status.success() { | 88 | |
89 | bail!("`{}` exited with {}", cmdline, status); | 89 | pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> { |
90 | } | 90 | do_run(cmdline, dir, |_| {}) |
91 | Ok(()) | ||
92 | } | 91 | } |
93 | 92 | ||
94 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 93 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
@@ -175,6 +174,23 @@ pub fn gen_tests(mode: Mode) -> Result<()> { | |||
175 | install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) | 174 | install_tests(&tests.err, ERR_INLINE_TESTS_DIR, mode) |
176 | } | 175 | } |
177 | 176 | ||
177 | fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> | ||
178 | where | ||
179 | F: FnMut(&mut Command), | ||
180 | { | ||
181 | eprintln!("\nwill run: {}", cmdline); | ||
182 | let proj_dir = project_root().join(dir); | ||
183 | let mut args = cmdline.split_whitespace(); | ||
184 | let exec = args.next().unwrap(); | ||
185 | let mut cmd = Command::new(exec); | ||
186 | f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); | ||
187 | let output = cmd.output()?; | ||
188 | if !output.status.success() { | ||
189 | bail!("`{}` exited with {}", cmdline, output.status); | ||
190 | } | ||
191 | Ok(output) | ||
192 | } | ||
193 | |||
178 | #[derive(Default, Debug)] | 194 | #[derive(Default, Debug)] |
179 | struct Tests { | 195 | struct Tests { |
180 | pub ok: HashMap<String, Test>, | 196 | pub ok: HashMap<String, Test>, |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 963ffbe98..4a1b2ff9a 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use clap::{App, SubCommand}; | 1 | use clap::{App, SubCommand}; |
2 | 2 | use core::str; | |
3 | use failure::bail; | ||
3 | use tools::{ | 4 | use tools::{ |
4 | generate, gen_tests, install_format_hook, run, run_rustfmt, | 5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, |
5 | Overwrite, Result, run_fuzzer, | 6 | Overwrite, Result, run_fuzzer, |
6 | }; | 7 | }; |
7 | 8 | ||
@@ -44,5 +45,21 @@ fn install_code_extension() -> Result<()> { | |||
44 | } else { | 45 | } else { |
45 | run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?; | 46 | run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?; |
46 | } | 47 | } |
48 | verify_installed_extensions()?; | ||
49 | Ok(()) | ||
50 | } | ||
51 | |||
52 | fn verify_installed_extensions() -> Result<()> { | ||
53 | let exts = if cfg!(windows) { | ||
54 | run_with_output(r"cmd.exe /c code.cmd --list-extensions", ".")? | ||
55 | } else { | ||
56 | run_with_output(r"code --list-extensions", ".")? | ||
57 | }; | ||
58 | if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") { | ||
59 | bail!( | ||
60 | "Could not install the Visual Studio Code extension. Please make sure you \ | ||
61 | have at least NodeJS 10.x installed and try again." | ||
62 | ); | ||
63 | } | ||
47 | Ok(()) | 64 | Ok(()) |
48 | } | 65 | } |