Minor revision
[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 -- * Paths
22 hadrianPath, configPath, configFile, sourcePath, configH, shakeFilesDir,
23 generatedDir, inplaceBinPath, inplaceLibBinPath, inplaceLibPath,
24 inplaceLibCopyTargets, haddockHtmlResourcesStamp, templateHscPath,
25 stage0PackageDbDir, inplacePackageDbPath, packageDbPath, packageDbStamp,
26 ghcSplitPath
27 ) where
28
29 import Control.Applicative
30 import Control.Monad.Extra
31 import Control.Monad.Reader
32 import Data.List.Extra
33 import Data.Maybe
34 import Data.Semigroup
35 import Development.Shake hiding (parallel, unit, (*>), Normal)
36 import Development.Shake.Classes
37 import Development.Shake.FilePath
38 import Development.Shake.Util
39 import Hadrian.Utilities
40 import Hadrian.Package
41
42 import Stage
43 import Way
44
45 -- | Hadrian lives in the 'hadrianPath' directory of the GHC tree.
46 hadrianPath :: FilePath
47 hadrianPath = "hadrian"
48
49 -- TODO: Move this to build directory?
50 -- | Path to system configuration files, such as 'configFile'.
51 configPath :: FilePath
52 configPath = hadrianPath -/- "cfg"
53
54 -- | Path to the system configuration file generated by the @configure@ script.
55 configFile :: FilePath
56 configFile = configPath -/- "system.config"
57
58 -- | Path to source files of the build system, e.g. this file is located at
59 -- @sourcePath -/- "Base.hs"@. We use this to track some of the source files.
60 sourcePath :: FilePath
61 sourcePath = hadrianPath -/- "src"
62
63 -- TODO: Change @mk/config.h@ to @shake-build/cfg/config.h@.
64 -- | Path to the generated @mk/config.h@ file.
65 configH :: FilePath
66 configH = "mk/config.h"
67
68 -- | The directory in 'buildRoot' containing the Shake database and other
69 -- auxiliary files generated by Hadrian.
70 shakeFilesDir :: FilePath
71 shakeFilesDir = "hadrian"
72
73 -- | Directory for binaries that are built "in place".
74 inplaceBinPath :: FilePath
75 inplaceBinPath = "inplace/bin"
76
77 -- | Directory for libraries that are built "in place".
78 inplaceLibPath :: FilePath
79 inplaceLibPath = "inplace/lib"
80
81 -- | Directory for binary wrappers, and auxiliary binaries such as @touchy@.
82 inplaceLibBinPath :: FilePath
83 inplaceLibBinPath = inplaceLibPath -/- "bin"
84
85 -- | The directory in 'buildRoot' containing generated source files that are not
86 -- package-specific, e.g. @ghcplatform.h@.
87 generatedDir :: FilePath
88 generatedDir = "generated"
89
90 -- | The directory in 'buildRoot' containing the 'Stage0' package database.
91 stage0PackageDbDir :: FilePath
92 stage0PackageDbDir = "stage0/bootstrapping.conf"
93
94 -- | Path to the inplace package database used in 'Stage1' and later.
95 inplacePackageDbPath :: FilePath
96 inplacePackageDbPath = inplaceLibPath -/- "package.conf.d"
97
98 -- | Path to the package database used in a given 'Stage'.
99 packageDbPath :: Stage -> Action FilePath
100 packageDbPath Stage0 = buildRoot <&> (-/- stage0PackageDbDir)
101 packageDbPath _ = return inplacePackageDbPath
102
103 -- | We use a stamp file to track the existence of a package database.
104 packageDbStamp :: FilePath
105 packageDbStamp = ".stamp"
106
107 -- ref: GHC_DEPENDENCIES in ghc/ghc.mk
108 -- ref: INSTALL_LIBS in driver/ghc.mk
109 -- TODO: Derive this from Builder.runtimeDependencies
110 -- | Files that need to be copied over to 'inplaceLibPath'.
111 inplaceLibCopyTargets :: [FilePath]
112 inplaceLibCopyTargets = map (inplaceLibPath -/-)
113 [ "ghc-usage.txt"
114 , "ghci-usage.txt"
115 , "llvm-targets"
116 , "platformConstants"
117 , "settings"
118 , "template-hsc.h" ]
119
120 -- TODO: This is fragile and will break if @README.md@ is removed. We need to
121 -- improve the story of program runtime dependencies on directories.
122 -- See: https://github.com/snowleopard/hadrian/issues/492.
123 -- | Path to a file in Haddock's HTML resource library.
124 haddockHtmlResourcesStamp :: FilePath
125 haddockHtmlResourcesStamp = inplaceLibPath -/- "html/README.md"
126
127 -- ref: utils/hsc2hs/ghc.mk
128 -- | Path to 'hsc2hs' template.
129 templateHscPath :: FilePath
130 templateHscPath = inplaceLibPath -/- "template-hsc.h"
131
132 -- | @ghc-split@ is a Perl script used by GHC when run with @-split-objs@ flag.
133 -- It is generated in "Rules.Generate".
134 ghcSplitPath :: FilePath
135 ghcSplitPath = inplaceLibBinPath -/- "ghc-split"