@@ -33,8 +33,10 @@ use foundry_compilers::{
3333 Compiler ,
3434 } ,
3535 error:: SolcError ,
36+ multi:: { MultiCompilerParsedSource , MultiCompilerRestrictions } ,
3637 solc:: { CliSettings , SolcSettings } ,
37- ConfigurableArtifacts , Project , ProjectPathsConfig , VyperLanguage ,
38+ ConfigurableArtifacts , Graph , Project , ProjectPathsConfig , RestrictionsWithVersion ,
39+ VyperLanguage ,
3840} ;
3941use inflector:: Inflector ;
4042use regex:: Regex ;
@@ -43,7 +45,7 @@ use semver::Version;
4345use serde:: { Deserialize , Serialize , Serializer } ;
4446use std:: {
4547 borrow:: Cow ,
46- collections:: HashMap ,
48+ collections:: { BTreeMap , HashMap } ,
4749 fs,
4850 path:: { Path , PathBuf } ,
4951 str:: FromStr ,
@@ -115,6 +117,9 @@ use vyper::VyperConfig;
115117mod bind_json;
116118use bind_json:: BindJsonConfig ;
117119
120+ mod compilation;
121+ use compilation:: { CompilationRestrictions , SettingsOverrides } ;
122+
118123/// Foundry configuration
119124///
120125/// # Defaults
@@ -469,6 +474,14 @@ pub struct Config {
469474 #[ serde( rename = "__warnings" , default , skip_serializing) ]
470475 pub warnings : Vec < Warning > ,
471476
477+ /// Additional settings profiles to use when compiling.
478+ #[ serde( default ) ]
479+ pub additional_compiler_profiles : Vec < SettingsOverrides > ,
480+
481+ /// Restrictions on compilation of certain files.
482+ #[ serde( default ) ]
483+ pub compilation_restrictions : Vec < CompilationRestrictions > ,
484+
472485 /// PRIVATE: This structure may grow, As such, constructing this structure should
473486 /// _always_ be done using a public constructor or update syntax:
474487 ///
@@ -835,12 +848,65 @@ impl Config {
835848 self . create_project ( false , true )
836849 }
837850
851+ /// Builds mapping with additional settings profiles.
852+ fn additional_settings (
853+ & self ,
854+ base : & MultiCompilerSettings ,
855+ ) -> BTreeMap < String , MultiCompilerSettings > {
856+ let mut map = BTreeMap :: new ( ) ;
857+
858+ for profile in & self . additional_compiler_profiles {
859+ let mut settings = base. clone ( ) ;
860+ profile. apply ( & mut settings) ;
861+ map. insert ( profile. name . clone ( ) , settings) ;
862+ }
863+
864+ map
865+ }
866+
867+ /// Resolves globs and builds a mapping from individual source files to their restrictions
868+ fn restrictions (
869+ & self ,
870+ paths : & ProjectPathsConfig ,
871+ ) -> Result < BTreeMap < PathBuf , RestrictionsWithVersion < MultiCompilerRestrictions > > , SolcError >
872+ {
873+ let mut map = BTreeMap :: new ( ) ;
874+
875+ let graph = Graph :: < MultiCompilerParsedSource > :: resolve ( paths) ?;
876+ let ( sources, _) = graph. into_sources ( ) ;
877+
878+ for res in & self . compilation_restrictions {
879+ for source in sources. keys ( ) . filter ( |path| {
880+ if res. paths . is_match ( path) {
881+ true
882+ } else if let Ok ( path) = path. strip_prefix ( & paths. root ) {
883+ res. paths . is_match ( path)
884+ } else {
885+ false
886+ }
887+ } ) {
888+ let res: RestrictionsWithVersion < _ > = res. clone ( ) . into ( ) ;
889+ if !map. contains_key ( source) {
890+ map. insert ( source. clone ( ) , res) ;
891+ } else {
892+ map. get_mut ( source. as_path ( ) ) . unwrap ( ) . merge ( res) ;
893+ }
894+ }
895+ }
896+
897+ Ok ( map)
898+ }
899+
838900 /// Creates a [Project] with the given `cached` and `no_artifacts` flags
839901 pub fn create_project ( & self , cached : bool , no_artifacts : bool ) -> Result < Project , SolcError > {
902+ let settings = self . compiler_settings ( ) ?;
903+ let paths = self . project_paths ( ) ;
840904 let mut builder = Project :: builder ( )
841905 . artifacts ( self . configured_artifacts_handler ( ) )
842- . paths ( self . project_paths ( ) )
843- . settings ( self . compiler_settings ( ) ?)
906+ . additional_settings ( self . additional_settings ( & settings) )
907+ . restrictions ( self . restrictions ( & paths) ?)
908+ . settings ( settings)
909+ . paths ( paths)
844910 . ignore_error_codes ( self . ignored_error_codes . iter ( ) . copied ( ) . map ( Into :: into) )
845911 . ignore_paths ( self . ignored_file_paths . clone ( ) )
846912 . set_compiler_severity_filter ( if self . deny_warnings {
@@ -2182,6 +2248,8 @@ impl Default for Config {
21822248 eof_version : None ,
21832249 alphanet : false ,
21842250 transaction_timeout : 120 ,
2251+ additional_compiler_profiles : Default :: default ( ) ,
2252+ compilation_restrictions : vec ! [ ] ,
21852253 _non_exhaustive : ( ) ,
21862254 }
21872255 }
0 commit comments