feat(nix/sparseTree): allow specifying subtrees as relative paths

Passed strings will be treated as a relative path below the given root,
which is quite convenient when using depot.path by eliminating a lot of
repetition.

Change-Id: I3da6058094484f4a6ffbb84f89ad4472b502a00c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3704
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
sterni 2021-10-09 16:48:14 +02:00
parent 04f7cc3880
commit 2397fd8d56
2 changed files with 20 additions and 12 deletions

View file

@ -14,6 +14,9 @@
root: root:
# list of paths below `root` that should be # list of paths below `root` that should be
# included in the resulting directory # included in the resulting directory
#
# If path, need to refer to the actual file / directory to be included.
# If a string, it is treated as a string relative to the root.
paths: paths:
let let
@ -40,8 +43,13 @@ let
# a leading slash. Additionally some sanity checking is done. # a leading slash. Additionally some sanity checking is done.
makeSymlink = path: makeSymlink = path:
let let
strPath = toString path; withLeading = p: if builtins.substring 0 1 p == "/" then p else "/" + p;
contextPath = "${path}"; fullPath =
/**/ if builtins.isPath path then path
else if builtins.isString path then (root + withLeading path)
else builtins.throw "Unsupported path type ${builtins.typeOf path}";
strPath = toString fullPath;
contextPath = "${fullPath}";
belowRoot = builtins.substring rootLength (-1) strPath; belowRoot = builtins.substring rootLength (-1) strPath;
prefix = builtins.substring 0 rootLength strPath; prefix = builtins.substring 0 rootLength strPath;
in assert toString root == prefix; { in assert toString root == prefix; {

View file

@ -12,20 +12,20 @@ let
minimalDepot = sparseTree depot.path [ minimalDepot = sparseTree depot.path [
# general depot things # general depot things
(depot.path + "/default.nix") "default.nix"
(depot.path + "/nix/readTree") "nix/readTree"
# nixpkgs for lib and packages # nixpkgs for lib and packages
(depot.path + "/third_party/nixpkgs") "third_party/nixpkgs"
(depot.path + "/third_party/overlays") "third_party/overlays"
# bubblegum and its dependencies # bubblegum and its dependencies
(depot.path + "/web/bubblegum") "web/bubblegum"
(depot.path + "/nix/runExecline") "nix/runExecline"
(depot.path + "/nix/utils") "nix/utils"
(depot.path + "/nix/sparseTree") "nix/sparseTree"
# tvix docs for svg demo # tvix docs for svg demo
(depot.path + "/tvix/docs") "tvix/docs"
# for blog.nix # for blog.nix
(depot.path + "/users/sterni/nix") "users/sterni/nix"
]; ];
statusCodes = { statusCodes = {