Skip to content

Commit

Permalink
Force Cabal >= 1.24 dep when there's no custom-setup stanza.
Browse files Browse the repository at this point in the history
Fixes #3199.
  • Loading branch information
23Skidoo committed Apr 14, 2016
1 parent d23a3b9 commit ecdfe57
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 35 deletions.
12 changes: 8 additions & 4 deletions Cabal/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module Distribution.PackageDescription (

import Distribution.Compat.Binary
import qualified Distribution.Compat.Semigroup as Semi ((<>))
import Distribution.Compat.Semigroup as Semi (Monoid(..), Semigroup, gmempty, gmappend)
import Distribution.Compat.Semigroup as Semi (Monoid(..), Semigroup, gmempty)
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import Distribution.Package
Expand Down Expand Up @@ -308,18 +308,22 @@ instance Text BuildType where
-- options authors can specify to just Haskell package dependencies.

data SetupBuildInfo = SetupBuildInfo {
setupDepends :: [Dependency]
setupDepends :: [Dependency],
defaultSetupDepends :: Bool
-- ^ Is this a default 'custom-setup' section added by the cabal-install
-- code (as opposed to user-provided)? See #3199.
}
deriving (Generic, Show, Eq, Read, Typeable, Data)

instance Binary SetupBuildInfo

instance Semi.Monoid SetupBuildInfo where
mempty = gmempty
mempty = SetupBuildInfo [] False
mappend = (Semi.<>)

instance Semigroup SetupBuildInfo where
(<>) = gmappend
a <> b = SetupBuildInfo (setupDepends a Semi.<> setupDepends b)
(defaultSetupDepends a || defaultSetupDepends b)

-- ---------------------------------------------------------------------------
-- Module renaming
Expand Down
48 changes: 30 additions & 18 deletions cabal-install/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,19 @@ configureSetupScript packageDBs
index
mpkg
= SetupScriptOptions {
useCabalVersion = cabalVersion
, useCabalSpecVersion = Nothing
, useCompiler = Just comp
, usePlatform = Just platform
, usePackageDB = packageDBs'
, usePackageIndex = index'
, useProgramConfig = conf
, useDistPref = distPref
, useLoggingHandle = Nothing
, useWorkingDir = Nothing
, setupCacheLock = lock
, useWin32CleanHack = False
useCabalVersion = cabalVersion
, noDefaultCabalDep = defaultSetupDeps
, useCabalSpecVersion = Nothing
, useCompiler = Just comp
, usePlatform = Just platform
, usePackageDB = packageDBs'
, usePackageIndex = index'
, useProgramConfig = conf
, useDistPref = distPref
, useLoggingHandle = Nothing
, useWorkingDir = Nothing
, setupCacheLock = lock
, useWin32CleanHack = False
, forceExternalSetupMethod = forceExternal
-- If we have explicit setup dependencies, list them; otherwise, we give
-- the empty list of dependencies; ideally, we would fix the version of
Expand All @@ -204,8 +205,8 @@ configureSetupScript packageDBs
-- know the version of Cabal at this point, but only find this there.
-- Therefore, for now, we just leave this blank.
, useDependencies = fromMaybe [] explicitSetupDeps
, useDependenciesExclusive = isJust explicitSetupDeps
, useVersionMacros = isJust explicitSetupDeps
, useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
, useVersionMacros = not defaultSetupDeps && isJust explicitSetupDeps
}
where
-- When we are compiling a legacy setup script without an explicit
Expand All @@ -223,13 +224,24 @@ configureSetupScript packageDBs
-- but if the user is using an odd db stack, don't touch it
_otherwise -> (packageDBs, Just index)

maybeSetupBuildInfo :: Maybe PkgDesc.SetupBuildInfo
maybeSetupBuildInfo = do
ReadyPackage (ConfiguredPackage (SourcePackage _ gpkg _ _) _ _ _) _
<- mpkg
PkgDesc.setupBuildInfo (PkgDesc.packageDescription gpkg)

-- Was a default 'custom-setup' stanza added by 'cabal-install' itself? If
-- so, 'setup-depends' must not be exclusive. See #3199.
defaultSetupDeps :: Bool
defaultSetupDeps = maybe False PkgDesc.defaultSetupDepends
maybeSetupBuildInfo

explicitSetupDeps :: Maybe [(UnitId, PackageId)]
explicitSetupDeps = do
ReadyPackage (ConfiguredPackage (SourcePackage _ gpkg _ _) _ _ _) deps
<- mpkg
-- Check if there is an explicit setup stanza
_buildInfo <- PkgDesc.setupBuildInfo (PkgDesc.packageDescription gpkg)
-- Check if there is an explicit setup stanza.
_buildInfo <- maybeSetupBuildInfo
-- Return the setup dependencies computed by the solver
ReadyPackage _ deps <- mpkg
return [ ( Installed.installedUnitId deppkg
, Installed.sourcePackageId deppkg
)
Expand Down
13 changes: 9 additions & 4 deletions cabal-install/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ import Distribution.PackageDescription.Configuration
import Distribution.Client.PackageUtils
( externalBuildDepends )
import Distribution.Version
( VersionRange, anyVersion, thisVersion, withinRange
, simplifyVersionRange )
( VersionRange, Version(..), anyVersion, orLaterVersion, thisVersion
, withinRange, simplifyVersionRange )
import Distribution.Compiler
( CompilerInfo(..) )
import Distribution.System
Expand All @@ -122,7 +122,7 @@ import Distribution.Verbosity
import Data.List
( foldl', sort, sortBy, nubBy, maximumBy, intercalate, nub )
import Data.Function (on)
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe)
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Set (Set)
Expand Down Expand Up @@ -409,7 +409,8 @@ addDefaultSetupDependencies defaultSetupDeps params =
-- NB: moving build-type check out kills performance.
case (PD.setupBuildInfo pkgdesc, bt) of
(Nothing, PD.Custom) -> Just PD.SetupBuildInfo {
PD.setupDepends = defaultSetupDeps srcpkg
PD.setupDepends = defaultSetupDeps srcpkg,
PD.defaultSetupDepends = True
}
(maybeSBI, _) -> maybeSBI
}
Expand Down Expand Up @@ -451,6 +452,10 @@ standardInstallPolicy
. hideInstalledPackagesSpecificBySourcePackageId
[ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]

. addDefaultSetupDependencies
(const [Dependency (PackageName "Cabal")
(orLaterVersion $ Version [1,24] [])])

. addSourcePackages
[ pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]

Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,7 @@ setupHsScriptOptions (ReadyPackage ElaboratedConfiguredPackage{..} deps)
useDependencies = [ (installedPackageId ipkg, packageId ipkg)
| ipkg <- CD.setupDeps deps ],
useDependenciesExclusive = True,
noDefaultCabalDep = False,
useVersionMacros = pkgSetupScriptStyle == SetupCustomExplicitDeps,
useProgramConfig = pkgConfigCompilerProgs,
useDistPref = builddir,
Expand Down
28 changes: 20 additions & 8 deletions cabal-install/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ import qualified System.Win32 as Win32

data SetupScriptOptions = SetupScriptOptions {
-- | The version of the Cabal library to use (if 'useDependenciesExclusive'
-- is not set). A suitable version of the Cabal library must be installed
-- (or for some build-types be the one cabal-install was built with).
-- or 'noDefaultCabalDep' is not set). A suitable version of the Cabal
-- library must be installed (or for some build-types be the one
-- cabal-install was built with).
--
-- The version found also determines the version of the Cabal specification
-- that we us for talking to the Setup.hs, unless overridden by
Expand Down Expand Up @@ -166,10 +167,11 @@ data SetupScriptOptions = SetupScriptOptions {

-- | Is the list of setup dependencies exclusive?
--
-- When this is @False@, if we compile the Setup.hs script we do so with
-- the list in 'useDependencies' but all other packages in the environment
-- are also visible. Additionally, a suitable version of @Cabal@ library
-- is added to the list of dependencies (see 'useCabalVersion').
-- When this is @False@, if we compile the Setup.hs script we do so with the
-- list in 'useDependencies' but all other packages in the environment are
-- also visible. Unless 'noDefaultCabalDep' is @True@, a suitable version of
-- @Cabal@ library is also added to the list of dependencies (see
-- 'useCabalVersion').
--
-- When @True@, only the 'useDependencies' packages are used, with other
-- packages in the environment hidden.
Expand All @@ -179,6 +181,13 @@ data SetupScriptOptions = SetupScriptOptions {
-- style with no dependencies.
useDependenciesExclusive :: Bool,

-- | Don't add a default dependency on Cabal even if
-- 'useDependenciesExclusive' is @False@. Assume that it is provided via
-- 'useDependencies'. This is turned on (in conjunction with
-- useDependenciesExclusive = False) when a default setup dependencies
-- stanza is added by cabal-install itself. See #3199.
noDefaultCabalDep :: Bool,

-- | Should we build the Setup.hs with CPP version macros available?
-- We turn this on when we have a setup stanza in .cabal that declares
-- explicit setup dependencies.
Expand Down Expand Up @@ -221,6 +230,7 @@ defaultSetupScriptOptions = SetupScriptOptions {
usePackageIndex = Nothing,
useDependencies = [],
useDependenciesExclusive = False,
noDefaultCabalDep = False,
useVersionMacros = False,
useProgramConfig = emptyProgramConfiguration,
useDistPref = defaultDistPref,
Expand Down Expand Up @@ -604,7 +614,7 @@ externalSetupMethod verbosity options pkg bt mkargs = do
-- With 'useDependenciesExclusive' we enforce the deps specified,
-- so only the given ones can be used. Otherwise we allow the use
-- of packages in the ambient environment, and add on a dep on the
-- Cabal library.
-- Cabal library (unless 'noDefaultCabalDep' is specified).
--
-- With 'useVersionMacros' we use a version CPP macros .h file.
--
Expand All @@ -613,7 +623,9 @@ externalSetupMethod verbosity options pkg bt mkargs = do
--
selectedDeps | useDependenciesExclusive options'
= useDependencies options'
| otherwise = useDependencies options' ++ cabalDep
| otherwise = useDependencies options' ++
if noDefaultCabalDep options'
then [] else cabalDep
addRenaming (ipid, pid) = (ipid, pid, defaultRenaming)
cppMacrosFile = setupDir </> "setup_macros.h"
ghcOptions = mempty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ exAvSrcPkg ex =
, C.benchmarks = error "not yet configured: benchmarks"
, C.buildDepends = error "not yet configured: buildDepends"
, C.setupBuildInfo = Just C.SetupBuildInfo {
C.setupDepends = mkSetupDeps (CD.setupDeps (exAvDeps ex))
C.setupDepends = mkSetupDeps (CD.setupDeps (exAvDeps ex)),
C.defaultSetupDepends = False
}
}
, C.genPackageFlags = nub $ concatMap extractFlags
Expand Down

0 comments on commit ecdfe57

Please sign in to comment.