Created
January 12, 2020 14:08
-
-
Save hasufell/6c9b1558735f151dfbf2900133f165c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
-- TODO: handle SIGTERM, SIGUSR | |
module GHCup where | |
import Control.Exception.Safe | |
import Data.Foldable | |
import Data.Map.Strict (Map) | |
import Data.Strict.List.NonEmpty (NonEmpty) | |
import Data.Strict.Maybe | |
import Data.Version | |
import HPath | |
import Network.URL | |
import Optics | |
import Prelude hiding (Maybe, Just, Nothing) | |
import qualified Data.ByteString.Char8 as C -- we control the format | |
import qualified Data.Map.Strict as Map | |
import qualified Data.Strict.List.NonEmpty as NE | |
import qualified GHC.Exts as GE | |
import qualified Prelude as Prelude | |
data Tool = GHC | |
| Cabal | |
| Stack | |
deriving (Eq, Ord, Show) | |
data Architecture = A_64 | |
| A_32 | |
deriving (Eq, Ord, Show) | |
data LinuxDistro = Debian (Maybe C.ByteString) | |
| Ubuntu (Maybe C.ByteString) | |
| Mint (Maybe C.ByteString) | |
| Fedora (Maybe C.ByteString) | |
| Exherbo | |
| Gentoo | |
deriving (Eq, Ord, Show) | |
data BSD_OS = FreeBSD (Maybe C.ByteString) | |
deriving (Eq, Ord, Show) | |
data Platform = Linux (Maybe LinuxDistro) | |
| Darwin | |
| BSD BSD_OS | |
deriving (Eq, Ord, Show) | |
data PlatformSpec = PlatformSpec { | |
_unknown :: URL | |
, _platformSpec :: Map Platform URL | |
} deriving (Show) | |
makeLenses ''PlatformSpec | |
type ArchitectureSpec = Map Architecture PlatformSpec | |
type VersionSpec = Map Version ArchitectureSpec | |
data DownloadURL = DownloadURL { | |
_tool :: Tool | |
, _versionSpec :: VersionSpec | |
} deriving (Show) | |
makeLenses ''DownloadURL | |
type AvailableDownloads = NonEmpty DownloadURL | |
availableDownloads :: AvailableDownloads | |
availableDownloads = GE.fromList [ | |
DownloadURL { | |
_tool = GHC | |
, _versionSpec = Map.fromList [ | |
(mkV [8, 6, 5], Map.fromList [ | |
(A_64, PlatformSpec { | |
_unknown = mkGHCUrl "~ghc/8.6.5/ghc-8.6.5-x86_64-fedora27-linux.tar.xz" | |
, _platformSpec = Map.fromList [] | |
}) | |
]) | |
] | |
} | |
] | |
where mkV = makeVersion | |
mkGHCUrl path = URL { | |
url_type = Absolute $ Host (HTTP True) "downloads.haskell.org" Prelude.Nothing | |
, url_path = path | |
, url_params = [] | |
} | |
downloadURL :: Tool | |
-> Version | |
-> Architecture | |
-> Platform | |
-> AvailableDownloads | |
-> DownloadURL | |
downloadURL = undefined | |
download :: URL -> Path Abs -> IO (Path Abs) | |
download = undefined | |
unpack :: Path Abs -> IO (Path Abs) | |
unpack = undefined | |
install :: DownloadURL -> IO (Path Abs) | |
install = undefined | |
parseAvailableDownloads :: Maybe (Path Abs) -> IO AvailableDownloads | |
parseAvailableDownloads = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment