@@ -22,7 +22,7 @@ use ethers_solc::{
22
22
remappings:: { RelativeRemapping , Remapping } ,
23
23
EvmVersion , Project , ProjectPathsConfig , SolcConfig ,
24
24
} ;
25
- use figment:: providers:: Data ;
25
+ use figment:: { providers:: Data , value :: Value } ;
26
26
use inflector:: Inflector ;
27
27
28
28
// Macros useful for creating a figment.
@@ -166,11 +166,11 @@ pub struct Config {
166
166
// "#
167
167
pub solc_settings : Option < String > ,
168
168
/// The root path where the config detection started from, `Config::with_root`
169
- ///
170
- /// **Note:** This field is never serialized nor deserialized. This is merely used to provided
171
- /// additional context.
172
169
#[ doc( hidden) ]
173
- #[ serde( skip) ]
170
+ // We're skipping serialization here, so it won't be included in the [`Config::to_string()`]
171
+ // representation, but will be deserialized from the `Figment` so that forge commands can
172
+ // override it.
173
+ #[ serde( rename = "root" , default , skip_serializing) ]
174
174
pub __root : RootPath ,
175
175
/// PRIVATE: This structure may grow, As such, constructing this structure should
176
176
/// _always_ be done using a public constructor or update syntax:
@@ -637,7 +637,8 @@ impl From<Config> for Figment {
637
637
}
638
638
639
639
/// A helper wrapper around the root path used during Config detection
640
- #[ derive( Debug , PartialEq , Eq , Hash , Clone , PartialOrd , Ord ) ]
640
+ #[ derive( Debug , PartialEq , Eq , Hash , Clone , PartialOrd , Ord , Deserialize , Serialize ) ]
641
+ #[ serde( transparent) ]
641
642
pub struct RootPath ( pub PathBuf ) ;
642
643
643
644
impl Default for RootPath {
@@ -676,7 +677,11 @@ impl Provider for Config {
676
677
677
678
#[ track_caller]
678
679
fn data ( & self ) -> Result < Map < Profile , Dict > , figment:: Error > {
679
- Serialized :: defaults ( self ) . data ( )
680
+ let mut data = Serialized :: defaults ( self ) . data ( ) ?;
681
+ if let Some ( entry) = data. get_mut ( & self . profile ) {
682
+ entry. insert ( "root" . to_string ( ) , Value :: serialize ( self . __root . clone ( ) ) ?) ;
683
+ }
684
+ Ok ( data)
680
685
}
681
686
682
687
fn profile ( & self ) -> Option < Profile > {
@@ -1461,6 +1466,7 @@ mod tests {
1461
1466
fn can_use_impl_figment_macro ( ) {
1462
1467
#[ derive( Default , Serialize ) ]
1463
1468
struct MyArgs {
1469
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1464
1470
root : Option < PathBuf > ,
1465
1471
}
1466
1472
impl_figment_convert ! ( MyArgs ) ;
0 commit comments