1b0dc13cb98791db4b45d1e0408c6a5f7b012113
[hadrian.git] / src / Settings / Path.hs
1 module Settings.Path (
2 stageDirectory, buildPath, pkgDataFile, pkgHaddockFile, pkgLibraryFile,
3 pkgLibraryFile0, pkgGhciLibraryFile, gmpContext, gmpBuildPath, gmpObjects,
4 gmpLibraryH, gmpBuildInfoPath, generatedPath, libffiContext, libffiBuildPath,
5 rtsContext, rtsBuildPath, rtsConfIn, shakeFilesPath,inplacePackageDbDirectory,
6 pkgConfFile, packageDbStamp, bootPackageConstraints, packageDependencies,
7 objectPath, inplaceBinPath, inplaceLibBinPath, inplaceLibPath,
8 inplaceInstallPath, autogenPath, pkgInplaceConfig, ghcSplitPath, stripCmdPath,
9 pkgSetupConfigFile
10 ) where
11
12 import Base
13 import Context
14 import Expression
15 import GHC
16 import Oracles.PackageData
17 import Oracles.Config.Setting (setting, Setting(..))
18 import Oracles.Path (getTopDirectory)
19 import UserSettings
20
21 -- | Path to the directory containing the Shake database and other auxiliary
22 -- files generated by Hadrian.
23 shakeFilesPath :: FilePath
24 shakeFilesPath = buildRootPath -/- "hadrian"
25
26 -- | Boot package versions extracted from @.cabal@ files.
27 bootPackageConstraints :: FilePath
28 bootPackageConstraints = shakeFilesPath -/- "boot-package-constraints"
29
30 -- | Dependencies between packages extracted from @.cabal@ files.
31 packageDependencies :: FilePath
32 packageDependencies = shakeFilesPath -/- "package-dependencies"
33
34 -- | Path to the directory containing generated source files that are not
35 -- package-specific, e.g. @ghcplatform.h@.
36 generatedPath :: FilePath
37 generatedPath = buildRootPath -/- "generated"
38
39 -- | Relative path to the directory containing build artefacts of a given 'Stage'.
40 stageDirectory :: Stage -> FilePath
41 stageDirectory = stageString
42
43 -- | Directory for binaries that are built "in place".
44 inplaceBinPath :: FilePath
45 inplaceBinPath = "inplace/bin"
46
47 -- | Directory for libraries that are built "in place".
48 inplaceLibPath :: FilePath
49 inplaceLibPath = "inplace/lib"
50
51 -- | Directory for binary wrappers, and auxiliary binaries such as @touchy@.
52 inplaceLibBinPath :: FilePath
53 inplaceLibBinPath = "inplace/lib/bin"
54
55 -- | Path to the directory containing build artefacts of a given 'Context'.
56 buildPath :: Context -> FilePath
57 buildPath Context {..} = buildRootPath -/- stageDirectory stage -/- pkgPath package
58
59 -- | Path to the autogen directory generated by @ghc-cabal@ of a given 'Context'.
60 autogenPath :: Context -> FilePath
61 autogenPath context@Context {..}
62 | isLibrary package = autogen "build"
63 | package == ghc = autogen "build/ghc"
64 | package == hpcBin = autogen "build/hpc"
65 | package == iservBin = autogen "build/iserv"
66 | otherwise = autogen $ "build" -/- pkgNameString package
67 where
68 autogen dir = buildPath context -/- dir -/- "autogen"
69
70 -- | Path to inplace package configuration of a given 'Context'.
71 pkgInplaceConfig :: Context -> FilePath
72 pkgInplaceConfig context = buildPath context -/- "inplace-pkg-config"
73
74 -- | Path to the @package-data.mk@ of a given 'Context'.
75 pkgDataFile :: Context -> FilePath
76 pkgDataFile context = buildPath context -/- "package-data.mk"
77
78
79 -- | Path to the @setup-config@ of a given 'Context'.
80 pkgSetupConfigFile :: Context -> FilePath
81 pkgSetupConfigFile context = buildPath context -/- "setup-config"
82
83 -- | Path to the haddock file of a given 'Context', e.g.:
84 -- "_build/stage1/libraries/array/doc/html/array/array.haddock".
85 pkgHaddockFile :: Context -> FilePath
86 pkgHaddockFile context@Context {..} =
87 buildPath context -/- "doc/html" -/- name -/- name <.> "haddock"
88 where name = pkgNameString package
89
90 -- | Path to the library file of a given 'Context', e.g.:
91 -- "_build/stage1/libraries/array/build/libHSarray-0.5.1.0.a".
92 pkgLibraryFile :: Context -> Action FilePath
93 pkgLibraryFile context@Context {..} = do
94 extension <- libsuf way
95 pkgFile context "libHS" extension
96
97 -- | Path to the auxiliary library file of a given 'Context', e.g.:
98 -- "_build/stage1/compiler/build/libHSghc-8.1-0.a".
99 pkgLibraryFile0 :: Context -> Action FilePath
100 pkgLibraryFile0 context@Context {..} = do
101 extension <- libsuf way
102 pkgFile context "libHS" ("-0" ++ extension)
103
104 -- | Path to the GHCi library file of a given 'Context', e.g.:
105 -- "_build/stage1/libraries/array/build/HSarray-0.5.1.0.o".
106 pkgGhciLibraryFile :: Context -> Action FilePath
107 pkgGhciLibraryFile context = pkgFile context "HS" ".o"
108
109 pkgFile :: Context -> String -> String -> Action FilePath
110 pkgFile context prefix suffix = do
111 let path = buildPath context
112 componentId <- pkgData $ ComponentId path
113 return $ path -/- prefix ++ componentId ++ suffix
114
115 -- | RTS is considered a Stage1 package. This determines RTS build directory.
116 rtsContext :: Context
117 rtsContext = vanillaContext Stage1 rts
118
119 -- | Path to the RTS build directory.
120 rtsBuildPath :: FilePath
121 rtsBuildPath = buildPath rtsContext
122
123 -- | Path to RTS package configuration file, to be processed by HsCpp.
124 rtsConfIn :: FilePath
125 rtsConfIn = pkgPath rts -/- "package.conf.in"
126
127 -- | GMP is considered a Stage1 package. This determines GMP build directory.
128 gmpContext :: Context
129 gmpContext = vanillaContext Stage1 integerGmp
130
131 -- | Build directory for in-tree GMP library.
132 gmpBuildPath :: FilePath
133 gmpBuildPath = buildRootPath -/- stageDirectory (stage gmpContext) -/- "gmp"
134
135 -- | Path to the GMP library header.
136 gmpLibraryH :: FilePath
137 gmpLibraryH = gmpBuildPath -/- "include/ghc-gmp.h"
138
139 -- | Path to the GMP library object files.
140 gmpObjects :: FilePath
141 gmpObjects = gmpBuildPath -/- "objs"
142
143 -- | Path to the GMP library buildinfo file.
144 gmpBuildInfoPath :: FilePath
145 gmpBuildInfoPath = pkgPath integerGmp -/- "integer-gmp.buildinfo"
146
147 -- | Libffi is considered a Stage1 package. This determines its build directory.
148 libffiContext :: Context
149 libffiContext = vanillaContext Stage1 libffi
150
151 -- | Build directory for in-tree Libffi library.
152 libffiBuildPath :: FilePath
153 libffiBuildPath = buildPath libffiContext
154
155 -- | Path to package database directory of a given 'Stage'. Note: StageN, N > 0,
156 -- share the same packageDbDirectory.
157 inplacePackageDbDirectory :: Stage -> FilePath
158 inplacePackageDbDirectory Stage0 = buildRootPath -/- "stage0/bootstrapping.conf"
159 inplacePackageDbDirectory _ = "inplace/lib/package.conf.d"
160
161 -- | We use a stamp file to track the existence of a package database.
162 packageDbStamp :: Stage -> FilePath
163 packageDbStamp stage = inplacePackageDbDirectory stage -/- ".stamp"
164
165 -- | Path to the configuration file of a given 'Context'.
166 pkgConfFile :: Context -> Action FilePath
167 pkgConfFile context@Context {..} = do
168 componentId <- pkgData . ComponentId $ buildPath context
169 return $ inplacePackageDbDirectory stage -/- componentId <.> "conf"
170
171 -- | Given a 'FilePath' to a source file, return 'True' if it is generated.
172 -- The current implementation simply assumes that a file is generated if it
173 -- lives in 'buildRootPath'. Since most files are not generated the test is
174 -- usually very fast.
175 isGeneratedSource :: FilePath -> Bool
176 isGeneratedSource = (buildRootPath `isPrefixOf`)
177
178 -- | Given a 'Context' and a 'FilePath' to a source file, compute the 'FilePath'
179 -- to its object file. For example:
180 -- * "Task.c" -> "_build/stage1/rts/Task.thr_o"
181 -- * "_build/stage1/rts/cmm/AutoApply.cmm" -> "_build/stage1/rts/cmm/AutoApply.o"
182 objectPath :: Context -> FilePath -> FilePath
183 objectPath context@Context {..} src
184 | isGeneratedSource src = obj
185 | "*hs*" ?== extension = buildPath context -/- obj
186 | otherwise = buildPath context -/- extension -/- obj
187 where
188 extension = drop 1 $ takeExtension src
189 obj = src -<.> osuf way
190
191 -- | Given a 'Package', return the path where the corresponding program is
192 -- installed. Most programs are installed in 'programInplacePath'.
193 inplaceInstallPath :: Package -> FilePath
194 inplaceInstallPath pkg
195 | pkg == touchy = inplaceLibBinPath
196 | pkg == unlit = inplaceLibBinPath
197 | pkg == iservBin = inplaceLibBinPath
198 | otherwise = inplaceBinPath
199
200 -- | @ghc-split@ is a Perl script used by GHC with @-split-objs@ flag. It is
201 -- generated in "Rules.Generators.GhcSplit".
202 ghcSplitPath :: FilePath
203 ghcSplitPath = inplaceLibBinPath -/- "ghc-split"
204
205 -- | Command line tool for stripping
206 -- ref: mk/config.mk
207 stripCmdPath :: Context -> Action FilePath
208 stripCmdPath ctx = do
209 targetPlatform <- setting TargetPlatform
210 top <- interpretInContext ctx getTopDirectory
211 case targetPlatform of
212 "x86_64-unknown-mingw32" ->
213 return (top -/- "inplace/mingw/bin/strip.exe")
214 "arm-unknown-linux" ->
215 return ":" -- HACK: from the make-based system, see the ref above
216 _ -> return "strip"