Skip to content

Commit d259a5b

Browse files
authored
Unrolled build for rust-lang#122982
Rollup merge of rust-lang#122982 - Zalathar:bootstrap-coverage-docs, r=onur-ozkan Add more comments to the bootstrap code that handles `tests/coverage` At the bootstrap level, coverage tests are a bit more complicated than other test suites, because we want to run the same set of test files in multiple different modes, in a way that's convenient and flexible when invoked manually. This PR adds a few more comments to explain what's going on.
2 parents dda2372 + 1bbab71 commit d259a5b

File tree

1 file changed

+49
-16
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+49
-16
lines changed

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

+49-16
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,9 @@ macro_rules! test_definitions {
12891289
/// Adapted from [`test_definitions`].
12901290
macro_rules! coverage_test_alias {
12911291
($name:ident {
1292-
alias_and_mode: $alias_and_mode:expr,
1293-
default: $default:expr,
1294-
only_hosts: $only_hosts:expr $(,)?
1292+
alias_and_mode: $alias_and_mode:expr, // &'static str
1293+
default: $default:expr, // bool
1294+
only_hosts: $only_hosts:expr $(,)? // bool
12951295
}) => {
12961296
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12971297
pub struct $name {
@@ -1309,6 +1309,8 @@ macro_rules! coverage_test_alias {
13091309
const ONLY_HOSTS: bool = $only_hosts;
13101310

13111311
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1312+
// Register the mode name as a command-line alias.
1313+
// This allows `x test coverage-map` and `x test coverage-run`.
13121314
run.alias($alias_and_mode)
13131315
}
13141316

@@ -1319,8 +1321,7 @@ macro_rules! coverage_test_alias {
13191321
}
13201322

13211323
fn run(self, builder: &Builder<'_>) {
1322-
Coverage { compiler: self.compiler, target: self.target }
1323-
.run_unified_suite(builder, Self::MODE)
1324+
Coverage::run_coverage_tests(builder, self.compiler, self.target, Self::MODE);
13241325
}
13251326
}
13261327
};
@@ -1449,11 +1450,20 @@ host_test!(RunMakeFullDeps {
14491450

14501451
default_test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly" });
14511452

1452-
/// Custom test step that is responsible for running the coverage tests
1453-
/// in multiple different modes.
1453+
/// Coverage tests are a bit more complicated than other test suites, because
1454+
/// we want to run the same set of test files in multiple different modes,
1455+
/// in a way that's convenient and flexible when invoked manually.
1456+
///
1457+
/// This combined step runs the specified tests (or all of `tests/coverage`)
1458+
/// in both "coverage-map" and "coverage-run" modes.
1459+
///
1460+
/// Used by:
1461+
/// - `x test coverage`
1462+
/// - `x test tests/coverage`
1463+
/// - `x test tests/coverage/trivial.rs` (etc)
14541464
///
1455-
/// Each individual mode also has its own alias that will run the tests in
1456-
/// just that mode.
1465+
/// (Each individual mode also has its own step that will run the tests in
1466+
/// just that mode.)
14571467
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14581468
pub struct Coverage {
14591469
pub compiler: Compiler,
@@ -1464,24 +1474,41 @@ impl Coverage {
14641474
const PATH: &'static str = "tests/coverage";
14651475
const SUITE: &'static str = "coverage";
14661476

1467-
fn run_unified_suite(&self, builder: &Builder<'_>, mode: &'static str) {
1477+
/// Runs the coverage test suite (or a user-specified subset) in one mode.
1478+
///
1479+
/// This same function is used by the multi-mode step ([`Coverage`]) and by
1480+
/// the single-mode steps ([`CoverageMap`] and [`CoverageRun`]), to help
1481+
/// ensure that they all behave consistently with each other, regardless of
1482+
/// how the coverage tests have been invoked.
1483+
fn run_coverage_tests(
1484+
builder: &Builder<'_>,
1485+
compiler: Compiler,
1486+
target: TargetSelection,
1487+
mode: &'static str,
1488+
) {
1489+
// Like many other test steps, we delegate to a `Compiletest` step to
1490+
// actually run the tests. (See `test_definitions!`.)
14681491
builder.ensure(Compiletest {
1469-
compiler: self.compiler,
1470-
target: self.target,
1492+
compiler,
1493+
target,
14711494
mode,
14721495
suite: Self::SUITE,
14731496
path: Self::PATH,
14741497
compare_mode: None,
1475-
})
1498+
});
14761499
}
14771500
}
14781501

14791502
impl Step for Coverage {
14801503
type Output = ();
1504+
// We rely on the individual CoverageMap/CoverageRun steps to run themselves.
14811505
const DEFAULT: bool = false;
1506+
// When manually invoked, try to run as much as possible.
1507+
// Compiletest will automatically skip the "coverage-run" tests if necessary.
14821508
const ONLY_HOSTS: bool = false;
14831509

14841510
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1511+
// Take responsibility for command-line paths within `tests/coverage`.
14851512
run.suite_path(Self::PATH)
14861513
}
14871514

@@ -1492,20 +1519,26 @@ impl Step for Coverage {
14921519
}
14931520

14941521
fn run(self, builder: &Builder<'_>) {
1495-
self.run_unified_suite(builder, CoverageMap::MODE);
1496-
self.run_unified_suite(builder, CoverageRun::MODE);
1522+
// Run the specified coverage tests (possibly all of them) in both modes.
1523+
Self::run_coverage_tests(builder, self.compiler, self.target, CoverageMap::MODE);
1524+
Self::run_coverage_tests(builder, self.compiler, self.target, CoverageRun::MODE);
14971525
}
14981526
}
14991527

1500-
// Aliases for running the coverage tests in only one mode.
1528+
// Runs `tests/coverage` in "coverage-map" mode only.
1529+
// Used by `x test` and `x test coverage-map`.
15011530
coverage_test_alias!(CoverageMap {
15021531
alias_and_mode: "coverage-map",
15031532
default: true,
15041533
only_hosts: false,
15051534
});
1535+
// Runs `tests/coverage` in "coverage-run" mode only.
1536+
// Used by `x test` and `x test coverage-run`.
15061537
coverage_test_alias!(CoverageRun {
15071538
alias_and_mode: "coverage-run",
15081539
default: true,
1540+
// Compiletest knows how to automatically skip these tests when cross-compiling,
1541+
// but skipping the whole step here makes it clearer that they haven't run at all.
15091542
only_hosts: true,
15101543
});
15111544

0 commit comments

Comments
 (0)