diff options
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r-- | xtask/src/codegen.rs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index f5f4b964a..98acd7fa6 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -15,7 +15,11 @@ use std::{ | |||
15 | path::{Path, PathBuf}, | 15 | path::{Path, PathBuf}, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | use crate::{not_bash::fs2, project_root, Result}; | 18 | use crate::{ |
19 | ensure_rustfmt, | ||
20 | not_bash::{fs2, pushenv, run}, | ||
21 | project_root, Result, | ||
22 | }; | ||
19 | 23 | ||
20 | pub use self::{ | 24 | pub use self::{ |
21 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, | 25 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, |
@@ -24,16 +28,16 @@ pub use self::{ | |||
24 | gen_syntax::generate_syntax, | 28 | gen_syntax::generate_syntax, |
25 | }; | 29 | }; |
26 | 30 | ||
27 | const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar"; | 31 | const GRAMMAR_DIR: &str = "crates/parser/src/grammar"; |
28 | const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/ok"; | 32 | const OK_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/ok"; |
29 | const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err"; | 33 | const ERR_INLINE_TESTS_DIR: &str = "crates/syntax/test_data/parser/inline/err"; |
30 | 34 | ||
31 | const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs"; | 35 | const SYNTAX_KINDS: &str = "crates/parser/src/syntax_kind/generated.rs"; |
32 | const AST_NODES: &str = "crates/ra_syntax/src/ast/generated/nodes.rs"; | 36 | const AST_NODES: &str = "crates/syntax/src/ast/generated/nodes.rs"; |
33 | const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs"; | 37 | const AST_TOKENS: &str = "crates/syntax/src/ast/generated/tokens.rs"; |
34 | 38 | ||
35 | const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; | 39 | const ASSISTS_DIR: &str = "crates/assists/src/handlers"; |
36 | const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs"; | 40 | const ASSISTS_TESTS: &str = "crates/assists/src/tests/generated.rs"; |
37 | 41 | ||
38 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 42 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
39 | pub enum Mode { | 43 | pub enum Mode { |
@@ -62,6 +66,18 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | |||
62 | } | 66 | } |
63 | } | 67 | } |
64 | 68 | ||
69 | const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`"; | ||
70 | |||
71 | fn reformat(text: impl std::fmt::Display) -> Result<String> { | ||
72 | let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); | ||
73 | ensure_rustfmt()?; | ||
74 | let stdout = run!( | ||
75 | "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display(); | ||
76 | <text.to_string().as_bytes() | ||
77 | )?; | ||
78 | Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout)) | ||
79 | } | ||
80 | |||
65 | fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { | 81 | fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> { |
66 | do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect() | 82 | do_extract_comment_blocks(text, false).into_iter().map(|(_line, block)| block).collect() |
67 | } | 83 | } |