diff options
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r-- | crates/tools/src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 91c35b9e1..29c46c7c4 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -4,9 +4,11 @@ extern crate teraron; | |||
4 | 4 | ||
5 | use std::{ | 5 | use std::{ |
6 | path::{Path, PathBuf}, | 6 | path::{Path, PathBuf}, |
7 | process::Command, | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | use itertools::Itertools; | 10 | use itertools::Itertools; |
11 | use failure::bail; | ||
10 | 12 | ||
11 | pub use teraron::{Mode, Verify, Overwrite}; | 13 | pub use teraron::{Mode, Verify, Overwrite}; |
12 | 14 | ||
@@ -15,6 +17,7 @@ pub type Result<T> = ::std::result::Result<T, failure::Error>; | |||
15 | pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; | 17 | pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; |
16 | pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera"; | 18 | pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera"; |
17 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; | 19 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; |
20 | const TOOLCHAIN: &str = "beta-2018-10-30"; | ||
18 | 21 | ||
19 | #[derive(Debug)] | 22 | #[derive(Debug)] |
20 | pub struct Test { | 23 | pub struct Test { |
@@ -80,3 +83,29 @@ pub fn project_root() -> PathBuf { | |||
80 | .unwrap() | 83 | .unwrap() |
81 | .to_path_buf() | 84 | .to_path_buf() |
82 | } | 85 | } |
86 | |||
87 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | ||
88 | eprintln!("\nwill run: {}", cmdline); | ||
89 | let project_dir = project_root().join(dir); | ||
90 | let mut args = cmdline.split_whitespace(); | ||
91 | let exec = args.next().unwrap(); | ||
92 | let status = Command::new(exec) | ||
93 | .args(args) | ||
94 | .current_dir(project_dir) | ||
95 | .status()?; | ||
96 | if !status.success() { | ||
97 | bail!("`{}` exited with {}", cmdline, status); | ||
98 | } | ||
99 | Ok(()) | ||
100 | } | ||
101 | |||
102 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | ||
103 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | ||
104 | run(&format!("rustup component add rustfmt-preview --toolchain {}", TOOLCHAIN), ".")?; | ||
105 | if mode == Verify { | ||
106 | run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; | ||
107 | } else { | ||
108 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; | ||
109 | } | ||
110 | Ok(()) | ||
111 | } | ||