Skip to content

Commit

Permalink
Fix dropExeExtension on Windows
Browse files Browse the repository at this point in the history
On Windows dropExeExtension doesn't actually drop the exe extension.

We have

    splitExtension "foo.exe" == ("foo", ".exe")

but the code is expecting just "exe" for the extension field.

Among other things this makes guessToolFromGhcPath behave
unexpectedly. Since takeVersionSuffix can't see past the extension the
`null suf` case in mkGuesses will trigger which causes the versioned
program path candidates to not be looked for.
  • Loading branch information
DanielG committed Oct 7, 2019
1 parent cc5bfb0 commit 38db5ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,14 +1415,14 @@ dropExeExtension filepath =
(filepath', extension) | extension `elem` exeExtensions -> filepath'
| otherwise -> filepath

-- | List of possible executable file extensions on the current platform.
-- | List of possible executable file extensions on the current build platform.
exeExtensions :: [String]
exeExtensions = case buildOS of
-- Possible improvement: on Windows, read the list of extensions from the
-- PATHEXT environment variable. By default PATHEXT is ".com; .exe; .bat;
-- .cmd".
Windows -> ["", "exe"]
Ghcjs -> ["", "exe"]
Windows -> ["", ".exe"]
Ghcjs -> ["", ".exe"]
_ -> [""]

-- ------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion Cabal/tests/UnitTests/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Distribution.Verbosity
import Data.IORef
import System.Directory ( doesDirectoryExist, doesFileExist
, getTemporaryDirectory
, removeDirectoryRecursive, removeFile )
, removeDirectoryRecursive, removeFile
, exeExtension )
import System.IO (hClose, localeEncoding, hPutStrLn)
import System.IO.Error
import qualified Control.Exception as Exception
Expand Down Expand Up @@ -84,6 +85,10 @@ rawSystemStdInOutTextDecodingTest ghcPath
Left err | isDoesNotExistError err -> Exception.throwIO err -- no ghc!
| otherwise -> return ()

dropExeExtensionTest :: Assertion
dropExeExtensionTest =
assertBool "dropExeExtension didn't drop exeExtension!" $
dropExeExtension ("foo" ++ exeExtension) == "foo"


tests :: FilePath -> [TestTree]
Expand All @@ -98,4 +103,6 @@ tests ghcPath =
withTempDirRemovedTest
, testCase "rawSystemStdInOut reports text decoding errors" $
rawSystemStdInOutTextDecodingTest ghcPath
, testCase "dropExeExtension drops exe extension" $
dropExeExtensionTest
]

0 comments on commit 38db5ce

Please sign in to comment.