summaryrefslogtreecommitdiffstats
path: root/src/tools/build_helper
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /src/tools/build_helper
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/build_helper')
-rw-r--r--src/tools/build_helper/Cargo.toml2
-rw-r--r--src/tools/build_helper/src/ci.rs54
-rw-r--r--src/tools/build_helper/src/git.rs8
-rw-r--r--src/tools/build_helper/src/lib.rs1
-rw-r--r--src/tools/build_helper/src/metrics.rs92
-rw-r--r--src/tools/build_helper/src/util.rs6
6 files changed, 151 insertions, 12 deletions
diff --git a/src/tools/build_helper/Cargo.toml b/src/tools/build_helper/Cargo.toml
index 99f6fea2e..66894e1ab 100644
--- a/src/tools/build_helper/Cargo.toml
+++ b/src/tools/build_helper/Cargo.toml
@@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+serde = "1"
+serde_derive = "1"
diff --git a/src/tools/build_helper/src/ci.rs b/src/tools/build_helper/src/ci.rs
index 893195b69..a8505ec95 100644
--- a/src/tools/build_helper/src/ci.rs
+++ b/src/tools/build_helper/src/ci.rs
@@ -36,15 +36,26 @@ impl CiEnv {
}
pub mod gha {
+ use std::sync::Mutex;
+
+ static ACTIVE_GROUPS: Mutex<Vec<String>> = Mutex::new(Vec::new());
+
/// All github actions log messages from this call to the Drop of the return value
- /// will be grouped and hidden by default in logs. Note that nesting these does
- /// not really work.
+ /// will be grouped and hidden by default in logs. Note that since github actions doesn't
+ /// support group nesting, any active group will be first finished when a subgroup is started,
+ /// and then re-started when the subgroup finishes.
+ #[track_caller]
pub fn group(name: impl std::fmt::Display) -> Group {
- if std::env::var_os("GITHUB_ACTIONS").is_some() {
- eprintln!("::group::{name}");
- } else {
- eprintln!("{name}")
+ let mut groups = ACTIVE_GROUPS.lock().unwrap();
+
+ // A group is currently active. End it first to avoid nesting.
+ if !groups.is_empty() {
+ end_group();
}
+
+ let name = name.to_string();
+ start_group(&name);
+ groups.push(name);
Group(())
}
@@ -54,9 +65,36 @@ pub mod gha {
impl Drop for Group {
fn drop(&mut self) {
- if std::env::var_os("GITHUB_ACTIONS").is_some() {
- eprintln!("::endgroup::");
+ end_group();
+
+ let mut groups = ACTIVE_GROUPS.lock().unwrap();
+ // Remove the current group
+ groups.pop();
+
+ // If there was some previous group, restart it
+ if is_in_gha() {
+ if let Some(name) = groups.last() {
+ start_group(format!("{name} (continued)"));
+ }
}
}
}
+
+ fn start_group(name: impl std::fmt::Display) {
+ if is_in_gha() {
+ eprintln!("::group::{name}");
+ } else {
+ eprintln!("{name}")
+ }
+ }
+
+ fn end_group() {
+ if is_in_gha() {
+ eprintln!("::endgroup::");
+ }
+ }
+
+ fn is_in_gha() -> bool {
+ std::env::var_os("GITHUB_ACTIONS").is_some()
+ }
}
diff --git a/src/tools/build_helper/src/git.rs b/src/tools/build_helper/src/git.rs
index 168633c8f..66876e02c 100644
--- a/src/tools/build_helper/src/git.rs
+++ b/src/tools/build_helper/src/git.rs
@@ -94,7 +94,9 @@ pub fn get_git_modified_files(
git_dir: Option<&Path>,
extensions: &Vec<&str>,
) -> Result<Option<Vec<String>>, String> {
- let Ok(updated_master) = updated_master_branch(git_dir) else { return Ok(None); };
+ let Ok(updated_master) = updated_master_branch(git_dir) else {
+ return Ok(None);
+ };
let git = || {
let mut git = Command::new("git");
@@ -119,7 +121,9 @@ pub fn get_git_modified_files(
/// Returns the files that haven't been added to git yet.
pub fn get_git_untracked_files(git_dir: Option<&Path>) -> Result<Option<Vec<String>>, String> {
- let Ok(_updated_master) = updated_master_branch(git_dir) else { return Ok(None); };
+ let Ok(_updated_master) = updated_master_branch(git_dir) else {
+ return Ok(None);
+ };
let mut git = Command::new("git");
if let Some(git_dir) = git_dir {
git.current_dir(git_dir);
diff --git a/src/tools/build_helper/src/lib.rs b/src/tools/build_helper/src/lib.rs
index 3fa970373..575f36771 100644
--- a/src/tools/build_helper/src/lib.rs
+++ b/src/tools/build_helper/src/lib.rs
@@ -1,3 +1,4 @@
pub mod ci;
pub mod git;
+pub mod metrics;
pub mod util;
diff --git a/src/tools/build_helper/src/metrics.rs b/src/tools/build_helper/src/metrics.rs
new file mode 100644
index 000000000..2d0c66a8f
--- /dev/null
+++ b/src/tools/build_helper/src/metrics.rs
@@ -0,0 +1,92 @@
+use serde_derive::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub struct JsonRoot {
+ #[serde(default)] // For version 0 the field was not present.
+ pub format_version: usize,
+ pub system_stats: JsonInvocationSystemStats,
+ pub invocations: Vec<JsonInvocation>,
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub struct JsonInvocation {
+ // Unix timestamp in seconds
+ //
+ // This is necessary to easily correlate this invocation with logs or other data.
+ pub start_time: u64,
+ pub duration_including_children_sec: f64,
+ pub children: Vec<JsonNode>,
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(tag = "kind", rename_all = "snake_case")]
+pub enum JsonNode {
+ RustbuildStep {
+ #[serde(rename = "type")]
+ type_: String,
+ debug_repr: String,
+
+ duration_excluding_children_sec: f64,
+ system_stats: JsonStepSystemStats,
+
+ children: Vec<JsonNode>,
+ },
+ TestSuite(TestSuite),
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct TestSuite {
+ pub metadata: TestSuiteMetadata,
+ pub tests: Vec<Test>,
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(tag = "kind", rename_all = "snake_case")]
+pub enum TestSuiteMetadata {
+ CargoPackage {
+ crates: Vec<String>,
+ target: String,
+ host: String,
+ stage: u32,
+ },
+ Compiletest {
+ suite: String,
+ mode: String,
+ compare_mode: Option<String>,
+ target: String,
+ host: String,
+ stage: u32,
+ },
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Test {
+ pub name: String,
+ #[serde(flatten)]
+ pub outcome: TestOutcome,
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(tag = "outcome", rename_all = "snake_case")]
+pub enum TestOutcome {
+ Passed,
+ Failed,
+ Ignored { ignore_reason: Option<String> },
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub struct JsonInvocationSystemStats {
+ pub cpu_threads_count: usize,
+ pub cpu_model: String,
+
+ pub memory_total_bytes: u64,
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub struct JsonStepSystemStats {
+ pub cpu_utilization_percent: f64,
+}
diff --git a/src/tools/build_helper/src/util.rs b/src/tools/build_helper/src/util.rs
index 11b8a228b..5801a8648 100644
--- a/src/tools/build_helper/src/util.rs
+++ b/src/tools/build_helper/src/util.rs
@@ -1,10 +1,12 @@
use std::process::Command;
/// Invokes `build_helper::util::detail_exit` with `cfg!(test)`
+///
+/// This is a macro instead of a function so that it uses `cfg(test)` in the *calling* crate, not in build helper.
#[macro_export]
-macro_rules! detail_exit_macro {
+macro_rules! exit {
($code:expr) => {
- build_helper::util::detail_exit($code, cfg!(test));
+ $crate::util::detail_exit($code, cfg!(test));
};
}