mod checkers;
mod generators;
mod mass_generators;
pub mod lua_processor;
use anyhow::{Context, Result};
#[cfg(debug_assertions)]
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::OnceLock;
use std::time::Duration;
use tokio::runtime::Runtime;
use tokio::sync::watch;
use crate::color;
use crate::errors;
use crate::config::{config_hash, resolve_extra_inputs};
use crate::file_index::FileIndex;
use crate::graph::{BuildGraph, Product};
pub mod names {
pub const TERA: &str = "tera";
pub const RUFF: &str = "ruff";
pub const PYLINT: &str = "pylint";
pub const MYPY: &str = "mypy";
pub const CC_SINGLE_FILE: &str = "cc_single_file";
pub const CC: &str = "cc";
pub const CPPCHECK: &str = "cppcheck";
pub const CLANG_TIDY: &str = "clang_tidy";
pub const SHELLCHECK: &str = "shellcheck";
pub const LUACHECK: &str = "luacheck";
pub const RUMDL: &str = "rumdl";
pub const SLEEP: &str = "sleep";
pub const MAKE: &str = "make";
pub const CARGO: &str = "cargo";
pub const CLIPPY: &str = "clippy";
pub const SPELLCHECK: &str = "spellcheck";
pub const YAMLLINT: &str = "yamllint";
pub const JQ: &str = "jq";
pub const JSONLINT: &str = "jsonlint";
pub const TAPLO: &str = "taplo";
pub const PYREFLY: &str = "pyrefly";
pub const JSON_SCHEMA: &str = "json_schema";
pub const TAGS: &str = "tags";
pub const PIP: &str = "pip";
pub const SPHINX: &str = "sphinx";
pub const NPM: &str = "npm";
pub const GEM: &str = "gem";
pub const MDBOOK: &str = "mdbook";
pub const MDL: &str = "mdl";
pub const MARKDOWNLINT: &str = "markdownlint";
pub const ASPELL: &str = "aspell";
pub const MARP: &str = "marp";
pub const PANDOC: &str = "pandoc";
pub const MARKDOWN: &str = "markdown";
pub const PDFLATEX: &str = "pdflatex";
pub const A2X: &str = "a2x";
pub const ASCII_CHECK: &str = "ascii_check";
pub const MERMAID: &str = "mermaid";
pub const DRAWIO: &str = "drawio";
pub const MAKO: &str = "mako";
pub const LIBREOFFICE: &str = "libreoffice";
pub const PDFUNITE: &str = "pdfunite";
pub const SCRIPT_CHECK: &str = "script_check";
pub const LINUX_MODULE: &str = "linux_module";
pub const CPPLINT: &str = "cpplint";
pub const CHECKPATCH: &str = "checkpatch";
pub const OBJDUMP: &str = "objdump";
}
static INTERRUPTED: AtomicBool = AtomicBool::new(false);
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
static INTERRUPT_SENDER: OnceLock<watch::Sender<bool>> = OnceLock::new();
fn get_runtime() -> &'static Runtime {
RUNTIME.get_or_init(|| {
Runtime::new().expect(errors::TOKIO_RUNTIME)
})
}
fn get_interrupt_sender() -> &'static watch::Sender<bool> {
INTERRUPT_SENDER.get_or_init(|| {
let (tx, _rx) = watch::channel(false);
tx
})
}
fn get_interrupt_receiver() -> watch::Receiver<bool> {
get_interrupt_sender().subscribe()
}
pub(crate) fn set_interrupted() {
INTERRUPTED.store(true, Ordering::SeqCst);
let _ = get_interrupt_sender().send(true);
}
pub(crate) fn is_interrupted() -> bool {
INTERRUPTED.load(Ordering::SeqCst)
}
#[cfg(debug_assertions)]
thread_local! {
static DECLARED_TOOLS: RefCell<Option<Vec<String>>> = const { RefCell::new(None) };
}
#[cfg(debug_assertions)]
pub(crate) fn set_declared_tools(tools: Option<Vec<String>>) {
DECLARED_TOOLS.with(|dt| {
*dt.borrow_mut() = tools;
});
}
#[cfg(not(debug_assertions))]
pub(crate) fn set_declared_tools(_tools: Option<Vec<String>>) {}
#[cfg(debug_assertions)]
pub(crate) fn suspend_tool_check() -> ToolCheckGuard {
let prev = DECLARED_TOOLS.with(|dt| dt.borrow_mut().take());
ToolCheckGuard { prev }
}
#[cfg(not(debug_assertions))]
pub(crate) fn suspend_tool_check() -> ToolCheckGuard {
ToolCheckGuard { _private: () }
}
#[cfg(debug_assertions)]
pub(crate) struct ToolCheckGuard {
prev: Option<Vec<String>>,
}
#[cfg(debug_assertions)]
impl Drop for ToolCheckGuard {
fn drop(&mut self) {
DECLARED_TOOLS.with(|dt| {
*dt.borrow_mut() = self.prev.take();
});
}
}
#[cfg(not(debug_assertions))]
pub(crate) struct ToolCheckGuard {
_private: (),
}
pub(crate) fn format_command(cmd: &Command) -> String {
let program = cmd.get_program().to_string_lossy();
let args: Vec<_> = cmd.get_args()
.map(|a| a.to_string_lossy())
.collect();
if args.is_empty() {
program.into_owned()
} else {
format!("{} {}", program, args.join(" "))
}
}
pub(crate) fn log_command(cmd: &Command) {
if crate::runtime_flags::show_child_processes() {
let cwd = cmd.get_current_dir()
.map(|p| p.display().to_string())
.unwrap_or_default();
if cwd.is_empty() {
eprintln!("{} {}", color::dim("[exec]"), format_command(cmd));
} else {
let cwd_info = format!("(in {})", cwd);
eprintln!("{} {} {}", color::dim("[exec]"), format_command(cmd), color::dim(&cwd_info));
}
}
}
fn run_command_inner(cmd: &mut Command, inherit_stdio: bool) -> Result<Output> {
log_command(cmd);
#[cfg(debug_assertions)]
DECLARED_TOOLS.with(|dt| {
if let Some(ref tools) = *dt.borrow() {
let program = cmd.get_program().to_string_lossy();
let basename = program.rsplit('/').next().unwrap_or(&program);
assert!(
tools.iter().any(|t| {
let t_basename = t.rsplit('/').next().unwrap_or(t);
t_basename == basename
}),
"Processor executed undeclared tool '{basename}'. Declared: {tools:?}",
);
}
});
if INTERRUPTED.load(Ordering::SeqCst) {
anyhow::bail!("Interrupted");
}
let program = cmd.get_program().to_os_string();
let args: Vec<_> = cmd.get_args().map(|a| a.to_os_string()).collect();
let current_dir = cmd.get_current_dir().map(|p| p.to_path_buf());
let envs: Vec<_> = cmd.get_envs()
.filter_map(|(k, v)| v.map(|val| (k.to_os_string(), val.to_os_string())))
.collect();
let rt = get_runtime();
rt.block_on(async {
let mut tokio_cmd = tokio::process::Command::new(&program);
tokio_cmd.args(&args);
if let Some(dir) = ¤t_dir {
tokio_cmd.current_dir(dir);
}
for (key, val) in &envs {
tokio_cmd.env(key, val);
}
if inherit_stdio {
tokio_cmd.stdout(std::process::Stdio::inherit());
tokio_cmd.stderr(std::process::Stdio::inherit());
} else {
tokio_cmd.stdout(std::process::Stdio::piped());
tokio_cmd.stderr(std::process::Stdio::piped());
}
tokio_cmd.kill_on_drop(true);
let child = tokio_cmd.spawn()
.with_context(|| format!("Failed to spawn: {} {}",
program.to_string_lossy(),
args.iter().map(|a| a.to_string_lossy()).collect::<Vec<_>>().join(" ")))?;
let mut interrupt_rx = get_interrupt_receiver();
if INTERRUPTED.load(Ordering::SeqCst) {
anyhow::bail!("Interrupted");
}
tokio::select! {
biased;
_ = interrupt_rx.changed() => {
anyhow::bail!("Interrupted")
}
result = child.wait_with_output() => {
let output = result.context("Failed to wait for child process")?;
Ok(output)
}
}
})
}
pub(crate) fn run_command(cmd: &mut Command) -> Result<Output> {
let show = crate::runtime_flags::show_output();
run_command_inner(cmd, show)
}
pub(crate) fn run_command_capture(cmd: &mut Command) -> Result<Output> {
run_command_inner(cmd, false)
}
pub(crate) fn check_command_output(output: &Output, context: impl std::fmt::Display) -> Result<()> {
if !output.status.success() {
use std::fmt::Write;
let mut msg = format!("{context} failed");
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
if !stderr.is_empty() {
let _ = write!(msg, "\nstderr:\n{}", stderr.trim_end());
}
if !stdout.is_empty() {
let _ = write!(msg, "\nstdout:\n{}", stdout.trim_end());
}
anyhow::bail!("{msg}");
}
Ok(())
}
pub(crate) fn scan_root(scan: &crate::config::ScanConfig) -> PathBuf {
PathBuf::from(scan.scan_dir())
}
pub(crate) fn scan_root_valid(scan: &crate::config::ScanConfig) -> bool {
let root = scan_root(scan);
root.as_os_str().is_empty() || root.exists()
}
pub(crate) fn stub_path(stub_dir: &Path, source: &Path, suffix: &str) -> PathBuf {
let stub_name = format!(
"{}.{}",
source.display().to_string().replace(['/', '\\'], "_"),
suffix,
);
stub_dir.join(stub_name)
}
pub(crate) fn dot_to_svg(dot_content: &str) -> Result<String> {
use std::process::{Command, Stdio};
let mut cmd = Command::new("dot");
cmd.arg("-Tsvg")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
log_command(&cmd);
let mut child = cmd
.spawn()
.map_err(|_| anyhow::anyhow!("Graphviz 'dot' command not found. Install Graphviz to use SVG format"))?;
child.stdin.take().expect(crate::errors::STDIN_PIPED).write_all(dot_content.as_bytes())?;
let output = child.wait_with_output()?;
check_command_output(&output, "dot")?;
Ok(String::from_utf8(output.stdout)?)
}
pub(crate) fn flush_words(
existing: &HashSet<String>,
new_words: &HashSet<String>,
words_path: &Path,
header_line: Option<&str>,
) -> Result<()> {
let to_add: Vec<_> = new_words.iter()
.filter(|w| !existing.contains(*w))
.collect();
if to_add.is_empty() {
return Ok(());
}
let mut sorted: Vec<_> = to_add;
sorted.sort();
let file_exists = words_path.exists();
let mut file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(words_path)
.with_context(|| format!("Failed to open words file: {}", words_path.display()))?;
if !file_exists {
if let Some(header) = header_line {
writeln!(file, "{}", header)?;
}
}
for word in &sorted {
writeln!(file, "{}", word)?;
}
println!("Added {} word(s) to {}", sorted.len(), words_path.display());
Ok(())
}
pub(crate) fn config_file_inputs(path: &str) -> Vec<String> {
if Path::new(path).exists() {
vec![path.to_string()]
} else {
Vec::new()
}
}
pub(crate) fn clean_outputs(product: &Product, label: &str, verbose: bool) -> Result<usize> {
let mut count = 0;
for output in &product.outputs {
match fs::remove_file(output) {
Ok(()) => {
count += 1;
if verbose {
println!("Removed {} output: {}", label, output.display());
}
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => return Err(e.into()),
}
}
Ok(count)
}
#[derive(Debug)]
pub(crate) struct SiblingFilter<'a> {
pub extensions: &'a [&'a str],
pub excludes: &'a [&'a str],
}
pub(crate) struct DirectoryProductOpts<'a, H: serde::Serialize> {
pub scan: &'a crate::config::ScanConfig,
pub file_index: &'a FileIndex,
pub extra_inputs: &'a [String],
pub cfg_hash: &'a H,
pub siblings: &'a SiblingFilter<'a>,
pub processor_name: &'a str,
pub output_dir_name: Option<&'a str>,
}
pub(crate) fn discover_directory_products(
graph: &mut BuildGraph,
opts: DirectoryProductOpts<'_, impl serde::Serialize>,
) -> Result<()> {
let DirectoryProductOpts { scan, file_index, extra_inputs, cfg_hash, siblings, processor_name, output_dir_name } = opts;
let files = file_index.scan(scan, true);
if files.is_empty() {
return Ok(());
}
let hash = Some(config_hash(cfg_hash));
let extra = resolve_extra_inputs(extra_inputs)?;
for anchor in files {
let anchor_dir = anchor.parent().map(|p| p.to_path_buf()).unwrap_or_default();
let sibling_files = file_index.query(
&anchor_dir,
siblings.extensions,
siblings.excludes,
&[],
&[],
);
let mut inputs: Vec<PathBuf> = Vec::with_capacity(1 + sibling_files.len() + extra.len());
inputs.push(anchor.clone());
for file in &sibling_files {
if *file != anchor {
inputs.push(file.clone());
}
}
inputs.extend_from_slice(&extra);
if let Some(dir_name) = output_dir_name {
let output_dir = if anchor_dir.as_os_str().is_empty() {
PathBuf::from(dir_name)
} else {
anchor_dir.join(dir_name)
};
graph.add_product_with_output_dir(inputs, vec![], processor_name, hash.clone(), output_dir)?;
} else {
graph.add_product(inputs, vec![], processor_name, hash.clone())?;
}
}
Ok(())
}
pub(crate) fn discover_checker_products(
graph: &mut BuildGraph,
scan: &crate::config::ScanConfig,
file_index: &FileIndex,
extra_inputs: &[String],
cfg_hash: &impl serde::Serialize,
processor_name: &str,
) -> Result<()> {
let files = file_index.scan(scan, true);
if files.is_empty() {
return Ok(());
}
let hash = Some(config_hash(cfg_hash));
let extra = resolve_extra_inputs(extra_inputs)?;
for file in files {
let mut inputs = Vec::with_capacity(1 + extra.len());
inputs.push(file);
inputs.extend_from_slice(&extra);
graph.add_product(inputs, vec![], processor_name, hash.clone())?;
}
Ok(())
}
pub(crate) fn run_in_anchor_dir(cmd: &mut Command, anchor: &Path) -> Result<Output> {
let anchor_dir = anchor.parent()
.context("Anchor file has no parent directory")?;
if !anchor_dir.as_os_str().is_empty() {
cmd.current_dir(anchor_dir);
}
run_command(cmd)
}
pub(crate) fn anchor_display_dir(anchor: &Path) -> &str {
anchor.parent()
.and_then(|p| if p.as_os_str().is_empty() { None } else { p.to_str() })
.unwrap_or(".")
}
pub(crate) fn ensure_stub_dir(stub_dir: &Path, processor_name: &str) -> Result<()> {
if !stub_dir.exists() {
fs::create_dir_all(stub_dir)
.with_context(|| format!("Failed to create {} stub directory", processor_name))?;
}
Ok(())
}
pub(crate) fn run_checker(
tool: &str,
subcommand: Option<&str>,
args: &[String],
files: &[&Path],
) -> Result<()> {
let mut cmd = Command::new(tool);
if let Some(sub) = subcommand {
cmd.arg(sub);
}
for arg in args {
cmd.arg(arg);
}
for file in files {
cmd.arg(file);
}
let output = run_command(&mut cmd)?;
check_command_output(&output, tool)
}
pub(crate) fn execute_checker_batch<F>(
products: &[&Product],
batch_fn: F,
) -> Vec<Result<()>>
where
F: Fn(&[&Path]) -> Result<()>,
{
let input_paths: Vec<&Path> = products.iter()
.map(|p| p.primary_input())
.collect();
match batch_fn(&input_paths) {
Ok(()) => products.iter().map(|_| Ok(())).collect(),
Err(e) => {
let err_msg = e.to_string();
products.iter().map(|_| Err(anyhow::anyhow!("{}", err_msg))).collect()
}
}
}
pub use checkers::{
AsciiCheckProcessor, AspellProcessor,
CheckpatchProcessor, ClippyProcessor, ClangTidyProcessor, CppcheckProcessor, CpplintProcessor,
JqProcessor, JsonlintProcessor, JsonSchemaProcessor,
LuacheckProcessor, MakeProcessor, MarkdownlintProcessor, MdlProcessor, MypyProcessor,
PylintProcessor, PyreflyProcessor, RuffProcessor, RumdlProcessor,
ScriptCheckProcessor, ShellcheckProcessor, SleepProcessor, SpellcheckProcessor,
TaploProcessor, YamllintProcessor,
};
pub use generators::{A2xProcessor, CcSingleFileProcessor, DrawioProcessor, LibreofficeProcessor, LinuxModuleProcessor, MakoProcessor, MarpProcessor, MarkdownProcessor, MermaidProcessor, ObjdumpProcessor, PandocProcessor, PdflatexProcessor, PdfuniteProcessor, TagsProcessor, TeraProcessor};
pub use mass_generators::{CargoProcessor, CcProcessor, GemProcessor, MdbookProcessor, NpmProcessor, PipProcessor, SphinxProcessor};
pub(crate) use generators::tags as tags_cmd;
pub use lua_processor::LuaProcessor;
pub type ProcessorMap = HashMap<String, Box<dyn ProductDiscovery>>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProcessorType {
Generator,
Checker,
MassGenerator,
}
impl ProcessorType {
pub fn as_str(&self) -> &'static str {
match self {
ProcessorType::Generator => "generator",
ProcessorType::Checker => "checker",
ProcessorType::MassGenerator => "mass_generator",
}
}
}
pub trait ProductDiscovery: Sync + Send {
fn description(&self) -> &str;
fn processor_type(&self) -> ProcessorType {
ProcessorType::Checker
}
fn hidden(&self) -> bool {
false
}
fn discover(&self, graph: &mut BuildGraph, file_index: &FileIndex) -> Result<()>;
fn discover_for_clean(&self, graph: &mut BuildGraph, file_index: &FileIndex) -> Result<()> {
self.discover(graph, file_index)
}
fn execute(&self, product: &Product) -> Result<()>;
fn clean(&self, _product: &Product, _verbose: bool) -> Result<usize> {
Ok(0)
}
fn auto_detect(&self, file_index: &FileIndex) -> bool;
fn required_tools(&self) -> Vec<String> {
Vec::new()
}
fn tool_version_commands(&self) -> Vec<(String, Vec<String>)> {
self.required_tools()
.into_iter()
.map(|tool| (tool, vec!["--version".to_string()]))
.collect()
}
fn supports_batch(&self) -> bool {
false
}
fn execute_batch(&self, products: &[&Product]) -> Vec<Result<()>> {
products.iter().map(|p| self.execute(p)).collect()
}
fn config_json(&self) -> Option<String> {
None
}
}
pub fn tool_install_command(tool: &str) -> Option<&'static str> {
match tool {
"ruff" => Some("pip install ruff"),
"pylint" => Some("pip install pylint"),
"mypy" => Some("pip install mypy"),
"pyrefly" => Some("pip install pyrefly"),
"yamllint" => Some("pip install yamllint"),
"sphinx-build" => Some("pip install sphinx"),
"pip" => Some("python3 -m ensurepip"),
"mdbook" => Some("cargo install mdbook"),
"rumdl" => Some("cargo install rumdl"),
"taplo" => Some("cargo install taplo-cli"),
"cargo" | "rustc" => Some("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"),
"shellcheck" => Some("apt install shellcheck"),
"luacheck" => Some("apt install lua-check"),
"cpplint" => Some("pip install cpplint"),
"cppcheck" => Some("apt install cppcheck"),
"clang-tidy" => Some("apt install clang-tidy"),
"gcc" => Some("apt install gcc"),
"g++" => Some("apt install g++"),
"clang" | "clang++" => Some("apt install clang"),
"make" => Some("apt install make"),
"jq" => Some("apt install jq"),
"aspell" => Some("apt install aspell"),
"pandoc" => Some("apt install pandoc"),
"markdown" => Some("apt install markdown"),
"pdflatex" => Some("apt install texlive-latex-base"),
"qpdf" => Some("apt install qpdf"),
"a2x" => Some("apt install asciidoc"),
"dot" => Some("apt install graphviz"),
"drawio" => Some("snap install drawio"),
"libreoffice" => Some("apt install libreoffice"),
"flock" => Some("apt install util-linux"),
"pdfunite" => Some("apt install poppler-utils"),
"python3" => Some("apt install python3"),
"jsonlint" => Some("pip install jsonlint"),
"marp" => Some("npm install -g @marp-team/marp-cli"),
"mmdc" => Some("npm install -g @mermaid-js/mermaid-cli"),
"node_modules/.bin/markdownlint" => Some("npm install markdownlint-cli"),
"npm" => Some("apt install npm"),
"node" => Some("apt install nodejs"),
"gems/bin/mdl" => Some("gem install mdl"),
"bundle" => Some("gem install bundler"),
"ruby" => Some("apt install ruby"),
"objdump" => Some("apt install binutils"),
"checkpatch.pl" => Some("install from Linux kernel source: scripts/checkpatch.pl"),
"perl" => Some("apt install perl"),
_ => None,
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ProductTiming {
pub display: String,
pub processor: String,
pub duration: Duration,
pub start_offset: Option<Duration>,
}
#[derive(Debug, Default, PartialEq)]
pub struct ProcessStats {
pub processed: usize,
pub failed: usize,
pub flaky: usize,
pub skipped: usize,
pub restored: usize,
pub files_created: usize,
pub files_restored: usize,
pub duration: Duration,
pub product_timings: Vec<ProductTiming>,
}
impl ProcessStats {
pub fn total(&self) -> usize {
self.processed + self.failed + self.skipped + self.restored
}
}
#[derive(Default)]
pub struct BuildStats {
pub categories: Vec<ProcessStats>,
pub total_duration: Duration,
pub failed_count: usize,
pub failed_messages: Vec<String>,
pub phase_timings: Vec<(String, Duration)>,
}
impl BuildStats {
pub fn add(&mut self, stats: ProcessStats) {
if stats.total() > 0 {
self.categories.push(stats);
}
}
pub fn total_processed(&self) -> usize {
self.categories.iter().map(|s| s.processed).sum()
}
pub fn total_skipped(&self) -> usize {
self.categories.iter().map(|s| s.skipped).sum()
}
pub fn total_restored(&self) -> usize {
self.categories.iter().map(|s| s.restored).sum()
}
pub fn total_files_created(&self) -> usize {
self.categories.iter().map(|s| s.files_created).sum()
}
pub fn total_files_restored(&self) -> usize {
self.categories.iter().map(|s| s.files_restored).sum()
}
pub fn total_flaky(&self) -> usize {
self.categories.iter().map(|s| s.flaky).sum()
}
pub fn print_summary(&self, summary: bool, timings: bool) {
if crate::json_output::is_json_mode() || crate::runtime_flags::quiet() {
return;
}
if !summary && !timings {
return;
}
if self.categories.is_empty() && self.failed_count == 0 {
if summary {
println!("{}", color::dim("Nothing to build."));
}
return;
}
if summary {
let total_processed = self.total_processed();
let total_restored = self.total_restored();
let total_failed = self.failed_count;
let total_skipped = self.total_skipped();
let total_files_created = self.total_files_created();
let total_files_restored = self.total_files_restored();
let mut parts = Vec::new();
if total_processed > 0 {
if total_files_created > 0 {
parts.push(format!("{} processed ({} files created)", total_processed, total_files_created));
} else {
parts.push(format!("{} processed", total_processed));
}
}
if total_restored > 0 {
if total_files_restored > 0 {
parts.push(format!("{} restored ({} files)", total_restored, total_files_restored));
} else {
parts.push(format!("{} restored", total_restored));
}
}
let total_flaky = self.total_flaky();
if total_flaky > 0 {
parts.push(format!("{} flaky", total_flaky));
}
if total_failed > 0 {
parts.push(format!("{} failed", total_failed));
}
if total_skipped > 0 {
parts.push(format!("{} unchanged", total_skipped));
}
if parts.is_empty() {
println!("{}", color::dim("Nothing to build."));
} else {
let line = format!("Build summary: {}", parts.join(", "));
if total_failed > 0 {
println!("{}", color::red(&line));
} else {
println!("{}", color::green(&line));
}
}
}
if self.failed_count > 0 {
println!("{}", color::red(&format!("Build finished with {} error(s):", self.failed_count)));
for msg in &self.failed_messages {
println!("{} {}", color::red("*"), msg);
}
}
if timings {
println!();
println!("{}", color::bold("Timing:"));
if !self.phase_timings.is_empty() {
let max_name_len = self.phase_timings.iter().map(|(n, _)| n.len()).max().unwrap_or(0);
for (name, dur) in &self.phase_timings {
println!(" {:width$} {:.3}s", name, dur.as_secs_f64(), width = max_name_len);
}
}
for cat in &self.categories {
for pt in &cat.product_timings {
println!("[{}] {} {}", pt.processor, pt.display,
color::dim(&format!("({:.3}s)", pt.duration.as_secs_f64())));
}
}
let total: f64 = self.phase_timings.iter().map(|(_, d)| d.as_secs_f64()).sum();
println!("{}", color::bold(&format!("Total: {:.3}s", total)));
}
}
}