Skip to content

Commit 775682d

Browse files
authored
Rollup merge of #110637 - oli-obk:gha, r=jyn514
Group some sections of our logs in github actions This makes logs a little bit more readable as you can now collapse all the parts that don't interest you (and they get collapsed automatically) Obviously there's a lot more sites where we can/need to do this, too, but this is already helpful imo r? ```@jyn514```
2 parents 8aab707 + 95e8b6a commit 775682d

File tree

9 files changed

+190
-177
lines changed

9 files changed

+190
-177
lines changed

src/bootstrap/bootstrap.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,14 @@ def bootstrap_binary(self):
722722

723723
def build_bootstrap(self, color, verbose_count):
724724
"""Build bootstrap"""
725-
print("Building bootstrap")
725+
env = os.environ.copy()
726+
if "GITHUB_ACTIONS" in env:
727+
print("::group::Building bootstrap")
728+
else:
729+
print("Building bootstrap")
726730
build_dir = os.path.join(self.build_dir, "bootstrap")
727731
if self.clean and os.path.exists(build_dir):
728732
shutil.rmtree(build_dir)
729-
env = os.environ.copy()
730733
# `CARGO_BUILD_TARGET` breaks bootstrap build.
731734
# See also: <https://github.com/rust-lang/rust/issues/70208>.
732735
if "CARGO_BUILD_TARGET" in env:
@@ -798,6 +801,9 @@ def build_bootstrap(self, color, verbose_count):
798801
# Run this from the source directory so cargo finds .cargo/config
799802
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
800803

804+
if "GITHUB_ACTIONS" in env:
805+
print("::endgroup::")
806+
801807
def build_triple(self):
802808
"""Build triple as in LLVM
803809

src/bootstrap/check.rs

+6-60
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,7 @@ impl Step for Std {
105105
cargo.arg("--lib");
106106
}
107107

108-
let msg = if compiler.host == target {
109-
format!("Checking stage{} library artifacts ({target})", builder.top_stage)
110-
} else {
111-
format!(
112-
"Checking stage{} library artifacts ({} -> {})",
113-
builder.top_stage, &compiler.host, target
114-
)
115-
};
116-
builder.info(&msg);
108+
let _guard = builder.msg_check("library artifacts", target);
117109
run_cargo(
118110
builder,
119111
cargo,
@@ -167,18 +159,7 @@ impl Step for Std {
167159
cargo.arg("-p").arg(krate.name);
168160
}
169161

170-
let msg = if compiler.host == target {
171-
format!(
172-
"Checking stage{} library test/bench/example targets ({target})",
173-
builder.top_stage
174-
)
175-
} else {
176-
format!(
177-
"Checking stage{} library test/bench/example targets ({} -> {})",
178-
builder.top_stage, &compiler.host, target
179-
)
180-
};
181-
builder.info(&msg);
162+
let _guard = builder.msg_check("library test/bench/example targets", target);
182163
run_cargo(
183164
builder,
184165
cargo,
@@ -252,15 +233,7 @@ impl Step for Rustc {
252233
cargo.arg("-p").arg(krate.name);
253234
}
254235

255-
let msg = if compiler.host == target {
256-
format!("Checking stage{} compiler artifacts ({target})", builder.top_stage)
257-
} else {
258-
format!(
259-
"Checking stage{} compiler artifacts ({} -> {})",
260-
builder.top_stage, &compiler.host, target
261-
)
262-
};
263-
builder.info(&msg);
236+
let _guard = builder.msg_check("compiler artifacts", target);
264237
run_cargo(
265238
builder,
266239
cargo,
@@ -317,15 +290,7 @@ impl Step for CodegenBackend {
317290
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
318291
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
319292

320-
let msg = if compiler.host == target {
321-
format!("Checking stage{} {} artifacts ({target})", builder.top_stage, backend)
322-
} else {
323-
format!(
324-
"Checking stage{} {} library ({} -> {})",
325-
builder.top_stage, backend, &compiler.host.triple, target.triple
326-
)
327-
};
328-
builder.info(&msg);
293+
let _guard = builder.msg_check(&backend, target);
329294

330295
run_cargo(
331296
builder,
@@ -385,15 +350,7 @@ impl Step for RustAnalyzer {
385350
cargo.arg("--benches");
386351
}
387352

388-
let msg = if compiler.host == target {
389-
format!("Checking stage{} {} artifacts ({target})", compiler.stage, "rust-analyzer")
390-
} else {
391-
format!(
392-
"Checking stage{} {} artifacts ({} -> {})",
393-
compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple
394-
)
395-
};
396-
builder.info(&msg);
353+
let _guard = builder.msg_check("rust-analyzer artifacts", target);
397354
run_cargo(
398355
builder,
399356
cargo,
@@ -460,18 +417,7 @@ macro_rules! tool_check_step {
460417
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
461418
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
462419
cargo.rustflag("-Zunstable-options");
463-
let msg = if compiler.host == target {
464-
format!("Checking stage{} {} artifacts ({target})", builder.top_stage, stringify!($name).to_lowercase())
465-
} else {
466-
format!(
467-
"Checking stage{} {} artifacts ({} -> {})",
468-
builder.top_stage,
469-
stringify!($name).to_lowercase(),
470-
&compiler.host.triple,
471-
target.triple
472-
)
473-
};
474-
builder.info(&msg);
420+
let _guard = builder.msg_check(&concat!(stringify!($name), " artifacts").to_lowercase(), target);
475421
run_cargo(
476422
builder,
477423
cargo,

src/bootstrap/compile.rs

+15-44
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,13 @@ impl Step for Std {
143143
cargo.arg("-p").arg(krate);
144144
}
145145

146-
let msg = if compiler.host == target {
147-
format!(
148-
"Building{} stage{} library artifacts ({}) ",
149-
crate_description(&self.crates),
150-
compiler.stage,
151-
compiler.host
152-
)
153-
} else {
154-
format!(
155-
"Building{} stage{} library artifacts ({} -> {})",
156-
crate_description(&self.crates),
157-
compiler.stage,
158-
compiler.host,
159-
target,
160-
)
161-
};
162-
builder.info(&msg);
146+
let _guard = builder.msg(
147+
Kind::Build,
148+
compiler.stage,
149+
format_args!("library artifacts{}", crate_description(&self.crates)),
150+
compiler.host,
151+
target,
152+
);
163153
run_cargo(
164154
builder,
165155
cargo,
@@ -790,24 +780,13 @@ impl Step for Rustc {
790780
cargo.arg("-p").arg(krate);
791781
}
792782

793-
let msg = if compiler.host == target {
794-
format!(
795-
"Building{} compiler artifacts (stage{} -> stage{})",
796-
crate_description(&self.crates),
797-
compiler.stage,
798-
compiler.stage + 1
799-
)
800-
} else {
801-
format!(
802-
"Building{} compiler artifacts (stage{}:{} -> stage{}:{})",
803-
crate_description(&self.crates),
804-
compiler.stage,
805-
compiler.host,
806-
compiler.stage + 1,
807-
target,
808-
)
809-
};
810-
builder.info(&msg);
783+
let _guard = builder.msg_sysroot_tool(
784+
Kind::Build,
785+
compiler.stage,
786+
format_args!("compiler artifacts{}", crate_description(&self.crates)),
787+
compiler.host,
788+
target,
789+
);
811790
run_cargo(
812791
builder,
813792
cargo,
@@ -1114,15 +1093,7 @@ impl Step for CodegenBackend {
11141093

11151094
let tmp_stamp = out_dir.join(".tmp.stamp");
11161095

1117-
let msg = if compiler.host == target {
1118-
format!("Building stage{} codegen backend {}", compiler.stage, backend)
1119-
} else {
1120-
format!(
1121-
"Building stage{} codegen backend {} ({} -> {})",
1122-
compiler.stage, backend, compiler.host, target
1123-
)
1124-
};
1125-
builder.info(&msg);
1096+
let _guard = builder.msg_build(compiler, format_args!("codegen backend {backend}"), target);
11261097
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false);
11271098
if builder.config.dry_run() {
11281099
return;

src/bootstrap/install.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::util::t;
1212

1313
use crate::dist;
1414
use crate::tarball::GeneratedTarball;
15-
use crate::Compiler;
15+
use crate::{Compiler, Kind};
1616

1717
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
1818
use crate::config::{Config, TargetSelection};
@@ -52,7 +52,7 @@ fn install_sh(
5252
host: Option<TargetSelection>,
5353
tarball: &GeneratedTarball,
5454
) {
55-
builder.info(&format!("Install {} stage{} ({:?})", package, stage, host));
55+
let _guard = builder.msg(Kind::Install, stage, package, host, host);
5656

5757
let prefix = default_path(&builder.config.prefix, "/usr/local");
5858
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));

src/bootstrap/lib.rs

+81-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
use std::cell::{Cell, RefCell};
2020
use std::collections::{HashMap, HashSet};
2121
use std::env;
22+
use std::fmt::Display;
2223
use std::fs::{self, File};
2324
use std::io;
2425
use std::path::{Path, PathBuf};
2526
use std::process::{Command, Stdio};
2627
use std::str;
2728

28-
use build_helper::ci::CiEnv;
29+
use build_helper::ci::{gha, CiEnv};
2930
use channel::GitInfo;
3031
use config::{DryRun, Target};
3132
use filetime::FileTime;
@@ -993,6 +994,85 @@ impl Build {
993994
}
994995
}
995996

997+
fn msg_check(
998+
&self,
999+
what: impl Display,
1000+
target: impl Into<Option<TargetSelection>>,
1001+
) -> Option<gha::Group> {
1002+
self.msg(Kind::Check, self.config.stage, what, self.config.build, target)
1003+
}
1004+
1005+
fn msg_build(
1006+
&self,
1007+
compiler: Compiler,
1008+
what: impl Display,
1009+
target: impl Into<Option<TargetSelection>>,
1010+
) -> Option<gha::Group> {
1011+
self.msg(Kind::Build, compiler.stage, what, compiler.host, target)
1012+
}
1013+
1014+
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
1015+
fn msg(
1016+
&self,
1017+
action: impl Into<Kind>,
1018+
stage: u32,
1019+
what: impl Display,
1020+
host: impl Into<Option<TargetSelection>>,
1021+
target: impl Into<Option<TargetSelection>>,
1022+
) -> Option<gha::Group> {
1023+
let action = action.into();
1024+
let msg = |fmt| format!("{action:?}ing stage{stage} {what}{fmt}");
1025+
let msg = if let Some(target) = target.into() {
1026+
let host = host.into().unwrap();
1027+
if host == target {
1028+
msg(format_args!(" ({target})"))
1029+
} else {
1030+
msg(format_args!(" ({host} -> {target})"))
1031+
}
1032+
} else {
1033+
msg(format_args!(""))
1034+
};
1035+
self.group(&msg)
1036+
}
1037+
1038+
/// Return a `Group` guard for a [`Step`] that is only built once and isn't affected by `--stage`.
1039+
fn msg_unstaged(
1040+
&self,
1041+
action: impl Into<Kind>,
1042+
what: impl Display,
1043+
target: TargetSelection,
1044+
) -> Option<gha::Group> {
1045+
let action = action.into();
1046+
let msg = format!("{action:?}ing {what} for {target}");
1047+
self.group(&msg)
1048+
}
1049+
1050+
fn msg_sysroot_tool(
1051+
&self,
1052+
action: impl Into<Kind>,
1053+
stage: u32,
1054+
what: impl Display,
1055+
host: TargetSelection,
1056+
target: TargetSelection,
1057+
) -> Option<gha::Group> {
1058+
let action = action.into();
1059+
let msg = |fmt| format!("{action:?}ing {what} {fmt}");
1060+
let msg = if host == target {
1061+
msg(format_args!("(stage{stage} -> stage{}, {target})", stage + 1))
1062+
} else {
1063+
msg(format_args!("(stage{stage}:{host} -> stage{}:{target})", stage + 1))
1064+
};
1065+
self.group(&msg)
1066+
}
1067+
1068+
fn group(&self, msg: &str) -> Option<gha::Group> {
1069+
self.info(&msg);
1070+
match self.config.dry_run {
1071+
DryRun::SelfCheck => None,
1072+
DryRun::Disabled | DryRun::UserSelected => Some(gha::group(&msg)),
1073+
}
1074+
}
1075+
9961076
/// Returns the number of parallel jobs that have been configured for this
9971077
/// build.
9981078
fn jobs(&self) -> u32 {

src/bootstrap/llvm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::channel;
2121
use crate::config::{Config, TargetSelection};
2222
use crate::util::get_clang_cl_resource_dir;
2323
use crate::util::{self, exe, output, t, up_to_date};
24-
use crate::{CLang, GitRepo};
24+
use crate::{CLang, GitRepo, Kind};
2525

2626
use build_helper::ci::CiEnv;
2727

@@ -271,7 +271,7 @@ impl Step for Llvm {
271271
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
272272
}
273273

274-
builder.info(&format!("Building LLVM for {}", target));
274+
let _guard = builder.msg_unstaged(Kind::Build, "LLVM", target);
275275
t!(stamp.remove());
276276
let _time = util::timeit(&builder);
277277
t!(fs::create_dir_all(&out_dir));
@@ -813,7 +813,7 @@ impl Step for Lld {
813813
return out_dir;
814814
}
815815

816-
builder.info(&format!("Building LLD for {}", target));
816+
let _guard = builder.msg_unstaged(Kind::Build, "LLD", target);
817817
let _time = util::timeit(&builder);
818818
t!(fs::create_dir_all(&out_dir));
819819

@@ -911,7 +911,7 @@ impl Step for Sanitizers {
911911
return runtimes;
912912
}
913913

914-
builder.info(&format!("Building sanitizers for {}", self.target));
914+
let _guard = builder.msg_unstaged(Kind::Build, "sanitizers", self.target);
915915
t!(stamp.remove());
916916
let _time = util::timeit(&builder);
917917

@@ -1103,7 +1103,7 @@ impl Step for CrtBeginEnd {
11031103
return out_dir;
11041104
}
11051105

1106-
builder.info("Building crtbegin.o and crtend.o");
1106+
let _guard = builder.msg_unstaged(Kind::Build, "crtbegin.o and crtend.o", self.target);
11071107
t!(fs::create_dir_all(&out_dir));
11081108

11091109
let mut cfg = cc::Build::new();
@@ -1168,7 +1168,7 @@ impl Step for Libunwind {
11681168
return out_dir;
11691169
}
11701170

1171-
builder.info(&format!("Building libunwind.a for {}", self.target.triple));
1171+
let _guard = builder.msg_unstaged(Kind::Build, "libunwind.a", self.target);
11721172
t!(fs::create_dir_all(&out_dir));
11731173

11741174
let mut cc_cfg = cc::Build::new();

0 commit comments

Comments
 (0)