Skip to content

Commit 0b62af1

Browse files
committed
Solve for both "build-tools" and "tool-depends" executable dependencies
1 parent 4013b53 commit 0b62af1

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

cabal-install/Distribution/Solver/Modular/IndexConversion.hs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import Prelude hiding (pi)
1212
import Distribution.Compiler
1313
import Distribution.InstalledPackageInfo as IPI
1414
import Distribution.Package -- from Cabal
15+
import Distribution.Simple.BuildToolDepends -- from Cabal
1516
import Distribution.Types.Dependency -- from Cabal
16-
import Distribution.Types.LegacyExeDependency -- from Cabal
17+
import Distribution.Types.ExeDependency -- from Cabal
1718
import Distribution.Types.PkgconfigDependency -- from Cabal
1819
import Distribution.Types.UnqualComponentName -- from Cabal
1920
import Distribution.PackageDescription as PD -- from Cabal
@@ -131,7 +132,7 @@ convGPD os arch cinfo strfl sexes pi
131132

132133
conv :: Mon.Monoid a => Component -> (a -> BuildInfo) ->
133134
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
134-
conv comp getInfo = convCondTree os arch cinfo pi fds comp getInfo ipns sexes .
135+
conv comp getInfo = convCondTree pkg os arch cinfo pi fds comp getInfo ipns sexes .
135136
PDC.addBuildableCondition getInfo
136137

137138
flagged_deps
@@ -178,47 +179,33 @@ filterIPNs ipns (Dependency pn _) fd
178179
-- | Convert condition trees to flagged dependencies. Mutually
179180
-- recursive with 'convBranch'. See 'convBranch' for an explanation
180181
-- of all arguments preceeding the input 'CondTree'.
181-
convCondTree :: OS -> Arch -> CompilerInfo -> PI PN -> FlagInfo ->
182+
convCondTree :: PackageDescription -> OS -> Arch -> CompilerInfo -> PI PN -> FlagInfo ->
182183
Component ->
183184
(a -> BuildInfo) ->
184185
IPNs ->
185186
SolveExecutables ->
186187
CondTree ConfVar [Dependency] a -> FlaggedDeps Component PN
187-
convCondTree os arch cinfo pi@(PI pn _) fds comp getInfo ipns sexes@(SolveExecutables sexes') (CondNode info ds branches) =
188+
convCondTree pkg os arch cinfo pi@(PI pn _) fds comp getInfo ipns sexes@(SolveExecutables sexes') (CondNode info ds branches) =
188189
concatMap
189190
(\d -> filterIPNs ipns d (D.Simple (convLibDep pn d) comp))
190191
ds -- unconditional package dependencies
191192
++ L.map (\e -> D.Simple (Ext e) comp) (PD.allExtensions bi) -- unconditional extension dependencies
192193
++ L.map (\l -> D.Simple (Lang l) comp) (PD.allLanguages bi) -- unconditional language dependencies
193194
++ L.map (\(PkgconfigDependency pkn vr) -> D.Simple (Pkg pkn vr) comp) (PD.pkgconfigDepends bi) -- unconditional pkg-config dependencies
194-
++ concatMap (convBranch os arch cinfo pi fds comp getInfo ipns sexes) branches
195+
++ concatMap (convBranch pkg os arch cinfo pi fds comp getInfo ipns sexes) branches
195196
-- build-tools dependencies
196197
-- NB: Only include these dependencies if SolveExecutables
197198
-- is True. It might be false in the legacy solver
198199
-- codepath, in which case there won't be any record of
199200
-- an executable we need.
200-
++ [ D.Simple (convExeDep pn (Dependency pn' vr)) comp
201+
++ [ D.Simple (convExeDep pn exeDep) comp
201202
| sexes'
202-
, LegacyExeDependency exe vr <- PD.buildTools bi
203-
, Just pn' <- return $ packageProvidingBuildTool exe
203+
, exeDep <- getAllToolDependencies pkg bi
204+
, not $ isInternal pkg exeDep
204205
]
205206
where
206207
bi = getInfo info
207208

208-
-- | This function maps known @build-tools@ entries to Haskell package
209-
-- names which provide them. This mapping corresponds exactly to
210-
-- those build-tools that Cabal understands by default
211-
-- ('builtinPrograms'), and are cabal install'able. This mapping is
212-
-- purely for legacy; for other executables, @tool-depends@ should be
213-
-- used instead.
214-
--
215-
packageProvidingBuildTool :: String -> Maybe PackageName
216-
packageProvidingBuildTool s =
217-
if s `elem` ["hscolour", "haddock", "happy", "alex", "hsc2hs",
218-
"c2hs", "cpphs", "greencard"]
219-
then Just (mkPackageName s)
220-
else Nothing
221-
222209
-- | Branch interpreter. Mutually recursive with 'convCondTree'.
223210
--
224211
-- Here, we try to simplify one of Cabal's condition tree branches into the
@@ -250,7 +237,7 @@ packageProvidingBuildTool s =
250237
--
251238
-- 6. The set of package names which should be considered internal
252239
-- dependencies, and thus not handled as dependencies.
253-
convBranch :: OS -> Arch -> CompilerInfo ->
240+
convBranch :: PackageDescription -> OS -> Arch -> CompilerInfo ->
254241
PI PN -> FlagInfo ->
255242
Component ->
256243
(a -> BuildInfo) ->
@@ -259,9 +246,9 @@ convBranch :: OS -> Arch -> CompilerInfo ->
259246
(Condition ConfVar,
260247
CondTree ConfVar [Dependency] a,
261248
Maybe (CondTree ConfVar [Dependency] a)) -> FlaggedDeps Component PN
262-
convBranch os arch cinfo pi@(PI pn _) fds comp getInfo ipns sexes (c', t', mf') =
263-
go c' ( convCondTree os arch cinfo pi fds comp getInfo ipns sexes t')
264-
(maybe [] (convCondTree os arch cinfo pi fds comp getInfo ipns sexes) mf')
249+
convBranch pkg os arch cinfo pi@(PI pn _) fds comp getInfo ipns sexes (c', t', mf') =
250+
go c' ( convCondTree pkg os arch cinfo pi fds comp getInfo ipns sexes t')
251+
(maybe [] (convCondTree pkg os arch cinfo pi fds comp getInfo ipns sexes) mf')
265252
where
266253
go :: Condition ConfVar ->
267254
FlaggedDeps Component PN -> FlaggedDeps Component PN -> FlaggedDeps Component PN
@@ -313,8 +300,9 @@ convLibDep :: PN -> Dependency -> Dep PN
313300
convLibDep pn' (Dependency pn vr) = Dep False {- not exe -} pn (Constrained [(vr, P pn')])
314301

315302
-- | Convert a Cabal dependency on a executable (build-tools) to a solver-specific dependency.
316-
convExeDep :: PN -> Dependency -> Dep PN
317-
convExeDep pn' (Dependency pn vr) = Dep True pn (Constrained [(vr, P pn')])
303+
-- TODO do something about the name of the exe component itself
304+
convExeDep :: PN -> ExeDependency -> Dep PN
305+
convExeDep pn' (ExeDependency pn _ vr) = Dep True pn (Constrained [(vr, P pn')])
318306

319307
-- | Convert setup dependencies
320308
convSetupBuildInfo :: PI PN -> SetupBuildInfo -> FlaggedDeps Component PN

0 commit comments

Comments
 (0)