Skip to content

Commit

Permalink
Outputs can't be autodeps, fixes ndmitchell#818
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed Jan 17, 2022
1 parent 06ed483 commit e4935aa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Development/Shake/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Prelude

import Development.Shake.Internal.CmdOption
import Development.Shake.Internal.Core.Action
import Development.Shake.Internal.Core.Monad
import Development.Shake.Internal.Core.Types hiding (Result)
import Development.Shake.FilePath
import Development.Shake.Internal.Options
Expand Down Expand Up @@ -313,18 +314,22 @@ commandExplicitAction oparams = do

autodeps act = do
ResultFSATrace pxs : res <- act params{opts = addFSAOptions "rwm" opts, results = ResultFSATrace [] : results}
Local{localProduces} <- Action getRW
let written = Set.fromList $ [x | FSAMove x _ <- pxs] ++ [x | FSAWrite x <- pxs]
-- If something both reads and writes to a file, it isn't eligible to be an autodeps
xs <- liftIO $ filterM doesFileExist [x | FSARead x <- pxs, not $ x `Set.member` written]
cwd <- liftIO getCurrentDirectory
temp <- fixPaths cwd xs
unsafeAllowApply $ need temp
-- Outputs can't be autodeps.
let outputs = Set.fromList $ snd <$> localProduces
inputs = filter (not . (`Set.member` outputs)) temp
unsafeAllowApply $ need inputs
pure res

fixPaths cwd xs = liftIO $ do
xs<- pure $ map toStandard xs
xs<- pure $ filter (\x -> any (`isPrefixOf` x) shakeLintInside) xs
mapM (\x -> fromMaybe x <$> makeRelativeEx cwd x) xs
let standard = map toStandard xs
inside = filter (\x -> any (`isPrefixOf` x) shakeLintInside) standard
mapM (\x -> fromMaybe x <$> makeRelativeEx cwd x) inside

fsalint act = do
ResultFSATrace xs : res <- act params{opts = addFSAOptions "rwm" opts, results = ResultFSATrace [] : results}
Expand Down

0 comments on commit e4935aa

Please sign in to comment.