From 4141be04fe0f3d76ab18268729eee09f070614e9 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 2 Aug 2023 12:05:18 -0700 Subject: [PATCH] stdenv: use shallow checking for meta.platforms (deep for bad*Platforms) --- lib/meta.nix | 12 ++++++------ pkgs/stdenv/generic/check-meta.nix | 24 +++++++++++------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/meta.nix b/lib/meta.nix index 46f101db1e17c..e3a7faf568ff9 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -111,20 +111,20 @@ rec { /* Check a platform against an availability. - An availability is an attrset with two attributes: - - `bad`: a list of platform patterns accepted by platformMatch - - `only`: a list of lists of platform patterns accepted by platformMatch + An availability is an attrset with two attributes `bad` and + `only`; each is a list of platform patterns accepted by + platformMatch. To match the availability, both of the following must be true: - The platform must not match any element of `bad` - - For each sublist of `only`, the platform must match at least one element of the sublist. + - If `only` is nonempty, the platform must match at least one element of the sublist. */ checkAvailability = platform: availability: # Must not match any of availability.bad !(lib.any (elem: platformMatch platform elem) (availability.bad or [])) - # For all sublists of availability.only, must match at least one sublist element - && lib.all (sublist: lib.any (elem: platformMatch platform elem) sublist) (availability.only or []) + # If availability.only is non-empty, must match at least one sublist element + && availability?only -> ((builtins.length availability.only != 0) -> lib.any (elem: platformMatch platform elem) availability.only) ; /* Get the corresponding attribute in lib.licenses diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 84c5c32cc0bb7..7b25763a2c8d5 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -66,7 +66,7 @@ let }; checkHostPlatform = checkAvailability hostPlatform { bad = (attrs.meta.badPlatforms or []) ++ (attrs.meta.badHostPlatforms or []); - only = lib.optionals (attrs?meta.platforms) [ attrs.meta.platforms ]; + only = lib.optionals (attrs?meta.platforms && attrs.meta.platforms != lib.platforms.all) attrs.meta.platforms; }; checkTargetPlatform = checkAvailability targetPlatform { bad = attrs.meta.badTargetPlatforms or []; @@ -483,16 +483,17 @@ let availability = let meta = attrs.meta or {}; in { build = { bad = lexicographicUniques ( - (map (pkg: pkg.meta.availability.host.bad or []) referencesOnBuild) ++ - (map (pkg: pkg.meta.availability.build.bad or []) referencesOnHost) ++ - [ (meta.badBuildPlatforms or []) ] + (meta.badBuildPlatforms or []) ++ + (builtins.concatMap (pkg: pkg.meta.availability.build.bad or []) referencesOnHost) ++ + (builtins.concatMap (pkg: pkg.meta.availability.host.bad or []) referencesOnBuild) ); }; host = { bad = lexicographicUniques ( - (map (pkg: pkg.meta.availability.target.bad or []) referencesOnBuild) ++ - (map (pkg: pkg.meta.availability.host.bad or []) referencesOnHost) ++ - [ (meta.badPlatforms or []) ] + (meta.badPlatforms or []) ++ + (meta.badHostPlatforms or []) ++ + (builtins.concatMap (pkg: pkg.meta.availability.host.bad or []) referencesOnHost) ++ + (builtins.concatMap (pkg: pkg.meta.availability.target.bad or []) referencesOnBuild) ); # "host.only" is needed to represent the (deprecated, @@ -504,14 +505,12 @@ let # There are no build.only or target.only attrsets because # we (thankfully) don't have meta.platforms equivalents # for those. - only = ( - (lib.optionals (meta?platforms && meta.platforms != lib.platforms.all) [ meta.platforms ]) - ); + only = lib.optionals (meta?platforms && meta.platforms != lib.platforms.all) meta.platforms; }; target = { bad = lexicographicUniques ( - (map (pkg: pkg.meta.availability.target.bad or []) referencesOnHost) ++ - [ (meta.badTargetPlatforms or []) ] + (meta.badTargetPlatforms or []) ++ + (builtins.concatMap (pkg: pkg.meta.availability.target.bad or []) referencesOnHost) ); }; }; @@ -534,7 +533,6 @@ let # O(n log n) # TODO(amjoseph@): possibly move to /lib/ lexicographicUniques = lists: lib.pipe lists [ - builtins.concatLists # O(n) (map (x: assert (lib.isAttrs x || lib.isString x); x)) (lib.sort (x: y: lexicographicCompare x y < 0)) # O(n log n) sortedUnique # O(n)