summaryrefslogtreecommitdiff
path: root/compiler/main/SysTools/BaseDir.hs
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2019-05-30 21:08:44 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-07 10:23:23 -0400
commit387050d0e26a9e6466b31c9d8e4e4f6273c64c9e (patch)
tree60fc360272273b1d02a4608771ade6bf0647fe3e /compiler/main/SysTools/BaseDir.hs
parentd1dc0ed75be0dafb0be3b4ff5e839612702eab47 (diff)
downloadhaskell-387050d0e26a9e6466b31c9d8e4e4f6273c64c9e.tar.gz
Factor out 'getLibDir' / 'getBaseDir' into a new GHC.BaseDir ghc-boot module
ghc-pkg and ghc already both needed this. I figure it is better to deduplicate, especially seeing that changes to one (FreeBSD CPP) didn't make it to the other. Additionally in !1090 I make ghc-pkg look up the settings file, which makes it use the top dir a bit more widely. If that lands, any difference in the way they find the top dir would be more noticable. That change also means sharing more code between ghc and ghc-package (namely the settings file parsing code), so I'd think it better to get off the slipperly slope of duplicating code now.
Diffstat (limited to 'compiler/main/SysTools/BaseDir.hs')
-rw-r--r--compiler/main/SysTools/BaseDir.hs43
1 files changed, 3 insertions, 40 deletions
diff --git a/compiler/main/SysTools/BaseDir.hs b/compiler/main/SysTools/BaseDir.hs
index d01d5214b4..1293d1898a 100644
--- a/compiler/main/SysTools/BaseDir.hs
+++ b/compiler/main/SysTools/BaseDir.hs
@@ -20,20 +20,17 @@ module SysTools.BaseDir
import GhcPrelude
+-- See note [Base Dir] for why some of this logic is shared with ghc-pkg.
+import GHC.BaseDir
+
import Panic
import System.Environment (lookupEnv)
import System.FilePath
import Data.List
--- POSIX
-#if defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS)
-import System.Environment (getExecutablePath)
-#endif
-
-- Windows
#if defined(mingw32_HOST_OS)
-import System.Environment (getExecutablePath)
import System.Directory (doesDirectoryExist)
#endif
@@ -125,40 +122,6 @@ findTopDir Nothing
InstallationError "missing -B<dir> option"
Just dir -> return dir
-getBaseDir :: IO (Maybe String)
-
-#if defined(mingw32_HOST_OS)
-
--- locate the "base dir" when given the path
--- to the real ghc executable (as opposed to symlink)
--- that is running this function.
-rootDir :: FilePath -> FilePath
-rootDir = takeDirectory . takeDirectory . normalise
-
-getBaseDir = Just . (\p -> p </> "lib") . rootDir <$> getExecutablePath
-#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS)
--- on unix, this is a bit more confusing.
--- The layout right now is something like
---
--- /bin/ghc-X.Y.Z <- wrapper script (1)
--- /bin/ghc <- symlink to wrapper script (2)
--- /lib/ghc-X.Y.Z/bin/ghc <- ghc executable (3)
--- /lib/ghc-X.Y.Z <- $topdir (4)
---
--- As such, we first need to find the absolute location to the
--- binary.
---
--- getExecutablePath will return (3). One takeDirectory will
--- give use /lib/ghc-X.Y.Z/bin, and another will give us (4).
---
--- This of course only works due to the current layout. If
--- the layout is changed, such that we have ghc-X.Y.Z/{bin,lib}
--- this would need to be changed accordingly.
---
-getBaseDir = Just . (\p -> p </> "lib") . takeDirectory . takeDirectory <$> getExecutablePath
-#else
-getBaseDir = return Nothing
-#endif
-- See Note [tooldir: How GHC finds mingw and perl on Windows]
-- Returns @Nothing@ when not on Windows.