Skip to content

Commit 432c14d

Browse files
committed
Don't output haddock stdout if verbosity is silent
1 parent ee615d8 commit 432c14d

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

Cabal/Distribution/Simple/Haddock.hs

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ mkNormalizerEnv = do
411411
list_out <- liftIO $ readProcess (programPath ghc_pkg_program)
412412
["list", "--global", "--simple-output"] ""
413413
tmpDir <- liftIO $ getTemporaryDirectory
414+
haddock <- let prog = fromJust $ lookupKnownProgram "haddock" (testProgramDb env)
415+
in fmap (fst . fromJust) $ liftIO $
416+
programFindLocation prog (testVerbosity env)
417+
[ProgramSearchPathDefault]
414418
return NormalizerEnv {
415419
normalizerRoot
416420
= addTrailingPathSeparator (testSourceDir env),
@@ -423,8 +427,12 @@ mkNormalizerEnv = do
423427
normalizerKnownPackages
424428
= mapMaybe simpleParse (words list_out),
425429
normalizerPlatform
426-
= testPlatform env
430+
= testPlatform env,
431+
normalizerHaddock
432+
= haddock
427433
}
434+
where
435+
428436

429437
requireProgramM :: Program -> TestM ConfiguredProgram
430438
requireProgramM program = do

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Distribution.System
1414
import qualified Data.Foldable as F
1515

1616
import Text.Regex
17+
import Data.List
1718

1819
normalizeOutput :: NormalizerEnv -> String -> String
1920
normalizeOutput nenv =
@@ -54,18 +55,49 @@ normalizeOutput nenv =
5455
else id)
5556
-- hackage-security locks occur non-deterministically
5657
. resub "(Released|Acquired|Waiting) .*hackage-security-lock\n" ""
58+
-- Substitute the haddock binary with <HADDOCK>
59+
-- Do this before the <GHCVER> substitution
60+
. resub (posixRegexEscape (normalizerHaddock nenv)) "<HADDOCK>"
61+
. removeErrors
5762
where
5863
packageIdRegex pid =
5964
resub (posixRegexEscape (display pid) ++ "(-[A-Za-z0-9.-]+)?")
6065
(prettyShow (packageName pid) ++ "-<VERSION>")
6166

67+
{- Given
68+
cabal: blah exited with an error:
69+
Example.hs:6:11: error:
70+
* Couldn't match expected type `Int' with actual type `Bool'
71+
* In the expression: False
72+
In an equation for `example': example = False
73+
|
74+
6 | example = False
75+
| ^^^^^
76+
cabal: Failed to build documentation for example-1.0-inplace.
77+
78+
this will remove the error in between the first line with "exited with an error"
79+
and the closing "cabal:". Pretty nasty, but its needed to ignore errors from
80+
external programs whose output might change.
81+
-}
82+
removeErrors :: String -> String
83+
removeErrors s = unlines (go (lines s) False)
84+
where
85+
go [] _ = []
86+
go (x:xs) True
87+
| "cabal:" `isPrefixOf` x = x:(go xs False)
88+
| otherwise = go xs True
89+
go (x:xs) False
90+
| "exited with an error" `isInfixOf` x = x:(go xs True)
91+
| otherwise = x:(go xs False)
92+
6293
data NormalizerEnv = NormalizerEnv
6394
{ normalizerRoot :: FilePath
6495
, normalizerTmpDir :: FilePath
6596
, normalizerGblTmpDir :: FilePath
6697
, normalizerGhcVersion :: Version
6798
, normalizerKnownPackages :: [PackageId]
6899
, normalizerPlatform :: Platform
100+
, normalizerHaddock :: FilePath
69101
}
70102

71103
posixSpecialChars :: [Char]

0 commit comments

Comments
 (0)