diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 409e6e1..73e6a9d 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -174,6 +174,7 @@ pub struct CommonVerbArgs { #[arg(short, long, default_value_t = 10, value_parser=more_than_zero)] pub parallel: usize, + /// Trace full build logs. #[arg(short = 'L', long, default_value_t = false)] pub print_build_logs: bool, } diff --git a/crates/core/src/commands/mod.rs b/crates/core/src/commands/mod.rs index bffc395..91e13d2 100644 --- a/crates/core/src/commands/mod.rs +++ b/crates/core/src/commands/mod.rs @@ -161,7 +161,12 @@ impl WireCommandChip for Either { impl ChildOutputMode { /// this function is by far the biggest hotspot in the whole tree /// Returns a string if this log is notable to be stored as an error message - fn trace_slice(self, line: &mut [u8], build_name_map: &BuildNameMap) -> Option { + fn trace_slice( + self, + line: &mut [u8], + build_name_map: &BuildNameMap, + print_build_logs: bool, + ) -> Option { let slice = match self { Self::Generic | Self::Interactive => { let string = String::from_utf8_lossy(line); @@ -201,6 +206,7 @@ impl ChildOutputMode { && matches!(r#type, nix_compat::log::ActivityType::Build) // first field of start log contains the build name. && let Some(Field::String(name)) = fields.first() + && print_build_logs { build_name_map .lock() @@ -221,6 +227,10 @@ impl ChildOutputMode { id, .. } => { + if !print_build_logs { + return None; + } + let Some(Field::String(msg)) = fields.into_iter().next() else { return None; }; diff --git a/crates/core/src/commands/noninteractive.rs b/crates/core/src/commands/noninteractive.rs index 0486c79..8925e41 100644 --- a/crates/core/src/commands/noninteractive.rs +++ b/crates/core/src/commands/noninteractive.rs @@ -98,6 +98,7 @@ pub(crate) async fn non_interactive_command_with_env>( true, true, arguments.build_name_map.clone(), + arguments.modifiers.print_build_logs, ) .in_current_span(), ); @@ -109,6 +110,7 @@ pub(crate) async fn non_interactive_command_with_env>( false, arguments.log_stdout, arguments.build_name_map.clone(), + arguments.modifiers.print_build_logs, ) .in_current_span(), ); @@ -164,6 +166,7 @@ pub async fn handle_io( is_error: bool, should_log: bool, build_name_map: BuildNameMap, + print_build_logs: bool, ) where R: tokio::io::AsyncRead + Unpin, { @@ -173,7 +176,7 @@ pub async fn handle_io( let mut line = line.into_bytes(); let log = if should_log { - Some(output_mode.trace_slice(&mut line, &build_name_map)) + Some(output_mode.trace_slice(&mut line, &build_name_map, print_build_logs)) } else { None }; diff --git a/crates/core/src/commands/pty/mod.rs b/crates/core/src/commands/pty/mod.rs index 500a5f5..2455f6d 100644 --- a/crates/core/src/commands/pty/mod.rs +++ b/crates/core/src/commands/pty/mod.rs @@ -191,6 +191,7 @@ pub(crate) async fn interactive_command_with_env>( log_stdout: arguments.log_stdout, status_sender, build_name_map: arguments.build_name_map.clone(), + print_build_logs: arguments.modifiers.print_build_logs, }; tokio::task::spawn_blocking(move || handle_pty_stdout(arguments)) diff --git a/crates/core/src/commands/pty/output.rs b/crates/core/src/commands/pty/output.rs index bcc8db5..8fb135c 100644 --- a/crates/core/src/commands/pty/output.rs +++ b/crates/core/src/commands/pty/output.rs @@ -32,6 +32,7 @@ pub(super) struct WatchStdoutArguments { pub span: Span, pub log_stdout: bool, pub build_name_map: BuildNameMap, + pub print_build_logs: bool, } /// Handles data from the PTY, and logs or prompts the user depending on the state @@ -52,6 +53,7 @@ pub(super) fn handle_pty_stdout(arguments: WatchStdoutArguments) -> Result<(), C status_sender, log_stdout, build_name_map, + print_build_logs, .. } = arguments; @@ -135,6 +137,7 @@ pub(super) fn handle_pty_stdout(arguments: WatchStdoutArguments) -> Result<(), C log_stdout, output_mode, &build_name_map, + print_build_logs, ); } } @@ -195,12 +198,13 @@ fn handle_normal_data( log_stdout: bool, output_mode: ChildOutputMode, build_name_map: &BuildNameMap, + print_build_logs: bool, ) { if line.starts_with(b"#") { let stripped = &mut line[1..]; if log_stdout { - output_mode.trace_slice(stripped, build_name_map); + output_mode.trace_slice(stripped, build_name_map, print_build_logs); } let mut queue = stdout_collection.lock().unwrap(); @@ -208,7 +212,7 @@ fn handle_normal_data( return; } - let log = output_mode.trace_slice(line, build_name_map); + let log = output_mode.trace_slice(line, build_name_map, print_build_logs); if let Some(error_msg) = log { let mut queue = stderr_collection.lock().unwrap(); diff --git a/crates/core/src/hive/executor.rs b/crates/core/src/hive/executor.rs index b6cbfd8..ec9b3ce 100644 --- a/crates/core/src/hive/executor.rs +++ b/crates/core/src/hive/executor.rs @@ -1,9 +1,9 @@ -use std::debug_assert_matches; use crate::{ SafeStorePath, hive::node::Step, status::{NodeStatus, UI_SENDER, UiMessage}, }; +use std::debug_assert_matches; use std::sync::Arc; use tracing::{Instrument, Span, debug, error, event, instrument}; @@ -143,14 +143,18 @@ pub async fn execute(mut plan: NodePlan) -> Result<(), HiveLibError> { #[cfg(test)] mod tests { use crate::{ - SubCommandModifiers, errors::HiveLibError, function_name, get_test_path, hive::{ + SubCommandModifiers, + errors::HiveLibError, + function_name, get_test_path, + hive::{ executor::execute, node::{ApplyGoal, HandleUnreachable, Name, Node, SwitchToConfigurationGoal}, plan::{ApplyGoalArgs, Goal, plan_for_node}, - }, location + }, + location, }; - use std::path::PathBuf; use std::assert_matches; + use std::path::PathBuf; use std::{ env, sync::{Arc, atomic::AtomicBool}, diff --git a/crates/core/src/hive/mod.rs b/crates/core/src/hive/mod.rs index 014c7a5..525d1df 100644 --- a/crates/core/src/hive/mod.rs +++ b/crates/core/src/hive/mod.rs @@ -300,8 +300,8 @@ mod tests { }; use super::*; - use std::env; use std::assert_matches; + use std::env; // flake should always come before hive.nix #[tokio::test]