Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl ProjectCompiler {
let quiet = self.quiet.unwrap_or(false);
let bail = self.bail.unwrap_or(true);

let output = with_compilation_reporter(quiet, || {
let output = with_compilation_reporter(quiet, Some(self.project_root.clone()), || {
tracing::debug!("compiling project");

let timer = Instant::now();
Expand Down Expand Up @@ -559,13 +559,17 @@ pub fn etherscan_project(metadata: &Metadata, target_path: &Path) -> Result<Proj
}

/// Configures the reporter and runs the given closure.
pub fn with_compilation_reporter<O>(quiet: bool, f: impl FnOnce() -> O) -> O {
pub fn with_compilation_reporter<O>(
quiet: bool,
project_root: Option<PathBuf>,
f: impl FnOnce() -> O,
) -> O {
#[expect(clippy::collapsible_else_if)]
let reporter = if quiet || shell::is_json() {
Report::new(NoReporter::default())
} else {
if std::io::stdout().is_terminal() {
Report::new(SpinnerReporter::spawn())
Report::new(SpinnerReporter::spawn(project_root))
} else {
Report::new(BasicStdoutReporter::default())
}
Expand Down
17 changes: 8 additions & 9 deletions crates/common/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use foundry_compilers::{
artifacts::remappings::Remapping,
report::{self, BasicStdoutReporter, Reporter},
};
use foundry_config::find_project_root;
use itertools::Itertools;
use semver::Version;
use std::{
Expand Down Expand Up @@ -94,6 +93,8 @@ impl Spinner {
pub struct SpinnerReporter {
/// The sender to the spinner thread.
sender: mpsc::Sender<SpinnerMsg>,
/// The project root path for trimming file paths in verbose output.
project_root: Option<PathBuf>,
}

impl SpinnerReporter {
Expand All @@ -102,7 +103,7 @@ impl SpinnerReporter {
/// The spinner's message will be updated via the `reporter` events
///
/// On drop the channel will disconnect and the thread will terminate
pub fn spawn() -> Self {
pub fn spawn(project_root: Option<PathBuf>) -> Self {
let (sender, rx) = mpsc::channel::<SpinnerMsg>();

std::thread::Builder::new()
Expand Down Expand Up @@ -130,7 +131,7 @@ impl SpinnerReporter {
})
.expect("failed to spawn thread");

Self { sender }
Self { sender, project_root }
}

fn send_msg(&self, msg: impl Into<String>) {
Expand All @@ -157,14 +158,12 @@ impl Reporter for SpinnerReporter {
// Verbose message with dirty files displays first to avoid being overlapped
// by the spinner in .tick() which prints repeatedly over the same line.
if shell::verbosity() >= 5 {
let project_root = find_project_root(None);

self.send_msg(format!(
"Files to compile:\n{}",
dirty_files
.iter()
.map(|path| {
let trimmed_path = if let Ok(project_root) = &project_root {
let trimmed_path = if let Some(project_root) = &self.project_root {
path.strip_prefix(project_root).unwrap_or(path)
} else {
path
Expand Down Expand Up @@ -214,9 +213,9 @@ impl Reporter for SpinnerReporter {
/// spinning cursor to display solc progress.
///
/// If no terminal is available this falls back to common `println!` in [`BasicStdoutReporter`].
pub fn with_spinner_reporter<T>(f: impl FnOnce() -> T) -> T {
pub fn with_spinner_reporter<T>(project_root: Option<PathBuf>, f: impl FnOnce() -> T) -> T {
let reporter = if TERM_SETTINGS.indicate_progress {
report::Report::new(SpinnerReporter::spawn())
report::Report::new(SpinnerReporter::spawn(project_root))
} else {
report::Report::new(BasicStdoutReporter::default())
};
Expand All @@ -240,7 +239,7 @@ mod tests {

#[test]
fn can_format_properly() {
let r = SpinnerReporter::spawn();
let r = SpinnerReporter::spawn(None);
let remappings: Vec<Remapping> = vec![
"library/=library/src/".parse().unwrap(),
"weird-erc20/=lib/weird-erc20/src/".parse().unwrap(),
Expand Down
5 changes: 3 additions & 2 deletions crates/forge/src/cmd/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ impl FlattenArgs {

let target_path = dunce::canonicalize(target_path)?;

let flattener =
with_compilation_reporter(true, || Flattener::new(project.clone(), &target_path));
let flattener = with_compilation_reporter(true, Some(project.root().to_path_buf()), || {
Flattener::new(project.clone(), &target_path)
});

let flattened = match flattener {
Ok(flattener) => Ok(flattener.flatten()),
Expand Down
Loading