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 authored and borsboom committed Oct 24, 2018
1 parent 538f211 commit 72a1976
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 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.1

Expand Down
12 changes: 7 additions & 5 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,13 @@ parseDumpHI dumpHIPath = do
thDeps =
-- The dependent file path is surrounded by quotes but is not escaped.
-- It can be an absolute or relative path.
mapMaybe
(fmap TL.unpack .
(TL.stripSuffix "\"" <=< TL.stripPrefix "\"") .
TL.dropWhileEnd (== '\r') . TLE.decodeUtf8 . CL8.dropWhile (/= '"')) $
filter ("addDependentFile \"" `CL8.isPrefixOf`) dumpHI
TL.unpack .
-- Starting with GHC 8.4.3, there's a hash following
-- the path. See
-- https://github.com/yesodweb/yesod/issues/1551
TLE.decodeUtf8 .
CL8.takeWhile (/= '\"') <$>
mapMaybe (CL8.stripPrefix "addDependentFile \"") dumpHI
thDepsResolved <- liftM catMaybes $ forM thDeps $ \x -> do
mresolved <- liftIO (forgivingAbsence (resolveFile dir x)) >>= rejectMissingFile
when (isNothing mresolved) $
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 ""
putStr 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
*.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")
9 changes: 9 additions & 0 deletions test/integration/tests/watched-files/files/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: watched-files
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 72a1976

Please sign in to comment.