@@ -7,12 +7,14 @@ use foundry_compilers::{
77} ;
88use foundry_config:: { Config , semver:: Version } ;
99use rayon:: prelude:: * ;
10- use solar:: sema:: ParsingContext ;
10+ use solar:: { interface :: MIN_SOLIDITY_VERSION as MSV , sema:: ParsingContext } ;
1111use std:: {
1212 collections:: { HashSet , VecDeque } ,
1313 path:: { Path , PathBuf } ,
1414} ;
1515
16+ const MIN_SUPPORTED_VERSION : Version = Version :: new ( MSV . 0 , MSV . 1 , MSV . 2 ) ;
17+
1618/// Configures a [`ParsingContext`] from [`Config`].
1719///
1820/// - Configures include paths, remappings
@@ -49,7 +51,7 @@ pub fn configure_pcx(
4951
5052 // Only process sources with latest Solidity version to avoid conflicts.
5153 let graph = Graph :: < MultiCompilerParser > :: resolve_sources ( & project. paths , sources) ?;
52- let ( version, sources, _ ) = graph
54+ let ( version, sources) = graph
5355 // Resolve graph into mapping language -> version -> sources
5456 . into_sources_by_version ( project) ?
5557 . sources
@@ -59,9 +61,15 @@ pub fn configure_pcx(
5961 . ok_or_else ( || eyre:: eyre!( "no Solidity sources" ) ) ?
6062 . 1
6163 . into_iter ( )
64+ // Filter unsupported versions
65+ . filter ( |( v, _, _) | v >= & MIN_SUPPORTED_VERSION )
6266 // Always pick the latest version
6367 . max_by ( |( v1, _, _) , ( v2, _, _) | v1. cmp ( v2) )
64- . unwrap ( ) ;
68+ . map_or ( ( MIN_SUPPORTED_VERSION , Sources :: default ( ) ) , |( v, s, _) | ( v, s) ) ;
69+
70+ if sources. is_empty ( ) {
71+ sh_warn ! ( "no files found. Solar doesn't support Solidity versions prior to 0.8.0" ) ?;
72+ }
6573
6674 let solc = SolcVersionedInput :: build (
6775 sources,
@@ -75,18 +83,17 @@ pub fn configure_pcx(
7583 Ok ( ( ) )
7684}
7785
78- /// Configures a [`ParsingContext`] from a [`ProjectCompileOutput`] and [`SolcVersionedInput `].
86+ /// Extracts Solar-compatible sources from a [`ProjectCompileOutput`].
7987///
8088/// # Note:
8189/// uses `output.graph().source_files()` and `output.artifact_ids()` rather than `output.sources()`
8290/// because sources aren't populated when build is skipped when there are no changes in the source
8391/// code. <https://github.com/foundry-rs/foundry/issues/12018>
84- pub fn configure_pcx_from_compile_output (
85- pcx : & mut ParsingContext < ' _ > ,
92+ pub fn get_solar_sources_from_compile_output (
8693 config : & Config ,
8794 output : & ProjectCompileOutput ,
8895 target_paths : Option < & [ PathBuf ] > ,
89- ) -> Result < ( ) > {
96+ ) -> Result < SolcVersionedInput > {
9097 let is_solidity_file = |path : & Path | -> bool {
9198 path. extension ( ) . and_then ( |s| s. to_str ( ) ) . is_some_and ( |ext| SOLC_EXTENSIONS . contains ( & ext) )
9299 } ;
@@ -125,12 +132,14 @@ pub fn configure_pcx_from_compile_output(
125132
126133 // Read all sources and find the latest version.
127134 let ( version, sources) = {
128- let ( mut max_version, mut sources) = ( Version :: new ( 0 , 0 , 0 ) , Sources :: new ( ) ) ;
135+ let ( mut max_version, mut sources) = ( MIN_SUPPORTED_VERSION , Sources :: new ( ) ) ;
129136 for ( id, _) in output. artifact_ids ( ) {
130137 if let Ok ( path) = dunce:: canonicalize ( & id. source )
131138 && source_paths. remove ( & path)
132139 {
133- if id. version > max_version {
140+ if id. version < MIN_SUPPORTED_VERSION {
141+ continue ;
142+ } else if max_version < id. version {
134143 max_version = id. version ;
135144 } ;
136145
@@ -149,6 +158,17 @@ pub fn configure_pcx_from_compile_output(
149158 version,
150159 ) ;
151160
161+ Ok ( solc)
162+ }
163+
164+ /// Configures a [`ParsingContext`] from a [`ProjectCompileOutput`].
165+ pub fn configure_pcx_from_compile_output (
166+ pcx : & mut ParsingContext < ' _ > ,
167+ config : & Config ,
168+ output : & ProjectCompileOutput ,
169+ target_paths : Option < & [ PathBuf ] > ,
170+ ) -> Result < ( ) > {
171+ let solc = get_solar_sources_from_compile_output ( config, output, target_paths) ?;
152172 configure_pcx_from_solc ( pcx, & config. project_paths ( ) , & solc, true ) ;
153173 Ok ( ( ) )
154174}
0 commit comments