Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bf25334

Browse files
committed
Make --static-root-path point to static.files
1 parent f9e1f6f commit bf25334

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

src/librustdoc/html/layout.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ pub(crate) struct Page<'a> {
3535
}
3636

3737
impl<'a> Page<'a> {
38-
pub(crate) fn get_static_root_path(&self) -> &str {
39-
self.static_root_path.unwrap_or(self.root_path)
38+
pub(crate) fn get_static_root_path(&self) -> String {
39+
match self.static_root_path {
40+
Some(s) => s.to_string(),
41+
None => format!("{}{}", self.root_path, "static.files/"),
42+
}
4043
}
4144
}
4245

4346
#[derive(Template)]
4447
#[template(path = "page.html")]
4548
struct PageLayout<'a> {
46-
static_root_path: &'a str,
49+
static_root_path: String,
4750
page: &'a Page<'a>,
4851
layout: &'a Layout,
4952

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
636636
<link rel=\"stylesheet\" type=\"text/css\" \
637637
href=\"{static_root_path}{settings_css}\">\
638638
<script defer src=\"{static_root_path}{settings_js}\"></script>",
639-
static_root_path = page.static_root_path.unwrap_or(""),
639+
static_root_path = page.get_static_root_path(),
640640
settings_css = static_files::STATIC_FILES.settings_css,
641641
settings_js = static_files::STATIC_FILES.settings_js,
642642
)

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(super) fn print_item(
147147
};
148148

149149
let item_vars = ItemVars {
150-
static_root_path: page.get_static_root_path(),
150+
static_root_path: &page.get_static_root_path(),
151151
clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
152152
typ,
153153
name: item.name.as_ref().unwrap().as_str(),

src/librustdoc/html/render/write_shared.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::{try_err, try_none};
2424
/// URL if the contents change, so they are safe to cache with the
2525
/// `Cache-Control: immutable` directive. They are written under the static.files/
2626
/// directory and are written when --emit-type is empty (default) or contains
27-
/// "toolchain-specific".
27+
/// "toolchain-specific". If using the --static-root-path flag, it should point
28+
/// to a URL path prefix where each of these filenames can be fetched.
2829
/// - Invocation specific files. These are generated based on the crate(s) being
2930
/// documented. Their filenames need to be predictable without knowing their
3031
/// contents, so they do not include a hash in their filename and are not safe to
@@ -85,8 +86,10 @@ pub(super) fn write_shared(
8586

8687
if options.emit.is_empty() || options.emit.contains(&EmitType::Toolchain) {
8788
for f in static_files::STATIC_FILES_LIST {
88-
let filename = static_files::static_filename(f.filename, f.bytes);
89-
cx.shared.fs.write(cx.dst.join(filename), f.minified())?;
89+
let filename = cx.dst.join(
90+
Path::new("static.files/").join(static_files::static_filename(f.filename, f.bytes)),
91+
);
92+
cx.shared.fs.write(filename, f.minified())?;
9093
}
9194
}
9295

src/librustdoc/html/static_files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use rustc_data_structures::fx::FxHasher;
77
use std::hash::Hasher;
8-
use std::path::{Path, PathBuf};
8+
use std::path::PathBuf;
99
use std::{fmt, str};
1010

1111
pub(crate) struct StaticFile {
@@ -51,7 +51,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf {
5151

5252
pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
5353
let filename = filename.rsplit("/").next().unwrap();
54-
Path::new("static.files").join(suffix_path(filename, &static_suffix(contents)))
54+
suffix_path(filename, &static_suffix(contents))
5555
}
5656

5757
fn static_suffix(bytes: &[u8]) -> String {

src/test/rustdoc/static-root-path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// compile-flags:-Z unstable-options --static-root-path /cache/
22

33
// @has static_root_path/struct.SomeStruct.html
4-
// @matchesraw - '"/cache/static.files/main-'
4+
// @matchesraw - '"/cache/main-'
55
// @!matchesraw - '"\.\./main'
66
// @matchesraw - 'data-root-path="\.\./"'
77
// @!matchesraw - '"/cache/search-index\.js"'
88
pub struct SomeStruct;
99

1010
// @has src/static_root_path/static-root-path.rs.html
11-
// @matchesraw - '"/cache/static.files/source-script-'
11+
// @matchesraw - '"/cache/source-script-'
1212
// @!matchesraw - '"\.\./\.\./source-script'
1313
// @matchesraw - '"\.\./\.\./source-files.js"'
1414
// @!matchesraw - '"/cache/source-files\.js"'
1515

1616
// @has settings.html
17-
// @matchesraw - '/cache/static.files/settings-'
17+
// @matchesraw - '/cache/settings-'
1818
// @!matchesraw - '\../settings'

0 commit comments

Comments
 (0)