From f939504e5c6709db8dbd29afefdc37103f026439 Mon Sep 17 00:00:00 2001 From: Alfredo Di Napoli Date: Thu, 17 Sep 2015 14:21:44 +0200 Subject: [PATCH] Fix #997 (pass --ghc-options -hpcdir) only on --coverage This patch extends `extraBuildOptions` in `Execute.hs` to accept an extra argument of type `BuildOpts`, as well as checking if coverage is enabled. In case it is, `-hpcdir` is passed as `--ghc-option`. This is needed to avoid certain in-memory REPL (like [hint](https://hackage.haskell.org/package/hint)) to choke on that command line option. --- src/Stack/Build/Execute.hs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 47ef881f98..6d259f46b5 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -927,7 +927,7 @@ singleBuild runInBase ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} in () <- announce "build" config <- asks getConfig - extraOpts <- extraBuildOptions + extraOpts <- extraBuildOptions eeBuildOpts cabal (console && configHideTHLoading config) $ (case taskType of TTLocal lp -> concat @@ -1043,7 +1043,7 @@ singleTest runInBase topts lptb ac ee task installedMap = do case taskType task of TTLocal lp -> writeBuildCache pkgDir $ lpNewBuildCache lp TTUpstream _ _ -> assert False $ return () - extraOpts <- extraBuildOptions + extraOpts <- extraBuildOptions (eeBuildOpts ee) cabal (console && configHideTHLoading config) $ "build" : (components ++ extraOpts) setTestBuilt pkgDir @@ -1187,7 +1187,7 @@ singleBench runInBase beopts _lptb ac ee task installedMap = do TTLocal lp -> writeBuildCache pkgDir $ lpNewBuildCache lp TTUpstream _ _ -> assert False $ return () config <- asks getConfig - extraOpts <- extraBuildOptions + extraOpts <- extraBuildOptions (eeBuildOpts ee) cabal (console && configHideTHLoading config) ("build" : extraOpts) setBenchBuilt pkgDir let args = maybe [] @@ -1278,10 +1278,17 @@ getSetupHs dir = do fp1 = dir $(mkRelFile "Setup.hs") fp2 = dir $(mkRelFile "Setup.lhs") -extraBuildOptions :: M env m => m [String] -extraBuildOptions = do - hpcIndexDir <- toFilePath . ( dotHpc) <$> hpcRelativeDir - return ["--ghc-options", "-hpcdir " ++ hpcIndexDir ++ " -ddump-hi -ddump-to-file"] +-- Do not pass `-hpcdir` as GHC option if the coverage is not enabled. +-- This helps running stack-compiled programs with dynamic interpreters like `hint`. +-- Cfr: https://github.com/commercialhaskell/stack/issues/997 +extraBuildOptions :: M env m => BuildOpts -> m [String] +extraBuildOptions bopts = do + let ddumpOpts = " -ddump-hi -ddump-to-file" + case toCoverage (boptsTestOpts bopts) of + True -> do + hpcIndexDir <- toFilePath . ( dotHpc) <$> hpcRelativeDir + return ["--ghc-options", "-hpcdir " ++ hpcIndexDir ++ ddumpOpts] + False -> return ["--ghc-options", ddumpOpts] -- | Take the given list of package dependencies and the contents of the global -- package database, and construct a set of installed package IDs that: