Skip to content

Commit 0a1dec8

Browse files
committed
Don't output haddock stdout if verbosity is silent
1 parent 152cdf4 commit 0a1dec8

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-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: '<HADDOCK>' exited with an error:
1516
cabal: Failed to build documentation for example-1.0-inplace.

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ mkNormalizerEnv = do
398398
list_out <- liftIO $ readProcess (programPath ghc_pkg_program)
399399
["list", "--global", "--simple-output"] ""
400400
tmpDir <- liftIO $ getTemporaryDirectory
401+
haddock_program <- requireProgramM haddockProgram
402+
canonicalHaddockPath <- liftIO $ canonicalizePath $ programPath haddock_program
403+
401404
return NormalizerEnv {
402405
normalizerRoot
403406
= addTrailingPathSeparator (testSourceDir env),
@@ -410,8 +413,12 @@ mkNormalizerEnv = do
410413
normalizerKnownPackages
411414
= mapMaybe simpleParse (words list_out),
412415
normalizerPlatform
413-
= testPlatform env
416+
= testPlatform env,
417+
normalizerHaddock
418+
= canonicalHaddockPath
414419
}
420+
where
421+
415422

416423
requireProgramM :: Program -> TestM ConfiguredProgram
417424
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)