Create package database directories using oracles.
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2 module Settings.Builders.GhcCabal (
3 ghcCabalBuilderArgs, ghcCabalHsColourBuilderArgs, bootPackageDbArgs,
4 PackageDbKey (..), cppArgs, needDll0
5 ) where
6
7 import Base
8 import Oracles.Config.Setting
9 import Oracles.Config.Flag
10 import GHC
11 import Package
12 import Way
13 import Builder
14 import Stage
15 import Expression
16 import Predicates hiding (stage)
17 import Settings
18 import Settings.Builders.Common
19
20 ghcCabalBuilderArgs :: Args
21 ghcCabalBuilderArgs = builder GhcCabal ? do
22 path <- getPackagePath
23 dir <- getTargetDirectory
24 mconcat [ arg "configure"
25 , arg path
26 , arg dir
27 , dll0Args
28 , withStaged Ghc
29 , withStaged GhcPkg
30 , bootPackageDbArgs
31 , libraryArgs
32 , with HsColour
33 , configureArgs
34 , packageConstraints
35 , withStaged Gcc
36 , notStage0 ? with Ld
37 , with Ar
38 , with Alex
39 , with Happy ]
40
41 ghcCabalHsColourBuilderArgs :: Args
42 ghcCabalHsColourBuilderArgs = builder GhcCabalHsColour ? do
43 path <- getPackagePath
44 dir <- getTargetDirectory
45 mconcat [ arg "hscolour"
46 , arg path
47 , arg dir ]
48
49 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
50 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
51 libraryArgs :: Args
52 libraryArgs = do
53 ways <- getLibraryWays
54 withGhci <- lift ghcWithInterpreter
55 append [ if vanilla `elem` ways
56 then "--enable-library-vanilla"
57 else "--disable-library-vanilla"
58 , if vanilla `elem` ways && withGhci && not dynamicGhcPrograms
59 then "--enable-library-for-ghci"
60 else "--disable-library-for-ghci"
61 , if profiling `elem` ways
62 then "--enable-library-profiling"
63 else "--disable-library-profiling"
64 , if dynamic `elem` ways
65 then "--enable-shared"
66 else "--disable-shared" ]
67
68 -- TODO: LD_OPTS?
69 configureArgs :: Args
70 configureArgs = do
71 let conf key = appendSubD $ "--configure-option=" ++ key
72 cFlags = mconcat [ cArgs
73 , remove ["-Werror"]
74 , argStagedSettingList ConfCcArgs ]
75 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
76 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
77 mconcat
78 [ conf "CFLAGS" cFlags
79 , conf "LDFLAGS" ldFlags
80 , conf "CPPFLAGS" cppFlags
81 , appendSubD "--gcc-options" $ cFlags <> ldFlags
82 , conf "--with-iconv-includes" $ argSettingList IconvIncludeDirs
83 , conf "--with-iconv-libraries" $ argSettingList IconvLibDirs
84 , conf "--with-gmp-includes" $ argSettingList GmpIncludeDirs
85 , conf "--with-gmp-libraries" $ argSettingList GmpLibDirs
86 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
87 , conf "--with-cc" $ argStagedBuilderPath Gcc ]
88
89 newtype PackageDbKey = PackageDbKey Stage
90 deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
91
92 initialisePackageDb :: Stage -> Action ()
93 initialisePackageDb stage = askOracle $ PackageDbKey stage
94
95 bootPackageDbArgs :: Args
96 bootPackageDbArgs = do
97 stage <- getStage
98 lift $ initialisePackageDb stage
99 stage0 ? do
100 path <- getTopDirectory
101 prefix <- ifM builderGhc (return "-package-db ") (return "--package-db=")
102 arg $ prefix ++ path -/- packageDbDirectory Stage0
103
104 packageConstraints :: Args
105 packageConstraints = stage0 ? do
106 constraints <- lift . readFileLines $ bootPackageConstraints
107 append $ concat [ ["--constraint", c] | c <- constraints ]
108
109 cppArgs :: Args
110 cppArgs = includesArgs
111
112 withBuilderKey :: Builder -> String
113 withBuilderKey b = case b of
114 Ar -> "--with-ar="
115 Ld -> "--with-ld="
116 Gcc _ -> "--with-gcc="
117 Ghc _ -> "--with-ghc="
118 Alex -> "--with-alex="
119 Happy -> "--with-happy="
120 GhcPkg _ -> "--with-ghc-pkg="
121 HsColour -> "--with-hscolour="
122 _ -> error "withBuilderKey: not supported builder"
123
124 -- Expression 'with Gcc' appends "--with-gcc=/path/to/gcc" and needs Gcc.
125 with :: Builder -> Args
126 with b = specified b ? do
127 top <- getTopDirectory
128 path <- getBuilderPath b
129 lift $ needBuilder laxDependencies b
130 append [withBuilderKey b ++ top -/- path]
131
132 withStaged :: (Stage -> Builder) -> Args
133 withStaged sb = (with . sb) =<< getStage
134
135 needDll0 :: Stage -> Package -> Action Bool
136 needDll0 stage pkg = do
137 windows <- windowsHost
138 return $ windows && pkg == compiler && stage == Stage1
139
140 -- This is a positional argument, hence:
141 -- * if it is empty, we need to emit one empty string argument;
142 -- * otherwise, we must collapse it into one space-separated string.
143 dll0Args :: Args
144 dll0Args = do
145 stage <- getStage
146 pkg <- getPackage
147 dll0 <- lift $ needDll0 stage pkg
148 withGhci <- lift ghcWithInterpreter
149 arg . unwords . concat $ [ modules | dll0 ]
150 ++ [ ghciModules | dll0 && withGhci ] -- see #9552
151 where
152 modules = [ "Annotations"
153 , "ApiAnnotation"
154 , "Avail"
155 , "Bag"
156 , "BasicTypes"
157 , "Binary"
158 , "BooleanFormula"
159 , "BreakArray"
160 , "BufWrite"
161 , "Class"
162 , "CmdLineParser"
163 , "CmmType"
164 , "CoAxiom"
165 , "ConLike"
166 , "Coercion"
167 , "Config"
168 , "Constants"
169 , "CoreArity"
170 , "CoreFVs"
171 , "CoreSubst"
172 , "CoreSyn"
173 , "CoreTidy"
174 , "CoreUnfold"
175 , "CoreUtils"
176 , "CoreSeq"
177 , "CoreStats"
178 , "CostCentre"
179 , "Ctype"
180 , "DataCon"
181 , "Demand"
182 , "Digraph"
183 , "DriverPhases"
184 , "DynFlags"
185 , "Encoding"
186 , "ErrUtils"
187 , "Exception"
188 , "ExtsCompat46"
189 , "FamInstEnv"
190 , "FastFunctions"
191 , "FastMutInt"
192 , "FastString"
193 , "FastTypes"
194 , "Fingerprint"
195 , "FiniteMap"
196 , "ForeignCall"
197 , "Hooks"
198 , "HsBinds"
199 , "HsDecls"
200 , "HsDoc"
201 , "HsExpr"
202 , "HsImpExp"
203 , "HsLit"
204 , "PlaceHolder"
205 , "HsPat"
206 , "HsSyn"
207 , "HsTypes"
208 , "HsUtils"
209 , "HscTypes"
210 , "IOEnv"
211 , "Id"
212 , "IdInfo"
213 , "IfaceSyn"
214 , "IfaceType"
215 , "InstEnv"
216 , "Kind"
217 , "Lexeme"
218 , "Lexer"
219 , "ListSetOps"
220 , "Literal"
221 , "Maybes"
222 , "MkCore"
223 , "MkId"
224 , "Module"
225 , "MonadUtils"
226 , "Name"
227 , "NameEnv"
228 , "NameSet"
229 , "OccName"
230 , "OccurAnal"
231 , "OptCoercion"
232 , "OrdList"
233 , "Outputable"
234 , "PackageConfig"
235 , "Packages"
236 , "Pair"
237 , "Panic"
238 , "PatSyn"
239 , "PipelineMonad"
240 , "Platform"
241 , "PlatformConstants"
242 , "PprCore"
243 , "PrelNames"
244 , "PrelRules"
245 , "Pretty"
246 , "PrimOp"
247 , "RdrName"
248 , "Rules"
249 , "Serialized"
250 , "SrcLoc"
251 , "StaticFlags"
252 , "StringBuffer"
253 , "TcEvidence"
254 , "TcRnTypes"
255 , "TcType"
256 , "TrieMap"
257 , "TyCon"
258 , "Type"
259 , "TypeRep"
260 , "TysPrim"
261 , "TysWiredIn"
262 , "Unify"
263 , "UniqFM"
264 , "UniqSet"
265 , "UniqSupply"
266 , "Unique"
267 , "Util"
268 , "Var"
269 , "VarEnv"
270 , "VarSet" ]
271 ghciModules = [ "Bitmap"
272 , "BlockId"
273 , "ByteCodeAsm"
274 , "ByteCodeInstr"
275 , "ByteCodeItbls"
276 , "CLabel"
277 , "Cmm"
278 , "CmmCallConv"
279 , "CmmExpr"
280 , "CmmInfo"
281 , "CmmMachOp"
282 , "CmmNode"
283 , "CmmSwitch"
284 , "CmmUtils"
285 , "CodeGen.Platform"
286 , "CodeGen.Platform.ARM"
287 , "CodeGen.Platform.ARM64"
288 , "CodeGen.Platform.NoRegs"
289 , "CodeGen.Platform.PPC"
290 , "CodeGen.Platform.PPC_Darwin"
291 , "CodeGen.Platform.SPARC"
292 , "CodeGen.Platform.X86"
293 , "CodeGen.Platform.X86_64"
294 , "FastBool"
295 , "Hoopl"
296 , "Hoopl.Dataflow"
297 , "InteractiveEvalTypes"
298 , "MkGraph"
299 , "PprCmm"
300 , "PprCmmDecl"
301 , "PprCmmExpr"
302 , "Reg"
303 , "RegClass"
304 , "SMRep"
305 , "StgCmmArgRep"
306 , "StgCmmClosure"
307 , "StgCmmEnv"
308 , "StgCmmLayout"
309 , "StgCmmMonad"
310 , "StgCmmProf"
311 , "StgCmmTicky"
312 , "StgCmmUtils"
313 , "StgSyn"
314 , "Stream" ]