refactor(nix): Move mkLabel from buildkite to readTree

This function is more generically useful than just for pipeline
construction.

A subsequent commit will use it inside of readTree itself.

Change-Id: I5eabd6f659726484667e060958865dddbc205762
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5237
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-02-07 13:24:18 +03:00 committed by tazjin
parent 98b6af02f5
commit 3bde425860
3 changed files with 15 additions and 10 deletions

View file

@ -6,7 +6,7 @@
# #
# The structure of the file that is being created is documented here: # The structure of the file that is being created is documented here:
# https://buildkite.com/docs/pipelines/defining-steps # https://buildkite.com/docs/pipelines/defining-steps
{ pkgs, ... }: { depot, pkgs, ... }:
let let
inherit (builtins) inherit (builtins)
@ -29,6 +29,7 @@ let
unsafeDiscardStringContext; unsafeDiscardStringContext;
inherit (pkgs) lib runCommandNoCC writeText; inherit (pkgs) lib runCommandNoCC writeText;
inherit (depot.nix.readTree) mkLabel;
in in
rec { rec {
# Creates a Nix expression that yields the target at the specified # Creates a Nix expression that yields the target at the specified
@ -46,13 +47,6 @@ rec {
in in
if target ? __subtarget then subtargetExpr else targetExpr; if target ? __subtarget then subtargetExpr else targetExpr;
# Create a pipeline label from the target's tree location.
mkLabel = target:
let label = concatStringsSep "/" target.__readTree;
in if target ? __subtarget
then "${label}:${target.__subtarget}"
else label;
# 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.
shouldSkip = parentTargetMap: label: drvPath: shouldSkip = parentTargetMap: label: drvPath:

View file

@ -58,6 +58,13 @@ let
__readTreeChildren = builtins.attrNames children; __readTreeChildren = builtins.attrNames children;
}; };
# Create a label from a target's tree location.
mkLabel = target:
let label = concatStringsSep "/" target.__readTree;
in if target ? __subtarget
then "${label}:${target.__subtarget}"
else label;
# Merge two attribute sets, but place attributes in `passthru` via # Merge two attribute sets, but place attributes in `passthru` via
# `overrideAttrs` for derivation targets that support it. # `overrideAttrs` for derivation targets that support it.
merge = a: b: merge = a: b:
@ -188,7 +195,7 @@ let
isDerivation = x: isAttrs x && x ? type && x.type == "derivation"; isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
in in
{ {
inherit gather; inherit gather mkLabel;
__functor = _: __functor = _:
{ path { path

View file

@ -15,9 +15,13 @@
pkgs.lib.fix (self: { pkgs.lib.fix (self: {
buildGo = import ./buildGo { inherit pkgs; }; buildGo = import ./buildGo { inherit pkgs; };
buildkite = import ./buildkite { inherit pkgs; };
readTree = import ./readTree { }; readTree = import ./readTree { };
buildkite = import ./buildkite {
inherit pkgs;
depot.nix.readTree = self.readTree;
};
besadii = import ./besadii { besadii = import ./besadii {
depot.nix.buildGo = self.buildGo; depot.nix.buildGo = self.buildGo;
}; };