about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-07-12 16:26:06 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-07-12 16:45:42 +0000
commit34d63e4c1d8700ebadc67a2672409f161a2a7777 (patch)
tree792c6bea5357919d7d289472ea065b7f5d74f8a1
parent8b9187dfecbd0b4ebbc670ae3ede66e87aa7c2e0 (diff)
downloadrust-34d63e4c1d8700ebadc67a2672409f161a2a7777.tar.gz
rust-34d63e4c1d8700ebadc67a2672409f161a2a7777.zip
Use GHA log grouping
-rw-r--r--build_system/build_backend.rs4
-rw-r--r--build_system/build_sysroot.rs3
-rw-r--r--build_system/tests.rs8
-rw-r--r--build_system/utils.rs28
4 files changed, 39 insertions, 4 deletions
diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs
index 6855c1a7fc5..1c5db23299d 100644
--- a/build_system/build_backend.rs
+++ b/build_system/build_backend.rs
@@ -3,7 +3,7 @@ use std::path::PathBuf;
 
 use super::path::{Dirs, RelPath};
 use super::rustc_info::get_file_name;
-use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler};
+use super::utils::{is_ci, is_ci_opt, maybe_incremental, CargoProject, Compiler, LogGroup};
 
 pub(crate) static CG_CLIF: CargoProject = CargoProject::new(&RelPath::SOURCE, "cg_clif");
 
@@ -13,6 +13,8 @@ pub(crate) fn build_backend(
     bootstrap_host_compiler: &Compiler,
     use_unstable_features: bool,
 ) -> PathBuf {
+    let _group = LogGroup::guard("Build backend");
+
     let mut cmd = CG_CLIF.build(&bootstrap_host_compiler, dirs);
     maybe_incremental(&mut cmd);
 
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index 2c8da62fb05..04097936d03 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -6,6 +6,7 @@ use super::path::{Dirs, RelPath};
 use super::rustc_info::get_file_name;
 use super::utils::{
     maybe_incremental, remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler,
+    LogGroup,
 };
 use super::{CodegenBackend, SysrootKind};
 
@@ -22,6 +23,8 @@ pub(crate) fn build_sysroot(
     rustup_toolchain_name: Option<&str>,
     target_triple: String,
 ) -> Compiler {
+    let _guard = LogGroup::guard("Build sysroot");
+
     eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
 
     DIST_DIR.ensure_fresh(dirs);
diff --git a/build_system/tests.rs b/build_system/tests.rs
index 8ff94702dd7..0254d18cf7c 100644
--- a/build_system/tests.rs
+++ b/build_system/tests.rs
@@ -3,7 +3,7 @@ use super::config;
 use super::path::{Dirs, RelPath};
 use super::prepare::{apply_patches, GitRepo};
 use super::rustc_info::get_default_sysroot;
-use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
+use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler, LogGroup};
 use super::{CodegenBackend, SysrootKind};
 use std::env;
 use std::ffi::OsStr;
@@ -386,15 +386,17 @@ impl<'a> TestRunner<'a> {
             let tag = tag.to_uppercase();
             let is_jit_test = tag == "JIT";
 
-            if !config::get_bool(config)
+            let _guard = if !config::get_bool(config)
                 || (is_jit_test && !self.jit_supported)
                 || self.skip_tests.contains(&config)
             {
                 eprintln!("[{tag}] {testname} (skipped)");
                 continue;
             } else {
+                let guard = LogGroup::guard(&format!("[{tag}] {testname}"));
                 eprintln!("[{tag}] {testname}");
-            }
+                guard
+            };
 
             match *cmd {
                 TestCaseCmd::Custom { func } => func(self),
diff --git a/build_system/utils.rs b/build_system/utils.rs
index 41fc366e290..92a33b8bf4d 100644
--- a/build_system/utils.rs
+++ b/build_system/utils.rs
@@ -3,6 +3,7 @@ use std::fs;
 use std::io::{self, Write};
 use std::path::{Path, PathBuf};
 use std::process::{self, Command, Stdio};
+use std::sync::atomic::{AtomicBool, Ordering};
 
 use super::path::{Dirs, RelPath};
 
@@ -259,6 +260,33 @@ pub(crate) fn is_ci_opt() -> bool {
     env::var("CI_OPT").is_ok()
 }
 
+static IN_GROUP: AtomicBool = AtomicBool::new(false);
+pub(crate) struct LogGroup {
+    is_gha: bool,
+}
+
+impl LogGroup {
+    pub(crate) fn guard(name: &str) -> LogGroup {
+        let is_gha = env::var("GITHUB_ACTIONS").is_ok();
+
+        assert!(!IN_GROUP.swap(true, Ordering::SeqCst));
+        if is_gha {
+            eprintln!("::group::{name}");
+        }
+
+        LogGroup { is_gha }
+    }
+}
+
+impl Drop for LogGroup {
+    fn drop(&mut self) {
+        if self.is_gha {
+            eprintln!("::endgroup::");
+        }
+        IN_GROUP.store(false, Ordering::SeqCst);
+    }
+}
+
 pub(crate) fn maybe_incremental(cmd: &mut Command) {
     if is_ci() || std::env::var("CARGO_BUILD_INCREMENTAL").map_or(false, |val| val == "false") {
         // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway