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
This commit is contained in:
Jack Huey 2021-02-02 16:01:42 -05:00 committed by GitHub
commit 3b9d77c7b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 24 deletions

View File

@ -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>()),
@ -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>()),
@ -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>()),

View File

@ -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,
}
@ -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
@ -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);

View File

@ -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 });
}
@ -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);
}
}

View File

@ -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))],
@ -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 });
}