1 use sysinfo
::{DiskExt, RefreshKind, System, SystemExt}
;
3 use crate::environment
::Environment
;
4 use crate::timer
::Timer
;
5 use crate::utils
::io
::delete_directory
;
7 use std
::time
::Duration
;
12 pub fn format_env_variables() -> String
{
13 let vars
= std
::env
::vars().map(|(key
, value
)| format
!("{key}={value}")).collect
::<Vec
<_
>>();
17 pub fn print_free_disk_space() -> anyhow
::Result
<()> {
18 let sys
= System
::new_with_specifics(RefreshKind
::default().with_disks_list().with_disks());
19 let available_space
: u64 = sys
.disks().iter().map(|d
| d
.available_space()).sum();
20 let total_space
: u64 = sys
.disks().iter().map(|d
| d
.total_space()).sum();
21 let used_space
= total_space
- available_space
;
24 "Free disk space: {} out of total {} ({:.2}% used)",
25 humansize
::format_size(available_space
, BINARY
),
26 humansize
::format_size(total_space
, BINARY
),
27 (used_space
as f64 / total_space
as f64) * 100.0
32 pub fn clear_llvm_files(env
: &Environment
) -> anyhow
::Result
<()> {
33 // Bootstrap currently doesn't support rebuilding LLVM when PGO options
34 // change (or any other llvm-related options); so just clear out the relevant
35 // directories ourselves.
36 log
::info
!("Clearing LLVM build files");
37 delete_directory(&env
.build_artifacts().join("llvm"))?
;
38 delete_directory(&env
.build_artifacts().join("lld"))?
;
42 /// Write the formatted statistics of the timer to a Github Actions summary.
43 pub fn write_timer_to_summary(path
: &str, timer
: &Timer
) -> anyhow
::Result
<()> {
46 let mut file
= std
::fs
::File
::options().append(true).create(true).open(path
)?
;
60 /// Wraps all output produced within the `func` closure in a CI output group, if we're running in
62 pub fn with_log_group
<F
: FnOnce() -> R
, R
>(group
: &str, func
: F
) -> R
{
64 println
!("::group::{group}");
66 println
!("::endgroup::");
74 pub fn retry_action
<F
: Fn() -> anyhow
::Result
<R
>, R
>(
78 ) -> anyhow
::Result
<R
> {
79 for attempt
in 0..count
{
81 Ok(result
) => return Ok(result
),
83 log
::error
!("Failed to perform action `{name}`, attempt #{attempt}: {error:?}");
84 std
::thread
::sleep(Duration
::from_secs(5));
88 Err(anyhow
::anyhow
!("Failed to perform action `{name}` after {count} retries"))
91 fn is_in_ci() -> bool
{
92 std
::env
::var("GITHUB_ACTIONS").is_ok()