fix(users/edef/depot-scan): properly trace readFile/readDir

Change-Id: I493e7d20504d34f83a53db50b69e86668874756e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1651
Reviewed-by: edef <edef@edef.eu>
Tested-by: BuildkiteCI
This commit is contained in:
edef 2020-08-05 01:48:16 +00:00
parent 88a6bea6e8
commit fcffacf8c9
3 changed files with 19 additions and 2 deletions

View file

@ -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

View file

@ -8,5 +8,5 @@ pkgs.writeShellScriptBin "depot-scan" ''
attr="''${path//\//.}" attr="''${path//\//.}"
root="$(git rev-parse --show-toplevel)" root="$(git rev-parse --show-toplevel)"
echo "scanning //$path" >&2 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
'' ''

View file

@ -3,7 +3,7 @@ use strict;
if (/^evaluating file '(.*)'$/ or if (/^evaluating file '(.*)'$/ or
/^copied source '(.*)' -> '.*'$/ or /^copied source '(.*)' -> '.*'$/ or
/^trace: lorri read: '(.*)'$/) { /^trace: depot-scan '(.*)'$/) {
print $1; print $1;
next; next;
} }