]> git.lizzy.rs Git - rust.git/commitdiff
Only generate documentation for local rustc crates.
authorDavid Wood <david@davidtw.co>
Thu, 22 Mar 2018 14:57:28 +0000 (14:57 +0000)
committerDavid Wood <david@davidtw.co>
Thu, 22 Mar 2018 17:21:30 +0000 (17:21 +0000)
src/bootstrap/doc.rs

index ca45adb4649afbb221d2de1a4f37a2ac2910e220..e525bdb98fc0c7e0517843439d1c9fd113e9bc15 100644 (file)
 //! Everything here is basically just a shim around calling either `rustbook` or
 //! `rustdoc`.
 
+use std::collections::HashSet;
 use std::fs::{self, File};
 use std::io::prelude::*;
 use std::io;
 use std::path::{PathBuf, Path};
 
-use Mode;
+use {Build, Mode};
 use build_helper::up_to_date;
 
 use util::{cp_r, symlink_dir};
@@ -704,15 +705,41 @@ fn run(self, builder: &Builder) {
         let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "doc");
         compile::rustc_cargo(build, &mut cargo);
 
-        // src/rustc/Cargo.toml contains a bin crate called rustc which
-        // would otherwise overwrite the docs for the real rustc lib crate.
-        cargo.arg("-p").arg("rustc_driver");
+        // Only include compiler crates, no dependencies of those, such as `libc`.
+        cargo.arg("--no-deps");
+
+        // Find dependencies for top level crates.
+        let mut compiler_crates = HashSet::new();
+        for root_crate in &["rustc", "rustc_driver"] {
+            let interned_root_crate = INTERNER.intern_str(root_crate);
+            find_compiler_crates(&build, &interned_root_crate, &mut compiler_crates);
+        }
+
+        for krate in &compiler_crates {
+            cargo.arg("-p").arg(krate);
+        }
 
         build.run(&mut cargo);
         cp_r(&my_out, &out);
     }
 }
 
+fn find_compiler_crates(
+    build: &Build,
+    name: &Interned<String>,
+    crates: &mut HashSet<Interned<String>>
+) {
+    // Add current crate.
+    crates.insert(*name);
+
+    // Look for dependencies.
+    for dep in build.crates.get(name).unwrap().deps.iter() {
+        if build.crates.get(dep).unwrap().is_local(build) {
+            find_compiler_crates(build, dep, crates);
+        }
+    }
+}
+
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct ErrorIndex {
     target: Interned<String>,