summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-07-12 18:45:49 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-04 21:45:49 -0400
commiteb892b28b92351358dd7cb0ee6b0b1a1d7fcc98e (patch)
tree13f1a678fadd6373d511dcc79991758e3165a804
parentd15b44d699ad12e74106baa43b99b94d80778e7f (diff)
downloadhaskell-eb892b28b92351358dd7cb0ee6b0b1a1d7fcc98e.tar.gz
Add tryFindTopDir to look for the top dir without blowing up if it is
not found.
-rw-r--r--compiler/main/SysTools/BaseDir.hs28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/main/SysTools/BaseDir.hs b/compiler/main/SysTools/BaseDir.hs
index f67d2def6d..c4fc71b502 100644
--- a/compiler/main/SysTools/BaseDir.hs
+++ b/compiler/main/SysTools/BaseDir.hs
@@ -14,6 +14,7 @@
module SysTools.BaseDir
( expandTopDir, expandToolDir
, findTopDir, findToolDir
+ , tryFindTopDir
) where
#include "HsVersions.h"
@@ -88,23 +89,28 @@ expandToolDir _ s = s
-- | Returns a Unix-format path pointing to TopDir.
findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix).
-> IO String -- TopDir (in Unix format '/' separated)
-findTopDir (Just minusb) = return (normalise minusb)
-findTopDir Nothing
+findTopDir m_minusb = do
+ maybe_exec_dir <- tryFindTopDir m_minusb
+ case maybe_exec_dir of
+ -- "Just" on Windows, "Nothing" on unix
+ Nothing -> throwGhcExceptionIO $
+ InstallationError "missing -B<dir> option"
+ Just dir -> return dir
+
+tryFindTopDir
+ :: Maybe String -- ^ Maybe TopDir path (without the '-B' prefix).
+ -> IO (Maybe String) -- ^ TopDir (in Unix format '/' separated)
+tryFindTopDir (Just minusb) = return $ Just $ normalise minusb
+tryFindTopDir Nothing
= do -- The _GHC_TOP_DIR environment variable can be used to specify
-- the top dir when the -B argument is not specified. It is not
-- intended for use by users, it was added specifically for the
-- purpose of running GHC within GHCi.
maybe_env_top_dir <- lookupEnv "_GHC_TOP_DIR"
case maybe_env_top_dir of
- Just env_top_dir -> return env_top_dir
- Nothing -> do
- -- Get directory of executable
- maybe_exec_dir <- getBaseDir
- case maybe_exec_dir of
- -- "Just" on Windows, "Nothing" on unix
- Nothing -> throwGhcExceptionIO $
- InstallationError "missing -B<dir> option"
- Just dir -> return dir
+ Just env_top_dir -> return $ Just env_top_dir
+ -- Try directory of executable
+ Nothing -> getBaseDir
-- See Note [tooldir: How GHC finds mingw and perl on Windows]