on iko/ghcjs-patch-master help sign in
Fix dependency merging of "all" component
5704909Rodney Lorrimar
modules/package.nix+20−15
@@ -19,6 +19,8 @@ with lib;
19with types;
19with types;
20
20
21let
21let
22+ haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
23+
22 # This is just like listOf, except that it filters out all null elements.
24 # This is just like listOf, except that it filters out all null elements.
23 listOfFilteringNulls = elemType: listOf elemType // {
25 listOfFilteringNulls = elemType: listOf elemType // {
24 # Mostly copied from nixpkgs/lib/types.nix
26 # Mostly copied from nixpkgs/lib/types.nix
@@ -97,11 +99,11 @@ in {
97 };
99 };
98
100
99 components = let
101 components = let
100− componentType = check: submodule {
102+ componentType = defaults: submodule {
101 options = {
103 options = {
102 depends = mkOption {
104 depends = mkOption {
103 type = listOfFilteringNulls unspecified;
105 type = listOfFilteringNulls unspecified;
104− default = [];
106+ default = defaults.depends or [];
105 };
107 };
106 libs = mkOption {
108 libs = mkOption {
107 type = listOfFilteringNulls (nullOr package);
109 type = listOfFilteringNulls (nullOr package);
@@ -141,7 +143,7 @@ in {
141 };
143 };
142 doCheck = mkOption {
144 doCheck = mkOption {
143 type = bool;
145 type = bool;
144− default = check;
146+ default = defaults.doCheck or false;
145 };
147 };
146 doCrossCheck = mkOption {
148 doCrossCheck = mkOption {
147 type = bool;
149 type = bool;
@@ -151,35 +153,38 @@ in {
151 };
153 };
152 in {
154 in {
153 library = mkOption {
155 library = mkOption {
154− type = componentType false;
156+ type = componentType {};
155 };
157 };
156 sublibs = mkOption {
158 sublibs = mkOption {
157− type = attrsOf (componentType false);
159+ type = attrsOf (componentType {});
158 default = {};
160 default = {};
159 };
161 };
160 foreignlibs = mkOption {
162 foreignlibs = mkOption {
161− type = attrsOf (componentType false);
163+ type = attrsOf (componentType {});
162 default = {};
164 default = {};
163 };
165 };
164 exes = mkOption {
166 exes = mkOption {
165− type = attrsOf (componentType false);
167+ type = attrsOf (componentType {});
166 default = {};
168 default = {};
167 };
169 };
168 tests = mkOption {
170 tests = mkOption {
169− type = attrsOf (componentType config.doCheck);
171+ type = attrsOf (componentType { inherit (config) doCheck; });
170 default = {};
172 default = {};
171 };
173 };
172 benchmarks = mkOption {
174 benchmarks = mkOption {
173− type = attrsOf (componentType false);
175+ type = attrsOf (componentType {});
174 default = {};
176 default = {};
175 };
177 };
176− all = mkOption {
178+ all = let
177− type = componentType false;
179+ subComponentsDepends = sub: concatLists
178− default = let
180+ (mapAttrsToList (_: c: c.depends or []) config.components.${sub} or {});
179− componentTypes = [ "library" "sublibs" "foreignlibs" "exes" "tests" "benchmarks" ];
181+ default = {
180− in {
182+ depends = config.components.library.depends ++
181− depends = mkMerge (map (c: config.components.${c}.depends or []) componentTypes);
183+ concatMap subComponentsDepends haskellLib.subComponentTypes;
182 };
184 };
185+ in mkOption {
186+ type = componentType default;
187+ inherit default;
183 defaultText = "The merged dependencies of all other components";
188 defaultText = "The merged dependencies of all other components";
184 };
189 };
185 };
190 };
test/tests.sh+7
@@ -36,4 +36,11 @@ nix-shell $NIX_BUILD_ARGS \
36 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
36 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
37echo >& 2
37echo >& 2
38
38
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+
39printf "\n*** Finished successfully\n" >& 2
46printf "\n*** Finished successfully\n" >& 2
test/with-packages/default.nix+15−2
@@ -21,6 +21,14 @@ let
21 {
21 {
22 packages.transformers-compat.components.library.doExactConfig = true;
22 packages.transformers-compat.components.library.doExactConfig = true;
23 }
23 }
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+ }
24 ];
32 ];
25 };
33 };
26
34
@@ -43,8 +51,10 @@ in
43 # test with-packages
51 # test with-packages
44
52
45 printf "checking that the 'all' component works... " >& 2
53 printf "checking that the 'all' component works... " >& 2
46− echo ${package.components.all}
54+ echo ${package.components.all} >& 2
47− # echo >& 2
55+
56+ printf "checking that the 'library' component works... " >& 2
57+ echo ${package.components.library} >& 2
48
58
49 printf "checking that the package env has the dependencies... " >& 2
59 printf "checking that the package env has the dependencies... " >& 2
50 ${package.components.all.env}/bin/runghc ${./Point.hs}
60 ${package.components.all.env}/bin/runghc ${./Point.hs}
@@ -65,4 +75,7 @@ in
65 # Used for testing externally with nix-shell (../tests.sh).
75 # Used for testing externally with nix-shell (../tests.sh).
66 # This just adds cabal-install to the existing shells.
76 # This just adds cabal-install to the existing shells.
67 test-shell = addCabalInstall packages.test-with-packages.components.all;
77 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;
68}
81}