Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stacks installation strategy and metadata, wrt #892 #907

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

hasufell
Copy link
Member

@hasufell hasufell commented Oct 22, 2023

stack-setup

@hasufell
Copy link
Member Author

@mpilgrem

{-# LANGUAGE RecordWildCards #-}

{-|
Module : GHCup.Types.Stack
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bold copy pasta, but uses a different Version type.

@@ -36,6 +36,9 @@ import Data.Void (Void)
ghcupURL :: URI
ghcupURL = [uri|https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.8.yaml|]

stackSetupURL :: URI
stackSetupURL = [uri|https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml|]
Copy link
Member Author

@hasufell hasufell Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack setup URL

TODO:

  • allow users to overwrite setup info sections like in stack

Settings{ stackSetupSource, stackSetup } <- lift getSettings
dlinfo <- if stackSetup
then do
lift $ logInfo "Using stack's setup-info to install GHC"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entry point for stacks GHC install logic

Comment on lines 351 to 397
getStackDownloadInfo stackSetupSource keys@(_:_) GHC tv@(GHCTargetVersion Nothing v) =
case stackSetupSource of
StackSetupURL -> do
(dli :: Stack.SetupInfo) <- liftE $ reThrowAll @_ @_ @'[DownloadFailed] DownloadFailed $ getBase stackSetupURL
let siGHCs = Stack.siGHCs $ dli
ghcVersionsPerKey = (\key -> M.lookup key siGHCs) <$> (T.pack <$> keys)
ghcVersions <- (listToMaybe . catMaybes $ ghcVersionsPerKey) ?? (NoDownload tv GHC Nothing)
ghcVersion <- M.lookup v ghcVersions ?? (NoDownload tv GHC Nothing)
fromStackDownloadInfo (Stack.gdiDownloadInfo ghcVersion)
where
fromStackDownloadInfo :: MonadThrow m => Stack.DownloadInfo -> m DownloadInfo
fromStackDownloadInfo Stack.DownloadInfo{..} = do
url <- either (\e -> throwM $ ParseError (show e)) pure $ parseURI strictURIParserOptions . E.encodeUtf8 $ downloadInfoUrl
sha256 <- maybe (throwM $ DigestMissing url) (pure . E.decodeUtf8) downloadInfoSha256
pure $ DownloadInfo url (Just $ RegexDir "ghc-.*") sha256 Nothing Nothing
getStackDownloadInfo _ _ t v = throwE $ NoDownload v t Nothing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat. Here we download the stacks setup info, index via the OS/platform keys, descend into version and then turn it into GHCup internal DownloadInfo type to let the rest of the callstack do the rest.

(dli :: Stack.SetupInfo) <- liftE $ reThrowAll @_ @_ @'[DownloadFailed] DownloadFailed $ getBase stackSetupURL
let siGHCs = Stack.siGHCs $ dli
ghcVersionsPerKey = (\key -> M.lookup key siGHCs) <$> (T.pack <$> keys)
ghcVersions <- (listToMaybe . catMaybes $ ghcVersionsPerKey) ?? (NoDownload tv GHC Nothing)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we pick the first key that has a valid version. We don't attempt multiple downloads.

@hasufell hasufell force-pushed the issue-892 branch 4 times, most recently from 019a6dd to fe888be Compare October 23, 2023 10:33
@hasufell hasufell merged commit 5fd0fa8 into master Oct 24, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant