Skip to content

Commit 3b9d77c

Browse files
authoredFeb 2, 2021
Rollup merge of #81603 - ehuss:error-index-build, r=Mark-Simulacrum
rustbuild: Don't build compiler twice for error-index-generator. When using `--stage=1`, the error-index-generator was forcing the compiler to be built twice. This isn't necessary; the error-index-generator just needs the same unusual logic that rustdoc uses to build with stage minus one. `--stage=0` and `--stage=2` should be unaffected by this change. cc #76371
2 parents d3304c8 + 071d227 commit 3b9d77c

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed
 

Diff for: ‎src/bootstrap/builder/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mod defaults {
146146
// rustdoc tool.
147147
assert_eq!(
148148
first(builder.cache.all::<doc::ErrorIndex>()),
149-
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 0 }, target: a },]
149+
&[doc::ErrorIndex { target: a },]
150150
);
151151
assert_eq!(
152152
first(builder.cache.all::<tool::ErrorIndex>()),
@@ -556,7 +556,7 @@ mod dist {
556556
// rustdoc tool.
557557
assert_eq!(
558558
first(builder.cache.all::<doc::ErrorIndex>()),
559-
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
559+
&[doc::ErrorIndex { target: a },]
560560
);
561561
assert_eq!(
562562
first(builder.cache.all::<tool::ErrorIndex>()),
@@ -594,7 +594,7 @@ mod dist {
594594
// rustdoc tool.
595595
assert_eq!(
596596
first(builder.cache.all::<doc::ErrorIndex>()),
597-
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
597+
&[doc::ErrorIndex { target: a },]
598598
);
599599
assert_eq!(
600600
first(builder.cache.all::<tool::ErrorIndex>()),

Diff for: ‎src/bootstrap/doc.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ impl Step for Rustdoc {
636636

637637
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
638638
pub struct ErrorIndex {
639-
pub compiler: Compiler,
640639
pub target: TargetSelection,
641640
}
642641

@@ -652,12 +651,7 @@ impl Step for ErrorIndex {
652651

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

663657
/// Generates the HTML rendered error-index by running the
@@ -666,7 +660,7 @@ impl Step for ErrorIndex {
666660
builder.info(&format!("Documenting error index ({})", self.target));
667661
let out = builder.doc_out(self.target);
668662
t!(fs::create_dir_all(&out));
669-
let mut index = tool::ErrorIndex::command(builder, self.compiler);
663+
let mut index = tool::ErrorIndex::command(builder);
670664
index.arg("html");
671665
index.arg(out.join("error-index.html"));
672666
index.arg(&builder.version);

Diff for: ‎src/bootstrap/test.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ impl Step for ErrorIndex {
14821482
// error_index_generator depends on librustdoc. Use the compiler that
14831483
// is normally used to build rustdoc for other tests (like compiletest
14841484
// tests in src/test/rustdoc) so that it shares the same artifacts.
1485-
let compiler = run.builder.compiler_for(run.builder.top_stage, run.target, run.target);
1485+
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
14861486
run.builder.ensure(ErrorIndex { compiler });
14871487
}
14881488

@@ -1499,19 +1499,16 @@ impl Step for ErrorIndex {
14991499
t!(fs::create_dir_all(&dir));
15001500
let output = dir.join("error-index.md");
15011501

1502-
let mut tool = tool::ErrorIndex::command(builder, compiler);
1502+
let mut tool = tool::ErrorIndex::command(builder);
15031503
tool.arg("markdown").arg(&output);
15041504

1505-
// Use the rustdoc that was built by self.compiler. This copy of
1506-
// rustdoc is shared with other tests (like compiletest tests in
1507-
// src/test/rustdoc). This helps avoid building rustdoc multiple
1508-
// times.
1509-
let rustdoc_compiler = builder.compiler(builder.top_stage, builder.config.build);
1510-
builder.info(&format!("Testing error-index stage{}", rustdoc_compiler.stage));
1505+
builder.info(&format!("Testing error-index stage{}", compiler.stage));
15111506
let _time = util::timeit(&builder);
15121507
builder.run_quiet(&mut tool);
1513-
builder.ensure(compile::Std { compiler: rustdoc_compiler, target: rustdoc_compiler.host });
1514-
markdown_test(builder, rustdoc_compiler, &output);
1508+
// The tests themselves need to link to std, so make sure it is
1509+
// available.
1510+
builder.ensure(compile::Std { compiler, target: compiler.host });
1511+
markdown_test(builder, compiler, &output);
15151512
}
15161513
}
15171514

Diff for: ‎src/bootstrap/tool.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,15 @@ pub struct ErrorIndex {
376376
}
377377

378378
impl ErrorIndex {
379-
pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
379+
pub fn command(builder: &Builder<'_>) -> Command {
380+
// This uses stage-1 to match the behavior of building rustdoc.
381+
// Error-index-generator links with the rustdoc library, so we want to
382+
// use the same librustdoc to avoid building rustdoc twice (and to
383+
// avoid building the compiler an extra time). This uses
384+
// saturating_sub to deal with building with stage 0. (Using stage 0
385+
// isn't recommended, since it will fail if any new error index tests
386+
// use new syntax, but it should work otherwise.)
387+
let compiler = builder.compiler(builder.top_stage.saturating_sub(1), builder.config.build);
380388
let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
381389
add_dylib_path(
382390
vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
@@ -396,8 +404,14 @@ impl Step for ErrorIndex {
396404
fn make_run(run: RunConfig<'_>) {
397405
// Compile the error-index in the same stage as rustdoc to avoid
398406
// recompiling rustdoc twice if we can.
399-
let host = run.builder.config.build;
400-
let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
407+
//
408+
// NOTE: This `make_run` isn't used in normal situations, only if you
409+
// manually build the tool with `x.py build
410+
// src/tools/error-index-generator` which almost nobody does.
411+
// Normally, `x.py test` or `x.py doc` will use the
412+
// `ErrorIndex::command` function instead.
413+
let compiler =
414+
run.builder.compiler(run.builder.top_stage.saturating_sub(1), run.builder.config.build);
401415
run.builder.ensure(ErrorIndex { compiler });
402416
}
403417

0 commit comments

Comments
 (0)
Please sign in to comment.