Skip to content

Commit e4a18ed

Browse files
committed
Move builder flatDepends to haskellLib.flatLibDepends
This function is also useful for the hoogle index builder.
1 parent cde9b82 commit e4a18ed

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

builder/make-config-files.nix

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ let
66
echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
77
'';
88

9-
flatDepends = component:
10-
let
11-
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
12-
closure = builtins.genericClosure {
13-
startSet = makePairs component.depends;
14-
operator = {val,...}: makePairs val.config.depends;
15-
};
16-
in map ({val,...}: val) closure;
17-
189
exactDep = pdbArg: p: ''
1910
if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then
2011
echo "--dependency=${p}=$id" >> $out/configure-flags
@@ -58,7 +49,7 @@ in { identifier, component, fullName, flags ? {} }:
5849
5950
${lib.concatMapStringsSep "\n" (p: ''
6051
target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
61-
'') (flatDepends component)}
52+
'') (haskellLib.flatLibDepends component)}
6253
6354
# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
6455
${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}

lib/default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ with haskellLib;
8080
let f' = if lib.isFunction f then f else import f;
8181
args' = (builtins.intersectAttrs (builtins.functionArgs f') scope) // args;
8282
in f' args';
83+
84+
# Collect all (transitive) Haskell library dependencies of a
85+
# component.
86+
## flatLibDepends :: Component -> [Package]
87+
flatLibDepends = component:
88+
let
89+
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
90+
closure = builtins.genericClosure {
91+
startSet = makePairs component.depends;
92+
operator = {val,...}: makePairs val.config.depends;
93+
};
94+
in map ({val,...}: val) closure;
8395
}

0 commit comments

Comments
 (0)