Skip to content

Commit cde532e

Browse files
committed
Support most executable extensions on Windows commercialhaskell#2225
1 parent 3103ebe commit cde532e

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Other enhancements:
1212

1313
Bug fixes:
1414

15+
* Support most executable extensions on Windows
16+
[#2225](https://github.com/commercialhaskell/stack/issues/2225)
17+
1518
## 1.1.2
1619

1720
Release notes:

src/System/Process/Read.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ data EnvOverride = EnvOverride
8181
, eoStringList :: [(String, String)] -- ^ Environment variables as association list
8282
, eoPath :: [FilePath] -- ^ List of directories searched for executables (@PATH@)
8383
, eoExeCache :: IORef (Map FilePath (Either ReadProcessException (Path Abs File)))
84-
, eoExeExtension :: String -- ^ @""@ or @".exe"@, depending on the platform
84+
, eoExeExtensions :: [String] -- ^ @[""]@ on non-Windows systems, @["", ".exe", ".bat"]@ on Windows
8585
, eoPlatform :: Platform
8686
}
8787

@@ -114,7 +114,10 @@ mkEnvOverride platform tm' = do
114114
, eoStringList = map (T.unpack *** T.unpack) $ Map.toList tm
115115
, eoPath = maybe [] (FP.splitSearchPath . T.unpack) (Map.lookup "PATH" tm)
116116
, eoExeCache = ref
117-
, eoExeExtension = if isWindows then ".exe" else ""
117+
, eoExeExtensions =
118+
if isWindows
119+
then ["", ".exe", ".bat", ".com"]
120+
else [""]
118121
, eoPlatform = platform
119122
}
120123
where
@@ -336,10 +339,7 @@ findExecutable :: (MonadIO m, MonadThrow n)
336339
-> String -- ^ Name of executable
337340
-> m (n (Path Abs File)) -- ^ Full path to that executable on success
338341
findExecutable eo name0 | any FP.isPathSeparator name0 = do
339-
let names0
340-
| null (eoExeExtension eo) = [name0]
341-
-- Support `stack exec foo/bar.exe` on Windows
342-
| otherwise = [name0 ++ eoExeExtension eo, name0]
342+
let names0 = map (name0 ++) (eoExeExtensions eo)
343343
testNames [] = return $ throwM $ ExecutableNotFoundAt name0
344344
testNames (name:names) = do
345345
exists <- liftIO $ D.doesFileExist name
@@ -357,10 +357,7 @@ findExecutable eo name = liftIO $ do
357357
let loop [] = return $ Left $ ExecutableNotFound name (eoPath eo)
358358
loop (dir:dirs) = do
359359
let fp0 = dir FP.</> name
360-
fps0
361-
| null (eoExeExtension eo) = [fp0]
362-
-- Support `stack exec foo.exe` on Windows
363-
| otherwise = [fp0 ++ eoExeExtension eo, fp0]
360+
fps0 = map (fp0 ++) (eoExeExtensions eo)
364361
testFPs [] = loop dirs
365362
testFPs (fp:fps) = do
366363
exists <- D.doesFileExist fp

0 commit comments

Comments
 (0)