summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Clean.hs
blob: 26a279d1780b0c9fd39eb499f65ff33d0cd24562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Rules.Clean (clean, cleanSourceTree, cleanRules) where

import qualified System.Directory as IO
import Base

distclean :: Action ()
distclean = do
    putBuild "| Removing mingw tarballs..."
    cleanMingwTarballs
    cleanFsUtils
    clean

clean :: Action ()
clean = do
    putBuild "| Removing Hadrian files..."
    cleanSourceTree
    path <- buildRoot
    putBuild $ "| Remove directory " ++ path ++ " (after build completes)"
    runAfter $ IO.removeDirectoryRecursive path -- since we can't delete the Shake database while Shake is running
    putSuccess "| Done. "

cleanSourceTree :: Action ()
cleanSourceTree = do
    path <- buildRoot
    forM_ [Stage0 ..] $ removeDirectory . (path -/-) . stageString
    removeDirectory "sdistprep"

cleanMingwTarballs :: Action ()
cleanMingwTarballs = do
    removeDirectory "ghc-tarballs"

-- Clean all temporary fs files copied by configure into the source folder
cleanFsUtils :: Action ()
cleanFsUtils = do
    let dirs = [ "utils/lndir/"
               , "utils/unlit/"
               , "rts/"
               , "libraries/base/include/"
               , "libraries/base/cbits/"
               ]
    liftIO $ forM_ dirs (flip removeFiles ["fs.*"])

cleanRules :: Rules ()
cleanRules = do
    "clean" ~> clean
    "distclean" ~> distclean