@@ -137,7 +137,7 @@ data SetupOpts = SetupOpts
137137 -- ^ Don't check for a compatible GHC version/architecture
138138 , soptsSkipMsys :: ! Bool
139139 -- ^ Do not use a custom msys installation on Windows
140- , soptsUpgradeCabal :: ! Bool
140+ , soptsUpgradeCabal :: ! ( Maybe UpgradeTo )
141141 -- ^ Upgrade the global Cabal library in the database to the newest
142142 -- version. Only works reliably with a stack-managed installation.
143143 , soptsResolveMissingGHC :: ! (Maybe Text )
@@ -231,7 +231,7 @@ setupEnv mResolveMissingGHC = do
231231 , soptsSanityCheck = False
232232 , soptsSkipGhcCheck = configSkipGHCCheck config
233233 , soptsSkipMsys = configSkipMsys config
234- , soptsUpgradeCabal = False
234+ , soptsUpgradeCabal = Nothing
235235 , soptsResolveMissingGHC = mResolveMissingGHC
236236 , soptsSetupInfoYaml = defaultSetupInfoYaml
237237 , soptsGHCBindistURL = Nothing
@@ -489,11 +489,12 @@ ensureCompiler sopts = do
489489 m <- augmentPathMap (edBins ed) (unEnvOverride menv0)
490490 mkEnvOverride (configPlatform config) (removeHaskellEnvVars m)
491491
492- when (soptsUpgradeCabal sopts) $ do
492+ let cabalVersion = soptsUpgradeCabal sopts
493+ when (isJust $ cabalVersion) $ do
493494 unless needLocal $ do
494- $ logWarn " Trying to upgrade Cabal library on a GHC not installed by stack."
495+ $ logWarn " Trying to change a Cabal library on a GHC not installed by stack."
495496 $ logWarn " This may fail, caveat emptor!"
496- upgradeCabal menv wc
497+ upgradeCabal menv wc (fromJust cabalVersion)
497498
498499 case mtools of
499500 Just (Just (ToolGhcjs cv), _) -> ensureGhcjsBooted menv cv (soptsInstallIfMissing sopts)
@@ -622,46 +623,47 @@ ensureDockerStackExe containerPlatform = do
622623 downloadStackExe platforms sri stackExeDir (const $ return () )
623624 return stackExePath
624625
625- -- | Install the newest version of Cabal globally
626+ -- | Install the newest version or a specific version of Cabal globally
626627upgradeCabal :: (StackM env m , HasConfig env , HasGHCVariant env )
627628 => EnvOverride
628629 -> WhichCompiler
630+ -> UpgradeTo
629631 -> m ()
630- upgradeCabal menv wc = do
632+ upgradeCabal menv wc cabalVersion = do
631633 let name = $ (mkPackageName " Cabal" )
632634 rmap <- resolvePackages menv Nothing Map. empty (Set. singleton name)
633- newest <-
634- case map rpIdent rmap of
635+ version <- case cabalVersion of
636+ Specific v -> return v
637+ Latest -> case map rpIdent rmap of
635638 [] -> error " No Cabal library found in index, cannot upgrade"
636- [PackageIdentifier name' version]
637- | name == name' -> return version
639+ [PackageIdentifier name' version] | name == name' -> return version
638640 x -> error $ " Unexpected results for resolvePackages: " ++ show x
639641 installed <- getCabalPkgVer menv wc
640- if installed >= newest
642+ if installed >= version
641643 then $ logInfo $ T. concat
642644 [ " Currently installed Cabal is "
643645 , T. pack $ versionString installed
644- , " , newest is "
645- , T. pack $ versionString newest
646- , " . I'm not upgrading Cabal."
646+ , case cabalVersion of
647+ Specific _ -> " (specified)"
648+ Latest -> " (latest)"
649+ , " . No work to be done."
647650 ]
648651 else withSystemTempDir " stack-cabal-upgrade" $ \ tmpdir -> do
649652 $ logInfo $ T. concat
650653 [ " Installing Cabal-"
651- , T. pack $ versionString newest
654+ , T. pack $ versionString version
652655 , " to replace "
653656 , T. pack $ versionString installed
654657 ]
655- let ident = PackageIdentifier name newest
658+ let ident = PackageIdentifier name version
656659 -- Nothing below: use the newest .cabal file revision
657660 m <- unpackPackageIdents menv tmpdir Nothing (Map. singleton ident Nothing )
658661
659662 compilerPath <- join $ findExecutable menv (compilerExeName wc)
660- newestDir <- parseRelDir $ versionString newest
663+ newestDir <- parseRelDir $ versionString version
661664 let installRoot = toFilePath $ parent (parent compilerPath)
662665 </> $ (mkRelDir " new-cabal" )
663666 </> newestDir
664-
665667 dir <-
666668 case Map. lookup ident m of
667669 Nothing -> error " upgradeCabal: Invariant violated, dir missing"
0 commit comments