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