1# Functions for copying sources to the Nix store.
2
3let lib = import ./default.nix; in
4
5rec {
6
7
8 # Bring in a path as a source, filtering out all Subversion and CVS
9 # directories, as well as backup files (*~).
10 cleanSource =
11 let filter = name: type: let baseName = baseNameOf (toString name); in ! (
12 # Filter out Subversion and CVS directories.
13 (type == "directory" && (baseName == ".git" || baseName == ".svn" || baseName == "CVS" || baseName == ".hg")) ||
14 # Filter out backup files.
15 lib.hasSuffix "~" baseName ||
16 # Filter out generates files.
17 lib.hasSuffix ".o" baseName ||
18 lib.hasSuffix ".so" baseName
19 );
20 in src: builtins.filterSource filter src;
21
22
23 # Get all files ending with the specified suffices from the given
24 # directory or its descendants. E.g. `sourceFilesBySuffices ./dir
25 # [".xml" ".c"]'.
26 sourceFilesBySuffices = path: exts:
27 let filter = name: type:
28 let base = baseNameOf (toString name);
29 in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
30 in builtins.filterSource filter path;
31
32}