From cde532e90e8ebdd41f621ad68ecc002868a350ca Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 6 Jun 2016 08:28:12 +0300 Subject: [PATCH 1/3] 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 From d5b8a7720ae8e0a3a6790e7de35863c9cbd43f59 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 6 Jun 2016 14:27:11 +0300 Subject: [PATCH 2/3] PATHEXT env var and support for "." on Windows PATH #2225 --- src/System/Process/Read.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/System/Process/Read.hs b/src/System/Process/Read.hs index 273598fbfb..0857c83dc8 100644 --- a/src/System/Process/Read.hs +++ b/src/System/Process/Read.hs @@ -112,11 +112,15 @@ 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 , eoExeExtensions = if isWindows - then ["", ".exe", ".bat", ".com"] + then case Map.lookup "PATHEXT" tm of + Nothing -> ["", ".exe", ".bat", ".com"] + Just t -> map T.unpack $ "" : T.splitOn ";" t else [""] , eoPlatform = platform } From 35ad01e6c7a2c7b090e52594043dc72cd7ed27b9 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 6 Jun 2016 15:05:58 +0300 Subject: [PATCH 3/3] Use better default path extension --- src/System/Process/Read.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/System/Process/Read.hs b/src/System/Process/Read.hs index 0857c83dc8..ed591fa9f7 100644 --- a/src/System/Process/Read.hs +++ b/src/System/Process/Read.hs @@ -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 @@ -118,9 +118,10 @@ mkEnvOverride platform tm' = do , eoExeCache = ref , eoExeExtensions = if isWindows - then case Map.lookup "PATHEXT" tm of - Nothing -> ["", ".exe", ".bat", ".com"] - Just t -> map T.unpack $ "" : T.splitOn ";" t + 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 }