aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src
diff options
context:
space:
mode:
authorMuhammad Mominul Huque <[email protected]>2018-10-31 19:50:43 +0000
committerAleksey Kladov <[email protected]>2018-10-31 20:39:21 +0000
commit857c1650efdb51650458f9ec1119adaa49b34371 (patch)
treef6239e330db9880f1f0712032eb98645f719c363 /crates/tools/src
parentd14610dab4b4fedee7a0d8f1739eb3e0691984c1 (diff)
Various changes
Pin to a specific toolchain version Format checking functionality Add a test to check the code formatting. Remove macro_use attribute
Diffstat (limited to 'crates/tools/src')
-rw-r--r--crates/tools/src/lib.rs29
-rw-r--r--crates/tools/src/main.rs30
2 files changed, 32 insertions, 27 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}
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index bc5ad6fa8..91675bbf0 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -1,5 +1,4 @@
1extern crate clap; 1extern crate clap;
2#[macro_use]
3extern crate failure; 2extern crate failure;
4extern crate tools; 3extern crate tools;
5extern crate walkdir; 4extern crate walkdir;
@@ -10,11 +9,11 @@ use std::{
10 collections::HashMap, 9 collections::HashMap,
11 fs, 10 fs,
12 path::{Path, PathBuf}, 11 path::{Path, PathBuf},
13 process::Command,
14}; 12};
15use tools::{ 13use tools::{
16 collect_tests, Result, Test, generate, Mode, Overwrite, Verify, project_root, 14 collect_tests, Result, Test, generate, Mode, Overwrite, Verify, run, run_rustfmt,
17}; 15};
16use failure::bail;
18 17
19const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; 18const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
20const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline"; 19const INLINE_TESTS_DIR: &str = "./crates/ra_syntax/tests/data/parser/inline";
@@ -42,7 +41,7 @@ fn main() -> Result<()> {
42 ("install-code", _) => install_code_extension()?, 41 ("install-code", _) => install_code_extension()?,
43 ("gen-tests", _) => gen_tests(mode)?, 42 ("gen-tests", _) => gen_tests(mode)?,
44 ("gen-syntax", _) => generate(Overwrite)?, 43 ("gen-syntax", _) => generate(Overwrite)?,
45 ("format", _) => run_rustfmt()?, 44 ("format", _) => run_rustfmt(Overwrite)?,
46 _ => unreachable!(), 45 _ => unreachable!(),
47 } 46 }
48 Ok(()) 47 Ok(())
@@ -145,26 +144,3 @@ fn install_code_extension() -> Result<()> {
145 } 144 }
146 Ok(()) 145 Ok(())
147} 146}
148
149fn run(cmdline: &'static str, dir: &str) -> Result<()> {
150 eprintln!("\nwill run: {}", cmdline);
151 let project_dir = project_root().join(dir);
152 let mut args = cmdline.split_whitespace();
153 let exec = args.next().unwrap();
154 let status = Command::new(exec)
155 .args(args)
156 .current_dir(project_dir)
157 .status()?;
158 if !status.success() {
159 bail!("`{}` exited with {}", cmdline, status);
160 }
161 Ok(())
162}
163
164fn run_rustfmt() -> Result<()> {
165 // Use beta toolchain for 2018 edition.
166 run("rustup install beta", ".")?;
167 run("rustup component add rustfmt-preview --toolchain beta", ".")?;
168 run("rustup run beta -- cargo fmt", ".")?;
169 Ok(())
170}