Skip to content

Commit acdfa9e

Browse files
committed
wip
1 parent 6c3fd26 commit acdfa9e

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

builder/comp-builder.nix

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{ stdenv, buildPackages, ghc, lib, pkgconfig, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp }:
22

3-
{ componentId
3+
{ allComponent
4+
, componentId
45
, component
56
, package
67
, name
@@ -19,6 +20,7 @@
1920
, preInstall ? component.preInstall , postInstall ? component.postInstall
2021
, preHaddock ? component.preHaddock , postHaddock ? component.postHaddock
2122
, shellHook ? ""
23+
, isDoctest ? component.isDoctest
2224

2325
, dontPatchELF ? component.dontPatchELF
2426
, dontStrip ? component.dontStrip
@@ -52,10 +54,19 @@ let
5254
then "${name}-all"
5355
else "${name}-${componentId.ctype}-${componentId.cname}";
5456

55-
configFiles = makeConfigFiles {
56-
inherit (package) identifier;
57-
inherit component fullName flags;
58-
};
57+
configFiles =
58+
if isDoctest
59+
then
60+
makeConfigFiles {
61+
inherit (package) identifier;
62+
component = allComponent;
63+
inherit fullName flags;
64+
}
65+
else
66+
makeConfigFiles {
67+
inherit (package) identifier;
68+
inherit component fullName flags;
69+
};
5970

6071
enableFeature = enable: feature:
6172
(if enable then "--enable-" else "--disable-") + feature;
@@ -64,7 +75,7 @@ let
6475

6576
finalConfigureFlags = lib.concatStringsSep " " (
6677
[ "--prefix=$out"
67-
"${haskellLib.componentTarget componentId}"
78+
"${haskellLib.componentSetupTarget componentId component}"
6879
"$(cat ${configFiles}/configure-flags)"
6980
# GHC
7081
"--with-ghc=${ghc.targetPrefix}ghc"
@@ -188,10 +199,11 @@ stdenv.mkDerivation ({
188199

189200
SETUP_HS = setup + /bin/Setup;
190201

191-
outputs = ["out" ]
202+
outputs = ["out"]
192203
++ (lib.optional enableSeparateDataOutput "data")
193204
++ (lib.optional doHaddock' "doc")
194-
++ (lib.optional keepSource "source");
205+
++ (lib.optional keepSource "source")
206+
++ (lib.optional isDoctest "dist");
195207

196208
# Phases
197209
preInstallPhases = lib.optional doHaddock' "haddockPhase";
@@ -219,7 +231,7 @@ stdenv.mkDerivation ({
219231
buildPhase = ''
220232
runHook preBuild
221233
# https://gitlab.haskell.org/ghc/ghc/issues/9221
222-
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (component.setupBuildFlags ++ setupGhcOptions)}
234+
$SETUP_HS build ${haskellLib.componentBuildTarget componentId component} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (component.setupBuildFlags ++ setupGhcOptions)}
223235
runHook postBuild
224236
'';
225237

@@ -325,7 +337,9 @@ stdenv.mkDerivation ({
325337
'')
326338
}
327339
runHook postInstall
328-
'' + (lib.optionalString keepSource ''
340+
'' + (lib.optionalString isDoctest ''
341+
cp -r dist/ $dist/
342+
'') + (lib.optionalString keepSource ''
329343
rm -rf dist
330344
'');
331345

builder/hspkg-builder.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ let
5151
inherit (config) preUnpack postUnpack;
5252
};
5353

54-
buildComp = componentId: component: comp-builder {
55-
inherit componentId component package name src flags setup cabalFile cabal-generator patches revision
54+
buildComp = allComponent: componentId: component: comp-builder {
55+
inherit allComponent componentId component package name src flags setup cabalFile cabal-generator patches revision
5656
shellHook
5757
;
5858
};
5959

6060
in rec {
61-
components = haskellLib.applyComponents buildComp config;
61+
components = haskellLib.applyComponents (buildComp config.components.all) config;
6262
checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
6363
(_: d: haskellLib.check d)
6464
(lib.filterAttrs (_: d: d.config.doCheck) components.tests));

lib/check.nix

+24-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let
1010
in stdenv.mkDerivation ({
1111
name = (drv.name + "-check");
1212

13-
# Useing `srcOnly` (rather than getting the `src` via a `drv.passthru`)
13+
# Using `srcOnly` (rather than getting the `src` via a `drv.passthru`)
1414
# should correctly apply the patches from `drv` (if any).
1515
src = drv.source or (srcOnly drv);
1616

@@ -26,15 +26,29 @@ in stdenv.mkDerivation ({
2626

2727
# If doCheck or doCrossCheck are false we may still build this
2828
# component and we want it to quietly succeed.
29-
buildPhase = ''
30-
touch $out
31-
32-
runHook preCheck
33-
34-
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out
35-
36-
runHook postCheck
37-
'';
29+
buildPhase =
30+
(lib.optionalString component.isDoctest ''
31+
# cabal-doctest assumes we are running tests in a directory with the same
32+
# name as when we built the test.
33+
this_dir_name=$(pwd)
34+
src_basename="$(basename "${drv.cleanSrc}")"
35+
cd ../
36+
mv "$this_dir_name" "$src_basename"
37+
cd "$src_basename"
38+
39+
# cabal-doctest needs the ./dist directory available to get auto-generated
40+
# modules.
41+
cp -r ${drv.dist} ./dist
42+
chmod u+w -R ./dist
43+
'') + ''
44+
touch $out
45+
46+
runHook preCheck
47+
48+
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out
49+
50+
runHook postCheck
51+
'';
3852
} // haskellLib.optionalHooks {
3953
inherit (component) preCheck postCheck;
4054
}

lib/default.nix

+14-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,20 @@ with haskellLib;
8181

8282
# Format a componentId as it should appear as a target on the
8383
# command line of the setup script.
84-
componentTarget = componentId:
85-
if componentId.ctype == "all" then ""
84+
componentSetupTarget = componentId: component:
85+
if componentId.ctype == "all"
86+
then ""
87+
else
88+
if component.isDoctest
89+
# TODO: Why is this needed???
90+
then "--enable-tests"
91+
else "${componentId.ctype}:${componentId.cname}";
92+
93+
# Format a componentId as it should appear as a target on the
94+
# command line of the setup script.
95+
componentBuildTarget = componentId: component:
96+
if componentId.ctype == "all"
97+
then ""
8698
else "${componentId.ctype}:${componentId.cname}";
8799

88100
# Remove null or empty values from an attrset.

modules/plan.nix

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ let
128128
type = bool;
129129
default = (def.enableShared or true);
130130
};
131+
isDoctest = mkOption {
132+
type = bool;
133+
default = false;
134+
};
131135
shellHook = mkOption {
132136
description = "Hook to run when entering a shell";
133137
type = unspecified; # Can be either a string or a function

0 commit comments

Comments
 (0)