2020-04-09 17:53:22 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2020-01-11 20:15:05 +00:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
2020-03-21 21:19:37 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2020-01-11 20:15:05 +00:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2020-03-21 21:19:37 +00:00
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2020-04-21 21:37:48 +00:00
|
|
|
{-# LANGUAGE ViewPatterns #-}
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
{-|
|
|
|
|
Module : GHCup
|
|
|
|
Description : GHCup installation functions
|
|
|
|
Copyright : (c) Julian Ospald, 2020
|
2020-07-30 18:04:02 +00:00
|
|
|
License : LGPL-3.0
|
2020-07-21 23:08:58 +00:00
|
|
|
Maintainer : hasufell@hasufell.de
|
|
|
|
Stability : experimental
|
|
|
|
Portability : POSIX
|
|
|
|
|
|
|
|
This module contains the main functions that correspond
|
|
|
|
to the command line interface, like installation, listing versions
|
|
|
|
and so on.
|
|
|
|
|
|
|
|
These are the entry points.
|
|
|
|
-}
|
2020-01-11 20:15:05 +00:00
|
|
|
module GHCup where
|
|
|
|
|
|
|
|
|
|
|
|
import GHCup.Download
|
|
|
|
import GHCup.Errors
|
|
|
|
import GHCup.Platform
|
|
|
|
import GHCup.Types
|
|
|
|
import GHCup.Types.JSON ( )
|
|
|
|
import GHCup.Types.Optics
|
|
|
|
import GHCup.Utils
|
|
|
|
import GHCup.Utils.File
|
|
|
|
import GHCup.Utils.Prelude
|
|
|
|
import GHCup.Utils.String.QQ
|
|
|
|
import GHCup.Utils.Version.QQ
|
|
|
|
import GHCup.Version
|
|
|
|
|
2020-07-12 20:29:50 +00:00
|
|
|
#if !defined(TAR)
|
2020-07-04 21:33:48 +00:00
|
|
|
import Codec.Archive ( ArchiveResult )
|
2020-07-12 20:29:50 +00:00
|
|
|
#endif
|
2020-01-11 20:15:05 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Control.Exception.Safe
|
|
|
|
import Control.Monad
|
2020-04-09 17:53:22 +00:00
|
|
|
#if !MIN_VERSION_base(4,13,0)
|
|
|
|
import Control.Monad.Fail ( MonadFail )
|
|
|
|
#endif
|
2020-01-11 20:15:05 +00:00
|
|
|
import Control.Monad.Logger
|
|
|
|
import Control.Monad.Reader
|
|
|
|
import Control.Monad.Trans.Resource
|
|
|
|
hiding ( throwM )
|
|
|
|
import Data.ByteString ( ByteString )
|
2020-05-10 22:18:53 +00:00
|
|
|
import Data.Either
|
2020-01-11 20:15:05 +00:00
|
|
|
import Data.List
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.String.Interpolate
|
2020-04-25 10:06:41 +00:00
|
|
|
import Data.Text ( Text )
|
2020-01-11 20:15:05 +00:00
|
|
|
import Data.Versions
|
|
|
|
import Data.Word8
|
|
|
|
import GHC.IO.Exception
|
|
|
|
import HPath
|
2020-07-15 13:00:59 +00:00
|
|
|
import HPath.IO hiding ( hideError )
|
2020-01-11 20:15:05 +00:00
|
|
|
import Haskus.Utils.Variant.Excepts
|
|
|
|
import Optics
|
|
|
|
import Prelude hiding ( abs
|
|
|
|
, readFile
|
|
|
|
, writeFile
|
|
|
|
)
|
2020-05-10 22:18:53 +00:00
|
|
|
import Safe hiding ( at )
|
2020-01-11 20:15:05 +00:00
|
|
|
import System.IO.Error
|
2020-04-25 10:06:41 +00:00
|
|
|
import System.Posix.Env.ByteString ( getEnvironment )
|
2020-09-12 14:41:17 +00:00
|
|
|
import System.Posix.FilePath ( getSearchPath, takeExtension )
|
2020-04-12 18:22:16 +00:00
|
|
|
import System.Posix.Files.ByteString
|
2020-09-12 14:41:17 +00:00
|
|
|
import Text.Regex.Posix
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
import qualified Crypto.Hash.SHA256 as SHA256
|
|
|
|
import qualified Data.ByteString.Base16 as B16
|
2020-01-11 20:15:05 +00:00
|
|
|
import qualified Data.ByteString as B
|
2020-04-25 10:06:41 +00:00
|
|
|
import qualified Data.ByteString.Lazy as BL
|
2020-01-11 20:15:05 +00:00
|
|
|
import qualified Data.Map.Strict as Map
|
2020-04-25 10:06:41 +00:00
|
|
|
import qualified Data.Text as T
|
2020-01-11 20:15:05 +00:00
|
|
|
import qualified Data.Text.Encoding as E
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-------------------------
|
|
|
|
--[ Tool installation ]--
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Like 'installGHCBin', except takes the 'DownloadInfo' as
|
|
|
|
-- argument instead of looking it up from 'GHCupDownloads'.
|
2020-07-21 18:18:51 +00:00
|
|
|
installGHCBindist :: ( MonadFail m
|
2020-07-21 23:08:58 +00:00
|
|
|
, MonadMask m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadIO m
|
|
|
|
)
|
|
|
|
=> DownloadInfo -- ^ where/how to download
|
|
|
|
-> Version -- ^ the version to install
|
|
|
|
-> PlatformRequest -- ^ the platform to install on
|
|
|
|
-> Excepts
|
|
|
|
'[ AlreadyInstalled
|
|
|
|
, BuildFailed
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
|
|
|
, NotInstalled
|
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-12 20:29:50 +00:00
|
|
|
#if !defined(TAR)
|
2020-07-21 23:08:58 +00:00
|
|
|
, ArchiveResult
|
2020-07-12 20:29:50 +00:00
|
|
|
#endif
|
2020-07-21 23:08:58 +00:00
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
2020-09-12 14:41:17 +00:00
|
|
|
installGHCBindist dlinfo ver pfreq = do
|
2020-04-25 10:06:41 +00:00
|
|
|
let tver = (mkTVer ver)
|
2020-01-11 20:15:05 +00:00
|
|
|
lift $ $(logDebug) [i|Requested to install GHC with #{ver}|]
|
2020-08-05 19:50:39 +00:00
|
|
|
whenM (lift $ ghcInstalled tver)
|
2020-01-11 20:15:05 +00:00
|
|
|
$ (throwE $ AlreadyInstalled GHC ver)
|
|
|
|
|
|
|
|
-- download (or use cached version)
|
2020-04-22 16:12:40 +00:00
|
|
|
dl <- liftE $ downloadCached dlinfo Nothing
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- prepare paths
|
2020-08-05 19:50:39 +00:00
|
|
|
ghcdir <- lift $ ghcupGHCDir tver
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
liftE $ installPackedGHC dl (view dlSubdir dlinfo) ghcdir ver pfreq
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-04-25 10:06:41 +00:00
|
|
|
liftE $ postGHCInstall tver
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
-- | Install a packed GHC distribution. This only deals with unpacking and the GHC
|
|
|
|
-- build system and nothing else.
|
|
|
|
installPackedGHC :: ( MonadMask m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
|
|
|
)
|
|
|
|
=> Path Abs -- ^ Path to the packed GHC bindist
|
|
|
|
-> Maybe TarDir -- ^ Subdir of the archive
|
|
|
|
-> Path Abs -- ^ Path to install to
|
|
|
|
-> Version -- ^ The GHC version
|
|
|
|
-> PlatformRequest
|
|
|
|
-> Excepts
|
|
|
|
'[ BuildFailed
|
|
|
|
, UnknownArchive
|
|
|
|
, TarDirDoesNotExist
|
|
|
|
#if !defined(TAR)
|
|
|
|
, ArchiveResult
|
|
|
|
#endif
|
|
|
|
] m ()
|
|
|
|
installPackedGHC dl msubdir inst ver pfreq@(PlatformRequest {..}) = do
|
|
|
|
-- unpack
|
|
|
|
tmpUnpack <- lift mkGhcupTmpDir
|
|
|
|
liftE $ unpackToDir tmpUnpack dl
|
|
|
|
void $ liftIO $ darwinNotarization _rPlatform tmpUnpack
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
-- the subdir of the archive where we do the work
|
|
|
|
workdir <- maybe (pure tmpUnpack)
|
|
|
|
(liftE . intoSubdir tmpUnpack)
|
|
|
|
(msubdir)
|
|
|
|
|
|
|
|
liftE $ runBuildAction tmpUnpack
|
|
|
|
(Just inst)
|
|
|
|
(installUnpackedGHC workdir inst ver pfreq)
|
|
|
|
|
|
|
|
|
|
|
|
-- | Install an unpacked GHC distribution. This only deals with the GHC
|
|
|
|
-- build system and nothing else.
|
|
|
|
installUnpackedGHC :: ( MonadReader Settings m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
|
|
|
)
|
|
|
|
=> Path Abs -- ^ Path to the unpacked GHC bindist (where the configure script resides)
|
|
|
|
-> Path Abs -- ^ Path to install to
|
|
|
|
-> Version -- ^ The GHC version
|
|
|
|
-> PlatformRequest
|
|
|
|
-> Excepts '[ProcessError] m ()
|
|
|
|
installUnpackedGHC path inst ver (PlatformRequest {..}) = do
|
|
|
|
lift $ $(logInfo) "Installing GHC (this may take a while)"
|
|
|
|
lEM $ execLogged "./configure"
|
|
|
|
False
|
|
|
|
(["--prefix=" <> toFilePath inst] ++ alpineArgs)
|
|
|
|
[rel|ghc-configure|]
|
|
|
|
(Just path)
|
|
|
|
Nothing
|
|
|
|
lEM $ make ["install"] (Just path)
|
|
|
|
pure ()
|
|
|
|
where
|
2020-07-20 18:48:22 +00:00
|
|
|
alpineArgs
|
2020-09-12 14:41:17 +00:00
|
|
|
| ver >= [vver|8.2.2|], Linux Alpine <- _rPlatform
|
|
|
|
= ["--disable-ld-override"]
|
|
|
|
| otherwise
|
|
|
|
= []
|
2020-07-20 18:48:22 +00:00
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Installs GHC into @~\/.ghcup\/ghc/\<ver\>@ and places the
|
|
|
|
-- following symlinks in @~\/.ghcup\/bin@:
|
|
|
|
--
|
|
|
|
-- * @ghc-x.y.z -> ..\/ghc\/x.y.z\/bin/ghc@
|
|
|
|
-- * @ghc-x.y -> ..\/ghc\/x.y.z\/bin/ghc@ (if x.y.z is the latest x.y version)
|
2020-07-21 18:18:51 +00:00
|
|
|
installGHCBin :: ( MonadFail m
|
|
|
|
, MonadMask m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadIO m
|
|
|
|
)
|
2020-07-21 23:08:58 +00:00
|
|
|
=> GHCupDownloads -- ^ the download info to look up the tarball from
|
|
|
|
-> Version -- ^ the version to install
|
|
|
|
-> PlatformRequest -- ^ the platform to install on
|
2020-07-21 18:18:51 +00:00
|
|
|
-> Excepts
|
|
|
|
'[ AlreadyInstalled
|
|
|
|
, BuildFailed
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
|
|
|
, NotInstalled
|
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-12 20:29:50 +00:00
|
|
|
#if !defined(TAR)
|
2020-07-21 18:18:51 +00:00
|
|
|
, ArchiveResult
|
2020-07-12 20:29:50 +00:00
|
|
|
#endif
|
2020-07-21 18:18:51 +00:00
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
|
|
|
installGHCBin bDls ver pfreq = do
|
|
|
|
dlinfo <- lE $ getDownloadInfo GHC ver pfreq bDls
|
|
|
|
installGHCBindist dlinfo ver pfreq
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Like 'installCabalBin', except takes the 'DownloadInfo' as
|
|
|
|
-- argument instead of looking it up from 'GHCupDownloads'.
|
2020-07-21 18:18:51 +00:00
|
|
|
installCabalBindist :: ( MonadMask m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadFail m
|
|
|
|
)
|
|
|
|
=> DownloadInfo
|
|
|
|
-> Version
|
|
|
|
-> PlatformRequest
|
|
|
|
-> Excepts
|
|
|
|
'[ AlreadyInstalled
|
|
|
|
, CopyError
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
|
|
|
, NotInstalled
|
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-21 18:18:51 +00:00
|
|
|
#if !defined(TAR)
|
|
|
|
, ArchiveResult
|
|
|
|
#endif
|
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
|
|
|
installCabalBindist dlinfo ver (PlatformRequest {..}) = do
|
2020-01-11 20:15:05 +00:00
|
|
|
lift $ $(logDebug) [i|Requested to install cabal version #{ver}|]
|
2020-05-10 22:18:53 +00:00
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
whenM
|
2020-08-05 19:50:39 +00:00
|
|
|
(lift (cabalInstalled ver) >>= \a -> liftIO $
|
2020-05-10 22:18:53 +00:00
|
|
|
handleIO (\_ -> pure False)
|
|
|
|
$ fmap (\x -> a && isSymbolicLink x)
|
|
|
|
-- ignore when the installation is a legacy cabal (binary, not symlink)
|
2020-08-05 19:50:39 +00:00
|
|
|
$ getSymbolicLinkStatus (toFilePath (binDir </> [rel|cabal|]))
|
2020-05-10 22:18:53 +00:00
|
|
|
)
|
|
|
|
$ (throwE $ AlreadyInstalled Cabal ver)
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
-- download (or use cached version)
|
2020-04-25 10:06:41 +00:00
|
|
|
dl <- liftE $ downloadCached dlinfo Nothing
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- unpack
|
2020-04-25 10:06:41 +00:00
|
|
|
tmpUnpack <- lift withGHCupTmpDir
|
2020-01-11 20:15:05 +00:00
|
|
|
liftE $ unpackToDir tmpUnpack dl
|
2020-04-10 17:27:17 +00:00
|
|
|
void $ liftIO $ darwinNotarization _rPlatform tmpUnpack
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- the subdir of the archive where we do the work
|
2020-08-06 11:28:20 +00:00
|
|
|
workdir <- maybe (pure tmpUnpack) (liftE . intoSubdir tmpUnpack) (view dlSubdir dlinfo)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
liftE $ installCabal' workdir binDir
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
-- create symlink if this is the latest version
|
2020-08-05 19:50:39 +00:00
|
|
|
cVers <- lift $ fmap rights $ getInstalledCabals
|
2020-05-10 22:18:53 +00:00
|
|
|
let lInstCabal = headMay . reverse . sort $ cVers
|
|
|
|
when (maybe True (ver >=) lInstCabal) $ liftE $ setCabal ver
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
pure ()
|
|
|
|
|
|
|
|
where
|
2020-04-26 09:55:20 +00:00
|
|
|
-- | Install an unpacked cabal distribution.
|
2020-01-11 20:15:05 +00:00
|
|
|
installCabal' :: (MonadLogger m, MonadCatch m, MonadIO m)
|
|
|
|
=> Path Abs -- ^ Path to the unpacked cabal bindist (where the executable resides)
|
|
|
|
-> Path Abs -- ^ Path to install to
|
|
|
|
-> Excepts '[CopyError] m ()
|
|
|
|
installCabal' path inst = do
|
2020-03-21 21:19:37 +00:00
|
|
|
lift $ $(logInfo) "Installing cabal"
|
2020-03-16 09:47:09 +00:00
|
|
|
let cabalFile = [rel|cabal|]
|
2020-08-31 11:03:12 +00:00
|
|
|
liftIO $ createDirRecursive' inst
|
2020-05-10 22:18:53 +00:00
|
|
|
destFileName <- lift $ parseRel (toFilePath cabalFile <> "-" <> verToBS ver)
|
2020-08-14 20:07:39 +00:00
|
|
|
let destPath = inst </> destFileName
|
2020-01-11 20:15:05 +00:00
|
|
|
handleIO (throwE . CopyError . show) $ liftIO $ copyFile
|
|
|
|
(path </> cabalFile)
|
2020-08-14 20:07:39 +00:00
|
|
|
(destPath)
|
2020-01-11 20:15:05 +00:00
|
|
|
Overwrite
|
2020-08-14 20:18:14 +00:00
|
|
|
lift $ chmod_777 destPath
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
2020-07-22 00:34:17 +00:00
|
|
|
-- | Installs cabal into @~\/.ghcup\/bin/cabal-\<ver\>@ and
|
2020-07-21 23:08:58 +00:00
|
|
|
-- creates a default @cabal -> cabal-x.y.z.q@ symlink for
|
|
|
|
-- the latest installed version.
|
2020-07-21 18:18:51 +00:00
|
|
|
installCabalBin :: ( MonadMask m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadFail m
|
|
|
|
)
|
|
|
|
=> GHCupDownloads
|
|
|
|
-> Version
|
|
|
|
-> PlatformRequest
|
|
|
|
-> Excepts
|
|
|
|
'[ AlreadyInstalled
|
|
|
|
, CopyError
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
|
|
|
, NotInstalled
|
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-21 18:18:51 +00:00
|
|
|
#if !defined(TAR)
|
|
|
|
, ArchiveResult
|
|
|
|
#endif
|
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
2020-07-21 20:42:39 +00:00
|
|
|
installCabalBin bDls ver pfreq = do
|
2020-07-21 21:10:47 +00:00
|
|
|
dlinfo <- lE $ getDownloadInfo Cabal ver pfreq bDls
|
2020-07-21 18:18:51 +00:00
|
|
|
installCabalBindist dlinfo ver pfreq
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
---------------------
|
|
|
|
--[ Set GHC/cabal ]--
|
|
|
|
---------------------
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Set GHC symlinks in @~\/.ghcup\/bin@ for the requested GHC version. The behavior depends
|
2020-01-11 20:15:05 +00:00
|
|
|
-- on `SetGHC`:
|
|
|
|
--
|
2020-07-21 23:08:58 +00:00
|
|
|
-- * SetGHCOnly: @~\/.ghcup\/bin\/ghc -> ~\/.ghcup\/ghc\/\<ver\>\/bin\/ghc@
|
|
|
|
-- * SetGHC_XY: @~\/.ghcup\/bin\/ghc-X.Y -> ~\/.ghcup\/ghc\/\<ver\>\/bin\/ghc@
|
|
|
|
-- * SetGHC_XYZ: @~\/.ghcup\/bin\/ghc-\<ver\> -> ~\/.ghcup\/ghc\/\<ver\>\/bin\/ghc@
|
2020-01-11 20:15:05 +00:00
|
|
|
--
|
2020-07-21 23:08:58 +00:00
|
|
|
-- Additionally creates a @~\/.ghcup\/share -> ~\/.ghcup\/ghc\/\<ver\>\/share symlink@
|
|
|
|
-- for 'SetGHCOnly' constructor.
|
2020-08-06 11:28:20 +00:00
|
|
|
setGHC :: ( MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadFail m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadCatch m
|
|
|
|
)
|
2020-04-25 10:06:41 +00:00
|
|
|
=> GHCTargetVersion
|
2020-01-11 20:15:05 +00:00
|
|
|
-> SetGHC
|
2020-04-25 10:06:41 +00:00
|
|
|
-> Excepts '[NotInstalled] m GHCTargetVersion
|
2020-01-11 20:15:05 +00:00
|
|
|
setGHC ver sghc = do
|
2020-04-25 10:06:41 +00:00
|
|
|
let verBS = verToBS (_tvVersion ver)
|
2020-08-06 11:28:20 +00:00
|
|
|
ghcdir <- lift $ ghcupGHCDir ver
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-08-13 18:40:09 +00:00
|
|
|
whenM (lift $ fmap not $ ghcInstalled ver) (throwE (NotInstalled GHC (ver ^. tvVersion % to prettyVer)))
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
-- symlink destination
|
2020-08-06 11:28:20 +00:00
|
|
|
Settings { dirs = Dirs {..} } <- lift ask
|
2020-08-31 11:03:12 +00:00
|
|
|
liftIO $ createDirRecursive' binDir
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- first delete the old symlinks (this fixes compatibility issues
|
|
|
|
-- with old ghcup)
|
|
|
|
case sghc of
|
2020-04-25 10:06:41 +00:00
|
|
|
SetGHCOnly -> liftE $ rmPlain (_tvTarget ver)
|
2020-01-11 20:15:05 +00:00
|
|
|
SetGHC_XY -> lift $ rmMajorSymlinks ver
|
|
|
|
SetGHC_XYZ -> lift $ rmMinorSymlinks ver
|
|
|
|
|
|
|
|
-- for ghc tools (ghc, ghci, haddock, ...)
|
|
|
|
verfiles <- ghcToolFiles ver
|
|
|
|
forM_ verfiles $ \file -> do
|
2020-08-06 11:28:20 +00:00
|
|
|
mTargetFile <- case sghc of
|
|
|
|
SetGHCOnly -> pure $ Just file
|
2020-01-11 20:15:05 +00:00
|
|
|
SetGHC_XY -> do
|
2020-08-06 11:28:20 +00:00
|
|
|
v' <-
|
|
|
|
handle
|
|
|
|
(\(e :: ParseError) -> lift $ $(logWarn) [i|#{e}|] >> pure Nothing)
|
|
|
|
$ fmap Just
|
|
|
|
$ getMajorMinorV (_tvVersion ver)
|
|
|
|
forM v' $ \(mj, mi) ->
|
|
|
|
let major' = E.encodeUtf8 $ intToText mj <> "." <> intToText mi
|
|
|
|
in parseRel (toFilePath file <> B.singleton _hyphen <> major')
|
|
|
|
SetGHC_XYZ ->
|
|
|
|
fmap Just $ parseRel (toFilePath file <> B.singleton _hyphen <> verBS)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- create symlink
|
2020-08-06 11:28:20 +00:00
|
|
|
forM mTargetFile $ \targetFile -> do
|
|
|
|
let fullF = binDir </> targetFile
|
|
|
|
destL <- lift $ ghcLinkDestination (toFilePath file) ver
|
|
|
|
lift $ $(logDebug) [i|ln -s #{destL} #{toFilePath fullF}|]
|
|
|
|
liftIO $ createSymlink fullF destL
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- create symlink for share dir
|
2020-04-25 10:06:41 +00:00
|
|
|
when (isNothing . _tvTarget $ ver) $ lift $ symlinkShareDir ghcdir verBS
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-04-15 15:06:48 +00:00
|
|
|
pure ver
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
where
|
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
symlinkShareDir :: (MonadReader Settings m, MonadIO m, MonadLogger m)
|
2020-01-11 20:15:05 +00:00
|
|
|
=> Path Abs
|
|
|
|
-> ByteString
|
|
|
|
-> m ()
|
|
|
|
symlinkShareDir ghcdir verBS = do
|
2020-08-06 11:28:20 +00:00
|
|
|
Settings { dirs = Dirs {..} } <- ask
|
2020-08-05 19:50:39 +00:00
|
|
|
let destdir = baseDir
|
2020-01-11 20:15:05 +00:00
|
|
|
case sghc of
|
|
|
|
SetGHCOnly -> do
|
2020-03-16 09:47:09 +00:00
|
|
|
let sharedir = [rel|share|]
|
2020-01-11 20:15:05 +00:00
|
|
|
let fullsharedir = ghcdir </> sharedir
|
|
|
|
whenM (liftIO $ doesDirectoryExist fullsharedir) $ do
|
|
|
|
let fullF = destdir </> sharedir
|
2020-03-21 21:19:37 +00:00
|
|
|
let targetF = "./ghc/" <> verBS <> "/" <> toFilePath sharedir
|
2020-01-11 20:15:05 +00:00
|
|
|
$(logDebug) [i|rm -f #{fullF}|]
|
|
|
|
liftIO $ hideError doesNotExistErrorType $ deleteFile fullF
|
|
|
|
$(logDebug) [i|ln -s #{targetF} #{fullF}|]
|
|
|
|
liftIO $ createSymlink fullF targetF
|
|
|
|
_ -> pure ()
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Set the @~\/.ghcup\/bin\/cabal@ symlink.
|
2020-08-05 19:50:39 +00:00
|
|
|
setCabal :: (MonadReader Settings m, MonadLogger m, MonadThrow m, MonadFail m, MonadIO m)
|
2020-05-10 22:18:53 +00:00
|
|
|
=> Version
|
|
|
|
-> Excepts '[NotInstalled] m ()
|
|
|
|
setCabal ver = do
|
|
|
|
let verBS = verToBS ver
|
|
|
|
targetFile <- parseRel ("cabal-" <> verBS)
|
|
|
|
|
|
|
|
-- symlink destination
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
2020-08-31 11:03:12 +00:00
|
|
|
liftIO $ createDirRecursive' binDir
|
2020-05-10 22:18:53 +00:00
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
whenM (liftIO $ fmap not $ doesFileExist (binDir </> targetFile))
|
2020-05-10 22:18:53 +00:00
|
|
|
$ throwE
|
|
|
|
$ NotInstalled Cabal (prettyVer ver)
|
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
let cabalbin = binDir </> [rel|cabal|]
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
-- delete old file (may be binary or symlink)
|
|
|
|
lift $ $(logDebug) [i|rm -f #{toFilePath cabalbin}|]
|
|
|
|
liftIO $ hideError doesNotExistErrorType $ deleteFile
|
|
|
|
cabalbin
|
|
|
|
|
|
|
|
-- create symlink
|
|
|
|
let destL = toFilePath targetFile
|
|
|
|
lift $ $(logDebug) [i|ln -s #{destL} #{toFilePath cabalbin}|]
|
|
|
|
liftIO $ createSymlink cabalbin destL
|
|
|
|
|
|
|
|
pure ()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
------------------
|
|
|
|
--[ List tools ]--
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Filter data type for 'listVersions'.
|
2020-01-11 20:15:05 +00:00
|
|
|
data ListCriteria = ListInstalled
|
|
|
|
| ListSet
|
|
|
|
deriving Show
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | A list result describes a single tool version
|
|
|
|
-- and various of its properties.
|
2020-01-11 20:15:05 +00:00
|
|
|
data ListResult = ListResult
|
|
|
|
{ lTool :: Tool
|
|
|
|
, lVer :: Version
|
2020-04-25 10:06:41 +00:00
|
|
|
, lCross :: Maybe Text -- ^ currently only for GHC
|
2020-01-11 20:15:05 +00:00
|
|
|
, lTag :: [Tag]
|
|
|
|
, lInstalled :: Bool
|
2020-04-21 21:37:48 +00:00
|
|
|
, lSet :: Bool -- ^ currently active version
|
|
|
|
, fromSrc :: Bool -- ^ compiled from source
|
|
|
|
, lStray :: Bool -- ^ not in download info
|
2020-05-15 19:53:45 +00:00
|
|
|
, lNoBindist :: Bool -- ^ whether the version is available for this platform/arch
|
2020-01-11 20:15:05 +00:00
|
|
|
}
|
2020-04-21 21:37:48 +00:00
|
|
|
deriving (Eq, Ord, Show)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Extract all available tool versions and their tags.
|
2020-04-21 21:37:48 +00:00
|
|
|
availableToolVersions :: GHCupDownloads -> Tool -> Map.Map Version [Tag]
|
|
|
|
availableToolVersions av tool = view
|
|
|
|
(at tool % non Map.empty % to (fmap (_viTags)))
|
2020-01-11 20:15:05 +00:00
|
|
|
av
|
|
|
|
|
|
|
|
|
2020-04-21 21:37:48 +00:00
|
|
|
-- | List all versions from the download info, as well as stray
|
|
|
|
-- versions.
|
2020-05-15 19:53:45 +00:00
|
|
|
listVersions :: ( MonadCatch m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
2020-08-05 19:50:39 +00:00
|
|
|
, MonadReader Settings m
|
2020-05-15 19:53:45 +00:00
|
|
|
)
|
2020-04-21 21:37:48 +00:00
|
|
|
=> GHCupDownloads
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Maybe Tool
|
|
|
|
-> Maybe ListCriteria
|
2020-07-13 16:27:21 +00:00
|
|
|
-> PlatformRequest
|
|
|
|
-> m [ListResult]
|
|
|
|
listVersions av lt criteria pfreq = do
|
2020-05-15 19:53:45 +00:00
|
|
|
case lt of
|
|
|
|
Just t -> do
|
|
|
|
-- get versions from GHCupDownloads
|
|
|
|
let avTools = availableToolVersions av t
|
2020-08-05 19:50:39 +00:00
|
|
|
lr <- filter' <$> forM (Map.toList avTools) (toListResult t)
|
2020-05-15 19:53:45 +00:00
|
|
|
|
|
|
|
case t of
|
|
|
|
-- append stray GHCs
|
|
|
|
GHC -> do
|
2020-07-13 16:27:21 +00:00
|
|
|
slr <- strayGHCs avTools
|
2020-05-15 19:53:45 +00:00
|
|
|
pure $ (sort (slr ++ lr))
|
2020-08-14 14:53:32 +00:00
|
|
|
Cabal -> do
|
|
|
|
slr <- strayCabals avTools
|
|
|
|
pure $ (sort (slr ++ lr))
|
2020-05-15 19:53:45 +00:00
|
|
|
_ -> pure lr
|
|
|
|
Nothing -> do
|
2020-07-13 16:27:21 +00:00
|
|
|
ghcvers <- listVersions av (Just GHC) criteria pfreq
|
|
|
|
cabalvers <- listVersions av (Just Cabal) criteria pfreq
|
|
|
|
ghcupvers <- listVersions av (Just GHCup) criteria pfreq
|
2020-05-15 19:53:45 +00:00
|
|
|
pure (ghcvers <> cabalvers <> ghcupvers)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
where
|
2020-08-05 19:50:39 +00:00
|
|
|
strayGHCs :: (MonadReader Settings m, MonadThrow m, MonadLogger m, MonadIO m)
|
2020-04-21 21:37:48 +00:00
|
|
|
=> Map.Map Version [Tag]
|
|
|
|
-> m [ListResult]
|
|
|
|
strayGHCs avTools = do
|
2020-04-25 10:06:41 +00:00
|
|
|
ghcs <- getInstalledGHCs
|
|
|
|
fmap catMaybes $ forM ghcs $ \case
|
|
|
|
Right tver@GHCTargetVersion{ _tvTarget = Nothing, .. } -> do
|
|
|
|
case Map.lookup _tvVersion avTools of
|
|
|
|
Just _ -> pure Nothing
|
|
|
|
Nothing -> do
|
|
|
|
lSet <- fmap (maybe False (\(GHCTargetVersion _ v ) -> v == _tvVersion)) $ ghcSet Nothing
|
2020-08-05 19:50:39 +00:00
|
|
|
fromSrc <- ghcSrcInstalled tver
|
2020-04-25 10:06:41 +00:00
|
|
|
pure $ Just $ ListResult
|
|
|
|
{ lTool = GHC
|
|
|
|
, lVer = _tvVersion
|
|
|
|
, lCross = Nothing
|
|
|
|
, lTag = []
|
|
|
|
, lInstalled = True
|
|
|
|
, lStray = maybe True (const False) (Map.lookup _tvVersion avTools)
|
2020-05-15 19:53:45 +00:00
|
|
|
, lNoBindist = False
|
2020-04-25 10:06:41 +00:00
|
|
|
, ..
|
|
|
|
}
|
|
|
|
Right tver@GHCTargetVersion{ .. } -> do
|
|
|
|
lSet <- fmap (maybe False (\(GHCTargetVersion _ v ) -> v == _tvVersion)) $ ghcSet _tvTarget
|
2020-08-05 19:50:39 +00:00
|
|
|
fromSrc <- ghcSrcInstalled tver
|
2020-04-25 10:06:41 +00:00
|
|
|
pure $ Just $ ListResult
|
|
|
|
{ lTool = GHC
|
|
|
|
, lVer = _tvVersion
|
|
|
|
, lCross = _tvTarget
|
|
|
|
, lTag = []
|
|
|
|
, lInstalled = True
|
|
|
|
, lStray = True -- NOTE: cross currently cannot be installed via bindist
|
2020-05-15 19:53:45 +00:00
|
|
|
, lNoBindist = False
|
2020-04-25 10:06:41 +00:00
|
|
|
, ..
|
|
|
|
}
|
|
|
|
Left e -> do
|
|
|
|
$(logWarn)
|
|
|
|
[i|Could not parse version of stray directory #{toFilePath e}|]
|
|
|
|
pure Nothing
|
|
|
|
|
2020-08-14 14:53:32 +00:00
|
|
|
strayCabals :: (MonadReader Settings m, MonadCatch m, MonadThrow m, MonadLogger m, MonadIO m)
|
|
|
|
=> Map.Map Version [Tag]
|
|
|
|
-> m [ListResult]
|
|
|
|
strayCabals avTools = do
|
|
|
|
cabals <- getInstalledCabals
|
|
|
|
fmap catMaybes $ forM cabals $ \case
|
|
|
|
Right ver ->
|
|
|
|
case Map.lookup ver avTools of
|
|
|
|
Just _ -> pure Nothing
|
|
|
|
Nothing -> do
|
|
|
|
lSet <- fmap (maybe False (== ver)) $ cabalSet
|
|
|
|
pure $ Just $ ListResult
|
|
|
|
{ lTool = Cabal
|
|
|
|
, lVer = ver
|
|
|
|
, lCross = Nothing
|
|
|
|
, lTag = []
|
|
|
|
, lInstalled = True
|
|
|
|
, lStray = maybe True (const False) (Map.lookup ver avTools)
|
|
|
|
, lNoBindist = False
|
|
|
|
, fromSrc = False -- actually, we don't know :>
|
|
|
|
, ..
|
|
|
|
}
|
|
|
|
Left e -> do
|
|
|
|
$(logWarn)
|
|
|
|
[i|Could not parse version of stray directory #{toFilePath e}|]
|
|
|
|
pure Nothing
|
|
|
|
|
2020-04-25 10:06:41 +00:00
|
|
|
-- NOTE: this are not cross ones, because no bindists
|
2020-08-05 19:50:39 +00:00
|
|
|
toListResult :: (MonadReader Settings m, MonadIO m, MonadCatch m) => Tool -> (Version, [Tag]) -> m ListResult
|
2020-07-13 16:27:21 +00:00
|
|
|
toListResult t (v, tags) = case t of
|
2020-01-11 20:15:05 +00:00
|
|
|
GHC -> do
|
2020-05-15 19:53:45 +00:00
|
|
|
let lNoBindist = isLeft $ getDownloadInfo GHC v pfreq av
|
2020-04-25 10:06:41 +00:00
|
|
|
let tver = mkTVer v
|
|
|
|
lSet <- fmap (maybe False (\(GHCTargetVersion _ v') -> v' == v)) $ ghcSet Nothing
|
|
|
|
lInstalled <- ghcInstalled tver
|
|
|
|
fromSrc <- ghcSrcInstalled tver
|
|
|
|
pure ListResult { lVer = v, lCross = Nothing , lTag = tags, lTool = t, lStray = False, .. }
|
2020-01-11 20:15:05 +00:00
|
|
|
Cabal -> do
|
2020-05-15 19:53:45 +00:00
|
|
|
let lNoBindist = isLeft $ getDownloadInfo Cabal v pfreq av
|
2020-05-10 22:18:53 +00:00
|
|
|
lSet <- fmap (maybe False (== v)) $ cabalSet
|
|
|
|
lInstalled <- cabalInstalled v
|
2020-04-21 21:37:48 +00:00
|
|
|
pure ListResult { lVer = v
|
2020-04-25 10:06:41 +00:00
|
|
|
, lCross = Nothing
|
2020-04-21 21:37:48 +00:00
|
|
|
, lTag = tags
|
|
|
|
, lTool = t
|
|
|
|
, fromSrc = False
|
|
|
|
, lStray = False
|
|
|
|
, ..
|
|
|
|
}
|
2020-01-11 20:15:05 +00:00
|
|
|
GHCup -> do
|
|
|
|
let lSet = prettyPVP ghcUpVer == prettyVer v
|
2020-03-16 09:49:34 +00:00
|
|
|
let lInstalled = lSet
|
2020-04-21 21:37:48 +00:00
|
|
|
pure ListResult { lVer = v
|
|
|
|
, lTag = tags
|
2020-04-25 10:06:41 +00:00
|
|
|
, lCross = Nothing
|
2020-04-21 21:37:48 +00:00
|
|
|
, lTool = t
|
|
|
|
, fromSrc = False
|
|
|
|
, lStray = False
|
2020-05-15 19:53:45 +00:00
|
|
|
, lNoBindist = False
|
2020-04-21 21:37:48 +00:00
|
|
|
, ..
|
|
|
|
}
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
filter' :: [ListResult] -> [ListResult]
|
|
|
|
filter' lr = case criteria of
|
|
|
|
Nothing -> lr
|
|
|
|
Just ListInstalled -> filter (\ListResult {..} -> lInstalled) lr
|
|
|
|
Just ListSet -> filter (\ListResult {..} -> lSet) lr
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
--------------------
|
|
|
|
--[ GHC/cabal rm ]--
|
|
|
|
--------------------
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Delete a ghc version and all its symlinks.
|
|
|
|
--
|
|
|
|
-- This may leave GHCup without a "set" version.
|
|
|
|
-- Will try to fix the ghc-x.y symlink after removal (e.g. to an
|
|
|
|
-- older version).
|
2020-08-06 11:28:20 +00:00
|
|
|
rmGHCVer :: ( MonadReader Settings m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadFail m
|
|
|
|
, MonadCatch m
|
|
|
|
)
|
2020-04-25 10:06:41 +00:00
|
|
|
=> GHCTargetVersion
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Excepts '[NotInstalled] m ()
|
|
|
|
rmGHCVer ver = do
|
2020-08-05 19:50:39 +00:00
|
|
|
isSetGHC <- lift $ fmap (maybe False (== ver)) $ ghcSet (_tvTarget ver)
|
2020-08-13 18:40:09 +00:00
|
|
|
|
|
|
|
whenM (lift $ fmap not $ ghcInstalled ver) (throwE (NotInstalled GHC (ver ^. tvVersion % to prettyVer)))
|
|
|
|
dir <- lift $ ghcupGHCDir ver
|
|
|
|
|
|
|
|
-- this isn't atomic, order matters
|
|
|
|
when isSetGHC $ do
|
|
|
|
lift $ $(logInfo) [i|Removing ghc symlinks|]
|
|
|
|
liftE $ rmPlain (_tvTarget ver)
|
|
|
|
|
|
|
|
lift $ $(logInfo) [i|Removing directory recursively: #{toFilePath dir}|]
|
|
|
|
liftIO $ deleteDirRecursive dir
|
|
|
|
|
|
|
|
lift $ $(logInfo) [i|Removing ghc-x.y.z symlinks|]
|
|
|
|
lift $ rmMinorSymlinks ver
|
|
|
|
|
|
|
|
lift $ $(logInfo) [i|Removing/rewiring ghc-x.y symlinks|]
|
|
|
|
-- first remove
|
|
|
|
handle (\(_ :: ParseError) -> pure ()) $ lift $ rmMajorSymlinks ver
|
|
|
|
-- then fix them (e.g. with an earlier version)
|
|
|
|
v' <-
|
|
|
|
handle
|
|
|
|
(\(e :: ParseError) -> lift $ $(logWarn) [i|#{e}|] >> pure Nothing)
|
|
|
|
$ fmap Just
|
|
|
|
$ getMajorMinorV (_tvVersion ver)
|
|
|
|
forM_ v' $ \(mj, mi) -> lift (getGHCForMajor mj mi (_tvTarget ver))
|
|
|
|
>>= mapM_ (\v -> liftE $ setGHC v SetGHC_XY)
|
|
|
|
|
|
|
|
Settings { dirs = Dirs {..} } <- lift ask
|
|
|
|
|
|
|
|
liftIO
|
|
|
|
$ hideError doesNotExistErrorType
|
|
|
|
$ deleteFile
|
|
|
|
$ (baseDir </> [rel|share|])
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Delete a cabal version. Will try to fix the @cabal@ symlink
|
|
|
|
-- after removal (e.g. setting it to an older version).
|
2020-08-05 19:50:39 +00:00
|
|
|
rmCabalVer :: (MonadReader Settings m, MonadThrow m, MonadLogger m, MonadIO m, MonadFail m, MonadCatch m)
|
2020-05-10 22:18:53 +00:00
|
|
|
=> Version
|
|
|
|
-> Excepts '[NotInstalled] m ()
|
|
|
|
rmCabalVer ver = do
|
2020-08-05 19:50:39 +00:00
|
|
|
whenM (lift $ fmap not $ cabalInstalled ver) $ throwE (NotInstalled Cabal (prettyVer ver))
|
|
|
|
|
|
|
|
cSet <- lift $ cabalSet
|
2020-05-10 22:18:53 +00:00
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
cabalFile <- lift $ parseRel ("cabal-" <> verToBS ver)
|
2020-08-05 19:50:39 +00:00
|
|
|
liftIO $ hideError doesNotExistErrorType $ deleteFile (binDir </> cabalFile)
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
when (maybe False (== ver) cSet) $ do
|
2020-08-05 19:50:39 +00:00
|
|
|
cVers <- lift $ fmap rights $ getInstalledCabals
|
2020-05-10 22:18:53 +00:00
|
|
|
case headMay . reverse . sort $ cVers of
|
|
|
|
Just latestver -> setCabal latestver
|
|
|
|
Nothing -> liftIO $ hideError doesNotExistErrorType $ deleteFile
|
2020-08-05 19:50:39 +00:00
|
|
|
(binDir </> [rel|cabal|])
|
2020-05-10 22:18:53 +00:00
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
------------------
|
|
|
|
--[ Debug info ]--
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
getDebugInfo :: (MonadReader Settings m, MonadLogger m, MonadCatch m, MonadIO m)
|
2020-01-11 20:15:05 +00:00
|
|
|
=> Excepts
|
|
|
|
'[NoCompatiblePlatform , NoCompatibleArch , DistroNotFound]
|
|
|
|
m
|
|
|
|
DebugInfo
|
|
|
|
getDebugInfo = do
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
|
|
|
let diBaseDir = baseDir
|
|
|
|
let diBinDir = binDir
|
|
|
|
diGHCDir <- lift ghcupGHCBaseDir
|
|
|
|
let diCacheDir = cacheDir
|
|
|
|
diArch <- lE getArchitecture
|
|
|
|
diPlatform <- liftE $ getPlatform
|
2020-01-11 20:15:05 +00:00
|
|
|
pure $ DebugInfo { .. }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---------------
|
|
|
|
--[ Compile ]--
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
2020-07-22 00:34:17 +00:00
|
|
|
-- | Compile a GHC from source. This behaves wrt symlinks and installation
|
2020-07-21 23:08:58 +00:00
|
|
|
-- the same as 'installGHCBin'.
|
2020-01-11 20:15:05 +00:00
|
|
|
compileGHC :: ( MonadMask m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadFail m
|
|
|
|
)
|
|
|
|
=> GHCupDownloads
|
2020-04-25 10:06:41 +00:00
|
|
|
-> GHCTargetVersion -- ^ version to install
|
2020-04-08 20:17:39 +00:00
|
|
|
-> Either Version (Path Abs) -- ^ version to bootstrap with
|
|
|
|
-> Maybe Int -- ^ jobs
|
|
|
|
-> Maybe (Path Abs) -- ^ build config
|
2020-04-25 10:06:41 +00:00
|
|
|
-> Maybe (Path Abs) -- ^ patch directory
|
|
|
|
-> [Text] -- ^ additional args to ./configure
|
2020-07-13 16:27:21 +00:00
|
|
|
-> PlatformRequest
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Excepts
|
|
|
|
'[ AlreadyInstalled
|
|
|
|
, BuildFailed
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, GHCupSetError
|
|
|
|
, NoDownload
|
2020-04-10 20:44:43 +00:00
|
|
|
, NotFoundInPATH
|
2020-04-08 20:57:57 +00:00
|
|
|
, PatchFailed
|
2020-01-11 20:15:05 +00:00
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-12 20:29:50 +00:00
|
|
|
#if !defined(TAR)
|
2020-07-04 21:33:48 +00:00
|
|
|
, ArchiveResult
|
2020-07-12 20:29:50 +00:00
|
|
|
#endif
|
2020-01-11 20:15:05 +00:00
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
2020-09-12 14:41:17 +00:00
|
|
|
compileGHC dls tver bstrap jobs mbuildConfig patchdir aargs pfreq@(PlatformRequest {..})
|
|
|
|
= do
|
|
|
|
lift $ $(logDebug) [i|Requested to compile: #{tver} with #{bstrap}|]
|
|
|
|
whenM (lift $ ghcInstalled tver)
|
|
|
|
(throwE $ AlreadyInstalled GHC (tver ^. tvVersion))
|
|
|
|
|
|
|
|
-- download source tarball
|
|
|
|
dlInfo <-
|
|
|
|
preview (ix GHC % ix (tver ^. tvVersion) % viSourceDL % _Just) dls
|
|
|
|
?? NoDownload
|
|
|
|
dl <- liftE $ downloadCached dlInfo Nothing
|
|
|
|
|
|
|
|
-- unpack
|
|
|
|
tmpUnpack <- lift mkGhcupTmpDir
|
|
|
|
liftE $ unpackToDir tmpUnpack dl
|
|
|
|
void $ liftIO $ darwinNotarization _rPlatform tmpUnpack
|
|
|
|
|
|
|
|
bghc <- case bstrap of
|
|
|
|
Right g -> pure $ Right g
|
|
|
|
Left bver -> Left <$> parseRel ("ghc-" <> verToBS bver)
|
|
|
|
workdir <- maybe (pure tmpUnpack)
|
|
|
|
(liftE . intoSubdir tmpUnpack)
|
|
|
|
(view dlSubdir dlInfo)
|
|
|
|
ghcdir <- lift $ ghcupGHCDir tver
|
|
|
|
|
|
|
|
(bindist, bmk) <- liftE $ runBuildAction
|
|
|
|
tmpUnpack
|
|
|
|
(Just ghcdir)
|
|
|
|
(do
|
|
|
|
b <- compileBindist bghc ghcdir workdir
|
|
|
|
bmk <- liftIO $ readFileStrict (build_mk workdir)
|
|
|
|
pure (b, bmk)
|
|
|
|
)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
liftE $ installPackedGHC bindist
|
|
|
|
(view dlSubdir dlInfo)
|
|
|
|
ghcdir
|
|
|
|
(tver ^. tvVersion)
|
|
|
|
pfreq
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
liftIO $ writeFile (ghcdir </> ghcUpSrcBuiltFile) (Just newFilePerms) bmk
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
reThrowAll GHCupSetError $ postGHCInstall tver
|
|
|
|
pure ()
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
where
|
2020-04-25 10:06:41 +00:00
|
|
|
defaultConf = case _tvTarget tver of
|
2020-09-12 14:41:17 +00:00
|
|
|
Nothing -> [s|
|
2020-04-25 10:06:41 +00:00
|
|
|
V=0
|
|
|
|
BUILD_MAN = NO
|
|
|
|
BUILD_SPHINX_HTML = NO
|
|
|
|
BUILD_SPHINX_PDF = NO
|
|
|
|
HADDOCK_DOCS = YES|]
|
2020-09-12 14:41:17 +00:00
|
|
|
Just _ -> [s|
|
2020-01-11 20:15:05 +00:00
|
|
|
V=0
|
|
|
|
BUILD_MAN = NO
|
|
|
|
BUILD_SPHINX_HTML = NO
|
|
|
|
BUILD_SPHINX_PDF = NO
|
2020-04-25 10:06:41 +00:00
|
|
|
HADDOCK_DOCS = NO
|
|
|
|
Stage1Only = YES|]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
compileBindist :: ( MonadReader Settings m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadFail m
|
|
|
|
)
|
|
|
|
=> Either (Path Rel) (Path Abs)
|
|
|
|
-> Path Abs
|
|
|
|
-> Path Abs
|
|
|
|
-> Excepts
|
|
|
|
'[FileDoesNotExistError, InvalidBuildConfig, PatchFailed, ProcessError, NotFoundInPATH, CopyError]
|
|
|
|
m
|
|
|
|
(Path Abs) -- ^ output path of bindist
|
|
|
|
compileBindist bghc ghcdir workdir = do
|
2020-01-11 20:15:05 +00:00
|
|
|
lift $ $(logInfo) [i|configuring build|]
|
2020-04-25 10:06:41 +00:00
|
|
|
liftE $ checkBuildConfig
|
2020-03-18 16:31:17 +00:00
|
|
|
|
2020-09-12 14:41:17 +00:00
|
|
|
Settings { dirs = Dirs {..} } <- lift ask
|
|
|
|
|
2020-04-08 20:57:57 +00:00
|
|
|
forM_ patchdir $ \dir -> liftE $ applyPatches dir workdir
|
|
|
|
|
2020-04-25 10:06:41 +00:00
|
|
|
cEnv <- liftIO $ getEnvironment
|
2020-03-18 16:31:17 +00:00
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
if
|
2020-04-25 10:06:41 +00:00
|
|
|
| (_tvVersion tver) >= [vver|8.8.0|] -> do
|
2020-04-08 20:17:39 +00:00
|
|
|
bghcPath <- case bghc of
|
|
|
|
Right ghc' -> pure ghc'
|
|
|
|
Left bver -> do
|
|
|
|
spaths <- catMaybes . fmap parseAbs <$> liftIO getSearchPath
|
2020-04-10 20:44:43 +00:00
|
|
|
(liftIO $ searchPath spaths bver) !? NotFoundInPATH bver
|
2020-07-13 09:52:34 +00:00
|
|
|
lEM $ execLogged
|
2020-03-21 21:19:37 +00:00
|
|
|
"./configure"
|
2020-03-18 16:31:17 +00:00
|
|
|
False
|
2020-04-25 10:06:41 +00:00
|
|
|
( ["--prefix=" <> toFilePath ghcdir]
|
|
|
|
++ (maybe mempty
|
|
|
|
(\x -> ["--target=" <> E.encodeUtf8 x])
|
|
|
|
(_tvTarget tver)
|
|
|
|
)
|
|
|
|
++ fmap E.encodeUtf8 aargs
|
|
|
|
)
|
2020-03-24 15:49:18 +00:00
|
|
|
[rel|ghc-conf|]
|
2020-03-18 16:31:17 +00:00
|
|
|
(Just workdir)
|
2020-04-25 10:06:41 +00:00
|
|
|
(Just (("GHC", toFilePath bghcPath) : cEnv))
|
2020-01-11 20:15:05 +00:00
|
|
|
| otherwise -> do
|
2020-07-13 09:52:34 +00:00
|
|
|
lEM $ execLogged
|
2020-03-21 21:19:37 +00:00
|
|
|
"./configure"
|
2020-01-11 20:15:05 +00:00
|
|
|
False
|
2020-04-25 10:06:41 +00:00
|
|
|
( [ "--prefix=" <> toFilePath ghcdir
|
|
|
|
, "--with-ghc=" <> either toFilePath toFilePath bghc
|
|
|
|
]
|
|
|
|
++ (maybe mempty
|
|
|
|
(\x -> ["--target=" <> E.encodeUtf8 x])
|
|
|
|
(_tvTarget tver)
|
|
|
|
)
|
|
|
|
++ fmap E.encodeUtf8 aargs
|
|
|
|
)
|
2020-03-24 15:49:18 +00:00
|
|
|
[rel|ghc-conf|]
|
2020-01-11 20:15:05 +00:00
|
|
|
(Just workdir)
|
2020-04-25 10:06:41 +00:00
|
|
|
(Just cEnv)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
case mbuildConfig of
|
|
|
|
Just bc -> liftIOException
|
|
|
|
doesNotExistErrorType
|
|
|
|
(FileDoesNotExistError $ toFilePath bc)
|
|
|
|
(liftIO $ copyFile bc (build_mk workdir) Overwrite)
|
|
|
|
Nothing ->
|
|
|
|
liftIO $ writeFile (build_mk workdir) (Just newFilePerms) defaultConf
|
|
|
|
|
2020-04-08 20:17:39 +00:00
|
|
|
lift $ $(logInfo) [i|Building (this may take a while)...|]
|
2020-09-12 14:41:17 +00:00
|
|
|
lEM $ make (maybe [] (\j -> ["-j" <> fS (show j)]) jobs) (Just workdir)
|
|
|
|
|
|
|
|
lift $ $(logInfo) [i|Creating bindist...|]
|
|
|
|
lEM $ make ["binary-dist"] (Just workdir)
|
|
|
|
[tar] <- liftIO $ findFiles
|
|
|
|
workdir
|
|
|
|
(makeRegexOpts compExtended
|
|
|
|
execBlank
|
|
|
|
([s|^ghc-.*\.tar\..*$|] :: ByteString)
|
|
|
|
)
|
|
|
|
c <- liftIO $ readFile (workdir </> tar)
|
|
|
|
cDigest <-
|
|
|
|
fmap (T.take 8)
|
|
|
|
. lift
|
|
|
|
. throwEither
|
|
|
|
. E.decodeUtf8'
|
|
|
|
. B16.encode
|
|
|
|
. SHA256.hashlazy
|
|
|
|
$ c
|
|
|
|
tarName <-
|
|
|
|
parseRel
|
|
|
|
[i|ghc-#{prettyTVer tver}-#{prettyPfReq pfreq}-#{cDigest}.tar#{takeExtension (toFilePath tar)}|]
|
|
|
|
let tarPath = cacheDir </> tarName
|
|
|
|
handleIO (throwE . CopyError . show) $ liftIO $ copyFile (workdir </> tar)
|
|
|
|
tarPath
|
|
|
|
Strict
|
|
|
|
lift $ $(logInfo) [i|Copied bindist to #{tarPath}|]
|
|
|
|
pure tarPath
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-03-16 09:47:09 +00:00
|
|
|
build_mk workdir = workdir </> [rel|mk/build.mk|]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-04-25 10:06:41 +00:00
|
|
|
checkBuildConfig :: (MonadCatch m, MonadIO m)
|
|
|
|
=> Excepts
|
2020-09-12 14:41:17 +00:00
|
|
|
'[FileDoesNotExistError, InvalidBuildConfig]
|
2020-04-25 10:06:41 +00:00
|
|
|
m
|
|
|
|
()
|
|
|
|
checkBuildConfig = do
|
|
|
|
c <- case mbuildConfig of
|
|
|
|
Just bc -> do
|
2020-09-12 14:41:17 +00:00
|
|
|
BL.toStrict <$> liftIOException
|
|
|
|
doesNotExistErrorType
|
|
|
|
(FileDoesNotExistError $ toFilePath bc)
|
|
|
|
(liftIO $ readFile bc)
|
2020-04-25 10:06:41 +00:00
|
|
|
Nothing -> pure defaultConf
|
|
|
|
let lines' = fmap T.strip . T.lines $ decUTF8Safe c
|
|
|
|
|
|
|
|
-- for cross, we need Stage1Only
|
|
|
|
case _tvTarget tver of
|
|
|
|
Just _ -> when (not $ elem "Stage1Only = YES" lines') $ throwE
|
|
|
|
(InvalidBuildConfig
|
|
|
|
[s|Cross compiling needs to be a Stage1 build, add "Stage1Only = YES" to your config!|]
|
|
|
|
)
|
|
|
|
Nothing -> pure ()
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-22 00:34:17 +00:00
|
|
|
-- | Compile a cabal from source. This behaves wrt symlinks and installation
|
2020-07-21 23:08:58 +00:00
|
|
|
-- the same as 'installCabalBin'.
|
2020-01-11 20:15:05 +00:00
|
|
|
compileCabal :: ( MonadReader Settings m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadMask m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadIO m
|
2020-05-10 22:18:53 +00:00
|
|
|
, MonadFail m
|
2020-01-11 20:15:05 +00:00
|
|
|
)
|
|
|
|
=> GHCupDownloads
|
2020-05-10 22:18:53 +00:00
|
|
|
-> Version -- ^ version to install
|
2020-04-08 20:17:39 +00:00
|
|
|
-> Either Version (Path Abs) -- ^ version to bootstrap with
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Maybe Int
|
2020-04-08 20:57:57 +00:00
|
|
|
-> Maybe (Path Abs)
|
2020-07-13 16:27:21 +00:00
|
|
|
-> PlatformRequest
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Excepts
|
2020-05-10 22:18:53 +00:00
|
|
|
'[ AlreadyInstalled
|
|
|
|
, BuildFailed
|
|
|
|
, CopyError
|
2020-01-11 20:15:05 +00:00
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
2020-05-10 22:18:53 +00:00
|
|
|
, NotInstalled
|
2020-04-08 20:57:57 +00:00
|
|
|
, PatchFailed
|
2020-01-11 20:15:05 +00:00
|
|
|
, UnknownArchive
|
2020-08-06 11:28:20 +00:00
|
|
|
, TarDirDoesNotExist
|
2020-07-12 20:29:50 +00:00
|
|
|
#if !defined(TAR)
|
2020-07-04 21:33:48 +00:00
|
|
|
, ArchiveResult
|
2020-07-12 20:29:50 +00:00
|
|
|
#endif
|
2020-01-11 20:15:05 +00:00
|
|
|
]
|
|
|
|
m
|
|
|
|
()
|
2020-07-13 16:27:21 +00:00
|
|
|
compileCabal dls tver bghc jobs patchdir PlatformRequest{..} = do
|
2020-04-08 20:17:39 +00:00
|
|
|
lift $ $(logDebug) [i|Requested to compile: #{tver} with ghc-#{bghc}|]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
2020-05-10 22:18:53 +00:00
|
|
|
|
|
|
|
whenM
|
2020-08-05 19:50:39 +00:00
|
|
|
(lift (cabalInstalled tver) >>= \a -> liftIO $
|
2020-05-10 22:18:53 +00:00
|
|
|
handleIO (\_ -> pure False)
|
|
|
|
$ fmap (\x -> a && isSymbolicLink x)
|
|
|
|
-- ignore when the installation is a legacy cabal (binary, not symlink)
|
2020-08-05 19:50:39 +00:00
|
|
|
$ getSymbolicLinkStatus (toFilePath (binDir </> [rel|cabal|]))
|
2020-05-10 22:18:53 +00:00
|
|
|
)
|
|
|
|
$ (throwE $ AlreadyInstalled Cabal tver)
|
|
|
|
|
2020-01-11 20:15:05 +00:00
|
|
|
-- download source tarball
|
|
|
|
dlInfo <- preview (ix Cabal % ix tver % viSourceDL % _Just) dls ?? NoDownload
|
|
|
|
dl <- liftE $ downloadCached dlInfo Nothing
|
|
|
|
|
|
|
|
-- unpack
|
|
|
|
tmpUnpack <- lift mkGhcupTmpDir
|
|
|
|
liftE $ unpackToDir tmpUnpack dl
|
2020-04-10 17:27:17 +00:00
|
|
|
void $ liftIO $ darwinNotarization _rPlatform tmpUnpack
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-08-06 11:28:20 +00:00
|
|
|
workdir <- maybe (pure tmpUnpack) (liftE . intoSubdir tmpUnpack) (view dlSubdir dlInfo)
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
cbin <- liftE $ runBuildAction tmpUnpack Nothing (compile workdir)
|
2020-04-22 16:12:40 +00:00
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
destFileName <- lift $ parseRel ("cabal-" <> verToBS tver)
|
|
|
|
handleIO (throwE . CopyError . show) $ liftIO $ copyFile
|
|
|
|
cbin
|
2020-08-05 19:50:39 +00:00
|
|
|
(binDir </> destFileName)
|
2020-05-10 22:18:53 +00:00
|
|
|
Overwrite
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
-- create symlink if this is the latest version
|
2020-08-05 19:50:39 +00:00
|
|
|
cVers <- lift $ fmap rights $ getInstalledCabals
|
2020-05-10 22:18:53 +00:00
|
|
|
let lInstCabal = headMay . reverse . sort $ cVers
|
|
|
|
when (maybe True (tver >=) lInstCabal) $ liftE $ setCabal tver
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
pure ()
|
|
|
|
|
|
|
|
where
|
2020-07-13 09:52:34 +00:00
|
|
|
compile :: (MonadReader Settings m, MonadThrow m, MonadLogger m, MonadIO m, MonadResource m)
|
2020-01-11 20:15:05 +00:00
|
|
|
=> Path Abs
|
2020-05-10 22:18:53 +00:00
|
|
|
-> Excepts '[ProcessError , PatchFailed] m (Path Abs)
|
2020-01-11 20:15:05 +00:00
|
|
|
compile workdir = do
|
2020-04-08 20:17:39 +00:00
|
|
|
lift $ $(logInfo) [i|Building (this may take a while)...|]
|
|
|
|
|
2020-04-08 20:57:57 +00:00
|
|
|
forM_ patchdir $ \dir -> liftE $ applyPatches dir workdir
|
|
|
|
|
2020-04-08 20:17:39 +00:00
|
|
|
ghcEnv <- case bghc of
|
|
|
|
Right path -> do
|
|
|
|
-- recover the version from /foo/ghc-6.5.4
|
|
|
|
bn <- basename path
|
|
|
|
let dn = toFilePath $ dirname path
|
|
|
|
let ver = snd . B.break (== _hyphen) . toFilePath $ bn
|
|
|
|
|
|
|
|
pure
|
|
|
|
[ ("GHC" , toFilePath path)
|
|
|
|
, ("GHC_PKG", dn <> "/" <> "ghc-pkg" <> ver)
|
2020-05-10 22:18:53 +00:00
|
|
|
, ("HADDOCK", dn <> "/" <> "haddock" <> ver)
|
2020-04-08 20:17:39 +00:00
|
|
|
]
|
|
|
|
Left bver -> do
|
|
|
|
let v' = verToBS bver
|
2020-05-10 22:18:53 +00:00
|
|
|
pure
|
|
|
|
[ ("GHC" , "ghc-" <> v')
|
|
|
|
, ("GHC_PKG", "ghc-pkg-" <> v')
|
|
|
|
, ("HADDOCK", "haddock-" <> v')
|
|
|
|
]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-05-10 22:18:53 +00:00
|
|
|
tmp <- lift withGHCupTmpDir
|
2020-08-31 11:03:12 +00:00
|
|
|
liftIO $ createDirRecursive' (tmp </> [rel|bin|])
|
2020-05-10 22:18:53 +00:00
|
|
|
newEnv <- lift $ addToCurrentEnv (("PREFIX", toFilePath tmp) : ghcEnv)
|
2020-04-08 20:17:39 +00:00
|
|
|
lift $ $(logDebug) [i|Environment: #{newEnv}|]
|
2020-01-11 20:15:05 +00:00
|
|
|
|
2020-07-13 09:52:34 +00:00
|
|
|
lEM $ execLogged "./bootstrap.sh"
|
2020-01-11 20:15:05 +00:00
|
|
|
False
|
2020-03-21 21:19:37 +00:00
|
|
|
(maybe [] (\j -> ["-j", fS (show j)]) jobs)
|
2020-03-24 15:49:18 +00:00
|
|
|
[rel|cabal-bootstrap|]
|
2020-01-11 20:15:05 +00:00
|
|
|
(Just workdir)
|
|
|
|
(Just newEnv)
|
2020-05-10 22:18:53 +00:00
|
|
|
pure $ (tmp </> [rel|bin/cabal|])
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---------------------
|
|
|
|
--[ Upgrade GHCup ]--
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Upgrade ghcup and place it in @~\/.ghcup\/bin\/ghcup@,
|
|
|
|
-- if no path is provided.
|
2020-01-11 20:15:05 +00:00
|
|
|
upgradeGHCup :: ( MonadMask m
|
|
|
|
, MonadReader Settings m
|
|
|
|
, MonadCatch m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadResource m
|
|
|
|
, MonadIO m
|
|
|
|
)
|
|
|
|
=> GHCupDownloads
|
|
|
|
-> Maybe (Path Abs) -- ^ full file destination to write ghcup into
|
2020-04-15 11:57:44 +00:00
|
|
|
-> Bool -- ^ whether to force update regardless
|
|
|
|
-- of currently installed version
|
2020-07-13 16:27:21 +00:00
|
|
|
-> PlatformRequest
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Excepts
|
|
|
|
'[ CopyError
|
|
|
|
, DigestError
|
|
|
|
, DownloadFailed
|
|
|
|
, NoDownload
|
2020-04-15 11:57:44 +00:00
|
|
|
, NoUpdate
|
2020-01-11 20:15:05 +00:00
|
|
|
]
|
|
|
|
m
|
|
|
|
Version
|
2020-07-13 16:27:21 +00:00
|
|
|
upgradeGHCup dls mtarget force pfreq = do
|
2020-08-05 19:50:39 +00:00
|
|
|
Settings {dirs = Dirs {..}} <- lift ask
|
2020-01-11 20:15:05 +00:00
|
|
|
lift $ $(logInfo) [i|Upgrading GHCup...|]
|
2020-03-16 09:49:34 +00:00
|
|
|
let latestVer = fromJust $ getLatest dls GHCup
|
2020-04-15 13:37:29 +00:00
|
|
|
when (not force && (latestVer <= pvpToVersion ghcUpVer)) $ throwE NoUpdate
|
2020-04-12 16:54:03 +00:00
|
|
|
dli <- lE $ getDownloadInfo GHCup latestVer pfreq dls
|
|
|
|
tmp <- lift withGHCupTmpDir
|
2020-03-16 09:47:09 +00:00
|
|
|
let fn = [rel|ghcup|]
|
2020-01-11 20:15:05 +00:00
|
|
|
p <- liftE $ download dli tmp (Just fn)
|
2020-07-07 17:39:58 +00:00
|
|
|
let fullDest = fromMaybe (binDir </> fn) mtarget
|
|
|
|
liftIO $ hideError NoSuchThing $ deleteFile fullDest
|
|
|
|
handleIO (throwE . CopyError . show) $ liftIO $ copyFile p
|
|
|
|
fullDest
|
|
|
|
Overwrite
|
2020-08-14 20:18:14 +00:00
|
|
|
lift $ chmod_777 fullDest
|
2020-01-11 20:15:05 +00:00
|
|
|
pure latestVer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
--[ Other ]--
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
2020-07-21 23:08:58 +00:00
|
|
|
-- | Creates @ghc-x.y.z@ and @ghc-x.y@ symlinks. This is used for
|
2020-01-11 20:15:05 +00:00
|
|
|
-- both installing from source and bindist.
|
2020-08-06 11:28:20 +00:00
|
|
|
postGHCInstall :: ( MonadReader Settings m
|
|
|
|
, MonadLogger m
|
|
|
|
, MonadThrow m
|
|
|
|
, MonadFail m
|
|
|
|
, MonadIO m
|
|
|
|
, MonadCatch m
|
|
|
|
)
|
2020-04-25 10:06:41 +00:00
|
|
|
=> GHCTargetVersion
|
2020-01-11 20:15:05 +00:00
|
|
|
-> Excepts '[NotInstalled] m ()
|
2020-08-06 11:28:20 +00:00
|
|
|
postGHCInstall ver@GHCTargetVersion {..} = do
|
2020-04-15 15:06:48 +00:00
|
|
|
void $ liftE $ setGHC ver SetGHC_XYZ
|
2020-01-11 20:15:05 +00:00
|
|
|
|
|
|
|
-- Create ghc-x.y symlinks. This may not be the current
|
|
|
|
-- version, create it regardless.
|
2020-08-06 11:28:20 +00:00
|
|
|
v' <-
|
|
|
|
handle (\(e :: ParseError) -> lift $ $(logWarn) [i|#{e}|] >> pure Nothing)
|
|
|
|
$ fmap Just
|
|
|
|
$ getMajorMinorV _tvVersion
|
|
|
|
forM_ v' $ \(mj, mi) -> lift (getGHCForMajor mj mi _tvTarget)
|
|
|
|
>>= mapM_ (\v -> liftE $ setGHC v SetGHC_XY)
|
|
|
|
|