From fd31a016548c37ea36e50cf27888f3ac8b183d2d Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sun, 8 Oct 2023 16:46:35 +0100 Subject: [PATCH] Fix #9318 Avoid Haddock warning with `haddock --for-hackage` --- Cabal/src/Distribution/Simple/Haddock.hs | 42 +++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Haddock.hs b/Cabal/src/Distribution/Simple/Haddock.hs index 7476f70006c..720989bfdfc 100644 --- a/Cabal/src/Distribution/Simple/Haddock.hs +++ b/Cabal/src/Distribution/Simple/Haddock.hs @@ -866,25 +866,33 @@ renderPureArgs version comp platform args = , ["--since-qual=external" | isVersion 2 20] , [ "--quickjump" | isVersion 2 19, True <- flagToList . argQuickJump $ args ] - , [ "--hyperlinked-source" | isVersion 2 17, True <- flagToList . argLinkedSource $ args - ] + , [ "--hyperlinked-source" | isHyperlinkedSource ] , (\(All b, xs) -> bool (map (("--hide=" ++) . prettyShow) xs) [] b) . argHideModules $ args , bool ["--ignore-all-exports"] [] . getAny . argIgnoreExports $ args - , maybe - [] - ( \(m, e, l) -> - [ "--source-module=" ++ m - , "--source-entity=" ++ e - ] - ++ if isVersion 2 14 - then ["--source-entity-line=" ++ l] - else [] - ) - . flagToMaybe - . argLinkSource - $ args + -- Haddock's --source-* options are ignored once --hyperlinked-source is + -- set. + -- See https://haskell-haddock.readthedocs.io/en/latest/invoking.html#cmdoption-hyperlinked-source + -- To avoid Haddock's warning, we only set --source-* options if + -- --hyperlinked-source is not set. + , if isHyperlinkedSource + then + [] + else + maybe + [] + ( \(m, e, l) -> + [ "--source-module=" ++ m + , "--source-entity=" ++ e + ] + ++ if isVersion 2 14 + then ["--source-entity-line=" ++ l] + else [] + ) + . flagToMaybe + . argLinkSource + $ args , maybe [] ((: []) . ("--css=" ++)) . flagToMaybe . argCssFile $ args , maybe [] ((: []) . ("--use-contents=" ++)) . flagToMaybe . argContents $ args , bool ["--gen-contents"] [] . fromFlagOrDefault False . argGenContents $ args @@ -965,6 +973,10 @@ renderPureArgs version comp platform args = | otherwise = "--verbose" haddockSupportsVisibility = version >= mkVersion [2, 26, 1] haddockSupportsPackageName = version > mkVersion [2, 16] + haddockSupportsHyperlinkedSource = isVersion 2 17 + isHyperlinkedSource = + haddockSupportsHyperlinkedSource + && fromFlagOrDefault False (argLinkedSource args) ---------------------------------------------------------------------------------