Skip to content

Commit

Permalink
Suppress warnings for verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkato committed Jul 20, 2021
1 parent ec3cf26 commit 2402791
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ verbosityHandle verbosity
--
warn :: Verbosity -> String -> IO ()
warn verbosity msg = withFrozenCallStack $ do
when (verbosity >= normal) $ do
when ((verbosity >= normal) && not (isVerboseNoWarn verbosity)) $ do
ts <- getPOSIXTime
hFlush stdout
hPutStr stderr . withMetadata ts NormalMark FlagTrace verbosity
Expand Down
13 changes: 13 additions & 0 deletions Cabal/src/Distribution/Verbosity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ module Distribution.Verbosity (
-- * Stderr
verboseStderr, isVerboseStderr,
verboseNoStderr,

-- * No warnings
verboseNoWarn, isVerboseNoWarn
) where

import Prelude ()
Expand Down Expand Up @@ -213,6 +216,7 @@ parsecVerbosity = parseIntVerbosity <|> parseStringVerbosity
"timestamp" -> return verboseTimestamp
"stderr" -> return verboseStderr
"stdout" -> return verboseNoStderr
"nowarn" -> return verboseNoWarn
_ -> P.unexpected $ "Bad verbosity flag: " ++ token

flagToVerbosity :: ReadE Verbosity
Expand All @@ -239,6 +243,7 @@ showForCabal v
showFlag VMarkOutput = ["+markoutput"]
showFlag VTimestamp = ["+timestamp"]
showFlag VStderr = ["+stderr"]
showFlag VNoWarn = ["+nowarn"]

showForGHC :: Verbosity -> String
showForGHC v = maybe (error "unknown verbosity") show $
Expand Down Expand Up @@ -290,6 +295,10 @@ verboseStderr = verboseFlag VStderr
verboseNoStderr :: Verbosity -> Verbosity
verboseNoStderr = verboseNoFlag VStderr

-- | Turn off warnings for log messages
verboseNoWarn :: Verbosity -> Verbosity
verboseNoWarn = verboseFlag VNoWarn

-- | Helper function for flag enabling functions
verboseFlag :: VerbosityFlag -> (Verbosity -> Verbosity)
verboseFlag flag v = v { vFlags = Set.insert flag (vFlags v) }
Expand Down Expand Up @@ -335,6 +344,10 @@ isVerboseTimestamp = isVerboseFlag VTimestamp
isVerboseStderr :: Verbosity -> Bool
isVerboseStderr = isVerboseFlag VStderr

-- | Test if we should output warnings when we log.
isVerboseNoWarn :: Verbosity -> Bool
isVerboseNoWarn = isVerboseFlag VNoWarn

-- | Helper function for flag testing functions.
isVerboseFlag :: VerbosityFlag -> Verbosity -> Bool
isVerboseFlag flag = (Set.member flag) . vFlags
Expand Down
1 change: 1 addition & 0 deletions Cabal/src/Distribution/Verbosity/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data VerbosityFlag
| VMarkOutput
| VTimestamp
| VStderr -- ^ @since 3.4.0.0
| VNoWarn
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded, Typeable)

instance Binary VerbosityFlag
Expand Down

0 comments on commit 2402791

Please sign in to comment.