feat(nix/utils): handle toString-able sets produced by builtins.path
When preparing cl/4381 I noticed that we actually handle this case properly. depot.nix.utils.storePathName depot.path now works as expected. Change-Id: Ice9329c67b2e2210852012f5abe82fbbb13193de Reviewed-on: https://cl.tvl.fyi/c/depot/+/4382 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in> Autosubmit: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
e25ef08c45
commit
887ac4d3d4
2 changed files with 8 additions and 3 deletions
|
@ -21,17 +21,18 @@ let
|
||||||
then p.name
|
then p.name
|
||||||
else if builtins.isPath p
|
else if builtins.isPath p
|
||||||
then builtins.baseNameOf p
|
then builtins.baseNameOf p
|
||||||
else if builtins.isString p
|
else if builtins.isString p || (builtins.isAttrs p && (p ? outPath || p ? __toString))
|
||||||
then
|
then
|
||||||
let
|
let
|
||||||
|
strPath = toString p;
|
||||||
# strip leading storeDir and trailing slashes
|
# strip leading storeDir and trailing slashes
|
||||||
noStoreDir = lib.removeSuffix "/"
|
noStoreDir = lib.removeSuffix "/"
|
||||||
(lib.removePrefix "${builtins.storeDir}/" p);
|
(lib.removePrefix "${builtins.storeDir}/" strPath);
|
||||||
# a basename of a child of a store path isn't really
|
# a basename of a child of a store path isn't really
|
||||||
# referring to a store path, so removing the string
|
# referring to a store path, so removing the string
|
||||||
# context is safe (e. g. "hello" for "${hello}/bin/hello").
|
# context is safe (e. g. "hello" for "${hello}/bin/hello").
|
||||||
basename = builtins.unsafeDiscardStringContext
|
basename = builtins.unsafeDiscardStringContext
|
||||||
(builtins.baseNameOf p);
|
(builtins.baseNameOf strPath);
|
||||||
in
|
in
|
||||||
# If p is a direct child of storeDir, we need to remove
|
# If p is a direct child of storeDir, we need to remove
|
||||||
# the leading hash as well to make sure that:
|
# the leading hash as well to make sure that:
|
||||||
|
|
|
@ -85,6 +85,8 @@ let
|
||||||
cheddarStorePath =
|
cheddarStorePath =
|
||||||
builtins.unsafeDiscardStringContext depot.tools.cheddar.outPath;
|
builtins.unsafeDiscardStringContext depot.tools.cheddar.outPath;
|
||||||
|
|
||||||
|
cleanedSource = lib.cleanSource ./.;
|
||||||
|
|
||||||
storePathNameTests = it "correctly gets the basename of a store path" [
|
storePathNameTests = it "correctly gets the basename of a store path" [
|
||||||
(assertEq "base name of a derivation"
|
(assertEq "base name of a derivation"
|
||||||
(storePathName depot.tools.cheddar) depot.tools.cheddar.name)
|
(storePathName depot.tools.cheddar) depot.tools.cheddar.name)
|
||||||
|
@ -94,6 +96,8 @@ let
|
||||||
(storePathName "${cheddarStorePath}/bin/cheddar") "cheddar")
|
(storePathName "${cheddarStorePath}/bin/cheddar") "cheddar")
|
||||||
(assertEq "base name of a path"
|
(assertEq "base name of a path"
|
||||||
(storePathName ../default.nix) "default.nix")
|
(storePathName ../default.nix) "default.nix")
|
||||||
|
(assertEq "base name of a cleanSourced path"
|
||||||
|
(storePathName cleanedSource) cleanedSource.name)
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue