@@ -168,6 +168,14 @@ pub struct Config {
168168 /// See `profile`.
169169 #[ serde( skip) ]
170170 pub profiles : Vec < Profile > ,
171+
172+ /// The root path where the config detection started from, [`Config::with_root`].
173+ // We're skipping serialization here, so it won't be included in the [`Config::to_string()`]
174+ // representation, but will be deserialized from the `Figment` so that forge commands can
175+ // override it.
176+ #[ serde( default = "root_default" , skip_serializing) ]
177+ pub root : PathBuf ,
178+
171179 /// path of the source contracts dir, like `src` or `contracts`
172180 pub src : PathBuf ,
173181 /// path of the test dir
@@ -466,13 +474,6 @@ pub struct Config {
466474 /// Soldeer custom configs
467475 pub soldeer : Option < SoldeerConfig > ,
468476
469- /// The root path where the config detection started from, [`Config::with_root`].
470- // We're skipping serialization here, so it won't be included in the [`Config::to_string()`]
471- // representation, but will be deserialized from the `Figment` so that forge commands can
472- // override it.
473- #[ serde( default , skip_serializing) ]
474- pub root : RootPath ,
475-
476477 /// Whether failed assertions should revert.
477478 ///
478479 /// Note that this only applies to native (cheatcode) assertions, invoked on Vm contract.
@@ -679,7 +680,7 @@ impl Config {
679680 return Figment :: from ( self ) ;
680681 }
681682
682- let root = self . root . 0 . as_path ( ) ;
683+ let root = self . root . as_path ( ) ;
683684 let profile = Self :: selected_profile ( ) ;
684685 let mut figment = Figment :: default ( ) . merge ( DappHardhatDirProvider ( root) ) ;
685686
@@ -760,7 +761,7 @@ impl Config {
760761 /// This joins all relative paths with the current root and attempts to make them canonic
761762 #[ must_use]
762763 pub fn canonic ( self ) -> Self {
763- let root = self . root . 0 . clone ( ) ;
764+ let root = self . root . clone ( ) ;
764765 self . canonic_at ( root)
765766 }
766767
@@ -1006,7 +1007,7 @@ impl Config {
10061007 . set_no_artifacts ( no_artifacts) ;
10071008
10081009 if !self . skip . is_empty ( ) {
1009- let filter = SkipBuildFilters :: new ( self . skip . clone ( ) , self . root . 0 . clone ( ) ) ;
1010+ let filter = SkipBuildFilters :: new ( self . skip . clone ( ) , self . root . clone ( ) ) ;
10101011 builder = builder. sparse_output ( filter) ;
10111012 }
10121013
@@ -1057,7 +1058,7 @@ impl Config {
10571058 fn ensure_solc ( & self ) -> Result < Option < Solc > , SolcError > {
10581059 if self . eof {
10591060 let ( tx, rx) = mpsc:: channel ( ) ;
1060- let root = self . root . 0 . clone ( ) ;
1061+ let root = self . root . clone ( ) ;
10611062 std:: thread:: spawn ( move || {
10621063 tx. send (
10631064 Solc :: new_with_args (
@@ -1167,7 +1168,7 @@ impl Config {
11671168 . artifacts ( & self . out )
11681169 . libs ( self . libs . iter ( ) )
11691170 . remappings ( self . get_all_remappings ( ) )
1170- . allowed_path ( & self . root . 0 )
1171+ . allowed_path ( & self . root )
11711172 . allowed_paths ( & self . libs )
11721173 . allowed_paths ( & self . allow_paths )
11731174 . include_paths ( & self . include_paths ) ;
@@ -1176,7 +1177,7 @@ impl Config {
11761177 builder = builder. build_infos ( build_info_path) ;
11771178 }
11781179
1179- builder. build_with_root ( & self . root . 0 )
1180+ builder. build_with_root ( & self . root )
11801181 }
11811182
11821183 /// Returns configuration for a compiler to use when setting up a [Project].
@@ -1428,7 +1429,7 @@ impl Config {
14281429
14291430 /// Returns the remapping for the project's _test_ directory, but only if it exists
14301431 pub fn get_test_dir_remapping ( & self ) -> Option < Remapping > {
1431- if self . root . 0 . join ( & self . test ) . exists ( ) {
1432+ if self . root . join ( & self . test ) . exists ( ) {
14321433 get_dir_remapping ( & self . test )
14331434 } else {
14341435 None
@@ -1437,7 +1438,7 @@ impl Config {
14371438
14381439 /// Returns the remapping for the project's _script_ directory, but only if it exists
14391440 pub fn get_script_dir_remapping ( & self ) -> Option < Remapping > {
1440- if self . root . 0 . join ( & self . script ) . exists ( ) {
1441+ if self . root . join ( & self . script ) . exists ( ) {
14411442 get_dir_remapping ( & self . script )
14421443 } else {
14431444 None
@@ -1615,7 +1616,7 @@ impl Config {
16151616 let paths = ProjectPathsConfig :: builder ( ) . build_with_root :: < ( ) > ( root) ;
16161617 let artifacts: PathBuf = paths. artifacts . file_name ( ) . unwrap ( ) . into ( ) ;
16171618 Self {
1618- root : paths. root . into ( ) ,
1619+ root : paths. root ,
16191620 src : paths. sources . file_name ( ) . unwrap ( ) . into ( ) ,
16201621 out : artifacts. clone ( ) ,
16211622 libs : paths. libraries . into_iter ( ) . map ( |lib| lib. file_name ( ) . unwrap ( ) . into ( ) ) . collect ( ) ,
@@ -1707,7 +1708,7 @@ impl Config {
17071708 pub fn update_libs ( & self ) -> eyre:: Result < ( ) > {
17081709 self . update ( |doc| {
17091710 let profile = self . profile . as_str ( ) . as_str ( ) ;
1710- let root = & self . root . 0 ;
1711+ let root = & self . root ;
17111712 let libs: toml_edit:: Value = self
17121713 . libs
17131714 . iter ( )
@@ -1764,7 +1765,7 @@ impl Config {
17641765
17651766 /// Returns the path to the `foundry.toml` of this `Config`.
17661767 pub fn get_config_path ( & self ) -> PathBuf {
1767- self . root . 0 . join ( Self :: FILE_NAME )
1768+ self . root . join ( Self :: FILE_NAME )
17681769 }
17691770
17701771 /// Returns the selected profile.
@@ -2211,43 +2212,6 @@ pub(crate) mod from_opt_glob {
22112212 }
22122213}
22132214
2214- /// A helper wrapper around the root path used during Config detection
2215- #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , Serialize , Deserialize ) ]
2216- #[ serde( transparent) ]
2217- pub struct RootPath ( pub PathBuf ) ;
2218-
2219- impl Default for RootPath {
2220- fn default ( ) -> Self {
2221- "." . into ( )
2222- }
2223- }
2224-
2225- impl < P : Into < PathBuf > > From < P > for RootPath {
2226- fn from ( p : P ) -> Self {
2227- Self ( p. into ( ) )
2228- }
2229- }
2230-
2231- impl AsRef < Path > for RootPath {
2232- fn as_ref ( & self ) -> & Path {
2233- & self . 0
2234- }
2235- }
2236-
2237- impl std:: ops:: Deref for RootPath {
2238- type Target = PathBuf ;
2239-
2240- fn deref ( & self ) -> & Self :: Target {
2241- & self . 0
2242- }
2243- }
2244-
2245- impl std:: ops:: DerefMut for RootPath {
2246- fn deref_mut ( & mut self ) -> & mut Self :: Target {
2247- & mut self . 0
2248- }
2249- }
2250-
22512215/// Parses a config profile
22522216///
22532217/// All `Profile` date is ignored by serde, however the `Config::to_string_pretty` includes it and
@@ -2299,7 +2263,7 @@ impl Default for Config {
22992263 profiles : vec ! [ Self :: DEFAULT_PROFILE ] ,
23002264 fs_permissions : FsPermissions :: new ( [ PathPermission :: read ( "out" ) ] ) ,
23012265 isolate : cfg ! ( feature = "isolate-by-default" ) ,
2302- root : Default :: default ( ) ,
2266+ root : root_default ( ) ,
23032267 src : "src" . into ( ) ,
23042268 test : "test" . into ( ) ,
23052269 script : "script" . into ( ) ,
@@ -3068,6 +3032,10 @@ fn canonic(path: impl Into<PathBuf>) -> PathBuf {
30683032 foundry_compilers:: utils:: canonicalize ( & path) . unwrap_or ( path)
30693033}
30703034
3035+ fn root_default ( ) -> PathBuf {
3036+ "." . into ( )
3037+ }
3038+
30713039#[ cfg( test) ]
30723040mod tests {
30733041 use super :: * ;
0 commit comments