Skip to content

Commit 2a7d00c

Browse files
committed
Remove cli code
1 parent c40661b commit 2a7d00c

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

src/GHC/Utils/GhcPkg/Main/Compat.hs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ import qualified Control.Exception as Exception
3737
import Control.Monad ( ap, forM, forM_, liftM, unless, when )
3838
import qualified Data.ByteString as BS
3939
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 )
4241
import qualified Data.Traversable as F
4342
import Distribution.InstalledPackageInfo as Cabal
4443
import Distribution.Package ( UnitId, mungedId )
@@ -75,19 +74,15 @@ ghcPkgUnregisterForce ::
7574
-> IO ()
7675
ghcPkgUnregisterForce globalDb pkgDb hasIpid pkgarg_strs = do
7776
pkgargs <- forM pkgarg_strs $ readPackageArg as_arg
78-
unregisterPackages globalDb pkgargs verbosity cli
77+
unregisterPackages globalDb pkgargs verbosity pkgDb'
7978
where
8079
verbosity = Normal
81-
cli = [FlagConfig $ toFilePath pkgDb]
80+
pkgDb' = toFilePath pkgDb
8281
as_arg = if hasIpid then AsUnitId else AsDefault
8382

8483
-- -----------------------------------------------------------------------------
8584
-- Command-line syntax
8685

87-
newtype Flag
88-
= FlagConfig FilePath
89-
deriving Eq
90-
9186
data Verbosity = Silent | Normal | Verbose
9287
deriving (Show, Eq, Ord)
9388

@@ -178,7 +173,8 @@ getPkgDatabases :: Path Abs Dir
178173
-- ^ Path to the global package database.
179174
-> Verbosity
180175
-> PackageArg
181-
-> [Flag]
176+
-> FilePath
177+
-- ^ Path the package database.
182178
-> IO (PackageDBStack,
183179
-- the real package DB stack: [global,user] ++
184180
-- DBs specified on the command line with -f.
@@ -190,15 +186,13 @@ getPkgDatabases :: Path Abs Dir
190186
-- is used as the list of package DBs for
191187
-- commands that just read the DB, such as 'list'.
192188

193-
getPkgDatabases globalDb verbosity pkgarg my_flags = do
189+
getPkgDatabases globalDb verbosity pkgarg pkgDb = do
194190
-- Second we determine the location of the global package config. On Windows,
195191
-- this is found relative to the ghc-pkg.exe binary, whereas on Unix the
196192
-- location is passed to the binary using the --global-package-db flag by the
197193
-- 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]
202196
e_pkg_path <- tryIO (System.Environment.getEnv "GHC_PACKAGE_PATH")
203197
let env_stack =
204198
case e_pkg_path of
@@ -209,28 +203,13 @@ getPkgDatabases globalDb verbosity pkgarg my_flags = do
209203
| otherwise
210204
-> splitSearchPath path
211205

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
229209

230-
(db_stack, db_to_operate_on) <- getDatabases flag_db_names final_stack
210+
(db_stack, db_to_operate_on) <- getDatabases [pkgDb] final_stack
231211

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 ]
234213

235214
when (verbosity > Normal) $ do
236215
infoLn ("db stack: " ++ show (map location db_stack))
@@ -475,9 +454,9 @@ unregisterPackages ::
475454
-- ^ Path to the global package database.
476455
-> [PackageArg]
477456
-> Verbosity
478-
-> [Flag]
457+
-> String
479458
-> IO ()
480-
unregisterPackages globalDb pkgargs verbosity my_flags = do
459+
unregisterPackages globalDb pkgargs verbosity pkgDb = do
481460
pkgsByPkgDBs <- F.foldlM (getPkgsByPkgDBs []) [] pkgargs
482461
forM_ pkgsByPkgDBs unregisterPackages'
483462
where
@@ -494,7 +473,7 @@ unregisterPackages globalDb pkgargs verbosity my_flags = do
494473
-- another package database.
495474
getPkgsByPkgDBs pkgsByPkgDBs [] pkgarg = do
496475
(_, GhcPkg.DbOpenReadWrite db, _flag_dbs) <-
497-
getPkgDatabases globalDb verbosity pkgarg my_flags
476+
getPkgDatabases globalDb verbosity pkgarg pkgDb
498477
pks <- do
499478
let pkgs = packages db
500479
ps = findPackage pkgarg pkgs

0 commit comments

Comments
 (0)