aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-03-08 13:35:27 +0000
committerAleksey Kladov <[email protected]>2021-03-08 18:45:06 +0000
commit0f6f458cc1b460076093efda903bf1a1b9062697 (patch)
tree2e1db2d81bc3ab3f3a954e3ea9ce7ccffca64259 /xtask/src
parent071dde1c1da10e3580bded99dc2d529074356536 (diff)
Make working with codegen less annoying
We probably should look into removing `xtask codegen` altogether. The test workflow works perfectly for package.json config. There are two things preventing that: * Lint completions are generated on demand. * Docs are not committed to the repository.
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen.rs17
-rw-r--r--xtask/src/main.rs13
-rw-r--r--xtask/src/tidy.rs16
3 files changed, 25 insertions, 21 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 2f56c5ad0..e3f9ccada 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -32,7 +32,7 @@ pub(crate) use self::{
32#[derive(Debug, PartialEq, Eq, Clone, Copy)] 32#[derive(Debug, PartialEq, Eq, Clone, Copy)]
33pub(crate) enum Mode { 33pub(crate) enum Mode {
34 Overwrite, 34 Overwrite,
35 Verify, 35 Ensure,
36} 36}
37 37
38impl flags::Codegen { 38impl flags::Codegen {
@@ -59,12 +59,19 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
59 } 59 }
60 _ => (), 60 _ => (),
61 } 61 }
62 if mode == Mode::Verify { 62 let return_error = match mode {
63 anyhow::bail!("`{}` is not up-to-date", path.display()); 63 Mode::Overwrite => false,
64 } 64 Mode::Ensure => true,
65 };
65 eprintln!("updating {}", path.display()); 66 eprintln!("updating {}", path.display());
66 write_file(path, contents)?; 67 write_file(path, contents)?;
67 return Ok(()); 68
69 return if return_error {
70 let path = path.strip_prefix(&project_root()).unwrap_or(path);
71 anyhow::bail!("`{}` was not up-to-date, updating", path.display());
72 } else {
73 Ok(())
74 };
68 75
69 fn normalize(s: &str) -> String { 76 fn normalize(s: &str) -> String {
70 s.replace("\r\n", "\n") 77 s.replace("\r\n", "\n")
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 3c4332f75..25fd32f92 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -89,11 +89,16 @@ fn run_rustfmt(mode: Mode) -> Result<()> {
89 let _dir = pushd(project_root())?; 89 let _dir = pushd(project_root())?;
90 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); 90 let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
91 ensure_rustfmt()?; 91 ensure_rustfmt()?;
92 let check = match mode { 92 match mode {
93 Mode::Overwrite => &[][..], 93 Mode::Overwrite => cmd!("cargo fmt").run()?,
94 Mode::Verify => &["--", "--check"], 94 Mode::Ensure => {
95 let res = cmd!("cargo fmt -- --check").run();
96 if !res.is_ok() {
97 let _ = cmd!("cargo fmt").run();
98 }
99 res?;
100 }
95 }; 101 };
96 cmd!("cargo fmt {check...}").run()?;
97 Ok(()) 102 Ok(())
98} 103}
99 104
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs
index 349ca14d0..3818b9e0f 100644
--- a/xtask/src/tidy.rs
+++ b/xtask/src/tidy.rs
@@ -13,30 +13,22 @@ use crate::{
13 13
14#[test] 14#[test]
15fn generated_grammar_is_fresh() { 15fn generated_grammar_is_fresh() {
16 if let Err(error) = codegen::generate_syntax(Mode::Verify) { 16 codegen::generate_syntax(Mode::Ensure).unwrap()
17 panic!("{}. Please update it by running `cargo xtask codegen`", error);
18 }
19} 17}
20 18
21#[test] 19#[test]
22fn generated_tests_are_fresh() { 20fn generated_tests_are_fresh() {
23 if let Err(error) = codegen::generate_parser_tests(Mode::Verify) { 21 codegen::generate_parser_tests(Mode::Ensure).unwrap()
24 panic!("{}. Please update tests by running `cargo xtask codegen`", error);
25 }
26} 22}
27 23
28#[test] 24#[test]
29fn generated_assists_are_fresh() { 25fn generated_assists_are_fresh() {
30 if let Err(error) = codegen::generate_assists_tests(Mode::Verify) { 26 codegen::generate_assists_tests(Mode::Ensure).unwrap();
31 panic!("{}. Please update assists by running `cargo xtask codegen`", error);
32 }
33} 27}
34 28
35#[test] 29#[test]
36fn check_code_formatting() { 30fn check_code_formatting() {
37 if let Err(error) = run_rustfmt(Mode::Verify) { 31 run_rustfmt(Mode::Ensure).unwrap()
38 panic!("{}. Please format the code by running `cargo format`", error);
39 }
40} 32}
41 33
42#[test] 34#[test]