Skip to content

Commit

Permalink
Support most executable extensions on Windows commercialhaskell#2225
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jun 6, 2016
1 parent 3103ebe commit cde532e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Other enhancements:

Bug fixes:

* Support most executable extensions on Windows
[#2225](https://github.com/commercialhaskell/stack/issues/2225)

## 1.1.2

Release notes:
Expand Down
17 changes: 7 additions & 10 deletions src/System/Process/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ data EnvOverride = EnvOverride
, eoStringList :: [(String, String)] -- ^ Environment variables as association list
, eoPath :: [FilePath] -- ^ List of directories searched for executables (@PATH@)
, eoExeCache :: IORef (Map FilePath (Either ReadProcessException (Path Abs File)))
, eoExeExtension :: String -- ^ @""@ or @".exe"@, depending on the platform
, eoExeExtensions :: [String] -- ^ @[""]@ on non-Windows systems, @["", ".exe", ".bat"]@ on Windows
, eoPlatform :: Platform
}

Expand Down Expand Up @@ -114,7 +114,10 @@ mkEnvOverride platform tm' = do
, eoStringList = map (T.unpack *** T.unpack) $ Map.toList tm
, eoPath = maybe [] (FP.splitSearchPath . T.unpack) (Map.lookup "PATH" tm)
, eoExeCache = ref
, eoExeExtension = if isWindows then ".exe" else ""
, eoExeExtensions =
if isWindows
then ["", ".exe", ".bat", ".com"]
else [""]
, eoPlatform = platform
}
where
Expand Down Expand Up @@ -336,10 +339,7 @@ findExecutable :: (MonadIO m, MonadThrow n)
-> String -- ^ Name of executable
-> m (n (Path Abs File)) -- ^ Full path to that executable on success
findExecutable eo name0 | any FP.isPathSeparator name0 = do
let names0
| null (eoExeExtension eo) = [name0]
-- Support `stack exec foo/bar.exe` on Windows
| otherwise = [name0 ++ eoExeExtension eo, name0]
let names0 = map (name0 ++) (eoExeExtensions eo)
testNames [] = return $ throwM $ ExecutableNotFoundAt name0
testNames (name:names) = do
exists <- liftIO $ D.doesFileExist name
Expand All @@ -357,10 +357,7 @@ findExecutable eo name = liftIO $ do
let loop [] = return $ Left $ ExecutableNotFound name (eoPath eo)
loop (dir:dirs) = do
let fp0 = dir FP.</> name
fps0
| null (eoExeExtension eo) = [fp0]
-- Support `stack exec foo.exe` on Windows
| otherwise = [fp0 ++ eoExeExtension eo, fp0]
fps0 = map (fp0 ++) (eoExeExtensions eo)
testFPs [] = loop dirs
testFPs (fp:fps) = do
exists <- D.doesFileExist fp
Expand Down

0 comments on commit cde532e

Please sign in to comment.