13
13
-- * changeDBDir' does not perform an effective @ghc-pkg recache@,
14
14
-- * the cache is not used,
15
15
-- * consistency checks are not performed,
16
+ -- * use Stack program name,
16
17
-- * redundant code deleted,
17
18
-- * Hlint applied, and
18
19
-- * explicit import lists.
@@ -34,7 +35,7 @@ module GHC.Utils.GhcPkg.Main.Compat
34
35
-----------------------------------------------------------------------------
35
36
36
37
import qualified Control.Exception as Exception
37
- import Control.Monad ( ap , forM , forM_ , liftM , unless , when )
38
+ import Control.Monad ( forM , forM_ , unless , when )
38
39
import qualified Data.ByteString as BS
39
40
import qualified Data.Foldable as F
40
41
import Data.List ( foldl' , isPrefixOf , isSuffixOf )
@@ -51,12 +52,13 @@ import GHC.IO.Exception (IOErrorType(InappropriateType))
51
52
import qualified GHC.Unit.Database as GhcPkg
52
53
import Path ( Abs , Dir , Path , toFilePath )
53
54
import Prelude
55
+ import Stack.Constants ( stackProgName )
54
56
import System.Directory
55
57
( createDirectoryIfMissing , doesDirectoryExist
56
58
, getDirectoryContents , removeFile
57
59
)
58
60
import System.Exit ( exitWith , ExitCode (.. ) )
59
- import System.Environment ( getProgName , getEnv )
61
+ import System.Environment ( getEnv )
60
62
import System.FilePath as FilePath
61
63
import System.IO ( hFlush , hPutStrLn , stderr , stdout )
62
64
import System.IO.Error
@@ -389,7 +391,7 @@ adjustOldDatabasePath :: FilePath -> FilePath
389
391
adjustOldDatabasePath = (<.> " d" )
390
392
391
393
parsePackageInfo :: BS. ByteString
392
- -> IO (InstalledPackageInfo , [ValidateWarning ])
394
+ -> IO (InstalledPackageInfo , [String ])
393
395
parsePackageInfo str =
394
396
case parseInstalledPackageInfo str of
395
397
Right (warnings, ok) -> pure (mungePackageInfo ok, ws)
@@ -528,42 +530,13 @@ matchesPkg :: PackageArg -> InstalledPackageInfo -> Bool
528
530
(Substring _ m) `matchesPkg` pkg = m (display (mungedId pkg))
529
531
530
532
-----------------------------------------------------------------------------
531
- -- Sanity-check a new package config, and automatically build GHCi libs
532
- -- if requested.
533
-
534
- type ValidateError = String
535
- type ValidateWarning = String
536
-
537
- newtype Validate a = V { runValidate :: IO (a , [ValidateError ],[ValidateWarning ]) }
538
-
539
- instance Functor Validate where
540
- fmap = liftM
541
-
542
- instance Applicative Validate where
543
- pure a = V $ pure (a, [] , [] )
544
- (<*>) = ap
545
-
546
- instance Monad Validate where
547
- m >>= k = V $ do
548
- (a, es, ws) <- runValidate m
549
- (b, es', ws') <- runValidate (k a)
550
- return (b,es++ es',ws++ ws')
551
-
552
- -----------------------------------------------------------------------------
553
-
554
- getProgramName :: IO String
555
- getProgramName = fmap (`withoutSuffix` " .bin" ) getProgName
556
- where str `withoutSuffix` suff
557
- | suff `isSuffixOf` str = take (length str - length suff) str
558
- | otherwise = str
559
533
560
534
die :: String -> IO a
561
535
die = dieWith 1
562
536
563
537
dieWith :: Int -> String -> IO a
564
538
dieWith ec s = do
565
- prog <- getProgramName
566
- reportError (prog ++ " : " ++ s)
539
+ reportError (stackProgName ++ " : " ++ s)
567
540
exitWith (ExitFailure ec)
568
541
569
542
warn :: String -> IO ()
0 commit comments