Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set docs.rs as the default extern-map for crates.io #8877

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/cargo/core/compiler/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'de> serde::de::Deserialize<'de> for RustdocExternMode {
#[derive(serde::Deserialize, Debug, Default)]
#[serde(default)]
pub struct RustdocExternMap {
registries: HashMap<String, String>,
pub(crate) registries: HashMap<String, String>,
std: Option<RustdocExternMode>,
}

Expand All @@ -80,10 +80,6 @@ pub fn add_root_urls(
return Ok(());
}
let map = config.doc_extern_map()?;
if map.registries.is_empty() && map.std.is_none() {
// Skip doing unnecessary work.
return Ok(());
}
let mut unstable_opts = false;
// Collect mapping of registry name -> index url.
let name2url: HashMap<&String, Url> = map
Expand Down
11 changes: 9 additions & 2 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,15 @@ impl Config {
// Note: This does not support environment variables. The `Unit`
// fundamentally does not have access to the registry name, so there is
// nothing to query. Plumbing the name into SourceId is quite challenging.
self.doc_extern_map
.try_borrow_with(|| self.get::<RustdocExternMap>("doc.extern-map"))
self.doc_extern_map.try_borrow_with(|| {
let mut extern_map = self.get::<RustdocExternMap>("doc.extern-map");
if let Ok(map) = &mut extern_map {
map.registries
.entry("crates-io".into())
.or_insert("https://docs.rs/".into());
}
extern_map
})
}

/// Returns the `[target]` table definition for the given target triple.
Expand Down
30 changes: 12 additions & 18 deletions tests/testsuite/rustdoc_extern_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,10 @@ fn basic_project() -> Project {
.build()
}

fn docs_rs(p: &Project) {
p.change_file(
".cargo/config",
r#"
[doc.extern-map.registries]
crates-io = "https://docs.rs/"
"#,
);
}

#[cargo_test]
fn ignores_on_stable() {
// Requires -Zrustdoc-map to use.
let p = basic_project();
docs_rs(&p);
p.cargo("doc -v --no-deps")
.with_stderr_does_not_contain("[..]--extern-html-root-url[..]")
.run();
Expand All @@ -60,7 +49,6 @@ fn simple() {
return;
}
let p = basic_project();
docs_rs(&p);
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_contains(
Expand Down Expand Up @@ -157,7 +145,6 @@ fn renamed_dep() {
"#,
)
.build();
docs_rs(&p);
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_contains(
Expand Down Expand Up @@ -211,7 +198,6 @@ fn lib_name() {
"#,
)
.build();
docs_rs(&p);
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_contains(
Expand Down Expand Up @@ -338,7 +324,6 @@ fn multiple_versions() {
",
)
.build();
docs_rs(&p);
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_contains(
Expand All @@ -364,12 +349,21 @@ fn rebuilds_when_changing() {
let p = basic_project();
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain("[..]--extern-html-root-url[..]")
.with_stderr_contains("[..]--extern-html-root-url[..]")
.run();

docs_rs(&p);
// This also tests that the map for docs.rs can be overridden.
p.change_file(
".cargo/config",
r#"
[doc.extern-map.registries]
crates-io = "https://example.com/"
"#,
);
p.cargo("doc -v --no-deps -Zrustdoc-map")
.masquerade_as_nightly_cargo()
.with_stderr_contains("[..]--extern-html-root-url[..]")
.with_stderr_contains(
"[RUNNING] `rustdoc [..]--extern-html-root-url [..]bar=https://example.com/bar/1.0.0/[..]",
)
.run();
}