Add ghc-iserv wrapper (#367)
[hadrian.git] / src / GHC.hs
1 {-# LANGUAGE OverloadedStrings, LambdaCase #-}
2 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
3 module GHC (
4 array, base, binary, bytestring, cabal, checkApiAnnotations, compareSizes,
5 compiler, containers, deepseq, deriveConstants, directory, dllSplit, filepath,
6 genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal, ghcCompact, ghci,
7 ghcPkg, ghcPrim, ghcTags, ghcSplit, haddock, haskeline, hsc2hs, hp2ps,
8 hpc, hpcBin, integerGmp, integerSimple, iservBin, libffi, mkUserGuidePart,
9 parallel, pretty, primitive, process, rts, runGhc, stm, templateHaskell,
10 terminfo, time, touchy, transformers, unlit, unix, win32, xhtml,
11 defaultKnownPackages, builderProvenance, programName, nonCabalContext,
12 nonHsMainPackage
13 ) where
14
15 import Builder
16 import Context
17 import Package
18 import Stage
19
20 -- | These are all GHC packages we know about. Build rules will be generated for
21 -- all of them. However, not all of these packages will be built. For example,
22 -- package 'win32' is built only on Windows.
23 -- "Packages" defines default conditions for building each package, which can
24 -- be overridden in @hadrian/src/UserSettings.hs@.
25 defaultKnownPackages :: [Package]
26 defaultKnownPackages =
27 [ array, base, binary, bytestring, cabal, checkApiAnnotations, compareSizes
28 , compiler, containers, deepseq, deriveConstants, directory, dllSplit
29 , filepath, genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal
30 , ghcCompact, ghci, ghcPkg, ghcPrim, ghcTags, haddock, haskeline, hsc2hs
31 , hp2ps, hpc, hpcBin, integerGmp, integerSimple, iservBin, libffi
32 , mkUserGuidePart, parallel, pretty, primitive, process, rts, runGhc, stm
33 , templateHaskell, terminfo, time, touchy, transformers, unlit, unix, win32
34 , xhtml ]
35
36 -- | Package definitions, see 'Package'.
37 array = library "array"
38 base = library "base"
39 binary = library "binary"
40 bytestring = library "bytestring"
41 cabal = library "Cabal" `setPath` "libraries/Cabal/Cabal"
42 checkApiAnnotations = utility "check-api-annotations"
43 compareSizes = utility "compareSizes" `setPath` "utils/compare_sizes"
44 compiler = topLevel "ghc" `setPath` "compiler"
45 containers = library "containers"
46 deepseq = library "deepseq"
47 deriveConstants = utility "deriveConstants"
48 directory = library "directory"
49 dllSplit = utility "dll-split"
50 filepath = library "filepath"
51 genapply = utility "genapply"
52 genprimopcode = utility "genprimopcode"
53 ghc = topLevel "ghc-bin" `setPath` "ghc" `setType` Program
54 ghcBoot = library "ghc-boot"
55 ghcBootTh = library "ghc-boot-th"
56 ghcCabal = utility "ghc-cabal"
57 ghcCompact = library "ghc-compact"
58 ghci = library "ghci"
59 ghcPkg = utility "ghc-pkg"
60 ghcPrim = library "ghc-prim"
61 ghcTags = utility "ghctags"
62 ghcSplit = utility "ghc-split"
63 haddock = utility "haddock"
64 haskeline = library "haskeline"
65 hsc2hs = utility "hsc2hs"
66 hp2ps = utility "hp2ps"
67 hpc = library "hpc"
68 hpcBin = utility "hpc-bin" `setPath` "utils/hpc"
69 integerGmp = library "integer-gmp"
70 integerSimple = library "integer-simple"
71 iservBin = topLevel "iserv-bin" `setPath` "iserv" `setType` Program
72 libffi = topLevel "libffi"
73 mkUserGuidePart = utility "mkUserGuidePart"
74 parallel = library "parallel"
75 pretty = library "pretty"
76 primitive = library "primitive"
77 process = library "process"
78 rts = topLevel "rts"
79 runGhc = utility "runghc"
80 stm = library "stm"
81 templateHaskell = library "template-haskell"
82 terminfo = library "terminfo"
83 time = library "time"
84 touchy = utility "touchy"
85 transformers = library "transformers"
86 unlit = utility "unlit"
87 unix = library "unix"
88 win32 = library "Win32"
89 xhtml = library "xhtml"
90
91 -- | Some builders are built by this very build system, in which case
92 -- 'builderProvenance' returns the corresponding build 'Context' (which includes
93 -- 'Stage' and GHC 'Package').
94 builderProvenance :: Builder -> Maybe Context
95 builderProvenance = \case
96 DeriveConstants -> context Stage0 deriveConstants
97 GenApply -> context Stage0 genapply
98 GenPrimopCode -> context Stage0 genprimopcode
99 Ghc _ Stage0 -> Nothing
100 Ghc _ stage -> context (pred stage) ghc
101 GhcCabal -> context Stage0 ghcCabal
102 GhcCabalHsColour -> builderProvenance $ GhcCabal
103 GhcPkg _ Stage0 -> Nothing
104 GhcPkg _ _ -> context Stage0 ghcPkg
105 Haddock -> context Stage2 haddock
106 Hpc -> context Stage1 hpcBin
107 Hsc2Hs -> context Stage0 hsc2hs
108 Unlit -> context Stage0 unlit
109 _ -> Nothing
110 where
111 context s p = Just $ vanillaContext s p
112
113 -- | Given a 'Context', compute the name of the program that is built in it
114 -- assuming that the corresponding package's type is 'Program'. For example, GHC
115 -- built in 'Stage0' is called @ghc-stage1@. If the given package is a
116 -- 'Library', the function simply returns its name.
117 programName :: Context -> String
118 programName Context {..}
119 | package == ghc = "ghc-stage" ++ show (fromEnum stage + 1)
120 | package == hpcBin = "hpc"
121 | package == runGhc = "runhaskell"
122 | package == iservBin = "ghc-iserv"
123 | otherwise = pkgNameString package
124
125 -- | Some contexts are special: their packages do have @.cabal@ metadata or
126 -- we cannot run @ghc-cabal@ on them, e.g. because the latter hasn't been built
127 -- yet (this is the case with the 'ghcCabal' package in 'Stage0').
128 nonCabalContext :: Context -> Bool
129 nonCabalContext Context {..} = (package `elem` [hp2ps, rts, touchy, unlit])
130 || package == ghcCabal && stage == Stage0
131
132 -- | Some program packages should not be linked with Haskell main function.
133 nonHsMainPackage :: Package -> Bool
134 nonHsMainPackage = (`elem` [ghc, hp2ps, iservBin, touchy, unlit])