Commit b11daf73 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Fix #3294, work around buggy relinking by removing link target.


Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent f83a6f21
......@@ -164,6 +164,7 @@ extra-source-files:
tests/PackageTests/PreProcessExtraSources/Main.hs
tests/PackageTests/PreProcessExtraSources/my.cabal
tests/PackageTests/ReexportedModules/ReexportedModules.cabal
tests/PackageTests/Regression/T3294/T3294.cabal
tests/PackageTests/TemplateHaskell/dynamic/Exe.hs
tests/PackageTests/TemplateHaskell/dynamic/Lib.hs
tests/PackageTests/TemplateHaskell/dynamic/TH.hs
......
......@@ -95,7 +95,7 @@ import Data.Monoid as Mon ( Monoid(..) )
import Data.Version ( showVersion )
import System.Directory
( doesFileExist, getAppUserDataDirectory, createDirectoryIfMissing
, canonicalizePath )
, canonicalizePath, removeFile )
import System.FilePath ( (</>), (<.>), takeExtension
, takeDirectory, replaceExtension
, isRelative )
......@@ -958,7 +958,13 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
-- link:
unless forRepl $ do
info verbosity "Linking..."
runGhcProg linkOpts { ghcOptOutputFile = toFlag (targetDir </> exeNameReal) }
-- Work around old GHCs not relinking in this
-- situation, see #3294
let target = targetDir </> exeNameReal
when (compilerVersion comp < Version [7,7] []) $ do
e <- doesFileExist target
when e (removeFile target)
runGhcProg linkOpts { ghcOptOutputFile = toFlag target }
-- | Returns True if the modification date of the given source file is newer than
-- the object file we last compiled for it, or if no object file exists yet.
......
name: T3294
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: ezyang@cs.stanford.edu
build-type: Simple
cabal-version: >=1.10
executable T3294
main-is: Main.hs
build-depends: base
default-language: Haskell2010
......@@ -344,6 +344,18 @@ tests config = do
runExe' "hello-world" []
>>= assertOutputContains "hello from A"
-- Test that executable recompilation works
-- https://github.com/haskell/cabal/issues/3294
tc "Regression/T3294" $ do
pkg_dir <- packageDir
liftIO $ writeFile (pkg_dir </> "Main.hs") "main = putStrLn \"aaa\""
cabal "configure" []
cabal "build" []
runExe' "T3294" [] >>= assertOutputContains "aaa"
liftIO $ writeFile (pkg_dir </> "Main.hs") "main = putStrLn \"bbb\""
cabal "build" []
runExe' "T3294" [] >>= assertOutputContains "bbb"
where
ghc_pkg_guess bin_name = do
cwd <- packageDir
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment