Skip to content

Commit

Permalink
Add an unstable option to print all unversioned files
Browse files Browse the repository at this point in the history
This allows sharing those files between different doc invocations
without having to know their names ahead of time.
  • Loading branch information
jyn514 committed Mar 5, 2021
1 parent 69a879f commit 173d2aa
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ impl Options {
return Err(0);
}

if matches.opt_strs("print").iter().any(|opt| opt == "unversioned-files") {
for file in crate::html::render::FILES_UNVERSIONED.keys() {
println!("{}", file);
}
return Err(0);
}

let color = config::parse_color(&matches);
let (json_rendered, _artifacts) = config::parse_json(&matches);
let error_format = config::parse_error_format(&matches, color, json_rendered);
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod print_item;
mod write_shared;

crate use context::*;
crate use write_shared::FILES_UNVERSIONED;

use std::cell::{Cell, RefCell};
use std::collections::VecDeque;
Expand Down
39 changes: 21 additions & 18 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::fmt::Write;
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::{self, BufReader};
use std::path::{Component, Path, PathBuf};
use std::lazy::SyncLazy as Lazy;
use std::path::{Component, Path, PathBuf};

use itertools::Itertools;
use rustc_data_structures::flock;
Expand All @@ -19,6 +19,26 @@ use crate::error::Error;
use crate::formats::FormatRenderer;
use crate::html::{layout, static_files};

crate static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
map! {
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
"FiraSans-Regular.woff" => static_files::fira_sans::REGULAR,
"FiraSans-Medium.woff" => static_files::fira_sans::MEDIUM,
"FiraSans-LICENSE.txt" => static_files::fira_sans::LICENSE,
"SourceSerifPro-Regular.ttf.woff" => static_files::source_serif_pro::REGULAR,
"SourceSerifPro-Bold.ttf.woff" => static_files::source_serif_pro::BOLD,
"SourceSerifPro-It.ttf.woff" => static_files::source_serif_pro::ITALIC,
"SourceSerifPro-LICENSE.md" => static_files::source_serif_pro::LICENSE,
"SourceCodePro-Regular.woff" => static_files::source_code_pro::REGULAR,
"SourceCodePro-Semibold.woff" => static_files::source_code_pro::SEMIBOLD,
"SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
"LICENSE-MIT.txt" => static_files::LICENSE_MIT,
"LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
"COPYRIGHT.txt" => static_files::COPYRIGHT,
}
});

pub(super) fn write_shared(
cx: &Context<'_>,
krate: &Crate,
Expand Down Expand Up @@ -213,23 +233,6 @@ themePicker.onblur = handleThemeButtonsBlur;
static_files::NORMALIZE_CSS,
options.enable_minification,
)?;
static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| map! {
"FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
"FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
"FiraSans-Regular.woff" => static_files::fira_sans::REGULAR,
"FiraSans-Medium.woff" => static_files::fira_sans::MEDIUM,
"FiraSans-LICENSE.txt" => static_files::fira_sans::LICENSE,
"SourceSerifPro-Regular.ttf.woff" => static_files::source_serif_pro::REGULAR,
"SourceSerifPro-Bold.ttf.woff" => static_files::source_serif_pro::BOLD,
"SourceSerifPro-It.ttf.woff" => static_files::source_serif_pro::ITALIC,
"SourceSerifPro-LICENSE.md" => static_files::source_serif_pro::LICENSE,
"SourceCodePro-Regular.woff" => static_files::source_code_pro::REGULAR,
"SourceCodePro-Semibold.woff" => static_files::source_code_pro::SEMIBOLD,
"SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
"LICENSE-MIT.txt" => static_files::LICENSE_MIT,
"LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
"COPYRIGHT.txt" => static_files::COPYRIGHT,
});
for (file, contents) in &*FILES_UNVERSIONED {
write(cx.dst.join(file), contents)?;
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ fn opts() -> Vec<RustcOptGroup> {
"Generate JSON file at the top level instead of generating HTML redirection files",
)
}),
unstable("print", |o| {
o.optmulti("", "print", "Rustdoc information to print on stdout", "[unversioned-files]")
}),
]
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/run-make-fulldeps/print-unversioned-files/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-include ../tools.mk

all:
$(RUSTDOC) -Z unstable-options --print unversioned-files | sort | diff - unversioned-files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
COPYRIGHT.txt
FiraSans-LICENSE.txt
FiraSans-Medium.woff
FiraSans-Medium.woff2
FiraSans-Regular.woff
FiraSans-Regular.woff2
LICENSE-APACHE.txt
LICENSE-MIT.txt
SourceCodePro-LICENSE.txt
SourceCodePro-Regular.woff
SourceCodePro-Semibold.woff
SourceSerifPro-Bold.ttf.woff
SourceSerifPro-It.ttf.woff
SourceSerifPro-LICENSE.md
SourceSerifPro-Regular.ttf.woff

0 comments on commit 173d2aa

Please sign in to comment.