From 2edc72b5cdeeffc61e92143742f83b04a812c34e Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Thu, 3 Aug 2023 09:07:20 +0200 Subject: [PATCH] Fix #5488: change default for logging to +nowrap This introduce a +wrap modifier that make Cabal CLI follows the ancient behavior. --- .../Distribution/Utils/Structured.hs | 2 +- Cabal/src/Distribution/Simple/Utils.hs | 4 ++-- Cabal/src/Distribution/Verbosity.hs | 21 +++++++++++++++---- Cabal/src/Distribution/Verbosity/Internal.hs | 4 +++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs index 900aedc0ca3..f10bab20174 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs @@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured" , testCase "GenericPackageDescription" $ md5Check (Proxy :: Proxy GenericPackageDescription) 0x6ad1e12c6f88291e9b8c131d239eda70 , testCase "LocalBuildInfo" $ - md5Check (Proxy :: Proxy LocalBuildInfo) 0xbc7ac84a9bc43345c812af222c3e5ba0 + md5Check (Proxy :: Proxy LocalBuildInfo) 0xca172408aaecfdda2052714e969563cb #endif ] diff --git a/Cabal/src/Distribution/Simple/Utils.hs b/Cabal/src/Distribution/Simple/Utils.hs index f05957bc271..11e22c2eafa 100644 --- a/Cabal/src/Distribution/Simple/Utils.hs +++ b/Cabal/src/Distribution/Simple/Utils.hs @@ -661,8 +661,8 @@ handleDoesNotExist e = -- | Wraps text unless the @+nowrap@ verbosity flag is active wrapTextVerbosity :: Verbosity -> String -> String wrapTextVerbosity verb - | isVerboseNoWrap verb = withTrailingNewline - | otherwise = withTrailingNewline . wrapText + | isVerboseWrap verb = withTrailingNewline . wrapText + | otherwise = withTrailingNewline -- | Prepends a timestamp if @+timestamp@ verbosity flag is set -- diff --git a/Cabal/src/Distribution/Verbosity.hs b/Cabal/src/Distribution/Verbosity.hs index bab48bbed21..623197f861d 100644 --- a/Cabal/src/Distribution/Verbosity.hs +++ b/Cabal/src/Distribution/Verbosity.hs @@ -56,6 +56,8 @@ module Distribution.Verbosity -- * Line wrapping , verboseNoWrap , isVerboseNoWrap + , verboseWrap + , isVerboseWrap -- * Time stamps , verboseTimestamp @@ -229,7 +231,9 @@ parsecVerbosity = parseIntVerbosity <|> parseStringVerbosity case token of "callsite" -> return verboseCallSite "callstack" -> return verboseCallStack - "nowrap" -> return verboseNoWrap + "nowrap" -> return verboseNoWrap -- This is the (new) default, but we + -- choose to not make the CLI break when using the legacy `+nowrap` arg. + "wrap" -> return verboseWrap "markoutput" -> return verboseMarkOutput "timestamp" -> return verboseTimestamp "stderr" -> return verboseStderr @@ -257,7 +261,8 @@ showForCabal v showFlag VCallSite = ["+callsite"] showFlag VCallStack = ["+callstack"] - showFlag VNoWrap = ["+nowrap"] + -- showFlag VNoWrap = ["+nowrap"] + showFlag VWrap = ["+wrap"] showFlag VMarkOutput = ["+markoutput"] showFlag VTimestamp = ["+timestamp"] showFlag VStderr = ["+stderr"] @@ -289,7 +294,11 @@ verboseUnmarkOutput = verboseNoFlag VMarkOutput -- | Disable line-wrapping for log messages. verboseNoWrap :: Verbosity -> Verbosity -verboseNoWrap = verboseFlag VNoWrap +verboseNoWrap = verboseNoFlag VWrap + +-- | Enable line-wrapping for log messages. +verboseWrap :: Verbosity -> Verbosity +verboseWrap = verboseFlag VWrap -- | Mark the verbosity as quiet. verboseQuiet :: Verbosity -> Verbosity @@ -348,7 +357,11 @@ isVerboseMarkOutput = isVerboseFlag VMarkOutput -- | Test if line-wrapping is disabled for log messages. isVerboseNoWrap :: Verbosity -> Bool -isVerboseNoWrap = isVerboseFlag VNoWrap +isVerboseNoWrap = not . isVerboseWrap + +-- | Test if line-wrapping is enabled for log messages. +isVerboseWrap :: Verbosity -> Bool +isVerboseWrap = isVerboseFlag VWrap -- | Test if we had called 'lessVerbose' on the verbosity. isVerboseQuiet :: Verbosity -> Bool diff --git a/Cabal/src/Distribution/Verbosity/Internal.hs b/Cabal/src/Distribution/Verbosity/Internal.hs index b8f55cf5b98..96aaab1ef97 100644 --- a/Cabal/src/Distribution/Verbosity/Internal.hs +++ b/Cabal/src/Distribution/Verbosity/Internal.hs @@ -18,12 +18,14 @@ instance Structured VerbosityLevel data VerbosityFlag = VCallStack | VCallSite - | VNoWrap + -- | VNoWrap | VMarkOutput | VTimestamp | -- | @since 3.4.0.0 VStderr | VNoWarn + | -- | @since 3.12.1.0 + VWrap deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded, Typeable) instance Binary VerbosityFlag