From cde532e90e8ebdd41f621ad68ecc002868a350ca Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 6 Jun 2016 08:28:12 +0300 Subject: [PATCH] Support most executable extensions on Windows #2225 --- ChangeLog.md | 3 +++ src/System/Process/Read.hs | 17 +++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5d9c9dff47..cd8b619ad6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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: diff --git a/src/System/Process/Read.hs b/src/System/Process/Read.hs index b94f57067b..273598fbfb 100644 --- a/src/System/Process/Read.hs +++ b/src/System/Process/Read.hs @@ -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 } @@ -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 @@ -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 @@ -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