Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): implement glob pattern for forge build --skip #5267

Merged
merged 3 commits into from
Jul 4, 2023

Conversation

0xalpharush
Copy link
Contributor

@0xalpharush 0xalpharush commented Jul 2, 2023

Motivation

Currently, forge build --skip test --skip script is unreliable as some projects do not consistently use .t.sol or .s.sol. This PR enables glob patterns like --skip */test/** --skip */script/** to enable only building src.

Closes #4628

Solution

I moved an existing glob matcher util to common and used it in the the FileFilter impl

@Evalir Evalir requested review from mattsse and Evalir July 3, 2023 02:39
///
/// 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 {
Copy link
Contributor Author

@0xalpharush 0xalpharush Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally to match /private/var/folders/test/Foo.sol (this is how it appears in the tests) one wouldn't need */test/** and could instead use ./test/*. I don't have insight into how paths are passed around in Foundry (are they always absolute?), but I could appreciate clarification on this point.

For example, this is the cause of the failing test:

        let file = Path::new("/private/var/folders/test/Foo.sol");
        assert!(!SkipBuildFilter::Custom("*/test/**".to_string()).is_match(file)); // passes 
        assert!(!SkipBuildFilter::Custom("./test/**".to_string()).is_match(file)); // fails

        let file = Path::new("script/Contract.sol");
        assert!(!SkipBuildFilter::Custom("*/script/**".to_string()).is_match(file)); // fails
        assert!(!SkipBuildFilter::Custom("./script/**".to_string()).is_match(file)); // passes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have insight into how paths are passed around in Foundry (are they always absolute?)

they're relative to the configured root when dealing solc, outside of solc they always should be absolute, so foundry should always have absolute paths

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, tysm for this.

a few nits, tests look good though

///
/// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have insight into how paths are passed around in Foundry (are they always absolute?)

they're relative to the configured root when dealing solc, outside of solc they always should be absolute, so foundry should always have absolute paths

@@ -528,8 +528,9 @@ impl FileFilter for SkipBuildFilter {
/// This is returns the inverse of `file.name.contains(pattern)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to update docs here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thank you for this!

just a super small nit for consistency

common/src/glob.rs Outdated Show resolved Hide resolved
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
tysm!

@Evalir Evalir merged commit 2487f00 into foundry-rs:master Jul 4, 2023
@0xalpharush 0xalpharush deleted the feat/glob-skip branch February 21, 2024 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support glob patterns in --skip option (e.g. to skip entire tests dir)
3 participants