Add test compiler option to test (#621)
[hadrian.git] / src / GHC.hs
1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2 module GHC (
3 -- * GHC packages
4 array, base, binary, bytestring, cabal, checkApiAnnotations, checkPpr,
5 compareSizes, compiler, containers, deepseq, deriveConstants, directory,
6 filepath, genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal,
7 ghcCompact, ghcHeap, ghci, ghcPkg, ghcPrim, ghcTags, ghcSplit, haddock,
8 haskeline, hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv,
9 libffi, libiserv, mtl, parsec, parallel, pretty, primitive, process, rts,
10 runGhc, stm, templateHaskell, terminfo, text, time, touchy, transformers,
11 unlit, unix, win32, xhtml, ghcPackages, isGhcPackage, defaultPackages,
12 testsuitePackages,
13
14 -- * Package information
15 programName, nonCabalContext, nonHsMainPackage, autogenPath, installStage,
16
17 -- * Miscellaneous
18 programPath, buildDll0
19 ) where
20
21 import Base
22 import Context
23 import Flavour
24 import GHC.Packages
25 import Oracles.Flag
26 import Oracles.Setting
27 import Settings (flavour)
28
29 -- | Packages that are built by default. You can change this in "UserSettings".
30 defaultPackages :: Stage -> Action [Package]
31 defaultPackages Stage0 = stage0Packages
32 defaultPackages Stage1 = stage1Packages
33 defaultPackages Stage2 = stage2Packages
34 defaultPackages Stage3 = return []
35
36 stage0Packages :: Action [Package]
37 stage0Packages = do
38 win <- windowsHost
39 cross <- flag CrossCompiling
40 return $ [ binary
41 , cabal
42 , compareSizes
43 , compiler
44 , deriveConstants
45 , genapply
46 , genprimopcode
47 , ghc
48 , ghcBoot
49 , ghcBootTh
50 , ghcHeap
51 , ghci
52 , ghcPkg
53 , ghcTags
54 , hsc2hs
55 , hp2ps
56 , hpc
57 , mtl
58 , parsec
59 , templateHaskell
60 , text
61 , transformers
62 , unlit ]
63 ++ [ terminfo | not win, not cross ]
64 ++ [ touchy | win ]
65
66 stage1Packages :: Action [Package]
67 stage1Packages = do
68 win <- windowsHost
69 intLib <- integerLibrary =<< flavour
70 libraries0 <- filter isLibrary <$> stage0Packages
71 cross <- flag CrossCompiling
72 return $ libraries0 -- Build all Stage0 libraries in Stage1
73 ++ [ array
74 , base
75 , bytestring
76 , containers
77 , deepseq
78 , directory
79 , filepath
80 , ghc
81 , ghcCompact
82 , ghcPkg
83 , ghcPrim
84 , haskeline
85 , hsc2hs
86 , intLib
87 , pretty
88 , process
89 , rts
90 , stm
91 , time
92 , unlit
93 , xhtml ]
94 ++ [ haddock | not cross ]
95 ++ [ runGhc | not cross ]
96 ++ [ hpcBin | not cross ]
97 ++ [ iserv | not win, not cross ]
98 ++ [ libiserv | not win, not cross ]
99 ++ [ unix | not win ]
100 ++ [ win32 | win ]
101
102 stage2Packages :: Action [Package]
103 stage2Packages = return [haddock]
104
105 -- | Packages that are built only for the testsuite.
106 testsuitePackages :: Action [Package]
107 testsuitePackages = return [ checkApiAnnotations
108 , checkPpr
109 , hp2ps ]
110
111 -- | Given a 'Context', compute the name of the program that is built in it
112 -- assuming that the corresponding package's type is 'Program'. For example, GHC
113 -- built in 'Stage0' is called @ghc-stage1@. If the given package is a
114 -- 'Library', the function simply returns its name.
115 programName :: Context -> Action String
116 programName Context {..} = do
117 cross <- flag CrossCompiling
118 targetPlatform <- setting TargetPlatformFull
119 let prefix = if cross then targetPlatform ++ "-" else ""
120 in return $ prefix ++ case package of
121 p | p == ghc -> "ghc"
122 | p == hpcBin -> "hpc"
123 | p == runGhc -> "runhaskell"
124 | p == iserv -> "ghc-iserv"
125 _ -> pkgName package
126
127 -- | The build stage whose results are used when installing a package, or
128 -- @Nothing@ if the package is not installed, e.g. because it is a user package.
129 -- The current implementation installs the /latest/ build stage of a package.
130 installStage :: Package -> Action (Maybe Stage)
131 installStage pkg
132 | not (isGhcPackage pkg) = return Nothing -- Only GHC packages are installed
133 | otherwise = do
134 stages <- filterM (fmap (pkg `elem`) . defaultPackages) [Stage0 ..]
135 return $ if null stages then Nothing else Just (maximum stages)
136
137 -- | The 'FilePath' to a program executable in a given 'Context'.
138 programPath :: Context -> Action FilePath
139 programPath context@Context {..} = do
140 -- The @touchy@ utility lives in the @lib/bin@ directory instead of @bin@,
141 -- which is likely just a historical accident that will hopefully be fixed.
142 -- See: https://github.com/snowleopard/hadrian/issues/570
143 -- Likewise for 'unlit'.
144 path <- if package `elem` [touchy, unlit]
145 then stageLibPath stage <&> (-/- "bin")
146 else stageBinPath stage
147 pgm <- programName context
148 return $ path -/- pgm <.> exe
149
150 -- | Some contexts are special: their packages do not have @.cabal@ metadata or
151 -- we cannot run @ghc-cabal@ on them, e.g. because the latter hasn't been built
152 -- yet (this is the case with the 'ghcCabal' package in 'Stage0').
153 nonCabalContext :: Context -> Bool
154 nonCabalContext Context {..} = (package `elem` [ hp2ps
155 , touchy
156 ])
157 || package == ghcCabal && stage == Stage0
158
159 -- | Some program packages should not be linked with Haskell main function.
160 nonHsMainPackage :: Package -> Bool
161 nonHsMainPackage = (`elem` [ghc, hp2ps, iserv, touchy, unlit])
162
163 -- | Path to the autogen directory generated by @ghc-cabal@ of a given 'Context'.
164 autogenPath :: Context -> Action FilePath
165 autogenPath context@Context {..}
166 | isLibrary package = autogen "build"
167 | package == ghc = autogen "build/ghc"
168 | package == hpcBin = autogen "build/hpc"
169 | otherwise = autogen $ "build" -/- pkgName package
170 where
171 autogen dir = contextPath context <&> (-/- dir -/- "autogen")
172
173 buildDll0 :: Context -> Action Bool
174 buildDll0 Context {..} = do
175 windows <- windowsHost
176 return $ windows && stage == Stage1 && package == compiler