Skip to content

Commit

Permalink
feat(forge): new flatten implementation (#6936)
Browse files Browse the repository at this point in the history
* Update Flatten impl

* Bump foundry-compilers

* fix error handling

* Update crates/forge/bin/cmd/flatten.rs

Co-authored-by: DaniPopes <[email protected]>

* error handling

* Bump compilers and block-explorers

* Simplify compilation

* fmt

* fix doc

* use patch

* bump compilers

---------

Co-authored-by: DaniPopes <[email protected]>
  • Loading branch information
klkvr and DaniPopes authored Feb 2, 2024
1 parent 84d9842 commit e2d3278
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
12 changes: 4 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ foundry-macros = { path = "crates/macros" }
foundry-test-utils = { path = "crates/test-utils" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.2.0", default-features = false }
foundry-compilers = { version = "0.2.4", default-features = false }
foundry-block-explorers = { version = "0.2.3", default-features = false }
foundry-compilers = { version = "0.3.1", default-features = false }

## revm
# no default features to avoid c-kzg
Expand Down Expand Up @@ -226,4 +226,4 @@ revm-primitives = { git = "https://github.com/bluealloy/revm", branch = "reth_fr
revm-interpreter = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" }
revm-precompile = { git = "https://github.com/bluealloy/revm", branch = "reth_freeze" }

revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors" }
23 changes: 19 additions & 4 deletions crates/forge/bin/cmd/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use foundry_cli::{
opts::{CoreBuildArgs, ProjectPathsArgs},
utils::LoadConfig,
};
use foundry_common::fs;
use foundry_common::{compile::ProjectCompiler, fs};
use foundry_compilers::{error::SolcError, flatten::Flattener};
use std::path::PathBuf;

/// CLI arguments for `forge flatten`.
Expand Down Expand Up @@ -38,10 +39,24 @@ impl FlattenArgs {

let config = build_args.try_load_config_emit_warnings()?;

let paths = config.project_paths();
let target_path = dunce::canonicalize(target_path)?;
let flattened =
paths.flatten(&target_path).map_err(|err| eyre::eyre!("Failed to flatten: {err}"))?;

let project = config.ephemeral_no_artifacts_project()?;

let compiler_output = ProjectCompiler::new().files([target_path.clone()]).compile(&project);

let flattened = match compiler_output {
Ok(compiler_output) => {
Flattener::new(&project, &compiler_output, &target_path).map(|f| f.flatten())
}
Err(_) => {
// Fallback to the old flattening implementation if we couldn't compile the target
// successfully. This would be the case if the target has invalid
// syntax. (e.g. Solang)
project.paths.flatten(&target_path)
}
}
.map_err(|err: SolcError| eyre::eyre!("Failed to flatten: {err}"))?;

match output {
Some(output) => {
Expand Down

0 comments on commit e2d3278

Please sign in to comment.