Skip to content

Commit 4e8777e

Browse files
committed
Refactor haskell#3082 to reduce code duplication and improve Haddock comment.
1 parent c036b79 commit 4e8777e

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

Cabal/src/Distribution/PackageDescription/Configuration.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Distribution.PackageDescription.Configuration (
2222
-- Utils
2323
parseCondition,
2424
freeVars,
25-
extractCondition,
25+
addBuildableCondition,
2626
mapCondTree,
2727
mapTreeData,
2828
mapTreeConds,
@@ -277,8 +277,10 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
277277
pdTaggedBuildInfo (Bench _ b) = benchmarkBuildInfo b
278278
pdTaggedBuildInfo PDNull = mempty
279279

280-
-- | Tries to determine under which condition the condition tree
281-
-- is buildable, and will add an additional condition on top accordingly.
280+
-- | Transforms a 'CondTree' by putting the input under the "then" branch of a
281+
-- conditional that is True when Buildable is True. If 'addBuildableCondition'
282+
-- can determine that Buildable is always True, it returns the input unchanged.
283+
-- If Buildable is always False, it returns the empty 'CondTree'.
282284
addBuildableCondition :: (Eq v, Monoid a, Monoid c) => (a -> BuildInfo)
283285
-> CondTree v c a
284286
-> CondTree v c a

cabal-install/Distribution/Client/Dependency/Modular/IndexConversion.hs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Distribution.Client.Dependency.Modular.IndexConversion
55
import Data.List as L
66
import Data.Map as M
77
import Data.Maybe
8+
import Data.Monoid as Mon
89
import Prelude hiding (pi)
910

1011
import qualified Distribution.Client.PackageIndex as CI
@@ -103,11 +104,15 @@ convSP os arch cinfo strfl (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
103104
-- | Convert a generic package description to a solver-specific 'PInfo'.
104105
convGPD :: OS -> Arch -> CompilerInfo -> Bool ->
105106
PI PN -> GenericPackageDescription -> PInfo
106-
convGPD os arch comp strfl pi
107+
convGPD os arch cinfo strfl pi
107108
(GenericPackageDescription pkg flags libs exes tests benchs) =
108109
let
109110
fds = flagInfo strfl flags
110-
conv = convBuildableCondTree os arch comp pi fds
111+
112+
conv :: Mon.Monoid a => Component -> (a -> BuildInfo) ->
113+
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
114+
conv comp getInfo = convCondTree os arch cinfo pi fds comp getInfo .
115+
PDC.addBuildableCondition getInfo
111116
in
112117
PInfo
113118
(maybe [] (conv ComponentLib libBuildInfo ) libs ++
@@ -129,20 +134,6 @@ prefix f fds = [f (concat fds)]
129134
flagInfo :: Bool -> [PD.Flag] -> FlagInfo
130135
flagInfo strfl = M.fromList . L.map (\ (MkFlag fn _ b m) -> (fn, FInfo b m (not (strfl || m))))
131136

132-
-- | Convert a condition tree to flagged dependencies.
133-
--
134-
-- In addition, tries to determine under which condition the condition tree
135-
-- is buildable, and will add an additional condition on top accordingly.
136-
convBuildableCondTree :: OS -> Arch -> CompilerInfo -> PI PN -> FlagInfo ->
137-
Component ->
138-
(a -> BuildInfo) ->
139-
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
140-
convBuildableCondTree os arch cinfo pi fds comp getInfo t =
141-
case PDC.extractCondition (buildable . getInfo) t of
142-
Lit True -> convCondTree os arch cinfo pi fds comp getInfo t
143-
Lit False -> []
144-
c -> convBranch os arch cinfo pi fds comp getInfo (c, t, Nothing)
145-
146137
-- | Convert condition trees to flagged dependencies.
147138
convCondTree :: OS -> Arch -> CompilerInfo -> PI PN -> FlagInfo ->
148139
Component ->

0 commit comments

Comments
 (0)