[Wip] fix issue 5345
authorRichard Dodd <richard.dodd@itp-group.co.uk>
Sun, 15 Apr 2018 12:56:22 +0000 (13:56 +0100)
committerRichard Dodd <richard.dodd@itp-group.co.uk>
Sun, 15 Apr 2018 12:56:22 +0000 (13:56 +0100)
src/cargo/core/package.rs
src/cargo/core/source/mod.rs
src/cargo/ops/cargo_doc.rs
tests/testsuite/doc.rs

index 990144254da043a8e6a4a92c7e624b3bb1828ab5..5f8d24d1e7b47799c7d07a94462391fb3ae39393 100644 (file)
@@ -196,6 +196,7 @@ impl hash::Hash for Package {
     }
 }
 
+#[derive(Debug)]
 pub struct PackageSet<'cfg> {
     packages: HashMap<PackageId, LazyCell<Package>>,
     sources: RefCell<SourceMap<'cfg>>,
index 65380e2077be96ae2f6ed8c776b8f69c094ff983..b842a5792cfbd4489b19fa90784a1b133800a27a 100644 (file)
@@ -1,4 +1,5 @@
 use std::collections::hash_map::{HashMap, IterMut, Values};
+use std::fmt;
 
 use core::{Package, PackageId, Registry};
 use util::CargoResult;
@@ -78,6 +79,14 @@ pub struct SourceMap<'src> {
     map: HashMap<SourceId, Box<Source + 'src>>,
 }
 
+// impl debug on source requires specialization, if even desirable at all
+impl<'src> fmt::Debug for SourceMap<'src> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "SourceMap ")?;
+        f.debug_set().entries(self.map.keys()).finish()
+    }
+}
+
 /// A `std::collection::hash_map::Values` for `SourceMap`
 pub type Sources<'a, 'src> = Values<'a, SourceId, Box<Source + 'src>>;
 
index 647b639ab8719ec27e57d6c03215bb1e88fc7da1..3f2c93e889912719c7ea7c88bb83b23aa4c745e3 100644 (file)
@@ -7,11 +7,16 @@ use core::Workspace;
 use ops;
 use util::CargoResult;
 
+/// Strongly typed options for the `cargo doc` command.
+#[derive(Debug)]
 pub struct DocOptions<'a> {
+    /// Whether to attempt to open the browser after compiling the docs
     pub open_result: bool,
+    /// Options to pass through to the compiler
     pub compile_opts: ops::CompileOptions<'a>,
 }
 
+/// Main method for `cargo doc`.
 pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
     let specs = options.compile_opts.spec.into_package_id_specs(ws)?;
     let resolve = ops::resolve_ws_precisely(
@@ -34,6 +39,7 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
 
     let mut lib_names = HashMap::new();
     let mut bin_names = HashMap::new();
+    //println!("{:#?}", pkgs);
     for package in &pkgs {
         for target in package.targets().iter().filter(|t| t.documented()) {
             if target.is_lib() {
@@ -61,6 +67,7 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
     }
 
     ops::compile(ws, &options.compile_opts)?;
+    //println!("Made it!");
 
     if options.open_result {
         let name = if pkgs.len() > 1 {
index b1ea625fcd0e91f0d01291297205a7a91a62244b..f81c37fbf5aeea2f34c81031f6bd0067adc9e2e3 100644 (file)
@@ -1494,3 +1494,32 @@ fn doc_edition() {
             .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
     );
 }
+
+// Tests an issue where depending on different versions of the same file caused `cargo doc` to
+// fail.
+#[test]
+fn issue_5345() {
+    let foo = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [target.'cfg(all(windows, target_arch = "x86"))'.dependencies]
+            bar = "0.1"
+
+            [target.'cfg(not(all(windows, target_arch = "x86")))'.dependencies]
+            bar = "0.2"
+        "#,
+        )
+        .file("src/lib.rs", "extern crate bar;")
+        .build();
+    Package::new("bar", "0.1.0").publish();
+    Package::new("bar", "0.2.0").publish();
+
+    assert_that(foo.cargo("build"), execs().with_status(0));
+    assert_that(foo.cargo("doc"), execs().with_status(0));
+}