refactor(nix/buildkite): use attr path over target drv in mkBuild*
mkBuild* is independent of the target abstraction, we can just use attribute paths. That is useful because we'll want to reuse that code in order to avoid building derivations (apart from unavoidable IfD) during pipeline construction for extraSteps. Breaking Change for mkBuildExpr and mkBuildCommand. Change-Id: I03646310192087d3e50f358a714472d1ac1a652f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10848 Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
aa14e36a91
commit
206742949b
1 changed files with 14 additions and 15 deletions
|
@ -29,20 +29,14 @@ let
|
||||||
inherit (depot.nix.readTree) mkLabel;
|
inherit (depot.nix.readTree) mkLabel;
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
# Creates a Nix expression that yields the target at the specified
|
# Given an arbitrary attribute path generate a Nix expression which obtains
|
||||||
# location in the repository.
|
# this from the root of depot (assumed to be ./.). Attributes may be any
|
||||||
#
|
# Nix strings suitable as attribute names, not just Nix literal-safe strings.
|
||||||
# This makes a distinction between normal targets (which physically
|
mkBuildExpr = attrPath:
|
||||||
# exist in the repository) and subtargets (which are "virtual"
|
|
||||||
# targets exposed by a physical one) to make it clear in the build
|
|
||||||
# output which is which.
|
|
||||||
mkBuildExpr = target:
|
|
||||||
let
|
let
|
||||||
descend = expr: attr: "builtins.getAttr \"${attr}\" (${expr})";
|
descend = expr: attr: "builtins.getAttr \"${attr}\" (${expr})";
|
||||||
targetExpr = foldl' descend "import ./. {}" target.__readTree;
|
|
||||||
subtargetExpr = descend targetExpr target.__subtarget;
|
|
||||||
in
|
in
|
||||||
if target ? __subtarget then subtargetExpr else targetExpr;
|
foldl' descend "import ./. {}" attrPath;
|
||||||
|
|
||||||
# Determine whether to skip a target if it has not diverged from the
|
# Determine whether to skip a target if it has not diverged from the
|
||||||
# HEAD branch.
|
# HEAD branch.
|
||||||
|
@ -51,8 +45,8 @@ rec {
|
||||||
then "Target has not changed."
|
then "Target has not changed."
|
||||||
else false;
|
else false;
|
||||||
|
|
||||||
# Create build command for a derivation target.
|
# Create build command for an attribute path pointing to a derivation.
|
||||||
mkBuildCommand = { target, drvPath }: concatStringsSep " " [
|
mkBuildCommand = { attrPath, drvPath }: concatStringsSep " " [
|
||||||
# First try to realise the drvPath of the target so we don't evaluate twice.
|
# First try to realise the drvPath of the target so we don't evaluate twice.
|
||||||
# Nix has no concept of depending on a derivation file without depending on
|
# Nix has no concept of depending on a derivation file without depending on
|
||||||
# at least one of its `outPath`s, so we need to discard the string context
|
# at least one of its `outPath`s, so we need to discard the string context
|
||||||
|
@ -62,7 +56,7 @@ rec {
|
||||||
# Since we don't gcroot the derivation files, they may be deleted by the
|
# Since we don't gcroot the derivation files, they may be deleted by the
|
||||||
# garbage collector. In that case we can reevaluate and build the attribute
|
# garbage collector. In that case we can reevaluate and build the attribute
|
||||||
# using nix-build.
|
# using nix-build.
|
||||||
"|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr target}' --show-trace)"
|
"|| (test ! -f '${drvPath}' && nix-build -E '${mkBuildExpr attrPath}' --show-trace)"
|
||||||
];
|
];
|
||||||
|
|
||||||
# Create a pipeline step from a single target.
|
# Create a pipeline step from a single target.
|
||||||
|
@ -75,7 +69,12 @@ rec {
|
||||||
label = ":nix: " + label;
|
label = ":nix: " + label;
|
||||||
key = hashString "sha1" label;
|
key = hashString "sha1" label;
|
||||||
skip = shouldSkip { inherit label drvPath parentTargetMap; };
|
skip = shouldSkip { inherit label drvPath parentTargetMap; };
|
||||||
command = mkBuildCommand { inherit target drvPath; };
|
command = mkBuildCommand {
|
||||||
|
attrPath =
|
||||||
|
target.__readTree
|
||||||
|
++ lib.optionals (target ? __subtarget) [ target.__subtarget ];
|
||||||
|
inherit drvPath;
|
||||||
|
};
|
||||||
env.READTREE_TARGET = label;
|
env.READTREE_TARGET = label;
|
||||||
cancel_on_build_failing = cancelOnBuildFailing;
|
cancel_on_build_failing = cancelOnBuildFailing;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue