about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2021-01-30 19:49:15 -0800
committerEric Huss <eric@huss.org>2021-01-31 10:25:29 -0800
commit071d22760af4b6f00fb52a6a2f28f9477b251772 (patch)
tree653513912013f3122b55b961a8e790bef1a86e34
parentfd20a8be0d74a7026267af5c9a0cd251eeaba7c6 (diff)
downloadrust-071d22760af4b6f00fb52a6a2f28f9477b251772.tar.gz
rust-071d22760af4b6f00fb52a6a2f28f9477b251772.zip
rustbuild: Don't build compiler twice for error-index-generator.
-rw-r--r--src/bootstrap/builder/tests.rs6
-rw-r--r--src/bootstrap/doc.rs10
-rw-r--r--src/bootstrap/test.rs17
-rw-r--r--src/bootstrap/tool.rs20
4 files changed, 29 insertions, 24 deletions
diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs
index a367aa53496..885fcfff030 100644
--- a/src/bootstrap/builder/tests.rs
+++ b/src/bootstrap/builder/tests.rs
@@ -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>()),
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs
index 8c849846676..c4b3e4cf95d 100644
--- a/src/bootstrap/doc.rs
+++ b/src/bootstrap/doc.rs
@@ -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);
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index 335a1731002..edacfd59c5c 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -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);
     }
 }
 
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index 835b8beb0e7..bf6bea539e5 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -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 });
     }