[commit: ghc] master: Fix runghc when $1_$2_SHELL_WRAPPER = NO (05a5ebe)

git at git.haskell.org git at git.haskell.org
Tue Dec 15 00:37:48 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/05a5ebed916dc00bc5761224047440fefe10485e/ghc

>---------------------------------------------------------------

commit 05a5ebed916dc00bc5761224047440fefe10485e
Author: RyanGlScott <ryan.gl.scott at gmail.com>
Date:   Tue Dec 15 01:02:46 2015 +0100

    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


>---------------------------------------------------------------

05a5ebed916dc00bc5761224047440fefe10485e
 utils/runghc/Main.hs | 22 ++++++++++++++++++----
 utils/runghc/ghc.mk  |  1 -
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/utils/runghc/Main.hs b/utils/runghc/Main.hs
index 42ddb83..d048125 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 e981abf..9169ca2 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
-



More information about the ghc-commits mailing list