diff options
author | Aleksey Kladov <[email protected]> | 2021-03-08 18:13:15 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-03-08 18:45:37 +0000 |
commit | 1eb61203b725684fd2c7e25ac7e2d53eef10c64c (patch) | |
tree | aae264078123fc4b9cbe6c9189179f6f147f8a88 /xtask/src | |
parent | abb6b8f14c4d05cf344048263651d8192997b6cf (diff) |
Make `code generation` just work
Contributors don't need to learn about `cargo xtask codegen` if `cargo
test` just does the right thing.
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/codegen.rs | 43 | ||||
-rw-r--r-- | xtask/src/flags.rs | 10 | ||||
-rw-r--r-- | xtask/src/main.rs | 1 | ||||
-rw-r--r-- | xtask/src/release.rs | 5 | ||||
-rw-r--r-- | xtask/src/tidy.rs | 21 |
5 files changed, 35 insertions, 45 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index e3f9ccada..7cdd8f251 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -7,9 +7,9 @@ | |||
7 | 7 | ||
8 | mod gen_syntax; | 8 | mod gen_syntax; |
9 | mod gen_parser_tests; | 9 | mod gen_parser_tests; |
10 | mod gen_lint_completions; | ||
10 | mod gen_assists_docs; | 11 | mod gen_assists_docs; |
11 | mod gen_feature_docs; | 12 | mod gen_feature_docs; |
12 | mod gen_lint_completions; | ||
13 | mod gen_diagnostic_docs; | 13 | mod gen_diagnostic_docs; |
14 | 14 | ||
15 | use std::{ | 15 | use std::{ |
@@ -18,38 +18,35 @@ use std::{ | |||
18 | }; | 18 | }; |
19 | use xshell::{cmd, pushenv, read_file, write_file}; | 19 | use xshell::{cmd, pushenv, read_file, write_file}; |
20 | 20 | ||
21 | use crate::{ensure_rustfmt, flags, project_root, Result}; | 21 | use crate::{ensure_rustfmt, project_root, Result}; |
22 | 22 | ||
23 | pub(crate) use self::{ | 23 | pub(crate) use self::{ |
24 | gen_assists_docs::{generate_assists_docs, generate_assists_tests}, | 24 | gen_assists_docs::generate_assists_tests, gen_lint_completions::generate_lint_completions, |
25 | gen_diagnostic_docs::generate_diagnostic_docs, | 25 | gen_parser_tests::generate_parser_tests, gen_syntax::generate_syntax, |
26 | gen_feature_docs::generate_feature_docs, | ||
27 | gen_lint_completions::generate_lint_completions, | ||
28 | gen_parser_tests::generate_parser_tests, | ||
29 | gen_syntax::generate_syntax, | ||
30 | }; | 26 | }; |
31 | 27 | ||
28 | pub(crate) fn docs() -> Result<()> { | ||
29 | // We don't commit docs to the repo, so we can just overwrite them. | ||
30 | gen_assists_docs::generate_assists_docs(Mode::Overwrite)?; | ||
31 | gen_feature_docs::generate_feature_docs(Mode::Overwrite)?; | ||
32 | gen_diagnostic_docs::generate_diagnostic_docs(Mode::Overwrite)?; | ||
33 | Ok(()) | ||
34 | } | ||
35 | |||
36 | #[allow(unused)] | ||
37 | fn used() { | ||
38 | generate_parser_tests(Mode::Overwrite); | ||
39 | generate_assists_tests(Mode::Overwrite); | ||
40 | generate_syntax(Mode::Overwrite); | ||
41 | generate_lint_completions(Mode::Overwrite); | ||
42 | } | ||
43 | |||
32 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 44 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
33 | pub(crate) enum Mode { | 45 | pub(crate) enum Mode { |
34 | Overwrite, | 46 | Overwrite, |
35 | Ensure, | 47 | Ensure, |
36 | } | 48 | } |
37 | 49 | ||
38 | impl flags::Codegen { | ||
39 | pub(crate) fn run(self) -> Result<()> { | ||
40 | if self.features { | ||
41 | generate_lint_completions(Mode::Overwrite)?; | ||
42 | } | ||
43 | generate_syntax(Mode::Overwrite)?; | ||
44 | generate_parser_tests(Mode::Overwrite)?; | ||
45 | generate_assists_tests(Mode::Overwrite)?; | ||
46 | generate_assists_docs(Mode::Overwrite)?; | ||
47 | generate_feature_docs(Mode::Overwrite)?; | ||
48 | generate_diagnostic_docs(Mode::Overwrite)?; | ||
49 | Ok(()) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | /// A helper to update file on disk if it has changed. | 50 | /// A helper to update file on disk if it has changed. |
54 | /// With verify = false, | 51 | /// With verify = false, |
55 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { | 52 | fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { |
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index b39d937ca..48d1ad45e 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs | |||
@@ -27,10 +27,6 @@ xflags::xflags! { | |||
27 | optional --jemalloc | 27 | optional --jemalloc |
28 | } | 28 | } |
29 | 29 | ||
30 | cmd codegen { | ||
31 | optional --features | ||
32 | } | ||
33 | |||
34 | cmd lint {} | 30 | cmd lint {} |
35 | cmd fuzz-tests {} | 31 | cmd fuzz-tests {} |
36 | cmd pre-cache {} | 32 | cmd pre-cache {} |
@@ -67,7 +63,6 @@ pub struct Xtask { | |||
67 | pub enum XtaskCmd { | 63 | pub enum XtaskCmd { |
68 | Help(Help), | 64 | Help(Help), |
69 | Install(Install), | 65 | Install(Install), |
70 | Codegen(Codegen), | ||
71 | Lint(Lint), | 66 | Lint(Lint), |
72 | FuzzTests(FuzzTests), | 67 | FuzzTests(FuzzTests), |
73 | PreCache(PreCache), | 68 | PreCache(PreCache), |
@@ -93,11 +88,6 @@ pub struct Install { | |||
93 | } | 88 | } |
94 | 89 | ||
95 | #[derive(Debug)] | 90 | #[derive(Debug)] |
96 | pub struct Codegen { | ||
97 | pub features: bool, | ||
98 | } | ||
99 | |||
100 | #[derive(Debug)] | ||
101 | pub struct Lint; | 91 | pub struct Lint; |
102 | 92 | ||
103 | #[derive(Debug)] | 93 | #[derive(Debug)] |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 25fd32f92..c2dda928e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -40,7 +40,6 @@ fn main() -> Result<()> { | |||
40 | return Ok(()); | 40 | return Ok(()); |
41 | } | 41 | } |
42 | flags::XtaskCmd::Install(cmd) => cmd.run(), | 42 | flags::XtaskCmd::Install(cmd) => cmd.run(), |
43 | flags::XtaskCmd::Codegen(cmd) => cmd.run(), | ||
44 | flags::XtaskCmd::Lint(_) => run_clippy(), | 43 | flags::XtaskCmd::Lint(_) => run_clippy(), |
45 | flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), | 44 | flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), |
46 | flags::XtaskCmd::PreCache(cmd) => cmd.run(), | 45 | flags::XtaskCmd::PreCache(cmd) => cmd.run(), |
diff --git a/xtask/src/release.rs b/xtask/src/release.rs index d8d86fd63..dde5d14ee 100644 --- a/xtask/src/release.rs +++ b/xtask/src/release.rs | |||
@@ -2,7 +2,7 @@ use std::fmt::Write; | |||
2 | 2 | ||
3 | use xshell::{cmd, cp, pushd, read_dir, write_file}; | 3 | use xshell::{cmd, cp, pushd, read_dir, write_file}; |
4 | 4 | ||
5 | use crate::{codegen, date_iso, flags, is_release_tag, project_root, Mode, Result}; | 5 | use crate::{codegen, date_iso, flags, is_release_tag, project_root, Result}; |
6 | 6 | ||
7 | impl flags::Release { | 7 | impl flags::Release { |
8 | pub(crate) fn run(self) -> Result<()> { | 8 | pub(crate) fn run(self) -> Result<()> { |
@@ -12,8 +12,7 @@ impl flags::Release { | |||
12 | cmd!("git reset --hard tags/nightly").run()?; | 12 | cmd!("git reset --hard tags/nightly").run()?; |
13 | cmd!("git push").run()?; | 13 | cmd!("git push").run()?; |
14 | } | 14 | } |
15 | codegen::generate_assists_docs(Mode::Overwrite)?; | 15 | codegen::docs()?; |
16 | codegen::generate_feature_docs(Mode::Overwrite)?; | ||
17 | 16 | ||
18 | let website_root = project_root().join("../rust-analyzer.github.io"); | 17 | let website_root = project_root().join("../rust-analyzer.github.io"); |
19 | let changelog_dir = website_root.join("./thisweek/_posts"); | 18 | let changelog_dir = website_root.join("./thisweek/_posts"); |
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index 3818b9e0f..03b4c0092 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs | |||
@@ -12,31 +12,36 @@ use crate::{ | |||
12 | }; | 12 | }; |
13 | 13 | ||
14 | #[test] | 14 | #[test] |
15 | fn generated_grammar_is_fresh() { | 15 | fn generate_grammar() { |
16 | codegen::generate_syntax(Mode::Ensure).unwrap() | 16 | codegen::generate_syntax(Mode::Ensure).unwrap() |
17 | } | 17 | } |
18 | 18 | ||
19 | #[test] | 19 | #[test] |
20 | fn generated_tests_are_fresh() { | 20 | fn generate_parser_tests() { |
21 | codegen::generate_parser_tests(Mode::Ensure).unwrap() | 21 | codegen::generate_parser_tests(Mode::Ensure).unwrap() |
22 | } | 22 | } |
23 | 23 | ||
24 | #[test] | 24 | #[test] |
25 | fn generated_assists_are_fresh() { | 25 | fn generate_assists_tests() { |
26 | codegen::generate_assists_tests(Mode::Ensure).unwrap(); | 26 | codegen::generate_assists_tests(Mode::Ensure).unwrap(); |
27 | } | 27 | } |
28 | 28 | ||
29 | /// This clones rustc repo, and so is not worth to keep up-to-date. We update | ||
30 | /// manually by un-ignoring the test from time to time. | ||
31 | #[test] | ||
32 | #[ignore] | ||
33 | fn generate_lint_completions() { | ||
34 | codegen::generate_lint_completions(Mode::Overwrite).unwrap() | ||
35 | } | ||
36 | |||
29 | #[test] | 37 | #[test] |
30 | fn check_code_formatting() { | 38 | fn check_code_formatting() { |
31 | run_rustfmt(Mode::Ensure).unwrap() | 39 | run_rustfmt(Mode::Ensure).unwrap() |
32 | } | 40 | } |
33 | 41 | ||
34 | #[test] | 42 | #[test] |
35 | fn smoke_test_docs_generation() { | 43 | fn smoke_test_generate_documentation() { |
36 | // We don't commit docs to the repo, so we can just overwrite in tests. | 44 | codegen::docs().unwrap() |
37 | codegen::generate_assists_docs(Mode::Overwrite).unwrap(); | ||
38 | codegen::generate_feature_docs(Mode::Overwrite).unwrap(); | ||
39 | codegen::generate_diagnostic_docs(Mode::Overwrite).unwrap(); | ||
40 | } | 45 | } |
41 | 46 | ||
42 | #[test] | 47 | #[test] |