From f7d2033e2535ee3c9279cef19d00fc50ae928bb6 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 20 Dec 2022 21:28:49 +0800 Subject: [PATCH] Improve postRm message, fixes #384 --- app/ghcup/BrickMain.hs | 2 ++ app/ghcup/GHCup/OptParse/Common.hs | 11 +++++++++++ app/ghcup/GHCup/OptParse/Rm.hs | 16 ++++++++-------- ghcup.cabal | 1 + 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/ghcup/BrickMain.hs b/app/ghcup/BrickMain.hs index 4edad3a..6054d83 100644 --- a/app/ghcup/BrickMain.hs +++ b/app/ghcup/BrickMain.hs @@ -13,6 +13,7 @@ import GHCup.Errors import GHCup.Types.Optics ( getDirs ) import GHCup.Types hiding ( LeanAppState(..) ) import GHCup.Utils +import GHCup.OptParse.Common (logGHCPostRm) import GHCup.Prelude ( decUTF8Safe ) import GHCup.Prelude.File import GHCup.Prelude.Logger @@ -554,6 +555,7 @@ del' _ (_, ListResult {..}) = do ) >>= \case VRight vi -> do + logGHCPostRm (mkTVer lVer) forM_ (_viPostRemove =<< vi) $ \msg -> logInfo msg pure $ Right () diff --git a/app/ghcup/GHCup/OptParse/Common.hs b/app/ghcup/GHCup/OptParse/Common.hs index 90ef768..e035cc5 100644 --- a/app/ghcup/GHCup/OptParse/Common.hs +++ b/app/ghcup/GHCup/OptParse/Common.hs @@ -25,6 +25,7 @@ import Control.DeepSeq import Control.Concurrent import Control.Concurrent.Async import Control.Exception.Safe +import Control.Monad.Identity (Identity(..)) #if !MIN_VERSION_base(4,13,0) import Control.Monad.Fail ( MonadFail ) #endif @@ -64,6 +65,7 @@ import qualified Text.Megaparsec as MP import qualified System.FilePath.Posix as FP import GHCup.Version import Control.Exception (evaluate) +import qualified Cabal.Config as CC ------------- @@ -789,3 +791,12 @@ checkForUpdates = do pure $ catMaybes (ghcup:otherTools) where forMM a f = fmap join $ forM a f + + +logGHCPostRm :: (MonadReader env m, HasLog env, MonadIO m) => GHCTargetVersion -> m () +logGHCPostRm ghcVer = do + cabalStore <- liftIO $ handleIO (\_ -> if isWindows then pure "C:\\cabal\\store" else pure "~/.cabal/store") + (runIdentity . CC.cfgStoreDir <$> CC.readConfig) + let storeGhcDir = cabalStore ("ghc-" <> T.unpack (prettyVer $ _tvVersion ghcVer)) + logInfo $ T.pack $ "After removing GHC you might also want to clean up your cabal store at: " <> storeGhcDir + diff --git a/app/ghcup/GHCup/OptParse/Rm.hs b/app/ghcup/GHCup/OptParse/Rm.hs index a5ee316..78e513a 100644 --- a/app/ghcup/GHCup/OptParse/Rm.hs +++ b/app/ghcup/GHCup/OptParse/Rm.hs @@ -175,8 +175,8 @@ rm rmCommand runAppState runLogger = case rmCommand of ) >>= \case VRight vi -> do - forM_ (_viPostRemove =<< vi) $ \msg -> - runLogger $ logInfo msg + runLogger $ logGHCPostRm ghcVer + postRmLog vi pure ExitSuccess VLeft e -> do runLogger $ logError $ T.pack $ prettyShow e @@ -191,8 +191,7 @@ rm rmCommand runAppState runLogger = case rmCommand of ) >>= \case VRight vi -> do - forM_ (_viPostRemove =<< vi) $ \msg -> - runLogger $ logInfo msg + postRmLog vi pure ExitSuccess VLeft e -> do runLogger $ logError $ T.pack $ prettyShow e @@ -207,8 +206,7 @@ rm rmCommand runAppState runLogger = case rmCommand of ) >>= \case VRight vi -> do - forM_ (_viPostRemove =<< vi) $ \msg -> - runLogger $ logInfo msg + postRmLog vi pure ExitSuccess VLeft e -> do runLogger $ logError $ T.pack $ prettyShow e @@ -223,10 +221,12 @@ rm rmCommand runAppState runLogger = case rmCommand of ) >>= \case VRight vi -> do - forM_ (_viPostRemove =<< vi) $ \msg -> - runLogger $ logInfo msg + postRmLog vi pure ExitSuccess VLeft e -> do runLogger $ logError $ T.pack $ prettyShow e pure $ ExitFailure 15 + postRmLog vi = + forM_ (_viPostRemove =<< vi) $ \msg -> + runLogger $ logInfo msg diff --git a/ghcup.cabal b/ghcup.cabal index 1963df3..fc79db1 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -247,6 +247,7 @@ executable ghcup , base >=4.12 && <5 , bytestring >=0.10 && <0.12 , cabal-plan ^>=0.7.2 + , cabal-install-parsers >=0.4.5 , containers ^>=0.6 , deepseq ^>=1.4 , directory ^>=1.3.6.0