forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInLibrary.hs
More file actions
338 lines (313 loc) · 11 KB
/
Copy pathInLibrary.hs
File metadata and controls
338 lines (313 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
{-# LANGUAGE DuplicateRecordFields #-}
module Distribution.Client.InLibrary
( libraryConfigureInputsFromElabPackage
, configure
, build
, haddock
, copy
, register
, repl
, test
, bench
)
where
import Distribution.Backpack.DescribeUnitId (setupMessage')
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.RebuildMonad
import qualified Distribution.Client.SetupHooks.CallHooksExe as ExternalHooksExe
( buildTypePreBuildHooks
, buildTypeSetupHooks
)
import Distribution.Client.Types
import qualified Distribution.PackageDescription as PD
import Distribution.Simple (Compiler, PackageDBStackCWD)
import qualified Distribution.Simple.Bench as Cabal
import Distribution.Simple.Build (build_setupHooks, repl_setupHooks)
import qualified Distribution.Simple.Configure as Cabal
import Distribution.Simple.Haddock (haddock_setupHooks)
import Distribution.Simple.Install (install_setupHooks)
import Distribution.Simple.LocalBuildInfo (mbWorkDirLBI)
import qualified Distribution.Simple.PreProcess as Cabal
import Distribution.Simple.Program.Db
import qualified Distribution.Simple.Register as Cabal
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.SetupHooks.Internal
import qualified Distribution.Simple.Test as Cabal
import Distribution.Simple.Utils
import Distribution.System (Platform)
import Distribution.Types.BuildType
import Distribution.Types.ComponentRequestedSpec
import qualified Distribution.Types.LocalBuildConfig as LBC
import Distribution.Types.LocalBuildInfo
import Distribution.Utils.Path
( makeSymbolicPath
, relativeSymbolicPath
)
import Distribution.Verbosity
( VerbosityHandles
, mkVerbosity
)
import Distribution.Types.HookedBuildInfo (emptyHookedBuildInfo)
import System.Directory (canonicalizePath)
--------------------------------------------------------------------------------
-- Configure
data LibraryConfigureInputs = LibraryConfigureInputs
{ verbosityHandles :: VerbosityHandles
, compiler :: Compiler
, platform :: Platform
, buildType :: BuildType
, compRequested :: Maybe PD.ComponentName
, localBuildConfig :: LBC.LocalBuildConfig
, packageDBStack :: PackageDBStackCWD
, packageDescription :: PD.PackageDescription
, gPackageDescription :: PD.GenericPackageDescription
, flagAssignment :: PD.FlagAssignment
}
libraryConfigureInputsFromElabPackage
:: VerbosityHandles
-> BuildType
-> ProgramDb
-> ElaboratedSharedConfig
-> ElaboratedReadyPackage
-> [String]
-- ^ targets
-> LibraryConfigureInputs
libraryConfigureInputsFromElabPackage
verbHandles
bt
progDb
-- NB: don't use the ProgramDb from the ElaboratedSharedConfig;
-- that one is only for the compiler itself and not for the package.
ElaboratedSharedConfig
{ pkgConfigToolchains = toolchains
}
(ReadyPackage pkg)
userTargets =
LibraryConfigureInputs
{ verbosityHandles = verbHandles
, compiler = compil
, platform = plat
, buildType =
-- NB: don't get the build-type from 'pkgDescr',
-- because for Configure build-type we rewrite the build-type
-- to Simple for components that are neither the main library
-- nor an executable.
--
-- See also 'isMainLibOrExeComponent'.
bt
, compRequested =
case elabPkgOrComp pkg of
ElabComponent elabComp
| Just elabCompNm <- compComponentName elabComp ->
Just elabCompNm
_ -> Nothing
, localBuildConfig =
LBC.LocalBuildConfig
{ LBC.extraConfigArgs = userTargets
, LBC.withPrograms = progDb
, LBC.withBuildOptions = elabBuildOptions pkg
}
, packageDBStack = elabBuildPackageDBStack pkg
, packageDescription = pkgDescr
, gPackageDescription = gpkgDescr
, flagAssignment = elabFlagAssignment pkg
}
where
pkgDescr = elabPkgDescription pkg
gpkgDescr = elabGPkgDescription pkg
hostToolchain = getStage toolchains Host
plat = toolchainPlatform hostToolchain
compil = toolchainCompiler hostToolchain
configure
:: LibraryConfigureInputs
-> Cabal.ConfigFlags
-> IO LocalBuildInfo
configure
LibraryConfigureInputs
{ verbosityHandles = verbHandles
, platform = plat
, compiler = compil
, buildType = bt
, compRequested = mbComp
, localBuildConfig = lbc0
, packageDBStack = packageDBs
, packageDescription = pkgDescr
, gPackageDescription = gpkgDescr
, flagAssignment = flagAssgn
}
cfg = do
-- Here, we essentially want to call the Cabal library 'configure' function,
-- but skipping over all the steps we don't need such as rediscovering the
-- compiler or re-resolving the conditionals in the package, as we have done
-- all of that already.
--
-- To achieve this, we call the Cabal 'configureFinal' function which skips
-- these preparatory steps.
let verbFlags = Cabal.fromFlag $ Cabal.configVerbosity cfg
verbosity = mkVerbosity verbHandles verbFlags
mbWorkDir = Cabal.flagToMaybe $ Cabal.configWorkingDir cfg
distPref = Cabal.fromFlag $ Cabal.configDistPref cfg
confHooks =
configureHooks $
ExternalHooksExe.buildTypeSetupHooks verbosity mbWorkDir distPref bt
-- cabal-install uses paths relative to the current working directory,
-- while the Cabal library expects symbolic paths. Perform the conversion here
-- by making the paths absolute.
packageDBs' <- traverse (traverse $ fmap makeSymbolicPath . canonicalizePath) packageDBs
-- Configure package
let pkgId :: PD.PackageIdentifier
pkgId = PD.package pkgDescr
case mbComp of
Nothing -> setupMessage verbosity "Configuring" pkgId
Just cname ->
setupMessage'
verbosity
"Configuring"
pkgId
cname
(Just (Cabal.configInstantiateWith cfg))
-- TODO: we should implement recompilation checking on the level of
-- individual components, so that we only re-configure the components that
-- need reconfiguring (including running their hooks). See #11761.
lbc1 <- case preConfPackageHook confHooks of
Nothing -> return lbc0
Just hk -> Cabal.runPreConfPackageHook cfg compil plat lbc0 hk
let compRequestedSpec = case mbComp of
Just compName -> OneComponentRequestedSpec compName
Nothing ->
ComponentRequestedSpec
{ testsRequested = Cabal.fromFlag (Cabal.configTests cfg)
, benchmarksRequested = Cabal.fromFlag (Cabal.configBenchmarks cfg)
}
(_allConstraints, pkgInfo) <-
Cabal.computePackageInfo verbHandles cfg lbc1 gpkgDescr compil
-- It's OK to discard constraints here: we already have a finalized PackageDescription
-- in hand, and we are using exact UnitIds for all dependencies (this corresponds
-- to using --exact-configuration and --dependency flags with the Setup CLI).
-- Post-configure hooks & per-component configure
lbi1 <-
Cabal.configureFinal
verbHandles
confHooks
emptyHookedBuildInfo
cfg
lbc1
(gpkgDescr, pkgDescr)
flagAssgn
compRequestedSpec
compil
plat
packageDBs'
pkgInfo
-- Remember the .cabal filename if we know it.
pkgDescrFilePath <-
case Cabal.flagToMaybe $ Cabal.configCabalFilePath cfg of
Just pkgFile -> return pkgFile
Nothing -> relativeSymbolicPath <$> tryFindPackageDesc verbosity mbWorkDir
return $ lbi1{pkgDescrFile = Just pkgDescrFilePath}
--------------------------------------------------------------------------------
-- Build
build
:: VerbosityHandles
-> Cabal.BuildFlags
-> LocalBuildInfo
-> [String]
-> IO [MonitorFilePath]
build verbHandles flags lbi _args =
build_setupHooks (preBuildHook, postBuildHook) verbHandles pkgDescr lbi flags Cabal.knownSuffixHandlers
where
verb = mkVerbosity verbHandles $ Cabal.fromFlag $ Cabal.buildVerbosity flags
hooks = ExternalHooksExe.buildTypeSetupHooks verb mbWorkDir distPref bt
-- (Recall that pre-build hooks are treated specially;
-- see the 'buildTypeSetupHooks' and 'buildTypePreBuildHooks' functions.)
preBuildHook = ExternalHooksExe.buildTypePreBuildHooks verbHandles mbWorkDir distPref bt
postBuildHook
| Just postBuild <- postBuildComponentHook $ buildHooks hooks =
postBuild
| otherwise =
const $ return ()
pkgDescr = localPkgDescr lbi
bt = PD.buildType pkgDescr
mbWorkDir = mbWorkDirLBI lbi
distPref = Cabal.fromFlag $ Cabal.buildDistPref flags
--------------------------------------------------------------------------------
-- Haddock
haddock
:: VerbosityHandles
-> Cabal.HaddockFlags
-> LocalBuildInfo
-> [String]
-> IO [MonitorFilePath]
haddock verbHandles flags lbi _args =
haddock_setupHooks preBuildHook verbHandles pkgDescr lbi Cabal.knownSuffixHandlers flags
where
preBuildHook = ExternalHooksExe.buildTypePreBuildHooks verbHandles mbWorkDir distPref bt
pkgDescr = localPkgDescr lbi
bt = PD.buildType pkgDescr
mbWorkDir = mbWorkDirLBI lbi
distPref = Cabal.fromFlag $ Cabal.haddockDistPref flags
--------------------------------------------------------------------------------
-- Repl
repl
:: VerbosityHandles
-> Cabal.ReplFlags
-> LocalBuildInfo
-> [String]
-> IO [MonitorFilePath]
repl verbHandles flags lbi _args =
repl_setupHooks preBuildHook verbHandles pkgDescr lbi flags Cabal.knownSuffixHandlers []
where
preBuildHook = ExternalHooksExe.buildTypePreBuildHooks verbHandles mbWorkDir distPref bt
pkgDescr = localPkgDescr lbi
bt = PD.buildType pkgDescr
mbWorkDir = mbWorkDirLBI lbi
distPref = Cabal.fromFlag $ Cabal.replDistPref flags
--------------------------------------------------------------------------------
-- Copy
copy
:: VerbosityHandles
-> Cabal.CopyFlags
-> LocalBuildInfo
-> [String]
-> IO ()
copy verbHandles flags lbi _args =
install_setupHooks hooks verbHandles pkgDescr lbi flags
where
verb = mkVerbosity verbHandles $ Cabal.fromFlag $ Cabal.copyVerbosity flags
hooks = installHooks $ ExternalHooksExe.buildTypeSetupHooks verb mbWorkDir distPref bt
pkgDescr = localPkgDescr lbi
bt = PD.buildType pkgDescr
mbWorkDir = mbWorkDirLBI lbi
distPref = Cabal.fromFlag $ Cabal.copyDistPref flags
--------------------------------------------------------------------------------
-- Test, bench, register.
--
-- NB: no hooks into these phases.
test
:: VerbosityHandles
-> Cabal.TestFlags
-> LocalBuildInfo
-> [String]
-> IO ()
test verb flags lbi args =
Cabal.test args verb pkgDescr lbi flags
where
pkgDescr = localPkgDescr lbi
bench
:: VerbosityHandles
-> Cabal.BenchmarkFlags
-> LocalBuildInfo
-> [String]
-> IO ()
bench verb flags lbi args =
Cabal.bench args verb pkgDescr lbi flags
where
pkgDescr = localPkgDescr lbi
register
:: Cabal.RegisterFlags
-> LocalBuildInfo
-> [String]
-> IO ()
register flags lbi _args = Cabal.register pkgDescr lbi flags
where
pkgDescr = localPkgDescr lbi