Skip to content

Commit 2f1bbc6

Browse files
committed
Refactor test::LintDocs
1 parent 1f81491 commit 2f1bbc6

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,11 @@ fn doc_std(
791791
}
792792

793793
/// Prepare a compiler that will be able to document something for `target` at `stage`.
794-
fn prepare_doc_compiler(builder: &Builder<'_>, target: TargetSelection, stage: u32) -> Compiler {
794+
pub fn prepare_doc_compiler(
795+
builder: &Builder<'_>,
796+
target: TargetSelection,
797+
stage: u32,
798+
) -> Compiler {
795799
assert!(stage > 0, "Cannot document anything in stage 0");
796800
let build_compiler = builder.compiler(stage - 1, builder.host_target);
797801
builder.std(build_compiler, target);

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{env, fs, iter};
1212
use build_helper::exit;
1313

1414
use crate::core::build_steps::compile::{Std, run_cargo};
15-
use crate::core::build_steps::doc::DocumentationFormat;
15+
use crate::core::build_steps::doc::{DocumentationFormat, prepare_doc_compiler};
1616
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
1717
use crate::core::build_steps::llvm::get_llvm_version;
1818
use crate::core::build_steps::run::get_completion_paths;
@@ -3306,8 +3306,8 @@ impl Step for TierCheck {
33063306

33073307
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33083308
pub struct LintDocs {
3309-
pub compiler: Compiler,
3310-
pub target: TargetSelection,
3309+
build_compiler: Compiler,
3310+
target: TargetSelection,
33113311
}
33123312

33133313
impl Step for LintDocs {
@@ -3320,17 +3320,36 @@ impl Step for LintDocs {
33203320
}
33213321

33223322
fn make_run(run: RunConfig<'_>) {
3323+
// Bump the stage to 2, because the rustc book requires an in-tree compiler.
3324+
// At the same time, since this step is enabled by default, we don't want `x test` to fail
3325+
// in stage 1.
3326+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
3327+
run.builder.top_stage
3328+
} else {
3329+
2
3330+
};
3331+
33233332
run.builder.ensure(LintDocs {
3324-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
3333+
build_compiler: prepare_doc_compiler(
3334+
run.builder,
3335+
run.builder.config.host_target,
3336+
stage,
3337+
),
33253338
target: run.target,
33263339
});
33273340
}
33283341

33293342
/// Tests that the lint examples in the rustc book generate the correct
33303343
/// lints and have the expected format.
33313344
fn run(self, builder: &Builder<'_>) {
3332-
builder
3333-
.ensure(crate::core::build_steps::doc::RustcBook::validate(self.compiler, self.target));
3345+
builder.ensure(crate::core::build_steps::doc::RustcBook::validate(
3346+
self.build_compiler,
3347+
self.target,
3348+
));
3349+
}
3350+
3351+
fn metadata(&self) -> Option<StepMetadata> {
3352+
Some(StepMetadata::test("lint-docs", self.target).built_by(self.build_compiler))
33343353
}
33353354
}
33363355

src/bootstrap/src/core/builder/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,7 @@ mod snapshot {
20462046
[build] rustc 0 <host> -> Linkchecker 1 <host>
20472047
[test] tier-check <host>
20482048
[doc] rustc (book) <host>
2049+
[test] rustc 1 <host> -> lint-docs 2 <host>
20492050
[doc] rustc 1 <host> -> std 1 <host> crates=[]
20502051
[build] rustc 0 <host> -> RustdocTheme 1 <host>
20512052
[test] RustdocUi <host>

0 commit comments

Comments
 (0)