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