Skip to content

Commit 30fbdc4

Browse files
committed
initial changes for adding "all" component
1 parent 195d9d0 commit 30fbdc4

File tree

5 files changed

+56
-18
lines changed

5 files changed

+56
-18
lines changed

builder/comp-builder.nix

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
, preInstall ? null, postInstall ? null
1919
, shellHook ? null
2020

21-
, doCheck ? component.doCheck || componentId.ctype == "test"
21+
, doCheck ? component.doCheck || haskellLib.isTest componentId
2222
, doCrossCheck ? component.doCrossCheck || false
2323
, dontPatchELF ? true
2424
, dontStrip ? true
@@ -28,18 +28,29 @@
2828
}:
2929

3030
let
31-
fullName = "${name}-${componentId.ctype}-${componentId.cname}";
31+
fullName = if haskellLib.isAll componentId
32+
then "${name}-all"
33+
else "${name}-${componentId.ctype}-${componentId.cname}";
3234

3335
flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
3436
echo ${lib.concatStringsSep " " (map (x: "--${field}=${x}") xs)} >> $out/configure-flags
3537
echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
3638
'';
3739

40+
componentDepends = if haskellLib.isAll componentId
41+
then
42+
# fixme: this needs to be the union of depends of all other components.
43+
# The depends could be combined at the module option level but I
44+
# had trouble with infinite recursion.
45+
component.depends
46+
else
47+
component.depends;
48+
3849
flatDepends =
3950
let
4051
makePairs = map (p: rec { key="${val}"; val=p.components.library; });
4152
closure = builtins.genericClosure {
42-
startSet = makePairs component.depends;
53+
startSet = makePairs componentDepends;
4354
operator = {val,...}: makePairs val.config.depends;
4455
};
4556
in map ({val,...}: val) closure;
@@ -85,7 +96,7 @@ let
8596
echo "allow-newer: ${package.identifier.name}:*" >> $out/cabal.config
8697
echo "allow-older: ${package.identifier.name}:*" >> $out/cabal.config
8798
88-
${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) component.depends}
99+
${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) componentDepends}
89100
${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
90101
91102
''
@@ -123,7 +134,7 @@ let
123134

124135
finalConfigureFlags = lib.concatStringsSep " " (
125136
[ "--prefix=$out"
126-
"${componentId.ctype}:${componentId.cname}"
137+
"${haskellLib.componentTarget componentId}"
127138
"$(cat ${configFiles}/configure-flags)"
128139
# GHC
129140
"--with-ghc=${ghc.targetPrefix}ghc"
@@ -222,12 +233,12 @@ in stdenv.mkDerivation ({
222233
installPhase = ''
223234
runHook preInstall
224235
$SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
225-
${lib.optionalString (haskellLib.isLibrary componentId) ''
236+
${lib.optionalString (haskellLib.isLibrary componentId || haskellLib.isAll componentId) ''
226237
$SETUP_HS register --gen-pkg-config=${name}.conf
227238
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
228239
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
229240
''}
230-
${lib.optionalString (componentId.ctype == "test") ''
241+
${lib.optionalString (haskellLib.isTest componentId || haskellLib.isAll componentId) ''
231242
mkdir -p $out/${name}
232243
if [ -f "dist/build/${componentId.cname}/${componentId.cname}" ]; then
233244
cp dist/build/${componentId.cname}/${componentId.cname} $out/${name}/

lib/default.nix

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
with haskellLib;
44

55
{
6+
# Within the package components, these are the attribute names of
7+
# nested attrsets.
68
subComponentTypes = [
79
"sublibs"
810
"foreignlibs"
@@ -66,13 +68,25 @@ with haskellLib;
6668
applyComponents = f: config:
6769
let
6870
comps = config.components;
69-
libComp = lib.mapAttrs (cname: f {ctype="lib"; cname=config.package.identifier.name;}) (removeAttrs comps subComponentTypes);
71+
applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
72+
applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype}; };
73+
applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
74+
libComp = lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
7075
subComps = lib.mapAttrs
71-
(ctype: lib.mapAttrs (cname: f {inherit cname; ctype=componentPrefix.${ctype};}))
76+
(ctype: lib.mapAttrs (applySubComp ctype))
7277
(builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
73-
in subComps // libComp;
78+
allComp = { all = applyAllComp comps.all; };
79+
in subComps // libComp // allComp;
7480

7581
isLibrary = componentId: componentId.ctype == "lib";
82+
isAll = componentId: componentId.ctype == "all";
83+
isTest = componentId: componentId.ctype == "test";
84+
85+
# Format a componentId as it should appear as a target on the
86+
# command line of the setup script.
87+
componentTarget = componentId:
88+
if componentId.ctype == "all" then ""
89+
else "${componentId.ctype}:${componentId.cname}";
7690

7791
# Avoid pkgs.callPackage for now. It does a lot of nonsense with OOP
7892
# style programming that we should avoid until we know we want it.

modules/package.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ in {
173173
type = attrsOf (componentType false);
174174
default = {};
175175
};
176+
all = mkOption {
177+
type = componentType false;
178+
default = {};
179+
};
176180
};
177181

178182
name = mkOption {

test/unit.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let
99
library = "library";
1010
sublibs = { };
1111
tests = { };
12+
all = "all";
1213
};
1314
package.identifier.name = "empty";
1415
};
@@ -21,20 +22,23 @@ let
2122
library = "library";
2223
sublibs = { };
2324
tests = { ttt = "ttt"; };
25+
all = "all";
2426
};
2527
package.identifier.name = "nnn";
2628
};
2729

2830
in
2931
lib.runTests {
32+
# identity function for applyComponents
3033
test-applyComponents-id = {
3134
expr = haskellLib.applyComponents (componentId: component: component) emptyConfig;
3235
expected = emptyConfig.components;
3336
};
3437

38+
# map a component to its component name and check these are correct
3539
test-applyComponents-library = {
3640
expr = haskellLib.applyComponents (componentId: component: componentId.cname) emptyConfig;
37-
expected = emptyConfig.components // { library = "empty"; };
41+
expected = emptyConfig.components // { library = "empty"; all = "empty"; };
3842
};
3943

4044
test-applyComponents-components = {

test/with-packages/default.nix

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,30 @@ in
3131
name = "with-packages-test";
3232

3333
buildCommand = let
34-
inherit (packages.test-with-packages.components) library;
35-
# inherit (packages.test-with-packages.components) all; # TODO
36-
inherit (packages.test-with-packages) devEnv;
34+
package = packages.test-with-packages;
35+
inherit (package.components) library;
36+
inherit (package) devEnv;
3737
in ''
3838
########################################################################
3939
# test with-packages
4040
41+
# fixme: test does not work yet -- need to fix dependencies of all component
42+
# printf "checking that the 'all' component works... " >& 2
43+
# echo ''${package.components.all}
44+
# echo >& 2
45+
4146
printf "checking that the package env has the dependencies... " >& 2
4247
${devEnv}/bin/runghc ${./Point.hs}
43-
echo
48+
echo >& 2
4449
4550
# # fixme: probably don't want separate derivation for this -- just use all
4651
# printf "checking that components.library.shell has the dependencies... " >& 2
4752
# ''${library.shell}/bin/runghc ${./Point.hs}
48-
# echo
53+
# echo >& 2
4954
5055
# printf "checking that components.all.shell has the dependencies... " >& 2
51-
# ''${all.shell}/bin/runghc ${./Point.hs}
52-
# echo
56+
# ''${package.components.all.shell}/bin/runghc ${./Point.hs}
57+
# echo >& 2
5358
5459
touch $out
5560
'';

0 commit comments

Comments
 (0)