Skip to content

Commit c61a12d

Browse files
committed
Remove Validate code and add stackProgName
1 parent a0ec94e commit c61a12d

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

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

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- * changeDBDir' does not perform an effective @ghc-pkg recache@,
1414
-- * the cache is not used,
1515
-- * consistency checks are not performed,
16+
-- * use Stack program name,
1617
-- * redundant code deleted,
1718
-- * Hlint applied, and
1819
-- * explicit import lists.
@@ -34,7 +35,7 @@ module GHC.Utils.GhcPkg.Main.Compat
3435
-----------------------------------------------------------------------------
3536

3637
import qualified Control.Exception as Exception
37-
import Control.Monad ( ap, forM, forM_, liftM, unless, when )
38+
import Control.Monad ( forM, forM_, unless, when )
3839
import qualified Data.ByteString as BS
3940
import qualified Data.Foldable as F
4041
import Data.List ( foldl', isPrefixOf, isSuffixOf )
@@ -51,12 +52,13 @@ import GHC.IO.Exception (IOErrorType(InappropriateType))
5152
import qualified GHC.Unit.Database as GhcPkg
5253
import Path ( Abs, Dir, Path, toFilePath )
5354
import Prelude
55+
import Stack.Constants ( stackProgName )
5456
import System.Directory
5557
( createDirectoryIfMissing, doesDirectoryExist
5658
, getDirectoryContents, removeFile
5759
)
5860
import System.Exit ( exitWith, ExitCode (..) )
59-
import System.Environment ( getProgName, getEnv )
61+
import System.Environment ( getEnv )
6062
import System.FilePath as FilePath
6163
import System.IO ( hFlush, hPutStrLn, stderr, stdout )
6264
import System.IO.Error
@@ -389,7 +391,7 @@ adjustOldDatabasePath :: FilePath -> FilePath
389391
adjustOldDatabasePath = (<.> "d")
390392

391393
parsePackageInfo :: BS.ByteString
392-
-> IO (InstalledPackageInfo, [ValidateWarning])
394+
-> IO (InstalledPackageInfo, [String])
393395
parsePackageInfo str =
394396
case parseInstalledPackageInfo str of
395397
Right (warnings, ok) -> pure (mungePackageInfo ok, ws)
@@ -528,42 +530,13 @@ matchesPkg :: PackageArg -> InstalledPackageInfo -> Bool
528530
(Substring _ m) `matchesPkg` pkg = m (display (mungedId pkg))
529531

530532
-----------------------------------------------------------------------------
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
559533

560534
die :: String -> IO a
561535
die = dieWith 1
562536

563537
dieWith :: Int -> String -> IO a
564538
dieWith ec s = do
565-
prog <- getProgramName
566-
reportError (prog ++ ": " ++ s)
539+
reportError (stackProgName ++ ": " ++ s)
567540
exitWith (ExitFailure ec)
568541

569542
warn :: String -> IO ()

0 commit comments

Comments
 (0)