Fix bug, test more, document more

This commit is contained in:
John Ericson 2022-07-14 20:22:46 -04:00
parent f3262bc216
commit 8735f55dec
3 changed files with 38 additions and 5 deletions

View file

@ -97,8 +97,12 @@ DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_vi
{
auto drvPath = store.parseStorePath(drvS);
std::set<std::string> outputs;
if (outputsS != "*")
if (outputsS != "*") {
outputs = tokenizeString<std::set<std::string>>(outputsS, ",");
if (outputs.empty())
throw Error(
"Explicit list of wanted outputs '%s' must not be empty. Consider using '*' as a wildcard meaning all outputs if no output in particular is wanted.", outputsS);
}
return {drvPath, outputs};
}

View file

@ -134,8 +134,9 @@ the Nix store. Here are the recognised types of installables:
*(Experimental, part of by the `computed-derivations` experimental feature.)*
Store derivations can be indexed with a specific output name. This
allows finer control versus just specifying a derivation (without
Store derivations can be indexed with a non-empty comma-separated list
of specific output names, or `*` meaning all ouptuts. This allows
finer control versus just specifying a derivation (without
`--derivation`) and getting all the outputs.
This is especially useful for (currently unstable) floating content

View file

@ -1,14 +1,24 @@
source common.sh
set -o pipefail
enableFeatures "computed-derivations"
restartDaemon
drv=$(nix eval -f multiple-outputs.nix --raw a.drvPath)
if nix build "$drv^not-an-output" --json; then
if nix build "$drv^not-an-output" --no-link --json; then
fail "'not-an-output' should fail to build"
fi
nix build "$drv^first" --json | jq --exit-status '
if nix build "$drv^" --no-link --json; then
fail "'empty outputs list' should fail to build"
fi
if nix build "$drv^*nope" --no-link --json; then
fail "'* must be entire string' should fail to build"
fi
nix build "$drv^first" --no-link --json | jq --exit-status '
(.[0] |
(.drvPath | match(".*multiple-outputs-a.drv")) and
(.outputs |
@ -16,3 +26,21 @@ nix build "$drv^first" --json | jq --exit-status '
(.first | match(".*multiple-outputs-a-first")) and
(has("second") | not)))
'
nix build "$drv^first,second" --no-link --json | jq --exit-status '
(.[0] |
(.drvPath | match(".*multiple-outputs-a.drv")) and
(.outputs |
(keys | length == 2) and
(.first | match(".*multiple-outputs-a-first")) and
(.second | match(".*multiple-outputs-a-second"))))
'
nix build "$drv^*" --no-link --json | jq --exit-status '
(.[0] |
(.drvPath | match(".*multiple-outputs-a.drv")) and
(.outputs |
(keys | length == 2) and
(.first | match(".*multiple-outputs-a-first")) and
(.second | match(".*multiple-outputs-a-second"))))
'