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

feat(ethers-solc): configurable build-info output dir #1433

Merged
merged 2 commits into from
Jun 30, 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

- 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
- Use H64 for Block Nonce [#1396](https://github.com/gakonst/ethers-rs/pull/1396)
Expand Down
26 changes: 26 additions & 0 deletions ethers-solc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct ProjectPathsConfig {
pub cache: PathBuf,
/// Where to store build artifacts
pub artifacts: PathBuf,
/// Where to store the build info files
pub build_infos: PathBuf,
/// Where to find sources
pub sources: PathBuf,
/// Where to find tests
Expand Down Expand Up @@ -67,6 +69,7 @@ impl ProjectPathsConfig {
pub fn paths(&self) -> ProjectPaths {
ProjectPaths {
artifacts: self.artifacts.clone(),
build_infos: self.build_infos.clone(),
sources: self.sources.clone(),
tests: self.tests.clone(),
scripts: self.scripts.clone(),
Expand Down Expand Up @@ -387,6 +390,7 @@ impl fmt::Display for ProjectPathsConfig {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ProjectPaths {
pub artifacts: PathBuf,
pub build_infos: PathBuf,
pub sources: PathBuf,
pub tests: PathBuf,
pub scripts: PathBuf,
Expand All @@ -398,6 +402,7 @@ impl ProjectPaths {
pub fn join_all(&mut self, root: impl AsRef<Path>) -> &mut Self {
let root = root.as_ref();
self.artifacts = root.join(&self.artifacts);
self.build_infos = root.join(&self.build_infos);
self.sources = root.join(&self.sources);
self.tests = root.join(&self.tests);
self.scripts = root.join(&self.scripts);
Expand All @@ -413,6 +418,9 @@ impl ProjectPaths {
if let Ok(prefix) = self.artifacts.strip_prefix(base) {
self.artifacts = prefix.to_path_buf();
}
if let Ok(prefix) = self.build_infos.strip_prefix(base) {
self.build_infos = prefix.to_path_buf();
}
if let Ok(prefix) = self.sources.strip_prefix(base) {
self.sources = prefix.to_path_buf();
}
Expand All @@ -436,6 +444,7 @@ impl Default for ProjectPaths {
fn default() -> Self {
Self {
artifacts: "out".into(),
build_infos: ["out", "build-info"].iter().collect::<PathBuf>(),
sources: "src".into(),
tests: "test".into(),
scripts: "script".into(),
Expand All @@ -460,13 +469,15 @@ impl PathStyle {
PathStyle::Dapptools => ProjectPathsConfig::builder()
.sources(root.join("src"))
.artifacts(root.join("out"))
.build_infos(root.join("out").join("build-info"))
.lib(root.join("lib"))
.remappings(Remapping::find_many(&root.join("lib")))
.root(root)
.build()?,
PathStyle::HardHat => ProjectPathsConfig::builder()
.sources(root.join("contracts"))
.artifacts(root.join("artifacts"))
.build_infos(root.join("artifacts").join("build-info"))
.lib(root.join("node_modules"))
.root(root)
.build()?,
Expand All @@ -479,6 +490,7 @@ pub struct ProjectPathsConfigBuilder {
root: Option<PathBuf>,
cache: Option<PathBuf>,
artifacts: Option<PathBuf>,
build_infos: Option<PathBuf>,
sources: Option<PathBuf>,
tests: Option<PathBuf>,
scripts: Option<PathBuf>,
Expand All @@ -502,6 +514,11 @@ impl ProjectPathsConfigBuilder {
self
}

pub fn build_infos(mut self, build_infos: impl Into<PathBuf>) -> Self {
self.build_infos = Some(utils::canonicalized(build_infos));
self
}

pub fn sources(mut self, sources: impl Into<PathBuf>) -> Self {
self.sources = Some(utils::canonicalized(sources));
self
Expand Down Expand Up @@ -561,6 +578,9 @@ impl ProjectPathsConfigBuilder {
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")
}),
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 @@ -702,6 +722,7 @@ mod tests {
let root = crate::utils::tempdir("root").unwrap();
let out = root.path().join("out");
let artifacts = root.path().join("artifacts");
let build_infos = artifacts.join("build-info");
let contracts = root.path().join("contracts");
let src = root.path().join("src");
let lib = root.path().join("lib");
Expand Down Expand Up @@ -729,6 +750,11 @@ mod tests {
ProjectPathsConfig::builder().build_with_root(&root).artifacts,
utils::canonicalized(artifacts),
);
assert_eq!(
ProjectPathsConfig::builder().build_with_root(&root).build_infos,
utils::canonicalized(build_infos)
);

std::fs::File::create(&out).unwrap();
assert_eq!(ProjectPathsConfig::find_artifacts_dir(root), out,);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions ethers-solc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl<T: ArtifactOutput> Project<T> {
}

/// Returns the path to the `build-info` directory nested in the artifacts dir
pub fn build_info_path(&self) -> PathBuf {
self.paths.artifacts.join("build-info")
pub fn build_info_path(&self) -> &PathBuf {
&self.paths.build_infos
}

/// Returns the root directory of the project
Expand Down