Skip to content

Commit b3c0bdc

Browse files
committed
Allow running stack exec foo.exe on Windows
1 parent 5ca1026 commit b3c0bdc

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
@@ -294,13 +294,20 @@ findExecutable eo name = liftIO $ do
294294
Nothing -> do
295295
let loop [] = return $ Left $ ExecutableNotFound name (eoPath eo)
296296
loop (dir:dirs) = do
297-
let fp = dir FP.</> name ++ eoExeExtension eo
298-
exists <- doesFileExist fp
299-
if exists
300-
then do
301-
fp' <- makeAbsolute fp >>= parseAbsFile
302-
return $ return fp'
303-
else loop dirs
297+
let fp0 = dir FP.</> name
298+
fps0
299+
| null (eoExeExtension eo) = [fp0]
300+
-- Support `stack exec foo.exe` on Windows
301+
| otherwise = [fp0 ++ eoExeExtension eo, fp0]
302+
testFPs [] = loop dirs
303+
testFPs (fp:fps) = do
304+
exists <- doesFileExist fp
305+
if exists
306+
then do
307+
fp' <- makeAbsolute fp >>= parseAbsFile
308+
return $ return fp'
309+
else testFPs fps
310+
testFPs fps0
304311
epath <- loop $ eoPath eo
305312
!() <- atomicModifyIORef (eoExeCache eo) $ \m' ->
306313
(Map.insert name epath m', ())

0 commit comments

Comments
 (0)