Remove some of the old compat stuff now that we assume GHC 6.4
[ghc-hetmet.git] / utils / ghc-pkg / Main.hs
index 416ecc1..ae85fbc 100644 (file)
@@ -22,14 +22,8 @@ import Distribution.ParseUtils
 import Distribution.Package
 import Distribution.Version
 import System.FilePath
-
-#ifdef USING_COMPAT
-import Compat.Directory ( getAppUserDataDirectory, createDirectoryIfMissing )
-import Compat.RawSystem ( rawSystem )
-#else
-import System.Directory ( getAppUserDataDirectory, createDirectoryIfMissing )
 import System.Cmd       ( rawSystem )
-#endif
+import System.Directory ( getAppUserDataDirectory, createDirectoryIfMissing )
 
 import Prelude
 
@@ -48,8 +42,13 @@ import System.Exit ( exitWith, ExitCode(..) )
 import System.Environment ( getArgs, getProgName, getEnv )
 import System.IO
 import System.IO.Error (try)
-import Data.List ( isPrefixOf, isSuffixOf, isInfixOf, intersperse, sortBy, nub,
+import Data.List ( isPrefixOf, isSuffixOf, intersperse, sortBy, nub,
                    unfoldr, break )
+#if __GLASGOW_HASKELL__ > 604
+import Data.List ( isInfixOf )
+#else
+import Data.List ( tails )
+#endif
 import Control.Concurrent
 
 #ifdef mingw32_HOST_OS
@@ -619,7 +618,7 @@ pid `matches` pid'
 
 matchesPkg :: PackageArg -> InstalledPackageInfo -> Bool
 (Id pid)        `matchesPkg` pkg = pid `matches` package pkg
-(Substring _ m) `matchesPkg` pkg = m (pkgName (package pkg))
+(Substring _ m) `matchesPkg` pkg = m (showPackageId (package pkg))
 
 compPkgIdVer :: PackageIdentifier -> PackageIdentifier -> Ordering
 compPkgIdVer p1 p2 = pkgVersion p1 `compare` pkgVersion p2
@@ -720,11 +719,16 @@ missingPackageDeps :: InstalledPackageInfo
                    -> [PackageIdentifier]
 missingPackageDeps pkg pkg_map =
   [ d | d <- depends pkg, isNothing (lookup d pkg_map)] ++
-  [ d | d <- depends pkg, Just p <- return (lookup d pkg_map), isBrokenPackage p pkg_map]
+  [ d | d <- depends pkg, Just p <- return (lookup d pkg_map), 
+                          isBrokenPackage p pkg_map]
 
 isBrokenPackage :: InstalledPackageInfo -> [(PackageIdentifier, InstalledPackageInfo)] -> Bool
-isBrokenPackage pkg pkg_map = not . null $ missingPackageDeps pkg pkg_map
-
+isBrokenPackage pkg pkg_map
+   = not . null $ missingPackageDeps pkg (filter notme pkg_map)
+   where notme (p,ipi) = package pkg /= p
+        -- remove p from the database when we invoke missingPackageDeps,
+        -- because we want mutually recursive groups of package to show up
+        -- as broken. (#1750)
 
 -- -----------------------------------------------------------------------------
 -- Manipulating package.conf files
@@ -1058,3 +1062,8 @@ installSignalHandlers = do
 #else
   return () -- nothing
 #endif
+
+#if __GLASGOW_HASKELL__ <= 604
+isInfixOf               :: (Eq a) => [a] -> [a] -> Bool
+isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)
+#endif