Skip to content

Commit f8399f7

Browse files
committed
[wip] add a check step for tidy\n this allows running clippy on it
1 parent ac1b394 commit f8399f7

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ impl<'a> Builder<'a> {
649649
check::Rustc,
650650
check::Rustdoc,
651651
check::CodegenBackend,
652+
check::Tidy,
652653
check::Clippy,
653654
check::Miri,
654655
check::CargoMiri,

src/bootstrap/check.rs

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,81 @@ impl Step for RustAnalyzer {
361361
}
362362
}
363363

364+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
365+
pub struct Tidy;
366+
367+
impl Step for Tidy {
368+
type Output = ();
369+
const ONLY_HOSTS: bool = true;
370+
const DEFAULT: bool = true;
371+
372+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
373+
run.path("src/tools/tidy")
374+
}
375+
376+
fn make_run(run: RunConfig<'_>) {
377+
run.builder.ensure(Tidy);
378+
}
379+
380+
fn run(self, builder: &Builder<'_>) -> Self::Output {
381+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
382+
let host = builder.build.build;
383+
384+
let mut cargo = prepare_tool_cargo(
385+
builder,
386+
compiler,
387+
Mode::ToolBootstrap,
388+
host,
389+
cargo_subcommand(builder.kind),
390+
"src/tools/tidy",
391+
SourceType::InTree,
392+
&[],
393+
);
394+
395+
// For ./x.py clippy, don't run with --all-targets because
396+
// linting tests and benchmarks can produce very noisy results
397+
if builder.kind != Kind::Clippy {
398+
cargo.arg("--all-targets");
399+
}
400+
401+
cargo.args(args(builder));
402+
403+
// Enable internal lints for clippy and rustdoc
404+
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
405+
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
406+
cargo.rustflag("-Zunstable-options");
407+
408+
builder.info(&format!(
409+
"Checking stage{} tidy artifacts ({} -> {})",
410+
builder.top_stage,
411+
&compiler.host.triple,
412+
host.triple
413+
));
414+
run_cargo(
415+
builder,
416+
cargo,
417+
&tool_stamp(builder, compiler, host, Mode::ToolBootstrap, "tidy"),
418+
vec![],
419+
true,
420+
false,
421+
);
422+
}
423+
}
424+
425+
/// Cargo's output path in a given stage, compiled by a particular
426+
/// compiler for the specified target.
427+
fn tool_stamp(
428+
builder: &Builder<'_>,
429+
compiler: Compiler,
430+
target: TargetSelection,
431+
mode: Mode,
432+
name: &str,
433+
) -> PathBuf {
434+
builder
435+
.cargo_out(compiler, mode, target)
436+
.join(format!(".{name}-check.stamp"))
437+
}
438+
364439
macro_rules! tool_check_step {
365440
($name:ident, $path:literal, $($alias:literal, )* $source_type:path $(, $default:literal )?) => {
366441
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -422,23 +497,11 @@ macro_rules! tool_check_step {
422497
run_cargo(
423498
builder,
424499
cargo,
425-
&stamp(builder, compiler, target),
500+
&tool_stamp(builder, compiler, target, Mode::ToolRustc, &stringify!($name).to_lowercase()),
426501
vec![],
427502
true,
428503
false,
429504
);
430-
431-
/// Cargo's output path in a given stage, compiled by a particular
432-
/// compiler for the specified target.
433-
fn stamp(
434-
builder: &Builder<'_>,
435-
compiler: Compiler,
436-
target: TargetSelection,
437-
) -> PathBuf {
438-
builder
439-
.cargo_out(compiler, Mode::ToolRustc, target)
440-
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()))
441-
}
442505
}
443506
}
444507
};

0 commit comments

Comments
 (0)