Skip to content

Commit ecdfe57

Browse files
committed
Force Cabal >= 1.24 dep when there's no custom-setup stanza.
Fixes #3199.
1 parent d23a3b9 commit ecdfe57

File tree

6 files changed

+70
-35
lines changed

6 files changed

+70
-35
lines changed

Cabal/Distribution/PackageDescription.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module Distribution.PackageDescription (
111111

112112
import Distribution.Compat.Binary
113113
import qualified Distribution.Compat.Semigroup as Semi ((<>))
114-
import Distribution.Compat.Semigroup as Semi (Monoid(..), Semigroup, gmempty, gmappend)
114+
import Distribution.Compat.Semigroup as Semi (Monoid(..), Semigroup, gmempty)
115115
import qualified Distribution.Compat.ReadP as Parse
116116
import Distribution.Compat.ReadP ((<++))
117117
import Distribution.Package
@@ -308,18 +308,22 @@ instance Text BuildType where
308308
-- options authors can specify to just Haskell package dependencies.
309309

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

315318
instance Binary SetupBuildInfo
316319

317320
instance Semi.Monoid SetupBuildInfo where
318-
mempty = gmempty
321+
mempty = SetupBuildInfo [] False
319322
mappend = (Semi.<>)
320323

321324
instance Semigroup SetupBuildInfo where
322-
(<>) = gmappend
325+
a <> b = SetupBuildInfo (setupDepends a Semi.<> setupDepends b)
326+
(defaultSetupDepends a || defaultSetupDepends b)
323327

324328
-- ---------------------------------------------------------------------------
325329
-- Module renaming

cabal-install/Distribution/Client/Configure.hs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,19 @@ configureSetupScript packageDBs
184184
index
185185
mpkg
186186
= SetupScriptOptions {
187-
useCabalVersion = cabalVersion
188-
, useCabalSpecVersion = Nothing
189-
, useCompiler = Just comp
190-
, usePlatform = Just platform
191-
, usePackageDB = packageDBs'
192-
, usePackageIndex = index'
193-
, useProgramConfig = conf
194-
, useDistPref = distPref
195-
, useLoggingHandle = Nothing
196-
, useWorkingDir = Nothing
197-
, setupCacheLock = lock
198-
, useWin32CleanHack = False
187+
useCabalVersion = cabalVersion
188+
, noDefaultCabalDep = defaultSetupDeps
189+
, useCabalSpecVersion = Nothing
190+
, useCompiler = Just comp
191+
, usePlatform = Just platform
192+
, usePackageDB = packageDBs'
193+
, usePackageIndex = index'
194+
, useProgramConfig = conf
195+
, useDistPref = distPref
196+
, useLoggingHandle = Nothing
197+
, useWorkingDir = Nothing
198+
, setupCacheLock = lock
199+
, useWin32CleanHack = False
199200
, forceExternalSetupMethod = forceExternal
200201
-- If we have explicit setup dependencies, list them; otherwise, we give
201202
-- the empty list of dependencies; ideally, we would fix the version of
@@ -204,8 +205,8 @@ configureSetupScript packageDBs
204205
-- know the version of Cabal at this point, but only find this there.
205206
-- Therefore, for now, we just leave this blank.
206207
, useDependencies = fromMaybe [] explicitSetupDeps
207-
, useDependenciesExclusive = isJust explicitSetupDeps
208-
, useVersionMacros = isJust explicitSetupDeps
208+
, useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
209+
, useVersionMacros = not defaultSetupDeps && isJust explicitSetupDeps
209210
}
210211
where
211212
-- When we are compiling a legacy setup script without an explicit
@@ -223,13 +224,24 @@ configureSetupScript packageDBs
223224
-- but if the user is using an odd db stack, don't touch it
224225
_otherwise -> (packageDBs, Just index)
225226

227+
maybeSetupBuildInfo :: Maybe PkgDesc.SetupBuildInfo
228+
maybeSetupBuildInfo = do
229+
ReadyPackage (ConfiguredPackage (SourcePackage _ gpkg _ _) _ _ _) _
230+
<- mpkg
231+
PkgDesc.setupBuildInfo (PkgDesc.packageDescription gpkg)
232+
233+
-- Was a default 'custom-setup' stanza added by 'cabal-install' itself? If
234+
-- so, 'setup-depends' must not be exclusive. See #3199.
235+
defaultSetupDeps :: Bool
236+
defaultSetupDeps = maybe False PkgDesc.defaultSetupDepends
237+
maybeSetupBuildInfo
238+
226239
explicitSetupDeps :: Maybe [(UnitId, PackageId)]
227240
explicitSetupDeps = do
228-
ReadyPackage (ConfiguredPackage (SourcePackage _ gpkg _ _) _ _ _) deps
229-
<- mpkg
230-
-- Check if there is an explicit setup stanza
231-
_buildInfo <- PkgDesc.setupBuildInfo (PkgDesc.packageDescription gpkg)
241+
-- Check if there is an explicit setup stanza.
242+
_buildInfo <- maybeSetupBuildInfo
232243
-- Return the setup dependencies computed by the solver
244+
ReadyPackage _ deps <- mpkg
233245
return [ ( Installed.installedUnitId deppkg
234246
, Installed.sourcePackageId deppkg
235247
)

cabal-install/Distribution/Client/Dependency.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ import Distribution.PackageDescription.Configuration
100100
import Distribution.Client.PackageUtils
101101
( externalBuildDepends )
102102
import Distribution.Version
103-
( VersionRange, anyVersion, thisVersion, withinRange
104-
, simplifyVersionRange )
103+
( VersionRange, Version(..), anyVersion, orLaterVersion, thisVersion
104+
, withinRange, simplifyVersionRange )
105105
import Distribution.Compiler
106106
( CompilerInfo(..) )
107107
import Distribution.System
@@ -122,7 +122,7 @@ import Distribution.Verbosity
122122
import Data.List
123123
( foldl', sort, sortBy, nubBy, maximumBy, intercalate, nub )
124124
import Data.Function (on)
125-
import Data.Maybe (fromMaybe)
125+
import Data.Maybe (fromMaybe)
126126
import qualified Data.Map as Map
127127
import qualified Data.Set as Set
128128
import Data.Set (Set)
@@ -409,7 +409,8 @@ addDefaultSetupDependencies defaultSetupDeps params =
409409
-- NB: moving build-type check out kills performance.
410410
case (PD.setupBuildInfo pkgdesc, bt) of
411411
(Nothing, PD.Custom) -> Just PD.SetupBuildInfo {
412-
PD.setupDepends = defaultSetupDeps srcpkg
412+
PD.setupDepends = defaultSetupDeps srcpkg,
413+
PD.defaultSetupDepends = True
413414
}
414415
(maybeSBI, _) -> maybeSBI
415416
}
@@ -451,6 +452,10 @@ standardInstallPolicy
451452
. hideInstalledPackagesSpecificBySourcePackageId
452453
[ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
453454

455+
. addDefaultSetupDependencies
456+
(const [Dependency (PackageName "Cabal")
457+
(orLaterVersion $ Version [1,24] [])])
458+
454459
. addSourcePackages
455460
[ pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
456461

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@ setupHsScriptOptions (ReadyPackage ElaboratedConfiguredPackage{..} deps)
17541754
useDependencies = [ (installedPackageId ipkg, packageId ipkg)
17551755
| ipkg <- CD.setupDeps deps ],
17561756
useDependenciesExclusive = True,
1757+
noDefaultCabalDep = False,
17571758
useVersionMacros = pkgSetupScriptStyle == SetupCustomExplicitDeps,
17581759
useProgramConfig = pkgConfigCompilerProgs,
17591760
useDistPref = builddir,

cabal-install/Distribution/Client/SetupWrapper.hs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ import qualified System.Win32 as Win32
131131

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

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

184+
-- | Don't add a default dependency on Cabal even if
185+
-- 'useDependenciesExclusive' is @False@. Assume that it is provided via
186+
-- 'useDependencies'. This is turned on (in conjunction with
187+
-- useDependenciesExclusive = False) when a default setup dependencies
188+
-- stanza is added by cabal-install itself. See #3199.
189+
noDefaultCabalDep :: Bool,
190+
182191
-- | Should we build the Setup.hs with CPP version macros available?
183192
-- We turn this on when we have a setup stanza in .cabal that declares
184193
-- explicit setup dependencies.
@@ -221,6 +230,7 @@ defaultSetupScriptOptions = SetupScriptOptions {
221230
usePackageIndex = Nothing,
222231
useDependencies = [],
223232
useDependenciesExclusive = False,
233+
noDefaultCabalDep = False,
224234
useVersionMacros = False,
225235
useProgramConfig = emptyProgramConfiguration,
226236
useDistPref = defaultDistPref,
@@ -604,7 +614,7 @@ externalSetupMethod verbosity options pkg bt mkargs = do
604614
-- With 'useDependenciesExclusive' we enforce the deps specified,
605615
-- so only the given ones can be used. Otherwise we allow the use
606616
-- of packages in the ambient environment, and add on a dep on the
607-
-- Cabal library.
617+
-- Cabal library (unless 'noDefaultCabalDep' is specified).
608618
--
609619
-- With 'useVersionMacros' we use a version CPP macros .h file.
610620
--
@@ -613,7 +623,9 @@ externalSetupMethod verbosity options pkg bt mkargs = do
613623
--
614624
selectedDeps | useDependenciesExclusive options'
615625
= useDependencies options'
616-
| otherwise = useDependencies options' ++ cabalDep
626+
| otherwise = useDependencies options' ++
627+
if noDefaultCabalDep options'
628+
then [] else cabalDep
617629
addRenaming (ipid, pid) = (ipid, pid, defaultRenaming)
618630
cppMacrosFile = setupDir </> "setup_macros.h"
619631
ghcOptions = mempty {

cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/DSL.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ exAvSrcPkg ex =
168168
, C.benchmarks = error "not yet configured: benchmarks"
169169
, C.buildDepends = error "not yet configured: buildDepends"
170170
, C.setupBuildInfo = Just C.SetupBuildInfo {
171-
C.setupDepends = mkSetupDeps (CD.setupDeps (exAvDeps ex))
171+
C.setupDepends = mkSetupDeps (CD.setupDeps (exAvDeps ex)),
172+
C.defaultSetupDepends = False
172173
}
173174
}
174175
, C.genPackageFlags = nub $ concatMap extractFlags

0 commit comments

Comments
 (0)