@@ -92,16 +92,14 @@ import Distribution.Package
9292 , Package (.. ), packageName , packageVersion
9393 , UnitId , Dependency (Dependency ))
9494import qualified Distribution.PackageDescription as PD
95- ( PackageDescription (.. ), SetupBuildInfo (.. )
96- , GenericPackageDescription (.. )
97- , Flag (flagName ), FlagName (.. ) )
95+ import qualified Distribution.PackageDescription.Configuration as PD
9896import Distribution.PackageDescription.Configuration
9997 ( finalizePackageDescription )
10098import Distribution.Client.PackageUtils
10199 ( externalBuildDepends )
102100import Distribution.Version
103- ( VersionRange , anyVersion , thisVersion , withinRange
104- , simplifyVersionRange )
101+ ( VersionRange , Version ( .. ), anyVersion , orLaterVersion , thisVersion
102+ , withinRange , simplifyVersionRange )
105103import Distribution.Compiler
106104 ( CompilerInfo (.. ) )
107105import Distribution.System
@@ -122,7 +120,7 @@ import Distribution.Verbosity
122120import Data.List
123121 ( foldl' , sort , sortBy , nubBy , maximumBy , intercalate , nub )
124122import Data.Function (on )
125- import Data.Maybe (fromMaybe )
123+ import Data.Maybe (fromMaybe )
126124import qualified Data.Map as Map
127125import qualified Data.Set as Set
128126import Data.Set (Set )
@@ -392,7 +390,7 @@ removeUpperBounds allowNewer params =
392390-- 'addSourcePackages'. Otherwise, the packages inserted by
393391-- 'addSourcePackages' won't have upper bounds in dependencies relaxed.
394392--
395- addDefaultSetupDependencies :: (SourcePackage -> [Dependency ])
393+ addDefaultSetupDependencies :: (SourcePackage -> Maybe [Dependency ])
396394 -> DepResolverParams -> DepResolverParams
397395addDefaultSetupDependencies defaultSetupDeps params =
398396 params {
@@ -408,9 +406,12 @@ addDefaultSetupDependencies defaultSetupDeps params =
408406 PD. setupBuildInfo =
409407 case PD. setupBuildInfo pkgdesc of
410408 Just sbi -> Just sbi
411- Nothing -> Just PD. SetupBuildInfo {
412- PD. setupDepends = defaultSetupDeps srcpkg
413- }
409+ Nothing -> case defaultSetupDeps srcpkg of
410+ Nothing -> Nothing
411+ Just deps -> Just PD. SetupBuildInfo {
412+ PD. defaultSetupDepends = True ,
413+ PD. setupDepends = deps
414+ }
414415 }
415416 }
416417 }
@@ -449,12 +450,41 @@ standardInstallPolicy
449450 . hideInstalledPackagesSpecificBySourcePackageId
450451 [ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
451452
453+ . addDefaultSetupDependencies mkDefaultSetupDeps
454+
452455 . addSourcePackages
453456 [ pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
454457
455458 $ basicDepResolverParams
456459 installedPkgIndex sourcePkgIndex
457460
461+ where
462+ -- Force Cabal >= 1.24 dep when the package is affected by #3199.
463+ mkDefaultSetupDeps :: SourcePackage -> Maybe [Dependency ]
464+ mkDefaultSetupDeps srcpkg | affected =
465+ Just [Dependency (PackageName " Cabal" )
466+ (orLaterVersion $ Version [1 ,24 ] [] )]
467+ | otherwise = Nothing
468+ where
469+ gpkgdesc = packageDescription srcpkg
470+ pkgdesc = PD. packageDescription gpkgdesc
471+ bt = fromMaybe PD. Custom (PD. buildType pkgdesc)
472+ affected = bt == PD. Custom && hasBuildableFalse gpkgdesc
473+
474+ -- Does this package contain any components with non-empty 'build-depends'
475+ -- and a 'buildable' field that could potentially be set to 'False'? False
476+ -- positives are possible.
477+ hasBuildableFalse :: PD. GenericPackageDescription -> Bool
478+ hasBuildableFalse gpkg =
479+ not (all alwaysTrue (zipWith PD. cOr buildableConditions noDepConditions))
480+ where
481+ buildableConditions = PD. extractConditions PD. buildable gpkg
482+ noDepConditions = PD. extractConditions
483+ (null . PD. targetBuildDepends) gpkg
484+ alwaysTrue (PD. Lit True ) = True
485+ alwaysTrue _ = False
486+
487+
458488applySandboxInstallPolicy :: SandboxPackageInfo
459489 -> DepResolverParams
460490 -> DepResolverParams
0 commit comments