Skip to content

Commit ef4cc9b

Browse files
authored
Rollup merge of #145007 - Kobzol:error-index, r=jieyouxu
Fix build/doc/test of error index generator It is essentially a RustcPrivate tool, so it should be treated as such using the new `RustcPrivateCompilers` infra. Found while working on unrelated `doc` cleanups. r? `@jieyouxu`
2 parents 44163e3 + b1f49d8 commit ef4cc9b

File tree

4 files changed

+124
-87
lines changed

4 files changed

+124
-87
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use std::path::{Path, PathBuf};
1212
use std::{env, fs, mem};
1313

1414
use crate::core::build_steps::compile;
15-
use crate::core::build_steps::tool::{self, SourceType, Tool, prepare_tool_cargo};
15+
use crate::core::build_steps::tool::{
16+
self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo,
17+
};
1618
use crate::core::builder::{
1719
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata,
1820
crate_description,
@@ -1082,9 +1084,9 @@ tool_doc!(
10821084
crates = ["compiletest"]
10831085
);
10841086

1085-
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
1087+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
10861088
pub struct ErrorIndex {
1087-
pub target: TargetSelection,
1089+
compilers: RustcPrivateCompilers,
10881090
}
10891091

10901092
impl Step for ErrorIndex {
@@ -1098,17 +1100,29 @@ impl Step for ErrorIndex {
10981100
}
10991101

11001102
fn make_run(run: RunConfig<'_>) {
1101-
let target = run.target;
1102-
run.builder.ensure(ErrorIndex { target });
1103+
run.builder.ensure(ErrorIndex {
1104+
compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
1105+
});
11031106
}
11041107

11051108
/// Generates the HTML rendered error-index by running the
11061109
/// `error_index_generator` tool.
11071110
fn run(self, builder: &Builder<'_>) {
1108-
builder.info(&format!("Documenting error index ({})", self.target));
1109-
let out = builder.doc_out(self.target);
1111+
builder.info(&format!("Documenting error index ({})", self.compilers.target()));
1112+
let out = builder.doc_out(self.compilers.target());
11101113
t!(fs::create_dir_all(&out));
1111-
tool::ErrorIndex::command(builder).arg("html").arg(out).arg(&builder.version).run(builder);
1114+
tool::ErrorIndex::command(builder, self.compilers)
1115+
.arg("html")
1116+
.arg(out)
1117+
.arg(&builder.version)
1118+
.run(builder);
1119+
}
1120+
1121+
fn metadata(&self) -> Option<StepMetadata> {
1122+
Some(
1123+
StepMetadata::doc("error-index", self.compilers.target())
1124+
.built_by(self.compilers.build_compiler()),
1125+
)
11121126
}
11131127
}
11141128

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ test_book!(
25022502

25032503
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
25042504
pub struct ErrorIndex {
2505-
compiler: Compiler,
2505+
compilers: RustcPrivateCompilers,
25062506
}
25072507

25082508
impl Step for ErrorIndex {
@@ -2520,8 +2520,12 @@ impl Step for ErrorIndex {
25202520
// error_index_generator depends on librustdoc. Use the compiler that
25212521
// is normally used to build rustdoc for other tests (like compiletest
25222522
// tests in tests/rustdoc) so that it shares the same artifacts.
2523-
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.host_target);
2524-
run.builder.ensure(ErrorIndex { compiler });
2523+
let compilers = RustcPrivateCompilers::new(
2524+
run.builder,
2525+
run.builder.top_stage,
2526+
run.builder.config.host_target,
2527+
);
2528+
run.builder.ensure(ErrorIndex { compilers });
25252529
}
25262530

25272531
/// Runs the error index generator tool to execute the tests located in the error
@@ -2531,24 +2535,30 @@ impl Step for ErrorIndex {
25312535
/// generate a markdown file from the error indexes of the code base which is
25322536
/// then passed to `rustdoc --test`.
25332537
fn run(self, builder: &Builder<'_>) {
2534-
let compiler = self.compiler;
2538+
// The compiler that we are testing
2539+
let target_compiler = self.compilers.target_compiler();
25352540

2536-
let dir = testdir(builder, compiler.host);
2541+
let dir = testdir(builder, target_compiler.host);
25372542
t!(fs::create_dir_all(&dir));
25382543
let output = dir.join("error-index.md");
25392544

2540-
let mut tool = tool::ErrorIndex::command(builder);
2545+
let mut tool = tool::ErrorIndex::command(builder, self.compilers);
25412546
tool.arg("markdown").arg(&output);
25422547

2543-
let guard =
2544-
builder.msg(Kind::Test, compiler.stage, "error-index", compiler.host, compiler.host);
2548+
let guard = builder.msg(
2549+
Kind::Test,
2550+
target_compiler.stage,
2551+
"error-index",
2552+
target_compiler.host,
2553+
target_compiler.host,
2554+
);
25452555
let _time = helpers::timeit(builder);
25462556
tool.run_capture(builder);
25472557
drop(guard);
25482558
// The tests themselves need to link to std, so make sure it is
25492559
// available.
2550-
builder.std(compiler, compiler.host);
2551-
markdown_test(builder, compiler, &output);
2560+
builder.std(target_compiler, target_compiler.host);
2561+
markdown_test(builder, target_compiler, &output);
25522562
}
25532563
}
25542564

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,20 @@ impl Step for RustcPerf {
588588
}
589589
}
590590

591-
#[derive(Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
591+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
592592
pub struct ErrorIndex {
593-
pub compiler: Compiler,
593+
compilers: RustcPrivateCompilers,
594594
}
595595

596596
impl ErrorIndex {
597-
pub fn command(builder: &Builder<'_>) -> BootstrapCommand {
597+
pub fn command(builder: &Builder<'_>, compilers: RustcPrivateCompilers) -> BootstrapCommand {
598598
// Error-index-generator links with the rustdoc library, so we need to add `rustc_lib_paths`
599599
// for rustc_private and libLLVM.so, and `sysroot_lib` for libstd, etc.
600-
let host = builder.config.host_target;
601-
let compiler = builder.compiler_for(builder.top_stage, host, host);
602-
let mut cmd = command(builder.ensure(ErrorIndex { compiler }).tool_path);
603-
let mut dylib_paths = builder.rustc_lib_paths(compiler);
604-
dylib_paths.push(builder.sysroot_target_libdir(compiler, compiler.host));
600+
let mut cmd = command(builder.ensure(ErrorIndex { compilers }).tool_path);
601+
602+
let target_compiler = compilers.target_compiler();
603+
let mut dylib_paths = builder.rustc_lib_paths(target_compiler);
604+
dylib_paths.push(builder.sysroot_target_libdir(target_compiler, target_compiler.host));
605605
add_dylib_path(dylib_paths, &mut cmd);
606606
cmd
607607
}
@@ -620,14 +620,19 @@ impl Step for ErrorIndex {
620620
// src/tools/error-index-generator` which almost nobody does.
621621
// Normally, `x.py test` or `x.py doc` will use the
622622
// `ErrorIndex::command` function instead.
623-
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.host_target);
624-
run.builder.ensure(ErrorIndex { compiler });
623+
run.builder.ensure(ErrorIndex {
624+
compilers: RustcPrivateCompilers::new(
625+
run.builder,
626+
run.builder.top_stage,
627+
run.builder.host_target,
628+
),
629+
});
625630
}
626631

627632
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
628633
builder.ensure(ToolBuild {
629-
build_compiler: self.compiler,
630-
target: self.compiler.host,
634+
build_compiler: self.compilers.build_compiler,
635+
target: self.compilers.target(),
631636
tool: "error_index_generator",
632637
mode: Mode::ToolRustc,
633638
path: "src/tools/error_index_generator",
@@ -638,6 +643,13 @@ impl Step for ErrorIndex {
638643
artifact_kind: ToolArtifactKind::Binary,
639644
})
640645
}
646+
647+
fn metadata(&self) -> Option<StepMetadata> {
648+
Some(
649+
StepMetadata::build("error-index", self.compilers.target())
650+
.built_by(self.compilers.build_compiler),
651+
)
652+
}
641653
}
642654

643655
#[derive(Debug, Clone, Hash, PartialEq, Eq)]

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

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -257,31 +257,6 @@ fn parse_config_download_rustc_at(path: &Path, download_rustc: &str, ci: bool) -
257257
)
258258
}
259259

260-
mod defaults {
261-
use pretty_assertions::assert_eq;
262-
263-
use super::{TEST_TRIPLE_1, TEST_TRIPLE_2, configure, first, run_build};
264-
use crate::Config;
265-
use crate::core::builder::*;
266-
267-
#[test]
268-
fn doc_default() {
269-
let mut config = configure("doc", &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
270-
config.compiler_docs = true;
271-
config.cmd = Subcommand::Doc { open: false, json: false };
272-
let mut cache = run_build(&[], config);
273-
let a = TargetSelection::from_user(TEST_TRIPLE_1);
274-
275-
// error_index_generator uses stage 0 to share rustdoc artifacts with the
276-
// rustdoc tool.
277-
assert_eq!(first(cache.all::<doc::ErrorIndex>()), &[doc::ErrorIndex { target: a },]);
278-
assert_eq!(
279-
first(cache.all::<tool::ErrorIndex>()),
280-
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
281-
);
282-
}
283-
}
284-
285260
mod dist {
286261
use pretty_assertions::assert_eq;
287262

@@ -309,28 +284,6 @@ mod dist {
309284
let target = TargetSelection::from_user(TEST_TRIPLE_1);
310285
assert!(build.llvm_out(target).ends_with("llvm"));
311286
}
312-
313-
#[test]
314-
fn doc_ci() {
315-
let mut config = configure(&[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
316-
config.compiler_docs = true;
317-
config.cmd = Subcommand::Doc { open: false, json: false };
318-
let build = Build::new(config);
319-
let mut builder = Builder::new(&build);
320-
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
321-
let a = TargetSelection::from_user(TEST_TRIPLE_1);
322-
323-
// error_index_generator uses stage 1 to share rustdoc artifacts with the
324-
// rustdoc tool.
325-
assert_eq!(
326-
first(builder.cache.all::<doc::ErrorIndex>()),
327-
&[doc::ErrorIndex { target: a },]
328-
);
329-
assert_eq!(
330-
first(builder.cache.all::<tool::ErrorIndex>()),
331-
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
332-
);
333-
}
334287
}
335288

336289
mod sysroot_target_dirs {
@@ -888,6 +841,19 @@ mod snapshot {
888841
");
889842
}
890843

844+
#[test]
845+
fn build_error_index() {
846+
let ctx = TestCtx::new();
847+
insta::assert_snapshot!(
848+
ctx.config("build")
849+
.path("error_index_generator")
850+
.render_steps(), @r"
851+
[build] llvm <host>
852+
[build] rustc 0 <host> -> rustc 1 <host>
853+
[build] rustc 0 <host> -> error-index 1 <host>
854+
");
855+
}
856+
891857
#[test]
892858
fn build_bootstrap_tool_no_explicit_stage() {
893859
let ctx = TestCtx::new();
@@ -1032,6 +998,8 @@ mod snapshot {
1032998
[build] rustc 1 <host> -> rustc 2 <host>
1033999
[build] rustdoc 2 <host>
10341000
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1001+
[build] rustc 1 <host> -> error-index 2 <host>
1002+
[doc] rustc 1 <host> -> error-index 2 <host>
10351003
[build] rustc 2 <host> -> std 2 <host>
10361004
[build] rustc 0 <host> -> LintDocs 1 <host>
10371005
[build] rustc 0 <host> -> RustInstaller 1 <host>
@@ -1074,6 +1042,8 @@ mod snapshot {
10741042
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
10751043
[build] rustdoc 2 <host>
10761044
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1045+
[build] rustc 1 <host> -> error-index 2 <host>
1046+
[doc] rustc 1 <host> -> error-index 2 <host>
10771047
[build] rustc 2 <host> -> std 2 <host>
10781048
[build] rustc 0 <host> -> LintDocs 1 <host>
10791049
[build] rustc 0 <host> -> RustInstaller 1 <host>
@@ -1114,6 +1084,8 @@ mod snapshot {
11141084
[build] rustdoc 2 <host>
11151085
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11161086
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1087+
[build] rustc 1 <host> -> error-index 2 <host>
1088+
[doc] rustc 1 <host> -> error-index 2 <host>
11171089
[build] rustc 2 <host> -> std 2 <host>
11181090
[build] rustc 0 <host> -> LintDocs 1 <host>
11191091
[build] rustc 0 <host> -> RustInstaller 1 <host>
@@ -1150,18 +1122,22 @@ mod snapshot {
11501122
[build] rustc 1 <host> -> rustc 2 <host>
11511123
[build] rustdoc 2 <host>
11521124
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1125+
[build] rustc 1 <host> -> error-index 2 <host>
1126+
[doc] rustc 1 <host> -> error-index 2 <host>
1127+
[build] llvm <target1>
1128+
[build] rustc 1 <host> -> std 1 <target1>
1129+
[build] rustc 1 <host> -> rustc 2 <target1>
1130+
[build] rustc 1 <host> -> error-index 2 <target1>
1131+
[doc] rustc 1 <host> -> error-index 2 <target1>
11531132
[build] rustc 2 <host> -> std 2 <host>
11541133
[build] rustc 0 <host> -> LintDocs 1 <host>
1155-
[build] rustc 1 <host> -> std 1 <target1>
11561134
[build] rustc 2 <host> -> std 2 <target1>
11571135
[build] rustc 0 <host> -> RustInstaller 1 <host>
11581136
[dist] docs <host>
11591137
[doc] std 2 <host> crates=[]
11601138
[dist] mingw <host>
11611139
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
11621140
[dist] rustc <host>
1163-
[build] llvm <target1>
1164-
[build] rustc 1 <host> -> rustc 2 <target1>
11651141
[build] rustdoc 2 <target1>
11661142
[dist] rustc <target1>
11671143
[dist] rustc 1 <host> -> std 1 <host>
@@ -1188,9 +1164,15 @@ mod snapshot {
11881164
[build] rustdoc 2 <host>
11891165
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11901166
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1167+
[build] rustc 1 <host> -> error-index 2 <host>
1168+
[doc] rustc 1 <host> -> error-index 2 <host>
1169+
[build] llvm <target1>
1170+
[build] rustc 1 <host> -> std 1 <target1>
1171+
[build] rustc 1 <host> -> rustc 2 <target1>
1172+
[build] rustc 1 <host> -> error-index 2 <target1>
1173+
[doc] rustc 1 <host> -> error-index 2 <target1>
11911174
[build] rustc 2 <host> -> std 2 <host>
11921175
[build] rustc 0 <host> -> LintDocs 1 <host>
1193-
[build] rustc 1 <host> -> std 1 <target1>
11941176
[build] rustc 2 <host> -> std 2 <target1>
11951177
[build] rustc 0 <host> -> RustInstaller 1 <host>
11961178
[dist] docs <host>
@@ -1201,8 +1183,6 @@ mod snapshot {
12011183
[dist] mingw <target1>
12021184
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
12031185
[dist] rustc <host>
1204-
[build] llvm <target1>
1205-
[build] rustc 1 <host> -> rustc 2 <target1>
12061186
[build] rustdoc 2 <target1>
12071187
[dist] rustc <target1>
12081188
[dist] rustc 1 <host> -> std 1 <host>
@@ -1261,17 +1241,19 @@ mod snapshot {
12611241
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
12621242
[build] rustdoc 2 <host>
12631243
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1264-
[build] rustc 2 <host> -> std 2 <host>
1244+
[build] llvm <target1>
12651245
[build] rustc 1 <host> -> std 1 <target1>
1246+
[build] rustc 1 <host> -> rustc 2 <target1>
1247+
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
1248+
[build] rustc 1 <host> -> error-index 2 <target1>
1249+
[doc] rustc 1 <host> -> error-index 2 <target1>
1250+
[build] rustc 2 <host> -> std 2 <host>
12661251
[build] rustc 2 <host> -> std 2 <target1>
12671252
[build] rustc 0 <host> -> LintDocs 1 <host>
12681253
[build] rustc 0 <host> -> RustInstaller 1 <host>
12691254
[dist] docs <target1>
12701255
[doc] std 2 <target1> crates=[]
12711256
[dist] mingw <target1>
1272-
[build] llvm <target1>
1273-
[build] rustc 1 <host> -> rustc 2 <target1>
1274-
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
12751257
[build] rustdoc 2 <target1>
12761258
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
12771259
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
@@ -1651,6 +1633,25 @@ mod snapshot {
16511633
");
16521634
}
16531635

1636+
#[test]
1637+
fn doc_all() {
1638+
let ctx = TestCtx::new();
1639+
insta::assert_snapshot!(
1640+
ctx.config("doc")
1641+
.render_steps(), @r"
1642+
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
1643+
[build] rustc 0 <host> -> Rustbook 1 <host>
1644+
[build] llvm <host>
1645+
[build] rustc 0 <host> -> rustc 1 <host>
1646+
[build] rustdoc 1 <host>
1647+
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1648+
[build] rustc 0 <host> -> error-index 1 <host>
1649+
[doc] rustc 0 <host> -> error-index 1 <host>
1650+
[build] rustc 1 <host> -> std 1 <host>
1651+
[build] rustc 0 <host> -> LintDocs 1 <host>
1652+
");
1653+
}
1654+
16541655
#[test]
16551656
fn doc_library() {
16561657
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)