From 8b8c98380e85b2057a3c35ce3d76879fab4266b0 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 7 Feb 2022 13:46:00 +0300 Subject: 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 --- nix/readTree/default.nix | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'nix') diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix index 5d2e1fff6a..ba3363d8d6 100644 --- a/nix/readTree/default.nix +++ b/nix/readTree/default.nix @@ -158,12 +158,27 @@ let then merge nodeValue (allChildren // (marker parts allChildren)) 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 # attribute set. # # This function will gather physical targets, that is targets which # 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 # pipelines. @@ -187,7 +202,7 @@ let __readTreeChildren = [ ]; __subtarget = k; }) - (node.meta.targets or [ ])) + (subtargets node)) else [ ]; # Determine whether a given value is a derivation. @@ -249,16 +264,21 @@ in # It is often required to create the args attribute set. 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 # derivations. # # Type: attrs -> attrs - drvTargets = attrs: attrs // { - meta = { - targets = builtins.filter - (x: isDerivation attrs."${x}") - (builtins.attrNames attrs); - } // (attrs.meta or { }); - }; + drvTargets = attrs: + 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 + (x: isDerivation attrs."${x}") + (builtins.attrNames attrs); + }; + }; + }; } -- cgit 1.4.1