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-cli): Add --no-metadata as CLI compiler option #7684

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ pub struct CoreBuildArgs {
#[serde(skip)]
pub via_ir: bool,

/// Whether to append the metadata hash to the bytecode.
/// This is equivalent to setting [Config::bytecode_hash] to `none` and
/// [Config::cbor_metadata] to `false`.
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long, help_heading = "Compiler options")]
#[serde(skip)]
pub no_metadata: bool,

/// The path to the contract artifacts folder.
#[arg(
long = "out",
Expand Down Expand Up @@ -204,9 +211,15 @@ impl Provider for CoreBuildArgs {
dict.insert("via_ir".to_string(), true.into());
}

if self.no_metadata {
dict.insert("bytecode_hash".to_string(), "none".into());
dict.insert("cbor_metadata".to_string(), false.into());
}

if self.force {
dict.insert("force".to_string(), self.force.into());
}

// we need to ensure no_cache set accordingly
if self.no_cache {
dict.insert("cache".to_string(), false.into());
Expand Down
6 changes: 4 additions & 2 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_primitives::{Address, B256, U256};
use foundry_cli::utils as forge_utils;
use foundry_compilers::artifacts::{OptimizerDetails, RevertStrings, YulDetails};
use foundry_compilers::artifacts::{BytecodeHash, OptimizerDetails, RevertStrings, YulDetails};
use foundry_config::{
cache::{CachedChains, CachedEndpoints, StorageCachingConfig},
fs_permissions::{FsAccessPermission, PathPermission},
Expand Down Expand Up @@ -305,8 +305,10 @@ forgetest_init!(can_get_evm_opts, |prj, _cmd| {

// checks that we can set various config values
forgetest_init!(can_set_config_values, |prj, _cmd| {
let config = prj.config_from_output(["--via-ir"]);
let config = prj.config_from_output(["--via-ir", "--no-metadata"]);
assert!(config.via_ir);
assert_eq!(config.cbor_metadata, false);
assert_eq!(config.bytecode_hash, BytecodeHash::None);
});

// tests that solc can be explicitly set
Expand Down
Loading