2 use std::num::ParseIntError;
4 use std::process::Command;
6 use std::time::{Duration, SystemTime};
10 /// Panics if the python commands could not be spawned
11 pub fn run(port: u16, lint: Option<&String>) -> ! {
12 let mut url = Some(match lint {
13 None => format!("http://localhost:{}", port),
14 Some(lint) => format!("http://localhost:{}/#{}", port, lint),
18 if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") {
20 .arg("collect-metadata")
26 if let Some(url) = url.take() {
27 thread::spawn(move || {
28 Command::new("python3")
31 .arg(port.to_string())
32 .current_dir("util/gh-pages")
35 // Give some time for python to start
36 thread::sleep(Duration::from_millis(500));
37 // Launch browser after first export.py has completed and http.server is up
38 let _result = opener::open(url);
41 thread::sleep(Duration::from_millis(1000));
45 fn mtime(path: impl AsRef<Path>) -> SystemTime {
46 let path = path.as_ref();
52 .map(|entry| mtime(&entry.path()))
54 .unwrap_or(SystemTime::UNIX_EPOCH)
57 .and_then(|metadata| metadata.modified())
58 .unwrap_or(SystemTime::UNIX_EPOCH)
62 #[allow(clippy::missing_errors_doc)]
63 pub fn validate_port(arg: &OsStr) -> Result<(), ParseIntError> {
64 arg.to_string_lossy().parse::<u16>().map(|_| ())