replace-dependency.nix: new feature

When replace-dependency is given a drv that doesn't actually depend on oldDependency, then just return back the original drv but also issue a warning.
This commit is contained in:
Russell O'Connor 2015-11-15 19:52:30 -05:00 committed by Russell O'Connor
parent 7ae05edcdd
commit 782cfe94b0

View File

@ -17,11 +17,12 @@
# }; # };
# This will rebuild glibc with your security patch, then copy over firefox # This will rebuild glibc with your security patch, then copy over firefox
# (and all of its dependencies) without rebuilding further. # (and all of its dependencies) without rebuilding further.
{ drv, oldDependency, newDependency }: { drv, oldDependency, newDependency, verbose ? true }:
with lib; with lib;
let let
warn = if verbose then builtins.trace else (x:y:y);
references = import (runCommand "references.nix" { exportReferencesGraph = [ "graph" drv ]; } '' references = import (runCommand "references.nix" { exportReferencesGraph = [ "graph" drv ]; } ''
(echo { (echo {
while read path while read path
@ -78,4 +79,6 @@ let
(filter dependsOnOld (builtins.attrNames references))) // rewrittenDeps; (filter dependsOnOld (builtins.attrNames references))) // rewrittenDeps;
in assert (stringLength (drvName (toString oldDependency)) == stringLength (drvName (toString newDependency))); in assert (stringLength (drvName (toString oldDependency)) == stringLength (drvName (toString newDependency)));
getAttr (discard (toString drv)) rewriteMemo if hasAttr (discard (toString drv)) rewriteMemo
then getAttr (discard (toString drv)) rewriteMemo
else warn "replace-dependency.nix: derivation ${discard (toString drv)} does not depend on ${discard (toString oldDependency)}\n" drv