@@ -58,7 +58,7 @@ module Distribution.PackageDescription.Configuration (
5858 ) where
5959
6060import Distribution.Package
61- ( PackageName , Dependency (.. ) )
61+ ( PackageName , Dependency (.. ), simplifyDependency )
6262import Distribution.PackageDescription
6363 ( GenericPackageDescription (.. ), PackageDescription (.. )
6464 , Library (.. ), Executable (.. ), BuildInfo (.. )
@@ -70,14 +70,16 @@ import Distribution.Compiler
7070 ( CompilerId (CompilerId ) )
7171import Distribution.System
7272 ( Platform (.. ), OS , Arch )
73- import Distribution.Simple.Utils (currentDir , lowercase )
73+ import Distribution.Simple.Utils (currentDir , lowercase , comparing )
7474
7575import Distribution.Text
7676 ( Text (parse ) )
7777import Distribution.Compat.ReadP as ReadP hiding ( char )
7878import Control.Arrow (first )
7979import qualified Distribution.Compat.ReadP as ReadP ( char )
8080
81+ import Control.Exception (assert )
82+ import Data.List (sortBy , nub )
8183import Data.Char ( isAlphaNum )
8284import Data.Maybe ( catMaybes , maybeToList )
8385import Data.Map ( Map , fromListWith , toList )
@@ -485,9 +487,29 @@ finalizePackageDescription userflags satisfyDep (Platform arch os) impl constrai
485487 Right ((mlib, exes'), targetSet, flagVals) ->
486488 Right ( pkg { library = mlib
487489 , executables = exes'
488- , buildDepends = fromDepMap $ overallDependencies targetSet
490+ , buildDepends = assert sanity overallDeps
489491 }
490492 , flagVals )
493+ where
494+ -- Note that we exclude non-buildable components. This means your tools and
495+ -- test progs to not contribute to the overall package dependencies.
496+ --
497+ overallDeps = nub
498+ . concatMap targetBuildDepends
499+ . filter buildable
500+ $ buildInfos
501+ buildInfos = map libBuildInfo (maybeToList mlib) ++ map buildInfo exes'
502+
503+ -- as a sanity check, check that the overall deps from the target set
504+ -- matches those from the (unfiltered for being buildable) components
505+ sanity = canonicalise overallDeps' == canonicalise overallDeps''
506+ overallDeps' = nub
507+ . concatMap targetBuildDepends
508+ $ buildInfos
509+ overallDeps'' = fromDepMap (overallDependencies targetSet)
510+ canonicalise = sortBy (comparing (\ (Dependency name _) -> name))
511+ . map simplifyDependency
512+
491513 Left missing -> Left missing
492514 where
493515 -- Combine lib and exes into one list of @CondTree@s with tagged data
0 commit comments