Skip to content

Commit 16cf0e6

Browse files
committed
allow running clippy on most of the in-tree tools
Signed-off-by: onur-ozkan <[email protected]>
1 parent 5253fe4 commit 16cf0e6

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

src/bootstrap/src/core/build_steps/check.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use std::path::{Path, PathBuf};
1313

1414
pub fn cargo_subcommand(kind: Kind) -> &'static str {
1515
match kind {
16-
Kind::Check | Kind::Clippy => "check",
16+
Kind::Check
17+
// We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
18+
| Kind::Clippy => "check",
1719
Kind::Fix => "fix",
1820
_ => unreachable!(),
1921
}

src/bootstrap/src/core/build_steps/clippy.rs

+39-10
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,17 @@ impl Step for Rustc {
185185
let compiler = builder.compiler(builder.top_stage, builder.config.build);
186186
let target = self.target;
187187

188-
builder.ensure(compile::Std::new(compiler, compiler.host));
189-
builder.ensure(compile::Std::new(compiler, target));
188+
if compiler.stage != 0 {
189+
// If we're not in stage 0, then we won't have a std from the beta
190+
// compiler around. That means we need to make sure there's one in
191+
// the sysroot for the compiler to find. Otherwise, we're going to
192+
// fail when building crates that need to generate code (e.g., build
193+
// scripts and their dependencies).
194+
builder.ensure(compile::Std::new(compiler, compiler.host));
195+
builder.ensure(compile::Std::new(compiler, target));
196+
} else {
197+
builder.ensure(check::Std::new(target));
198+
}
190199

191200
let mut cargo = builder::Cargo::new(
192201
builder,
@@ -197,7 +206,7 @@ impl Step for Rustc {
197206
"clippy",
198207
);
199208

200-
rustc_cargo(builder, &mut cargo, target, compiler.stage);
209+
rustc_cargo(builder, &mut cargo, target, &compiler);
201210

202211
// Explicitly pass -p for all compiler crates -- this will force cargo
203212
// to also lint the tests/benches/examples for these crates, rather
@@ -224,9 +233,7 @@ impl Step for Rustc {
224233
macro_rules! lint_any {
225234
($(
226235
$name:ident, $path:expr, $readable_name:expr
227-
$(,is_external_tool = $external:expr)*
228-
$(,is_unstable_tool = $unstable:expr)*
229-
$(,allow_features = $allow_features:expr)?
236+
$(,lint_by_default = $lint_by_default:expr)*
230237
;
231238
)+) => {
232239
$(
@@ -238,6 +245,7 @@ macro_rules! lint_any {
238245

239246
impl Step for $name {
240247
type Output = ();
248+
const DEFAULT: bool = if false $(|| $lint_by_default)* { true } else { false };
241249

242250
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
243251
run.path($path)
@@ -275,11 +283,15 @@ macro_rules! lint_any {
275283
&target,
276284
);
277285

286+
let stamp = builder
287+
.cargo_out(compiler, Mode::ToolRustc, target)
288+
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()));
289+
278290
run_cargo(
279291
builder,
280292
cargo,
281293
lint_args(builder, &[]),
282-
&libstd_stamp(builder, compiler, target),
294+
&stamp,
283295
vec![],
284296
true,
285297
false,
@@ -293,9 +305,26 @@ macro_rules! lint_any {
293305
lint_any!(
294306
Bootstrap, "src/bootstrap", "bootstrap";
295307
BuildHelper, "src/tools/build_helper", "build_helper";
296-
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
297-
Tidy, "src/tools/tidy", "tidy";
308+
BuildManifest, "src/tools/build-manifest", "build-manifest";
309+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri";
310+
Clippy, "src/tools/clippy", "clippy";
311+
CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata";
298312
Compiletest, "src/tools/compiletest", "compiletest";
299-
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server";
313+
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
314+
Jsondocck, "src/tools/jsondocck", "jsondocck";
315+
Jsondoclint, "src/tools/jsondoclint", "jsondoclint";
316+
LintDocs, "src/tools/lint-docs", "lint-docs";
317+
LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker";
318+
Miri, "src/tools/miri", "miri";
319+
MiroptTestTools, "src/tools/miropt-test-tools", "miropt-test-tools";
320+
OptDist, "src/tools/opt-dist", "opt-dist";
300321
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
322+
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server";
323+
Rls, "src/tools/rls", "rls";
324+
RustAnalyzer, "src/tools/rust-analyzer", "rust-analyzer";
325+
RustDemangler, "src/tools/rust-demangler", "rust-demangler";
326+
Rustdoc, "src/tools/rustdoc", "clippy";
327+
Rustfmt, "src/tools/rustfmt", "rustfmt";
328+
RustInstaller, "src/tools/rust-installer", "rust-installer";
329+
Tidy, "src/tools/tidy", "tidy";
301330
);

src/bootstrap/src/core/build_steps/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ pub fn run_cargo(
20122012
crate::exit!(1);
20132013
}
20142014

2015-
if builder.config.dry_run() || builder.kind == Kind::Clippy {
2015+
if builder.config.dry_run() {
20162016
return Vec::new();
20172017
}
20182018

src/bootstrap/src/core/builder.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,28 @@ impl<'a> Builder<'a> {
732732
clippy::Rustc,
733733
clippy::Bootstrap,
734734
clippy::BuildHelper,
735+
clippy::BuildManifest,
736+
clippy::CargoMiri,
737+
clippy::Clippy,
738+
clippy::CollectLicenseMetadata,
739+
clippy::Compiletest,
735740
clippy::CoverageDump,
736-
clippy::Tidy,
737-
clippy::RemoteTestServer,
741+
clippy::Jsondocck,
742+
clippy::Jsondoclint,
743+
clippy::LintDocs,
744+
clippy::LlvmBitcodeLinker,
745+
clippy::Miri,
746+
clippy::MiroptTestTools,
747+
clippy::OptDist,
738748
clippy::RemoteTestClient,
749+
clippy::RemoteTestServer,
750+
clippy::Rls,
751+
clippy::RustAnalyzer,
752+
clippy::RustDemangler,
753+
clippy::Rustdoc,
754+
clippy::Rustfmt,
755+
clippy::RustInstaller,
756+
clippy::Tidy,
739757
),
740758
Kind::Check | Kind::Fix => describe!(
741759
check::Std,

0 commit comments

Comments
 (0)