Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,13 @@ hPutCallStackPrefix h verbosity = withFrozenCallStack $ do
-- produce the desired output.
--
-- Like 'die', these messages are always displayed on @stderr@, irrespective
-- of the 'Verbosity' level.
-- of the 'Verbosity' level. The 'Verbosity' parameter is needed though to
-- decide how to format the output (e.g. line-wrapping).
--
dieMsg :: String -> NoCallStackIO ()
dieMsg msg = do
dieMsg :: Verbosity -> String -> NoCallStackIO ()
dieMsg verbosity msg = do
hFlush stdout
hPutStr stderr (wrapText msg)
hPutStr stderr (wrapTextVerbosity verbosity msg)

-- | As 'dieMsg' but with pre-formatted text.
--
Expand All @@ -349,7 +350,7 @@ warn verbosity msg = withFrozenCallStack $ do
when (verbosity >= normal) $ do
hFlush stdout
hPutCallStackPrefix stderr verbosity
hPutStr stderr (wrapText ("Warning: " ++ msg))
hPutStr stderr (wrapTextVerbosity verbosity ("Warning: " ++ msg))

-- | Useful status messages.
--
Expand All @@ -362,7 +363,7 @@ notice :: Verbosity -> String -> IO ()
notice verbosity msg = withFrozenCallStack $ do
when (verbosity >= normal) $ do
hPutCallStackPrefix stdout verbosity
putStr (wrapText msg)
putStr (wrapTextVerbosity verbosity msg)

noticeNoWrap :: Verbosity -> String -> IO ()
noticeNoWrap verbosity msg = withFrozenCallStack $ do
Expand All @@ -382,7 +383,7 @@ info :: Verbosity -> String -> IO ()
info verbosity msg = withFrozenCallStack $
when (verbosity >= verbose) $ do
hPutCallStackPrefix stdout verbosity
putStr (wrapText msg)
putStr (wrapTextVerbosity verbosity msg)

-- | Detailed internal debugging information
--
Expand All @@ -392,7 +393,7 @@ debug :: Verbosity -> String -> IO ()
debug verbosity msg = withFrozenCallStack $
when (verbosity >= deafening) $ do
hPutCallStackPrefix stdout verbosity
putStr (wrapText msg)
putStr (wrapTextVerbosity verbosity msg)
hFlush stdout

-- | A variant of 'debug' that doesn't perform the automatic line
Expand Down Expand Up @@ -433,6 +434,12 @@ wrapText = unlines
. words)
. lines

-- | Wraps text unless the @+nowrap@ verbosity flag is active
wrapTextVerbosity :: Verbosity -> String -> String
wrapTextVerbosity verb
| isVerboseNoWrap verb = unlines . lines -- makes sure there's a trailing LF
| otherwise = wrapText

-- | Wraps a list of words to a list of lines of words of a particular width.
wrapLine :: Int -> [String] -> [[String]]
wrapLine width = wrap 0 []
Expand Down
13 changes: 13 additions & 0 deletions Cabal/Distribution/Verbosity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module Distribution.Verbosity (
-- * Call stacks
verboseCallSite, verboseCallStack,
isVerboseCallSite, isVerboseCallStack,

-- * line-wrapping
verboseNoWrap, isVerboseNoWrap,
) where

import Prelude ()
Expand Down Expand Up @@ -140,6 +143,7 @@ parseVerbosity = parseIntVerbosity <++ parseStringVerbosity
parseExtra = char '+' >> choice
[ string "callsite" >> return verboseCallSite
, string "callstack" >> return verboseCallStack
, string "nowrap" >> return verboseNoWrap
]

flagToVerbosity :: ReadE Verbosity
Expand All @@ -164,6 +168,7 @@ showForGHC v = maybe (error "unknown verbosity") show $
data VerbosityFlag
= VCallStack
| VCallSite
| VNoWrap
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)

instance Binary VerbosityFlag
Expand All @@ -183,3 +188,11 @@ isVerboseCallSite = (Set.member VCallSite) . vFlags
-- | Test if we should output call stacks when we log.
isVerboseCallStack :: Verbosity -> Bool
isVerboseCallStack = (Set.member VCallStack) . vFlags

-- | Disable line-wrapping for log messages.
verboseNoWrap :: Verbosity -> Verbosity
verboseNoWrap v = v { vFlags = Set.insert VNoWrap (vFlags v) }

-- | Test if line-wrapping is disabled for log messages.
isVerboseNoWrap :: Verbosity -> Bool
isVerboseNoWrap = (Set.member VNoWrap) . vFlags
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ dieOnBuildFailures verbosity plan buildOutcomes
| otherwise = do
-- For failures where we have a build log, print the log plus a header
sequence_
[ do dieMsg $
[ do dieMsg verbosity $
'\n' : renderFailureDetail False pkg reason
++ "\nBuild log ( " ++ logfile ++ " ):"
readFile logfile >>= dieMsgNoWrap
Expand Down