diff --git a/hledger-lib/Hledger/Utils/Debug.hs b/hledger-lib/Hledger/Utils/Debug.hs index 5b4f68d7f..a5071b509 100644 --- a/hledger-lib/Hledger/Utils/Debug.hs +++ b/hledger-lib/Hledger/Utils/Debug.hs @@ -184,7 +184,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO) import Data.List hiding (uncons) -- import Debug.Breakpoint import Debug.Trace (trace, traceIO, traceShowId) -#ifdef DEBUG +#ifdef GHCDEBUG import GHC.Debug.Stub (pause, withGhcDebug) #endif import Safe (readDef) @@ -224,11 +224,12 @@ debugLevel = case dropWhile (/="--debug") progArgs of _ -> 0 -- | Whether ghc-debug support is included in this build, and if so, how it will behave. --- When hledger is built with the @debug@ cabal flag (off by default), +-- When hledger is built with the @ghcdebug@ cabal flag (off by default, because of extra deps), -- it can listen (on unix ?) for connections from ghc-debug clients like ghc-debug-brick, -- for pausing/resuming the program and inspecting memory usage and profile information. -- --- This is enabled by running hledger with a negative --debug level, with three different modes: +-- With a ghc-debug-supporting build, ghc-debug can be enabled by running hledger with +-- a negative --debug level. There are three different modes: -- --debug=-1 - run normally (can be paused/resumed by a ghc-debug client), -- --debug=-2 - pause and await client commands at program start (not useful currently), -- --debug=-3 - pause and await client commands at program end. @@ -244,7 +245,7 @@ data GhcDebugMode = -- | Is the hledger-lib package built with ghc-debug support ? ghcDebugSupportedInLib :: Bool ghcDebugSupportedInLib = -#ifdef DEBUG +#ifdef GHCDEBUG True #else False @@ -254,6 +255,7 @@ ghcDebugSupportedInLib = -- See GhcDebugMode. ghcDebugMode :: GhcDebugMode ghcDebugMode = +#ifdef GHCDEBUG case debugLevel of _ | not ghcDebugSupportedInLib -> GDNotSupported (-1) -> GDNoPause @@ -261,11 +263,14 @@ ghcDebugMode = (-3) -> GDPauseAtEnd _ -> GDDisabled -- keep synced with GhcDebugMode +#else + GDNotSupported +#endif -- | When ghc-debug support has been built into the program and enabled at runtime with --debug=-N, -- this calls ghc-debug's withGhcDebug; otherwise it's a no-op. withGhcDebug' = -#ifdef DEBUG +#ifdef GHCDEBUG if ghcDebugMode > GDDisabled then withGhcDebug else id #else id @@ -274,7 +279,7 @@ withGhcDebug' = -- | When ghc-debug support has been built into the program, this calls ghc-debug's pause, otherwise it's a no-op. ghcDebugPause' :: IO () ghcDebugPause' = -#ifdef DEBUG +#ifdef GHCDEBUG pause #else return () diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 7399a194e..2d02b98b4 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -46,7 +46,7 @@ source-repository head location: https://github.com/simonmichael/hledger flag debug - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled manual: True default: False @@ -172,8 +172,6 @@ library pager >=0.1.1.0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 test-suite doctest type: exitcode-stdio-1.0 @@ -237,8 +235,6 @@ test-suite doctest pager >=0.1.1.0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 if impl(ghc >= 9.0) && impl(ghc < 9.2) buildable: False @@ -305,5 +301,3 @@ test-suite unittest pager >=0.1.1.0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index 10b7a71c6..f3ca3aa57 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -97,9 +97,14 @@ ghc-options: flags: debug: - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled default: false manual: true +# bitrotted +# ghcdebug: +# description: Build with support for attaching a ghc-debug client +# default: false +# manual: true when: - condition: (!(os(windows))) @@ -107,8 +112,10 @@ when: - pager >=0.1.1.0 - condition: (flag(debug)) cpp-options: -DDEBUG - dependencies: - - ghc-debug-stub >=0.6.0.0 && <0.7 +# - condition: (flag(ghcdebug)) +# cpp-options: -DGHCDEBUG +# dependencies: +# - ghc-debug-stub >=0.6.0.0 && <0.7 source-dirs: #- other/ledger-parse diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index 0c5a6e72e..fda3c3413 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -82,13 +82,18 @@ hledgerUiMain = withGhcDebug' $ withProgName "hledger-ui.log" $ do -- force Hle dbg1IO "args" progArgs dbg1IO "debugLevel" debugLevel - -- try to encourage user's $PAGER to properly display ANSI (in command line help) - usecolor <- useColorOnStdout - when usecolor setupPager - - opts@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=iopts,rawopts_=rawopts}} <- getHledgerUIOpts + opts1@UIOpts{uoCliOpts=copts@CliOpts{inputopts_=iopts,rawopts_=rawopts}} <- getHledgerUIOpts -- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts) + usecolor <- useColorOnStdout + -- When ANSI colour/styling is available and enabled, encourage user's $PAGER to use it (for command line help). + when usecolor setupPager + -- And when it's not, disable colour in the TUI ? + -- Theme.hs's themes currently hard code various colours and styles provided by vty, + -- which probably are disabled automatically when terminal doesn't support them. + -- But we'll at least force hledger-ui's theme to a monochrome one. + let opts = if usecolor then opts1 else opts1{uoTheme=Just "terminal"} + -- always generate forecasted periodic transactions; their visibility will be toggled by the UI. let copts' = copts{inputopts_=iopts{forecast_=forecast_ iopts <|> Just nulldatespan}} diff --git a/hledger-ui/Hledger/UI/UIOptions.hs b/hledger-ui/Hledger/UI/UIOptions.hs index f3ffc0b70..5573f3b0a 100644 --- a/hledger-ui/Hledger/UI/UIOptions.hs +++ b/hledger-ui/Hledger/UI/UIOptions.hs @@ -33,7 +33,7 @@ prognameandversion :: String prognameandversion = versionStringWith $$tGitInfoCwdTry -#ifdef DEBUG +#ifdef GHCDEBUG True #else False diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index 489fe5168..3aca91f8c 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -40,7 +40,7 @@ source-repository head location: https://github.com/simonmichael/hledger flag debug - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled manual: True default: False @@ -107,8 +107,6 @@ library default-language: Haskell2010 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 if os(windows) build-depends: vty-windows >=0.2.0.1 && <0.3.0.0 @@ -130,7 +128,5 @@ executable hledger-ui default-language: Haskell2010 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 if flag(threaded) ghc-options: -threaded -with-rtsopts=-T diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index f31507749..d3c225475 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -38,9 +38,14 @@ flags: default: true manual: false debug: - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled default: false manual: true +# bitrotted +# ghcdebug: +# description: Build with support for attaching a ghc-debug client +# default: false +# manual: true cpp-options: -DVERSION="1.40.99" @@ -58,8 +63,10 @@ dependencies: when: - condition: (flag(debug)) cpp-options: -DDEBUG - dependencies: - - ghc-debug-stub >=0.6.0.0 && <0.7 +# - condition: (flag(ghcdebug)) +# cpp-options: -DGHCDEBUG +# dependencies: +# - ghc-debug-stub >=0.6.0.0 && <0.7 # curses is required to build terminfo for vty for hledger-ui. # On POSIX systems it might be not present. diff --git a/hledger-web/Hledger/Web/WebOptions.hs b/hledger-web/Hledger/Web/WebOptions.hs index 18aae9bd8..5a0375e1b 100644 --- a/hledger-web/Hledger/Web/WebOptions.hs +++ b/hledger-web/Hledger/Web/WebOptions.hs @@ -43,7 +43,7 @@ prognameandversion :: String prognameandversion = versionStringWith $$tGitInfoCwdTry -#ifdef DEBUG +#ifdef GHCDEBUG True #else False diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index c3e2d03b0..463a42d86 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -113,7 +113,7 @@ source-repository head location: https://github.com/simonmichael/hledger flag debug - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled manual: True default: False @@ -214,8 +214,6 @@ library ghc-options: -O0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 executable hledger-web main-is: main.hs @@ -236,8 +234,6 @@ executable hledger-web ghc-options: -O0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 if flag(library-only) buildable: False if flag(threaded) @@ -261,5 +257,3 @@ test-suite test ghc-options: -O0 if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index 13a3d9d7c..fd01e9fac 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -60,9 +60,14 @@ flags: default: true manual: false debug: - description: Build with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled default: false manual: true +# bitrotted +# ghcdebug: +# description: Build with support for attaching a ghc-debug client +# default: false +# manual: true ghc-options: - -Wall @@ -82,8 +87,10 @@ when: ghc-options: -O0 - condition: (flag(debug)) cpp-options: -DDEBUG - dependencies: - - ghc-debug-stub >=0.6.0.0 && <0.7 +# - condition: (flag(ghcdebug)) +# cpp-options: -DGHCDEBUG +# dependencies: +# - ghc-debug-stub >=0.6.0.0 && <0.7 dependencies: - base >=4.14 && <4.21 diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 8678516af..5b9f8e546 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -134,7 +134,7 @@ prognameandversion :: String prognameandversion = versionStringWith $$tGitInfoCwdTry -#ifdef DEBUG +#ifdef GHCDEBUG True #else False diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 968478546..d31a0a7cb 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -93,7 +93,7 @@ source-repository head location: https://github.com/simonmichael/hledger flag debug - description: Build with GHC 9.10+'s stack traces enabled, and with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled manual: True default: False @@ -198,8 +198,6 @@ library terminfo if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 executable hledger main-is: hledger-cli.hs @@ -252,8 +250,6 @@ executable hledger terminfo if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 if flag(threaded) ghc-options: -threaded -with-rtsopts=-T @@ -307,8 +303,6 @@ test-suite unittest terminfo if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 benchmark bench type: exitcode-stdio-1.0 @@ -362,5 +356,3 @@ benchmark bench terminfo if (flag(debug)) cpp-options: -DDEBUG - build-depends: - ghc-debug-stub >=0.6.0.0 && <0.7 diff --git a/hledger/package.yaml b/hledger/package.yaml index 0f517b54f..76da38bcd 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -100,9 +100,14 @@ flags: default: true manual: false debug: - description: Build with GHC 9.10+'s stack traces enabled, and with support for attaching a ghc-debug client + description: Build with GHC 9.10+'s stack traces enabled default: false manual: true +# bitrotted +# ghcdebug: +# description: Build with support for attaching a ghc-debug client +# default: false +# manual: true ghc-options: - -Wall @@ -157,8 +162,10 @@ when: - terminfo - condition: (flag(debug)) cpp-options: -DDEBUG - dependencies: - - ghc-debug-stub >=0.6.0.0 && <0.7 +# - condition: (flag(ghcdebug)) +# cpp-options: -DGHCDEBUG +# dependencies: +# - ghc-debug-stub >=0.6.0.0 && <0.7 library: cpp-options: -DVERSION="1.40.99"