Skip to content

Commit

Permalink
Allow to remove all unset versions, fixes #1019
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Mar 11, 2024
1 parent 5d0a7b7 commit 5eaae99
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib-opt/GHCup/OptParse/GC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ data GCOptions = GCOptions
, gcHLSNoGHC :: Bool
, gcCache :: Bool
, gcTmp :: Bool
, gcUnset :: Bool
} deriving (Eq, Show)


Expand Down Expand Up @@ -77,6 +78,9 @@ gcP =
<*>
switch
(short 't' <> long "tmpdirs" <> help "Remove tmpdir leftovers")
<*>
switch
(short 'u' <> long "unset" <> help "Remove all tool versions that are not 'set'")



Expand Down Expand Up @@ -134,6 +138,7 @@ gc GCOptions{..} runAppState runLogger = runGC runAppState (do
liftE $ when gcHLSNoGHC rmHLSNoGHC
lift $ when gcCache rmCache
lift $ when gcTmp rmTmp
liftE $ when gcUnset rmUnsetTools
) >>= \case
VRight _ -> do
pure ExitSuccess
Expand Down
20 changes: 20 additions & 0 deletions lib/GHCup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,26 @@ rmOldGHC = do
forM_ ghcs $ \ghc -> when (ghc `elem` oldGHCs) $ rmGHCVer ghc


rmUnsetTools :: ( MonadReader env m
, HasGHCupInfo env
, HasPlatformReq env
, HasDirs env
, HasLog env
, MonadIO m
, MonadFail m
, MonadMask m
, MonadUnliftIO m
)
=> Excepts '[NotInstalled, UninstallFailed] m ()
rmUnsetTools = do
vers <- lift $ listVersions Nothing [ListInstalled True, ListSet False] False True (Nothing, Nothing)
forM_ vers $ \ListResult{..} -> case lTool of
GHC -> liftE $ rmGHCVer (GHCTargetVersion lCross lVer)
HLS -> liftE $ rmHLSVer lVer
Cabal -> liftE $ rmCabalVer lVer
Stack -> liftE $ rmStackVer lVer
GHCup -> pure ()


rmProfilingLibs :: ( MonadReader env m
, HasDirs env
Expand Down
5 changes: 4 additions & 1 deletion test/optparse-test/GCTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defaultOptions =
False
False
False
False

gcCheckList :: [(String, GCOptions)]
gcCheckList =
Expand All @@ -33,7 +34,9 @@ gcCheckList =
, ("gc --cache", defaultOptions{gcCache = True})
, ("gc -t", defaultOptions{gcTmp = True})
, ("gc --tmpdirs", defaultOptions{gcTmp = True})
, ("gc -o -p -s -h -c -t", GCOptions True True True True True True)
, ("gc -u", defaultOptions{gcUnset = True})
, ("gc --unset", defaultOptions{gcUnset = True})
, ("gc -o -p -s -h -c -t -u", GCOptions True True True True True True True)
]

gcParseWith :: [String] -> IO GCOptions
Expand Down

0 comments on commit 5eaae99

Please sign in to comment.