Skip to content

Commit 68fcd33

Browse files
alt-romesMikolaj
authored andcommitted
haddock: Pass --no-tmp-comp-dir by default
With "Hi Haddock", we want to re-use GHC's compilation output (in particular, the generated interface files) to generate documentation from. However, haddock by default will use a temporary location to build sources, and will therefore fail to find the interface files produced by GHC. To avoid recompilation, we need to instruct Cabal to pass --no-tmp-comp-dir to Haddock so as to not use a temporary directory and thus re-use existing interface files.
1 parent 144383e commit 68fcd33

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Cabal/src/Distribution/Simple/Haddock.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ haddock_setupHooks
326326
[] -> allTargetsInBuildOrder' pkg_descr lbi
327327
_ -> targets
328328

329+
-- See Note [Hi Haddock Recompilation Avoidance]
329330
mtmp
330331
| version >= mkVersion [2, 28, 0] = const Nothing
331332
| otherwise = Just
@@ -593,6 +594,17 @@ componentGhcOptions verbosity lbi bi clbi odir =
593594
++ "haddock only supports GHC and GHCJS"
594595
in f verbosity lbi bi clbi odir
595596

597+
{-
598+
Note [Hi Haddock Recompilation Avoidance]
599+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
600+
Starting with Haddock 2.28, we no longer want to run Haddock's
601+
GHC session in a temporary directory. Doing so always causes
602+
recompilation during documentation generation, which can now be
603+
avoided thanks to Hi Haddock.
604+
605+
See https://github.com/haskell/cabal/pull/9177 for discussion.
606+
-}
607+
596608
mkHaddockArgs
597609
:: Verbosity
598610
-> Maybe (SymbolicPath Pkg (Path.Dir Tmp))
@@ -611,11 +623,7 @@ mkHaddockArgs verbosity mtmp lbi clbi htmlTemplate inFiles bi = do
611623
componentGhcOptions normal lbi bi clbi (buildDir lbi)
612624
vanillaOpts =
613625
vanillaOpts'
614-
{ -- Starting with Haddock 2.28, we no longer want to run Haddock's
615-
-- GHC session in a temporary directory. Doing so always causes
616-
-- recompilation during documentation generation, which can now be
617-
-- avoided thanks to Hi Haddock. See
618-
-- https://github.com/haskell/cabal/pull/9177 for discussion.
626+
{ -- See Note [Hi Haddock Recompilation Avoidance]
619627
ghcOptObjDir = maybe (ghcOptObjDir vanillaOpts') (toFlag . coerceSymbolicPath) mtmp
620628
, ghcOptHiDir = maybe (ghcOptHiDir vanillaOpts') (toFlag . coerceSymbolicPath) mtmp
621629
, ghcOptStubDir = maybe (ghcOptStubDir vanillaOpts') (toFlag . coerceSymbolicPath) mtmp
@@ -973,6 +981,10 @@ renderPureArgs version comp platform args =
973981
]
974982
, argTargets $ args
975983
, maybe [] ((: []) . (resourcesDirFlag ++)) . flagToMaybe . argResourcesDir $ args
984+
-- Do not re-direct compilation output to a temporary directory (--no-tmp-comp-dir)
985+
-- We pass this option by default to haddock to avoid recompilation
986+
-- See Note [Hi Haddock Recompilation Avoidance]
987+
, [ "--no-tmp-comp-dir" | version >= mkVersion [2, 28, 0] ]
976988
]
977989
where
978990
-- See Note [Symbolic paths] in Distribution.Utils.Path

0 commit comments

Comments
 (0)