feat: only compile changed files (#544)
This commit is contained in:
parent
5c6ce6b0a1
commit
46bedb3282
|
@ -58,9 +58,17 @@ impl SolFilesCache {
|
||||||
self.files.retain(|file, _| Path::new(file).exists())
|
self.files.retain(|file, _| Path::new(file).exists())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns if true if a source has changed and false if no source has changed
|
/// Returns only the files that were changed from the provided sources, to save time
|
||||||
pub fn is_changed(&self, sources: &Sources, config: Option<&SolcConfig>) -> bool {
|
/// when compiling.
|
||||||
sources.iter().any(|(file, source)| self.has_changed(file, source.content_hash(), config))
|
pub fn get_changed_files<'a>(
|
||||||
|
&'a self,
|
||||||
|
sources: Sources,
|
||||||
|
config: Option<&'a SolcConfig>,
|
||||||
|
) -> Sources {
|
||||||
|
sources
|
||||||
|
.into_iter()
|
||||||
|
.filter(move |(file, source)| self.has_changed(file, source.content_hash(), config))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given content hash or config differs from the file's
|
/// Returns true if the given content hash or config differs from the file's
|
||||||
|
|
|
@ -105,13 +105,17 @@ impl Project {
|
||||||
source_name_path.insert(import, path);
|
source_name_path.insert(import, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.cached && self.paths.cache.exists() {
|
// If there's a cache set, filter to only re-compile the files which were changed
|
||||||
// check anything changed
|
let sources = if self.cached && self.paths.cache.exists() {
|
||||||
let cache = SolFilesCache::read(&self.paths.cache)?;
|
let cache = SolFilesCache::read(&self.paths.cache)?;
|
||||||
if !cache.is_changed(&sources, Some(&self.solc_config)) {
|
let changed_files = cache.get_changed_files(sources, Some(&self.solc_config));
|
||||||
|
if changed_files.is_empty() {
|
||||||
return Ok(ProjectCompileOutput::Unchanged)
|
return Ok(ProjectCompileOutput::Unchanged)
|
||||||
}
|
}
|
||||||
}
|
changed_files
|
||||||
|
} else {
|
||||||
|
sources
|
||||||
|
};
|
||||||
|
|
||||||
// replace absolute path with source name to make solc happy
|
// replace absolute path with source name to make solc happy
|
||||||
let sources = apply_mappings(sources, path_source_name);
|
let sources = apply_mappings(sources, path_source_name);
|
||||||
|
|
Loading…
Reference in New Issue