Skip to content
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
9 changes: 9 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,15 @@ impl Config {
self.create_project(false, true)
}

/// Same as [`Self::ephemeral_project()`] but configures the project to not emit any artifacts.
pub fn solar_project(&self) -> Result<Project<MultiCompiler>, SolcError> {
let mut project = self.ephemeral_project()?;
project.update_output_selection(|selection| {
*selection = OutputSelection::common_output_selection([]);
});
Ok(project)
}

/// Builds mapping with additional settings profiles.
fn additional_settings(
&self,
Expand Down
40 changes: 16 additions & 24 deletions crates/forge/src/cmd/eip712.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use alloy_primitives::{B256, keccak256};
use clap::{Parser, ValueHint};
use eyre::Result;
use foundry_cli::{
opts::{BuildOpts, configure_pcx},
utils::LoadConfig,
};
use foundry_cli::{opts::BuildOpts, utils::LoadConfig};
use foundry_common::compile::ProjectCompiler;
use serde::Serialize;
use solar::{
parse::interface::Session,
sema::{
Gcx, Hir,
hir::StructId,
ty::{Ty, TyKind},
},
use solar::sema::{
Gcx, Hir,
hir::StructId,
ty::{Ty, TyKind},
};
use std::{
collections::BTreeMap,
fmt::{Display, Formatter, Result as FmtResult, Write},
ops::ControlFlow,
path::{Path, PathBuf},
slice,
};

foundry_config::impl_figment_convert!(Eip712Args, build);
Expand Down Expand Up @@ -58,18 +52,10 @@ impl Display for Eip712Output {
impl Eip712Args {
pub fn run(self) -> Result<()> {
let config = self.build.load_config()?;

let mut sess = Session::builder().with_stderr_emitter().build();
sess.dcx = sess.dcx.set_flags(|flags| flags.track_diagnostics = false);
let mut compiler = solar::sema::Compiler::new(sess);

let project = config.solar_project()?;
let mut output = ProjectCompiler::new().files([self.target_path]).compile(&project)?;
let compiler = output.parser_mut().solc_mut().compiler_mut();
compiler.enter_mut(|compiler| -> Result<()> {
// Set up the parsing context with the project paths and sources.
let mut pcx = compiler.parse();
configure_pcx(&mut pcx, &config, None, Some(slice::from_ref(&self.target_path)))?;

// Parse and resolve
pcx.parse();
let Ok(ControlFlow::Continue(())) = compiler.lower_asts() else { return Ok(()) };
let gcx = compiler.gcx();
let resolver = Resolver::new(gcx);
Expand Down Expand Up @@ -97,7 +83,13 @@ impl Eip712Args {
Ok(())
})?;

eyre::ensure!(compiler.sess().dcx.has_errors().is_ok(), "errors occurred");
// `compiler.sess()` inside of `ProjectCompileOutput` is built with `with_buffer_emitter`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// `compiler.sess()` inside of `ProjectCompileOutput` is built with `with_buffer_emitter`.
// SAFETY: `compiler.sess()` inside of `ProjectCompileOutput` is built with `with_buffer_emitter`.

i find the preamble useful for context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAFETY should only be used for unsafe

let diags = compiler.sess().dcx.emitted_diagnostics().unwrap();
if compiler.sess().dcx.has_errors().is_err() {
eyre::bail!("{diags}");
} else {
let _ = sh_print!("{diags}");
}

Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions crates/forge/tests/cli/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ library Structs2 {

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

cmd.forge_fuse().args(["eip712", path.to_string_lossy().as_ref()]).assert_success().stdout_eq(
str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
No files changed, compilation skipped
FreeStanding:
- type: FreeStanding(uint256 id,string name)
- hash: 0xfb3c934b2382873277133498bde6eb3914ab323e3bef8b373ebcd423969bf1a2
Expand Down
Loading