Skip to content

Commit 0d6bcc3

Browse files
committed
bootstrap: Add check/test/run steps for src/tools/coverage-dump
This also causes the coverage-dump unit tests to run in CI and `./x test` by default.
1 parent 555e1d0 commit 0d6bcc3

File tree

5 files changed

+98
-4
lines changed

5 files changed

+98
-4
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,70 @@ tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
527527
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
528528
// check to make it easier to work on.
529529
tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: false });
530+
531+
/// Check step for the `coverage-dump` bootstrap tool. The coverage-dump tool
532+
/// is used internally by coverage tests.
533+
///
534+
/// FIXME(Zalathar): This is temporarily separate from the other tool check
535+
/// steps so that it can use the stage 0 compiler instead of `top_stage`,
536+
/// without introducing conflicts with the stage 0 redesign (#119899).
537+
///
538+
/// After the stage 0 redesign lands, we can look into using the stage 0
539+
/// compiler to check all bootstrap tools (#139170).
540+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
541+
pub(crate) struct CoverageDump;
542+
543+
impl CoverageDump {
544+
const PATH: &str = "src/tools/coverage-dump";
545+
}
546+
547+
impl Step for CoverageDump {
548+
type Output = ();
549+
550+
/// Most contributors won't care about coverage-dump, so don't make their
551+
/// check builds slower unless they opt in and check it explicitly.
552+
const DEFAULT: bool = false;
553+
const ONLY_HOSTS: bool = true;
554+
555+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
556+
run.path(Self::PATH)
557+
}
558+
559+
fn make_run(run: RunConfig<'_>) {
560+
run.builder.ensure(Self {});
561+
}
562+
563+
fn run(self, builder: &Builder<'_>) -> Self::Output {
564+
// Make sure we haven't forgotten any fields, if there are any.
565+
let Self {} = self;
566+
let display_name = "coverage-dump";
567+
let host = builder.config.build;
568+
let target = host;
569+
let mode = Mode::ToolBootstrap;
570+
571+
let compiler = builder.compiler(0, host);
572+
let cargo = prepare_tool_cargo(
573+
builder,
574+
compiler,
575+
mode,
576+
target,
577+
builder.kind,
578+
Self::PATH,
579+
SourceType::InTree,
580+
&[],
581+
);
582+
583+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, mode, target))
584+
.with_prefix(&format!("{display_name}-check"));
585+
586+
let _guard = builder.msg_tool(
587+
builder.kind,
588+
mode,
589+
display_name,
590+
compiler.stage,
591+
&compiler.host,
592+
&target,
593+
);
594+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
595+
}
596+
}

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,31 @@ impl Step for CyclicStep {
392392
builder.ensure(CyclicStep { n: self.n.saturating_sub(1) })
393393
}
394394
}
395+
396+
/// Step to manually run the coverage-dump tool (`./x run coverage-dump`).
397+
///
398+
/// The coverage-dump tool is an internal detail of coverage tests, so this run
399+
/// step is only needed when testing coverage-dump manually.
400+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
401+
pub struct CoverageDump;
402+
403+
impl Step for CoverageDump {
404+
type Output = ();
405+
406+
const DEFAULT: bool = false;
407+
const ONLY_HOSTS: bool = true;
408+
409+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
410+
run.path("src/tools/coverage-dump")
411+
}
412+
413+
fn make_run(run: RunConfig<'_>) {
414+
run.builder.ensure(Self {});
415+
}
416+
417+
fn run(self, builder: &Builder<'_>) {
418+
let mut cmd = builder.tool_cmd(Tool::CoverageDump);
419+
cmd.args(&builder.config.free_args);
420+
cmd.run(builder);
421+
}
422+
}

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl Step for CrateBootstrap {
5454
run.path("src/tools/jsondoclint")
5555
.path("src/tools/suggest-tests")
5656
.path("src/tools/replace-version-placeholder")
57+
.path("src/tools/coverage-dump")
5758
// We want `./x test tidy` to _run_ the tidy tool, not its tests.
5859
// So we need a separate alias to test the tidy tool itself.
5960
.alias("tidyselftest")

src/bootstrap/src/core/builder/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ impl<'a> Builder<'a> {
961961
check::RunMakeSupport,
962962
check::Compiletest,
963963
check::FeaturesStatusDump,
964+
check::CoverageDump,
964965
),
965966
Kind::Test => describe!(
966967
crate::core::build_steps::toolstate::ToolStateCheck,
@@ -1114,6 +1115,7 @@ impl<'a> Builder<'a> {
11141115
run::UnicodeTableGenerator,
11151116
run::FeaturesStatusDump,
11161117
run::CyclicStep,
1118+
run::CoverageDump,
11171119
),
11181120
Kind::Setup => {
11191121
describe!(setup::Profile, setup::Hook, setup::Link, setup::Editor)

src/tools/coverage-dump/src/parser/tests.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use super::unescape_llvm_string_contents;
22

3-
// WARNING: These tests don't necessarily run in CI, and were mainly used to
4-
// help track down problems when originally developing this tool.
5-
// (The tool is still tested indirectly by snapshot tests that rely on it.)
6-
73
// Tests for `unescape_llvm_string_contents`:
84

95
#[test]

0 commit comments

Comments
 (0)