Merge pull request #39464 from oxij/stdenv/docheck-infra

stdenv: implement most of #33599
This commit is contained in:
Michael Raskin 2018-04-30 17:17:24 +00:00 committed by GitHub
commit a591d28c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 63 deletions

View File

@ -1005,6 +1005,13 @@ but only if the <varname>doCheck</varname> variable is enabled.</para>
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>checkInputs</varname></term>
<listitem><para>
A list of dependencies used by the phase. This gets included in <varname>buildInputs</varname> when <varname>doCheck</varname> is set.
</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>makeFlags</varname> / <term><varname>makeFlags</varname> /
<varname>makeFlagsArray</varname> / <varname>makeFlagsArray</varname> /
@ -1291,6 +1298,13 @@ installcheck</command>.</para>
</para></listitem> </para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>installCheckInputs</varname></term>
<listitem><para>
A list of dependencies used by the phase. This gets included in <varname>buildInputs</varname> when <varname>doInstallCheck</varname> is set.
</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>preInstallCheck</varname></term> <term><varname>preInstallCheck</varname></term>
<listitem><para>Hook executed at the start of the installCheck <listitem><para>Hook executed at the start of the installCheck

View File

@ -20,7 +20,7 @@ in
, buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? [] , buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? []
, configureFlags ? [] , configureFlags ? []
, description ? "" , description ? ""
, doCheck ? !isCross && (stdenv.lib.versionOlder "7.4" ghc.version) , doCheck ? !isCross && stdenv.lib.versionOlder "7.4" ghc.version
, doBenchmark ? false , doBenchmark ? false
, doHoogle ? true , doHoogle ? true
, editedCabalFile ? null , editedCabalFile ? null
@ -172,7 +172,7 @@ let
buildTools ++ libraryToolDepends ++ executableToolDepends; buildTools ++ libraryToolDepends ++ executableToolDepends;
propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends; propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends;
otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++
optionals (allPkgconfigDepends != []) allPkgconfigDepends ++ allPkgconfigDepends ++
optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testToolDepends) ++ optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testToolDepends) ++
optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkToolDepends); optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkToolDepends);
allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; allBuildInputs = propagatedBuildInputs ++ otherBuildInputs;
@ -314,6 +314,8 @@ stdenv.mkDerivation ({
runHook postBuild runHook postBuild
''; '';
inherit doCheck;
checkPhase = '' checkPhase = ''
runHook preCheck runHook preCheck
${setupCommand} test ${testTarget} ${setupCommand} test ${testTarget}
@ -428,7 +430,6 @@ stdenv.mkDerivation ({
// optionalAttrs (postConfigure != "") { inherit postConfigure; } // optionalAttrs (postConfigure != "") { inherit postConfigure; }
// optionalAttrs (preBuild != "") { inherit preBuild; } // optionalAttrs (preBuild != "") { inherit preBuild; }
// optionalAttrs (postBuild != "") { inherit postBuild; } // optionalAttrs (postBuild != "") { inherit postBuild; }
// optionalAttrs (doCheck) { inherit doCheck; }
// optionalAttrs (doBenchmark) { inherit doBenchmark; } // optionalAttrs (doBenchmark) { inherit doBenchmark; }
// optionalAttrs (checkPhase != "") { inherit checkPhase; } // optionalAttrs (checkPhase != "") { inherit checkPhase; }
// optionalAttrs (preCheck != "") { inherit preCheck; } // optionalAttrs (preCheck != "") { inherit preCheck; }

View File

@ -2,6 +2,7 @@
# and can build packages that use distutils, setuptools or flit. # and can build packages that use distutils, setuptools or flit.
{ lib { lib
, config
, python , python
, wrapPython , wrapPython
, setuptools , setuptools
@ -19,7 +20,7 @@ let
wheel-specific = import ./build-python-package-wheel.nix { }; wheel-specific = import ./build-python-package-wheel.nix { };
common = import ./build-python-package-common.nix { inherit python bootstrapped-pip; }; common = import ./build-python-package-common.nix { inherit python bootstrapped-pip; };
mkPythonDerivation = import ./mk-python-derivation.nix { mkPythonDerivation = import ./mk-python-derivation.nix {
inherit lib python wrapPython setuptools unzip ensureNewerSourcesForZipFilesHook toPythonModule namePrefix; inherit lib config python wrapPython setuptools unzip ensureNewerSourcesForZipFilesHook toPythonModule namePrefix;
}; };
in in

View File

@ -1,6 +1,7 @@
# Generic builder. # Generic builder.
{ lib { lib
, config
, python , python
, wrapPython , wrapPython
, setuptools , setuptools
@ -53,7 +54,7 @@
, passthru ? {} , passthru ? {}
, doCheck ? false , doCheck ? config.doCheckByDefault or false
, ... } @ attrs: , ... } @ attrs:
@ -74,7 +75,6 @@ toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attrs [
buildInputs = [ wrapPython ] buildInputs = [ wrapPython ]
++ lib.optional (lib.hasSuffix "zip" (attrs.src.name or "")) unzip ++ lib.optional (lib.hasSuffix "zip" (attrs.src.name or "")) unzip
++ lib.optionals doCheck checkInputs
++ lib.optional catchConflicts setuptools # If we no longer propagate setuptools ++ lib.optional catchConflicts setuptools # If we no longer propagate setuptools
++ buildInputs ++ buildInputs
++ pythonPath; ++ pythonPath;
@ -85,6 +85,7 @@ toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attrs [
# Python packages don't have a checkPhase, only an installCheckPhase # Python packages don't have a checkPhase, only an installCheckPhase
doCheck = false; doCheck = false;
doInstallCheck = doCheck; doInstallCheck = doCheck;
installCheckInputs = checkInputs;
postFixup = lib.optionalString (!dontWrapPythonPrograms) '' postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
wrapPythonPrograms wrapPythonPrograms

View File

@ -36,6 +36,9 @@ rec {
, depsTargetTarget ? [] # 1 -> 1 , depsTargetTarget ? [] # 1 -> 1
, depsTargetTargetPropagated ? [] # 1 -> 1 , depsTargetTargetPropagated ? [] # 1 -> 1
, checkInputs ? []
, installCheckInputs ? []
# Configure Phase # Configure Phase
, configureFlags ? [] , configureFlags ? []
, # Target is not included by default because most programs don't care. , # Target is not included by default because most programs don't care.
@ -46,11 +49,13 @@ rec {
(stdenv.hostPlatform != stdenv.buildPlatform) (stdenv.hostPlatform != stdenv.buildPlatform)
[ "build" "host" ] [ "build" "host" ]
# TODO(@Ericson2314): Make unconditional / resolve #33599
# Check phase # Check phase
, doCheck ? false , doCheck ? config.doCheckByDefault or false
# TODO(@Ericson2314): Make unconditional / resolve #33599
# InstallCheck phase # InstallCheck phase
, doInstallCheck ? false , doInstallCheck ? config.doCheckByDefault or false
, crossConfig ? null , crossConfig ? null
, meta ? {} , meta ? {}
@ -99,7 +104,9 @@ rec {
] ]
[ [
(map (drv: drv.__spliced.hostHost or drv) depsHostHost) (map (drv: drv.__spliced.hostHost or drv) depsHostHost)
(map (drv: drv.crossDrv or drv) buildInputs) (map (drv: drv.crossDrv or drv) (buildInputs
++ lib.optionals doCheck' checkInputs
++ lib.optionals doInstallCheck' installCheckInputs))
] ]
[ [
(map (drv: drv.__spliced.targetTarget or drv) depsTargetTarget) (map (drv: drv.__spliced.targetTarget or drv) depsTargetTarget)
@ -120,34 +127,43 @@ rec {
] ]
]; ];
# TODO(@oxij, @Ericson2314): This is here to keep the old semantics, remove when
# no package has `doCheck = true`.
doCheck' = doCheck && stdenv.hostPlatform == stdenv.buildPlatform;
doInstallCheck' = doInstallCheck && stdenv.hostPlatform == stdenv.buildPlatform;
outputs' = outputs' =
outputs ++ outputs ++
(if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []); (if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []);
computedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies);
computedPropagatedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(lib.concatLists propagatedDependencies);
computedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies));
computedPropagatedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(lib.concatLists propagatedDependencies));
derivationArg = derivationArg =
(removeAttrs attrs (removeAttrs attrs
["meta" "passthru" "crossAttrs" "pos" ["meta" "passthru" "crossAttrs" "pos"
"doCheck" "doInstallCheck"
"checkInputs" "installCheckInputs"
"__impureHostDeps" "__propagatedImpureHostDeps" "__impureHostDeps" "__propagatedImpureHostDeps"
"sandboxProfile" "propagatedSandboxProfile"]) "sandboxProfile" "propagatedSandboxProfile"])
// (let // {
computedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies);
computedPropagatedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(lib.concatLists propagatedDependencies);
computedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies));
computedPropagatedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(lib.concatLists propagatedDependencies));
in
{
# A hack to make `nix-env -qa` and `nix search` ignore broken packages. # A hack to make `nix-env -qa` and `nix search` ignore broken packages.
# TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix. # TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix.
name = assert validity.handled; name + lib.optionalString name = assert validity.handled; name + lib.optionalString
@ -186,6 +202,13 @@ rec {
} // lib.optionalAttrs (hardeningDisable != [] || hardeningEnable != []) { } // lib.optionalAttrs (hardeningDisable != [] || hardeningEnable != []) {
NIX_HARDENING_ENABLE = enabledHardeningOptions; NIX_HARDENING_ENABLE = enabledHardeningOptions;
} // lib.optionalAttrs (outputs' != [ "out" ]) {
outputs = outputs';
} // lib.optionalAttrs doCheck' {
doCheck = true;
} // lib.optionalAttrs doInstallCheck' {
doInstallCheck = true;
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) { } // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) {
# TODO: remove lib.unique once nix has a list canonicalization primitive # TODO: remove lib.unique once nix has a list canonicalization primitive
__sandboxProfile = __sandboxProfile =
@ -200,15 +223,7 @@ rec {
"/bin/sh" "/bin/sh"
]; ];
__propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps; __propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps;
} // lib.optionalAttrs (outputs' != [ "out" ]) { };
outputs = outputs';
} // lib.optionalAttrs (attrs ? doCheck) {
# TODO(@Ericson2314): Make unconditional / resolve #33599
doCheck = doCheck && (stdenv.hostPlatform == stdenv.buildPlatform);
} // lib.optionalAttrs (attrs ? doInstallCheck) {
# TODO(@Ericson2314): Make unconditional / resolve #33599
doInstallCheck = doInstallCheck && (stdenv.hostPlatform == stdenv.buildPlatform);
});
validity = import ./check-meta.nix { validity = import ./check-meta.nix {
inherit lib config meta; inherit lib config meta;

View File

@ -968,9 +968,11 @@ buildPhase() {
# set to empty if unset # set to empty if unset
: ${makeFlags=} : ${makeFlags=}
if [[ -z "$makeFlags" && ! ( -n "${makefile:-}" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then if [[ -z "$makeFlags" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then
echo "no Makefile, doing nothing" echo "no Makefile, doing nothing"
else else
foundMakefile=1
# See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409 # See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409
makeFlags="SHELL=$SHELL $makeFlags" makeFlags="SHELL=$SHELL $makeFlags"
@ -994,18 +996,38 @@ buildPhase() {
checkPhase() { checkPhase() {
runHook preCheck runHook preCheck
# Old bash empty array hack if [[ -z "${foundMakefile:-}" ]]; then
# shellcheck disable=SC2086 echo "no Makefile or custom buildPhase, doing nothing"
local flagsArray=( runHook postCheck
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} return
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} fi
${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
${checkTarget:-check}
)
echoCmd 'check flags' "${flagsArray[@]}" if [[ -z "${checkTarget:-}" ]]; then
make ${makefile:+-f $makefile} "${flagsArray[@]}" #TODO(@oxij): should flagsArray influence make -n?
unset flagsArray if make -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then
checkTarget=check
elif make -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then
checkTarget=test
fi
fi
if [[ -z "${checkTarget:-}" ]]; then
echo "no check/test target in ${makefile:-Makefile}, doing nothing"
else
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
${checkTarget}
)
echoCmd 'check flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
fi
runHook postCheck runHook postCheck
} }
@ -1018,14 +1040,12 @@ installPhase() {
mkdir -p "$prefix" mkdir -p "$prefix"
fi fi
installTargets="${installTargets:-install}"
# Old bash empty array hack # Old bash empty array hack
# shellcheck disable=SC2086 # shellcheck disable=SC2086
local flagsArray=( local flagsArray=(
$installTargets
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installFlags ${installFlagsArray+"${installFlagsArray[@]}"} $installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
${installTargets:-install}
) )
echoCmd 'install flags' "${flagsArray[@]}" echoCmd 'install flags' "${flagsArray[@]}"
@ -1106,18 +1126,26 @@ fixupPhase() {
installCheckPhase() { installCheckPhase() {
runHook preInstallCheck runHook preInstallCheck
# Old bash empty array hack if [[ -z "${foundMakefile:-}" ]]; then
# shellcheck disable=SC2086 echo "no Makefile or custom buildPhase, doing nothing"
local flagsArray=( #TODO(@oxij): should flagsArray influence make -n?
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} elif [[ -z "${installCheckTarget:-}" ]] \
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} && ! make -n ${makefile:+-f $makefile} ${installCheckTarget:-installcheck} >/dev/null 2>&1; then
$installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"} echo "no installcheck target in ${makefile:-Makefile}, doing nothing"
${installCheckTarget:-installcheck} else
) # Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"}
${installCheckTarget:-installcheck}
)
echoCmd 'installcheck flags' "${flagsArray[@]}" echoCmd 'installcheck flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}" make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray unset flagsArray
fi
runHook postInstallCheck runHook postInstallCheck
} }