Bump Cabal upper bound (#651)
[hadrian.git] / src / Base.hs
1 module Base (
2 -- * General utilities
3 module Control.Applicative,
4 module Control.Monad.Extra,
5 module Data.List.Extra,
6 module Data.Maybe,
7 module Data.Semigroup,
8 module Hadrian.Utilities,
9
10 -- * Shake
11 module Development.Shake,
12 module Development.Shake.Classes,
13 module Development.Shake.FilePath,
14 module Development.Shake.Util,
15
16 -- * Basic data types
17 module Hadrian.Package,
18 module Stage,
19 module Way,
20
21 -- * Files
22 configH, ghcVersionH,
23
24 -- * Paths
25 hadrianPath, configPath, configFile, sourcePath, shakeFilesDir,
26 generatedDir, generatedPath, stageBinPath, stageLibPath, templateHscPath,
27 ghcDeps, relativePackageDbPath, packageDbPath, packageDbStamp, ghcSplitPath
28 ) where
29
30 import Control.Applicative
31 import Control.Monad.Extra
32 import Control.Monad.Reader
33 import Data.List.Extra
34 import Data.Maybe
35 import Data.Semigroup
36 import Development.Shake hiding (parallel, unit, (*>), Normal)
37 import Development.Shake.Classes
38 import Development.Shake.FilePath
39 import Development.Shake.Util
40 import Hadrian.Utilities
41 import Hadrian.Package
42
43 import Stage
44 import Way
45
46 -- | Hadrian lives in the 'hadrianPath' directory of the GHC tree.
47 hadrianPath :: FilePath
48 hadrianPath = "hadrian"
49
50 -- TODO: Move this to build directory?
51 -- | Path to system configuration files, such as 'configFile'.
52 configPath :: FilePath
53 configPath = hadrianPath -/- "cfg"
54
55 -- | Path to the system configuration file generated by the @configure@ script.
56 configFile :: FilePath
57 configFile = configPath -/- "system.config"
58
59 -- | Path to source files of the build system, e.g. this file is located at
60 -- @sourcePath -/- "Base.hs"@. We use this to track some of the source files.
61 sourcePath :: FilePath
62 sourcePath = hadrianPath -/- "src"
63
64 -- TODO: Change @mk/config.h@ to @shake-build/cfg/config.h@.
65 -- | Path to the generated @mk/config.h@ file.
66 configH :: FilePath
67 configH = "mk/config.h"
68
69 ghcVersionH :: Action FilePath
70 ghcVersionH = generatedPath <&> (-/- "ghcversion.h")
71
72 -- | The directory in 'buildRoot' containing the Shake database and other
73 -- auxiliary files generated by Hadrian.
74 shakeFilesDir :: FilePath
75 shakeFilesDir = "hadrian"
76
77 -- | The directory in 'buildRoot' containing generated source files that are not
78 -- package-specific, e.g. @ghcplatform.h@.
79 generatedDir :: FilePath
80 generatedDir = "generated"
81
82 generatedPath :: Action FilePath
83 generatedPath = buildRoot <&> (-/- generatedDir)
84
85 -- | Path to the package database for the given stage of GHC,
86 -- relative to the build root.
87 relativePackageDbPath :: Stage -> FilePath
88 relativePackageDbPath stage = stageString stage -/- "lib" -/- "package.conf.d"
89
90 -- | Path to the package database used in a given 'Stage', including
91 -- the build root.
92 packageDbPath :: Stage -> Action FilePath
93 packageDbPath stage = buildRoot <&> (-/- relativePackageDbPath stage)
94
95 -- | We use a stamp file to track the existence of a package database.
96 packageDbStamp :: FilePath
97 packageDbStamp = ".stamp"
98
99 -- | @bin@ directory for the given 'Stage' (including the build root)
100 stageBinPath :: Stage -> Action FilePath
101 stageBinPath stage = buildRoot <&> (-/- stageString stage -/- "bin")
102
103 -- | @lib@ directory for the given 'Stage' (including the build root)
104 stageLibPath :: Stage -> Action FilePath
105 stageLibPath stage = buildRoot <&> (-/- stageString stage -/- "lib")
106
107 -- | Files the `ghc` binary depends on
108 ghcDeps :: Stage -> Action [FilePath]
109 ghcDeps stage = mapM (\f -> stageLibPath stage <&> (-/- f))
110 [ "ghc-usage.txt"
111 , "ghci-usage.txt"
112 , "llvm-targets"
113 , "llvm-passes"
114 , "platformConstants"
115 , "settings" ]
116
117 -- ref: utils/hsc2hs/ghc.mk
118 -- | Path to 'hsc2hs' template.
119 templateHscPath :: Stage -> Action FilePath
120 templateHscPath stage = stageLibPath stage <&> (-/- "template-hsc.h")
121
122 -- | @ghc-split@ is a Perl script used by GHC when run with @-split-objs@ flag.
123 -- It is generated in "Rules.Generate". This function returns the path relative
124 -- to the build root under which we will copy @ghc-split@.
125 ghcSplitPath :: Stage -> FilePath
126 ghcSplitPath stage = stageString stage -/- "bin" -/- "ghc-split"