Skip to content

Commit 5704909

Browse files
committed
Fix dependency merging of "all" component
1 parent 78629ca commit 5704909

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

modules/package.nix

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ with lib;
1919
with types;
2020

2121
let
22+
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
23+
2224
# This is just like listOf, except that it filters out all null elements.
2325
listOfFilteringNulls = elemType: listOf elemType // {
2426
# Mostly copied from nixpkgs/lib/types.nix
@@ -97,11 +99,11 @@ in {
9799
};
98100

99101
components = let
100-
componentType = check: submodule {
102+
componentType = defaults: submodule {
101103
options = {
102104
depends = mkOption {
103105
type = listOfFilteringNulls unspecified;
104-
default = [];
106+
default = defaults.depends or [];
105107
};
106108
libs = mkOption {
107109
type = listOfFilteringNulls (nullOr package);
@@ -141,7 +143,7 @@ in {
141143
};
142144
doCheck = mkOption {
143145
type = bool;
144-
default = check;
146+
default = defaults.doCheck or false;
145147
};
146148
doCrossCheck = mkOption {
147149
type = bool;
@@ -151,35 +153,38 @@ in {
151153
};
152154
in {
153155
library = mkOption {
154-
type = componentType false;
156+
type = componentType {};
155157
};
156158
sublibs = mkOption {
157-
type = attrsOf (componentType false);
159+
type = attrsOf (componentType {});
158160
default = {};
159161
};
160162
foreignlibs = mkOption {
161-
type = attrsOf (componentType false);
163+
type = attrsOf (componentType {});
162164
default = {};
163165
};
164166
exes = mkOption {
165-
type = attrsOf (componentType false);
167+
type = attrsOf (componentType {});
166168
default = {};
167169
};
168170
tests = mkOption {
169-
type = attrsOf (componentType config.doCheck);
171+
type = attrsOf (componentType { inherit (config) doCheck; });
170172
default = {};
171173
};
172174
benchmarks = mkOption {
173-
type = attrsOf (componentType false);
175+
type = attrsOf (componentType {});
174176
default = {};
175177
};
176-
all = mkOption {
177-
type = componentType false;
178-
default = let
179-
componentTypes = [ "library" "sublibs" "foreignlibs" "exes" "tests" "benchmarks" ];
180-
in {
181-
depends = mkMerge (map (c: config.components.${c}.depends or []) componentTypes);
178+
all = let
179+
subComponentsDepends = sub: concatLists
180+
(mapAttrsToList (_: c: c.depends or []) config.components.${sub} or {});
181+
default = {
182+
depends = config.components.library.depends ++
183+
concatMap subComponentsDepends haskellLib.subComponentTypes;
182184
};
185+
in mkOption {
186+
type = componentType default;
187+
inherit default;
183188
defaultText = "The merged dependencies of all other components";
184189
};
185190
};

test/tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ nix-shell $NIX_BUILD_ARGS \
3636
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
3737
echo >& 2
3838

39+
printf "*** Checking that a nix-shell works for cabal (doExactConfig component)...\n" >& 2
40+
nix-shell $NIX_BUILD_ARGS \
41+
--pure ./default.nix \
42+
-A with-packages.test-shell-dec \
43+
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
44+
echo >& 2
45+
3946
printf "\n*** Finished successfully\n" >& 2

test/with-packages/default.nix

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ let
2121
{
2222
packages.transformers-compat.components.library.doExactConfig = true;
2323
}
24+
25+
# vary component config for tests
26+
{
27+
packages.test-with-packages.components = {
28+
all.doExactConfig = false; # the default
29+
library.doExactConfig = true; # not the default
30+
};
31+
}
2432
];
2533
};
2634

@@ -43,8 +51,10 @@ in
4351
# test with-packages
4452
4553
printf "checking that the 'all' component works... " >& 2
46-
echo ${package.components.all}
47-
# echo >& 2
54+
echo ${package.components.all} >& 2
55+
56+
printf "checking that the 'library' component works... " >& 2
57+
echo ${package.components.library} >& 2
4858
4959
printf "checking that the package env has the dependencies... " >& 2
5060
${package.components.all.env}/bin/runghc ${./Point.hs}
@@ -65,4 +75,7 @@ in
6575
# Used for testing externally with nix-shell (../tests.sh).
6676
# This just adds cabal-install to the existing shells.
6777
test-shell = addCabalInstall packages.test-with-packages.components.all;
78+
79+
# A variant of test-shell with the component option doExactConfig enabled
80+
test-shell-dec = addCabalInstall packages.test-with-packages.components.library;
6881
}

0 commit comments

Comments
 (0)