Skip to content

Commit f1357f9

Browse files
authored
Unrolled build for #155374
Rollup merge of #155374 - notriddle:non-static-dep-info, r=fmease rustdoc: fix a few spots where emit isn't respected Addresses the third list item of #155298
2 parents f676c20 + de48fc6 commit f1357f9

4 files changed

Lines changed: 79 additions & 37 deletions

File tree

src/librustdoc/html/render/write_shared.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(crate) fn write_not_crate_specific(
153153
include_sources: bool,
154154
) -> Result<(), Error> {
155155
write_rendered_cross_crate_info(crates, dst, opt, include_sources, resource_suffix)?;
156-
write_static_files(dst, opt, style_files, css_file_extension, resource_suffix)?;
156+
write_resources(dst, opt, style_files, css_file_extension, resource_suffix)?;
157157
Ok(())
158158
}
159159

@@ -183,43 +183,45 @@ fn write_rendered_cross_crate_info(
183183

184184
/// Writes the static files, the style files, and the css extensions.
185185
/// Have to be careful about these, because they write to the root out dir.
186-
fn write_static_files(
186+
fn write_resources(
187187
dst: &Path,
188188
opt: &RenderOptions,
189189
style_files: &[StylePath],
190190
css_file_extension: Option<&Path>,
191191
resource_suffix: &str,
192192
) -> Result<(), Error> {
193-
let static_dir = dst.join("static.files");
194-
try_err!(fs::create_dir_all(&static_dir), &static_dir);
195-
196-
// Handle added third-party themes
197-
for entry in style_files {
198-
let theme = entry.basename()?;
199-
let extension =
200-
try_none!(try_none!(entry.path.extension(), &entry.path).to_str(), &entry.path);
201-
202-
// Skip the official themes. They are written below as part of STATIC_FILES_LIST.
203-
if matches!(theme.as_str(), "light" | "dark" | "ayu") {
204-
continue;
205-
}
193+
if opt.emit.is_empty() || opt.emit.contains(&EmitType::HtmlNonStaticFiles) {
194+
// Handle added third-party themes
195+
for entry in style_files {
196+
let theme = entry.basename()?;
197+
let extension =
198+
try_none!(try_none!(entry.path.extension(), &entry.path).to_str(), &entry.path);
199+
200+
// Skip the official themes. They are written below as part of STATIC_FILES_LIST.
201+
if matches!(theme.as_str(), "light" | "dark" | "ayu") {
202+
continue;
203+
}
206204

207-
let bytes = try_err!(fs::read(&entry.path), &entry.path);
208-
let filename = format!("{theme}{resource_suffix}.{extension}");
209-
let dst_filename = dst.join(filename);
210-
try_err!(fs::write(&dst_filename, bytes), &dst_filename);
211-
}
205+
let bytes = try_err!(fs::read(&entry.path), &entry.path);
206+
let filename = format!("{theme}{resource_suffix}.{extension}");
207+
let dst_filename = dst.join(filename);
208+
try_err!(fs::write(&dst_filename, bytes), &dst_filename);
209+
}
212210

213-
// When the user adds their own CSS files with --extend-css, we write that as an
214-
// invocation-specific file (that is, with a resource suffix).
215-
if let Some(css) = css_file_extension {
216-
let buffer = try_err!(fs::read_to_string(css), css);
217-
let path = static_files::suffix_path("theme.css", resource_suffix);
218-
let dst_path = dst.join(path);
219-
try_err!(fs::write(&dst_path, buffer), &dst_path);
211+
// When the user adds their own CSS files with --extend-css, we write that as an
212+
// invocation-specific file (that is, with a resource suffix).
213+
if let Some(css) = css_file_extension {
214+
let buffer = try_err!(fs::read_to_string(css), css);
215+
let path = static_files::suffix_path("theme.css", resource_suffix);
216+
let dst_path = dst.join(path);
217+
try_err!(fs::write(&dst_path, buffer), &dst_path);
218+
}
220219
}
221220

222221
if opt.emit.is_empty() || opt.emit.contains(&EmitType::HtmlStaticFiles) {
222+
let static_dir = dst.join("static.files");
223+
try_err!(fs::create_dir_all(&static_dir), &static_dir);
224+
223225
static_files::for_each(|f: &static_files::StaticFile| {
224226
let filename = static_dir.join(f.output_filename());
225227
let contents: &[u8] =

src/librustdoc/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ use rustc_span::{BytePos, Span, SyntaxContext};
8181
use tracing::info;
8282

8383
use crate::clean::utils::DOC_RUST_LANG_ORG_VERSION;
84+
use crate::config::EmitType;
8485
use crate::error::Error;
8586
use crate::formats::cache::Cache;
8687

@@ -868,7 +869,11 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
868869
};
869870
rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
870871
let has_dep_info = render_options.dep_info().is_some();
871-
markdown::render_and_write(file, render_options, edition)?;
872+
if render_options.emit.contains(&EmitType::HtmlNonStaticFiles)
873+
|| render_options.emit.is_empty()
874+
{
875+
markdown::render_and_write(file, render_options, edition)?;
876+
}
872877
if has_dep_info {
873878
// Register the loaded external files in the source map so they show up in depinfo.
874879
// We can't load them via the source map because it gets created after we process the options.
File renamed without changes.

tests/run-make/rustdoc-dep-info/rmake.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ use run_make_support::{path, rfs, rustdoc};
99
fn main() {
1010
rfs::create_dir("doc");
1111

12-
// We're only emitting dep info, so we shouldn't be running static analysis to
13-
// figure out that this program is erroneous.
1412
// Ensure that all kinds of input reading flags end up in dep-info.
1513
rustdoc()
1614
.input("lib.rs")
1715
.arg("-Zunstable-options")
1816
.arg("--html-before-content=before.html")
1917
.arg("--markdown-after-content=after.md")
2018
.arg("--extend-css=extend.css")
21-
.arg("--theme=theme.css")
19+
.arg("--theme=custom_theme.css")
2220
.arg("--index-page=index-page.md")
2321
.emit("dep-info")
2422
.run();
@@ -31,8 +29,31 @@ fn main() {
3129
assert_contains(&content, "after.md:");
3230
assert_contains(&content, "before.html:");
3331
assert_contains(&content, "extend.css:");
34-
assert_contains(&content, "theme.css:");
32+
assert_contains(&content, "custom_theme.css:");
3533
assert_contains(&content, "index-page.md:");
34+
// Only emit dep-info. Don't emit the actual page.
35+
assert!(!path("doc/foo/index.html").exists());
36+
assert!(!path("doc/custom_theme.css").exists());
37+
// weird that --extend-css generates a file named theme.css
38+
assert!(!path("doc/theme.css").exists());
39+
40+
// Now try emitting dep-info and html files at the same time.
41+
rustdoc()
42+
.input("lib.rs")
43+
.arg("-Zunstable-options")
44+
.arg("--html-before-content=before.html")
45+
.arg("--markdown-after-content=after.md")
46+
.arg("--extend-css=extend.css")
47+
.arg("--theme=custom_theme.css")
48+
.arg("--index-page=index-page.md")
49+
.emit("dep-info,html-non-static-files,html-static-files")
50+
.run();
51+
assert!(path("doc/foo/index.html").exists());
52+
// These files are copied into the doc output folder,
53+
// which is why they show up in dep-info.
54+
assert!(path("doc/custom_theme.css").exists());
55+
// weird that --extend-css generates a file named theme.css
56+
assert!(path("doc/theme.css").exists());
3657

3758
// Now we check that we can provide a file name to the `dep-info` argument.
3859
rustdoc().input("lib.rs").arg("-Zunstable-options").emit("dep-info=bla.d").run();
@@ -72,7 +93,9 @@ fn main() {
7293
assert_not_contains(&content, "after.md:");
7394
assert_not_contains(&content, "before.html:");
7495
assert_not_contains(&content, "extend.css:");
75-
assert_not_contains(&content, "theme.css:");
96+
assert_not_contains(&content, "custom_theme.css:");
97+
// Only emit dep-info, not the actual html.
98+
assert!(!path("doc/example.html").exists());
7699

77100
// combine --emit=dep-info=filename with plain markdown input
78101
rustdoc()
@@ -81,10 +104,12 @@ fn main() {
81104
.arg("--html-before-content=before.html")
82105
.arg("--markdown-after-content=after.md")
83106
.arg("--extend-css=extend.css")
84-
.arg("--theme=theme.css")
107+
.arg("--theme=custom_theme.css")
108+
.arg("--markdown-css=markdown.css")
85109
.arg("--index-page=index-page.md")
86-
.emit("dep-info=example.d")
110+
.emit("dep-info=example.d,html-non-static-files,html-static-files")
87111
.run();
112+
assert!(path("doc/example.html").exists());
88113
let content = rfs::read_to_string("example.d");
89114
assert_contains(&content, "example.md:");
90115
assert_not_contains(&content, "lib.rs:");
@@ -93,7 +118,17 @@ fn main() {
93118
assert_not_contains(&content, "doc.md:");
94119
assert_contains(&content, "after.md:");
95120
assert_contains(&content, "before.html:");
96-
assert_contains(&content, "extend.css:");
97-
assert_contains(&content, "theme.css:");
98121
assert_contains(&content, "index-page.md:");
122+
// This is a hotlink, not a file that gets copied,
123+
// so it shouldn't add to the dep-info, it shouldn't be copied,
124+
// and it shouldn't be resolved relative to the root path.
125+
//
126+
// It's weird that this is different from the other two css
127+
// files, but it's stable, so I can't change it.
128+
assert!(!path("doc/markdown.css").exists());
129+
assert_not_contains(&content, "markdown.css:");
130+
// These files aren't actually used, and the fact that they show up
131+
// is arguably a bug, but test it anyway.
132+
assert_contains(&content, "extend.css:");
133+
assert_contains(&content, "custom_theme.css:");
99134
}

0 commit comments

Comments
 (0)