Skip to content

Commit 49b65bf

Browse files
committed
fix: better check for 'is_source_file'
1 parent a48b275 commit 49b65bf

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/compilers/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
670670
{
671671
/// Whether given file is a source file or a test/script file.
672672
fn is_source_file(&self, file: &Path) -> bool {
673-
!self.project.paths.is_test_or_script(file)
673+
self.project.paths.is_source_file(file)
674674
}
675675

676676
/// Creates a new cache entry for the file

crates/compilers/src/config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,8 @@ impl<L> ProjectPathsConfig<L> {
251251
}
252252

253253
pub(crate) fn is_test_or_script(&self, path: &Path) -> bool {
254-
let test_dir = self.tests.strip_prefix(&self.root).unwrap_or(&self.tests);
255-
let script_dir = self.scripts.strip_prefix(&self.root).unwrap_or(&self.scripts);
256-
path.starts_with(test_dir) || path.starts_with(script_dir)
254+
path_starts_with_rooted(path, &self.tests, &self.root)
255+
|| path_starts_with_rooted(path, &self.scripts, &self.root)
257256
}
258257

259258
pub(crate) fn is_source_file(&self, path: &Path) -> bool {
@@ -984,6 +983,17 @@ impl SolcConfigBuilder {
984983
}
985984
}
986985

986+
/// Return true if `a` starts with `b` or `b - root`.
987+
fn path_starts_with_rooted(a: &Path, b: &Path, root: &Path) -> bool {
988+
if a.starts_with(b) {
989+
return true;
990+
}
991+
if let Ok(b) = b.strip_prefix(root) {
992+
return a.starts_with(b);
993+
}
994+
false
995+
}
996+
987997
#[cfg(test)]
988998
mod tests {
989999
use super::*;

0 commit comments

Comments
 (0)