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 6, 2019
1 parent cc5bfb0 commit 8a2393d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,10 @@ shortRelativePath from to =
dropExeExtension :: FilePath -> FilePath
dropExeExtension filepath =
case splitExtension filepath of
(filepath', extension) | extension `elem` exeExtensions -> filepath'
| otherwise -> filepath
(filepath', extension)
| extension `elem` exts -> filepath'
| otherwise -> filepath
where exts = [ "." ++ ext | ext <- exeExtensions ]

-- | List of possible executable file extensions on the current platform.
exeExtensions :: [String]
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 actually drops exe extension" $
dropExeExtensionTest
]

0 comments on commit 8a2393d

Please sign in to comment.