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

refactor: rewrite compile functions to a common builder #6702

Merged
merged 6 commits into from
Jan 4, 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
1 change: 0 additions & 1 deletion crates/cast/bin/cmd/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct AccessListArgs {
#[clap(
long,
value_name = "DATA",
value_parser = foundry_common::clap_helpers::strip_0x_prefix,
conflicts_with_all = &["sig", "args"]
)]
data: Option<String>,
Expand Down
1 change: 0 additions & 1 deletion crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct CallArgs {
/// Data for the transaction.
#[clap(
long,
value_parser = foundry_common::clap_helpers::strip_0x_prefix,
conflicts_with_all = &["sig", "args"]
)]
data: Option<String>,
Expand Down
8 changes: 4 additions & 4 deletions crates/cast/bin/cmd/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use foundry_cli::{
};
use foundry_common::{
abi::find_source,
compile::{compile, etherscan_project, suppress_compile},
compile::{etherscan_project, ProjectCompiler},
types::{ToAlloy, ToEthers},
RetryProvider,
};
Expand Down Expand Up @@ -100,7 +100,7 @@ impl StorageArgs {
if project.paths.has_input_files() {
// Find in artifacts and pretty print
add_storage_layout_output(&mut project);
let out = compile(&project, false, false)?;
let out = ProjectCompiler::new().compile(&project)?;
let match_code = |artifact: &ConfigurableContractArtifact| -> Option<bool> {
let bytes =
artifact.deployed_bytecode.as_ref()?.bytecode.as_ref()?.object.as_bytes()?;
Expand Down Expand Up @@ -146,7 +146,7 @@ impl StorageArgs {
project.auto_detect = auto_detect;

// Compile
let mut out = suppress_compile(&project)?;
let mut out = ProjectCompiler::new().quiet(true).compile(&project)?;
let artifact = {
let (_, mut artifact) = out
.artifacts()
Expand All @@ -159,7 +159,7 @@ impl StorageArgs {
let solc = Solc::find_or_install_svm_version(MIN_SOLC.to_string())?;
project.solc = solc;
project.auto_detect = false;
if let Ok(output) = suppress_compile(&project) {
if let Ok(output) = ProjectCompiler::new().quiet(true).compile(&project) {
out = output;
let (_, new_artifact) = out
.artifacts()
Expand Down
5 changes: 1 addition & 4 deletions crates/cast/bin/cmd/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ pub enum WalletSubcommands {
#[clap(visible_aliases = &["a", "addr"])]
Address {
/// If provided, the address will be derived from the specified private key.
#[clap(
value_name = "PRIVATE_KEY",
value_parser = foundry_common::clap_helpers::strip_0x_prefix,
)]
#[clap(value_name = "PRIVATE_KEY")]
private_key_override: Option<String>,

#[clap(flatten)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use opts::{Opts, Subcommands, ToBaseArgs};

#[tokio::main]
async fn main() -> Result<()> {
handler::install()?;
handler::install();
utils::load_dotenv();
utils::subscriber();
utils::enable_paint();
Expand Down
17 changes: 9 additions & 8 deletions crates/cast/bin/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ const VERSION_MESSAGE: &str = concat!(
")"
);

#[derive(Debug, Parser)]
#[clap(name = "cast", version = VERSION_MESSAGE)]
/// Perform Ethereum RPC calls from the comfort of your command line.
#[derive(Parser)]
#[clap(
name = "cast",
version = VERSION_MESSAGE,
after_help = "Find more information in the book: http://book.getfoundry.sh/reference/cast/cast.html",
next_display_order = None,
)]
pub struct Opts {
#[clap(subcommand)]
pub sub: Subcommands,
}

/// Perform Ethereum RPC calls from the comfort of your command line.
#[derive(Debug, Subcommand)]
#[clap(
after_help = "Find more information in the book: http://book.getfoundry.sh/reference/cast/cast.html",
next_display_order = None
)]
#[derive(Subcommand)]
pub enum Subcommands {
/// Prints the maximum value of the given integer type.
#[clap(visible_aliases = &["--max-int", "maxi"])]
Expand Down
10 changes: 5 additions & 5 deletions crates/cast/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ impl FromStr for Base {
"10" | "d" | "dec" | "decimal" => Ok(Self::Decimal),
"16" | "h" | "hex" | "hexadecimal" => Ok(Self::Hexadecimal),
s => Err(eyre::eyre!(
r#"Invalid base "{}". Possible values:
2, b, bin, binary
8, o, oct, octal
"\
Invalid base \"{s}\". Possible values:
2, b, bin, binary
8, o, oct, octal
10, d, dec, decimal
16, h, hex, hexadecimal"#,
s
16, h, hex, hexadecimal"
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/chisel/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum ChiselParserSub {

#[tokio::main]
async fn main() -> eyre::Result<()> {
handler::install()?;
handler::install();
utils::subscriber();
#[cfg(windows)]
if !Paint::enable_windows_ascii() {
Expand Down
7 changes: 2 additions & 5 deletions crates/cli/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eyre::{EyreHandler, Result};
use eyre::EyreHandler;
use std::error::Error;
use yansi::Paint;

Expand Down Expand Up @@ -47,9 +47,8 @@ impl EyreHandler for Handler {
/// verbose debug-centric handler is installed.
///
/// Panics are always caught by the more debug-centric handler.
pub fn install() -> Result<()> {
pub fn install() {
let debug_enabled = std::env::var("FOUNDRY_DEBUG").is_ok();

if debug_enabled {
if let Err(e) = color_eyre::install() {
debug!("failed to install color eyre error hook: {e}");
Expand All @@ -65,6 +64,4 @@ pub fn install() -> Result<()> {
debug!("failed to install eyre error hook: {e}");
}
}

Ok(())
}
6 changes: 1 addition & 5 deletions crates/cli/src/opts/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ pub struct RawWallet {
pub interactive: bool,

/// Use the provided private key.
#[clap(
long,
value_name = "RAW_PRIVATE_KEY",
value_parser = foundry_common::clap_helpers::strip_0x_prefix
mattsse marked this conversation as resolved.
Show resolved Hide resolved
)]
#[clap(long, value_name = "RAW_PRIVATE_KEY")]
pub private_key: Option<String>,

/// Use the mnemonic phrase of mnemonic file at the specified path.
Expand Down
10 changes: 2 additions & 8 deletions crates/cli/src/opts/wallet/multi_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,15 @@ pub struct MultiWallet {
pub interactives: u32,

/// Use the provided private keys.
#[clap(
long,
help_heading = "Wallet options - raw",
value_name = "RAW_PRIVATE_KEYS",
value_parser = foundry_common::clap_helpers::strip_0x_prefix,
)]
#[clap(long, help_heading = "Wallet options - raw", value_name = "RAW_PRIVATE_KEYS")]
pub private_keys: Option<Vec<String>>,

/// Use the provided private key.
#[clap(
long,
help_heading = "Wallet options - raw",
conflicts_with = "private_keys",
value_name = "RAW_PRIVATE_KEY",
value_parser = foundry_common::clap_helpers::strip_0x_prefix,
value_name = "RAW_PRIVATE_KEY"
)]
pub private_key: Option<String>,

Expand Down
6 changes: 0 additions & 6 deletions crates/common/src/clap_helpers.rs

This file was deleted.

Loading
Loading