Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkgs/development/haskell-modules/generic-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,10 @@ let
(enableFeature doCoverage "coverage")
(enableFeature enableStaticLibraries "static")
(enableFeature enableSharedExecutables "executable-dynamic")
(enableFeature doCheck "tests")
(enableFeature doBenchmark "benchmarks")
# "--enable-tests/--enable-benchmarks are incompatible with explicitly
# specifying a component to configure."
(enableFeature (doCheck && buildTarget == "") "tests")
(enableFeature (doBenchmark && buildTarget == "") "benchmarks")
"--enable-library-vanilla" # TODO: Should this be configurable?
(enableFeature enableLibraryForGhci "library-for-ghci")
(enableFeature enableDeadCodeElimination "split-sections")
Expand Down Expand Up @@ -724,7 +726,7 @@ lib.fix (
runHook preConfigure

echo configureFlags: $configureFlags
${setupCommand} configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
${setupCommand} configure ${buildTarget} $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
${lib.optionalString (!allowInconsistentDependencies) ''
if grep -E -q -z 'Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
echo >&2 "*** abort because of serious configure-time warning from Cabal"
Expand Down Expand Up @@ -807,7 +809,10 @@ lib.fix (
mkdir -p "$packageConfDir"
${setupCommand} register --gen-pkg-config=$packageConfFile
if [ -d "$packageConfFile" ]; then
mv "$packageConfFile/"* "$packageConfDir"
# Avoid 'mv "$dir"/*' failing due to unexpanded glob in empty directory.
if [ -n "$(find "$packageConfFile" -mindepth 1 -print -quit)" ]; then
mv "$packageConfFile/"* "$packageConfDir"
fi
rmdir "$packageConfFile"
fi
for packageConfFile in "$packageConfDir/"*; do
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/haskell/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lib.recurseIntoAttrs {
shellFor = callPackage ./shellFor { };
cabalSdist = callPackage ./cabalSdist { };
documentationTarball = callPackage ./documentationTarball { };
setBuildTarget = callPackage ./setBuildTarget { };
setBuildTarget = lib.recurseIntoAttrs (callPackage ./setBuildTarget { });
incremental = callPackage ./incremental { };
upstreamStackHpackVersion = callPackage ./upstreamStackHpackVersion { };
}
48 changes: 34 additions & 14 deletions pkgs/test/haskell/setBuildTarget/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{ pkgs, haskellPackages }:
{
haskell,
haskellPackages,
pkgs,
testers,
}:

let
inherit (haskell.lib.compose) doCheck dontCheck setBuildTarget;

# This can be regenerated by running `cabal2nix ./src` in the current directory.
pkgDef =
{
Expand All @@ -12,9 +19,11 @@ let
pname = "haskell-setBuildTarget";
version = "0.1.0.0";
src = ./src;
isLibrary = false;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base ];
license = "unknown";
};

Expand All @@ -23,7 +32,7 @@ let
test =
target: excluded:
let
only = pkgs.haskell.lib.compose.setBuildTarget target drv;
only = dontCheck (setBuildTarget target drv);
in
''
if [[ ! -f "${only}/bin/${target}" ]]; then
Expand All @@ -38,14 +47,25 @@ let
'';

in
pkgs.runCommand "test haskell.lib.compose.setBuildTarget"
{
meta = {
inherit (drv.meta) platforms;
};
}
''
${test "foo" "bar"}
${test "bar" "foo"}
touch "$out"
''
{
pass-setBuildTarget =
pkgs.runCommand "test haskell.lib.compose.setBuildTarget"
{ meta = { inherit (drv.meta) platforms; }; }
''
${test "foo" "bar"}
${test "bar" "foo"}
touch "$out"
'';

# Not building the test-suite (that is mentioned in the .cabal file) is a
# failure when doCheck=true.
fail-doCheck-setBuildTarget =
pkgs.runCommand "fail-doCheck-setBuildTarget"
{ result = testers.testBuildFailure (doCheck (setBuildTarget "exe:foo" drv)); }
''
echo -n 'Checking testBuildFailure.log: '
grep --quiet --fixed-strings 'Error: Setup: No test suites enabled.' $result/testBuildFailure.log
echo OK
touch "$out"
'';
}
1 change: 1 addition & 0 deletions pkgs/test/haskell/setBuildTarget/src/SomeModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module SomeModule where
12 changes: 12 additions & 0 deletions pkgs/test/haskell/setBuildTarget/src/haskell-setBuildTarget.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ executable bar
main-is: Bar.hs
build-depends: base
default-language: Haskell2010

-- A library that the executables don't depend on.
library
exposed-modules: SomeModule
build-depends: base
default-language: Haskell2010

test-suite sometest
type: exitcode-stdio-1.0
main-is: sometest.hs
build-depends: base
default-language: Haskell2010
4 changes: 4 additions & 0 deletions pkgs/test/haskell/setBuildTarget/src/sometest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = return ()