Skip to content

Commit b4224fe

Browse files
authored
Rollup merge of rust-lang#82803 - jyn514:unversioned-files, r=GuillaumeGomez
rustdoc: Add an unstable option to print all unversioned files This allows sharing those files between different doc invocations without having to know their names ahead of time. Helps with rust-lang/docs.rs#1302. r? ```@GuillaumeGomez``` cc ```@pietroalbini``` ```@Nemo157```
2 parents ef401b3 + 173d2aa commit b4224fe

File tree

7 files changed

+72
-33
lines changed

7 files changed

+72
-33
lines changed

src/librustdoc/clean/types.rs

-18
Original file line numberDiff line numberDiff line change
@@ -1615,24 +1615,6 @@ impl PrimitiveType {
16151615
CELL.get_or_init(move || {
16161616
use self::PrimitiveType::*;
16171617

1618-
/// A macro to create a FxHashMap.
1619-
///
1620-
/// Example:
1621-
///
1622-
/// ```
1623-
/// let letters = map!{"a" => "b", "c" => "d"};
1624-
/// ```
1625-
///
1626-
/// Trailing commas are allowed.
1627-
/// Commas between elements are required (even if the expression is a block).
1628-
macro_rules! map {
1629-
($( $key: expr => $val: expr ),* $(,)*) => {{
1630-
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
1631-
$( map.insert($key, $val); )*
1632-
map
1633-
}}
1634-
}
1635-
16361618
let single = |a: Option<DefId>| a.into_iter().collect();
16371619
let both = |a: Option<DefId>, b: Option<DefId>| -> ArrayVec<_> {
16381620
a.into_iter().chain(b).collect()

src/librustdoc/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ impl Options {
315315
return Err(0);
316316
}
317317

318+
if matches.opt_strs("print").iter().any(|opt| opt == "unversioned-files") {
319+
for file in crate::html::render::FILES_UNVERSIONED.keys() {
320+
println!("{}", file);
321+
}
322+
return Err(0);
323+
}
324+
318325
let color = config::parse_color(&matches);
319326
let (json_rendered, _artifacts) = config::parse_json(&matches);
320327
let error_format = config::parse_error_format(&matches, color, json_rendered);

src/librustdoc/html/render/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod print_item;
3333
mod write_shared;
3434

3535
crate use context::*;
36+
crate use write_shared::FILES_UNVERSIONED;
3637

3738
use std::cell::{Cell, RefCell};
3839
use std::collections::VecDeque;

src/librustdoc/html/render/write_shared.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Write;
33
use std::fs::{self, File};
44
use std::io::prelude::*;
55
use std::io::{self, BufReader};
6+
use std::lazy::SyncLazy as Lazy;
67
use std::path::{Component, Path, PathBuf};
78

89
use itertools::Itertools;
@@ -18,6 +19,26 @@ use crate::error::Error;
1819
use crate::formats::FormatRenderer;
1920
use crate::html::{layout, static_files};
2021

22+
crate static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
23+
map! {
24+
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
25+
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
26+
"FiraSans-Regular.woff" => static_files::fira_sans::REGULAR,
27+
"FiraSans-Medium.woff" => static_files::fira_sans::MEDIUM,
28+
"FiraSans-LICENSE.txt" => static_files::fira_sans::LICENSE,
29+
"SourceSerifPro-Regular.ttf.woff" => static_files::source_serif_pro::REGULAR,
30+
"SourceSerifPro-Bold.ttf.woff" => static_files::source_serif_pro::BOLD,
31+
"SourceSerifPro-It.ttf.woff" => static_files::source_serif_pro::ITALIC,
32+
"SourceSerifPro-LICENSE.md" => static_files::source_serif_pro::LICENSE,
33+
"SourceCodePro-Regular.woff" => static_files::source_code_pro::REGULAR,
34+
"SourceCodePro-Semibold.woff" => static_files::source_code_pro::SEMIBOLD,
35+
"SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
36+
"LICENSE-MIT.txt" => static_files::LICENSE_MIT,
37+
"LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
38+
"COPYRIGHT.txt" => static_files::COPYRIGHT,
39+
}
40+
});
41+
2142
pub(super) fn write_shared(
2243
cx: &Context<'_>,
2344
krate: &Crate,
@@ -212,21 +233,9 @@ themePicker.onblur = handleThemeButtonsBlur;
212233
static_files::NORMALIZE_CSS,
213234
options.enable_minification,
214235
)?;
215-
write(cx.dst.join("FiraSans-Regular.woff2"), static_files::fira_sans::REGULAR2)?;
216-
write(cx.dst.join("FiraSans-Medium.woff2"), static_files::fira_sans::MEDIUM2)?;
217-
write(cx.dst.join("FiraSans-Regular.woff"), static_files::fira_sans::REGULAR)?;
218-
write(cx.dst.join("FiraSans-Medium.woff"), static_files::fira_sans::MEDIUM)?;
219-
write(cx.dst.join("FiraSans-LICENSE.txt"), static_files::fira_sans::LICENSE)?;
220-
write(cx.dst.join("SourceSerifPro-Regular.ttf.woff"), static_files::source_serif_pro::REGULAR)?;
221-
write(cx.dst.join("SourceSerifPro-Bold.ttf.woff"), static_files::source_serif_pro::BOLD)?;
222-
write(cx.dst.join("SourceSerifPro-It.ttf.woff"), static_files::source_serif_pro::ITALIC)?;
223-
write(cx.dst.join("SourceSerifPro-LICENSE.md"), static_files::source_serif_pro::LICENSE)?;
224-
write(cx.dst.join("SourceCodePro-Regular.woff"), static_files::source_code_pro::REGULAR)?;
225-
write(cx.dst.join("SourceCodePro-Semibold.woff"), static_files::source_code_pro::SEMIBOLD)?;
226-
write(cx.dst.join("SourceCodePro-LICENSE.txt"), static_files::source_code_pro::LICENSE)?;
227-
write(cx.dst.join("LICENSE-MIT.txt"), static_files::LICENSE_MIT)?;
228-
write(cx.dst.join("LICENSE-APACHE.txt"), static_files::LICENSE_APACHE)?;
229-
write(cx.dst.join("COPYRIGHT.txt"), static_files::COPYRIGHT)?;
236+
for (file, contents) in &*FILES_UNVERSIONED {
237+
write(cx.dst.join(file), contents)?;
238+
}
230239

231240
fn collect(path: &Path, krate: &str, key: &str) -> io::Result<(Vec<String>, Vec<String>)> {
232241
let mut ret = Vec::new();

src/librustdoc/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
7171
use rustc_session::getopts;
7272
use rustc_session::{early_error, early_warn};
7373

74+
/// A macro to create a FxHashMap.
75+
///
76+
/// Example:
77+
///
78+
/// ```
79+
/// let letters = map!{"a" => "b", "c" => "d"};
80+
/// ```
81+
///
82+
/// Trailing commas are allowed.
83+
/// Commas between elements are required (even if the expression is a block).
84+
macro_rules! map {
85+
($( $key: expr => $val: expr ),* $(,)*) => {{
86+
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
87+
$( map.insert($key, $val); )*
88+
map
89+
}}
90+
}
91+
7492
#[macro_use]
7593
mod externalfiles;
7694

@@ -506,6 +524,9 @@ fn opts() -> Vec<RustcOptGroup> {
506524
"Generate JSON file at the top level instead of generating HTML redirection files",
507525
)
508526
}),
527+
unstable("print", |o| {
528+
o.optmulti("", "print", "Rustdoc information to print on stdout", "[unversioned-files]")
529+
}),
509530
]
510531
}
511532

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTDOC) -Z unstable-options --print unversioned-files | sort | diff - unversioned-files.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
COPYRIGHT.txt
2+
FiraSans-LICENSE.txt
3+
FiraSans-Medium.woff
4+
FiraSans-Medium.woff2
5+
FiraSans-Regular.woff
6+
FiraSans-Regular.woff2
7+
LICENSE-APACHE.txt
8+
LICENSE-MIT.txt
9+
SourceCodePro-LICENSE.txt
10+
SourceCodePro-Regular.woff
11+
SourceCodePro-Semibold.woff
12+
SourceSerifPro-Bold.ttf.woff
13+
SourceSerifPro-It.ttf.woff
14+
SourceSerifPro-LICENSE.md
15+
SourceSerifPro-Regular.ttf.woff

0 commit comments

Comments
 (0)