From fcffacf8c9246c7b83d90164bedb50f488ca5baa Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 5 Aug 2020 01:48:16 +0000 Subject: [PATCH] fix(users/edef/depot-scan): properly trace readFile/readDir Change-Id: I493e7d20504d34f83a53db50b69e86668874756e Reviewed-on: https://cl.tvl.fyi/c/depot/+/1651 Reviewed-by: edef Tested-by: BuildkiteCI --- users/edef/depot-scan-wrap.nix | 17 +++++++++++++++++ users/edef/depot-scan.nix | 2 +- users/edef/depot-scan.pl | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 users/edef/depot-scan-wrap.nix diff --git a/users/edef/depot-scan-wrap.nix b/users/edef/depot-scan-wrap.nix new file mode 100644 index 000000000..52ea5cc85 --- /dev/null +++ b/users/edef/depot-scan-wrap.nix @@ -0,0 +1,17 @@ +# this wraps import to override readFile and readDir to trace the files it touches +# technique inspired by lorri +{ ... }: + +let + + global = { + import = global.scopedImport {}; + scopedImport = x: builtins.scopedImport (global // x); + builtins = builtins // { + inherit (global) import scopedImport; + readFile = path: builtins.trace "depot-scan '${toString path}'" (builtins.readFile path); + readDir = path: builtins.trace "depot-scan '${toString path}'" (builtins.readDir path); + }; + }; + +in global.import diff --git a/users/edef/depot-scan.nix b/users/edef/depot-scan.nix index ce0f8d979..f0654188c 100644 --- a/users/edef/depot-scan.nix +++ b/users/edef/depot-scan.nix @@ -8,5 +8,5 @@ pkgs.writeShellScriptBin "depot-scan" '' attr="''${path//\//.}" root="$(git rev-parse --show-toplevel)" echo "scanning //$path" >&2 - nix-instantiate "$root" -A "$attr" -vv 2> >(${pkgs.perl}/bin/perl ${./depot-scan.pl}) >&2 + nix-instantiate -E "import ${./depot-scan-wrap.nix} {} $root" -A "$attr" -vv 2> >(${pkgs.perl}/bin/perl ${./depot-scan.pl}) >&2 '' diff --git a/users/edef/depot-scan.pl b/users/edef/depot-scan.pl index 39550d83c..8808e2eb0 100755 --- a/users/edef/depot-scan.pl +++ b/users/edef/depot-scan.pl @@ -3,7 +3,7 @@ use strict; if (/^evaluating file '(.*)'$/ or /^copied source '(.*)' -> '.*'$/ or - /^trace: lorri read: '(.*)'$/) { + /^trace: depot-scan '(.*)'$/) { print $1; next; }