Skip to content

Commit 0e4112a

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

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-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: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@ convSP os arch cinfo strfl (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
103103
-- | Convert a generic package description to a solver-specific 'PInfo'.
104104
convGPD :: OS -> Arch -> CompilerInfo -> Bool ->
105105
PI PN -> GenericPackageDescription -> PInfo
106-
convGPD os arch comp strfl pi
106+
convGPD os arch cinfo strfl pi
107107
(GenericPackageDescription pkg flags libs exes tests benchs) =
108108
let
109109
fds = flagInfo strfl flags
110-
conv = convBuildableCondTree os arch comp pi fds
110+
111+
conv :: Monoid a => Component -> (a -> BuildInfo) ->
112+
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
113+
conv comp getInfo = convCondTree os arch cinfo pi fds comp getInfo .
114+
PDC.addBuildableCondition getInfo
111115
in
112116
PInfo
113117
(maybe [] (conv ComponentLib libBuildInfo ) libs ++
@@ -129,20 +133,6 @@ prefix f fds = [f (concat fds)]
129133
flagInfo :: Bool -> [PD.Flag] -> FlagInfo
130134
flagInfo strfl = M.fromList . L.map (\ (MkFlag fn _ b m) -> (fn, FInfo b m (not (strfl || m))))
131135

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-
146136
-- | Convert condition trees to flagged dependencies.
147137
convCondTree :: OS -> Arch -> CompilerInfo -> PI PN -> FlagInfo ->
148138
Component ->

0 commit comments

Comments
 (0)