diff options
author | Profpatsch <mail@profpatsch.de> | 2018-04-02 18:30:21 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2018-04-27 18:59:39 +0200 |
commit | a7fdd10bf321f2db45c7fcdb79a39d7bc75bb828 (patch) | |
tree | e0be4d140d5344c301814a5374494707e03bee72 /lib/debug.nix | |
parent | a455637d28fb209a4677f55d887aa91ca05ed44e (diff) |
lib/debug: deprecate & modernize showVal
The code is re-implemented in terms of `generators.toPretty`, but is strictly
less general than `traceValSeqN`, so we deprecate it.
Diffstat (limited to 'lib/debug.nix')
-rw-r--r-- | lib/debug.nix | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/debug.nix b/lib/debug.nix index 7eaa1bd9c8b1..2e052ba31d85 100644 --- a/lib/debug.nix +++ b/lib/debug.nix @@ -56,19 +56,25 @@ rec { traceShowVal = x: trace (showVal x) x; traceShowValMarked = str: x: trace (str + showVal x) x; attrNamesToStr = a: lib.concatStringsSep "; " (map (x: "${x}=") (attrNames a)); - showVal = x: - if isAttrs x then - if x ? outPath then "x is a derivation, name ${if x ? name then x.name else "<no name>"}, { ${attrNamesToStr x} }" - else "x is attr set { ${attrNamesToStr x} }" - else if isFunction x then "x is a function" - else if x == [] then "x is an empty list" - else if isList x then "x is a list, first element is: ${showVal (head x)}" - else if x == true then "x is boolean true" - else if x == false then "x is boolean false" - else if x == null then "x is null" - else if isInt x then "x is an integer `${toString x}'" - else if isString x then "x is a string `${substring 0 50 x}...'" - else "x is probably a path `${substring 0 50 (toString x)}...'"; + showVal = with lib; + trace ( "Warning: `showVal` is deprecated " + + "and will be removed in the next release, " + + "please use `traceSeqN`" ) + (let + modify = v: + let pr = f: { __pretty = f; val = v; }; + in if isDerivation v then pr + (drv: "<δ:${drv.name}:${concatStringsSep "," + (attrNames drv)}>") + else if [] == v then pr (const "[]") + else if isList v then pr (l: "[ ${go (head l)}, … ]") + else if isAttrs v then pr + (a: "{ ${ concatStringsSep ", " (attrNames a)} }") + else v; + go = x: generators.toPretty + { allowPrettyValues = true; } + (modify x); + in go); # trace the arguments passed to function and its result # maybe rewrite these functions in a traceCallXml like style. Then one function is enough |