]> git.proxmox.com Git - cargo.git/commitdiff
Fix --scrape-examples-target-crate using package name (with dashes) instead of crate...
authorWill Crichton <wcrichto@cs.stanford.edu>
Thu, 4 Nov 2021 18:23:40 +0000 (11:23 -0700)
committerWill Crichton <wcrichto@cs.stanford.edu>
Thu, 4 Nov 2021 18:23:40 +0000 (11:23 -0700)
src/cargo/core/compiler/mod.rs
tests/testsuite/doc.rs

index 2f58b60abeb22658847858b268f4906cecf27274..2781ffbd8cfd8388afbee341a0714f485c44298c 100644 (file)
@@ -21,6 +21,7 @@ mod unit;
 pub mod unit_dependencies;
 pub mod unit_graph;
 
+use std::collections::HashSet;
 use std::env;
 use std::ffi::{OsStr, OsString};
 use std::fs::{self, File};
@@ -666,9 +667,14 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
 
         // Only scrape example for items from crates in the workspace, to reduce generated file size
         for pkg in cx.bcx.ws.members() {
-            rustdoc
-                .arg("--scrape-examples-target-crate")
-                .arg(pkg.name());
+            let names = pkg
+                .targets()
+                .iter()
+                .map(|target| target.crate_name())
+                .collect::<HashSet<_>>();
+            for name in names {
+                rustdoc.arg("--scrape-examples-target-crate").arg(name);
+            }
         }
     } else if cx.bcx.scrape_units.len() > 0 && cx.bcx.ws.is_member(&unit.pkg) {
         // We only pass scraped examples to packages in the workspace
index 9e7c6e04f2fb8a5eedf902b156cbaa0f2fd4e4f2..a8bd1447f710c62a09eb4897e515aa257190ea78 100644 (file)
@@ -2297,3 +2297,32 @@ fn scrape_examples_complex_reverse_dependencies() {
         .masquerade_as_nightly_cargo()
         .run();
 }
+
+#[cargo_test]
+fn scrape_examples_crate_with_dash() {
+    if !is_nightly() {
+        // -Z rustdoc-scrape-examples is unstable
+        return;
+    }
+
+    let p = project()
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "da-sh"
+                version = "0.0.1"
+                authors = []
+            "#,
+        )
+        .file("src/lib.rs", "pub fn foo() {}")
+        .file("examples/a.rs", "fn main() { da_sh::foo(); }")
+        .build();
+
+    p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples=all")
+        .masquerade_as_nightly_cargo()
+        .run();
+
+    let doc_html = p.read_file("target/doc/da_sh/fn.foo.html");
+    assert!(doc_html.contains("Examples found in repository"));
+}