aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/tools/src/lib.rs9
-rw-r--r--crates/tools/src/main.rs19
2 files changed, 17 insertions, 11 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index 7c5410d3c..91c35b9e1 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -12,9 +12,9 @@ pub use teraron::{Mode, Verify, Overwrite};
12 12
13pub type Result<T> = ::std::result::Result<T, failure::Error>; 13pub type Result<T> = ::std::result::Result<T, failure::Error>;
14 14
15pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron"; 15pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
16pub const SYNTAX_KINDS: &str = "ra_syntax/src/syntax_kinds/generated.rs.tera"; 16pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera";
17pub const AST: &str = "ra_syntax/src/ast/generated.rs.tera"; 17pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera";
18 18
19#[derive(Debug)] 19#[derive(Debug)]
20pub struct Test { 20pub struct Test {
@@ -75,7 +75,8 @@ pub fn generate(mode: Mode) -> Result<()> {
75 75
76pub fn project_root() -> PathBuf { 76pub fn project_root() -> PathBuf {
77 Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) 77 Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
78 .parent() 78 .ancestors()
79 .nth(2)
79 .unwrap() 80 .unwrap()
80 .to_path_buf() 81 .to_path_buf()
81} 82}
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}