1
Fork 0

Store UNVERSIONED_FILES in a data structure

This allows querying it programatically.
This commit is contained in:
Joshua Nelson 2021-03-05 10:35:22 -05:00
parent 8ccc89bc31
commit 69a879f3d1
3 changed files with 39 additions and 33 deletions

View file

@ -1612,24 +1612,6 @@ impl PrimitiveType {
CELL.get_or_init(move || { CELL.get_or_init(move || {
use self::PrimitiveType::*; use self::PrimitiveType::*;
/// A macro to create a FxHashMap.
///
/// Example:
///
/// ```
/// let letters = map!{"a" => "b", "c" => "d"};
/// ```
///
/// Trailing commas are allowed.
/// Commas between elements are required (even if the expression is a block).
macro_rules! map {
($( $key: expr => $val: expr ),* $(,)*) => {{
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
$( map.insert($key, $val); )*
map
}}
}
let single = |a: Option<DefId>| a.into_iter().collect(); let single = |a: Option<DefId>| a.into_iter().collect();
let both = |a: Option<DefId>, b: Option<DefId>| -> ArrayVec<_> { let both = |a: Option<DefId>, b: Option<DefId>| -> ArrayVec<_> {
a.into_iter().chain(b).collect() a.into_iter().chain(b).collect()

View file

@ -4,6 +4,7 @@ use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use std::io::{self, BufReader}; use std::io::{self, BufReader};
use std::path::{Component, Path, PathBuf}; use std::path::{Component, Path, PathBuf};
use std::lazy::SyncLazy as Lazy;
use itertools::Itertools; use itertools::Itertools;
use rustc_data_structures::flock; use rustc_data_structures::flock;
@ -212,21 +213,26 @@ themePicker.onblur = handleThemeButtonsBlur;
static_files::NORMALIZE_CSS, static_files::NORMALIZE_CSS,
options.enable_minification, options.enable_minification,
)?; )?;
write(cx.dst.join("FiraSans-Regular.woff2"), static_files::fira_sans::REGULAR2)?; static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| map! {
write(cx.dst.join("FiraSans-Medium.woff2"), static_files::fira_sans::MEDIUM2)?; "FiraSans-Regular.woff2" => static_files::fira_sans::REGULAR2,
write(cx.dst.join("FiraSans-Regular.woff"), static_files::fira_sans::REGULAR)?; "FiraSans-Medium.woff2" => static_files::fira_sans::MEDIUM2,
write(cx.dst.join("FiraSans-Medium.woff"), static_files::fira_sans::MEDIUM)?; "FiraSans-Regular.woff" => static_files::fira_sans::REGULAR,
write(cx.dst.join("FiraSans-LICENSE.txt"), static_files::fira_sans::LICENSE)?; "FiraSans-Medium.woff" => static_files::fira_sans::MEDIUM,
write(cx.dst.join("SourceSerifPro-Regular.ttf.woff"), static_files::source_serif_pro::REGULAR)?; "FiraSans-LICENSE.txt" => static_files::fira_sans::LICENSE,
write(cx.dst.join("SourceSerifPro-Bold.ttf.woff"), static_files::source_serif_pro::BOLD)?; "SourceSerifPro-Regular.ttf.woff" => static_files::source_serif_pro::REGULAR,
write(cx.dst.join("SourceSerifPro-It.ttf.woff"), static_files::source_serif_pro::ITALIC)?; "SourceSerifPro-Bold.ttf.woff" => static_files::source_serif_pro::BOLD,
write(cx.dst.join("SourceSerifPro-LICENSE.md"), static_files::source_serif_pro::LICENSE)?; "SourceSerifPro-It.ttf.woff" => static_files::source_serif_pro::ITALIC,
write(cx.dst.join("SourceCodePro-Regular.woff"), static_files::source_code_pro::REGULAR)?; "SourceSerifPro-LICENSE.md" => static_files::source_serif_pro::LICENSE,
write(cx.dst.join("SourceCodePro-Semibold.woff"), static_files::source_code_pro::SEMIBOLD)?; "SourceCodePro-Regular.woff" => static_files::source_code_pro::REGULAR,
write(cx.dst.join("SourceCodePro-LICENSE.txt"), static_files::source_code_pro::LICENSE)?; "SourceCodePro-Semibold.woff" => static_files::source_code_pro::SEMIBOLD,
write(cx.dst.join("LICENSE-MIT.txt"), static_files::LICENSE_MIT)?; "SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
write(cx.dst.join("LICENSE-APACHE.txt"), static_files::LICENSE_APACHE)?; "LICENSE-MIT.txt" => static_files::LICENSE_MIT,
write(cx.dst.join("COPYRIGHT.txt"), static_files::COPYRIGHT)?; "LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
"COPYRIGHT.txt" => static_files::COPYRIGHT,
});
for (file, contents) in &*FILES_UNVERSIONED {
write(cx.dst.join(file), contents)?;
}
fn collect(path: &Path, krate: &str, key: &str) -> io::Result<(Vec<String>, Vec<String>)> { fn collect(path: &Path, krate: &str, key: &str) -> io::Result<(Vec<String>, Vec<String>)> {
let mut ret = Vec::new(); let mut ret = Vec::new();

View file

@ -71,6 +71,24 @@ use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGro
use rustc_session::getopts; use rustc_session::getopts;
use rustc_session::{early_error, early_warn}; use rustc_session::{early_error, early_warn};
/// A macro to create a FxHashMap.
///
/// Example:
///
/// ```
/// let letters = map!{"a" => "b", "c" => "d"};
/// ```
///
/// Trailing commas are allowed.
/// Commas between elements are required (even if the expression is a block).
macro_rules! map {
($( $key: expr => $val: expr ),* $(,)*) => {{
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
$( map.insert($key, $val); )*
map
}}
}
#[macro_use] #[macro_use]
mod externalfiles; mod externalfiles;