Skip to content

Commit

Permalink
Handle hash at the end of addDependentFile
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Aug 13, 2018
1 parent 15decc8 commit 7e36fb0
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Other enhancements:

Bug fixes:

* Handle a change in GHC's hi-dump format around `addDependentFile`,
which now includes a hash. See
[yesodweb/yesod#1551](https://github.com/yesodweb/yesod/issues/1551)


## v1.9.0 (release candidate)

Expand Down
7 changes: 5 additions & 2 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,11 @@ parseDumpHI dumpHIPath = do
-- It can be an absolute or relative path.
mapMaybe
(fmap TL.unpack .
(TL.stripSuffix "\"" <=< TL.stripPrefix "\"") .
TL.dropWhileEnd (== '\r') . TLE.decodeUtf8 . CL8.dropWhile (/= '"')) $
TL.stripPrefix "\"" .
-- Starting with GHC 8.4.3, there's a hash following
-- the path. See
-- https://github.com/yesodweb/yesod/issues/1551
TL.takeWhile (/= '\"') . TLE.decodeUtf8 . CL8.dropWhile (/= '"')) $
filter ("addDependentFile \"" `CL8.isPrefixOf`) dumpHI
thDepsResolved <- liftM catMaybes $ forM thDeps $ \x -> do
mresolved <- liftIO (forgivingAbsence (resolveFile dir x)) >>= rejectMissingFile
Expand Down
18 changes: 18 additions & 0 deletions test/integration/lib/StackTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ stackErrStderr args check = do
then error "Stack process succeeded, but it shouldn't"
else check err

stackStdout :: [String] -> IO (ExitCode, String)
stackStdout args = do
stackExe' <- stackExe
logInfo $ "Running: " ++ stackExe' ++ " " ++ unwords (map showProcessArgDebug args)
(ec, out, err) <- readProcessWithExitCode stackExe' args ""
hPutStr stdout out
hPutStr stderr err
return (ec, out)

-- | Run stack with arguments and apply a check to the resulting
-- stdout output if the process succeeded.
stackCheckStdout :: [String] -> (String -> IO ()) -> IO ()
stackCheckStdout args check = do
(ec, out) <- stackStdout args
if ec /= ExitSuccess
then error $ "Exited with exit code: " ++ show ec
else check out

doesNotExist :: FilePath -> IO ()
doesNotExist fp = do
logInfo $ "doesNotExist " ++ fp
Expand Down
14 changes: 14 additions & 0 deletions test/integration/tests/watched-files/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import StackTest
import Data.Foldable (for_)
import Control.Monad (unless)

main :: IO ()
main = for_ (words "foo bar baz bin") $ \x -> do
writeFile "some-text-file.txt" x
stackCheckStdout ["run"] $ \y ->
unless (x == y) $ error $ concat
[ "Expected: "
, show x
, "\nActual: "
, show y
]
2 changes: 2 additions & 0 deletions test/integration/tests/watched-files/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
some-text-file.txt
files.cabal
9 changes: 9 additions & 0 deletions test/integration/tests/watched-files/files/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE TemplateHaskell #-}
module Main where

import Data.FileEmbed
import qualified Data.ByteString as B
import System.IO (stdout)

main :: IO ()
main = B.hPut stdout $(embedFile "some-text-file.txt")
8 changes: 8 additions & 0 deletions test/integration/tests/watched-files/files/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies:
- base
- bytestring
- file-embed

executables:
watched:
main: Main.hs
1 change: 1 addition & 0 deletions test/integration/tests/watched-files/files/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolver: lts-11.19

0 comments on commit 7e36fb0

Please sign in to comment.