@@ -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
@@ -451,6 +456,14 @@ pub struct Config {
451456 #[ serde( rename = "__warnings" , default , skip_serializing) ]
452457 pub warnings : Vec < Warning > ,
453458
459+ /// Additional settings profiles to use when compiling.
460+ #[ serde( default ) ]
461+ pub additional_compiler_profiles : BTreeMap < String , SettingsOverrides > ,
462+
463+ /// Restrictions on compilation of certain files.
464+ #[ serde( default ) ]
465+ pub compilation_restrictions : Vec < CompilationRestrictions > ,
466+
454467 /// PRIVATE: This structure may grow, As such, constructing this structure should
455468 /// _always_ be done using a public constructor or update syntax:
456469 ///
@@ -816,12 +829,65 @@ impl Config {
816829 self . create_project ( false , true )
817830 }
818831
832+ /// Builds mapping with additional settings profiles.
833+ fn additional_settings (
834+ & self ,
835+ base : & MultiCompilerSettings ,
836+ ) -> BTreeMap < String , MultiCompilerSettings > {
837+ let mut map = BTreeMap :: new ( ) ;
838+
839+ for ( name, profile) in & self . additional_compiler_profiles {
840+ let mut settings = base. clone ( ) ;
841+ profile. apply ( & mut settings) ;
842+ map. insert ( name. clone ( ) , settings) ;
843+ }
844+
845+ map
846+ }
847+
848+ /// Resolves globs and builds a mapping from individual source files to their restrictions
849+ fn restrictions (
850+ & self ,
851+ paths : & ProjectPathsConfig ,
852+ ) -> Result < BTreeMap < PathBuf , RestrictionsWithVersion < MultiCompilerRestrictions > > , SolcError >
853+ {
854+ let mut map = BTreeMap :: new ( ) ;
855+
856+ let graph = Graph :: < MultiCompilerParsedSource > :: resolve ( paths) ?;
857+ let ( sources, _) = graph. into_sources ( ) ;
858+
859+ for res in & self . compilation_restrictions {
860+ for source in sources. keys ( ) . filter ( |path| {
861+ if res. paths . is_match ( path) {
862+ true
863+ } else if let Ok ( path) = path. strip_prefix ( & paths. root ) {
864+ res. paths . is_match ( path)
865+ } else {
866+ false
867+ }
868+ } ) {
869+ let res: RestrictionsWithVersion < _ > = res. clone ( ) . into ( ) ;
870+ if !map. contains_key ( source) {
871+ map. insert ( source. clone ( ) , res) ;
872+ } else {
873+ map. get_mut ( source. as_path ( ) ) . unwrap ( ) . merge ( res) ;
874+ }
875+ }
876+ }
877+
878+ Ok ( map)
879+ }
880+
819881 /// Creates a [Project] with the given `cached` and `no_artifacts` flags
820882 pub fn create_project ( & self , cached : bool , no_artifacts : bool ) -> Result < Project , SolcError > {
883+ let settings = self . compiler_settings ( ) ?;
884+ let paths = self . project_paths ( ) ;
821885 let mut builder = Project :: builder ( )
822886 . artifacts ( self . configured_artifacts_handler ( ) )
823- . paths ( self . project_paths ( ) )
824- . settings ( self . compiler_settings ( ) ?)
887+ . additional_settings ( self . additional_settings ( & settings) )
888+ . restrictions ( self . restrictions ( & paths) ?)
889+ . settings ( settings)
890+ . paths ( paths)
825891 . ignore_error_codes ( self . ignored_error_codes . iter ( ) . copied ( ) . map ( Into :: into) )
826892 . ignore_paths ( self . ignored_file_paths . clone ( ) )
827893 . set_compiler_severity_filter ( if self . deny_warnings {
@@ -2139,6 +2205,8 @@ impl Default for Config {
21392205 warnings : vec ! [ ] ,
21402206 extra_args : vec ! [ ] ,
21412207 eof_version : None ,
2208+ additional_compiler_profiles : Default :: default ( ) ,
2209+ compilation_restrictions : vec ! [ ] ,
21422210 _non_exhaustive : ( ) ,
21432211 }
21442212 }
0 commit comments