@@ -58,7 +58,7 @@ module Distribution.PackageDescription.Configuration (
58
58
) where
59
59
60
60
import Distribution.Package
61
- ( PackageName , Dependency (.. ) )
61
+ ( PackageName , Dependency (.. ), simplifyDependency )
62
62
import Distribution.PackageDescription
63
63
( GenericPackageDescription (.. ), PackageDescription (.. )
64
64
, Library (.. ), Executable (.. ), BuildInfo (.. )
@@ -70,14 +70,16 @@ import Distribution.Compiler
70
70
( CompilerId (CompilerId ) )
71
71
import Distribution.System
72
72
( Platform (.. ), OS , Arch )
73
- import Distribution.Simple.Utils (currentDir , lowercase )
73
+ import Distribution.Simple.Utils (currentDir , lowercase , comparing )
74
74
75
75
import Distribution.Text
76
76
( Text (parse ) )
77
77
import Distribution.Compat.ReadP as ReadP hiding ( char )
78
78
import Control.Arrow (first )
79
79
import qualified Distribution.Compat.ReadP as ReadP ( char )
80
80
81
+ import Control.Exception (assert )
82
+ import Data.List (sortBy , nub )
81
83
import Data.Char ( isAlphaNum )
82
84
import Data.Maybe ( catMaybes , maybeToList )
83
85
import Data.Map ( Map , fromListWith , toList )
@@ -485,9 +487,29 @@ finalizePackageDescription userflags satisfyDep (Platform arch os) impl constrai
485
487
Right ((mlib, exes'), targetSet, flagVals) ->
486
488
Right ( pkg { library = mlib
487
489
, executables = exes'
488
- , buildDepends = fromDepMap $ overallDependencies targetSet
490
+ , buildDepends = assert sanity overallDeps
489
491
}
490
492
, 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
+
491
513
Left missing -> Left missing
492
514
where
493
515
-- Combine lib and exes into one list of @CondTree@s with tagged data
0 commit comments