From 3c6841725c05c3e75a8321b114b2132eb1699fb8 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 12 Jun 2024 13:01:21 +0200 Subject: define all the clippy lints we check in CI in a step --- src/bootstrap/src/core/build_steps/clippy.rs | 68 ++++++++++++++++++++++++++++ src/bootstrap/src/core/builder/mod.rs | 1 + 2 files changed, 69 insertions(+) (limited to 'src/bootstrap') diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index de96648d59d..ad2b349bab6 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -102,6 +102,19 @@ impl LintConfig { _ => unreachable!("LintConfig can only be called from `clippy` subcommands."), } } + + fn merge(&self, other: &Self) -> Self { + let merged = |self_attr: &[String], other_attr: &[String]| -> Vec { + self_attr.iter().cloned().chain(other_attr.iter().cloned()).collect() + }; + // This is written this way to ensure we get a compiler error if we add a new field. + Self { + allow: merged(&self.allow, &other.allow), + warn: merged(&self.warn, &other.warn), + deny: merged(&self.deny, &other.deny), + forbid: merged(&self.forbid, &other.forbid), + } + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -339,3 +352,58 @@ lint_any!( Tidy, "src/tools/tidy", "tidy"; TestFloatParse, "src/etc/test-float-parse", "test-float-parse"; ); + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CI { + target: TargetSelection, + config: LintConfig, +} + +impl Step for CI { + type Output = (); + const DEFAULT: bool = false; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.alias("ci") + } + + fn make_run(run: RunConfig<'_>) { + let config = LintConfig::new(run.builder); + run.builder.ensure(CI { target: run.target, config }); + } + + fn run(self, builder: &Builder<'_>) -> Self::Output { + builder.ensure(Bootstrap { + target: self.target, + config: self.config.merge(&LintConfig { + allow: vec![], + warn: vec![], + deny: vec!["warnings".into()], + forbid: vec![], + }), + }); + let library_clippy_cfg = LintConfig { + allow: vec!["clippy::all".into()], + warn: vec![], + deny: vec!["clippy::correctness".into()], + forbid: vec![], + }; + let compiler_clippy_cfg = LintConfig { + allow: vec!["clippy::all".into()], + warn: vec![], + deny: vec!["clippy::correctness".into(), "clippy::clone_on_ref_ptr".into()], + forbid: vec![], + }; + + builder.ensure(Std { + target: self.target, + config: self.config.merge(&library_clippy_cfg), + crates: vec![], + }); + builder.ensure(Rustc { + target: self.target, + config: self.config.merge(&compiler_clippy_cfg), + crates: vec![], + }); + } +} diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index f1b3cf6da13..d59e0fa7288 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -839,6 +839,7 @@ impl<'a> Builder<'a> { clippy::RustInstaller, clippy::TestFloatParse, clippy::Tidy, + clippy::CI, ), Kind::Check | Kind::Fix => describe!( check::Std, -- cgit 1.4.1-3-g733a5