diff options
author | Jan Tojnar <jtojnar@gmail.com> | 2020-05-13 10:29:01 +0200 |
---|---|---|
committer | Jan Tojnar <jtojnar@gmail.com> | 2020-05-13 12:12:18 +0200 |
commit | 3f3aeb7c85fb5b7e6b9e950aed3a36a0e65e8bde (patch) | |
tree | 3bc8dc6d08fc2f19ae48ff6f51bd0ecce3a14184 /maintainers/scripts | |
parent | fab2ee8c10c2d39310c8e3cdddde9fd118727063 (diff) |
maintainers/scripts/update.nix: refactor package collector
The `packagesWith` function expected an attrSet but `packagesWithUpdateScript`
could be passing it a derivation or a list when the attribute path
supplied by user through the `--argstr path` argument pointed to one.
It only worked because derivations are also attrSets and contain their
outputs as attributes, and did not work for lists at all.
Additionally, the improper handling would cause the `src` attribute
to be built in some rare cases (`mkYarnPackage` seems to trigger this).
Rewriting the `packagesWith` function to be inductive with a derivation
as a base case and attrSets and lists as inductive steps is much cleaner
and also fixes the unnecessary build.
Diffstat (limited to 'maintainers/scripts')
-rwxr-xr-x | maintainers/scripts/update.nix | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/maintainers/scripts/update.nix b/maintainers/scripts/update.nix index 492000a10377..66ea18ddf62e 100755 --- a/maintainers/scripts/update.nix +++ b/maintainers/scripts/update.nix @@ -25,26 +25,29 @@ let in [x] ++ nubOn f xs; - packagesWith = cond: return: set: - nubOn (pkg: pkg.updateScript) - (lib.flatten - (lib.mapAttrsToList - (name: pkg: - let - result = builtins.tryEval ( - if lib.isDerivation pkg - then lib.optional (cond name pkg) (return name pkg) - else if pkg.recurseForDerivations or false || pkg.recurseForRelease or false - then packagesWith cond return pkg - else [] - ); - in - if result.success then result.value - else [] - ) - set - ) - ); + packagesWithPath = relativePath: cond: return: pathContent: + let + result = builtins.tryEval pathContent; + + dedupResults = lst: nubOn (pkg: pkg.updateScript) (lib.concatLists lst); + in + if result.success then + let + pathContent = result.value; + in + if lib.isDerivation pathContent then + lib.optional (cond relativePath pathContent) (return relativePath pathContent) + else if lib.isAttrs pathContent then + # If user explicitly points to an attrSet or it is marked for recursion, we recur. + if relativePath == [] || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then + dedupResults (lib.mapAttrsToList (name: elem: packagesWithPath (relativePath ++ [name]) cond return elem) pathContent) + else [] + else if lib.isList pathContent then + dedupResults (lib.imap0 (i: elem: packagesWithPath (relativePath ++ [i]) cond return elem) pathContent) + else [] + else []; + + packagesWith = packagesWithPath []; packagesWithUpdateScriptAndMaintainer = maintainer': let @@ -54,7 +57,7 @@ let else builtins.getAttr maintainer' lib.maintainers; in - packagesWith (name: pkg: builtins.hasAttr "updateScript" pkg && + packagesWith (relativePath: pkg: builtins.hasAttr "updateScript" pkg && (if builtins.hasAttr "maintainers" pkg.meta then (if builtins.isList pkg.meta.maintainers then builtins.elem maintainer pkg.meta.maintainers @@ -63,19 +66,19 @@ let else false ) ) - (name: pkg: pkg) + (relativePath: pkg: pkg) pkgs; packagesWithUpdateScript = path: let - attrSet = lib.attrByPath (lib.splitString "." path) null pkgs; + pathContent = lib.attrByPath (lib.splitString "." path) null pkgs; in - if attrSet == null then + if pathContent == null then builtins.throw "Attribute path `${path}` does not exists." else - packagesWith (name: pkg: builtins.hasAttr "updateScript" pkg) - (name: pkg: pkg) - attrSet; + packagesWith (relativePath: pkg: builtins.hasAttr "updateScript" pkg) + (relativePath: pkg: pkg) + pathContent; packageByName = name: let |