Skip to content

Commit cf7d7f5

Browse files
authored
Rollup merge of #134950 - Zalathar:tool-check-step, r=jieyouxu
bootstrap: Overhaul and simplify the `tool_check_step!` macro Main changes: - Pull most of `run` out of the macro and into a regular helper function - Reduce the number of redundant/unnecessary macro arguments - Switch to struct-like syntax so that optional arguments are clearer, and so that rustfmt is happy ~~The one “functional” change is that the `-check.stamp` files now get their name from the final path segment, instead of the struct name; in practice this means that they now contain more hyphens in some cases. As far as I'm aware, the exact filename doesn't matter so this should be fine.~~ (that change has been removed from this PR)
2 parents f91bfd9 + 66fd534 commit cf7d7f5

File tree

1 file changed

+65
-75
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+65
-75
lines changed

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

+65-75
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,13 @@ impl Step for RustAnalyzer {
401401

402402
macro_rules! tool_check_step {
403403
(
404-
$name:ident,
405-
$display_name:literal,
406-
$path:literal,
407-
$($alias:literal, )*
408-
$source_type:path
409-
$(, $default:literal )?
404+
$name:ident {
405+
// The part of this path after the final '/' is also used as a display name.
406+
path: $path:literal
407+
$(, alt_path: $alt_path:literal )*
408+
$(, default: $default:literal )?
409+
$( , )?
410+
}
410411
) => {
411412
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
412413
pub struct $name {
@@ -416,94 +417,83 @@ macro_rules! tool_check_step {
416417
impl Step for $name {
417418
type Output = ();
418419
const ONLY_HOSTS: bool = true;
419-
/// don't ever check out-of-tree tools by default, they'll fail when toolstate is broken
420-
const DEFAULT: bool = matches!($source_type, SourceType::InTree) $( && $default )?;
420+
/// Most of the tool-checks using this macro are run by default.
421+
const DEFAULT: bool = true $( && $default )?;
421422

422423
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
423-
run.paths(&[ $path, $($alias),* ])
424+
run.paths(&[ $path, $( $alt_path ),* ])
424425
}
425426

426427
fn make_run(run: RunConfig<'_>) {
427428
run.builder.ensure($name { target: run.target });
428429
}
429430

430431
fn run(self, builder: &Builder<'_>) {
431-
let compiler = builder.compiler(builder.top_stage, builder.config.build);
432-
let target = self.target;
433-
434-
builder.ensure(Rustc::new(target, builder));
435-
436-
let mut cargo = prepare_tool_cargo(
437-
builder,
438-
compiler,
439-
Mode::ToolRustc,
440-
target,
441-
builder.kind,
442-
$path,
443-
$source_type,
444-
&[],
445-
);
446-
447-
// For ./x.py clippy, don't run with --all-targets because
448-
// linting tests and benchmarks can produce very noisy results
449-
if builder.kind != Kind::Clippy {
450-
cargo.arg("--all-targets");
451-
}
452-
453-
let _guard = builder.msg_check(&format!("{} artifacts", $display_name), target);
454-
run_cargo(
455-
builder,
456-
cargo,
457-
builder.config.free_args.clone(),
458-
&stamp(builder, compiler, target),
459-
vec![],
460-
true,
461-
false,
462-
);
463-
464-
/// Cargo's output path in a given stage, compiled by a particular
465-
/// compiler for the specified target.
466-
fn stamp(
467-
builder: &Builder<'_>,
468-
compiler: Compiler,
469-
target: TargetSelection,
470-
) -> PathBuf {
471-
builder
472-
.cargo_out(compiler, Mode::ToolRustc, target)
473-
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()))
474-
}
432+
let Self { target } = self;
433+
run_tool_check_step(builder, target, stringify!($name), $path);
475434
}
476435
}
477-
};
436+
}
437+
}
438+
439+
/// Used by the implementation of `Step::run` in `tool_check_step!`.
440+
fn run_tool_check_step(
441+
builder: &Builder<'_>,
442+
target: TargetSelection,
443+
step_type_name: &str,
444+
path: &str,
445+
) {
446+
let display_name = path.rsplit('/').next().unwrap();
447+
let compiler = builder.compiler(builder.top_stage, builder.config.build);
448+
449+
builder.ensure(Rustc::new(target, builder));
450+
451+
let mut cargo = prepare_tool_cargo(
452+
builder,
453+
compiler,
454+
Mode::ToolRustc,
455+
target,
456+
builder.kind,
457+
path,
458+
// Currently, all of the tools that use this macro/function are in-tree.
459+
// If support for out-of-tree tools is re-added in the future, those
460+
// steps should probably be marked non-default so that the default
461+
// checks aren't affected by toolstate being broken.
462+
SourceType::InTree,
463+
&[],
464+
);
465+
466+
// For ./x.py clippy, don't run with --all-targets because
467+
// linting tests and benchmarks can produce very noisy results
468+
if builder.kind != Kind::Clippy {
469+
cargo.arg("--all-targets");
470+
}
471+
472+
let stamp = builder
473+
.cargo_out(compiler, Mode::ToolRustc, target)
474+
.join(format!(".{}-check.stamp", step_type_name.to_lowercase()));
475+
476+
let _guard = builder.msg_check(format!("{display_name} artifacts"), target);
477+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
478478
}
479479

480-
tool_check_step!(Rustdoc, "rustdoc", "src/tools/rustdoc", "src/librustdoc", SourceType::InTree);
480+
tool_check_step!(Rustdoc { path: "src/tools/rustdoc", alt_path: "src/librustdoc" });
481481
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
482482
// of a submodule. Since the SourceType only drives the deny-warnings
483483
// behavior, treat it as in-tree so that any new warnings in clippy will be
484484
// rejected.
485-
tool_check_step!(Clippy, "clippy", "src/tools/clippy", SourceType::InTree);
486-
tool_check_step!(Miri, "miri", "src/tools/miri", SourceType::InTree);
487-
tool_check_step!(CargoMiri, "cargo-miri", "src/tools/miri/cargo-miri", SourceType::InTree);
488-
tool_check_step!(Rls, "rls", "src/tools/rls", SourceType::InTree);
489-
tool_check_step!(Rustfmt, "rustfmt", "src/tools/rustfmt", SourceType::InTree);
490-
tool_check_step!(
491-
MiroptTestTools,
492-
"miropt-test-tools",
493-
"src/tools/miropt-test-tools",
494-
SourceType::InTree
495-
);
496-
tool_check_step!(
497-
TestFloatParse,
498-
"test-float-parse",
499-
"src/etc/test-float-parse",
500-
SourceType::InTree
501-
);
502-
503-
tool_check_step!(Bootstrap, "bootstrap", "src/bootstrap", SourceType::InTree, false);
485+
tool_check_step!(Clippy { path: "src/tools/clippy" });
486+
tool_check_step!(Miri { path: "src/tools/miri" });
487+
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri" });
488+
tool_check_step!(Rls { path: "src/tools/rls" });
489+
tool_check_step!(Rustfmt { path: "src/tools/rustfmt" });
490+
tool_check_step!(MiroptTestTools { path: "src/tools/miropt-test-tools" });
491+
tool_check_step!(TestFloatParse { path: "src/etc/test-float-parse" });
492+
493+
tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
504494
// Compiletest is implicitly "checked" when it gets built in order to run tests,
505495
// so this is mainly for people working on compiletest to run locally.
506-
tool_check_step!(Compiletest, "compiletest", "src/tools/compiletest", SourceType::InTree, false);
496+
tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });
507497

508498
/// Cargo's output path for the standard library in a given stage, compiled
509499
/// by a particular compiler for the specified target.

0 commit comments

Comments
 (0)