Commit eb892b28 authored by John Ericson's avatar John Ericson Committed by Marge Bot
Browse files

Add tryFindTopDir to look for the top dir without blowing up if it is

not found.
parent d15b44d6
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment