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