Skip to content

Commit

Permalink
stdenv: use shallow checking for meta.platforms (deep for bad*Platforms)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Joseph committed Aug 2, 2023
1 parent dc7b49d commit 4141be0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
12 changes: 6 additions & 6 deletions lib/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions pkgs/stdenv/generic/check-meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down Expand Up @@ -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,
Expand All @@ -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)
);
};
};
Expand All @@ -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)
Expand Down

0 comments on commit 4141be0

Please sign in to comment.