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

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

* chore: update changelog
This commit is contained in:
Mark Tyneway 2022-06-30 09:21:46 -07:00 committed by GitHub
parent 1992c9176a
commit 3bafe5b9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -4,6 +4,7 @@
### Unreleased ### 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) - 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
- Use H64 for Block Nonce [#1396](https://github.com/gakonst/ethers-rs/pull/1396) - Use H64 for Block Nonce [#1396](https://github.com/gakonst/ethers-rs/pull/1396)

View File

@ -25,6 +25,8 @@ pub struct ProjectPathsConfig {
pub cache: PathBuf, pub cache: PathBuf,
/// Where to store build artifacts /// Where to store build artifacts
pub artifacts: PathBuf, pub artifacts: PathBuf,
/// Where to store the build info files
pub build_infos: PathBuf,
/// Where to find sources /// Where to find sources
pub sources: PathBuf, pub sources: PathBuf,
/// Where to find tests /// Where to find tests
@ -67,6 +69,7 @@ impl ProjectPathsConfig {
pub fn paths(&self) -> ProjectPaths { pub fn paths(&self) -> ProjectPaths {
ProjectPaths { ProjectPaths {
artifacts: self.artifacts.clone(), artifacts: self.artifacts.clone(),
build_infos: self.build_infos.clone(),
sources: self.sources.clone(), sources: self.sources.clone(),
tests: self.tests.clone(), tests: self.tests.clone(),
scripts: self.scripts.clone(), scripts: self.scripts.clone(),
@ -387,6 +390,7 @@ impl fmt::Display for ProjectPathsConfig {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ProjectPaths { pub struct ProjectPaths {
pub artifacts: PathBuf, pub artifacts: PathBuf,
pub build_infos: PathBuf,
pub sources: PathBuf, pub sources: PathBuf,
pub tests: PathBuf, pub tests: PathBuf,
pub scripts: PathBuf, pub scripts: PathBuf,
@ -398,6 +402,7 @@ impl ProjectPaths {
pub fn join_all(&mut self, root: impl AsRef<Path>) -> &mut Self { pub fn join_all(&mut self, root: impl AsRef<Path>) -> &mut Self {
let root = root.as_ref(); let root = root.as_ref();
self.artifacts = root.join(&self.artifacts); self.artifacts = root.join(&self.artifacts);
self.build_infos = root.join(&self.build_infos);
self.sources = root.join(&self.sources); self.sources = root.join(&self.sources);
self.tests = root.join(&self.tests); self.tests = root.join(&self.tests);
self.scripts = root.join(&self.scripts); self.scripts = root.join(&self.scripts);
@ -413,6 +418,9 @@ impl ProjectPaths {
if let Ok(prefix) = self.artifacts.strip_prefix(base) { if let Ok(prefix) = self.artifacts.strip_prefix(base) {
self.artifacts = prefix.to_path_buf(); 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) { if let Ok(prefix) = self.sources.strip_prefix(base) {
self.sources = prefix.to_path_buf(); self.sources = prefix.to_path_buf();
} }
@ -436,6 +444,7 @@ impl Default for ProjectPaths {
fn default() -> Self { fn default() -> Self {
Self { Self {
artifacts: "out".into(), artifacts: "out".into(),
build_infos: ["out", "build-info"].iter().collect::<PathBuf>(),
sources: "src".into(), sources: "src".into(),
tests: "test".into(), tests: "test".into(),
scripts: "script".into(), scripts: "script".into(),
@ -460,6 +469,7 @@ impl PathStyle {
PathStyle::Dapptools => ProjectPathsConfig::builder() PathStyle::Dapptools => ProjectPathsConfig::builder()
.sources(root.join("src")) .sources(root.join("src"))
.artifacts(root.join("out")) .artifacts(root.join("out"))
.build_infos(root.join("out").join("build-info"))
.lib(root.join("lib")) .lib(root.join("lib"))
.remappings(Remapping::find_many(&root.join("lib"))) .remappings(Remapping::find_many(&root.join("lib")))
.root(root) .root(root)
@ -467,6 +477,7 @@ impl PathStyle {
PathStyle::HardHat => ProjectPathsConfig::builder() PathStyle::HardHat => ProjectPathsConfig::builder()
.sources(root.join("contracts")) .sources(root.join("contracts"))
.artifacts(root.join("artifacts")) .artifacts(root.join("artifacts"))
.build_infos(root.join("artifacts").join("build-info"))
.lib(root.join("node_modules")) .lib(root.join("node_modules"))
.root(root) .root(root)
.build()?, .build()?,
@ -479,6 +490,7 @@ pub struct ProjectPathsConfigBuilder {
root: Option<PathBuf>, root: Option<PathBuf>,
cache: Option<PathBuf>, cache: Option<PathBuf>,
artifacts: Option<PathBuf>, artifacts: Option<PathBuf>,
build_infos: Option<PathBuf>,
sources: Option<PathBuf>, sources: Option<PathBuf>,
tests: Option<PathBuf>, tests: Option<PathBuf>,
scripts: Option<PathBuf>, scripts: Option<PathBuf>,
@ -502,6 +514,11 @@ impl ProjectPathsConfigBuilder {
self 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 { pub fn sources(mut self, sources: impl Into<PathBuf>) -> Self {
self.sources = Some(utils::canonicalized(sources)); self.sources = Some(utils::canonicalized(sources));
self self
@ -561,6 +578,9 @@ impl ProjectPathsConfigBuilder {
artifacts: self artifacts: self
.artifacts .artifacts
.unwrap_or_else(|| ProjectPathsConfig::find_artifacts_dir(&root)), .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")),
@ -702,6 +722,7 @@ mod tests {
let root = crate::utils::tempdir("root").unwrap(); let root = crate::utils::tempdir("root").unwrap();
let out = root.path().join("out"); let out = root.path().join("out");
let artifacts = root.path().join("artifacts"); let artifacts = root.path().join("artifacts");
let build_infos = artifacts.join("build-info");
let contracts = root.path().join("contracts"); let contracts = root.path().join("contracts");
let src = root.path().join("src"); let src = root.path().join("src");
let lib = root.path().join("lib"); let lib = root.path().join("lib");
@ -729,6 +750,11 @@ mod tests {
ProjectPathsConfig::builder().build_with_root(&root).artifacts, ProjectPathsConfig::builder().build_with_root(&root).artifacts,
utils::canonicalized(artifacts), utils::canonicalized(artifacts),
); );
assert_eq!(
ProjectPathsConfig::builder().build_with_root(&root).build_infos,
utils::canonicalized(build_infos)
);
std::fs::File::create(&out).unwrap(); std::fs::File::create(&out).unwrap();
assert_eq!(ProjectPathsConfig::find_artifacts_dir(root), out,); assert_eq!(ProjectPathsConfig::find_artifacts_dir(root), out,);
assert_eq!( assert_eq!(

View File

@ -125,8 +125,8 @@ impl<T: ArtifactOutput> Project<T> {
} }
/// Returns the path to the `build-info` directory nested in the artifacts dir /// Returns the path to the `build-info` directory nested in the artifacts dir
pub fn build_info_path(&self) -> PathBuf { pub fn build_info_path(&self) -> &PathBuf {
self.paths.artifacts.join("build-info") &self.paths.build_infos
} }
/// Returns the root directory of the project /// Returns the root directory of the project