aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mingling_ci/Cargo.lock42
-rw-r--r--mingling_ci/Cargo.toml2
-rw-r--r--mingling_ci/help.txt15
-rw-r--r--mingling_ci/src/task/cmd_build.rs90
4 files changed, 142 insertions, 7 deletions
diff --git a/mingling_ci/Cargo.lock b/mingling_ci/Cargo.lock
index 5316e7a..8187736 100644
--- a/mingling_ci/Cargo.lock
+++ b/mingling_ci/Cargo.lock
@@ -24,6 +24,12 @@ dependencies = [
]
[[package]]
+name = "bytes"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
+
+[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -93,6 +99,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
+name = "errno"
+version = "0.3.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -282,6 +298,17 @@ dependencies = [
]
[[package]]
+name = "mio"
+version = "1.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427"
+dependencies = [
+ "libc",
+ "wasi",
+ "windows-sys",
+]
+
+[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -381,6 +408,16 @@ dependencies = [
]
[[package]]
+name = "signal-hook-registry"
+version = "1.4.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
+dependencies = [
+ "errno",
+ "libc",
+]
+
+[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -439,8 +476,13 @@ version = "1.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
dependencies = [
+ "bytes",
+ "libc",
+ "mio",
"pin-project-lite",
+ "signal-hook-registry",
"tokio-macros",
+ "windows-sys",
]
[[package]]
diff --git a/mingling_ci/Cargo.toml b/mingling_ci/Cargo.toml
index 197bca3..5db7c97 100644
--- a/mingling_ci/Cargo.toml
+++ b/mingling_ci/Cargo.toml
@@ -28,7 +28,9 @@ tokio = { version = "1.53.1", features = [
"rt",
"rt-multi-thread",
"macros",
+ "process",
] }
+
prettytable-rs = "0.10.0"
toml = "0.8"
just_template = "0.2.1"
diff --git a/mingling_ci/help.txt b/mingling_ci/help.txt
index 24563be..0e0f320 100644
--- a/mingling_ci/help.txt
+++ b/mingling_ci/help.txt
@@ -1,11 +1,18 @@
This program is used to check the code quality of the Mingling project itself.
+USAGE: cargo ci <FLAGS> [SUBCOMMAND] <ARGS...>
+ ^^___ Developing, currently `cin`
+
FLAGS:
-h, --help Print this help page
-q, --quiet Quiet output
-USAGE:
- report-collect Collect and organize all inspection reports
- report-clean Clean up all reports
+COMMANDS:
+ UTILS:
+ report-collect Collect and organize all inspection reports
+ report-clean Clean up all reports
+
+ show-manifests Print all crate paths that need to be checked
- show-manifests Print all crate paths that need to be checked
+ TASKS:
+ build-all Build all crates
diff --git a/mingling_ci/src/task/cmd_build.rs b/mingling_ci/src/task/cmd_build.rs
index 7f43102..a72ab0b 100644
--- a/mingling_ci/src/task/cmd_build.rs
+++ b/mingling_ci/src/task/cmd_build.rs
@@ -1,4 +1,88 @@
-use mingling::macros::command;
+use std::path::Path;
-#[command(node = "build")]
-pub fn build() {}
+use just_progress::progress::{self, ProgressInfo};
+use mingling::{
+ Grouped, Routable,
+ macros::{buffer, command, r_println, renderer},
+};
+
+use crate::Next;
+use crate::reporter::{self, ReportResult};
+use crate::res::Manifests;
+
+#[command(node = "build-all")]
+pub async fn build_all(manifests: &Manifests) -> Next {
+ const TASK: &str = "Build-All";
+
+ reporter::set_task(TASK);
+
+ let total = manifests.package_dirs.len();
+ progress::update(TASK, 0.0, ProgressInfo::Info("Building"));
+
+ // Run one `cargo build` per manifest in parallel.
+ let mut set = tokio::task::JoinSet::new();
+ for (name, path) in &manifests.package_dirs {
+ let (name, path) = (name.clone(), path.clone());
+ set.spawn(async move { (name, run_cargo_build(&path).await) });
+ }
+
+ // Collect all outcomes first, then dump the report files in one round.
+ let mut results: Vec<(String, ReportResult)> = Vec::new();
+ let mut done = 0;
+ while let Some(joined) = set.join_next().await {
+ done += 1;
+ let Ok((name, (ok, output))) = joined else {
+ continue;
+ };
+ // The count is small, so the `usize -> f32` cast cannot lose precision.
+ #[allow(clippy::cast_precision_loss)]
+ let overall = done as f32 / total as f32;
+ progress::update(TASK, overall, ProgressInfo::Info("Building"));
+ results.push((
+ name,
+ if ok {
+ ReportResult::Ok
+ } else {
+ ReportResult::Error(output)
+ },
+ ));
+ }
+
+ let fail_count = results
+ .iter()
+ .filter(|(_, r)| matches!(r, ReportResult::Error(_)))
+ .count();
+ for (name, result) in results {
+ reporter::export(&name, result);
+ }
+
+ ResultBuildAll { fail_count }.to_chain()
+}
+
+/// Runs `cargo build --manifest-path <path>`, returning success and output.
+async fn run_cargo_build(path: &Path) -> (bool, String) {
+ let output = tokio::process::Command::new("cargo")
+ .args(["build", "--manifest-path"])
+ .arg(path)
+ .output()
+ .await;
+ match output {
+ Ok(output) => {
+ let mut log = String::from_utf8_lossy(&output.stdout).into_owned();
+ log.push_str(&String::from_utf8_lossy(&output.stderr));
+ (output.status.success(), log)
+ }
+ Err(e) => (false, format!("failed to run cargo: {e}")),
+ }
+}
+
+/// Number of packages that failed to build.
+#[derive(Grouped)]
+pub struct ResultBuildAll {
+ pub fail_count: usize,
+}
+
+#[renderer(buffer)]
+pub fn render_build_all(r: ResultBuildAll) {
+ r_println!("Build-All: {} package(s) failed", r.fail_count);
+}