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
@@ -86,6 +88,7 @@ import Prelude ()
86
88
import Control.Arrow ((***) )
87
89
import Control.Monad (forM_ )
88
90
import qualified Data.Map as Map
91
+ import Data.Maybe (fromJust )
89
92
import Distribution.CabalSpecVersion
90
93
import Distribution.InstalledPackageInfo (InstalledPackageInfo )
91
94
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
@@ -152,20 +155,35 @@ import Distribution.Simple.Setup.Build
152
155
-- -----------------------------------------------------------------------------
153
156
-- Configuring
154
157
158
+ -- | Configure GHC, and then auxiliary programs such as @ghc-pkg@, @haddock@
159
+ -- as well as toolchain programs such as @ar@, @ld.
155
160
configure
156
161
:: Verbosity
157
162
-> Maybe FilePath
163
+ -- ^ user-specified @ghc@ path (optional)
158
164
-> Maybe FilePath
165
+ -- ^ user-specified @ghc-pkg@ path (optional)
159
166
-> ProgramDb
160
167
-> IO (Compiler , Maybe Platform , ProgramDb )
161
168
configure verbosity hcPath hcPkgPath conf0 = do
169
+ (comp, compPlatform, progdb1) <- configureCompiler verbosity hcPath conf0
170
+ compProgDb <- compilerProgramDb verbosity comp progdb1 hcPkgPath
171
+ return (comp, compPlatform, compProgDb)
172
+
173
+ -- | Configure GHC.
174
+ configureCompiler
175
+ :: Verbosity
176
+ -> Maybe FilePath
177
+ -- ^ user-specified @ghc@ path (optional)
178
+ -> ProgramDb
179
+ -> IO (Compiler , Maybe Platform , ProgramDb )
180
+ configureCompiler verbosity hcPath conf0 = do
162
181
(ghcProg, ghcVersion, progdb1) <-
163
182
requireProgramVersion
164
183
verbosity
165
184
ghcProgram
166
185
(orLaterVersion (mkVersion [7 , 0 , 1 ]))
167
186
(userMaybeSpecifyPath " ghc" hcPath conf0)
168
- let implInfo = ghcVersionImplInfo ghcVersion
169
187
170
188
-- Cabal currently supports GHC less than `maxGhcVersion`
171
189
let maxGhcVersion = mkVersion [9 , 14 ]
@@ -181,48 +199,12 @@ configure verbosity hcPath hcPkgPath conf0 = do
181
199
++ " is version "
182
200
++ prettyShow ghcVersion
183
201
184
- -- This is slightly tricky, we have to configure ghc first, then we use the
185
- -- location of ghc to help find ghc-pkg in the case that the user did not
186
- -- specify the location of ghc-pkg directly:
187
- (ghcPkgProg, ghcPkgVersion, progdb2) <-
188
- requireProgramVersion
189
- verbosity
190
- ghcPkgProgram
191
- { programFindLocation = guessGhcPkgFromGhcPath ghcProg
192
- }
193
- anyVersion
194
- (userMaybeSpecifyPath " ghc-pkg" hcPkgPath progdb1)
195
-
196
- when (ghcVersion /= ghcPkgVersion) $
197
- dieWithException verbosity $
198
- VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
199
- -- Likewise we try to find the matching hsc2hs and haddock programs.
200
- let hsc2hsProgram' =
201
- hsc2hsProgram
202
- { programFindLocation = guessHsc2hsFromGhcPath ghcProg
203
- }
204
- haddockProgram' =
205
- haddockProgram
206
- { programFindLocation = guessHaddockFromGhcPath ghcProg
207
- }
208
- hpcProgram' =
209
- hpcProgram
210
- { programFindLocation = guessHpcFromGhcPath ghcProg
211
- }
212
- runghcProgram' =
213
- runghcProgram
214
- { programFindLocation = guessRunghcFromGhcPath ghcProg
215
- }
216
- progdb3 =
217
- addKnownProgram haddockProgram' $
218
- addKnownProgram hsc2hsProgram' $
219
- addKnownProgram hpcProgram' $
220
- addKnownProgram runghcProgram' progdb2
221
-
202
+ let implInfo = ghcVersionImplInfo ghcVersion
222
203
languages <- Internal. getLanguages verbosity implInfo ghcProg
223
204
extensions0 <- Internal. getExtensions verbosity implInfo ghcProg
224
205
225
206
ghcInfo <- Internal. getGhcInfo verbosity implInfo ghcProg
207
+
226
208
let ghcInfoMap = Map. fromList ghcInfo
227
209
filterJS = if ghcVersion < mkVersion [9 , 8 ] then filterExt JavaScriptFFI else id
228
210
extensions =
@@ -254,7 +236,13 @@ configure verbosity hcPath hcPkgPath conf0 = do
254
236
-- So, we need to be careful to only strip the /common/ prefix.
255
237
-- In this example, @AbiTag@ is "inplace".
256
238
compilerAbiTag :: AbiTag
257
- compilerAbiTag = maybe NoAbiTag AbiTag (dropWhile (== ' -' ) . stripCommonPrefix (prettyShow compilerId) <$> Map. lookup " Project Unit Id" ghcInfoMap)
239
+ compilerAbiTag =
240
+ maybe
241
+ NoAbiTag
242
+ AbiTag
243
+ ( dropWhile (== ' -' ) . stripCommonPrefix (prettyShow compilerId)
244
+ <$> Map. lookup " Project Unit Id" ghcInfoMap
245
+ )
258
246
259
247
let comp =
260
248
Compiler
@@ -266,9 +254,73 @@ configure verbosity hcPath hcPkgPath conf0 = do
266
254
, compilerProperties = ghcInfoMap
267
255
}
268
256
compPlatform = Internal. targetPlatform ghcInfo
269
- -- configure gcc and ld
270
- progdb4 = Internal. configureToolchain implInfo ghcProg ghcInfoMap progdb3
271
- return (comp, compPlatform, progdb4)
257
+ return (comp, compPlatform, progdb1)
258
+
259
+ -- | Given a configured @ghc@ program, configure auxiliary programs such
260
+ -- as @ghc-pkg@ or @haddock@, as well as toolchain programs such as @ar@, @ld@,
261
+ -- based on:
262
+ --
263
+ -- - the location of the @ghc@ executable,
264
+ -- - toolchain information in the GHC settings file.
265
+ compilerProgramDb
266
+ :: Verbosity
267
+ -> Compiler
268
+ -> ProgramDb
269
+ -> Maybe FilePath
270
+ -- ^ user-specified @ghc-pkg@ path (optional)
271
+ -> IO ProgramDb
272
+ compilerProgramDb verbosity comp progdb1 hcPkgPath = do
273
+ let
274
+ ghcProg = fromJust $ lookupProgram ghcProgram progdb1
275
+ ghcVersion = compilerVersion comp
276
+
277
+ -- This is slightly tricky, we have to configure ghc first, then we use the
278
+ -- location of ghc to help find ghc-pkg in the case that the user did not
279
+ -- specify the location of ghc-pkg directly:
280
+ (ghcPkgProg, ghcPkgVersion, progdb2) <-
281
+ requireProgramVersion
282
+ verbosity
283
+ ghcPkgProgram
284
+ { programFindLocation = guessGhcPkgFromGhcPath ghcProg
285
+ }
286
+ anyVersion
287
+ (userMaybeSpecifyPath " ghc-pkg" hcPkgPath progdb1)
288
+
289
+ when (ghcVersion /= ghcPkgVersion) $
290
+ dieWithException verbosity $
291
+ VersionMismatchGHC (programPath ghcProg) ghcVersion (programPath ghcPkgProg) ghcPkgVersion
292
+ -- Likewise we try to find the matching hsc2hs and haddock programs.
293
+ let hsc2hsProgram' =
294
+ hsc2hsProgram
295
+ { programFindLocation = guessHsc2hsFromGhcPath ghcProg
296
+ }
297
+ haddockProgram' =
298
+ haddockProgram
299
+ { programFindLocation = guessHaddockFromGhcPath ghcProg
300
+ }
301
+ hpcProgram' =
302
+ hpcProgram
303
+ { programFindLocation = guessHpcFromGhcPath ghcProg
304
+ }
305
+ runghcProgram' =
306
+ runghcProgram
307
+ { programFindLocation = guessRunghcFromGhcPath ghcProg
308
+ }
309
+ progdb3 =
310
+ addKnownProgram haddockProgram' $
311
+ addKnownProgram hsc2hsProgram' $
312
+ addKnownProgram hpcProgram' $
313
+ addKnownProgram runghcProgram' progdb2
314
+
315
+ -- configure gcc, ld, ar etc... based on the paths stored
316
+ -- in the GHC settings file
317
+ progdb4 =
318
+ Internal. configureToolchain
319
+ (ghcVersionImplInfo ghcVersion)
320
+ ghcProg
321
+ (compilerProperties comp)
322
+ progdb3
323
+ return progdb4
272
324
273
325
-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
274
326
-- the corresponding tool; e.g. if the tool is ghc-pkg, we try looking
0 commit comments