Skip to content

Commit c714a0a

Browse files
authored
chore(forge eip712): use solar from compiler output (#11458)
* chore(forge eip712): use solar from compiler output * com * output * fix: actually select nothing
1 parent ffdc91b commit c714a0a

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

crates/config/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,15 @@ impl Config {
957957
self.create_project(false, true)
958958
}
959959

960+
/// Same as [`Self::ephemeral_project()`] but configures the project to not emit any artifacts.
961+
pub fn solar_project(&self) -> Result<Project<MultiCompiler>, SolcError> {
962+
let mut project = self.ephemeral_project()?;
963+
project.update_output_selection(|selection| {
964+
*selection = OutputSelection::common_output_selection([]);
965+
});
966+
Ok(project)
967+
}
968+
960969
/// Builds mapping with additional settings profiles.
961970
fn additional_settings(
962971
&self,

crates/forge/src/cmd/eip712.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
use alloy_primitives::{B256, keccak256};
22
use clap::{Parser, ValueHint};
33
use eyre::Result;
4-
use foundry_cli::{
5-
opts::{BuildOpts, configure_pcx},
6-
utils::LoadConfig,
7-
};
4+
use foundry_cli::{opts::BuildOpts, utils::LoadConfig};
5+
use foundry_common::compile::ProjectCompiler;
86
use serde::Serialize;
9-
use solar::{
10-
parse::interface::Session,
11-
sema::{
12-
Gcx, Hir,
13-
hir::StructId,
14-
ty::{Ty, TyKind},
15-
},
7+
use solar::sema::{
8+
Gcx, Hir,
9+
hir::StructId,
10+
ty::{Ty, TyKind},
1611
};
1712
use std::{
1813
collections::BTreeMap,
1914
fmt::{Display, Formatter, Result as FmtResult, Write},
2015
ops::ControlFlow,
2116
path::{Path, PathBuf},
22-
slice,
2317
};
2418

2519
foundry_config::impl_figment_convert!(Eip712Args, build);
@@ -58,18 +52,10 @@ impl Display for Eip712Output {
5852
impl Eip712Args {
5953
pub fn run(self) -> Result<()> {
6054
let config = self.build.load_config()?;
61-
62-
let mut sess = Session::builder().with_stderr_emitter().build();
63-
sess.dcx = sess.dcx.set_flags(|flags| flags.track_diagnostics = false);
64-
let mut compiler = solar::sema::Compiler::new(sess);
65-
55+
let project = config.solar_project()?;
56+
let mut output = ProjectCompiler::new().files([self.target_path]).compile(&project)?;
57+
let compiler = output.parser_mut().solc_mut().compiler_mut();
6658
compiler.enter_mut(|compiler| -> Result<()> {
67-
// Set up the parsing context with the project paths and sources.
68-
let mut pcx = compiler.parse();
69-
configure_pcx(&mut pcx, &config, None, Some(slice::from_ref(&self.target_path)))?;
70-
71-
// Parse and resolve
72-
pcx.parse();
7359
let Ok(ControlFlow::Continue(())) = compiler.lower_asts() else { return Ok(()) };
7460
let gcx = compiler.gcx();
7561
let resolver = Resolver::new(gcx);
@@ -97,7 +83,13 @@ impl Eip712Args {
9783
Ok(())
9884
})?;
9985

100-
eyre::ensure!(compiler.sess().dcx.has_errors().is_ok(), "errors occurred");
86+
// `compiler.sess()` inside of `ProjectCompileOutput` is built with `with_buffer_emitter`.
87+
let diags = compiler.sess().dcx.emitted_diagnostics().unwrap();
88+
if compiler.sess().dcx.has_errors().is_err() {
89+
eyre::bail!("{diags}");
90+
} else {
91+
let _ = sh_print!("{diags}");
92+
}
10193

10294
Ok(())
10395
}

crates/forge/tests/cli/eip712.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ library Structs2 {
5757

5858
cmd.forge_fuse().args(["eip712", path.to_string_lossy().as_ref()]).assert_success().stdout_eq(
5959
str![[r#"
60+
[COMPILING_FILES] with [SOLC_VERSION]
61+
[SOLC_VERSION] [ELAPSED]
62+
No files changed, compilation skipped
6063
Structs.sol > Structs > Foo:
6164
- type: Foo(Bar bar)Art(uint256 id)Bar(Art art)
6265
- hash: 0x6d9b732373bd999fde4072274c752e03f7437067dd75521eb406d8edf1d30f7d
@@ -179,6 +182,9 @@ library InsideLibrary {
179182

180183
cmd.forge_fuse().args(["eip712", path.to_string_lossy().as_ref()]).assert_success().stdout_eq(
181184
str![[r#"
185+
[COMPILING_FILES] with [SOLC_VERSION]
186+
[SOLC_VERSION] [ELAPSED]
187+
No files changed, compilation skipped
182188
FreeStanding:
183189
- type: FreeStanding(uint256 id,string name)
184190
- hash: 0xfb3c934b2382873277133498bde6eb3914ab323e3bef8b373ebcd423969bf1a2

0 commit comments

Comments
 (0)