diff options
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r-- | xtask/src/codegen.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 45b17bb48..afa703471 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -10,20 +10,19 @@ mod gen_parser_tests; | |||
10 | mod gen_assists_docs; | 10 | mod gen_assists_docs; |
11 | mod gen_feature_docs; | 11 | mod gen_feature_docs; |
12 | mod gen_features; | 12 | mod gen_features; |
13 | mod gen_diagnostic_docs; | ||
13 | 14 | ||
14 | use std::{ | 15 | use std::{ |
15 | fmt, mem, | 16 | fmt, mem, |
16 | path::{Path, PathBuf}, | 17 | path::{Path, PathBuf}, |
17 | }; | 18 | }; |
19 | use xshell::{cmd, pushenv, read_file, write_file}; | ||
18 | 20 | ||
19 | use crate::{ | 21 | use crate::{ensure_rustfmt, project_root, Result}; |
20 | ensure_rustfmt, | ||
21 | not_bash::{fs2, pushenv, run}, | ||
22 | project_root, Result, | ||
23 | }; | ||
24 | 22 | ||
25 | pub use self::{ | 23 | pub use self::{ |
26 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, | 24 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, |
25 | gen_diagnostic_docs::generate_diagnostic_docs, | ||
27 | gen_feature_docs::generate_feature_docs, | 26 | gen_feature_docs::generate_feature_docs, |
28 | gen_features::generate_features, | 27 | gen_features::generate_features, |
29 | gen_parser_tests::generate_parser_tests, | 28 | gen_parser_tests::generate_parser_tests, |
@@ -50,6 +49,7 @@ impl CodegenCmd { | |||
50 | generate_assists_tests(Mode::Overwrite)?; | 49 | generate_assists_tests(Mode::Overwrite)?; |
51 | generate_assists_docs(Mode::Overwrite)?; | 50 | generate_assists_docs(Mode::Overwrite)?; |
52 | generate_feature_docs(Mode::Overwrite)?; | 51 | generate_feature_docs(Mode::Overwrite)?; |
52 | generate_diagnostic_docs(Mode::Overwrite)?; | ||
53 | Ok(()) | 53 | Ok(()) |
54 | } | 54 | } |
55 | } | 55 | } |
@@ -57,7 +57,7 @@ impl CodegenCmd { | |||
57 | /// A helper to update file on disk if it has changed. | 57 | /// A helper to update file on disk if it has changed. |
58 | /// With verify = false, | 58 | /// With verify = false, |
59 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | 59 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { |
60 | match fs2::read_to_string(path) { | 60 | match read_file(path) { |
61 | Ok(old_contents) if normalize(&old_contents) == normalize(contents) => { | 61 | Ok(old_contents) if normalize(&old_contents) == normalize(contents) => { |
62 | return Ok(()); | 62 | return Ok(()); |
63 | } | 63 | } |
@@ -67,7 +67,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | |||
67 | anyhow::bail!("`{}` is not up-to-date", path.display()); | 67 | anyhow::bail!("`{}` is not up-to-date", path.display()); |
68 | } | 68 | } |
69 | eprintln!("updating {}", path.display()); | 69 | eprintln!("updating {}", path.display()); |
70 | fs2::write(path, contents)?; | 70 | write_file(path, contents)?; |
71 | return Ok(()); | 71 | return Ok(()); |
72 | 72 | ||
73 | fn normalize(s: &str) -> String { | 73 | fn normalize(s: &str) -> String { |
@@ -77,13 +77,13 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | |||
77 | 77 | ||
78 | const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`"; | 78 | const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`"; |
79 | 79 | ||
80 | fn reformat(text: impl std::fmt::Display) -> Result<String> { | 80 | fn reformat(text: &str) -> Result<String> { |
81 | let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); | 81 | let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); |
82 | ensure_rustfmt()?; | 82 | ensure_rustfmt()?; |
83 | let stdout = run!( | 83 | let rustfmt_toml = project_root().join("rustfmt.toml"); |
84 | "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display(); | 84 | let stdout = cmd!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true") |
85 | <text.to_string().as_bytes() | 85 | .stdin(text) |
86 | )?; | 86 | .read()?; |
87 | Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout)) | 87 | Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout)) |
88 | } | 88 | } |
89 | 89 | ||