ethers-solc: fix build info default directory (#1458)

* ethers-solc: fix build info default directory

This commit fixes the default behavior for the `build-info`
directory when it is unconfigured. It should end up in
the configured artifacts directory, taking into account
whatever the config for the artifacts directory is.
If the build info is specifically configured, then that
will take precendence over the default.

* chore: add changelog entry
This commit is contained in:
Mark Tyneway 2022-07-06 11:44:47 -07:00 committed by GitHub
parent bc9d4b48b6
commit 1efdadefc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -4,6 +4,7 @@
### Unreleased ### 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) - 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) - 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 - Methods like `set_to()` from `TypedTransaction` can be chained

View File

@ -570,17 +570,15 @@ impl ProjectPathsConfigBuilder {
let root = utils::canonicalized(root); let root = utils::canonicalized(root);
let libraries = self.libraries.unwrap_or_else(|| ProjectPathsConfig::find_libs(&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 { ProjectPathsConfig {
cache: self cache: self
.cache .cache
.unwrap_or_else(|| root.join("cache").join(SOLIDITY_FILES_CACHE_FILENAME)), .unwrap_or_else(|| root.join("cache").join(SOLIDITY_FILES_CACHE_FILENAME)),
artifacts: self build_infos: self.build_infos.unwrap_or_else(|| artifacts.join("build-info")),
.artifacts 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")
}),
sources: self.sources.unwrap_or_else(|| ProjectPathsConfig::find_source_dir(&root)), sources: self.sources.unwrap_or_else(|| ProjectPathsConfig::find_source_dir(&root)),
tests: self.tests.unwrap_or_else(|| root.join("test")), tests: self.tests.unwrap_or_else(|| root.join("test")),
scripts: self.scripts.unwrap_or_else(|| root.join("script")), scripts: self.scripts.unwrap_or_else(|| root.join("script")),
@ -776,4 +774,21 @@ mod tests {
vec![utils::canonicalized(lib)], 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")));
}
} }