Skip to content

Commit a0ca303

Browse files
committed
Exclude non-buildable components when constructing the overall package deps
1 parent a891311 commit a0ca303

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

Distribution/PackageDescription/Configuration.hs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module Distribution.PackageDescription.Configuration (
5858
) where
5959

6060
import Distribution.Package
61-
( PackageName, Dependency(..) )
61+
( PackageName, Dependency(..), simplifyDependency )
6262
import Distribution.PackageDescription
6363
( GenericPackageDescription(..), PackageDescription(..)
6464
, Library(..), Executable(..), BuildInfo(..)
@@ -70,14 +70,16 @@ import Distribution.Compiler
7070
( CompilerId(CompilerId) )
7171
import Distribution.System
7272
( Platform(..), OS, Arch )
73-
import Distribution.Simple.Utils (currentDir, lowercase)
73+
import Distribution.Simple.Utils (currentDir, lowercase, comparing)
7474

7575
import Distribution.Text
7676
( Text(parse) )
7777
import Distribution.Compat.ReadP as ReadP hiding ( char )
7878
import Control.Arrow (first)
7979
import qualified Distribution.Compat.ReadP as ReadP ( char )
8080

81+
import Control.Exception (assert)
82+
import Data.List (sortBy, nub)
8183
import Data.Char ( isAlphaNum )
8284
import Data.Maybe ( catMaybes, maybeToList )
8385
import 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

Comments
 (0)