From 83344195ee86d249d5bfae6d732082eb6899be54 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 14 Jul 2020 21:18:41 -0700 Subject: [PATCH] Use local links in the alloc docs. --- src/bootstrap/builder.rs | 3 ++- src/bootstrap/doc.rs | 39 +++++++++++++++------------------------ src/bootstrap/lib.rs | 7 ------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 557fb1aa550a5..f6060ac14e75e 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -773,7 +773,8 @@ impl<'a> Builder<'a> { let my_out = match mode { // This is the intended out directory for compiler documentation. Mode::Rustc | Mode::ToolRustc | Mode::Codegen => self.compiler_doc_out(target), - _ => self.crate_doc_out(target), + Mode::Std => out_dir.join(target).join("doc"), + _ => panic!("doc mode {:?} not expected", mode), }; let rustdoc = self.rustdoc(compiler); self.clear_if_dirty(&my_out, &rustdoc); diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 582bc9da0e804..3121690285868 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -417,21 +417,6 @@ impl Step for Std { builder.ensure(compile::Std { compiler, target }); let out_dir = builder.stage_out(compiler, Mode::Std).join(target).join("doc"); - // Here what we're doing is creating a *symlink* (directory junction on - // Windows) to the final output location. This is not done as an - // optimization but rather for correctness. We've got three trees of - // documentation, one for std, one for test, and one for rustc. It's then - // our job to merge them all together. - // - // Unfortunately rustbuild doesn't know nearly as well how to merge doc - // trees as rustdoc does itself, so instead of actually having three - // separate trees we just have rustdoc output to the same location across - // all of them. - // - // This way rustdoc generates output directly into the output, and rustdoc - // will also directly handle merging. - let my_out = builder.crate_doc_out(target); - t!(symlink_dir_force(&builder.config, &my_out, &out_dir)); t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css"))); let run_cargo_rustdoc_for = |package: &str| { @@ -439,12 +424,9 @@ impl Step for Std { builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc"); compile::std_cargo(builder, target, compiler.stage, &mut cargo); - cargo.arg("-p").arg(package); - // Create all crate output directories first to make sure rustdoc uses - // relative links. - // FIXME: Cargo should probably do this itself. - t!(fs::create_dir_all(out_dir.join(package))); cargo + .arg("-p") + .arg(package) .arg("--") .arg("--markdown-css") .arg("rust.css") @@ -462,11 +444,17 @@ impl Step for Std { // folder structure, that would also build internal crates that we do // not want to show in documentation. These crates will later be visited // by the rustc step, so internal documentation will show them. - let krates = ["alloc", "core", "std", "proc_macro", "test"]; + // + // Note that the order here is important! The crates need to be + // processed starting from the leaves, otherwise rustdoc will not + // create correct links between crates because rustdoc depends on the + // existence of the output directories to know if it should be a local + // or remote link. + let krates = ["core", "alloc", "std", "proc_macro", "test"]; for krate in &krates { run_cargo_rustdoc_for(krate); } - builder.cp_r(&my_out, &out); + builder.cp_r(&out_dir, &out); // Look for src/libstd, src/libcore etc in the `x.py doc` arguments and // open the corresponding rendered docs. @@ -529,8 +517,11 @@ impl Step for Rustc { // Build rustc. builder.ensure(compile::Rustc { compiler, target }); - // We do not symlink to the same shared folder that already contains std library - // documentation from previous steps as we do not want to include that. + // This uses a shared directory so that librustdoc documentation gets + // correctly built and merged with the rustc documentation. This is + // needed because rustdoc is built in a different directory from + // rustc. rustdoc needs to be able to see everything, for example when + // merging the search index, or generating local (relative) links. let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc"); t!(symlink_dir_force(&builder.config, &out, &out_dir)); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 783a64c3581f9..9ca9e338d55c5 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -612,13 +612,6 @@ impl Build { INTERNER.intern_path(self.out.join(&*target).join("md-doc")) } - /// Output directory for all crate documentation for a target (temporary) - /// - /// The artifacts here are then copied into `doc_out` above. - fn crate_doc_out(&self, target: Interned) -> PathBuf { - self.out.join(&*target).join("crate-docs") - } - /// Returns `true` if no custom `llvm-config` is set for the specified target. /// /// If no custom `llvm-config` was specified then Rust's llvm will be used.