Skip to content

Commit 5b854ab

Browse files
committed
SetupWrapper: allow being explicit about the Cabal spec version
A new option in SetupScriptOptions to specify exactly what version of the Cabal spec we believe we're using when we're talking to the Setup.hs. Currently the version of cabal to use is guessed by the SetupWrapper code based on the useCabalVersion version range and what versions are installed in the ambient package environment, and cached state of whatever an existing compiled Setup used. When an explicit useCabalSpecVersion is given, all of these heuristics are short cut and we use exactly the version we're told to use. In this case it's the responsibility of the caller to useDependencies with a suitable Cabal lib version, or otherwise know that we'll be using the self or internal setup methods. This approach goes along with the idea of deciding up front (and in a deterministic way) what setup deps to use (using defaults if needed), rather than deciding based on what's currently in the user environment. In the current code paths, useCabalSpecVersion is Nothing, so no change in behaviour yet.
1 parent 41c2080 commit 5b854ab

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

cabal-install/Distribution/Client/Configure.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ configureSetupScript packageDBs
182182
mpkg
183183
= SetupScriptOptions {
184184
useCabalVersion = cabalVersion
185+
, useCabalSpecVersion = Nothing
185186
, useCompiler = Just comp
186187
, usePlatform = Just platform
187188
, usePackageDB = packageDBs'

cabal-install/Distribution/Client/SetupWrapper.hs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ import qualified System.Win32 as Win32
122122

123123
data SetupScriptOptions = SetupScriptOptions {
124124
useCabalVersion :: VersionRange,
125+
126+
-- | This is the version of the Cabal specification that we believe that
127+
-- this package uses. This affects the semantics and in particular the
128+
-- Setup command line interface.
129+
useCabalSpecVersion :: Maybe Version,
125130
useCompiler :: Maybe Compiler,
126131
usePlatform :: Maybe Platform,
127132
usePackageDB :: PackageDBStack,
@@ -180,6 +185,7 @@ data SetupScriptOptions = SetupScriptOptions {
180185
defaultSetupScriptOptions :: SetupScriptOptions
181186
defaultSetupScriptOptions = SetupScriptOptions {
182187
useCabalVersion = anyVersion,
188+
useCabalSpecVersion = Nothing,
183189
useCompiler = Nothing,
184190
usePlatform = Nothing,
185191
usePackageDB = [GlobalPackageDB, UserPackageDB],
@@ -242,7 +248,9 @@ determineSetupMethod options buildType'
242248
-- between the self and internal setup methods, which are
243249
-- consistent with each other.
244250
| buildType' == Custom = externalSetupMethod
245-
| not (cabalVersion `withinRange`
251+
| maybe False (cabalVersion /=)
252+
(useCabalSpecVersion options)
253+
|| not (cabalVersion `withinRange`
246254
useCabalVersion options) = externalSetupMethod
247255
| isJust (useLoggingHandle options)
248256
-- Forcing is done to use an external process e.g. due to parallel
@@ -345,18 +353,24 @@ externalSetupMethod verbosity options pkg bt mkargs = do
345353

346354
cabalLibVersionToUse :: IO (Version, (Maybe UnitId)
347355
,SetupScriptOptions)
348-
cabalLibVersionToUse = do
349-
savedVer <- savedVersion
350-
case savedVer of
351-
Just version | version `withinRange` useCabalVersion options
352-
-> do updateSetupScript version bt
353-
-- Does the previously compiled setup executable still exist and
354-
-- is it up-to date?
355-
useExisting <- canUseExistingSetup version
356-
if useExisting
357-
then return (version, Nothing, options)
358-
else installedVersion
359-
_ -> installedVersion
356+
cabalLibVersionToUse =
357+
case useCabalSpecVersion options of
358+
Just version -> do
359+
updateSetupScript version bt
360+
writeFile setupVersionFile (show version ++ "\n")
361+
return (version, Nothing, options)
362+
Nothing -> do
363+
savedVer <- savedVersion
364+
case savedVer of
365+
Just version | version `withinRange` useCabalVersion options
366+
-> do updateSetupScript version bt
367+
-- Does the previously compiled setup executable still exist
368+
-- and is it up-to date?
369+
useExisting <- canUseExistingSetup version
370+
if useExisting
371+
then return (version, Nothing, options)
372+
else installedVersion
373+
_ -> installedVersion
360374
where
361375
-- This check duplicates the checks in 'getCachedSetupExecutable' /
362376
-- 'compileSetupExecutable'. Unfortunately, we have to perform it twice

0 commit comments

Comments
 (0)