Reduce verbosity of ghc-cabal and ghc-pkg
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 module Settings.Builders.GhcCabal (
3 ghcCabalBuilderArgs, ghcCabalHsColourBuilderArgs, bootPackageDatabaseArgs,
4 PackageDatabaseKey (..), buildDll0
5 ) where
6
7 import Base
8 import Context
9 import Flavour
10 import GHC
11 import Oracles.Config.Flag
12 import Oracles.Config.Setting
13 import Oracles.WindowsPath
14 import Predicate
15 import Settings
16 import Settings.Builders.Common
17 import Settings.Paths
18
19 ghcCabalBuilderArgs :: Args
20 ghcCabalBuilderArgs = builder GhcCabal ? do
21 verbosity <- lift $ getVerbosity
22 mconcat [ arg "configure"
23 , arg =<< getPackagePath
24 , arg =<< getContextDirectory
25 , dll0Args
26 , withStaged $ Ghc CompileHs
27 , withStaged GhcPkg
28 , bootPackageDatabaseArgs
29 , libraryArgs
30 , with HsColour
31 , configureArgs
32 , packageConstraints
33 , withStaged $ Cc CompileC
34 , notStage0 ? with Ld
35 , with Ar
36 , with Alex
37 , with Happy
38 , verbosity < Chatty ? append [ "-v0", "--configure-option=--quiet"
39 , "--configure-option=--disable-option-checking" ] ]
40
41 ghcCabalHsColourBuilderArgs :: Args
42 ghcCabalHsColourBuilderArgs = builder GhcCabalHsColour ? do
43 path <- getPackagePath
44 dir <- getContextDirectory
45 append [ "hscolour", path, dir ]
46
47 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
48 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
49 libraryArgs :: Args
50 libraryArgs = do
51 ways <- getLibraryWays
52 withGhci <- lift ghcWithInterpreter
53 append [ if vanilla `elem` ways
54 then "--enable-library-vanilla"
55 else "--disable-library-vanilla"
56 , if vanilla `elem` ways && withGhci && not (dynamicGhcPrograms flavour)
57 then "--enable-library-for-ghci"
58 else "--disable-library-for-ghci"
59 , if profiling `elem` ways
60 then "--enable-library-profiling"
61 else "--disable-library-profiling"
62 , if dynamic `elem` ways
63 then "--enable-shared"
64 else "--disable-shared" ]
65
66 -- TODO: LD_OPTS?
67 -- TODO: WARNING: unrecognized options: --with-compiler, --with-gmp-libraries, --with-cc
68 configureArgs :: Args
69 configureArgs = do
70 top <- getTopDirectory
71 let conf key = appendSubD $ "--configure-option=" ++ key
72 cFlags = mconcat [ cArgs
73 , remove ["-Werror"]
74 , argStagedSettingList ConfCcArgs
75 , arg $ "-I" ++ top -/- generatedPath ]
76 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
77 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
78 mconcat
79 [ conf "CFLAGS" cFlags
80 , conf "LDFLAGS" ldFlags
81 , conf "CPPFLAGS" cppFlags
82 , appendSubD "--gcc-options" $ cFlags <> ldFlags
83 , conf "--with-iconv-includes" $ argSetting IconvIncludeDir
84 , conf "--with-iconv-libraries" $ argSetting IconvLibDir
85 , conf "--with-gmp-includes" $ argSetting GmpIncludeDir
86 , conf "--with-gmp-libraries" $ argSetting GmpLibDir
87 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
88 , conf "--with-cc" $ argStagedBuilderPath (Cc CompileC) ]
89
90 newtype PackageDatabaseKey = PackageDatabaseKey Stage
91 deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
92
93 initialisePackageDatabase :: Stage -> Action ()
94 initialisePackageDatabase = askOracle . PackageDatabaseKey
95
96 bootPackageDatabaseArgs :: Args
97 bootPackageDatabaseArgs = do
98 stage <- getStage
99 lift $ initialisePackageDatabase stage
100 stage0 ? do
101 path <- getTopDirectory
102 prefix <- ifM (builder Ghc) (return "-package-db ") (return "--package-db=")
103 arg $ prefix ++ path -/- packageDbDirectory Stage0
104
105 packageConstraints :: Args
106 packageConstraints = stage0 ? do
107 constraints <- lift . readFileLines $ bootPackageConstraints
108 append $ concat [ ["--constraint", c] | c <- constraints ]
109
110 cppArgs :: Args
111 cppArgs = arg $ "-I" ++ generatedPath
112
113 withBuilderKey :: Builder -> String
114 withBuilderKey b = case b of
115 Ar -> "--with-ar="
116 Ld -> "--with-ld="
117 Cc _ _ -> "--with-gcc="
118 Ghc _ _ -> "--with-ghc="
119 Alex -> "--with-alex="
120 Happy -> "--with-happy="
121 GhcPkg _ -> "--with-ghc-pkg="
122 HsColour -> "--with-hscolour="
123 _ -> error $ "withBuilderKey: not supported builder " ++ show b
124
125 -- Expression 'with Alex' appends "--with-alex=/path/to/alex" and needs Alex.
126 with :: Builder -> Args
127 with b = specified b ? do
128 top <- getTopDirectory
129 path <- getBuilderPath b
130 lift $ needBuilder b
131 arg $ withBuilderKey b ++ unifyPath (top </> path)
132
133 withStaged :: (Stage -> Builder) -> Args
134 withStaged sb = with . sb =<< getStage
135
136 buildDll0 :: Context -> Action Bool
137 buildDll0 Context {..} = do
138 windows <- windowsHost
139 return $ windows && stage == Stage1 && package == compiler
140
141 -- This is a positional argument, hence:
142 -- * if it is empty, we need to emit one empty string argument;
143 -- * otherwise, we must collapse it into one space-separated string.
144 dll0Args :: Args
145 dll0Args = do
146 context <- getContext
147 dll0 <- lift $ buildDll0 context
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" ]