-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forge): implement glob pattern for forge build --skip (#5267)
- Loading branch information
1 parent
6e4b417
commit 2487f00
Showing
9 changed files
with
105 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Compiling 1 files with 0.8.17 | ||
Solc 0.8.17 finished in 33.25ms | ||
Compiler run successful! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! Contains `globset::Glob` wrapper functions used for filtering | ||
use std::{fmt, str::FromStr}; | ||
/// A `globset::Glob` that creates its `globset::GlobMatcher` when its created, so it doesn't need | ||
/// to be compiled when the filter functions `TestFilter` functions are called. | ||
#[derive(Debug, Clone)] | ||
pub struct GlobMatcher { | ||
/// The parsed glob | ||
pub glob: globset::Glob, | ||
/// The compiled glob | ||
pub matcher: globset::GlobMatcher, | ||
} | ||
|
||
// === impl GlobMatcher === | ||
|
||
impl GlobMatcher { | ||
/// Tests whether the given path matches this pattern or not. | ||
/// | ||
/// The glob `./test/*` won't match absolute paths like `test/Contract.sol`, which is common | ||
/// format here, so we also handle this case here | ||
pub fn is_match(&self, path: &str) -> bool { | ||
let mut matches = self.matcher.is_match(path); | ||
if !matches && !path.starts_with("./") && self.as_str().starts_with("./") { | ||
matches = self.matcher.is_match(format!("./{path}")); | ||
} | ||
matches | ||
} | ||
|
||
/// Returns the `Glob` string used to compile this matcher. | ||
pub fn as_str(&self) -> &str { | ||
self.glob.glob() | ||
} | ||
} | ||
|
||
impl fmt::Display for GlobMatcher { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.glob.fmt(f) | ||
} | ||
} | ||
|
||
impl FromStr for GlobMatcher { | ||
type Err = globset::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
s.parse::<globset::Glob>().map(Into::into) | ||
} | ||
} | ||
|
||
impl From<globset::Glob> for GlobMatcher { | ||
fn from(glob: globset::Glob) -> Self { | ||
let matcher = glob.compile_matcher(); | ||
Self { glob, matcher } | ||
} | ||
} | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn can_match_glob_paths() { | ||
let matcher: GlobMatcher = "./test/*".parse().unwrap(); | ||
assert!(matcher.is_match("test/Contract.sol")); | ||
assert!(matcher.is_match("./test/Contract.sol")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters