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

fix(solc): skip artifacts check for files without artifacts #1018

Merged
merged 1 commit into from
Mar 13, 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
35 changes: 20 additions & 15 deletions ethers-solc/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,23 +638,28 @@ impl<'a, T: ArtifactOutput> ArtifactsCacheInner<'a, T> {
return true
}

if !entry.contains_version(version) {
tracing::trace!(
"missing linked artifacts for source file `{}` for version \"{}\"",
file.display(),
version
);
return true
}
// only check artifact's existence if the file generated artifacts.
// e.g. a solidity file consisting only of import statements (like interfaces that
// re-export) do not create artifacts
if !entry.artifacts.is_empty() {
if !entry.contains_version(version) {
tracing::trace!(
"missing linked artifacts for source file `{}` for version \"{}\"",
file.display(),
version
);
return true
}

if entry.artifacts_for_version(version).any(|artifact_path| {
let missing_artifact = !self.cached_artifacts.has_artifact(artifact_path);
if missing_artifact {
tracing::trace!("missing artifact \"{}\"", artifact_path.display());
if entry.artifacts_for_version(version).any(|artifact_path| {
let missing_artifact = !self.cached_artifacts.has_artifact(artifact_path);
if missing_artifact {
tracing::trace!("missing artifact \"{}\"", artifact_path.display());
}
missing_artifact
}) {
return true
}
missing_artifact
}) {
return true
}
// all things match, can be reused
return false
Expand Down
48 changes: 48 additions & 0 deletions ethers-solc/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,51 @@ fn can_recompile_with_changes() {
assert!(compiled.find("A").is_some());
assert!(compiled.find("B").is_some());
}

#[test]
fn can_recompile_unchanged_with_empty_files() {
let tmp = TempProject::dapptools().unwrap();

tmp.add_source(
"A",
r#"
pragma solidity ^0.8.10;
import "./B.sol";
contract A {}
"#,
)
.unwrap();

tmp.add_source(
"B",
r#"
pragma solidity ^0.8.10;
import "./C.sol";
"#,
)
.unwrap();

let c = r#"
pragma solidity ^0.8.10;
contract C {}
"#;
tmp.add_source("C", c).unwrap();

let compiled = tmp.compile().unwrap();
assert!(!compiled.has_compiler_errors());
assert!(compiled.find("A").is_some());
assert!(compiled.find("C").is_some());

let compiled = tmp.compile().unwrap();
assert!(compiled.find("A").is_some());
assert!(compiled.find("C").is_some());
assert!(compiled.is_unchanged());

// modify C.sol
tmp.add_source("C", format!("{}\n", c)).unwrap();
let compiled = tmp.compile().unwrap();
assert!(!compiled.has_compiler_errors());
assert!(!compiled.is_unchanged());
assert!(compiled.find("A").is_some());
assert!(compiled.find("C").is_some());
}