about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2019-05-10T20·39-0400
committerGraham Christensen <graham@grahamc.com>2019-05-12T17·17-0400
commitc78686e411e0a14cff51836fe6c35d7584171df3 (patch)
tree25786768998e25f72a2d41c2004e1b0041d96335 /src/libstore
parent7c6391ddc730519a632cc0ee526c94a04812d871 (diff)
build: run diff-hook under --check and document diff-hook
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 91eb97dfb873..026828c535ca 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -461,6 +461,19 @@ static void commonChildInit(Pipe & logPipe)
     close(fdDevNull);
 }
 
+void handleDiffHook(Path tryA, Path tryB, Path drvPath)
+{
+    auto diffHook = settings.diffHook;
+    if (diffHook != "" && settings.runDiffHook) {
+        try {
+            auto diff = runProgram(diffHook, true, {tryA, tryB, drvPath});
+            if (diff != "")
+                printError(chomp(diff));
+        } catch (Error & error) {
+            printError("diff hook execution failed: %s", error.what());
+        }
+    }
+}
 
 //////////////////////////////////////////////////////////////////////
 
@@ -3039,8 +3052,7 @@ void DerivationGoal::registerOutputs()
     InodesSeen inodesSeen;
 
     Path checkSuffix = ".check";
-    bool runDiffHook = settings.runDiffHook;
-    bool keepPreviousRound = settings.keepFailed || runDiffHook;
+    bool keepPreviousRound = settings.keepFailed || settings.runDiffHook;
 
     std::exception_ptr delayedException;
 
@@ -3185,11 +3197,14 @@ void DerivationGoal::registerOutputs()
             if (!worker.store.isValidPath(path)) continue;
             auto info = *worker.store.queryPathInfo(path);
             if (hash.first != info.narHash) {
+                handleDiffHook(path, actualPath, drvPath);
+
                 if (settings.keepFailed) {
                     Path dst = worker.store.toRealPath(path + checkSuffix);
                     deletePath(dst);
                     if (rename(actualPath.c_str(), dst.c_str()))
                         throw SysError(format("renaming '%1%' to '%2%'") % actualPath % dst);
+
                     throw Error(format("derivation '%1%' may not be deterministic: output '%2%' differs from '%3%'")
                         % drvPath % path % dst);
                 } else
@@ -3254,16 +3269,7 @@ void DerivationGoal::registerOutputs()
                     ? fmt("output '%1%' of '%2%' differs from '%3%' from previous round", i->second.path, drvPath, prev)
                     : fmt("output '%1%' of '%2%' differs from previous round", i->second.path, drvPath);
 
-                auto diffHook = settings.diffHook;
-                if (prevExists && diffHook != "" && runDiffHook) {
-                    try {
-                        auto diff = runProgram(diffHook, true, {prev, i->second.path});
-                        if (diff != "")
-                            printError(chomp(diff));
-                    } catch (Error & error) {
-                        printError("diff hook execution failed: %s", error.what());
-                    }
-                }
+                handleDiffHook(prev, i->second.path, drvPath);
 
                 if (settings.enforceDeterminism)
                     throw NotDeterministic(msg);