Skip to content

Commit

Permalink
Rollup merge of rust-lang#81603 - ehuss:error-index-build, r=Mark-Sim…
Browse files Browse the repository at this point in the history
…ulacrum

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 rust-lang#76371
  • Loading branch information
jackh726 authored Feb 2, 2021
2 parents fb487b5 + 071d227 commit 4a74152
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod defaults {
// rustdoc tool.
assert_eq!(
first(builder.cache.all::<doc::ErrorIndex>()),
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 0 }, target: a },]
&[doc::ErrorIndex { target: a },]
);
assert_eq!(
first(builder.cache.all::<tool::ErrorIndex>()),
Expand Down Expand Up @@ -556,7 +556,7 @@ mod dist {
// rustdoc tool.
assert_eq!(
first(builder.cache.all::<doc::ErrorIndex>()),
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
&[doc::ErrorIndex { target: a },]
);
assert_eq!(
first(builder.cache.all::<tool::ErrorIndex>()),
Expand Down Expand Up @@ -594,7 +594,7 @@ mod dist {
// rustdoc tool.
assert_eq!(
first(builder.cache.all::<doc::ErrorIndex>()),
&[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
&[doc::ErrorIndex { target: a },]
);
assert_eq!(
first(builder.cache.all::<tool::ErrorIndex>()),
Expand Down
10 changes: 2 additions & 8 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ impl Step for Rustdoc {

#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ErrorIndex {
pub compiler: Compiler,
pub target: TargetSelection,
}

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

fn make_run(run: RunConfig<'_>) {
let target = run.target;
// error_index_generator depends on librustdoc. Use the compiler that
// is normally used to build rustdoc for other documentation so that
// it shares the same artifacts.
let compiler =
run.builder.compiler_for(run.builder.top_stage, run.builder.config.build, target);
run.builder.ensure(ErrorIndex { compiler, target });
run.builder.ensure(ErrorIndex { target });
}

/// Generates the HTML rendered error-index by running the
Expand All @@ -666,7 +660,7 @@ impl Step for ErrorIndex {
builder.info(&format!("Documenting error index ({})", self.target));
let out = builder.doc_out(self.target);
t!(fs::create_dir_all(&out));
let mut index = tool::ErrorIndex::command(builder, self.compiler);
let mut index = tool::ErrorIndex::command(builder);
index.arg("html");
index.arg(out.join("error-index.html"));
index.arg(&builder.version);
Expand Down
17 changes: 7 additions & 10 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ impl Step for ErrorIndex {
// error_index_generator depends on librustdoc. Use the compiler that
// is normally used to build rustdoc for other tests (like compiletest
// tests in src/test/rustdoc) so that it shares the same artifacts.
let compiler = run.builder.compiler_for(run.builder.top_stage, run.target, run.target);
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
run.builder.ensure(ErrorIndex { compiler });
}

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

let mut tool = tool::ErrorIndex::command(builder, compiler);
let mut tool = tool::ErrorIndex::command(builder);
tool.arg("markdown").arg(&output);

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

Expand Down
20 changes: 17 additions & 3 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,15 @@ pub struct ErrorIndex {
}

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

Expand Down

0 comments on commit 4a74152

Please sign in to comment.