Skip to content

Commit ec7e313

Browse files
committed
rustdoc: fix missing resource suffix on crates.js
Fixes a regression introduced in #128252.
1 parent bf662eb commit ec7e313

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/librustdoc/html/render/write_shared.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ pub(crate) fn write_shared(
7575
let crate_name = krate.name(cx.tcx());
7676
let crate_name = crate_name.as_str(); // rand
7777
let crate_name_json = OrderedJson::serialize(crate_name).unwrap(); // "rand"
78-
let external_crates = hack_get_external_crate_names(&cx.dst)?;
78+
let external_crates = hack_get_external_crate_names(&cx.dst, &cx.shared.resource_suffix)?;
7979
let info = CrateInfo {
8080
src_files_js: SourcesPart::get(cx, &crate_name_json)?,
8181
search_index_js: SearchIndexPart::get(index, &cx.shared.resource_suffix)?,
82-
all_crates: AllCratesPart::get(crate_name_json.clone())?,
82+
all_crates: AllCratesPart::get(crate_name_json.clone(), &cx.shared.resource_suffix)?,
8383
crates_index: CratesIndexPart::get(&crate_name, &external_crates)?,
8484
trait_impl: TraitAliasPart::get(cx, &crate_name_json)?,
8585
type_impl: TypeAliasPart::get(cx, krate, &crate_name_json)?,
@@ -291,10 +291,13 @@ impl AllCratesPart {
291291
SortedTemplate::from_before_after("window.ALL_CRATES = [", "];")
292292
}
293293

294-
fn get(crate_name_json: OrderedJson) -> Result<PartsAndLocations<Self>, Error> {
294+
fn get(
295+
crate_name_json: OrderedJson,
296+
resource_suffix: &str,
297+
) -> Result<PartsAndLocations<Self>, Error> {
295298
// external hack_get_external_crate_names not needed here, because
296299
// there's no way that we write the search index but not crates.js
297-
let path = PathBuf::from("crates.js");
300+
let path = suffix_path("crates.js", resource_suffix);
298301
Ok(PartsAndLocations::with(path, crate_name_json))
299302
}
300303
}
@@ -305,8 +308,11 @@ impl AllCratesPart {
305308
///
306309
/// This is to match the current behavior of rustdoc, which allows you to get all crates
307310
/// on the index page, even if --enable-index-page is only passed to the last crate.
308-
fn hack_get_external_crate_names(doc_root: &Path) -> Result<Vec<String>, Error> {
309-
let path = doc_root.join("crates.js");
311+
fn hack_get_external_crate_names(
312+
doc_root: &Path,
313+
resource_suffix: &str,
314+
) -> Result<Vec<String>, Error> {
315+
let path = doc_root.join(suffix_path("crates.js", resource_suffix));
310316
let Ok(content) = fs::read_to_string(&path) else {
311317
// they didn't emit invocation specific, so we just say there were no crates
312318
return Ok(Vec::default());

src/librustdoc/html/render/write_shared/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::html::render::write_shared::*;
66
fn hack_external_crate_names() {
77
let path = tempfile::TempDir::new().unwrap();
88
let path = path.path();
9-
let crates = hack_get_external_crate_names(&path).unwrap();
9+
let crates = hack_get_external_crate_names(&path, "").unwrap();
1010
assert!(crates.is_empty());
1111
fs::write(path.join("crates.js"), r#"window.ALL_CRATES = ["a","b","c"];"#).unwrap();
12-
let crates = hack_get_external_crate_names(&path).unwrap();
12+
let crates = hack_get_external_crate_names(&path, "").unwrap();
1313
assert_eq!(crates, ["a".to_string(), "b".to_string(), "c".to_string()]);
1414
}
1515

tests/run-make/emit-shared-files/rmake.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() {
2020
.input("x.rs")
2121
.run();
2222
assert!(Path::new("invocation-only/search-index-xxx.js").exists());
23+
assert!(Path::new("invocation-only/crates-xxx.js").exists());
2324
assert!(Path::new("invocation-only/settings.html").exists());
2425
assert!(Path::new("invocation-only/x/all.html").exists());
2526
assert!(Path::new("invocation-only/x/index.html").exists());

0 commit comments

Comments
 (0)