diff options
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r-- | xtask/src/codegen.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 78a84f68d..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}, |
@@ -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 | } |