6e56c666b6eceb0d5eab8efce27d8516715493b3
[ghc.git] / hadrian / src / Rules / SourceDist.hs
1 module Rules.SourceDist (sourceDistRules) where
2
3 import Hadrian.Oracles.DirectoryContents
4
5 import Base
6 import Builder
7 import Oracles.Setting
8 import Rules.Clean
9
10 sourceDistRules :: Rules ()
11 sourceDistRules = do
12 "source-dist" ~> do
13 -- We clean the source tree first.
14 -- See https://github.com/snowleopard/hadrian/issues/384.
15 -- TODO: Do we still need to clean the tree?
16 cleanSourceTree
17 version <- setting ProjectVersion
18 need ["sdistprep/ghc-" ++ version ++ "-src.tar.xz"]
19 putSuccess "| Done"
20 "sdistprep/ghc-*-src.tar.xz" %> \fname -> do
21 let tarName = takeFileName fname
22 dropTarXz = dropExtension . dropExtension
23 treePath = "sdistprep/ghc" -/- dropTarXz tarName
24 prepareTree treePath
25 runBuilderWithCmdOptions [Cwd "sdistprep/ghc"] (Tar Create)
26 ["cJf", ".." -/- tarName, dropTarXz tarName]
27 ["cJf", ".." -/- tarName] [dropTarXz tarName]
28 "GIT_COMMIT_ID" %> \fname ->
29 writeFileChanged fname =<< setting ProjectGitCommitId
30 "VERSION" %> \fname ->
31 writeFileChanged fname =<< setting ProjectVersion
32
33 prepareTree :: FilePath -> Action ()
34 prepareTree dest = do
35 mapM_ cpDir srcDirs
36 mapM_ cpFile srcFiles
37 where
38 cpFile a = copyFile a (dest -/- a)
39 cpDir a = copyDirectoryContents (Not excluded) a (dest -/- a)
40 excluded = Or
41 [ Test "//.*"
42 , Test "//#*"
43 , Test "//*-SAVE"
44 , Test "//*.orig"
45 , Test "//*.rej"
46 , Test "//*~"
47 , Test "//autom4te*"
48 , Test "//dist"
49 , Test "//dist-install"
50 , Test "//log"
51 , Test "//stage0"
52 , Test "//stage1"
53 , Test "//stage2"
54 , Test "//stage3"
55 , Test "hadrian/.cabal-sandbox"
56 , Test "hadrian/.stack-work"
57 , Test "hadrian/UserSettings.hs"
58 , Test "hadrian/cabal.sandbox.config"
59 , Test "hadrian/cfg/system.config"
60 , Test "hadrian/bin"
61 , Test "hadrian/dist"
62 , Test "hadrian/dist-newstyle"
63 , Test "libraries//*.buildinfo"
64 , Test "libraries//GNUmakefile"
65 , Test "libraries//config.log"
66 , Test "libraries//config.status"
67 , Test "libraries//configure"
68 , Test "libraries//ghc.mk"
69 , Test "libraries//include/Hs*Config.h"
70 , Test "libraries/dph"
71 , Test "libraries/primitive"
72 , Test "libraries/random"
73 , Test "libraries/stm"
74 , Test "libraries/vector"
75 , Test "mk/build.mk" ]
76 srcDirs =
77 [ "bindisttest"
78 , "compiler"
79 , "distrib"
80 , "docs"
81 , "docs"
82 , "driver"
83 , "ghc"
84 , "hadrian"
85 , "includes"
86 , "iserv"
87 , "libffi"
88 , "libffi-tarballs"
89 , "libraries"
90 , "mk"
91 , "rts"
92 , "rules"
93 , "utils" ]
94 srcFiles =
95 [ "ANNOUNCE"
96 , "GIT_COMMIT_ID"
97 , "HACKING.md"
98 , "INSTALL.md"
99 , "LICENSE"
100 , "MAKEHELP.md"
101 , "Makefile"
102 , "README.md"
103 , "VERSION"
104 , "aclocal.m4"
105 , "boot"
106 , "config.guess"
107 , "config.sub"
108 , "configure"
109 , "configure.ac"
110 , "ghc.mk"
111 , "install-sh"
112 , "packages"
113 , "settings.in" ]