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): add max supported EVM version in compiler -vv #9129

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 12 additions & 8 deletions crates/forge/bin/cmd/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{ArgAction, Parser, Subcommand, ValueHint};
use eyre::Result;
use foundry_compilers::Graph;
use foundry_compilers::{artifacts::EvmVersion, Graph};
use foundry_config::Config;
use semver::Version;
use std::{collections::BTreeMap, path::PathBuf};
Expand Down Expand Up @@ -67,10 +67,10 @@ impl ResolveArgs {
&project.compiler,
)?;

let mut output: BTreeMap<String, Vec<(Version, Vec<String>)>> = BTreeMap::new();
let mut output: BTreeMap<String, Vec<(Version, EvmVersion, Vec<String>)>> = BTreeMap::new();

for (language, sources) in sources {
let mut versions_with_paths: Vec<(Version, Vec<String>)> = sources
let mut versions_with_paths: Vec<(Version, EvmVersion, Vec<String>)> = sources
.iter()
.map(|(version, sources)| {
let paths: Vec<String> = sources
Expand All @@ -94,13 +94,17 @@ impl ResolveArgs {
})
.collect();

(version.clone(), paths)
(
version.clone(),
EvmVersion::default().normalize_version_solc(version).unwrap_or_default(),
paths,
)
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
})
.filter(|(_, paths)| !paths.is_empty())
.filter(|(_, _, paths)| !paths.is_empty())
.collect();

// Sort by SemVer version.
versions_with_paths.sort_by(|(v1, _), (v2, _)| Version::cmp(v1, v2));
versions_with_paths.sort_by(|(v1, _, _), (v2, _, _)| Version::cmp(v1, v2));

// Skip language if no paths are found after filtering.
if !versions_with_paths.is_empty() {
Expand All @@ -120,9 +124,9 @@ impl ResolveArgs {
println!("{language}:\n");
}

for (version, paths) in versions {
for (version, evm_version, paths) in versions {
if verbosity >= 1 {
println!("{version}:");
println!("{version} [Max supported EVM version: {evm_version}]:");
for (idx, path) in paths.iter().enumerate() {
if idx == paths.len() - 1 {
println!("└── {path}\n");
Expand Down
20 changes: 10 additions & 10 deletions crates/forge/tests/cli/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract ContractD {}
"#;

const VYPER_INTERFACE: &str = r#"
# pragma version 0.4.0
# pragma version >=0.4.0

@external
@view
Expand Down Expand Up @@ -94,7 +94,7 @@ forgetest!(can_list_resolved_compiler_versions_verbose, |prj, cmd| {
cmd.args(["compiler", "resolve", "-v"]).assert_success().stdout_eq(str![[r#"
Solidity:

0.8.27:
0.8.27 [Max supported EVM version: [..]]:
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
├── src/ContractC.sol
└── src/ContractD.sol

Expand All @@ -108,7 +108,7 @@ forgetest!(can_list_resolved_compiler_versions_json, |prj, cmd| {

cmd.args(["compiler", "resolve", "--json"]).assert_success().stdout_eq(
str![[r#"
{"Solidity":[["0.8.27",["src/ContractC.sol","src/ContractD.sol"]]]}"#]]
{"Solidity":[["0.8.27","[..]",["src/ContractC.sol","src/ContractD.sol"]]]}"#]]
.is_json(),
);
});
Expand Down Expand Up @@ -146,7 +146,7 @@ forgetest!(can_list_resolved_multiple_compiler_versions_skipped, |prj, cmd| {
r#"
Vyper:

0.4.0:
0.4.0 [Max supported EVM version: [..]]:
├── src/Counter.vy
└── src/ICounter.vyi

Expand All @@ -166,7 +166,7 @@ forgetest!(can_list_resolved_multiple_compiler_versions_skipped_json, |prj, cmd|
cmd.args(["compiler", "resolve", "--skip", "Contract(A|B|C)", "--json"])
.assert_success()
.stdout_eq(str![[r#"
{"Solidity":[["0.8.27",["src/ContractD.sol"]]],"Vyper":[["0.4.0",["src/Counter.vy","src/ICounter.vyi"]]]}
{"Solidity":[["0.8.27","[..]",["src/ContractD.sol"]]],"Vyper":[["0.4.0","[..]",["src/Counter.vy","src/ICounter.vyi"]]]}
"#]].is_json());
});

Expand All @@ -181,19 +181,19 @@ forgetest!(can_list_resolved_multiple_compiler_versions_verbose, |prj, cmd| {
cmd.args(["compiler", "resolve", "-v"]).assert_success().stdout_eq(str![[r#"
Solidity:

0.8.4:
0.8.4 [Max supported EVM version: istanbul]:
└── src/ContractA.sol

0.8.11:
0.8.11 [Max supported EVM version: london]:
└── src/ContractB.sol

0.8.27:
0.8.27 [Max supported EVM version: [..]]:
├── src/ContractC.sol
└── src/ContractD.sol

Vyper:

0.4.0:
0.4.0 [Max supported EVM version: [..]]:
├── src/Counter.vy
└── src/ICounter.vyi

Expand All @@ -211,7 +211,7 @@ forgetest!(can_list_resolved_multiple_compiler_versions_json, |prj, cmd| {

cmd.args(["compiler", "resolve", "--json"]).assert_success().stdout_eq(
str![[r#"
{"Solidity":[["0.8.4",["src/ContractA.sol"]],["0.8.11",["src/ContractB.sol"]],["0.8.27",["src/ContractC.sol","src/ContractD.sol"]]],"Vyper":[["0.4.0",["src/Counter.vy","src/ICounter.vyi"]]]}
{"Solidity":[["0.8.4","Istanbul",["src/ContractA.sol"]],["0.8.11","London",["src/ContractB.sol"]],["0.8.27","[..]",["src/ContractC.sol","src/ContractD.sol"]]],"Vyper":[["0.4.0","Cancun",["src/Counter.vy","src/ICounter.vyi"]]]}
"#]]
.is_json(),
);
Expand Down
Loading