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

Commit 7e26fcc

Browse files
committed
docs: more docs and tracing
1 parent 23c356c commit 7e26fcc

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

Diff for: ethers-solc/src/cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ impl SolFilesCacheBuilder {
242242
solc_config: solc_config.clone(),
243243
imports,
244244
version_pragmas,
245-
// TODO detect artifacts
246245
artifacts: vec![],
247246
};
248247
files.insert(file, entry);

Diff for: ethers-solc/src/lib.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pub mod artifacts;
44

55
pub use artifacts::{CompilerInput, CompilerOutput, EvmVersion};
6-
use std::collections::{btree_map::Entry, hash_map};
6+
use std::collections::btree_map::Entry;
77

88
pub mod cache;
99

@@ -96,12 +96,12 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
9696
sources: Sources,
9797
artifacts: Vec<(PathBuf, Vec<String>)>,
9898
) -> Result<()> {
99-
tracing::trace!("inserting files to cache");
99+
tracing::trace!("inserting {} sources in file cache", sources.len());
100100
let mut cache = SolFilesCache::builder()
101101
.root(&self.paths.root)
102102
.solc_config(self.solc_config.clone())
103103
.insert_files(sources, Some(self.paths.cache.clone()))?;
104-
tracing::trace!("files inserted");
104+
tracing::trace!("source files inserted");
105105

106106
// add the artifacts for each file to the cache entry
107107
for (file, artifacts) in artifacts {
@@ -111,8 +111,11 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
111111
}
112112

113113
if let Some(cache_dir) = self.paths.cache.parent() {
114+
tracing::trace!("creating cache file parent directory \"{}\"", cache_dir.display());
114115
fs::create_dir_all(cache_dir)?
115116
}
117+
118+
tracing::trace!("writing cache file to \"{}\"", self.paths.cache.display());
116119
cache.write(&self.paths.cache)?;
117120

118121
Ok(())
@@ -196,6 +199,7 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
196199
#[tracing::instrument(skip(self, sources))]
197200
fn svm_compile(&self, sources: Sources) -> Result<ProjectCompileOutput<Artifacts>> {
198201
use semver::{Version, VersionReq};
202+
use std::collections::hash_map;
199203

200204
// split them by version
201205
let mut sources_by_version = BTreeMap::new();
@@ -224,7 +228,7 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
224228
// gets the solc binary for that version, it is expected tha this will succeed
225229
// AND find the solc since it was installed right above
226230
let mut solc = Solc::find_svm_installed_version(version.to_string())?
227-
.expect("solc should have been installed");
231+
.unwrap_or_else(|| panic!("solc \"{}\" should have been installed", version));
228232

229233
if !self.allowed_lib_paths.0.is_empty() {
230234
solc = solc.arg("--allow-paths").arg(self.allowed_lib_paths.to_string());
@@ -262,6 +266,13 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
262266
Ok(compiled)
263267
}
264268

269+
/// Compiles the given source files with the exact `Solc` executable
270+
///
271+
/// First all libraries for the sources are resolved by scanning all their imports.
272+
/// If caching is enabled for the `Project`, then all unchanged files are filtered from the
273+
/// sources and their existing artifacts are read instead. This will also update the cache
274+
/// file and cleans up entries for files which may have been removed. Unchanged files that
275+
/// for which an artifact exist, are not compiled again.
265276
pub fn compile_with_version(
266277
&self,
267278
solc: &Solc,
@@ -301,15 +312,15 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
301312
let cached_artifacts = if self.paths.artifacts.exists() {
302313
tracing::trace!("reading artifacts from cache..");
303314
let artifacts = cache.read_artifacts::<Artifacts>(&self.paths.artifacts)?;
304-
tracing::trace!("done reading artifacts from cache");
315+
tracing::trace!("read artifacts from cache");
305316
artifacts
306317
} else {
307318
BTreeMap::default()
308319
};
309320

310321
// if nothing changed and all artifacts still exist
311322
if changed_files.is_empty() {
312-
tracing::trace!("no change");
323+
tracing::trace!("unchanged source files");
313324
return Ok(ProjectCompileOutput::from_unchanged(cached_artifacts))
314325
}
315326
// There are changed files and maybe some cached files
@@ -324,9 +335,10 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
324335
let input = CompilerInput::with_sources(sources)
325336
.normalize_evm_version(&solc.version()?)
326337
.with_remappings(self.paths.remappings.clone());
327-
tracing::trace!("calling solc");
338+
tracing::trace!("calling solc with {} sources", input.sources.len());
328339
let output = solc.compile(&input)?;
329340
tracing::trace!("compiled input, output has error: {}", output.has_error());
341+
330342
if output.has_error() {
331343
return Ok(ProjectCompileOutput::from_compiler_output(
332344
output,
@@ -367,11 +379,14 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
367379

368380
/// Removes the project's artifacts and cache file
369381
pub fn cleanup(&self) -> Result<()> {
382+
tracing::trace!("clean up project");
370383
if self.paths.cache.exists() {
371-
std::fs::remove_dir_all(&self.paths.cache)?;
384+
std::fs::remove_file(&self.paths.cache)?;
385+
tracing::trace!("removed cache file \"{}\"", self.paths.cache.display());
372386
}
373387
if self.paths.artifacts.exists() {
374388
std::fs::remove_dir_all(&self.paths.artifacts)?;
389+
tracing::trace!("removed artifacts dir \"{}\"", self.paths.artifacts.display());
375390
}
376391
Ok(())
377392
}

0 commit comments

Comments
 (0)