Skip to content

Commit

Permalink
Rollup merge of rust-lang#110637 - oli-obk:gha, r=jyn514
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
matthiaskrgr authored Apr 24, 2023
2 parents f07a69e + 95e8b6a commit 48c34fa
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 177 deletions.
10 changes: 8 additions & 2 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,14 @@ def bootstrap_binary(self):

def build_bootstrap(self, color, verbose_count):
"""Build bootstrap"""
print("Building bootstrap")
env = os.environ.copy()
if "GITHUB_ACTIONS" in env:
print("::group::Building bootstrap")
else:
print("Building bootstrap")
build_dir = os.path.join(self.build_dir, "bootstrap")
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
env = os.environ.copy()
# `CARGO_BUILD_TARGET` breaks bootstrap build.
# See also: <https://github.com/rust-lang/rust/issues/70208>.
if "CARGO_BUILD_TARGET" in env:
Expand Down Expand Up @@ -798,6 +801,9 @@ def build_bootstrap(self, color, verbose_count):
# Run this from the source directory so cargo finds .cargo/config
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)

if "GITHUB_ACTIONS" in env:
print("::endgroup::")

def build_triple(self):
"""Build triple as in LLVM
Expand Down
66 changes: 6 additions & 60 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ impl Step for Std {
cargo.arg("--lib");
}

let msg = if compiler.host == target {
format!("Checking stage{} library artifacts ({target})", builder.top_stage)
} else {
format!(
"Checking stage{} library artifacts ({} -> {})",
builder.top_stage, &compiler.host, target
)
};
builder.info(&msg);
let _guard = builder.msg_check("library artifacts", target);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -167,18 +159,7 @@ impl Step for Std {
cargo.arg("-p").arg(krate.name);
}

let msg = if compiler.host == target {
format!(
"Checking stage{} library test/bench/example targets ({target})",
builder.top_stage
)
} else {
format!(
"Checking stage{} library test/bench/example targets ({} -> {})",
builder.top_stage, &compiler.host, target
)
};
builder.info(&msg);
let _guard = builder.msg_check("library test/bench/example targets", target);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -252,15 +233,7 @@ impl Step for Rustc {
cargo.arg("-p").arg(krate.name);
}

let msg = if compiler.host == target {
format!("Checking stage{} compiler artifacts ({target})", builder.top_stage)
} else {
format!(
"Checking stage{} compiler artifacts ({} -> {})",
builder.top_stage, &compiler.host, target
)
};
builder.info(&msg);
let _guard = builder.msg_check("compiler artifacts", target);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -317,15 +290,7 @@ impl Step for CodegenBackend {
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);

let msg = if compiler.host == target {
format!("Checking stage{} {} artifacts ({target})", builder.top_stage, backend)
} else {
format!(
"Checking stage{} {} library ({} -> {})",
builder.top_stage, backend, &compiler.host.triple, target.triple
)
};
builder.info(&msg);
let _guard = builder.msg_check(&backend, target);

run_cargo(
builder,
Expand Down Expand Up @@ -385,15 +350,7 @@ impl Step for RustAnalyzer {
cargo.arg("--benches");
}

let msg = if compiler.host == target {
format!("Checking stage{} {} artifacts ({target})", compiler.stage, "rust-analyzer")
} else {
format!(
"Checking stage{} {} artifacts ({} -> {})",
compiler.stage, "rust-analyzer", &compiler.host.triple, target.triple
)
};
builder.info(&msg);
let _guard = builder.msg_check("rust-analyzer artifacts", target);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -460,18 +417,7 @@ macro_rules! tool_check_step {
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
cargo.rustflag("-Zunstable-options");
let msg = if compiler.host == target {
format!("Checking stage{} {} artifacts ({target})", builder.top_stage, stringify!($name).to_lowercase())
} else {
format!(
"Checking stage{} {} artifacts ({} -> {})",
builder.top_stage,
stringify!($name).to_lowercase(),
&compiler.host.triple,
target.triple
)
};
builder.info(&msg);
let _guard = builder.msg_check(&concat!(stringify!($name), " artifacts").to_lowercase(), target);
run_cargo(
builder,
cargo,
Expand Down
59 changes: 15 additions & 44 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,13 @@ impl Step for Std {
cargo.arg("-p").arg(krate);
}

let msg = if compiler.host == target {
format!(
"Building{} stage{} library artifacts ({}) ",
crate_description(&self.crates),
compiler.stage,
compiler.host
)
} else {
format!(
"Building{} stage{} library artifacts ({} -> {})",
crate_description(&self.crates),
compiler.stage,
compiler.host,
target,
)
};
builder.info(&msg);
let _guard = builder.msg(
Kind::Build,
compiler.stage,
format_args!("library artifacts{}", crate_description(&self.crates)),
compiler.host,
target,
);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -790,24 +780,13 @@ impl Step for Rustc {
cargo.arg("-p").arg(krate);
}

let msg = if compiler.host == target {
format!(
"Building{} compiler artifacts (stage{} -> stage{})",
crate_description(&self.crates),
compiler.stage,
compiler.stage + 1
)
} else {
format!(
"Building{} compiler artifacts (stage{}:{} -> stage{}:{})",
crate_description(&self.crates),
compiler.stage,
compiler.host,
compiler.stage + 1,
target,
)
};
builder.info(&msg);
let _guard = builder.msg_sysroot_tool(
Kind::Build,
compiler.stage,
format_args!("compiler artifacts{}", crate_description(&self.crates)),
compiler.host,
target,
);
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -1114,15 +1093,7 @@ impl Step for CodegenBackend {

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

let msg = if compiler.host == target {
format!("Building stage{} codegen backend {}", compiler.stage, backend)
} else {
format!(
"Building stage{} codegen backend {} ({} -> {})",
compiler.stage, backend, compiler.host, target
)
};
builder.info(&msg);
let _guard = builder.msg_build(compiler, format_args!("codegen backend {backend}"), target);
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false);
if builder.config.dry_run() {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::util::t;

use crate::dist;
use crate::tarball::GeneratedTarball;
use crate::Compiler;
use crate::{Compiler, Kind};

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

let prefix = default_path(&builder.config.prefix, "/usr/local");
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
Expand Down
82 changes: 81 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet};
use std::env;
use std::fmt::Display;
use std::fs::{self, File};
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str;

use build_helper::ci::CiEnv;
use build_helper::ci::{gha, CiEnv};
use channel::GitInfo;
use config::{DryRun, Target};
use filetime::FileTime;
Expand Down Expand Up @@ -993,6 +994,85 @@ impl Build {
}
}

fn msg_check(
&self,
what: impl Display,
target: impl Into<Option<TargetSelection>>,
) -> Option<gha::Group> {
self.msg(Kind::Check, self.config.stage, what, self.config.build, target)
}

fn msg_build(
&self,
compiler: Compiler,
what: impl Display,
target: impl Into<Option<TargetSelection>>,
) -> Option<gha::Group> {
self.msg(Kind::Build, compiler.stage, what, compiler.host, target)
}

/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
fn msg(
&self,
action: impl Into<Kind>,
stage: u32,
what: impl Display,
host: impl Into<Option<TargetSelection>>,
target: impl Into<Option<TargetSelection>>,
) -> Option<gha::Group> {
let action = action.into();
let msg = |fmt| format!("{action:?}ing stage{stage} {what}{fmt}");
let msg = if let Some(target) = target.into() {
let host = host.into().unwrap();
if host == target {
msg(format_args!(" ({target})"))
} else {
msg(format_args!(" ({host} -> {target})"))
}
} else {
msg(format_args!(""))
};
self.group(&msg)
}

/// Return a `Group` guard for a [`Step`] that is only built once and isn't affected by `--stage`.
fn msg_unstaged(
&self,
action: impl Into<Kind>,
what: impl Display,
target: TargetSelection,
) -> Option<gha::Group> {
let action = action.into();
let msg = format!("{action:?}ing {what} for {target}");
self.group(&msg)
}

fn msg_sysroot_tool(
&self,
action: impl Into<Kind>,
stage: u32,
what: impl Display,
host: TargetSelection,
target: TargetSelection,
) -> Option<gha::Group> {
let action = action.into();
let msg = |fmt| format!("{action:?}ing {what} {fmt}");
let msg = if host == target {
msg(format_args!("(stage{stage} -> stage{}, {target})", stage + 1))
} else {
msg(format_args!("(stage{stage}:{host} -> stage{}:{target})", stage + 1))
};
self.group(&msg)
}

fn group(&self, msg: &str) -> Option<gha::Group> {
self.info(&msg);
match self.config.dry_run {
DryRun::SelfCheck => None,
DryRun::Disabled | DryRun::UserSelected => Some(gha::group(&msg)),
}
}

/// Returns the number of parallel jobs that have been configured for this
/// build.
fn jobs(&self) -> u32 {
Expand Down
12 changes: 6 additions & 6 deletions src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::channel;
use crate::config::{Config, TargetSelection};
use crate::util::get_clang_cl_resource_dir;
use crate::util::{self, exe, output, t, up_to_date};
use crate::{CLang, GitRepo};
use crate::{CLang, GitRepo, Kind};

use build_helper::ci::CiEnv;

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

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

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

Expand Down Expand Up @@ -911,7 +911,7 @@ impl Step for Sanitizers {
return runtimes;
}

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

Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl Step for CrtBeginEnd {
return out_dir;
}

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

let mut cfg = cc::Build::new();
Expand Down Expand Up @@ -1168,7 +1168,7 @@ impl Step for Libunwind {
return out_dir;
}

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

let mut cc_cfg = cc::Build::new();
Expand Down
Loading

0 comments on commit 48c34fa

Please sign in to comment.