Fix the stage3 build
[ghc-hetmet.git] / utils / ghc-pkg / Main.hs
index 7f727d7..0f0b9ec 100644 (file)
@@ -375,7 +375,16 @@ getPkgDatabases modify my_flags = do
         [] -> do mb_dir <- getExecDir "/bin/ghc-pkg.exe"
                  case mb_dir of
                         Nothing  -> die err_msg
-                        Just dir -> return (dir </> "package.conf")
+                        Just dir ->
+                            do let path1 = dir </> "package.conf"
+                                   path2 = dir </> ".." </> ".." </> ".."
+                                               </> "inplace-datadir"
+                                               </> "package.conf"
+                               exists1 <- doesFileExist path1
+                               exists2 <- doesFileExist path2
+                               if exists1 then return path1
+                                   else if exists2 then return path2
+                                   else die "Can't find package.conf"
         fs -> return (last fs)
 
   let global_conf_dir = global_conf ++ ".d"
@@ -626,7 +635,7 @@ doDump = mapM_ putStrLn . intersperse "---" . map showInstalledPackageInfo
 findPackages :: PackageDBStack -> PackageArg -> IO [InstalledPackageInfo]
 findPackages db_stack pkgarg
   = case [ p | p <- all_pkgs, pkgarg `matchesPkg` p ] of
-        []  -> die ("cannot find package " ++ pkg_msg pkgarg)
+        []  -> dieWith 2 ("cannot find package " ++ pkg_msg pkgarg)
         ps -> return ps
   where
         all_pkgs = allPackagesInStack db_stack
@@ -1017,11 +1026,14 @@ bye :: String -> IO a
 bye s = putStr s >> exitWith ExitSuccess
 
 die :: String -> IO a
-die s = do
+die = dieWith 1
+
+dieWith :: Int -> String -> IO a
+dieWith ec s = do
   hFlush stdout
   prog <- getProgramName
   hPutStrLn stderr (prog ++ ": " ++ s)
-  exitWith (ExitFailure 1)
+  exitWith (ExitFailure ec)
 
 dieOrForceAll :: Force -> String -> IO ()
 dieOrForceAll ForceAll s = ignoreError s