aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tools/src/main.rs')
-rw-r--r--crates/tools/src/main.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index fdb443690..bc5ad6fa8 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -13,7 +13,7 @@ use std::{
13 process::Command, 13 process::Command,
14}; 14};
15use tools::{ 15use tools::{
16 collect_tests, Result, Test, generate, Mode, Overwrite, Verify, 16 collect_tests, Result, Test, generate, Mode, Overwrite, Verify, project_root,
17}; 17};
18 18
19const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; 19const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
@@ -31,6 +31,7 @@ fn main() -> Result<()> {
31 .subcommand(SubCommand::with_name("gen-syntax")) 31 .subcommand(SubCommand::with_name("gen-syntax"))
32 .subcommand(SubCommand::with_name("gen-tests")) 32 .subcommand(SubCommand::with_name("gen-tests"))
33 .subcommand(SubCommand::with_name("install-code")) 33 .subcommand(SubCommand::with_name("install-code"))
34 .subcommand(SubCommand::with_name("format"))
34 .get_matches(); 35 .get_matches();
35 let mode = if matches.is_present("verify") { 36 let mode = if matches.is_present("verify") {
36 Verify 37 Verify
@@ -41,6 +42,7 @@ fn main() -> Result<()> {
41 ("install-code", _) => install_code_extension()?, 42 ("install-code", _) => install_code_extension()?,
42 ("gen-tests", _) => gen_tests(mode)?, 43 ("gen-tests", _) => gen_tests(mode)?,
43 ("gen-syntax", _) => generate(Overwrite)?, 44 ("gen-syntax", _) => generate(Overwrite)?,
45 ("format", _) => run_rustfmt()?,
44 _ => unreachable!(), 46 _ => unreachable!(),
45 } 47 }
46 Ok(()) 48 Ok(())
@@ -146,12 +148,7 @@ fn install_code_extension() -> Result<()> {
146 148
147fn run(cmdline: &'static str, dir: &str) -> Result<()> { 149fn run(cmdline: &'static str, dir: &str) -> Result<()> {
148 eprintln!("\nwill run: {}", cmdline); 150 eprintln!("\nwill run: {}", cmdline);
149 let manifest_dir = env!("CARGO_MANIFEST_DIR"); 151 let project_dir = project_root().join(dir);
150 let project_dir = Path::new(manifest_dir)
151 .ancestors()
152 .nth(2)
153 .unwrap()
154 .join(dir);
155 let mut args = cmdline.split_whitespace(); 152 let mut args = cmdline.split_whitespace();
156 let exec = args.next().unwrap(); 153 let exec = args.next().unwrap();
157 let status = Command::new(exec) 154 let status = Command::new(exec)
@@ -163,3 +160,11 @@ fn run(cmdline: &'static str, dir: &str) -> Result<()> {
163 } 160 }
164 Ok(()) 161 Ok(())
165} 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}