Skip to content

Commit c6fd1fd

Browse files
committed
Change --extern-html-root-url to use crate source path as key
1 parent 120cf57 commit c6fd1fd

File tree

9 files changed

+32
-13
lines changed

9 files changed

+32
-13
lines changed

src/librustdoc/clean/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_attr as attr;
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{CtorKind, DefKind, Res};
17-
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
17+
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1818
use rustc_index::vec::{Idx, IndexVec};
1919
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
2020
use rustc_middle::bug;
@@ -211,9 +211,13 @@ impl Clean<ExternalCrate> for CrateNum {
211211
cx.tcx.item_children(root).iter().map(|item| item.res).filter_map(as_keyword).collect()
212212
};
213213

214+
let extern_paths =
215+
if *self == LOCAL_CRATE { vec![] } else { cx.tcx.crate_extern_paths(*self) };
216+
214217
ExternalCrate {
215218
name: cx.tcx.crate_name(*self).to_string(),
216219
src: krate_src,
220+
extern_paths,
217221
attrs: cx.tcx.get_attrs(root).clean(cx),
218222
primitives,
219223
keywords,

src/librustdoc/clean/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt;
44
use std::hash::{Hash, Hasher};
55
use std::iter::FromIterator;
66
use std::lazy::SyncOnceCell as OnceCell;
7+
use std::path::PathBuf;
78
use std::rc::Rc;
89
use std::sync::Arc;
910
use std::{slice, vec};
@@ -66,6 +67,7 @@ pub struct Crate {
6667
pub struct ExternalCrate {
6768
pub name: String,
6869
pub src: FileName,
70+
pub extern_paths: Vec<PathBuf>,
6971
pub attrs: Attributes,
7072
pub primitives: Vec<(DefId, PrimitiveType, Attributes)>,
7173
pub keywords: Vec<(DefId, String, Attributes)>,

src/librustdoc/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ pub struct RenderOptions {
214214
pub themes: Vec<StylePath>,
215215
/// If present, CSS file that contains rules to add to the default CSS.
216216
pub extension_css: Option<PathBuf>,
217-
/// A map of crate names to the URL to use instead of querying the crate's `html_root_url`.
218-
pub extern_html_root_urls: BTreeMap<String, String>,
217+
/// A map of crate sources to the URL to use instead of querying the crate's `html_root_url`.
218+
pub extern_html_root_urls: BTreeMap<PathBuf, String>,
219219
/// A map of the default settings (values are as for DOM storage API). Keys should lack the
220220
/// `rustdoc-` prefix.
221221
pub default_settings: HashMap<String, String>,
@@ -690,13 +690,13 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
690690
/// describing the issue.
691691
fn parse_extern_html_roots(
692692
matches: &getopts::Matches,
693-
) -> Result<BTreeMap<String, String>, &'static str> {
693+
) -> Result<BTreeMap<PathBuf, String>, &'static str> {
694694
let mut externs = BTreeMap::new();
695695
for arg in &matches.opt_strs("extern-html-root-url") {
696696
let mut parts = arg.splitn(2, '=');
697697
let name = parts.next().ok_or("--extern-html-root-url must not be empty")?;
698698
let url = parts.next().ok_or("--extern-html-root-url must be of the form name=url")?;
699-
externs.insert(name.to_string(), url.to_string());
699+
externs.insert(name.into(), url.to_string());
700700
}
701701

702702
Ok(externs)

src/librustdoc/formats/cache.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Cache {
128128
pub fn from_krate(
129129
render_info: RenderInfo,
130130
document_private: bool,
131-
extern_html_root_urls: &BTreeMap<String, String>,
131+
extern_html_root_urls: &BTreeMap<PathBuf, String>,
132132
dst: &Path,
133133
mut krate: clean::Crate,
134134
) -> (clean::Crate, Cache) {
@@ -173,7 +173,12 @@ impl Cache {
173173
},
174174
_ => PathBuf::new(),
175175
};
176-
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
176+
let extern_url = e
177+
.extern_paths
178+
.iter()
179+
.filter_map(|path| extern_html_root_urls.get(&*path))
180+
.next()
181+
.map(|u| &**u);
177182
cache
178183
.extern_locations
179184
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));

src/librustdoc/html/render/cache.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::html::render::{plain_text_summary, shorten};
1313
use crate::html::render::{Generic, IndexItem, IndexItemFunctionType, RenderType, TypeWithKind};
1414

1515
/// Indicates where an external crate can be found.
16+
#[derive(Debug)]
1617
pub enum ExternalLocation {
1718
/// Remote URL root of the external crate
1819
Remote(String),

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn opts() -> Vec<RustcOptGroup> {
146146
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
147147
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
148148
unstable("extern-html-root-url", |o| {
149-
o.optmulti("", "extern-html-root-url", "base URL to use for dependencies", "NAME=URL")
149+
o.optmulti("", "extern-html-root-url", "base URL to use for dependencies", "PATH=URL")
150150
}),
151151
stable("plugin-path", |o| o.optmulti("", "plugin-path", "removed", "DIR")),
152152
stable("C", |o| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// compile-flags: -C metadata=1
2+
pub mod iter {}
+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// compile-flags:-Z unstable-options --extern-html-root-url core=https://example.com/core/0.1.0
1+
// ignore-tidy-linelength
2+
// aux-crate: priv:extern_html_root_url=extern-html-root-url.rs
3+
// compile-flags: -Z unstable-options
4+
// compile-flags: --edition 2018
5+
// compile-flags: --extern-html-root-url {{build-base}}/extern-html-root-url/auxiliary/libextern_html_root_url.so=https://example.com/core/0.1.0
26

37
// @has extern_html_root_url/index.html
4-
// @has - '//a/@href' 'https://example.com/core/0.1.0/core/iter/index.html'
8+
// @has - '//a/@href' 'https://example.com/core/0.1.0/extern_html_root_url/iter/index.html'
59
#[doc(no_inline)]
6-
pub use std::iter;
10+
pub use extern_html_root_url::iter;

src/test/rustdoc/issue-76296-override.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// ignore-tidy-linelength
12
// aux-build: issue-76296-1.rs
23
// aux-build: issue-76296-2.rs
34
// compile-flags: -Z unstable-options
45
// compile-flags: --edition 2018
56
// compile-flags: --extern priv:foo1={{build-base}}/issue-76296-override/auxiliary/libfoo-1.so
67
// compile-flags: --extern priv:foo2={{build-base}}/issue-76296-override/auxiliary/libfoo-2.so
7-
// compile-flags: --extern-html-root-url foo=https://example.com/override/v1
8-
// compile-flags: --extern-html-root-url foo=https://example.com/override/v2
8+
// compile-flags: --extern-html-root-url {{build-base}}/issue-76296-override/auxiliary/libfoo-1.so=https://example.com/override/v1
9+
// compile-flags: --extern-html-root-url {{build-base}}/issue-76296-override/auxiliary/libfoo-2.so=https://example.com/override/v2
910

1011
// @has 'issue_76296_override/index.html'
1112
// @matches - '//a[@href="https://example.com/override/v1/foo/struct.Foo1.html"]' '^Foo1$'

0 commit comments

Comments
 (0)