Skip to content

Commit 0b9bc79

Browse files
committed
Tests for number of times rustdoc is built with x.py test and doc.
1 parent 9154863 commit 0b9bc79

File tree

3 files changed

+94
-14
lines changed

3 files changed

+94
-14
lines changed

src/bootstrap/builder/tests.rs

+79
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ fn dist_baseline() {
5454
&[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
5555
);
5656
assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
57+
// Make sure rustdoc is only built once.
58+
assert_eq!(
59+
first(builder.cache.all::<tool::Rustdoc>()),
60+
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
61+
);
5762
}
5863

5964
#[test]
@@ -414,3 +419,77 @@ fn test_exclude() {
414419
// Ensure other tests are not affected.
415420
assert!(builder.cache.contains::<test::RustdocUi>());
416421
}
422+
423+
#[test]
424+
fn doc_default() {
425+
let mut config = configure(&[], &[]);
426+
config.compiler_docs = true;
427+
config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
428+
let build = Build::new(config);
429+
let mut builder = Builder::new(&build);
430+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
431+
let a = INTERNER.intern_str("A");
432+
433+
// error_index_generator uses stage 1 to share rustdoc artifacts with the
434+
// rustdoc tool.
435+
assert_eq!(
436+
first(builder.cache.all::<doc::ErrorIndex>()),
437+
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
438+
);
439+
assert_eq!(
440+
first(builder.cache.all::<tool::ErrorIndex>()),
441+
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
442+
);
443+
// This is actually stage 1, but Rustdoc::run swaps out the compiler with
444+
// stage minus 1 if --stage is not 0. Very confusing!
445+
assert_eq!(
446+
first(builder.cache.all::<tool::Rustdoc>()),
447+
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
448+
);
449+
}
450+
451+
#[test]
452+
fn test_docs() {
453+
// Behavior of `x.py test` doing various documentation tests.
454+
let mut config = configure(&[], &[]);
455+
config.cmd = Subcommand::Test {
456+
paths: vec![],
457+
test_args: vec![],
458+
rustc_args: vec![],
459+
fail_fast: true,
460+
doc_tests: DocTests::Yes,
461+
bless: false,
462+
compare_mode: None,
463+
rustfix_coverage: false,
464+
pass: None,
465+
};
466+
let build = Build::new(config);
467+
let mut builder = Builder::new(&build);
468+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
469+
let a = INTERNER.intern_str("A");
470+
471+
// error_index_generator uses stage 1 to share rustdoc artifacts with the
472+
// rustdoc tool.
473+
assert_eq!(
474+
first(builder.cache.all::<doc::ErrorIndex>()),
475+
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
476+
);
477+
assert_eq!(
478+
first(builder.cache.all::<tool::ErrorIndex>()),
479+
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
480+
);
481+
// Unfortunately rustdoc is built twice. Once from stage1 for compiletest
482+
// (and other things), and once from stage0 for std crates. Ideally it
483+
// would only be built once. If someone wants to fix this, it might be
484+
// worth investigating if it would be possible to test std from stage1.
485+
// Note that the stages here are +1 than what they actually are because
486+
// Rustdoc::run swaps out the compiler with stage minus 1 if --stage is
487+
// not 0.
488+
assert_eq!(
489+
first(builder.cache.all::<tool::Rustdoc>()),
490+
&[
491+
tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
492+
tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },
493+
]
494+
);
495+
}

src/bootstrap/doc.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,10 @@ impl Step for Rustdoc {
637637
}
638638
}
639639

640-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
640+
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
641641
pub struct ErrorIndex {
642-
target: Interned<String>,
642+
pub compiler: Compiler,
643+
pub target: Interned<String>,
643644
}
644645

645646
impl Step for ErrorIndex {
@@ -653,22 +654,22 @@ impl Step for ErrorIndex {
653654
}
654655

655656
fn make_run(run: RunConfig<'_>) {
656-
run.builder.ensure(ErrorIndex { target: run.target });
657+
let target = run.target;
658+
// error_index_generator depends on librustdoc. Use the compiler that
659+
// is normally used to build rustdoc for other documentation so that
660+
// it shares the same artifacts.
661+
let compiler =
662+
run.builder.compiler_for(run.builder.top_stage, run.builder.config.build, target);
663+
run.builder.ensure(ErrorIndex { compiler, target });
657664
}
658665

659666
/// Generates the HTML rendered error-index by running the
660667
/// `error_index_generator` tool.
661668
fn run(self, builder: &Builder<'_>) {
662-
let target = self.target;
663-
664-
builder.info(&format!("Documenting error index ({})", target));
665-
let out = builder.doc_out(target);
669+
builder.info(&format!("Documenting error index ({})", self.target));
670+
let out = builder.doc_out(self.target);
666671
t!(fs::create_dir_all(&out));
667-
// error_index_generator depends on librustdoc. Use the compiler that
668-
// is normally used to build rustdoc for other documentation so that
669-
// it shares the same artifacts.
670-
let compiler = builder.compiler_for(builder.top_stage, builder.config.build, target);
671-
let mut index = tool::ErrorIndex::command(builder, compiler);
672+
let mut index = tool::ErrorIndex::command(builder, self.compiler);
672673
index.arg("html");
673674
index.arg(out.join("error-index.html"));
674675
index.arg(crate::channel::CFG_RELEASE_NUM);

src/bootstrap/tool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ bootstrap_tool!(
366366
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
367367
);
368368

369-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
369+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
370370
pub struct ErrorIndex {
371371
pub compiler: Compiler,
372372
}
@@ -449,7 +449,7 @@ impl Step for RemoteTestServer {
449449
}
450450
}
451451

452-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
452+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
453453
pub struct Rustdoc {
454454
/// This should only ever be 0 or 2.
455455
/// We sometimes want to reference the "bootstrap" rustdoc, which is why this option is here.

0 commit comments

Comments
 (0)