aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r--crates/tools/src/lib.rs29
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
5use std::{ 5use std::{
6 path::{Path, PathBuf}, 6 path::{Path, PathBuf},
7 process::Command,
7}; 8};
8 9
9use itertools::Itertools; 10use itertools::Itertools;
11use failure::bail;
10 12
11pub use teraron::{Mode, Verify, Overwrite}; 13pub use teraron::{Mode, Verify, Overwrite};
12 14
@@ -15,6 +17,7 @@ pub type Result<T> = ::std::result::Result<T, failure::Error>;
15pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; 17pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
16pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera"; 18pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera";
17pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; 19pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera";
20const TOOLCHAIN: &str = "beta-2018-10-30";
18 21
19#[derive(Debug)] 22#[derive(Debug)]
20pub struct Test { 23pub 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
87pub 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
102pub 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}