Skip to content

Commit

Permalink
Include elapsed time in non-interactive download message (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
messense authored Jan 12, 2025
1 parent c695735 commit d001ee4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ clap = { version = "4.3.0", features = [
] }
dirs = "5.0.0"
fs-err = "3.0.0"
humantime = "2.1.0"
indicatif = "0.17.2"
native-tls-crate = { package = "native-tls", version = "0.2.11", optional = true }
paste = "1.0.12"
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::{Duration, Instant};

use anyhow::{Context, Result};
use fs_err as fs;
Expand Down Expand Up @@ -202,15 +203,19 @@ impl Clang {
pb.set_prefix("sysroot");
pb.set_message("📥 downloading");
if pb.is_hidden() {
eprintln!("📥 Start downloading MSVC sysroot...");
eprintln!("📥 Downloading MSVC sysroot...");
}
let start_time = Instant::now();
let reader = pb.wrap_read(response.into_reader());
let tar = XzDecoder::new(reader);
let mut archive = tar::Archive::new(tar);
archive.unpack(cache_dir)?;
pb.finish_with_message("Download completed");
if pb.is_hidden() {
eprintln!("✅ Finished downloading MSVC sysroot.");
// Display elapsed time in human-readable format to seconds only
let elapsed =
humantime::format_duration(Duration::from_secs(start_time.elapsed().as_secs()));
eprintln!("✅ Downloaded MSVC sysroot in {elapsed}.");
}
Ok(())
}
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/clang_cl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::{Duration, Instant};

use anyhow::{Context, Result};
use fs_err as fs;
Expand Down Expand Up @@ -248,8 +249,9 @@ impl<'a> ClangCl<'a> {

mp.set_move_cursor(true);
if mp.is_hidden() {
eprintln!("⏬ Start downloading MSVC CRT...");
eprintln!("⏬ Downloading MSVC CRT...");
}
let start_time = Instant::now();
ctx.execute(
pkgs,
work_items,
Expand Down Expand Up @@ -277,7 +279,10 @@ impl<'a> ClangCl<'a> {
let _ = fs::remove_dir_all(unpack);
}
if mp.is_hidden() {
eprintln!("✅ Finished downloading MSVC CRT.");
// Display elapsed time in human-readable format to seconds only
let elapsed =
humantime::format_duration(Duration::from_secs(start_time.elapsed().as_secs()));
eprintln!("✅ Downloaded MSVC CRT in {elapsed}.");
}
Ok(())
}
Expand Down

0 comments on commit d001ee4

Please sign in to comment.