Permalink
Browse files

Handle hash at the end of addDependentFile

  • Loading branch information...
snoyberg committed Aug 13, 2018
1 parent 0f20925 commit aae15e3ae5767febe9fcad36bf5a5e184c635de1
@@ -18,6 +18,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)

@@ -1284,11 +1284,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) $
@@ -126,6 +126,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
@@ -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
]
@@ -0,0 +1,2 @@
some-text-file.txt
*.cabal
@@ -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")
@@ -0,0 +1,9 @@
name: watched-files
dependencies:
- base
- bytestring
- file-embed

executables:
watched:
main: Main.hs
@@ -0,0 +1 @@
resolver: lts-11.19

0 comments on commit aae15e3

Please sign in to comment.