Skip to content

Commit ec73ba9

Browse files
cootmergify[bot]
authored andcommitted
Build dependencies with haddock-project
`haddock-project` command need to build the project so that haddocks of the dependencies are available in the store. Fixes #8958. (cherry picked from commit 2c597e8) # Conflicts: # cabal-install/src/Distribution/Client/CmdHaddockProject.hs
1 parent ef0abf0 commit ec73ba9

File tree

1 file changed

+107
-3
lines changed

1 file changed

+107
-3
lines changed

cabal-install/src/Distribution/Client/CmdHaddockProject.hs

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ haddockProjectAction flags _extraArgs globalFlags = do
217217
, haddockOutputDir = haddockProjectOutputDir flags
218218
>>>>>>> 1b89c1bf5 (Removed some haddock-project options)
219219
}
220+
<<<<<<< HEAD
220221
nixFlags = (commandDefaultFlags CmdHaddock.haddockCommand)
221222
{ NixStyleOptions.haddockFlags = haddockFlags
222223
, NixStyleOptions.configFlags =
@@ -227,6 +228,95 @@ haddockProjectAction flags _extraArgs globalFlags = do
227228
--
228229
-- Construct the build plan and infer the list of packages which haddocks
229230
-- we need.
231+
=======
232+
nixFlags =
233+
(commandDefaultFlags CmdHaddock.haddockCommand)
234+
{ NixStyleOptions.haddockFlags = haddockFlags
235+
, NixStyleOptions.configFlags =
236+
(NixStyleOptions.configFlags (commandDefaultFlags CmdBuild.buildCommand))
237+
{ configVerbosity = haddockProjectVerbosity flags
238+
}
239+
}
240+
241+
--
242+
-- Construct the build plan and infer the list of packages which haddocks
243+
-- we need.
244+
--
245+
246+
withContextAndSelectors RejectNoTargets Nothing
247+
(commandDefaultFlags CmdBuild.buildCommand)
248+
["all"] globalFlags HaddockCommand
249+
$ \targetCtx ctx targetSelectors -> do
250+
baseCtx <- case targetCtx of
251+
ProjectContext -> return ctx
252+
GlobalContext -> return ctx
253+
ScriptContext path exemeta -> updateContextAndWriteProjectFile ctx path exemeta
254+
let distLayout = distDirLayout baseCtx
255+
cabalLayout = cabalDirLayout baseCtx
256+
buildCtx <-
257+
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
258+
-- Interpret the targets on the command line as build targets
259+
-- (as opposed to say repl or haddock targets).
260+
targets <-
261+
either reportTargetProblems return $
262+
resolveTargets
263+
selectPackageTargets
264+
selectComponentTargetBasic
265+
elaboratedPlan
266+
Nothing
267+
targetSelectors
268+
269+
let elaboratedPlan' =
270+
pruneInstallPlanToTargets
271+
TargetActionBuild
272+
targets
273+
elaboratedPlan
274+
return (elaboratedPlan', targets)
275+
276+
printPlan verbosity baseCtx buildCtx
277+
278+
let elaboratedPlan :: ElaboratedInstallPlan
279+
elaboratedPlan = elaboratedPlanOriginal buildCtx
280+
281+
sharedConfig :: ElaboratedSharedConfig
282+
sharedConfig = elaboratedShared buildCtx
283+
284+
pkgs :: [Either InstalledPackageInfo ElaboratedConfiguredPackage]
285+
pkgs = matchingPackages elaboratedPlan
286+
287+
progs <-
288+
reconfigurePrograms
289+
verbosity
290+
(haddockProjectProgramPaths flags)
291+
(haddockProjectProgramArgs flags)
292+
-- we need to insert 'haddockProgram' before we reconfigure it,
293+
-- otherwise 'set
294+
. addKnownProgram haddockProgram
295+
. pkgConfigCompilerProgs
296+
$ sharedConfig
297+
let sharedConfig' = sharedConfig{pkgConfigCompilerProgs = progs}
298+
299+
_ <-
300+
requireProgramVersion
301+
verbosity
302+
haddockProgram
303+
(orLaterVersion (mkVersion [2, 26, 1]))
304+
progs
305+
306+
--
307+
-- Build project; we need to build dependencies.
308+
-- Issue #8958.
309+
--
310+
311+
when localStyle $
312+
CmdBuild.buildAction
313+
(commandDefaultFlags CmdBuild.buildCommand)
314+
["all"]
315+
globalFlags
316+
317+
--
318+
-- Build haddocks of each components
319+
>>>>>>> 2c597e8c9 (Build dependencies with haddock-project)
230320
--
231321

232322
withContextAndSelectors RejectNoTargets Nothing nixFlags ["all"] globalFlags HaddockCommand $ \targetCtx ctx targetSelectors -> do
@@ -317,8 +407,8 @@ haddockProjectAction flags _extraArgs globalFlags = do
317407
| not localStyle ->
318408
return []
319409
Left package -> do
320-
-- TODO: this might not work for public packages with sublibraries
321-
-- (which will be visible if one is using `--local` switch).
410+
-- TODO: this might not work for public packages with sublibraries.
411+
-- Issue #9026.
322412
let packageName = unPackageName (pkgName $ sourcePackageId package)
323413
destDir = outputDir </> packageName
324414
fmap catMaybes $ for (haddockInterfaces package) $ \interfacePath -> do
@@ -363,7 +453,12 @@ haddockProjectAction flags _extraArgs globalFlags = do
363453
, Visible
364454
)
365455
]
366-
False -> return []
456+
False -> do
457+
warn verbosity
458+
("haddocks of "
459+
++ show unitId
460+
++ " not found in the store")
461+
return []
367462
False
368463
| not localStyle ->
369464
return []
@@ -394,8 +489,17 @@ haddockProjectAction flags _extraArgs globalFlags = do
394489
, Hidden
395490
)
396491
]
492+
<<<<<<< HEAD
397493
False -> return []
398494
>>>>>>> 1840bca4b (haddock-project: use UnitId instead of package names)
495+
=======
496+
False -> do
497+
warn verbosity
498+
("haddocks of "
499+
++ show unitId
500+
++ " not found in the store")
501+
return []
502+
>>>>>>> 2c597e8c9 (Build dependencies with haddock-project)
399503

400504
Right package ->
401505
case elabLocalToProject package of

0 commit comments

Comments
 (0)