summaryrefslogtreecommitdiffstats
path: root/src/tools/rustdoc-themes
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:36 +0000
commite02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch)
treefd60ebbbb5299e16e5fca8c773ddb74f764760db /src/tools/rustdoc-themes
parentAdding debian version 1.73.0+dfsg1-1. (diff)
downloadrustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz
rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rustdoc-themes')
-rw-r--r--src/tools/rustdoc-themes/main.rs45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/tools/rustdoc-themes/main.rs b/src/tools/rustdoc-themes/main.rs
index 7cac985a9..1eba83a80 100644
--- a/src/tools/rustdoc-themes/main.rs
+++ b/src/tools/rustdoc-themes/main.rs
@@ -1,25 +1,38 @@
use std::env::args;
-use std::fs::read_dir;
+use std::fs::{create_dir_all, File};
+use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::Path;
use std::process::{exit, Command};
-const FILES_TO_IGNORE: &[&str] = &["light.css"];
-
-fn get_folders<P: AsRef<Path>>(folder_path: P) -> Vec<String> {
+fn get_themes<P: AsRef<Path>>(style_path: P) -> Vec<String> {
let mut ret = Vec::with_capacity(10);
- for entry in read_dir(folder_path.as_ref()).expect("read_dir failed") {
- let entry = entry.expect("Couldn't unwrap entry");
- let path = entry.path();
+ const BEGIN_THEME_MARKER: &'static str = "/* Begin theme: ";
+ const END_THEME_MARKER: &'static str = "/* End theme: ";
+
+ let timestamp =
+ std::time::SystemTime::UNIX_EPOCH.elapsed().expect("time is after UNIX epoch").as_millis();
- if !path.is_file() {
- continue;
+ let mut in_theme = None;
+ create_dir_all("build/tmp").expect("failed to create temporary test directory");
+ for line in BufReader::new(File::open(style_path).expect("read rustdoc.css failed")).lines() {
+ let line = line.expect("read line from rustdoc.css failed");
+ let line = line.trim();
+ if line.starts_with(BEGIN_THEME_MARKER) {
+ let theme_name = &line[BEGIN_THEME_MARKER.len()..].trim().trim_end_matches("*/").trim();
+ let filename = format!("build/tmp/rustdoc.bootstrap.{timestamp}.{theme_name}.css");
+ in_theme = Some(BufWriter::new(
+ File::create(&filename).expect("failed to create temporary test css file"),
+ ));
+ ret.push(filename);
+ }
+ if let Some(in_theme) = in_theme.as_mut() {
+ in_theme.write_all(line.as_bytes()).expect("write to temporary test css file");
+ in_theme.write_all(b"\n").expect("write to temporary test css file");
}
- let filename = path.file_name().expect("file_name failed");
- if FILES_TO_IGNORE.iter().any(|x| x == &filename) {
- continue;
+ if line.starts_with(END_THEME_MARKER) {
+ in_theme = None;
}
- ret.push(format!("{}", path.display()));
}
ret
}
@@ -32,10 +45,10 @@ fn main() {
exit(1);
}
let rustdoc_bin = &argv[1];
- let themes_folder = &argv[2];
- let themes = get_folders(&themes_folder);
+ let style_path = &argv[2];
+ let themes = get_themes(&style_path);
if themes.is_empty() {
- eprintln!("No theme found in \"{}\"...", themes_folder);
+ eprintln!("No themes found in \"{}\"...", style_path);
exit(1);
}
let arg_name = "--check-theme".to_owned();