Use ghcup's internal dir for 'ghcup run'
This commit is contained in:
parent
b8aeb1f935
commit
b6ff5bc764
@ -5,6 +5,7 @@
|
|||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
module GHCup.OptParse.Run where
|
module GHCup.OptParse.Run where
|
||||||
|
|
||||||
|
|
||||||
@ -233,12 +234,16 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
|
|||||||
r <- if not runQuick
|
r <- if not runQuick
|
||||||
then runRUN runAppState $ do
|
then runRUN runAppState $ do
|
||||||
toolchain <- liftE resolveToolchainFull
|
toolchain <- liftE resolveToolchainFull
|
||||||
tmp <- liftIO $ createTmpDir toolchain
|
|
||||||
|
-- oh dear
|
||||||
|
r <- lift ask
|
||||||
|
tmp <- lift . lift . lift . flip runReaderT (fromAppState r) $ createTmpDir toolchain
|
||||||
|
|
||||||
liftE $ installToolChainFull toolchain tmp
|
liftE $ installToolChainFull toolchain tmp
|
||||||
pure tmp
|
pure tmp
|
||||||
else runLeanRUN leanAppstate $ do
|
else runLeanRUN leanAppstate $ do
|
||||||
toolchain <- resolveToolchain
|
toolchain <- resolveToolchain
|
||||||
tmp <- liftIO $ createTmpDir toolchain
|
tmp <- lift $ createTmpDir toolchain
|
||||||
liftE $ installToolChain toolchain tmp
|
liftE $ installToolChain toolchain tmp
|
||||||
pure tmp
|
pure tmp
|
||||||
case r of
|
case r of
|
||||||
@ -268,17 +273,6 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
|
|||||||
|
|
||||||
where
|
where
|
||||||
|
|
||||||
createTmpDir :: Toolchain -> IO FilePath
|
|
||||||
createTmpDir toolchain =
|
|
||||||
case runBinDir of
|
|
||||||
Just bindir -> do
|
|
||||||
createDirRecursive' bindir
|
|
||||||
canonicalizePath bindir
|
|
||||||
Nothing -> do
|
|
||||||
d <- predictableTmpDir toolchain
|
|
||||||
createDirRecursive' d
|
|
||||||
canonicalizePath d
|
|
||||||
|
|
||||||
-- TODO: doesn't work for cross
|
-- TODO: doesn't work for cross
|
||||||
resolveToolchainFull :: ( MonadFail m
|
resolveToolchainFull :: ( MonadFail m
|
||||||
, MonadThrow m
|
, MonadThrow m
|
||||||
@ -443,11 +437,33 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
|
|||||||
liftIO $ setEnv pathVar newPath
|
liftIO $ setEnv pathVar newPath
|
||||||
return envWithNewPath
|
return envWithNewPath
|
||||||
|
|
||||||
predictableTmpDir (Toolchain Nothing Nothing Nothing Nothing) =
|
createTmpDir :: ( MonadUnliftIO m
|
||||||
liftIO (getTemporaryDirectory >>= \tmp -> pure (tmp </> "ghcup-none"))
|
, MonadCatch m
|
||||||
|
, MonadThrow m
|
||||||
|
, MonadMask m
|
||||||
|
, MonadIO m
|
||||||
|
)
|
||||||
|
=> Toolchain
|
||||||
|
-> ReaderT LeanAppState m FilePath
|
||||||
|
createTmpDir toolchain =
|
||||||
|
case runBinDir of
|
||||||
|
Just bindir -> do
|
||||||
|
liftIO $ createDirRecursive' bindir
|
||||||
|
liftIO $ canonicalizePath bindir
|
||||||
|
Nothing -> do
|
||||||
|
d <- predictableTmpDir toolchain
|
||||||
|
liftIO $ createDirRecursive' d
|
||||||
|
liftIO $ canonicalizePath d
|
||||||
|
|
||||||
|
predictableTmpDir :: Monad m
|
||||||
|
=> Toolchain
|
||||||
|
-> ReaderT LeanAppState m FilePath
|
||||||
|
predictableTmpDir (Toolchain Nothing Nothing Nothing Nothing) = do
|
||||||
|
Dirs { tmpDir } <- getDirs
|
||||||
|
pure (fromGHCupPath tmpDir </> "ghcup-none")
|
||||||
predictableTmpDir Toolchain{..} = do
|
predictableTmpDir Toolchain{..} = do
|
||||||
tmp <- getTemporaryDirectory
|
Dirs { tmpDir } <- getDirs
|
||||||
pure $ tmp
|
pure $ fromGHCupPath tmpDir
|
||||||
</> ("ghcup-" <> intercalate "_"
|
</> ("ghcup-" <> intercalate "_"
|
||||||
( maybe [] ( (:[]) . ("ghc-" <>) . T.unpack . tVerToText) ghcVer
|
( maybe [] ( (:[]) . ("ghc-" <>) . T.unpack . tVerToText) ghcVer
|
||||||
<> maybe [] ( (:[]) . ("cabal-" <>) . T.unpack . tVerToText) cabalVer
|
<> maybe [] ( (:[]) . ("cabal-" <>) . T.unpack . tVerToText) cabalVer
|
||||||
@ -469,4 +485,4 @@ data Toolchain = Toolchain
|
|||||||
, cabalVer :: Maybe GHCTargetVersion
|
, cabalVer :: Maybe GHCTargetVersion
|
||||||
, hlsVer :: Maybe GHCTargetVersion
|
, hlsVer :: Maybe GHCTargetVersion
|
||||||
, stackVer :: Maybe GHCTargetVersion
|
, stackVer :: Maybe GHCTargetVersion
|
||||||
}
|
} deriving Show
|
||||||
|
@ -407,6 +407,9 @@ data AppState = AppState
|
|||||||
|
|
||||||
instance NFData AppState
|
instance NFData AppState
|
||||||
|
|
||||||
|
fromAppState :: AppState -> LeanAppState
|
||||||
|
fromAppState AppState {..} = LeanAppState {..}
|
||||||
|
|
||||||
data LeanAppState = LeanAppState
|
data LeanAppState = LeanAppState
|
||||||
{ settings :: Settings
|
{ settings :: Settings
|
||||||
, dirs :: Dirs
|
, dirs :: Dirs
|
||||||
|
Loading…
Reference in New Issue
Block a user