Skip to content

Commit 34d63e4

Browse files
committed
Use GHA log grouping
1 parent 8b9187d commit 34d63e4

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

build_system/build_backend.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33

44
use super::path::{Dirs, RelPath};
55
use super::rustc_info::get_file_name;
6-
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler};
6+
use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
77

88
pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
99

@@ -13,6 +13,8 @@ pub(crate) fn build_backend(
1313
bootstrap_host_compiler: &Compiler,
1414
use_unstable_features: bool,
1515
) -> PathBuf {
16+
let _group = LogGroup::guard("Build backend");
17+
1618
let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
1719
maybe_incremental(&mut cmd);
1820

build_system/build_sysroot.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::path::{Dirs, RelPath};
66
use super::rustc_info::get_file_name;
77
use super::utils::{
88
maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
9+
LogGroup,
910
};
1011
use super::{CodegenBackend, SysrootKind};
1112

@@ -22,6 +23,8 @@ pub(crate) fn build_sysroot(
2223
rustup_toolchain_name: Option<&str>,
2324
target_triple: String,
2425
) -> Compiler {
26+
let _guard = LogGroup::guard("Build sysroot");
27+
2528
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
2629

2730
DIST_DIR.ensure_fresh(dirs);

build_system/tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::config;
33
use super::path::{Dirs, RelPath};
44
use super::prepare::{apply_patches, GitRepo};
55
use super::rustc_info::get_default_sysroot;
6-
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
6+
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup};
77
use super::{CodegenBackend, SysrootKind};
88
use std::env;
99
use std::ffi::OsStr;
@@ -386,15 +386,17 @@ impl<'a> TestRunner<'a> {
386386
let tag = tag.to_uppercase();
387387
let is_jit_test = tag == "JIT";
388388

389-
if !config::get_bool(config)
389+
let _guard = if !config::get_bool(config)
390390
|| (is_jit_test && !self.jit_supported)
391391
|| self.skip_tests.contains(&config)
392392
{
393393
eprintln!("[{tag}] {testname} (skipped)");
394394
continue;
395395
} else {
396+
let guard = LogGroup::guard(&format!("[{tag}] {testname}"));
396397
eprintln!("[{tag}] {testname}");
397-
}
398+
guard
399+
};
398400

399401
match *cmd {
400402
TestCaseCmd::Custom { func } => func(self),

build_system/utils.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fs;
33
use std::io::{self, Write};
44
use std::path::{Path, PathBuf};
55
use std::process::{self, Command, Stdio};
6+
use std::sync::atomic::{AtomicBool, Ordering};
67

78
use super::path::{Dirs, RelPath};
89

@@ -259,6 +260,33 @@ pub(crate) fn is_ci_opt() -> bool {
259260
env::var("CI_OPT").is_ok()
260261
}
261262

263+
static IN_GROUP: AtomicBool = AtomicBool::new(false);
264+
pub(crate) struct LogGroup {
265+
is_gha: bool,
266+
}
267+
268+
impl LogGroup {
269+
pub(crate) fn guard(name: &str) -> LogGroup {
270+
let is_gha = env::var("GITHUB_ACTIONS").is_ok();
271+
272+
assert!(!IN_GROUP.swap(true, Ordering::SeqCst));
273+
if is_gha {
274+
eprintln!("::group::{name}");
275+
}
276+
277+
LogGroup { is_gha }
278+
}
279+
}
280+
281+
impl Drop for LogGroup {
282+
fn drop(&mut self) {
283+
if self.is_gha {
284+
eprintln!("::endgroup::");
285+
}
286+
IN_GROUP.store(false, Ordering::SeqCst);
287+
}
288+
}
289+
262290
pub(crate) fn maybe_incremental(cmd: &mut Command) {
263291
if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
264292
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway

0 commit comments

Comments
 (0)