This commit is contained in:
2020-03-03 23:34:25 +01:00
parent 62b249db2d
commit 63f9bc6b0a
9 changed files with 292 additions and 141 deletions

View File

@@ -13,6 +13,86 @@ import URI.ByteString.QQ
import qualified Data.Map as M
-----------------
--[ GHC 8.4.4 ]--
-----------------
ghc_844_64_fedora :: DownloadInfo
ghc_844_64_fedora = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.4.4|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
ghc_844_64_debian9 :: DownloadInfo
ghc_844_64_debian9 = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-deb9-linux.tar.xz|]
(Just ([rel|ghc-8.4.4|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
ghc_844_64_debian8 :: DownloadInfo
ghc_844_64_debian8 = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-deb8-linux.tar.xz|]
(Just ([rel|ghc-8.4.4|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
-----------------
--[ GHC 8.6.5 ]--
-----------------
ghc_865_64_fedora :: DownloadInfo
ghc_865_64_fedora = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
ghc_865_64_debian9 :: DownloadInfo
ghc_865_64_debian9 = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-deb9-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|8de779b73c1b2f1b7ab49030015fce3d|]
ghc_865_64_debian8 :: DownloadInfo
ghc_865_64_debian8 = DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-deb8-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
---------------------
--[ Cabal-3.0.0.0 ]--
---------------------
cabal_3000_64_linux :: DownloadInfo
cabal_3000_64_linux = DownloadInfo
[uri|https://downloads.haskell.org/~cabal/cabal-install-3.0.0.0/cabal-install-3.0.0.0-x86_64-unknown-linux.tar.xz|]
Nothing
[s|32352d2259909970e6ff04faf61bbfac|]
-------------
--[ GHCup ]--
-------------
ghcup_010_64_linux :: DownloadInfo
ghcup_010_64_linux = DownloadInfo [uri|file:///home/ospa_ju/tmp/ghcup-exe|]
Nothing
[s|d8da9e09ca71648f4c1bc6a0a46efc82|]
-----------------------
--[ Tarball mapping ]--
-----------------------
binaryDownloads :: BinaryDownloads
binaryDownloads = M.fromList
[ ( GHC
@@ -21,84 +101,28 @@ binaryDownloads = M.fromList
, VersionInfo [Latest] $ M.fromList
[ ( A_64
, M.fromList
[ ( Linux UnknownLinux
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
)
]
)
, ( Linux Ubuntu
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
)
]
)
[ (Linux UnknownLinux, M.fromList [(Nothing, ghc_865_64_fedora)])
, (Linux Ubuntu , M.fromList [(Nothing, ghc_865_64_debian9)])
, ( Linux Debian
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-debian9-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
)
, ( Just $ [vers|8|]
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-debian9-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|5f871a3eaf808acb2420fdeef9318698|]
)
[ (Nothing , ghc_865_64_debian9)
, (Just $ [vers|8|], ghc_865_64_debian8)
]
)
]
)
]
),
( [vver|8.4.4|]
)
, ( [vver|8.4.4|]
, VersionInfo [] $ M.fromList
[ ( A_64
, M.fromList
[ ( Linux UnknownLinux
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.4.4|] :: Path Rel))
[s|86785f41d228168461859e40956973fb|]
)
]
)
, ( Linux Ubuntu
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-fedora27-linux.tar.xz|]
(Just ([rel|ghc-8.4.4|] :: Path Rel))
[s|f943a245c54c2f2dcb354dceeff886e1|]
)
]
)
[ (Linux UnknownLinux, M.fromList [(Nothing, ghc_844_64_fedora)])
, (Linux Ubuntu , M.fromList [(Nothing, ghc_844_64_fedora)])
, ( Linux Debian
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-debian9-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|f943a245c54c2f2dcb354dceeff886e1|]
)
, ( Just $ [vers|8|]
, DownloadInfo
[uri|https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-debian8-linux.tar.xz|]
(Just ([rel|ghc-8.6.5|] :: Path Rel))
[s|f943a245c54c2f2dcb354dceeff886e1|]
)
[ (Nothing , ghc_844_64_debian9)
, (Just $ [vers|8|], ghc_844_64_debian8)
]
)
]
@@ -114,14 +138,7 @@ binaryDownloads = M.fromList
[ ( A_64
, M.fromList
[ ( Linux UnknownLinux
, M.fromList
[ ( Nothing
, DownloadInfo
[uri|https://downloads.haskell.org/~cabal/cabal-install-3.0.0.0/cabal-install-3.0.0.0-x86_64-unknown-linux.tar.xz|]
Nothing
[s|32352d2259909970e6ff04faf61bbfac|]
)
]
, M.fromList [(Nothing, cabal_3000_64_linux)]
)
]
)
@@ -129,4 +146,16 @@ binaryDownloads = M.fromList
)
]
)
, ( GHCup
, M.fromList
[ ( [vver|0.1.0|]
, VersionInfo [Latest] $ M.fromList
[ ( A_64
, M.fromList
[(Linux UnknownLinux, M.fromList [(Nothing, ghcup_010_64_linux)])]
)
]
)
]
)
]

View File

@@ -33,6 +33,7 @@ instance Exception ValidationError
-- TODO: test that GHC is in semver
-- TODO: check there's LATEST tag for every tool
validate :: (Monad m, MonadLogger m, MonadThrow m, MonadIO m)
=> GHCupDownloads
-> m ExitCode

View File

@@ -31,6 +31,7 @@ import Haskus.Utils.Variant.Excepts
import HPath
import Options.Applicative hiding ( style )
import System.Console.Pretty
import System.Environment
import System.Exit
import System.IO
import Text.Read
@@ -63,6 +64,7 @@ data Command
| Rm RmOptions
| DInfo
| Compile CompileOptions
| Upgrade UpgradeOpts
data ToolVersion = ToolVersion Version
| ToolTag Tag
@@ -96,6 +98,11 @@ data CompileOptions = CompileOptions
, buildConfig :: Maybe (Path Abs)
}
data UpgradeOpts = UpgradeInplace
| UpgradeAt (Path Abs)
| UpgradeGHCupDir
deriving Show
opts :: Parser Options
opts =
@@ -127,7 +134,9 @@ com =
( command
"install"
( Install
<$> (info (installP <**> helper) (progDesc "Install GHC or cabal"))
<$> (info (installP <**> helper)
(progDesc "Install or update GHC/cabal")
)
)
<> command
"list"
@@ -136,6 +145,11 @@ com =
(progDesc "Show available GHCs and other tools")
)
)
<> command
"upgrade"
( Upgrade
<$> (info (upgradeOptsP <**> helper) (progDesc "Upgrade ghcup (per default in ~/.ghcup/bin/)"))
)
<> commandGroup "Main commands:"
)
<|> subparser
@@ -309,6 +323,32 @@ toSettings Options {..} =
in Settings { .. }
upgradeOptsP :: Parser UpgradeOpts
upgradeOptsP =
flag'
UpgradeInplace
(short 'i' <> long "inplace" <> help
"Upgrade ghcup in-place (wherever it's at)"
)
<|> ( UpgradeAt
<$> (option
(eitherReader
(\x ->
bimap show id . parseAbs . E.encodeUtf8 . T.pack $ x :: Either
String
(Path Abs)
)
)
(short 't' <> long "target" <> metavar "TARGET_DIR" <> help
"Absolute filepath to write ghcup into"
)
)
)
<|> (pure UpgradeGHCupDir)
-- TODO: something better than Show instance for errors
main :: IO ()
@@ -387,12 +427,28 @@ main = do
, JSONError
]
let runUpgrade =
runLogger
. flip runReaderT settings
. runResourceT
. runE
@'[ DigestError
, URLException
, DistroNotFound
, PlatformResultError
, NoCompatibleArch
, NoDownload
, FileDoesNotExistError
, JSONError
]
case optCommand of
Install (InstallGHC InstallOptions {..}) ->
void
$ (runInstTool $ do
dls <- _binaryDownloads <$> liftE getDownloads
v <- liftE $ fromVersion dls instVer GHC
v <- liftE $ fromVersion dls instVer GHC
liftE $ installTool dls (ToolRequest GHC v) Nothing
)
>>= \case
@@ -407,7 +463,7 @@ main = do
void
$ (runInstTool $ do
dls <- _binaryDownloads <$> liftE getDownloads
v <- liftE $ fromVersion dls instVer Cabal
v <- liftE $ fromVersion dls instVer Cabal
liftE $ installTool dls (ToolRequest Cabal v) Nothing
)
>>= \case
@@ -423,7 +479,7 @@ main = do
void
$ (runSetGHC $ do
dls <- _binaryDownloads <$> liftE getDownloads
v <- liftE $ fromVersion dls ghcVer GHC
v <- liftE $ fromVersion dls ghcVer GHC
liftE $ setGHC v SetGHCOnly
)
>>= \case
@@ -479,6 +535,30 @@ main = do
VLeft e ->
runLogger ($(logError) [i|#{e}|]) >> exitFailure
Upgrade (uOpts) -> do
liftIO $ putStrLn $ show uOpts
target <- case uOpts of
UpgradeInplace -> do
efp <- liftIO $ getExecutablePath
p <- parseAbs . E.encodeUtf8 . T.pack $ efp
pure $ Just p
(UpgradeAt p) -> pure $ Just p
UpgradeGHCupDir -> do
liftIO $ putStrLn "blah"
pure Nothing
void
$ (runUpgrade $ do
dls <- _binaryDownloads <$> liftE getDownloads
liftE $ upgradeGHCup dls target
)
>>= \case
VRight v' ->
runLogger $ $(logInfo)
[i|Successfully upgraded GHCup to version #{v'}|]
VLeft e ->
runLogger ($(logError) [i|#{e}|]) >> exitFailure
pure ()