aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_tools/Cargo.toml3
-rw-r--r--crates/ra_tools/src/bin/pre-commit.rs7
-rw-r--r--crates/ra_tools/src/lib.rs14
-rw-r--r--crates/ra_tools/src/main.rs11
4 files changed, 16 insertions, 19 deletions
diff --git a/crates/ra_tools/Cargo.toml b/crates/ra_tools/Cargo.toml
index 35ea3231b..9c5430992 100644
--- a/crates/ra_tools/Cargo.toml
+++ b/crates/ra_tools/Cargo.toml
@@ -6,8 +6,7 @@ authors = ["rust-analyzer developers"]
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
9teraron = "0.0.1" 9teraron = "0.1.0"
10walkdir = "2.1.3" 10walkdir = "2.1.3"
11itertools = "0.8.0" 11itertools = "0.8.0"
12clap = "2.32.0" 12clap = "2.32.0"
13failure = "0.1.4"
diff --git a/crates/ra_tools/src/bin/pre-commit.rs b/crates/ra_tools/src/bin/pre-commit.rs
index c514e992b..95bb55cae 100644
--- a/crates/ra_tools/src/bin/pre-commit.rs
+++ b/crates/ra_tools/src/bin/pre-commit.rs
@@ -1,7 +1,5 @@
1use std::process::Command; 1use std::process::Command;
2 2
3use failure::bail;
4
5use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite}; 3use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite};
6 4
7fn main() -> Result<()> { 5fn main() -> Result<()> {
@@ -19,7 +17,10 @@ fn update_staged() -> Result<()> {
19 .current_dir(&root) 17 .current_dir(&root)
20 .output()?; 18 .output()?;
21 if !output.status.success() { 19 if !output.status.success() {
22 bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status); 20 Err(format!(
21 "`git diff --diff-filter=MAR --name-only --cached` exited with {}",
22 output.status
23 ))?;
23 } 24 }
24 for line in String::from_utf8(output.stdout)?.lines() { 25 for line in String::from_utf8(output.stdout)?.lines() {
25 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; 26 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index 61f6b08cd..821209567 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -3,15 +3,15 @@ use std::{
3 collections::HashMap, 3 collections::HashMap,
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
5 process::{Command, Output, Stdio}, 5 process::{Command, Output, Stdio},
6 io::{Error, ErrorKind} 6 io::{Error as IoError, ErrorKind},
7 error::Error
7}; 8};
8 9
9use failure::bail;
10use itertools::Itertools; 10use itertools::Itertools;
11 11
12pub use teraron::{Mode, Overwrite, Verify}; 12pub use teraron::{Mode, Overwrite, Verify};
13 13
14pub type Result<T> = std::result::Result<T, failure::Error>; 14pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
15 15
16pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; 16pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
17const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; 17const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
@@ -128,7 +128,7 @@ pub fn install_format_hook() -> Result<()> {
128 fs::copy("./target/debug/pre-commit", result_path)?; 128 fs::copy("./target/debug/pre-commit", result_path)?;
129 } 129 }
130 } else { 130 } else {
131 return Err(Error::new(ErrorKind::AlreadyExists, "Git hook already created").into()); 131 Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?;
132 } 132 }
133 Ok(()) 133 Ok(())
134} 134}
@@ -224,7 +224,7 @@ where
224 f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit())); 224 f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
225 let output = cmd.output()?; 225 let output = cmd.output()?;
226 if !output.status.success() { 226 if !output.status.success() {
227 bail!("`{}` exited with {}", cmdline, output.status); 227 Err(format!("`{}` exited with {}", cmdline, output.status))?;
228 } 228 }
229 Ok(output) 229 Ok(output)
230} 230}
@@ -256,11 +256,11 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> {
256 for (_, test) in collect_tests(&text) { 256 for (_, test) in collect_tests(&text) {
257 if test.ok { 257 if test.ok {
258 if let Some(old_test) = res.ok.insert(test.name.clone(), test) { 258 if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
259 bail!("Duplicate test: {}", old_test.name) 259 Err(format!("Duplicate test: {}", old_test.name))?
260 } 260 }
261 } else { 261 } else {
262 if let Some(old_test) = res.err.insert(test.name.clone(), test) { 262 if let Some(old_test) = res.err.insert(test.name.clone(), test) {
263 bail!("Duplicate test: {}", old_test.name) 263 Err(format!("Duplicate test: {}", old_test.name))?
264 } 264 }
265 } 265 }
266 } 266 }
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index 285071ea5..846e0223e 100644
--- a/crates/ra_tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -1,6 +1,5 @@
1use clap::{App, SubCommand}; 1use clap::{App, SubCommand};
2use core::str; 2use core::str;
3use failure::bail;
4use ra_tools::{ 3use ra_tools::{
5 generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, 4 generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
6 Overwrite, Result, run_fuzzer, run_clippy, 5 Overwrite, Result, run_fuzzer, run_clippy,
@@ -64,10 +63,8 @@ fn verify_installed_extensions() -> Result<()> {
64 run_with_output(r"code --list-extensions", ".")? 63 run_with_output(r"code --list-extensions", ".")?
65 }; 64 };
66 if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") { 65 if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
67 bail!( 66 Err("Could not install the Visual Studio Code extension. Please make sure you \
68 "Could not install the Visual Studio Code extension. Please make sure you \ 67 have at least NodeJS 10.x installed and try again.")?;
69 have at least NodeJS 10.x installed and try again."
70 );
71 } 68 }
72 Ok(()) 69 Ok(())
73} 70}
@@ -79,7 +76,7 @@ fn fix_path_for_mac() -> Result<()> {
79 const ROOT_DIR: &str = ""; 76 const ROOT_DIR: &str = "";
80 let home_dir = match env::var("HOME") { 77 let home_dir = match env::var("HOME") {
81 Ok(home) => home, 78 Ok(home) => home,
82 Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), 79 Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?,
83 }; 80 };
84 81
85 [ROOT_DIR, &home_dir] 82 [ROOT_DIR, &home_dir]
@@ -93,7 +90,7 @@ fn fix_path_for_mac() -> Result<()> {
93 if !vscode_path.is_empty() { 90 if !vscode_path.is_empty() {
94 let vars = match env::var_os("PATH") { 91 let vars = match env::var_os("PATH") {
95 Some(path) => path, 92 Some(path) => path,
96 None => bail!("Could not get PATH variable from env."), 93 None => Err("Could not get PATH variable from env.")?,
97 }; 94 };
98 95
99 let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); 96 let mut paths = env::split_paths(&vars).collect::<Vec<_>>();