diff options
author | Muhammad Mominul Huque <[email protected]> | 2018-10-26 14:08:21 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-31 20:39:21 +0000 |
commit | d14610dab4b4fedee7a0d8f1739eb3e0691984c1 (patch) | |
tree | d022f3a2e3afc8cb56cb8b4d49fc5e8dab1abcf6 | |
parent | 9b9fc135d6763b403dcf2455c35251d5c36d83e5 (diff) |
initial implementation
-rw-r--r-- | .cargo/config | 1 | ||||
-rw-r--r-- | crates/tools/src/lib.rs | 9 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 19 |
3 files changed, 18 insertions, 11 deletions
diff --git a/.cargo/config b/.cargo/config index fd32471ea..c0be661fd 100644 --- a/.cargo/config +++ b/.cargo/config | |||
@@ -3,6 +3,7 @@ | |||
3 | gen-syntax = "run --package tools -- gen-syntax" | 3 | gen-syntax = "run --package tools -- gen-syntax" |
4 | gen-tests = "run --package tools -- gen-tests" | 4 | gen-tests = "run --package tools -- gen-tests" |
5 | install-code = "run --package tools -- install-code" | 5 | install-code = "run --package tools -- install-code" |
6 | format = "run --package tools -- format" | ||
6 | 7 | ||
7 | render-test = "run --package ra_cli -- render-test" | 8 | render-test = "run --package ra_cli -- render-test" |
8 | parse = "run --package ra_cli -- parse" | 9 | parse = "run --package ra_cli -- parse" |
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 | ||
13 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 13 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
14 | 14 | ||
15 | pub const GRAMMAR: &str = "ra_syntax/src/grammar.ron"; | 15 | pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; |
16 | pub const SYNTAX_KINDS: &str = "ra_syntax/src/syntax_kinds/generated.rs.tera"; | 16 | pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera"; |
17 | pub const AST: &str = "ra_syntax/src/ast/generated.rs.tera"; | 17 | pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs.tera"; |
18 | 18 | ||
19 | #[derive(Debug)] | 19 | #[derive(Debug)] |
20 | pub struct Test { | 20 | pub struct Test { |
@@ -75,7 +75,8 @@ pub fn generate(mode: Mode) -> Result<()> { | |||
75 | 75 | ||
76 | pub fn project_root() -> PathBuf { | 76 | pub 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 | }; |
15 | use tools::{ | 15 | use 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 | ||
19 | const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar"; | 19 | const 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 | ||
147 | fn run(cmdline: &'static str, dir: &str) -> Result<()> { | 149 | fn 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 | |||
164 | fn 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 | } | ||