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