diff options
| author | bors <bors@rust-lang.org> | 2018-08-31 17:39:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-31 17:39:28 +0000 |
| commit | aaa170bebe31d03e2eea14e8cb06dc2e8891216b (patch) | |
| tree | 69401f21bce6a0136c59a6df85f20da6f29e700a /src/librustdoc/html | |
| parent | 163adf2860d0a5d9eff0e401e314de9383ff56a1 (diff) | |
| parent | fcb54f674ab5f86b72ef97178a3df255f1ef4783 (diff) | |
| download | rust-aaa170bebe31d03e2eea14e8cb06dc2e8891216b.tar.gz rust-aaa170bebe31d03e2eea14e8cb06dc2e8891216b.zip | |
Auto merge of #51384 - QuietMisdreavus:extern-version, r=GuillaumeGomez
rustdoc: add flag to control the html_root_url of dependencies The `--extern-html-root-url` flag in this PR allows one to override links to crates whose docs are not already available locally in the doc bundle. Docs.rs currently uses a version of this to make sure links to other crates go into that crate's docs.rs page. See the included test for intended use, but the idea is as follows: Calling rustdoc with `--extern-html-root-url crate=https://some-url.com` will cause rustdoc to override links that point to that crate to instead be replaced with a link rooted at `https://some-url.com/`. (e.g. for docs.rs this would be `https://docs.rs/crate/0.1.0` or the like.) Cheekily, rustup could use these options to redirect links to std/core/etc to instead point to locally-downloaded docs, if it so desired. Fixes https://github.com/rust-lang/rust/issues/19603
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1abe01dd0ac..be51ab5484d 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -479,6 +479,7 @@ pub fn initial_ids() -> Vec<String> { /// Generates the documentation for `crate` into the directory `dst` pub fn run(mut krate: clean::Crate, + extern_urls: BTreeMap<String, String>, external_html: &ExternalHtml, playground_url: Option<String>, dst: PathBuf, @@ -611,8 +612,9 @@ pub fn run(mut krate: clean::Crate, }, _ => PathBuf::new(), }; + let extern_url = extern_urls.get(&e.name).map(|u| &**u); cache.extern_locations.insert(n, (e.name.clone(), src_root, - extern_location(e, &cx.dst))); + extern_location(e, extern_url, &cx.dst))); let did = DefId { krate: n, index: CRATE_DEF_INDEX }; cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module)); @@ -1096,13 +1098,23 @@ fn clean_srcpath<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) wh /// Attempts to find where an external crate is located, given that we're /// rendering in to the specified source destination. -fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation { +fn extern_location(e: &clean::ExternalCrate, extern_url: Option<&str>, dst: &Path) + -> ExternalLocation +{ // See if there's documentation generated into the local directory let local_location = dst.join(&e.name); if local_location.is_dir() { return Local; } + if let Some(url) = extern_url { + let mut url = url.to_string(); + if !url.ends_with("/") { + url.push('/'); + } + return Remote(url); + } + // Failing that, see if there's an attribute specifying where to find this // external crate e.attrs.lists("doc") |
