Implement buildPackageDependencies rule.
[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 | GccM Stage
33 | GhcPkg Stage
34 deriving (Show, Eq, Generic)
35
36 -- Configuration files refer to Builders as follows:
37 builderKey :: Builder -> String
38 builderKey builder = case builder of
39 Ar -> "ar"
40 Ld -> "ld"
41 Alex -> "alex"
42 Happy -> "happy"
43 HsColour -> "hscolour"
44 GhcCabal -> "ghc-cabal"
45 Ghc Stage0 -> "system-ghc"
46 Ghc Stage1 -> "ghc-stage1"
47 Ghc Stage2 -> "ghc-stage2"
48 Ghc Stage3 -> "ghc-stage3"
49 Gcc Stage0 -> "system-gcc"
50 Gcc _ -> "gcc"
51 GhcPkg Stage0 -> "system-ghc-pkg"
52 GhcPkg _ -> "ghc-pkg"
53 -- GhcM is currently a synonym for Ghc (to be called with -M flag)
54 GhcM stage -> builderKey $ Ghc stage
55 GccM stage -> builderKey $ Gcc stage
56
57 builderPath :: Builder -> Action String
58 builderPath builder = do
59 path <- askConfigWithDefault (builderKey builder) $
60 redError $ "\nCannot find path to '" ++ (builderKey builder)
61 ++ "' in configuration files."
62 fixAbsolutePathOnWindows $ if null path then "" else path -<.> exe
63
64 specified :: Builder -> Action Bool
65 specified = fmap (not . null) . builderPath
66
67 -- On Windows: if the path starts with "/", prepend it with the correct path to
68 -- the root, e.g: "/usr/local/bin/ghc.exe" => "C:/msys/usr/local/bin/ghc.exe".
69 fixAbsolutePathOnWindows :: FilePath -> Action FilePath
70 fixAbsolutePathOnWindows path = do
71 windows <- windowsHost
72 -- Note, below is different from FilePath.isAbsolute:
73 if (windows && "/" `isPrefixOf` path)
74 then do
75 root <- windowsRoot
76 return . unifyPath $ root ++ drop 1 path
77 else
78 return path
79
80 -- When LaxDeps flag is set ('lax-dependencies = YES' in user.config),
81 -- dependencies on the GHC executable are turned into order-only dependencies
82 -- to avoid needless recompilation when making changes to GHC's sources. In
83 -- certain situations this can lead to build failures, in which case you
84 -- should reset the flag (at least temporarily).
85
86 -- Instances for storing in the Shake database
87 instance Binary Builder
88 instance Hashable Builder