Commit 7ba63c64 authored by Yueh-Shun Li's avatar Yueh-Shun Li
Browse files

testers.invalidateFetcherByDrvHash: use overrideAttrs if fetcher ignore name arguments

parent cb39a53e
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -132,7 +132,8 @@
  invalidateFetcherByDrvHash =
    f: args:
    let
      drvPath = (f args).drvPath;
      unsalted = f args;
      drvPath = unsalted.drvPath;
      # It's safe to discard the context, because we don't access the path.
      salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath));
      saltName = name: "${name}-salted-${salt}";
@@ -143,14 +144,23 @@
        else
          { name = saltName args.name or "source"; };
      # New derivation incorporating the original drv hash in the name
      salted = f (args // getSaltedNames args);
      # Make sure we did change the derivation. If the fetcher ignores `name`,
      saltedByArgs = f (args // getSaltedNames args);
      saltedByOverrideAttrs = unsalted.overrideAttrs (previousAttrs: getSaltedNames previousAttrs);
      saltedByOverrideAttrsForced = unsalted.overrideAttrs (previousAttrs: {
        name = saltName unsalted.name;
      });
      # Make sure we did change the derivation.
      # If the fetcher ignores `pname` and `name` and provide a broken `overrideAttrs`,
      # `invalidateFetcherByDrvHash` doesn't work.
      checked =
        if salted.drvPath == drvPath then
          throw "invalidateFetcherByDrvHash: Adding the derivation hash to the fixed-output derivation name had no effect. Make sure the fetcher's name argument ends up in the derivation name. Otherwise, the fetcher will not be re-run when its implementation changes. This is important for testing."
        if saltedByArgs.drvPath != drvPath then
          saltedByArgs
        else if saltedByOverrideAttrs.drvPath != drvPath then
          saltedByOverrideAttrs
        else if saltedByOverrideAttrsForced.drvPath != drvPath then
          saltedByOverrideAttrsForced
        else
          salted;
          throw "invalidateFetcherByDrvHash: Neither adding pname/name to the fetcher args nor overriding with overrideAttrs change the result drvPath.";
    in
    checked;