33735d32a0815a0188879602fc7b55b1f76b894b
[hadrian.git] / src / Builder.hs
1 {-# LANGUAGE DeriveGeneric #-}
2
3 module Builder (
4 Builder (..), builderKey, builderPath, specified
5 ) where
6
7 import Util
8 import Stage
9 import Data.List
10 import Oracles.Base
11 import Oracles.Setting
12 import Oracles.WindowsRoot
13 import GHC.Generics
14
15 -- A Builder is an external command invoked in separate process using Shake.cmd
16 --
17 -- Ghc Stage0 is the bootstrapping compiler
18 -- Ghc StageN, N > 0, is the one built on stage (N - 1)
19 -- GhcPkg Stage0 is the bootstrapping GhcPkg
20 -- GhcPkg StageN, N > 0, is the one built on stage 0 (TODO: need only Stage1?)
21 -- TODO: add Cpp and Haddock builders
22 -- TODO: rename Gcc to Cc?
23 data Builder = Ar
24 | Ld
25 | Alex
26 | Happy
27 | HsColour
28 | GhcCabal
29 | Gcc Stage
30 | Ghc Stage
31 | GhcM Stage
32 | GhcPkg Stage
33 deriving (Show, Eq, Generic)
34
35 -- Configuration files refer to Builders as follows:
36 builderKey :: Builder -> String
37 builderKey builder = case builder of
38 Ar -> "ar"
39 Ld -> "ld"
40 Alex -> "alex"
41 Happy -> "happy"
42 HsColour -> "hscolour"
43 GhcCabal -> "ghc-cabal"
44 Ghc Stage0 -> "system-ghc"
45 Ghc Stage1 -> "ghc-stage1"
46 Ghc Stage2 -> "ghc-stage2"
47 Ghc Stage3 -> "ghc-stage3"
48 Gcc Stage0 -> "system-gcc"
49 Gcc _ -> "gcc"
50 GhcPkg Stage0 -> "system-ghc-pkg"
51 GhcPkg _ -> "ghc-pkg"
52 -- GhcM is currently a synonym for Ghc (to be called with -M flag)
53 GhcM stage -> builderKey $ Ghc stage
54
55 builderPath :: Builder -> Action String
56 builderPath builder = do
57 path <- askConfigWithDefault (builderKey builder) $
58 redError $ "\nCannot find path to '" ++ (builderKey builder)
59 ++ "' in configuration files."
60 fixAbsolutePathOnWindows $ if null path then "" else path -<.> exe
61
62 specified :: Builder -> Action Bool
63 specified = fmap (not . null) . builderPath
64
65 -- On Windows: if the path starts with "/", prepend it with the correct path to
66 -- the root, e.g: "/usr/local/bin/ghc.exe" => "C:/msys/usr/local/bin/ghc.exe".
67 fixAbsolutePathOnWindows :: FilePath -> Action FilePath
68 fixAbsolutePathOnWindows path = do
69 windows <- windowsHost
70 -- Note, below is different from FilePath.isAbsolute:
71 if (windows && "/" `isPrefixOf` path)
72 then do
73 root <- windowsRoot
74 return . unifyPath $ root ++ drop 1 path
75 else
76 return path
77
78 -- When LaxDeps flag is set ('lax-dependencies = YES' in user.config),
79 -- dependencies on the GHC executable are turned into order-only dependencies
80 -- to avoid needless recompilation when making changes to GHC's sources. In
81 -- certain situations this can lead to build failures, in which case you
82 -- should reset the flag (at least temporarily).
83
84 -- Instances for storing in the Shake database
85 instance Binary Builder
86 instance Hashable Builder