Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): new flatten implementation #6936

Merged
merged 11 commits into from
Feb 2, 2024
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
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 @@ -124,8 +124,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 @@ -222,4 +222,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}"))?;
DaniPopes marked this conversation as resolved.
Show resolved Hide resolved

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