Skip to content

Commit b940258

Browse files
committed
--include-info-json --write-info-json take path directly to crate-info.json
1 parent 210fda6 commit b940258

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

src/librustdoc/config.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub(crate) struct RenderOptions {
298298
pub(crate) write_rendered_cci: bool,
299299
/// The location of the doc directory for externally located crates.
300300
/// Absolute path ending in doc/.
301-
pub(crate) parts_paths: FxHashMap<String, PathToParts>,
301+
pub(crate) parts_paths: Vec<PathToParts>,
302302
/// Where to write the cross-crate information parts
303303
pub(crate) parts_out_dir: Option<PathToParts>,
304304
}
@@ -505,10 +505,9 @@ impl Options {
505505
Err(err) => dcx.fatal(err),
506506
};
507507

508-
let parts_paths = match parse_include_info_json(matches) {
509-
Ok(ex) => ex,
510-
Err(err) => dcx.fatal(err),
511-
};
508+
let parts_paths = matches.opt_strs("include-info-json").iter()
509+
.map(|path| PathToParts::from_path_to_crate_info(PathBuf::from(path)))
510+
.collect();
512511

513512
let default_settings: Vec<Vec<(String, String)>> = vec![
514513
matches
@@ -754,7 +753,7 @@ impl Options {
754753
Ok(result) => result,
755754
Err(e) => dcx.fatal(format!("could not parse --merge: {e}")),
756755
};
757-
let parts_out_dir = matches.opt_str("write-info-json").map(|p| PathToParts::from_doc_root(PathBuf::from(p)));
756+
let parts_out_dir = matches.opt_str("write-info-json").map(|p| PathToParts::from_path_to_crate_info(PathBuf::from(p)));
758757

759758
if generate_link_to_definition && (show_coverage || output_format != OutputFormat::Html) {
760759
dcx.fatal(
@@ -924,35 +923,20 @@ fn parse_extern_html_roots(
924923

925924
/// Absolute path to cci root, including doc.parts, but not the crate name
926925
///
927-
/// For example, `/home/user/project/target/doc.parts/`.
926+
/// For example, `/home/user/project/target/doc.parts/<crate>/crate-info.json`.
928927
#[derive(Clone, Debug)]
929928
pub(crate) struct PathToParts(PathBuf);
930929

931930
impl PathToParts {
932931
/// Absolute path to cci root, including doc.parts, but not the crate name
933-
fn from_doc_root(doc_root: PathBuf) -> Self {
932+
fn from_path_to_crate_info(doc_root: PathBuf) -> Self {
934933
PathToParts(doc_root)
935934
}
936935

937936
/// Gets the final path at which to place the cci part
938-
pub(crate) fn crate_info_path(&self, crate_name: &str) -> PathBuf {
939-
PathBuf::from_iter([&self.0, Path::new(crate_name), Path::new("crate-info.json")])
940-
}
941-
}
942-
943-
/// Extracts `--include-info-json` arguments from `matches` and returns a map of crate names to
944-
/// the given locations. If an `--include-info-json` argument was ill-formed, returns an error
945-
/// describing the issue.
946-
fn parse_include_info_json(
947-
matches: &getopts::Matches,
948-
) -> Result<FxHashMap<String, PathToParts>, &'static str> {
949-
let mut externs = FxHashMap::default();
950-
for arg in &matches.opt_strs("include-info-json") {
951-
let (name, path) =
952-
arg.split_once('=').ok_or("--include-info-json must be of the form NAME=PATH")?;
953-
externs.insert(name.to_string(), PathToParts::from_doc_root(PathBuf::from(path)));
937+
pub(crate) fn path(&self) -> &Path {
938+
&self.0
954939
}
955-
Ok(externs)
956940
}
957941

958942
struct MergeResult {

src/librustdoc/html/render/offset_template.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ mod tests {
142142
s.starts_with("//")
143143
}
144144

145+
/// not correct, but good enough for these tests
145146
fn is_comment_html(s: &str) -> bool {
146147
s.starts_with("<!--") && s.ends_with("-->")
147148
}

src/librustdoc/html/render/write_shared.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct CrateInfo {
7575
}
7676

7777
impl CrateInfo {
78+
/// Gets a reference to the cross-crate information parts for `T`
7879
fn get<T: 'static>(&self) -> Option<&PartsAndLocations<T>> {
7980
(&self.src_files_js as &dyn Any).downcast_ref()
8081
.or_else(|| (&self.search_index_js as &dyn Any).downcast_ref())
@@ -84,17 +85,17 @@ impl CrateInfo {
8485
.or_else(|| (&self.type_impl as &dyn Any).downcast_ref())
8586
}
8687

87-
fn read(parts_paths: &FxHashMap<String, PathToParts>) -> Result<Vec<Self>, Error> {
88+
/// read all of the crate info from its location on the filesystem
89+
fn read(parts_paths: &[PathToParts]) -> Result<Vec<Self>, Error> {
8890
parts_paths.iter()
89-
.map(|(crate_name, parts_path)| {
90-
let path = parts_path.crate_info_path(crate_name);
91+
.map(|parts_path| {
92+
let path = parts_path.path();
9193
let parts = try_err!(fs::read(&path), &path);
9294
let parts: CrateInfo = try_err!(serde_json::from_slice(&parts), &path);
9395
Ok::<_, Error>(parts)
9496
})
9597
.collect::<Result<Vec<CrateInfo>, Error>>()
9698
}
97-
9899
}
99100

100101

@@ -125,8 +126,8 @@ pub(crate) fn write_shared(
125126
};
126127

127128
if let Some(parts_out_dir) = &opt.parts_out_dir {
128-
let path = parts_out_dir.crate_info_path(&crate_name);
129-
write_create_parents(cx, path, serde_json::to_string(&info).unwrap())?;
129+
let path = parts_out_dir.path().to_owned();
130+
write_create_parents(cx, dbg!(path), serde_json::to_string(&info).unwrap())?;
130131
}
131132

132133
let mut crates_info = CrateInfo::read(&opt.parts_paths)?;

0 commit comments

Comments
 (0)