Skip to content

Commit a0d7bc8

Browse files
committed
Fix --with-compiler failing to locate compiler on Windows
Due to idiosyncrasies (courtesy of the `SearchPath` Win32 function) in the Windows implementation of `findExecutable` we need to explicitly try both, with and without appending the Windows specific executable extensions (i.e. `.exe`). For example, before this patch, cabal new-build -w ghc-8.6.2 would fail to find the `ghc-8.6.2.exe` even though it's on `%PATH%` and invoking ghc-8.6.2 --version on the `CMD.exe` shell would have been able to locate the executable.
1 parent 28d7da0 commit a0d7bc8

File tree

1 file changed

+10
-1
lines changed
  • Cabal/Distribution/Simple/Program

1 file changed

+10
-1
lines changed

Cabal/Distribution/Simple/Program/Find.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ findProgramOnSearchPath verbosity searchpath prog = do
102102
-- On windows, getSystemSearchPath is not guaranteed 100% correct so we
103103
-- use findExecutable and then approximate the not-found-at locations.
104104
tryPathElem ProgramSearchPathDefault | buildOS == Windows = do
105-
mExe <- findExecutable prog
105+
mExe <- firstJustM [ findExecutable (prog <.> ext) | ext <- exeExtensions ]
106106
syspath <- getSystemSearchPath
107107
case mExe of
108108
Nothing ->
@@ -130,6 +130,15 @@ findProgramOnSearchPath verbosity searchpath prog = do
130130
then return (Just f, reverse fs')
131131
else go (f:fs') fs
132132

133+
-- Helper for evaluating actions until the first one returns 'Just'
134+
firstJustM :: Monad m => [m (Maybe a)] -> m (Maybe a)
135+
firstJustM [] = return Nothing
136+
firstJustM (ma:mas) = do
137+
a <- ma
138+
case a of
139+
Just _ -> return a
140+
Nothing -> firstJustM mas
141+
133142
-- | Interpret a 'ProgramSearchPath' to construct a new @$PATH@ env var.
134143
-- Note that this is close but not perfect because on Windows the search
135144
-- algorithm looks at more than just the @%PATH%@.

0 commit comments

Comments
 (0)