From 1eb61203b725684fd2c7e25ac7e2d53eef10c64c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Mar 2021 21:13:15 +0300 Subject: Make `code generation` just work Contributors don't need to learn about `cargo xtask codegen` if `cargo test` just does the right thing. --- xtask/src/codegen.rs | 43 ++++++++++++++++++++----------------------- xtask/src/flags.rs | 10 ---------- xtask/src/main.rs | 1 - xtask/src/release.rs | 5 ++--- xtask/src/tidy.rs | 21 +++++++++++++-------- 5 files changed, 35 insertions(+), 45 deletions(-) (limited to 'xtask') 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 @@ mod gen_syntax; mod gen_parser_tests; +mod gen_lint_completions; mod gen_assists_docs; mod gen_feature_docs; -mod gen_lint_completions; mod gen_diagnostic_docs; use std::{ @@ -18,38 +18,35 @@ use std::{ }; use xshell::{cmd, pushenv, read_file, write_file}; -use crate::{ensure_rustfmt, flags, project_root, Result}; +use crate::{ensure_rustfmt, project_root, Result}; pub(crate) use self::{ - gen_assists_docs::{generate_assists_docs, generate_assists_tests}, - gen_diagnostic_docs::generate_diagnostic_docs, - gen_feature_docs::generate_feature_docs, - gen_lint_completions::generate_lint_completions, - gen_parser_tests::generate_parser_tests, - gen_syntax::generate_syntax, + gen_assists_docs::generate_assists_tests, gen_lint_completions::generate_lint_completions, + gen_parser_tests::generate_parser_tests, gen_syntax::generate_syntax, }; +pub(crate) fn docs() -> Result<()> { + // We don't commit docs to the repo, so we can just overwrite them. + gen_assists_docs::generate_assists_docs(Mode::Overwrite)?; + gen_feature_docs::generate_feature_docs(Mode::Overwrite)?; + gen_diagnostic_docs::generate_diagnostic_docs(Mode::Overwrite)?; + Ok(()) +} + +#[allow(unused)] +fn used() { + generate_parser_tests(Mode::Overwrite); + generate_assists_tests(Mode::Overwrite); + generate_syntax(Mode::Overwrite); + generate_lint_completions(Mode::Overwrite); +} + #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(crate) enum Mode { Overwrite, Ensure, } -impl flags::Codegen { - pub(crate) fn run(self) -> Result<()> { - if self.features { - generate_lint_completions(Mode::Overwrite)?; - } - generate_syntax(Mode::Overwrite)?; - generate_parser_tests(Mode::Overwrite)?; - generate_assists_tests(Mode::Overwrite)?; - generate_assists_docs(Mode::Overwrite)?; - generate_feature_docs(Mode::Overwrite)?; - generate_diagnostic_docs(Mode::Overwrite)?; - Ok(()) - } -} - /// A helper to update file on disk if it has changed. /// With verify = false, 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! { optional --jemalloc } - cmd codegen { - optional --features - } - cmd lint {} cmd fuzz-tests {} cmd pre-cache {} @@ -67,7 +63,6 @@ pub struct Xtask { pub enum XtaskCmd { Help(Help), Install(Install), - Codegen(Codegen), Lint(Lint), FuzzTests(FuzzTests), PreCache(PreCache), @@ -92,11 +87,6 @@ pub struct Install { pub jemalloc: bool, } -#[derive(Debug)] -pub struct Codegen { - pub features: bool, -} - #[derive(Debug)] pub struct Lint; 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<()> { return Ok(()); } flags::XtaskCmd::Install(cmd) => cmd.run(), - flags::XtaskCmd::Codegen(cmd) => cmd.run(), flags::XtaskCmd::Lint(_) => run_clippy(), flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), 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; use xshell::{cmd, cp, pushd, read_dir, write_file}; -use crate::{codegen, date_iso, flags, is_release_tag, project_root, Mode, Result}; +use crate::{codegen, date_iso, flags, is_release_tag, project_root, Result}; impl flags::Release { pub(crate) fn run(self) -> Result<()> { @@ -12,8 +12,7 @@ impl flags::Release { cmd!("git reset --hard tags/nightly").run()?; cmd!("git push").run()?; } - codegen::generate_assists_docs(Mode::Overwrite)?; - codegen::generate_feature_docs(Mode::Overwrite)?; + codegen::docs()?; let website_root = project_root().join("../rust-analyzer.github.io"); 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::{ }; #[test] -fn generated_grammar_is_fresh() { +fn generate_grammar() { codegen::generate_syntax(Mode::Ensure).unwrap() } #[test] -fn generated_tests_are_fresh() { +fn generate_parser_tests() { codegen::generate_parser_tests(Mode::Ensure).unwrap() } #[test] -fn generated_assists_are_fresh() { +fn generate_assists_tests() { codegen::generate_assists_tests(Mode::Ensure).unwrap(); } +/// This clones rustc repo, and so is not worth to keep up-to-date. We update +/// manually by un-ignoring the test from time to time. +#[test] +#[ignore] +fn generate_lint_completions() { + codegen::generate_lint_completions(Mode::Overwrite).unwrap() +} + #[test] fn check_code_formatting() { run_rustfmt(Mode::Ensure).unwrap() } #[test] -fn smoke_test_docs_generation() { - // We don't commit docs to the repo, so we can just overwrite in tests. - codegen::generate_assists_docs(Mode::Overwrite).unwrap(); - codegen::generate_feature_docs(Mode::Overwrite).unwrap(); - codegen::generate_diagnostic_docs(Mode::Overwrite).unwrap(); +fn smoke_test_generate_documentation() { + codegen::docs().unwrap() } #[test] -- cgit v1.2.3