allow running clippy on most of the in-tree tools

Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
onur-ozkan 2024-03-22 20:19:24 +03:00
parent 5253fe4520
commit 16cf0e6607
4 changed files with 63 additions and 14 deletions

View File

@ -13,7 +13,9 @@ use std::path::{Path, PathBuf};
pub fn cargo_subcommand(kind: Kind) -> &'static str { pub fn cargo_subcommand(kind: Kind) -> &'static str {
match kind { match kind {
Kind::Check | Kind::Clippy => "check", Kind::Check
// We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
| Kind::Clippy => "check",
Kind::Fix => "fix", Kind::Fix => "fix",
_ => unreachable!(), _ => unreachable!(),
} }

View File

@ -185,8 +185,17 @@ impl Step for Rustc {
let compiler = builder.compiler(builder.top_stage, builder.config.build); let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target; let target = self.target;
builder.ensure(compile::Std::new(compiler, compiler.host)); if compiler.stage != 0 {
builder.ensure(compile::Std::new(compiler, target)); // If we're not in stage 0, then we won't have a std from the beta
// compiler around. That means we need to make sure there's one in
// the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build
// scripts and their dependencies).
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
} else {
builder.ensure(check::Std::new(target));
}
let mut cargo = builder::Cargo::new( let mut cargo = builder::Cargo::new(
builder, builder,
@ -197,7 +206,7 @@ impl Step for Rustc {
"clippy", "clippy",
); );
rustc_cargo(builder, &mut cargo, target, compiler.stage); rustc_cargo(builder, &mut cargo, target, &compiler);
// Explicitly pass -p for all compiler crates -- this will force cargo // Explicitly pass -p for all compiler crates -- this will force cargo
// to also lint the tests/benches/examples for these crates, rather // to also lint the tests/benches/examples for these crates, rather
@ -224,9 +233,7 @@ impl Step for Rustc {
macro_rules! lint_any { macro_rules! lint_any {
($( ($(
$name:ident, $path:expr, $readable_name:expr $name:ident, $path:expr, $readable_name:expr
$(,is_external_tool = $external:expr)* $(,lint_by_default = $lint_by_default:expr)*
$(,is_unstable_tool = $unstable:expr)*
$(,allow_features = $allow_features:expr)?
; ;
)+) => { )+) => {
$( $(
@ -238,6 +245,7 @@ macro_rules! lint_any {
impl Step for $name { impl Step for $name {
type Output = (); type Output = ();
const DEFAULT: bool = if false $(|| $lint_by_default)* { true } else { false };
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path($path) run.path($path)
@ -275,11 +283,15 @@ macro_rules! lint_any {
&target, &target,
); );
let stamp = builder
.cargo_out(compiler, Mode::ToolRustc, target)
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()));
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
lint_args(builder, &[]), lint_args(builder, &[]),
&libstd_stamp(builder, compiler, target), &stamp,
vec![], vec![],
true, true,
false, false,
@ -293,9 +305,26 @@ macro_rules! lint_any {
lint_any!( lint_any!(
Bootstrap, "src/bootstrap", "bootstrap"; Bootstrap, "src/bootstrap", "bootstrap";
BuildHelper, "src/tools/build_helper", "build_helper"; BuildHelper, "src/tools/build_helper", "build_helper";
CoverageDump, "src/tools/coverage-dump", "coverage-dump"; BuildManifest, "src/tools/build-manifest", "build-manifest";
Tidy, "src/tools/tidy", "tidy"; CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri";
Clippy, "src/tools/clippy", "clippy";
CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata";
Compiletest, "src/tools/compiletest", "compiletest"; Compiletest, "src/tools/compiletest", "compiletest";
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server"; CoverageDump, "src/tools/coverage-dump", "coverage-dump";
Jsondocck, "src/tools/jsondocck", "jsondocck";
Jsondoclint, "src/tools/jsondoclint", "jsondoclint";
LintDocs, "src/tools/lint-docs", "lint-docs";
LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker";
Miri, "src/tools/miri", "miri";
MiroptTestTools, "src/tools/miropt-test-tools", "miropt-test-tools";
OptDist, "src/tools/opt-dist", "opt-dist";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client"; RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server";
Rls, "src/tools/rls", "rls";
RustAnalyzer, "src/tools/rust-analyzer", "rust-analyzer";
RustDemangler, "src/tools/rust-demangler", "rust-demangler";
Rustdoc, "src/tools/rustdoc", "clippy";
Rustfmt, "src/tools/rustfmt", "rustfmt";
RustInstaller, "src/tools/rust-installer", "rust-installer";
Tidy, "src/tools/tidy", "tidy";
); );

View File

@ -2012,7 +2012,7 @@ pub fn run_cargo(
crate::exit!(1); crate::exit!(1);
} }
if builder.config.dry_run() || builder.kind == Kind::Clippy { if builder.config.dry_run() {
return Vec::new(); return Vec::new();
} }

View File

@ -732,10 +732,28 @@ impl<'a> Builder<'a> {
clippy::Rustc, clippy::Rustc,
clippy::Bootstrap, clippy::Bootstrap,
clippy::BuildHelper, clippy::BuildHelper,
clippy::BuildManifest,
clippy::CargoMiri,
clippy::Clippy,
clippy::CollectLicenseMetadata,
clippy::Compiletest,
clippy::CoverageDump, clippy::CoverageDump,
clippy::Tidy, clippy::Jsondocck,
clippy::RemoteTestServer, clippy::Jsondoclint,
clippy::LintDocs,
clippy::LlvmBitcodeLinker,
clippy::Miri,
clippy::MiroptTestTools,
clippy::OptDist,
clippy::RemoteTestClient, clippy::RemoteTestClient,
clippy::RemoteTestServer,
clippy::Rls,
clippy::RustAnalyzer,
clippy::RustDemangler,
clippy::Rustdoc,
clippy::Rustfmt,
clippy::RustInstaller,
clippy::Tidy,
), ),
Kind::Check | Kind::Fix => describe!( Kind::Check | Kind::Fix => describe!(
check::Std, check::Std,