Skip to content

Commit

Permalink
WIP, workaround for fsatrace on OSX 10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed May 6, 2016
1 parent 9e611b6 commit cf5e949
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Development/Shake/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ commandExplicit funcName oopts results exe args = do
, not $ any ($ x) ignore]

fsaCmd act opts file
| isMac = fsaCmdMac act opts file
| useShell = runShell (unwords $ exe : args) $ \exe args -> act "fsatrace" $ opts : file : "--" : exe : args
| otherwise = act "fsatrace" $ opts : file : "--" : exe : args

fsaCmdMac act opts file = do
fexe <- fakeExe exe
if useShell
then do
fsh <- fakeExe "/bin/sh"
act "fsatrace" $ opts : file : "--" : fsh : "-c" : [unwords $ fexe : args]
else act "fsatrace" $ opts : file : "--" : fexe : args

fsatrace act = withTempFile $ \file -> do
res <- fsaCmd act "rwm" file
xs <- liftIO $ parseFSAT <$> readFileUTF8' file
Expand Down
32 changes: 30 additions & 2 deletions src/Development/Shake/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module Development.Shake.Core(
parallel,
orderOnlyAction,
-- Internal stuff
runAfter
runAfter,
fakeExe
) where

import Control.Exception.Extra
Expand All @@ -34,6 +35,7 @@ import qualified Data.HashMap.Strict as Map
import Data.Maybe
import Data.IORef
import System.Directory
import System.FilePath
import System.IO.Extra
import System.Time.Extra
import Data.Monoid
Expand Down Expand Up @@ -324,6 +326,7 @@ data Global = Global
,globalAfter :: IORef [IO ()]
,globalTrackAbsent :: IORef [(Key, Key)] -- in rule fst, snd must be absent
,globalProgress :: IO Progress
,globalFakesCache :: FilePath -> Action FilePath
}


Expand Down Expand Up @@ -400,6 +403,27 @@ run opts@ShakeOptions{..} rs = (if shakeLineBuffering then lineBuffering else id
,("Wanted",Just dir)
,("Got",Just now)]
""

fcache <- newCacheIO $ \e -> liftIO $ do
me <- findExecutable e
case me of
Just re -> do
let isSystem = any (`isPrefixOf` re) [ "/bin"
, "/usr"
, "/sbin"
]
if isSystem
then do
tmpdir <- getTemporaryDirectory
let fakedir = tmpdir ++ "fsatrace-fakes/"
fake = fakedir ++ takeFileName e
createDirectoryIfMissing True fakedir
putStrLn $ "copying " ++ re ++ " to " ++ fake
copyFile re fake
return fake
else return re
Nothing -> return e

diagnostic "Starting run 2"

after <- newIORef []
Expand All @@ -425,7 +449,7 @@ run opts@ShakeOptions{..} rs = (if shakeLineBuffering then lineBuffering else id
let ruleinfo = createRuleinfo opts rs
addTiming "Running rules"
runPool (shakeThreads == 1) shakeThreads $ \pool -> do
let s0 = Global database pool cleanup start ruleinfo output opts diagnostic lint after absent getProgress
let s0 = Global database pool cleanup start ruleinfo output opts diagnostic lint after absent getProgress fcache
let s1 = Local emptyStack shakeVerbosity Nothing [] 0 [] [] []
forM_ (actions rs) $ \act ->
addPool pool $ runAction s0 s1 act $ \x -> case x of
Expand Down Expand Up @@ -566,6 +590,10 @@ getProgress = do
res <- Action $ getsRO globalProgress
liftIO res

fakeExe :: FilePath -> Action FilePath
fakeExe e = do
gfc <- Action $ getsRO globalFakesCache
gfc e

-- | Write an action to the trace list, along with the start/end time of running the IO action.
-- The 'Development.Shake.cmd' and 'Development.Shake.command' functions automatically call 'traced'.
Expand Down

0 comments on commit cf5e949

Please sign in to comment.