summaryrefslogtreecommitdiffstats
path: root/lib/sources.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-02-21 12:36:42 +0100
committerRobert Hensing <robert@roberthensing.nl>2021-05-29 16:03:55 +0200
commit4cf56e56405a226d8b21e8643e32a10b60930ae9 (patch)
tree92e5323c12a13a6436f3b179d9172115d916a17d /lib/sources.nix
parent4a025692d1daf90b3a9cefe2d996e163e1ad05d3 (diff)
lib.sources.trace: init
Diffstat (limited to 'lib/sources.nix')
-rw-r--r--lib/sources.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index 407f9d21b8bc..407829b547b0 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -12,6 +12,7 @@ let
tryEval
;
inherit (lib)
+ boolToString
filter
getAttr
isString
@@ -90,6 +91,29 @@ let
name = if name != null then name else orig.name;
};
+ /*
+ Add logging to a source, for troubleshooting the filtering behavior.
+ Type:
+ sources.trace :: sourceLike -> Source
+ */
+ trace =
+ # Source to debug. The returned source will behave like this source, but also log its filter invocations.
+ src:
+ let
+ attrs = toSourceAttributes src;
+ in
+ fromSourceAttributes (
+ attrs // {
+ filter = path: type:
+ let
+ r = attrs.filter path type;
+ in
+ builtins.trace "${attrs.name}.filter ${path} = ${boolToString r}" r;
+ }
+ ) // {
+ satisfiesSubpathInvariant = src ? satisfiesSubpathInvariant && src.satisfiesSubpathInvariant;
+ };
+
# Filter sources by a list of regular expressions.
#
# E.g. `src = sourceByRegex ./my-subproject [".*\.py$" "^database.sql$"]`
@@ -233,5 +257,7 @@ in {
sourceByRegex
sourceFilesBySuffices
+
+ trace
;
}