From 50af975d8595c7fce05bc8bbd9db93e3c4cece25 Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Thu, 15 Mar 2018 00:00:04 +0000 Subject: [PATCH] stdenv: implement `checkTarget` and `installCheckTarget` autodetection --- pkgs/stdenv/generic/setup.sh | 74 +++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index bb9e32486674..c85f05d9a919 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -971,6 +971,8 @@ buildPhase() { if [[ -z "$makeFlags" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then echo "no Makefile, doing nothing" else + foundMakefile=1 + # See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409 makeFlags="SHELL=$SHELL $makeFlags" @@ -994,18 +996,38 @@ buildPhase() { checkPhase() { runHook preCheck - # 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:-check} - ) + if [[ -z "${foundMakefile:-}" ]]; then + echo "no Makefile or custom buildPhase, doing nothing" + runHook postCheck + return + fi - echoCmd 'check flags' "${flagsArray[@]}" - make ${makefile:+-f $makefile} "${flagsArray[@]}" - unset flagsArray + if [[ -z "${checkTarget:-}" ]]; then + #TODO(@oxij): should flagsArray influence make -n? + 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 } @@ -1104,18 +1126,26 @@ fixupPhase() { installCheckPhase() { runHook preInstallCheck - # 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} - ) + if [[ -z "${foundMakefile:-}" ]]; then + echo "no Makefile or custom buildPhase, doing nothing" + #TODO(@oxij): should flagsArray influence make -n? + elif [[ -z "${installCheckTarget:-}" ]] \ + && ! make -n ${makefile:+-f $makefile} ${installCheckTarget:-installcheck} >/dev/null 2>&1; then + echo "no installcheck 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[@]}"} + $installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"} + ${installCheckTarget:-installcheck} + ) - echoCmd 'installcheck flags' "${flagsArray[@]}" - make ${makefile:+-f $makefile} "${flagsArray[@]}" - unset flagsArray + echoCmd 'installcheck flags' "${flagsArray[@]}" + make ${makefile:+-f $makefile} "${flagsArray[@]}" + unset flagsArray + fi runHook postInstallCheck }