From 1608f935aad2696f38231ef779bffc1f5ac31fec Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 13 Feb 2024 18:00:43 +0100 Subject: [PATCH] refactor(nix/buildkite): unify target attr path calculation After the previous refactor that made mkBuildExpr use attribute paths, mkStep and mkDrvMap can now share the code for calculating the attribute path of any given target. Change-Id: I50f9687e85c3b4407e4a55ff7e645db882bb80d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10849 Autosubmit: sterni Reviewed-by: tazjin Tested-by: BuildkiteCI --- nix/buildkite/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index e45deade4..45af87784 100644 --- a/nix/buildkite/default.nix +++ b/nix/buildkite/default.nix @@ -59,6 +59,13 @@ rec { "|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr attrPath}' --show-trace)" ]; + # Attribute path of a target relative to the depot root. Needs to take into + # account whether the target is a physical target (which corresponds to a path + # in the filesystem) or the subtarget of a physical target. + targetAttrPath = target: + target.__readTree + ++ lib.optionals (target ? __subtarget) [ target.__subtarget ]; + # Create a pipeline step from a single target. mkStep = { headBranch, parentTargetMap, target, cancelOnBuildFailing }: let @@ -70,9 +77,7 @@ rec { key = hashString "sha1" label; skip = shouldSkip { inherit label drvPath parentTargetMap; }; command = mkBuildCommand { - attrPath = - target.__readTree - ++ lib.optionals (target ? __subtarget) [ target.__subtarget ]; + attrPath = targetAttrPath target; inherit drvPath; }; env.READTREE_TARGET = label; @@ -257,9 +262,7 @@ rec { # Include the attrPath in the output to reconstruct the drv # without parsing the human-readable label. - attrPath = target.__readTree ++ lib.optionals (target ? __subtarget) [ - target.__subtarget - ]; + attrPath = targetAttrPath target; }; }) drvTargets)));