summaryrefslogtreecommitdiff
path: root/utils/runghc
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2015-12-15 01:02:46 +0100
committerBen Gamari <ben@smart-cactus.org>2015-12-15 01:38:10 +0100
commit05a5ebed916dc00bc5761224047440fefe10485e (patch)
tree583a611b8f5d7bc725543a0231e707811dd7048c /utils/runghc
parent9017f16a78d66fe5aaf0ec98aeb9add1792fd838 (diff)
downloadhaskell-05a5ebed916dc00bc5761224047440fefe10485e.tar.gz
Fix runghc when $1_$2_SHELL_WRAPPER = NO
When that variable isn't on (which is always the case on Windows), `runghc` naively attempts to invoke `ghc` by finding an executable simply named `ghc`. This won't work if `ghc` doesn't exist (e.g., if we're building GHC and using `ghc-stage2` instead). A simple fix is to test for the existence of `ghc` beforehand, and if that fails, fall back on `ghc-stage2`. Fixes #11185. Test Plan: ./validate Reviewers: austin, hvr, thomie, bgamari Reviewed By: thomie, bgamari Differential Revision: https://phabricator.haskell.org/D1621 GHC Trac Issues: #11185
Diffstat (limited to 'utils/runghc')
-rw-r--r--utils/runghc/Main.hs22
-rw-r--r--utils/runghc/ghc.mk1
2 files changed, 18 insertions, 5 deletions
diff --git a/utils/runghc/Main.hs b/utils/runghc/Main.hs
index 42ddb83f25..d048125fd0 100644
--- a/utils/runghc/Main.hs
+++ b/utils/runghc/Main.hs
@@ -52,9 +52,24 @@ main = do
mbPath <- getExecPath
case mbPath of
Nothing -> dieProg ("cannot find ghc")
- Just path ->
- let ghc = takeDirectory (normalise path) </> "ghc"
- in uncurry (doIt ghc) $ getGhcArgs args'
+ Just path -> do
+ ghc <- findGhc path
+ uncurry (doIt ghc) $ getGhcArgs args'
+
+-- In some cases, runghc isn't given a path to ghc explicitly. This can occur
+-- if $1_$2_SHELL_WRAPPER = NO (which is always the case on Windows). In such
+-- a scenario, we must guess where ghc lives. Given a path where ghc might
+-- live, we check for the existence of ghc. If we can't find it, we assume that
+-- we're building ghc from source, in which case we fall back on ghc-stage2.
+-- (See Trac #1185.)
+findGhc :: FilePath -> IO FilePath
+findGhc path = do
+ let ghcDir = takeDirectory (normalise path)
+ ghc = ghcDir </> "ghc" <.> exeExtension
+ ghcExists <- doesFileExist ghc
+ return $ if ghcExists
+ then ghc
+ else ghcDir </> "ghc-stage2" <.> exeExtension
data RunGhcFlags = RunGhcFlags (Maybe FilePath) -- GHC location
| Help -- Print help text
@@ -177,4 +192,3 @@ foreign import WINDOWS_CCONV unsafe "windows.h GetModuleFileNameW"
#else
getExecPath = return Nothing
#endif
-
diff --git a/utils/runghc/ghc.mk b/utils/runghc/ghc.mk
index e981abf9a5..9169ca21bd 100644
--- a/utils/runghc/ghc.mk
+++ b/utils/runghc/ghc.mk
@@ -42,4 +42,3 @@ install_runhaskell:
$(call removeFiles,"$(DESTDIR)$(bindir)/runghc")
$(LN_S) runghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/runghc"
endif
-