1

I would like to remove files that no longer have source but without cleaning.

Is there support for partially cleaning an incremental build? In this case, I guess I could compare against set of source files that were consumed in previous builds and define how to clean those that are gone.

main = shakeArgs shakeOptions { shakeVerbosity = Diagnostic } $ do
    want [".build"]
    phony ".build" $ do
      files <- getDirectoryFiles "." ["//*.txt"]
      let goals = map (-<.> "") files
      need goals
    "*" %> \out -> do
      Stdout o <- cmd $ "sort " ++ (out ++ ".txt")
      writeFile' out o
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
sevo
  • 4,559
  • 1
  • 15
  • 31

1 Answers1

0

Using shakeArgsPrune you can define a function that gets passed the live files afterwards. You can then write something like:

import Development.Shake
import Development.Shake.FilePath
import Development.Shake.Util
import System.Directory.Extra
import Data.List
import System.IO

pruner :: [FilePath] -> IO ()
pruner live = do
    present <- listFilesRecursive "output"
    mapM_ removeFile $ map toStandard present \\ map toStandard live

main :: IO ()
main = shakeArgsPrune shakeOptions pruner $ do
    ... rules go here ...

This deletes all files in output that are not generated and up-to-date according to the build system as it stands. For a complete example see http://neilmitchell.blogspot.co.uk/2015/04/cleaning-stale-files-with-shake.html.

The shakeArgsPrune function is only available in shake-0.15.1 and above, but is based on the shakeLiveFiles feature which has been available for longer and can be used directly if you so desire.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85