Commit 9f601e47 authored by Profpatsch's avatar Profpatsch

buildSupport/package-tests: abstract drvSeq from withTests

withTests is just a small wrapper around the more abstract functions `drvSeq`
and `drvSeqL`, which act as `seq` for derivations.
It might be possible to make them even more abstract by not requiring (some of)
their arguments to be derivations, but this is a nice first step.

Maybe the functions should move to `lib/trivial` instead?
parent 111e3e57
{ runCommand, lib }:
{
/* Takes a derivation and an attribute set of
* test names to tests.
* Tests are shell fragments which test the
* derivation and should result in failure if
* the functionality is not as expected. */
withTests = tests: drv: let
drvOutputs = drv.outputs or ["out"];
in
assert (drv ? drvAttrs); # not a derivation!
runCommand drv.name {
# we inherit all attributes in order to replicate
# the original derivation as much as possible
outputs = drvOutputs;
passthru = drv.drvAttrs;
# depend on each test (by putting in builder context)
tests = lib.mapAttrsToList
(name: testScript:
runCommand "${drv.name}-test-${name}" {} ''
${testScript}
touch "$out"
'')
tests;
}
# the outputs of the original derivation are replicated
# by creating a symlink
(lib.concatMapStrings (output: ''
ln -s ${lib.escapeShellArg drv.${output}} "${"$"}${output}"
'') drvOutputs);
}
{ runCommand, lib }:
let
/* Realize drvDep, then return drvOut if that succeds.
* This can be used to make drvOut depend on the
* build success of drvDep without making drvDep a
* dependency of drvOut
* => drvOut is not rebuilt if drvDep changes
*/
drvSeq = drvDep: drvOut: drvSeqL [drvDep] drvOut;
/* TODO DOCS */
drvSeqL = drvDeps: drvOut: let
drvOutOutputs = drvOut.outputs or ["out"];
in
runCommand drvOut.name {
# we inherit all attributes in order to replicate
# the original derivation as much as possible
outputs = drvOutOutputs;
passthru = drvOut.drvAttrs;
# depend on drvDeps (by putting it in builder context)
inherit drvDeps;
}
# the outputs of the original derivation are replicated
# by creating a symlink to the old output path
(lib.concatMapStrings (output: ''
target=${lib.escapeShellArg drvOut.${output}}
# if the target is already a symlink, follow it until it’s not;
# this is done to prevent too many dereferences
target=$(readlink -e "$target")
# link to the output
ln -s "$target" "${"$"}${output}"
'') drvOutOutputs);
/* Takes a derivation and an attribute set of
* test names to tests.
* Tests are shell fragments which test the
* derivation and should result in failure if
* the functionality is not as expected. */
withTests = tests: drv:
let testDrvs = lib.mapAttrsToList
(name: testScript:
runCommand "${drv.name}-test-${name}" {} ''
${testScript}
touch "$out"
'') tests;
in drvSeqL testDrvs drv;
in
{ inherit drvSeq drvSeqL withTests; }
......@@ -70,7 +70,7 @@ let
};
packageTests = self: super:
import ../build-support/package-tests.nix {
import ../build-support/package-tests {
inherit (super) runCommand; inherit lib;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment