2 use std
::fs
::{create_dir_all, File}
;
3 use std
::io
::{BufRead, BufReader, BufWriter, Write}
;
5 use std
::process
::{exit, Command}
;
7 fn get_themes
<P
: AsRef
<Path
>>(style_path
: P
) -> Vec
<String
> {
8 let mut ret
= Vec
::with_capacity(10);
10 const BEGIN_THEME_MARKER
: &'
static str = "/* Begin theme: ";
11 const END_THEME_MARKER
: &'
static str = "/* End theme: ";
14 std
::time
::SystemTime
::UNIX_EPOCH
.elapsed().expect("time is after UNIX epoch").as_millis();
16 let mut in_theme
= None
;
17 create_dir_all("build/tmp").expect("failed to create temporary test directory");
18 for line
in BufReader
::new(File
::open(style_path
).expect("read rustdoc.css failed")).lines() {
19 let line
= line
.expect("read line from rustdoc.css failed");
20 let line
= line
.trim();
21 if line
.starts_with(BEGIN_THEME_MARKER
) {
22 let theme_name
= &line
[BEGIN_THEME_MARKER
.len()..].trim().trim_end_matches("*/").trim();
23 let filename
= format
!("build/tmp/rustdoc.bootstrap.{timestamp}.{theme_name}.css");
24 in_theme
= Some(BufWriter
::new(
25 File
::create(&filename
).expect("failed to create temporary test css file"),
29 if let Some(in_theme
) = in_theme
.as_mut() {
30 in_theme
.write_all(line
.as_bytes()).expect("write to temporary test css file");
31 in_theme
.write_all(b
"\n").expect("write to temporary test css file");
33 if line
.starts_with(END_THEME_MARKER
) {
41 let argv
: Vec
<String
> = args().collect();
44 eprintln
!("Needs rustdoc binary path");
47 let rustdoc_bin
= &argv
[1];
48 let style_path
= &argv
[2];
49 let themes
= get_themes(&style_path
);
50 if themes
.is_empty() {
51 eprintln
!("No themes found in \"{}\"...", style_path
);
54 let arg_name
= "--check-theme".to_owned();
55 let status
= Command
::new(rustdoc_bin
)
56 .args(&themes
.iter().flat_map(|t
| vec
![&arg_name
, t
].into_iter()).collect
::<Vec
<_
>>())
58 .expect("failed to execute child");
59 if !status
.success() {