Skip to content

Commit

Permalink
fix: correctly process relative paths as --skip values (#7737)
Browse files Browse the repository at this point in the history
* fix: correctly process relative paths as  values

* clippy

* nit
  • Loading branch information
klkvr authored Apr 20, 2024
1 parent 167295e commit 30f145f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
24 changes: 20 additions & 4 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,35 @@ pub fn etherscan_project(metadata: &Metadata, target_path: impl AsRef<Path>) ->

/// Bundles multiple `SkipBuildFilter` into a single `FileFilter`
#[derive(Clone, Debug)]
pub struct SkipBuildFilters(Vec<GlobMatcher>);
pub struct SkipBuildFilters {
/// All provided filters.
pub matchers: Vec<GlobMatcher>,
/// Root of the project.
pub project_root: PathBuf,
}

impl FileFilter for SkipBuildFilters {
/// Only returns a match if _no_ exclusion filter matches
fn is_match(&self, file: &Path) -> bool {
self.0.iter().all(|matcher| is_match_exclude(matcher, file))
self.matchers.iter().all(|matcher| {
if !is_match_exclude(matcher, file) {
false
} else {
file.strip_prefix(&self.project_root)
.map_or(true, |stripped| is_match_exclude(matcher, stripped))
}
})
}
}

impl SkipBuildFilters {
/// Creates a new `SkipBuildFilters` from multiple `SkipBuildFilter`.
pub fn new(matchers: impl IntoIterator<Item = SkipBuildFilter>) -> Result<Self> {
matchers.into_iter().map(|m| m.compile()).collect::<Result<_>>().map(Self)
pub fn new(
filters: impl IntoIterator<Item = SkipBuildFilter>,
project_root: PathBuf,
) -> Result<Self> {
let matchers = filters.into_iter().map(|m| m.compile()).collect::<Result<_>>();
matchers.map(|filters| Self { matchers: filters, project_root })
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/forge/bin/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl BuildArgs {
.bail(!self.format_json);
if let Some(skip) = self.skip {
if !skip.is_empty() {
compiler = compiler.filter(Box::new(SkipBuildFilters::new(skip)?));
compiler = compiler
.filter(Box::new(SkipBuildFilters::new(skip, project.root().to_path_buf())?));
}
}
let output = compiler.compile(&project)?;
Expand Down
7 changes: 6 additions & 1 deletion crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,12 @@ function test_run() external {}

// only builds the single template contract `src/*` even if `*.t.sol` or `.s.sol` is absent
prj.clear();
cmd.args(["build", "--skip", "*/test/**", "--skip", "*/script/**"]);
cmd.args(["build", "--skip", "*/test/**", "--skip", "*/script/**", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/can_build_skip_glob.stdout"),
);

cmd.forge_fuse().args(["build", "--skip", "./test/**", "--skip", "./script/**", "--force"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/can_build_skip_glob.stdout"),
);
Expand Down
5 changes: 4 additions & 1 deletion crates/verify/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ impl VerifyBytecodeArgs {

if let Some(skip) = &self.skip {
if !skip.is_empty() {
compiler = compiler.filter(Box::new(SkipBuildFilters::new(skip.to_owned())?));
compiler = compiler.filter(Box::new(SkipBuildFilters::new(
skip.to_owned(),
project.root().to_path_buf(),
)?));
}
}
let output = compiler.compile(&project)?;
Expand Down

0 comments on commit 30f145f

Please sign in to comment.