refactor(readTree): deprecate meta.targets for meta.ci.targets

This means that we use the meta.ci attribute more consistently.

The meta.targets attribute is still read, but prints a big, red
warning telling people to migrate to the new one.

Fixes b/176

Change-Id: Ifb4452f529cfc6bbd5018ad7374cac1c83b10045
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5238
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-02-07 13:46:00 +03:00 committed by tazjin
parent 3bde425860
commit 8b8c98380e

View file

@ -158,12 +158,27 @@ let
then merge nodeValue (allChildren // (marker parts allChildren)) then merge nodeValue (allChildren // (marker parts allChildren))
else nodeValue; else nodeValue;
# Helper function to fetch subtargets from a target. This is a
# temporary helper to warn on the use of the `meta.targets`
# attribute, which is deprecated in favour of `meta.ci.targets`.
subtargets = node:
let targets = (node.meta.targets or [ ]) ++ (node.meta.ci.targets or [ ]);
in if node ? meta.targets then
builtins.trace ''
Warning: The meta.targets attribute is deprecated.
Please move the subtargets of //${mkLabel node} to the
meta.ci.targets attribute.

''
targets else targets;
# Function which can be used to find all readTree targets within an # Function which can be used to find all readTree targets within an
# attribute set. # attribute set.
# #
# This function will gather physical targets, that is targets which # This function will gather physical targets, that is targets which
# correspond directly to a location in the repository, as well as # correspond directly to a location in the repository, as well as
# subtargets (specified in the meta.targets attribute of a node). # subtargets (specified in the meta.ci.targets attribute of a node).
# #
# This can be used to discover targets for inclusion in CI # This can be used to discover targets for inclusion in CI
# pipelines. # pipelines.
@ -187,7 +202,7 @@ let
__readTreeChildren = [ ]; __readTreeChildren = [ ];
__subtarget = k; __subtarget = k;
}) })
(node.meta.targets or [ ])) (subtargets node))
else [ ]; else [ ];
# Determine whether a given value is a derivation. # Determine whether a given value is a derivation.
@ -249,16 +264,21 @@ in
# It is often required to create the args attribute set. # It is often required to create the args attribute set.
fix = f: let x = f x; in x; fix = f: let x = f x; in x;
# Takes an attribute set and adds a meta.targets attribute to it # Takes an attribute set and adds a meta.ci.targets attribute to it
# which contains all direct children of the attribute set which are # which contains all direct children of the attribute set which are
# derivations. # derivations.
# #
# Type: attrs -> attrs # Type: attrs -> attrs
drvTargets = attrs: attrs // { drvTargets = attrs:
meta = { attrs // {
# preserve .meta from original attrs
meta = (attrs.meta or { }) // {
# preserve .meta.ci (except .targets) from original attrs
ci = (attrs.meta.ci or { }) // {
targets = builtins.filter targets = builtins.filter
(x: isDerivation attrs."${x}") (x: isDerivation attrs."${x}")
(builtins.attrNames attrs); (builtins.attrNames attrs);
} // (attrs.meta or { }); };
};
}; };
} }