1
0
Fork 0

Extend getSrc to allow specifying subtrees of sources.

Using ${l.src dir} will include the whole subtree as a dependency.
master
Michael Raitza 2021-02-18 22:28:04 +01:00
parent 69bd805cc6
commit 5e3b992c6f
2 changed files with 17 additions and 7 deletions

View File

@ -20,7 +20,7 @@ let
funcPkgs = {
__functor = self: arg: resolve arg;
src = getSrc root rcwd filter;
inherit pkgs cwd rcwd;
inherit pkgs cwd rcwd d1 d2;
};
_builder = let

22
lib.nix
View File

@ -1,10 +1,10 @@
{ lib ? import <nixpkgs/lib> }:
let
inherit (builtins) baseNameOf dirOf length genList pathExists filterSource
isString match replaceStrings;
isString match replaceStrings stringLength;
inherit (lib) take splitString concatStringsSep last foldl foldr head tail
singleton removePrefix hasSuffix removeSuffix flatten crossLists reverseList
all any unique;
all any unique hasPrefix;
butlast = list: take (length list - 1) list;
doFileSuffix = "do";
@ -77,7 +77,7 @@ let
# Add all preceding paths to a src down to the root. Otherwise
# builtins.filterSource will reject it.
augmentedSrcs = root: srcs: let
aug = map (s: singleton s ++ (map (p: root + (removeSuffix "/" p)) (genPathlist (removePrefix root s)))) srcs;
aug = map (s: (map (p: root + (removeSuffix "/" p)) (genPathlist (removePrefix root s)))) srcs;
in unique (flatten aug);
# The source tree resolver combinator.
@ -90,15 +90,25 @@ let
captureFunc (resolveSrc root rcwd) (srcs: let
rejector = path: (all (x: path != x) rejected);
# If a src in srcs is a prefix to a that (it must be a dir, then, or the
# file itself), allow all sub-paths.
srcFilter = path:
if srcs == []
then true
else (any (x: (hasPrefix x path)) srcs);
# Allow all directories lying on the way to specified srcs.
_srcs = (augmentedSrcs root srcs);
srcFilter = path: if srcs == []
srcDirFilter = path: if srcs == []
then true # No explicit srcs means: Take the whole source tree!
else (any (x: path == x) _srcs);
else (any (x: path == x) (_srcs));
filter = (path: type:
(baseNameOf path != ".git") &&
(baseNameOf path != ".envrc") &&
(rejector path) &&
(srcFilter path));
((srcFilter path) ||
(srcDirFilter path)));
in (builtins.filterSource filter root));
self = {