|
1 | 1 | use alloy_primitives::{B256, keccak256};
|
2 | 2 | use clap::{Parser, ValueHint};
|
3 | 3 | 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; |
8 | 6 | 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}, |
16 | 11 | };
|
17 | 12 | use std::{
|
18 | 13 | collections::BTreeMap,
|
19 | 14 | fmt::{Display, Formatter, Result as FmtResult, Write},
|
20 | 15 | ops::ControlFlow,
|
21 | 16 | path::{Path, PathBuf},
|
22 |
| - slice, |
23 | 17 | };
|
24 | 18 |
|
25 | 19 | foundry_config::impl_figment_convert!(Eip712Args, build);
|
@@ -58,18 +52,10 @@ impl Display for Eip712Output {
|
58 | 52 | impl Eip712Args {
|
59 | 53 | pub fn run(self) -> Result<()> {
|
60 | 54 | 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(); |
66 | 58 | 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(); |
73 | 59 | let Ok(ControlFlow::Continue(())) = compiler.lower_asts() else { return Ok(()) };
|
74 | 60 | let gcx = compiler.gcx();
|
75 | 61 | let resolver = Resolver::new(gcx);
|
@@ -97,7 +83,13 @@ impl Eip712Args {
|
97 | 83 | Ok(())
|
98 | 84 | })?;
|
99 | 85 |
|
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 | + } |
101 | 93 |
|
102 | 94 | Ok(())
|
103 | 95 | }
|
|
0 commit comments