-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Easily filter directories based on a simple whitelist of paths: ``` std.path.filter [ "some/dir" "some/other/file" ] ./some/dir ``` `std.set.filter` returns a store path with the filtered directories contents. This is useful for quickly collecting paths in a large repository, e.g. a mono-repo. If the second argument is not a directory, it will simply return a store path with an empty file (same as passing a constant `false` value to a `builtins.path` filter. If a directory is in the list, it's entire contents are added. This function is used to offer a simple API in the TOML manifest to include filtered source files as dependencies available at `atom.src`: ```toml [src] binSrcA = ["paths" "to" "include"] binSrcB = ["some" "other" "paths"] ```
- Loading branch information
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
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,29 @@ | ||
paths: path: | ||
let | ||
f = | ||
dir: | ||
let | ||
pred = builtins.elem dir paths; | ||
next = f (dirOf dir); | ||
in | ||
dir != "." && (pred || next); | ||
|
||
type = builtins.readFileType path; | ||
name = | ||
let | ||
s = std.string.split "-" path; | ||
pred = builtins.match "^${builtins.storeDir}/.*" (toString path) == null; | ||
in | ||
if pred || builtins.length s < 2 then baseNameOf path else builtins.elemAt s 1; | ||
in | ||
builtins.path { | ||
inherit path name; | ||
filter = | ||
p: t: | ||
let | ||
frag = builtins.match "^${toString path}/(.*)" p; | ||
frag' = builtins.head frag; | ||
pred = if frag == null then false else builtins.elem frag' paths; | ||
in | ||
(t == "directory" && type == "directory" && pred) || f (dirOf frag'); | ||
} |
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,5 @@ | ||
sep: str: | ||
let | ||
p = builtins.split sep (toString str); | ||
in | ||
builtins.filter (x: builtins.typeOf x == "string") p |