From 24027915a25dac32544fd5a9761b7275fb5cebc8 Mon Sep 17 00:00:00 2001 From: Patrick Augusto Date: Wed, 30 Jun 2021 18:16:56 -0300 Subject: [PATCH] Suppress warnings for verbosity --- Cabal/src/Distribution/Simple/Utils.hs | 2 +- Cabal/src/Distribution/Verbosity.hs | 13 +++++++++++++ Cabal/src/Distribution/Verbosity/Internal.hs | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cabal/src/Distribution/Simple/Utils.hs b/Cabal/src/Distribution/Simple/Utils.hs index 26c727b4657..54c1b4c4408 100644 --- a/Cabal/src/Distribution/Simple/Utils.hs +++ b/Cabal/src/Distribution/Simple/Utils.hs @@ -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 diff --git a/Cabal/src/Distribution/Verbosity.hs b/Cabal/src/Distribution/Verbosity.hs index 23ffaba1389..d73cbd8031d 100644 --- a/Cabal/src/Distribution/Verbosity.hs +++ b/Cabal/src/Distribution/Verbosity.hs @@ -52,6 +52,9 @@ module Distribution.Verbosity ( -- * Stderr verboseStderr, isVerboseStderr, verboseNoStderr, + + -- * No warnings + verboseNoWarn, isVerboseNoWarn ) where import Prelude () @@ -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 @@ -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 $ @@ -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) } @@ -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 diff --git a/Cabal/src/Distribution/Verbosity/Internal.hs b/Cabal/src/Distribution/Verbosity/Internal.hs index ea436825dd4..21a4e6932c2 100644 --- a/Cabal/src/Distribution/Verbosity/Internal.hs +++ b/Cabal/src/Distribution/Verbosity/Internal.hs @@ -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