41
41
module Distribution.Simple.GHC
42
42
( getGhcInfo
43
43
, configure
44
+ , configureCompiler
45
+ , compilerProgramDb
44
46
, getInstalledPackages
45
47
, getInstalledPackagesMonitorFiles
46
48
, getPackageDBContents
@@ -124,6 +126,7 @@ import Distribution.Utils.Path
124
126
import Distribution.Verbosity
125
127
import Distribution.Version
126
128
import Language.Haskell.Extension
129
+ import Data.Maybe (fromJust )
127
130
import System.FilePath
128
131
( isRelative
129
132
, takeDirectory
@@ -153,20 +156,33 @@ import Distribution.Simple.Setup.Build
153
156
-- -----------------------------------------------------------------------------
154
157
-- Configuring
155
158
159
+ -- | Configure GHC, and then auxiliary programs such as @ghc-pkg@, @haddock@
160
+ -- as well as toolchain programs such as @ar@, @ld.
156
161
configure
157
162
:: Verbosity
158
- -> Maybe FilePath
159
- -> Maybe FilePath
163
+ -> Maybe FilePath -- ^ user-specified @ghc@ path (optional)
164
+ -> Maybe FilePath -- ^ user-specified @ghc-pkg@ path (optional)
160
165
-> ProgramDb
161
166
-> IO (Compiler , Maybe Platform , ProgramDb )
162
167
configure verbosity hcPath hcPkgPath conf0 = do
168
+ (comp, compPlatform, progdb1) <- configureCompiler verbosity hcPath conf0
169
+ compProgDb <- compilerProgramDb verbosity comp progdb1 hcPkgPath
170
+ return (comp, compPlatform, compProgDb)
171
+
172
+ -- | Configure GHC.
173
+ configureCompiler
174
+ :: Verbosity
175
+ -> Maybe FilePath -- ^ user-specified @ghc@ path (optional)
176
+ -> ProgramDb
177
+ -> IO (Compiler , Maybe Platform , ProgramDb )
178
+ configureCompiler verbosity hcPath conf0 = do
179
+
163
180
(ghcProg, ghcVersion, progdb1) <-
164
181
requireProgramVersion
165
182
verbosity
166
183
ghcProgram
167
184
(orLaterVersion (mkVersion [7 , 0 , 1 ]))
168
185
(userMaybeSpecifyPath " ghc" hcPath conf0)
169
- let implInfo = ghcVersionImplInfo ghcVersion
170
186
171
187
-- Cabal currently supports GHC less than `maxGhcVersion`
172
188
let maxGhcVersion = mkVersion [9 , 14 ]
@@ -182,48 +198,12 @@ configure verbosity hcPath hcPkgPath conf0 = do
182
198
++ " is version "
183
199
++ prettyShow ghcVersion
184
200
185
- -- This is slightly tricky, we have to configure ghc first, then we use the
186
- -- location of ghc to help find ghc-pkg in the case that the user did not
187
- -- specify the location of ghc-pkg directly:
188
- (ghcPkgProg, ghcPkgVersion, progdb2) <-
189
- requireProgramVersion
190
- verbosity
191
- ghcPkgProgram
192
- { programFindLocation = guessGhcPkgFromGhcPath ghcProg
193
- }
194
- anyVersion
195
- (userMaybeSpecifyPath " ghc-pkg" hcPkgPath progdb1)
196
-
197
- when (ghcVersion /= ghcPkgVersion) $
198
- dieWithException verbosity $
199
- VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
200
- -- Likewise we try to find the matching hsc2hs and haddock programs.
201
- let hsc2hsProgram' =
202
- hsc2hsProgram
203
- { programFindLocation = guessHsc2hsFromGhcPath ghcProg
204
- }
205
- haddockProgram' =
206
- haddockProgram
207
- { programFindLocation = guessHaddockFromGhcPath ghcProg
208
- }
209
- hpcProgram' =
210
- hpcProgram
211
- { programFindLocation = guessHpcFromGhcPath ghcProg
212
- }
213
- runghcProgram' =
214
- runghcProgram
215
- { programFindLocation = guessRunghcFromGhcPath ghcProg
216
- }
217
- progdb3 =
218
- addKnownProgram haddockProgram' $
219
- addKnownProgram hsc2hsProgram' $
220
- addKnownProgram hpcProgram' $
221
- addKnownProgram runghcProgram' progdb2
222
-
201
+ let implInfo = ghcVersionImplInfo ghcVersion
223
202
languages <- Internal. getLanguages verbosity implInfo ghcProg
224
203
extensions0 <- Internal. getExtensions verbosity implInfo ghcProg
225
204
226
205
ghcInfo <- Internal. getGhcInfo verbosity implInfo ghcProg
206
+
227
207
let ghcInfoMap = Map. fromList ghcInfo
228
208
filterJS = if ghcVersion < mkVersion [9 , 8 ] then filterExt JavaScriptFFI else id
229
209
extensions =
@@ -249,7 +229,10 @@ configure verbosity hcPath hcPkgPath conf0 = do
249
229
compilerId = CompilerId GHC ghcVersion
250
230
251
231
compilerAbiTag :: AbiTag
252
- compilerAbiTag = maybe NoAbiTag AbiTag (Map. lookup " Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> " -" ))
232
+ compilerAbiTag =
233
+ maybe NoAbiTag AbiTag
234
+ (Map. lookup " Project Unit Id" ghcInfoMap
235
+ >>= stripPrefix (prettyShow compilerId <> " -" ))
253
236
254
237
let comp =
255
238
Compiler
@@ -261,9 +244,73 @@ configure verbosity hcPath hcPkgPath conf0 = do
261
244
, compilerProperties = ghcInfoMap
262
245
}
263
246
compPlatform = Internal. targetPlatform ghcInfo
264
- -- configure gcc and ld
265
- progdb4 = Internal. configureToolchain implInfo ghcProg ghcInfoMap progdb3
266
- return (comp, compPlatform, progdb4)
247
+ return (comp, compPlatform, progdb1)
248
+
249
+ -- | Given a configured @ghc@ program, configure auxiliary programs such
250
+ -- as @ghc-pkg@ or @haddock@, as well as toolchain programs such as @ar@, @ld@,
251
+ -- based on:
252
+ --
253
+ -- - the location of the @ghc@ executable,
254
+ -- - toolchain information in the GHC settings file.
255
+ compilerProgramDb
256
+ :: Verbosity
257
+ -> Compiler
258
+ -> ProgramDb
259
+ -> Maybe FilePath -- ^ user-specified @ghc-pkg@ path (optional)
260
+ -> IO ProgramDb
261
+ compilerProgramDb verbosity comp progdb1 hcPkgPath = do
262
+
263
+ let
264
+ ghcProg = fromJust $ lookupProgram ghcProgram progdb1
265
+ ghcVersion = compilerVersion comp
266
+
267
+ -- This is slightly tricky, we have to configure ghc first, then we use the
268
+ -- location of ghc to help find ghc-pkg in the case that the user did not
269
+ -- specify the location of ghc-pkg directly:
270
+ (ghcPkgProg, ghcPkgVersion, progdb2) <-
271
+ requireProgramVersion
272
+ verbosity
273
+ ghcPkgProgram
274
+ { programFindLocation = guessGhcPkgFromGhcPath ghcProg
275
+ }
276
+ anyVersion
277
+ (userMaybeSpecifyPath " ghc-pkg" hcPkgPath progdb1)
278
+
279
+ when (ghcVersion /= ghcPkgVersion) $
280
+ dieWithException verbosity $
281
+ VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
282
+ -- Likewise we try to find the matching hsc2hs and haddock programs.
283
+ let hsc2hsProgram' =
284
+ hsc2hsProgram
285
+ { programFindLocation = guessHsc2hsFromGhcPath ghcProg
286
+ }
287
+ haddockProgram' =
288
+ haddockProgram
289
+ { programFindLocation = guessHaddockFromGhcPath ghcProg
290
+ }
291
+ hpcProgram' =
292
+ hpcProgram
293
+ { programFindLocation = guessHpcFromGhcPath ghcProg
294
+ }
295
+ runghcProgram' =
296
+ runghcProgram
297
+ { programFindLocation = guessRunghcFromGhcPath ghcProg
298
+ }
299
+ progdb3 =
300
+ addKnownProgram haddockProgram' $
301
+ addKnownProgram hsc2hsProgram' $
302
+ addKnownProgram hpcProgram' $
303
+ addKnownProgram runghcProgram' progdb2
304
+
305
+ -- configure gcc, ld, ar etc... based on the paths stored
306
+ -- in the GHC settings file
307
+ progdb4 =
308
+ Internal. configureToolchain
309
+ (ghcVersionImplInfo ghcVersion)
310
+ ghcProg
311
+ (compilerProperties comp)
312
+ progdb3
313
+ return progdb4
267
314
268
315
-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
269
316
-- the corresponding tool; e.g. if the tool is ghc-pkg, we try looking
0 commit comments