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

lib: Add a function to filter sources by regular expressions. #22912

Merged
merged 1 commit into from Feb 19, 2017

Conversation

teh
Copy link
Contributor

@teh teh commented Feb 17, 2017

Branch as discussed on the mailing list @basvandijk. Discussion points:

  • If we following the one existing naming example sourceFilesBySuffices this should be called sourceFilesByRegexes but I find that quite untypeable.
  • I can't figure out how to add or run tests in lib/tests.nix - any ideas?

@mention-bot
Copy link

@teh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @obadz, @edolstra and @ericsagnes to be potential reviewers.

@basvandijk
Copy link
Member

As I mentioned on the mailinglist the following implementation might be more efficient:

{ sourceByRegex = src: regexes: builtins.filterSource (path: type:
      let relPath = lib.removePrefix (toString src + "/") (toString path);
      in builtins.match (concatStringsSep "|" (map (r: "(${r})") regexes)) relPath != null)
    src;
}

But I'm not sure so this has to be benchmarked. But we can always do that later.

Regarding tests, I see there's <nixpkgs/lib/tests/release.nix>. Maybe you can hook up a test in there?

@teh
Copy link
Contributor Author

teh commented Feb 18, 2017

I'm not a huge fan of concatStringsSep "|" because that breaks when users use | in their own regex. If speed becomes an issue I think we should move this to builtins. What do you think?

@basvandijk
Copy link
Member

I did put parenthesis around the individual regexes so that the | from users didn't clash. Although I agree that speed isn't a big priority now.

@teh
Copy link
Contributor Author

teh commented Feb 18, 2017

nix-build pkgs/top-level/release.nix -A lib-tests does something but it always succeeds, even if I intentionally break a test.

Even with parenthesis I can write )|( . It's unlikely but I don't feel we need to introduce a potentially unsound behaviour when the number of regexes is usually pretty small, and we always have the escape hatch of introducing a builtin.

@basvandijk
Copy link
Member

Ok agreed.

@domenkozar domenkozar merged commit 50da0b3 into NixOS:master Feb 19, 2017
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.

None yet

4 participants