mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-03-06 23:31:34 +00:00
devShellTools.unstructuredDerivationInputEnv: Return attrsOf str
... and test it.
This commit is contained in:
parent
43df2b50f9
commit
33aaac17c5
pkgs/build-support/dev-shell-tools
|
@ -25,7 +25,7 @@ rec {
|
|||
(name: value:
|
||||
let str = valueToString value;
|
||||
in if lib.elem name (drvAttrs.passAsFile or [])
|
||||
then lib.nameValuePair "${name}Path" (writeText "pass-as-text-${name}" str)
|
||||
then lib.nameValuePair "${name}Path" "${writeText "pass-as-text-${name}" str}"
|
||||
else lib.nameValuePair name str
|
||||
)
|
||||
drvAttrs;
|
||||
|
|
|
@ -4,9 +4,16 @@
|
|||
lib,
|
||||
stdenv,
|
||||
hello,
|
||||
writeText,
|
||||
runCommand, zlib,
|
||||
}:
|
||||
let
|
||||
inherit (lib) escapeShellArg;
|
||||
inherit (lib)
|
||||
concatLines
|
||||
escapeShellArg
|
||||
isString
|
||||
mapAttrsToList
|
||||
;
|
||||
in
|
||||
{
|
||||
# nix-build -A tests.devShellTools.valueToString
|
||||
|
@ -42,4 +49,99 @@ in
|
|||
) >log 2>&1 || { cat log; exit 1; }
|
||||
'';
|
||||
};
|
||||
|
||||
# nix-build -A tests.devShellTools.valueToString
|
||||
unstructuredDerivationInputEnv =
|
||||
let
|
||||
inherit (devShellTools) unstructuredDerivationInputEnv;
|
||||
|
||||
drvAttrs = {
|
||||
one = 1;
|
||||
boolTrue = true;
|
||||
boolFalse = false;
|
||||
foo = "foo";
|
||||
list = [ 1 2 3 ];
|
||||
pathDefaultNix = ./default.nix;
|
||||
stringWithDep = "Exe: ${hello}/bin/hello";
|
||||
aPackageAttrSet = hello;
|
||||
anOutPath = hello.outPath;
|
||||
anAnAlternateOutput = zlib.dev;
|
||||
|
||||
passAsFile = [ "bar" ];
|
||||
bar = ''
|
||||
bar
|
||||
${writeText "qux" "yea"}
|
||||
'';
|
||||
};
|
||||
result = unstructuredDerivationInputEnv { inherit drvAttrs; };
|
||||
in
|
||||
assert result // { barPath = "<check later>"; } == {
|
||||
one = "1";
|
||||
boolTrue = "1";
|
||||
boolFalse = "";
|
||||
foo = "foo";
|
||||
list = "1 2 3";
|
||||
pathDefaultNix = "${./default.nix}";
|
||||
stringWithDep = "Exe: ${hello}/bin/hello";
|
||||
aPackageAttrSet = "${hello}";
|
||||
anOutPath = "${hello.outPath}";
|
||||
anAnAlternateOutput = "${zlib.dev}";
|
||||
|
||||
passAsFile = "bar";
|
||||
barPath = "<check later>";
|
||||
};
|
||||
|
||||
# Not runCommand, because it alters `passAsFile`
|
||||
stdenv.mkDerivation ({
|
||||
name = "devShellTools-unstructuredDerivationInputEnv-built-tests";
|
||||
|
||||
exampleBarPathString =
|
||||
assert isString result.barPath;
|
||||
result.barPath;
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
dontFixup = true;
|
||||
doCheck = true;
|
||||
|
||||
installPhase = "touch $out";
|
||||
|
||||
checkPhase = ''
|
||||
checkAttr() {
|
||||
echo checking attribute $1...
|
||||
if [[ "$2" != "$3" ]]; then
|
||||
echo "expected: $3"
|
||||
echo "actual: $2"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
${
|
||||
concatLines
|
||||
(mapAttrsToList
|
||||
(name: value:
|
||||
"checkAttr ${name} \"\$${name}\" ${escapeShellArg value}"
|
||||
)
|
||||
(removeAttrs
|
||||
result
|
||||
[
|
||||
# Nix puts it in workdir, which is not a concept for
|
||||
# unstructuredDerivationInputEnv, so we have to put it in the
|
||||
# store instead. This means the full path won't match.
|
||||
"barPath"
|
||||
])
|
||||
)
|
||||
}
|
||||
(
|
||||
set -x
|
||||
|
||||
diff $exampleBarPathString $barPath
|
||||
|
||||
# TODO nice to have, as `cp $barPath foo/` preserves the basename:
|
||||
# this is usually a mistake, so not that big a deal perhaps
|
||||
# [[ "$(basename $exampleBarPathString)" = "$(basename $barPath)" ]]
|
||||
)
|
||||
|
||||
touch $out
|
||||
'';
|
||||
} // drvAttrs);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue