@@ -25,7 +25,6 @@ import qualified Data.ByteString.Lazy as BL
2525import qualified Data.List as L
2626import qualified Data.Text as T
2727import qualified Data.Text.Encoding as T
28- import GHC.Utils.GhcPkg.Main.Compat ( ghcPkgUnregisterForce )
2928import Path ( (</>) , parent )
3029import Path.Extra ( toFilePathNoTrailingSep )
3130import Path.IO
@@ -34,11 +33,7 @@ import RIO.Process ( HasProcessContext, proc, readProcess_ )
3433import Stack.Constants ( relFilePackageCache )
3534import Stack.Prelude
3635import Stack.Types.Compiler ( WhichCompiler (.. ) )
37- import Stack.Types.CompilerPaths
38- ( CompilerPaths (.. ), GhcPkgExe (.. ), HasCompiler
39- , compilerPathsL
40- )
41- import Stack.Types.GhcPkgExe ( GhcPkgPrettyException (.. ) )
36+ import Stack.Types.CompilerPaths ( GhcPkgExe (.. ) )
4237import Stack.Types.GhcPkgId ( GhcPkgId , ghcPkgIdString )
4338import System.FilePath ( searchPathSeparator )
4439
@@ -154,50 +149,38 @@ findGhcPkgField pkgexe pkgDbs name field =
154149-- using GHC package id where available (from GHC 7.9)
155150--
156151-- The version of the ghc-pkg executable supplied with GHCs published before
157- -- 28 August 2023 does not efficiently bulk unregister. Until an \'efficient\'
158- -- ghc-pkg is available, this function no longer uses:
159- --
160- -- > eres <- ghcPkg pkgexe [pkgDb] args
161- -- > where
162- -- > args = "unregister" : "--user" : "--force" :
163- -- > map packageIdentifierString idents ++
164- -- > if null gids then [] else "--ipid" : map ghcPkgIdString gids
165- --
166- -- but uses:
167- --
168- -- > globalDb <- view $ compilerPathsL.to cpGlobalDB
169- -- > eres <- tryAny $ liftIO $
170- -- > ghcPkgUnregisterUserForce globalDb pkgDb hasIpid pkgarg_strs
152+ -- 28 August 2023 does not efficiently bulk unregister. This function delegates
153+ -- the bulk unregister directly to the ghc-pkg executable, which is efficient
154+ -- with the versions of GHC that Stack now supports.
171155--
172156unregisterGhcPkgIds ::
173- (HasCompiler env , HasProcessContext env , HasTerm env )
157+ (HasProcessContext env , HasTerm env )
174158 => Bool
175159 -- ^ Report pretty exceptions as warnings?
176160 -> GhcPkgExe
177161 -> Path Abs Dir -- ^ package database
178162 -> NonEmpty (Either PackageIdentifier GhcPkgId )
179163 -> RIO env ()
180164unregisterGhcPkgIds isWarn pkgexe pkgDb epgids = do
181- globalDb <- view $ compilerPathsL . to (. globalDB)
182- try (ghcPkgUnregisterForce globalDb pkgDb hasIpid pkgarg_strs) >>= \ case
183- Left (PrettyException e) -> when isWarn $
165+ -- The ghcPkg function supplies initial arguments
166+ -- --no-user-package-db --package-db=<db1> ... --package-db=<dbn>. The ghc-pkg
167+ -- executable bulk unregisters in a single invocation and recaches the package
168+ -- database itself, so no separate 'ghc-pkg recache' is required.
169+ ghcPkg pkgexe [pkgDb] args >>= \ case
170+ Left e -> when isWarn $
184171 prettyWarn $
185172 " [S-8729]"
186173 <> line
187174 <> flow " While unregistering packages, Stack encountered the following \
188175 \error:"
189176 <> blankLine
190- <> pretty e
191- Right _ -> pure ()
192- -- ghcPkgUnregisterForce does not perform an effective 'ghc-pkg recache', as
193- -- that depends on a specific version of the Cabal package.
194- ghcPkg pkgexe [pkgDb] [" recache" ] >>= \ case
195- Left err -> prettyThrowM $ CannotRecacheAfterUnregister pkgDb err
177+ <> string (displayException e)
196178 Right _ -> pure ()
197179 where
198180 (idents, gids) = partitionEithers $ toList epgids
199- hasIpid = not (null gids)
200- pkgarg_strs = map packageIdentifierString idents <> map ghcPkgIdString gids
181+ args = " unregister" : " --force" :
182+ map packageIdentifierString idents <>
183+ if null gids then [] else " --ipid" : map ghcPkgIdString gids
201184
202185-- | Get the value for GHC_PACKAGE_PATH
203186mkGhcPackagePath :: Bool -> Path Abs Dir -> Path Abs Dir -> [Path Abs Dir ] -> Path Abs Dir -> Text
0 commit comments