Improve outdated ghc-pkg cache warning (#9606)
authorThomas Miedema <thomasmiedema@gmail.com>
Tue, 17 Feb 2015 14:39:35 +0000 (08:39 -0600)
committerAustin Seipp <austin@well-typed.com>
Tue, 17 Feb 2015 15:06:11 +0000 (09:06 -0600)
Summary: No more frustration.

Test Plan: I tested it.

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D658

GHC Trac Issues: #9606

utils/ghc-pkg/Main.hs

index b2815b8..53bc43b 100644 (file)
@@ -706,7 +706,7 @@ readParseDatabase verbosity mb_user_conf modify use_cache path
                       then do
                         warn ("WARNING: cache does not exist: " ++ cache)
                         warn ("ghc will fail to read this package db. " ++
-                              "Use 'ghc-pkg recache' to fix.")
+                              recacheAdvice)
                       else do
                         warn ("WARNING: cache cannot be read: " ++ show ex)
                         warn "ghc will fail to read this package db."
@@ -736,7 +736,7 @@ readParseDatabase verbosity mb_user_conf modify use_cache path
                           whenReportCacheErrors $ do
                               warn ("WARNING: cache is out of date: " ++ cache)
                               warn ("ghc will see an old view of this " ++
-                                    "package db. Use 'ghc-pkg recache' to fix.")
+                                    "package db. " ++ recacheAdvice)
                           ignore_cache compareTimestampToCache
             where
                  ignore_cache :: (FilePath -> IO ()) -> IO PackageDB
@@ -753,6 +753,12 @@ readParseDatabase verbosity mb_user_conf modify use_cache path
                      when (   verbosity >  Normal
                            || verbosity >= Normal && not modify)
   where
+    recacheAdvice
+      | Just (user_conf, True) <- mb_user_conf, path == user_conf
+      = "Use 'ghc-pkg recache --user' to fix."
+      | otherwise
+      = "Use 'ghc-pkg recache' to fix."
+
     mkPackageDB pkgs = do
       path_abs <- absolutePath path
       return PackageDB {