Skip to content

Commit 74199d3

Browse files
committed
findExecutables: try '.exe' extension on Windows when executable has path
1 parent a8507ad commit 74199d3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/System/Process/Read.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,20 @@ makeAbsolute = fmap FP.normalise . absolutize
326326
--
327327
-- Throws a 'ReadProcessException' if unsuccessful.
328328
findExecutable :: (MonadIO m, MonadThrow n) => EnvOverride -> String -> m (n (Path Abs File))
329-
findExecutable _ name | any FP.isPathSeparator name = do
330-
exists <- liftIO $ doesFileExist name
331-
if exists
332-
then do
333-
path <- liftIO $ parseRelAsAbsFile name
334-
return $ return path
335-
else return $ throwM $ ExecutableNotFoundAt name
329+
findExecutable eo name0 | any FP.isPathSeparator name0 = do
330+
let names0
331+
| null (eoExeExtension eo) = [name0]
332+
-- Support `stack exec foo/bar.exe` on Windows
333+
| otherwise = [name0 ++ eoExeExtension eo, name0]
334+
testNames [] = return $ throwM $ ExecutableNotFoundAt name0
335+
testNames (name:names) = do
336+
exists <- liftIO $ doesFileExist name
337+
if exists
338+
then do
339+
path <- liftIO $ parseRelAsAbsFile name
340+
return $ return path
341+
else testNames names
342+
testNames names0
336343
findExecutable eo name = liftIO $ do
337344
m <- readIORef $ eoExeCache eo
338345
epath <- case Map.lookup name m of

0 commit comments

Comments
 (0)