Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

ethers-solc: fix build info default directory #1458

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Unreleased

- Fix the default config for generated `BuildInfo` [#1458](https://github.com/gakonst/ethers-rs/pull/1458)
- Allow configuration of the output directory of the generated `BuildInfo` [#1433](https://github.com/gakonst/ethers-rs/pull/1433)
- capture unknown fields in `Block` and `Transaction` type via new `OtherFields` type [#1423](https://github.com/gakonst/ethers-rs/pull/1423)
- Methods like `set_to()` from `TypedTransaction` can be chained
Expand Down
27 changes: 21 additions & 6 deletions ethers-solc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,15 @@ impl ProjectPathsConfigBuilder {
let root = utils::canonicalized(root);

let libraries = self.libraries.unwrap_or_else(|| ProjectPathsConfig::find_libs(&root));
let artifacts =
self.artifacts.unwrap_or_else(|| ProjectPathsConfig::find_artifacts_dir(&root));

ProjectPathsConfig {
cache: self
.cache
.unwrap_or_else(|| root.join("cache").join(SOLIDITY_FILES_CACHE_FILENAME)),
artifacts: self
.artifacts
.unwrap_or_else(|| ProjectPathsConfig::find_artifacts_dir(&root)),
build_infos: self.build_infos.unwrap_or_else(|| {
ProjectPathsConfig::find_artifacts_dir(&root).join("build-info")
}),
build_infos: self.build_infos.unwrap_or_else(|| artifacts.join("build-info")),
artifacts,
sources: self.sources.unwrap_or_else(|| ProjectPathsConfig::find_source_dir(&root)),
tests: self.tests.unwrap_or_else(|| root.join("test")),
scripts: self.scripts.unwrap_or_else(|| root.join("script")),
Expand Down Expand Up @@ -776,4 +774,21 @@ mod tests {
vec![utils::canonicalized(lib)],
);
}

#[test]
fn can_have_sane_build_info_default() {
let root = crate::utils::tempdir("root").unwrap();
let root = root.path();
let artifacts = root.join("forge-artifacts");

// Set the artifacts directory without setting the
// build info directory
let project = ProjectPathsConfig::builder().artifacts(&artifacts).build_with_root(&root);

// The artifacts should be set correctly based on the configured value
assert_eq!(project.artifacts, utils::canonicalized(artifacts));

// The build infos should by default in the artifacts directory
assert_eq!(project.build_infos, utils::canonicalized(project.artifacts.join("build-info")));
}
}