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 <sternenseemann@systemli.org>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
sterni 2024-02-13 18:00:43 +01:00 committed by clbot
parent 206742949b
commit 1608f935aa

View file

@ -59,6 +59,13 @@ rec {
"|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr attrPath}' --show-trace)" "|| (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. # Create a pipeline step from a single target.
mkStep = { headBranch, parentTargetMap, target, cancelOnBuildFailing }: mkStep = { headBranch, parentTargetMap, target, cancelOnBuildFailing }:
let let
@ -70,9 +77,7 @@ rec {
key = hashString "sha1" label; key = hashString "sha1" label;
skip = shouldSkip { inherit label drvPath parentTargetMap; }; skip = shouldSkip { inherit label drvPath parentTargetMap; };
command = mkBuildCommand { command = mkBuildCommand {
attrPath = attrPath = targetAttrPath target;
target.__readTree
++ lib.optionals (target ? __subtarget) [ target.__subtarget ];
inherit drvPath; inherit drvPath;
}; };
env.READTREE_TARGET = label; env.READTREE_TARGET = label;
@ -257,9 +262,7 @@ rec {
# Include the attrPath in the output to reconstruct the drv # Include the attrPath in the output to reconstruct the drv
# without parsing the human-readable label. # without parsing the human-readable label.
attrPath = target.__readTree ++ lib.optionals (target ? __subtarget) [ attrPath = targetAttrPath target;
target.__subtarget
];
}; };
}) })
drvTargets))); drvTargets)));