Skip to content

Commit 5cfdb14

Browse files
committed
Don't output haddock stdout if verbosity is silent
1 parent 3c4023f commit 5cfdb14

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

Cabal/src/Distribution/Simple/Haddock.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,9 @@ runHaddock verbosity tmpFileOpts comp platform haddockProg args
559559
renderArgs verbosity tmpFileOpts haddockVersion comp platform args $
560560
\(flags,result)-> do
561561

562-
runProgram verbosity haddockProg flags
562+
haddockOut <- getProgramOutput verbosity haddockProg flags
563+
unless (verbosity <= silent) $
564+
putStr haddockOut
563565

564566
notice verbosity $ "Documentation created: " ++ result
565567

cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.out

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ In order, the following will be built:
1212
- example-1.0 (lib) (first run)
1313
Preprocessing library for example-1.0..
1414
Running Haddock on library for example-1.0..
15+
cabal: '/home/hugin/.ghcup/ghc/<GHCVER>/bin/haddock-ghc-<GHCVER>' exited with an error:
1516
cabal: Failed to build documentation for example-1.0-inplace.

cabal-testsuite/src/Test/Cabal/Monad.hs

+9-1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ mkNormalizerEnv = do
398398
list_out <- liftIO $ readProcess (programPath ghc_pkg_program)
399399
["list", "--global", "--simple-output"] ""
400400
tmpDir <- liftIO $ getTemporaryDirectory
401+
haddock <- let prog = fromJust $ lookupKnownProgram "haddock" (testProgramDb env)
402+
in fmap (fst . fromJust) $ liftIO $
403+
programFindLocation prog (testVerbosity env)
404+
[ProgramSearchPathDefault]
401405
return NormalizerEnv {
402406
normalizerRoot
403407
= addTrailingPathSeparator (testSourceDir env),
@@ -410,8 +414,12 @@ mkNormalizerEnv = do
410414
normalizerKnownPackages
411415
= mapMaybe simpleParse (words list_out),
412416
normalizerPlatform
413-
= testPlatform env
417+
= testPlatform env,
418+
normalizerHaddock
419+
= haddock
414420
}
421+
where
422+
415423

416424
requireProgramM :: Program -> TestM ConfiguredProgram
417425
requireProgramM program = do

cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs

+32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Distribution.System
1414
import Text.Regex.Base
1515
import Text.Regex.TDFA
1616
import Data.Array ((!))
17+
import Data.List (isPrefixOf, isInfixOf)
1718

1819
import qualified Data.Foldable as F
1920

@@ -62,18 +63,49 @@ normalizeOutput nenv =
6263
else id)
6364
-- hackage-security locks occur non-deterministically
6465
. resub "(Released|Acquired|Waiting) .*hackage-security-lock\n" ""
66+
-- Substitute the haddock binary with <HADDOCK>
67+
-- Do this before the <GHCVER> substitution
68+
. resub (posixRegexEscape (normalizerHaddock nenv)) "<HADDOCK>"
69+
. removeErrors
6570
where
6671
packageIdRegex pid =
6772
resub (posixRegexEscape (display pid) ++ "(-[A-Za-z0-9.-]+)?")
6873
(prettyShow (packageName pid) ++ "-<VERSION>")
6974

75+
{- Given
76+
cabal: blah exited with an error:
77+
Example.hs:6:11: error:
78+
* Couldn't match expected type `Int' with actual type `Bool'
79+
* In the expression: False
80+
In an equation for `example': example = False
81+
|
82+
6 | example = False
83+
| ^^^^^
84+
cabal: Failed to build documentation for example-1.0-inplace.
85+
86+
this will remove the error in between the first line with "exited with an error"
87+
and the closing "cabal:". Pretty nasty, but its needed to ignore errors from
88+
external programs whose output might change.
89+
-}
90+
removeErrors :: String -> String
91+
removeErrors s = unlines (go (lines s) False)
92+
where
93+
go [] _ = []
94+
go (x:xs) True
95+
| "cabal:" `isPrefixOf` x = x:(go xs False)
96+
| otherwise = go xs True
97+
go (x:xs) False
98+
| "exited with an error" `isInfixOf` x = x:(go xs True)
99+
| otherwise = x:(go xs False)
100+
70101
data NormalizerEnv = NormalizerEnv
71102
{ normalizerRoot :: FilePath
72103
, normalizerTmpDir :: FilePath
73104
, normalizerGblTmpDir :: FilePath
74105
, normalizerGhcVersion :: Version
75106
, normalizerKnownPackages :: [PackageId]
76107
, normalizerPlatform :: Platform
108+
, normalizerHaddock :: FilePath
77109
}
78110

79111
posixSpecialChars :: [Char]

changelog.d/pr-7483

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
synopsis: Don't output haddock stdout if verbosity is silent
2+
packages: Cabal
3+
prs: #7483
4+
5+
description: {
6+
7+
- Silence the output of the Haddock executable if verbosity 'silent' is set.
8+
- Hide output of 'stderr' if Haddock succeeded.
9+
}

0 commit comments

Comments
 (0)