@@ -37,8 +37,7 @@ import qualified Control.Exception as Exception
37
37
import Control.Monad ( ap , forM , forM_ , liftM , unless , when )
38
38
import qualified Data.ByteString as BS
39
39
import qualified Data.Foldable as F
40
- import Data.List ( foldl' , isPrefixOf , isSuffixOf , nub )
41
- import Data.Maybe ( mapMaybe )
40
+ import Data.List ( foldl' , isPrefixOf , isSuffixOf )
42
41
import qualified Data.Traversable as F
43
42
import Distribution.InstalledPackageInfo as Cabal
44
43
import Distribution.Package ( UnitId , mungedId )
@@ -75,19 +74,15 @@ ghcPkgUnregisterForce ::
75
74
-> IO ()
76
75
ghcPkgUnregisterForce globalDb pkgDb hasIpid pkgarg_strs = do
77
76
pkgargs <- forM pkgarg_strs $ readPackageArg as_arg
78
- unregisterPackages globalDb pkgargs verbosity cli
77
+ unregisterPackages globalDb pkgargs verbosity pkgDb'
79
78
where
80
79
verbosity = Normal
81
- cli = [ FlagConfig $ toFilePath pkgDb]
80
+ pkgDb' = toFilePath pkgDb
82
81
as_arg = if hasIpid then AsUnitId else AsDefault
83
82
84
83
-- -----------------------------------------------------------------------------
85
84
-- Command-line syntax
86
85
87
- newtype Flag
88
- = FlagConfig FilePath
89
- deriving Eq
90
-
91
86
data Verbosity = Silent | Normal | Verbose
92
87
deriving (Show , Eq , Ord )
93
88
@@ -178,7 +173,8 @@ getPkgDatabases :: Path Abs Dir
178
173
-- ^ Path to the global package database.
179
174
-> Verbosity
180
175
-> PackageArg
181
- -> [Flag ]
176
+ -> FilePath
177
+ -- ^ Path the package database.
182
178
-> IO (PackageDBStack ,
183
179
-- the real package DB stack: [global,user] ++
184
180
-- DBs specified on the command line with -f.
@@ -190,15 +186,13 @@ getPkgDatabases :: Path Abs Dir
190
186
-- is used as the list of package DBs for
191
187
-- commands that just read the DB, such as 'list'.
192
188
193
- getPkgDatabases globalDb verbosity pkgarg my_flags = do
189
+ getPkgDatabases globalDb verbosity pkgarg pkgDb = do
194
190
-- Second we determine the location of the global package config. On Windows,
195
191
-- this is found relative to the ghc-pkg.exe binary, whereas on Unix the
196
192
-- location is passed to the binary using the --global-package-db flag by the
197
193
-- wrapper script.
198
- let global_conf = toFilePath globalDb
199
-
200
- let sys_databases = [global_conf]
201
-
194
+ let global_conf = toFilePath globalDb
195
+ sys_databases = [global_conf]
202
196
e_pkg_path <- tryIO (System.Environment. getEnv " GHC_PACKAGE_PATH" )
203
197
let env_stack =
204
198
case e_pkg_path of
@@ -209,28 +203,13 @@ getPkgDatabases globalDb verbosity pkgarg my_flags = do
209
203
| otherwise
210
204
-> splitSearchPath path
211
205
212
- let db_flags = mapMaybe is_db_flag my_flags
213
- where is_db_flag (FlagConfig f) = Just f
214
-
215
- let flag_db_names | null db_flags = env_stack
216
- | otherwise = reverse (nub db_flags)
217
-
218
- -- For a "modify" command, treat all the databases as
219
- -- a stack, where we are modifying the top one, but it
220
- -- can refer to packages in databases further down the
221
- -- stack.
222
-
223
- -- -f flags on the command line add to the database
224
- -- stack, unless any of them are present in the stack
225
- -- already.
226
- let final_stack = filter (`notElem` env_stack)
227
- [ f | FlagConfig f <- reverse my_flags ]
228
- ++ env_stack
206
+ -- -f flags on the command line add to the database stack, unless any of them
207
+ -- are present in the stack already.
208
+ let final_stack = [pkgDb | pkgDb `notElem` env_stack] <> env_stack
229
209
230
- (db_stack, db_to_operate_on) <- getDatabases flag_db_names final_stack
210
+ (db_stack, db_to_operate_on) <- getDatabases [pkgDb] final_stack
231
211
232
- let flag_db_stack = [ db | db_name <- flag_db_names,
233
- db <- db_stack, location db == db_name ]
212
+ let flag_db_stack = [ db | db <- db_stack, location db == pkgDb ]
234
213
235
214
when (verbosity > Normal ) $ do
236
215
infoLn (" db stack: " ++ show (map location db_stack))
@@ -475,9 +454,9 @@ unregisterPackages ::
475
454
-- ^ Path to the global package database.
476
455
-> [PackageArg ]
477
456
-> Verbosity
478
- -> [ Flag ]
457
+ -> String
479
458
-> IO ()
480
- unregisterPackages globalDb pkgargs verbosity my_flags = do
459
+ unregisterPackages globalDb pkgargs verbosity pkgDb = do
481
460
pkgsByPkgDBs <- F. foldlM (getPkgsByPkgDBs [] ) [] pkgargs
482
461
forM_ pkgsByPkgDBs unregisterPackages'
483
462
where
@@ -494,7 +473,7 @@ unregisterPackages globalDb pkgargs verbosity my_flags = do
494
473
-- another package database.
495
474
getPkgsByPkgDBs pkgsByPkgDBs [] pkgarg = do
496
475
(_, GhcPkg. DbOpenReadWrite db, _flag_dbs) <-
497
- getPkgDatabases globalDb verbosity pkgarg my_flags
476
+ getPkgDatabases globalDb verbosity pkgarg pkgDb
498
477
pks <- do
499
478
let pkgs = packages db
500
479
ps = findPackage pkgarg pkgs
0 commit comments