Skip to content

Commit 8b8d1cd

Browse files
authored
chore(config): remove RootPath (#9448)
1 parent d4e91c8 commit 8b8d1cd

File tree

14 files changed

+41
-75
lines changed

14 files changed

+41
-75
lines changed

crates/cheatcodes/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl CheatsConfig {
6868
running_contract: Option<String>,
6969
running_version: Option<Version>,
7070
) -> Self {
71-
let mut allowed_paths = vec![config.root.0.clone()];
71+
let mut allowed_paths = vec![config.root.clone()];
7272
allowed_paths.extend(config.libs.clone());
7373
allowed_paths.extend(config.allow_paths.clone());
7474

@@ -88,8 +88,8 @@ impl CheatsConfig {
8888
rpc_endpoints,
8989
paths: config.project_paths(),
9090
fs_permissions: config.fs_permissions.clone().joined(config.root.as_ref()),
91-
root: config.root.0.clone(),
92-
broadcast: config.root.0.clone().join(&config.broadcast),
91+
root: config.root.clone(),
92+
broadcast: config.root.clone().join(&config.broadcast),
9393
allowed_paths,
9494
evm_opts,
9595
labels: config.labels.clone(),
@@ -239,7 +239,7 @@ mod tests {
239239

240240
fn config(root: &str, fs_permissions: FsPermissions) -> CheatsConfig {
241241
CheatsConfig::new(
242-
&Config { root: PathBuf::from(root).into(), fs_permissions, ..Default::default() },
242+
&Config { root: root.into(), fs_permissions, ..Default::default() },
243243
Default::default(),
244244
None,
245245
None,

crates/cli/src/opts/build/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a> From<&'a CoreBuildArgs> for Config {
204204
// if `--config-path` is set we need to adjust the config's root path to the actual root
205205
// path for the project, otherwise it will the parent dir of the `--config-path`
206206
if args.project_paths.config_path.is_some() {
207-
config.root = args.project_paths.project_root().into();
207+
config.root = args.project_paths.project_root();
208208
}
209209
config
210210
}

crates/cli/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a> Git<'a> {
287287

288288
#[inline]
289289
pub fn from_config(config: &'a Config) -> Self {
290-
Self::new(config.root.0.as_path())
290+
Self::new(config.root.as_path())
291291
}
292292

293293
pub fn root_of(relative_to: &Path) -> Result<PathBuf> {

crates/config/src/lib.rs

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
30723040
mod tests {
30733041
use super::*;

crates/forge/bin/cmd/bind_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl BindJsonArgs {
6464
let config = self.try_load_config_emit_warnings()?;
6565
let project = config.create_project(false, true)?;
6666

67-
let target_path = config.root.0.join(self.out.as_ref().unwrap_or(&config.bind_json.out));
67+
let target_path = config.root.join(self.out.as_ref().unwrap_or(&config.bind_json.out));
6868

6969
let sources = project.paths.read_input_files()?;
7070
let graph = Graph::<MultiCompilerParsedSource>::resolve_sources(&project.paths, sources)?;

crates/forge/bin/cmd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl BuildArgs {
137137
// directories as well as the `foundry.toml` configuration file.
138138
self.watch.watchexec_config(|| {
139139
let config = Config::from(self);
140-
let foundry_toml: PathBuf = config.root.0.join(Config::FILE_NAME);
140+
let foundry_toml: PathBuf = config.root.join(Config::FILE_NAME);
141141
[config.src, config.test, config.script, foundry_toml]
142142
})
143143
}

crates/forge/bin/cmd/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct DocArgs {
6868
impl DocArgs {
6969
pub async fn run(self) -> Result<()> {
7070
let config = self.config()?;
71-
let root = &config.root.0;
71+
let root = &config.root;
7272
let project = config.project()?;
7373
let compiler = ProjectCompiler::new().quiet(true);
7474
let _output = compiler.compile(&project)?;

crates/forge/bin/cmd/fmt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl FmtArgs {
4848
let config = self.try_load_config_emit_warnings()?;
4949

5050
// Expand ignore globs and canonicalize from the get go
51-
let ignored = expand_globs(&config.root.0, config.fmt.ignore.iter())?
51+
let ignored = expand_globs(&config.root, config.fmt.ignore.iter())?
5252
.iter()
5353
.flat_map(foundry_common::fs::canonicalize_path)
5454
.collect::<Vec<_>>();
@@ -96,9 +96,7 @@ impl FmtArgs {
9696

9797
let format = |source: String, path: Option<&Path>| -> Result<_> {
9898
let name = match path {
99-
Some(path) => {
100-
path.strip_prefix(&config.root.0).unwrap_or(path).display().to_string()
101-
}
99+
Some(path) => path.strip_prefix(&config.root).unwrap_or(path).display().to_string(),
102100
None => "stdin".to_string(),
103101
};
104102

crates/forge/bin/cmd/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl TestArgs {
559559

560560
if self.decode_internal.is_some() {
561561
let sources =
562-
ContractSources::from_project_output(output, &config.root.0, Some(&libraries))?;
562+
ContractSources::from_project_output(output, &config.root, Some(&libraries))?;
563563
builder = builder.with_debug_identifier(DebugTraceIdentifier::new(sources));
564564
}
565565
let mut decoder = builder.build();

crates/forge/bin/cmd/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl UpdateArgs {
5252
/// Returns `(root, paths)` where `root` is the root of the Git repository and `paths` are the
5353
/// relative paths of the dependencies.
5454
pub fn dependencies_paths(deps: &[Dependency], config: &Config) -> Result<(PathBuf, Vec<PathBuf>)> {
55-
let git_root = Git::root_of(&config.root.0)?;
55+
let git_root = Git::root_of(&config.root)?;
5656
let libs = config.install_lib_dir();
5757

5858
let mut paths = Vec::with_capacity(deps.len());

0 commit comments

Comments
 (0)