3
3
pub mod artifacts;
4
4
5
5
pub use artifacts:: { CompilerInput , CompilerOutput , EvmVersion } ;
6
- use std:: collections:: { btree_map:: Entry , hash_map } ;
6
+ use std:: collections:: btree_map:: Entry ;
7
7
8
8
pub mod cache;
9
9
@@ -96,12 +96,12 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
96
96
sources : Sources ,
97
97
artifacts : Vec < ( PathBuf , Vec < String > ) > ,
98
98
) -> Result < ( ) > {
99
- tracing:: trace!( "inserting files to cache" ) ;
99
+ tracing:: trace!( "inserting {} sources in file cache" , sources . len ( ) ) ;
100
100
let mut cache = SolFilesCache :: builder ( )
101
101
. root ( & self . paths . root )
102
102
. solc_config ( self . solc_config . clone ( ) )
103
103
. insert_files ( sources, Some ( self . paths . cache . clone ( ) ) ) ?;
104
- tracing:: trace!( "files inserted" ) ;
104
+ tracing:: trace!( "source files inserted" ) ;
105
105
106
106
// add the artifacts for each file to the cache entry
107
107
for ( file, artifacts) in artifacts {
@@ -111,8 +111,11 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
111
111
}
112
112
113
113
if let Some ( cache_dir) = self . paths . cache . parent ( ) {
114
+ tracing:: trace!( "creating cache file parent directory \" {}\" " , cache_dir. display( ) ) ;
114
115
fs:: create_dir_all ( cache_dir) ?
115
116
}
117
+
118
+ tracing:: trace!( "writing cache file to \" {}\" " , self . paths. cache. display( ) ) ;
116
119
cache. write ( & self . paths . cache ) ?;
117
120
118
121
Ok ( ( ) )
@@ -196,6 +199,7 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
196
199
#[ tracing:: instrument( skip( self , sources) ) ]
197
200
fn svm_compile ( & self , sources : Sources ) -> Result < ProjectCompileOutput < Artifacts > > {
198
201
use semver:: { Version , VersionReq } ;
202
+ use std:: collections:: hash_map;
199
203
200
204
// split them by version
201
205
let mut sources_by_version = BTreeMap :: new ( ) ;
@@ -224,7 +228,7 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
224
228
// gets the solc binary for that version, it is expected tha this will succeed
225
229
// AND find the solc since it was installed right above
226
230
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 ) ) ;
228
232
229
233
if !self . allowed_lib_paths . 0 . is_empty ( ) {
230
234
solc = solc. arg ( "--allow-paths" ) . arg ( self . allowed_lib_paths . to_string ( ) ) ;
@@ -262,6 +266,13 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
262
266
Ok ( compiled)
263
267
}
264
268
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.
265
276
pub fn compile_with_version (
266
277
& self ,
267
278
solc : & Solc ,
@@ -301,15 +312,15 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
301
312
let cached_artifacts = if self . paths . artifacts . exists ( ) {
302
313
tracing:: trace!( "reading artifacts from cache.." ) ;
303
314
let artifacts = cache. read_artifacts :: < Artifacts > ( & self . paths . artifacts ) ?;
304
- tracing:: trace!( "done reading artifacts from cache" ) ;
315
+ tracing:: trace!( "read artifacts from cache" ) ;
305
316
artifacts
306
317
} else {
307
318
BTreeMap :: default ( )
308
319
} ;
309
320
310
321
// if nothing changed and all artifacts still exist
311
322
if changed_files. is_empty ( ) {
312
- tracing:: trace!( "no change " ) ;
323
+ tracing:: trace!( "unchanged source files " ) ;
313
324
return Ok ( ProjectCompileOutput :: from_unchanged ( cached_artifacts) )
314
325
}
315
326
// There are changed files and maybe some cached files
@@ -324,9 +335,10 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
324
335
let input = CompilerInput :: with_sources ( sources)
325
336
. normalize_evm_version ( & solc. version ( ) ?)
326
337
. with_remappings ( self . paths . remappings . clone ( ) ) ;
327
- tracing:: trace!( "calling solc" ) ;
338
+ tracing:: trace!( "calling solc with {} sources" , input . sources . len ( ) ) ;
328
339
let output = solc. compile ( & input) ?;
329
340
tracing:: trace!( "compiled input, output has error: {}" , output. has_error( ) ) ;
341
+
330
342
if output. has_error ( ) {
331
343
return Ok ( ProjectCompileOutput :: from_compiler_output (
332
344
output,
@@ -367,11 +379,14 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
367
379
368
380
/// Removes the project's artifacts and cache file
369
381
pub fn cleanup ( & self ) -> Result < ( ) > {
382
+ tracing:: trace!( "clean up project" ) ;
370
383
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( ) ) ;
372
386
}
373
387
if self . paths . artifacts . exists ( ) {
374
388
std:: fs:: remove_dir_all ( & self . paths . artifacts ) ?;
389
+ tracing:: trace!( "removed artifacts dir \" {}\" " , self . paths. artifacts. display( ) ) ;
375
390
}
376
391
Ok ( ( ) )
377
392
}
0 commit comments