Skip to content

Commit

Permalink
Merge pull request #2247 from commercialhaskell/2225-executable-exten…
Browse files Browse the repository at this point in the history
…sion-windows

Support most executable extensions on Windows #2225
  • Loading branch information
mgsloan committed Jun 6, 2016
2 parents d731ef4 + 35ad01e commit 7669717
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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
26 changes: 14 additions & 12 deletions src/System/Process/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Data.Foldable (forM_)
import Data.IORef
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (isJust, maybeToList)
import Data.Maybe (isJust, maybeToList, fromMaybe)
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
Expand All @@ -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 @@ -112,9 +112,17 @@ mkEnvOverride platform tm' = do
return EnvOverride
{ eoTextMap = tm
, eoStringList = map (T.unpack *** T.unpack) $ Map.toList tm
, eoPath = maybe [] (FP.splitSearchPath . T.unpack) (Map.lookup "PATH" tm)
, eoPath =
(if isWindows then (".":) else id)
(maybe [] (FP.splitSearchPath . T.unpack) (Map.lookup "PATH" tm))
, eoExeCache = ref
, eoExeExtension = if isWindows then ".exe" else ""
, eoExeExtensions =
if isWindows
then let pathext = fromMaybe
".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
(Map.lookup "PATHEXT" tm)
in map T.unpack $ "" : T.splitOn ";" pathext
else [""]
, eoPlatform = platform
}
where
Expand Down Expand Up @@ -336,10 +344,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 +362,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 7669717

Please sign in to comment.