aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/test_utils/src/lib.rs5
-rw-r--r--docs/dev/architecture.md3
-rw-r--r--xtask/src/codegen.rs43
-rw-r--r--xtask/src/flags.rs10
-rw-r--r--xtask/src/main.rs1
-rw-r--r--xtask/src/release.rs5
-rw-r--r--xtask/src/tidy.rs21
8 files changed, 42 insertions, 50 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index bceca2b0f..078c83f75 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -864,7 +864,7 @@ mod tests {
864 use super::*; 864 use super::*;
865 865
866 #[test] 866 #[test]
867 fn ensure_schema_in_package_json() { 867 fn generate_package_json_config() {
868 let s = Config::json_schema(); 868 let s = Config::json_schema();
869 let schema = format!("{:#}", s); 869 let schema = format!("{:#}", s);
870 let mut schema = schema 870 let mut schema = schema
@@ -895,7 +895,7 @@ mod tests {
895 } 895 }
896 896
897 #[test] 897 #[test]
898 fn schema_in_sync_with_docs() { 898 fn generate_config_documentation() {
899 let docs_path = project_root().join("docs/user/generated_config.adoc"); 899 let docs_path = project_root().join("docs/user/generated_config.adoc");
900 let current = fs::read_to_string(&docs_path).unwrap(); 900 let current = fs::read_to_string(&docs_path).unwrap();
901 let expected = ConfigData::manual(); 901 let expected = ConfigData::manual();
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 097a54139..dd582c77c 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -18,7 +18,7 @@ use std::{
18}; 18};
19 19
20use profile::StopWatch; 20use profile::StopWatch;
21use stdx::lines_with_ends; 21use stdx::{is_ci, lines_with_ends};
22use text_size::{TextRange, TextSize}; 22use text_size::{TextRange, TextSize};
23 23
24pub use dissimilar::diff as __diff; 24pub use dissimilar::diff as __diff;
@@ -376,6 +376,9 @@ pub fn try_ensure_file_contents(file: &Path, contents: &str) -> Result<(), ()> {
376 "\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n", 376 "\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n",
377 display_path.display() 377 display_path.display()
378 ); 378 );
379 if is_ci() {
380 eprintln!("\n NOTE: run `cargo test` locally and commit the updated files\n");
381 }
379 if let Some(parent) = file.parent() { 382 if let Some(parent) = file.parent() {
380 let _ = std::fs::create_dir_all(parent); 383 let _ = std::fs::create_dir_all(parent);
381 } 384 }
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index ead12616e..0a3fd4285 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -308,9 +308,8 @@ This sections talks about the things which are everywhere and nowhere in particu
308### Code generation 308### Code generation
309 309
310Some of the components of this repository are generated through automatic processes. 310Some of the components of this repository are generated through automatic processes.
311`cargo xtask codegen` runs all generation tasks. 311Generated code is updated automatically on `cargo test`.
312Generated code is generally committed to the git repository. 312Generated code is generally committed to the git repository.
313There are tests to check that the generated code is fresh.
314 313
315In particular, we generate: 314In particular, we generate:
316 315
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
8mod gen_syntax; 8mod gen_syntax;
9mod gen_parser_tests; 9mod gen_parser_tests;
10mod gen_lint_completions;
10mod gen_assists_docs; 11mod gen_assists_docs;
11mod gen_feature_docs; 12mod gen_feature_docs;
12mod gen_lint_completions;
13mod gen_diagnostic_docs; 13mod gen_diagnostic_docs;
14 14
15use std::{ 15use std::{
@@ -18,38 +18,35 @@ use std::{
18}; 18};
19use xshell::{cmd, pushenv, read_file, write_file}; 19use xshell::{cmd, pushenv, read_file, write_file};
20 20
21use crate::{ensure_rustfmt, flags, project_root, Result}; 21use crate::{ensure_rustfmt, project_root, Result};
22 22
23pub(crate) use self::{ 23pub(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
28pub(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)]
37fn 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)]
33pub(crate) enum Mode { 45pub(crate) enum Mode {
34 Overwrite, 46 Overwrite,
35 Ensure, 47 Ensure,
36} 48}
37 49
38impl 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,
55fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { 52fn 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 {
67pub enum XtaskCmd { 63pub 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)]
96pub struct Codegen {
97 pub features: bool,
98}
99
100#[derive(Debug)]
101pub struct Lint; 91pub 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
3use xshell::{cmd, cp, pushd, read_dir, write_file}; 3use xshell::{cmd, cp, pushd, read_dir, write_file};
4 4
5use crate::{codegen, date_iso, flags, is_release_tag, project_root, Mode, Result}; 5use crate::{codegen, date_iso, flags, is_release_tag, project_root, Result};
6 6
7impl flags::Release { 7impl 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]
15fn generated_grammar_is_fresh() { 15fn generate_grammar() {
16 codegen::generate_syntax(Mode::Ensure).unwrap() 16 codegen::generate_syntax(Mode::Ensure).unwrap()
17} 17}
18 18
19#[test] 19#[test]
20fn generated_tests_are_fresh() { 20fn 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]
25fn generated_assists_are_fresh() { 25fn 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]
33fn generate_lint_completions() {
34 codegen::generate_lint_completions(Mode::Overwrite).unwrap()
35}
36
29#[test] 37#[test]
30fn check_code_formatting() { 38fn check_code_formatting() {
31 run_rustfmt(Mode::Ensure).unwrap() 39 run_rustfmt(Mode::Ensure).unwrap()
32} 40}
33 41
34#[test] 42#[test]
35fn smoke_test_docs_generation() { 43fn 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]