dev: split debug/ghcdebug flags, comment out the latter for now

Compilation with ghc-debug is failing, and it has not yet been used
for anything. Separate the flag and leave it in place but commented for now.
This commit is contained in:
Simon Michael 2024-10-21 18:42:09 -10:00
parent 4b4cc54a6a
commit 50bf401ea6
13 changed files with 68 additions and 54 deletions

View File

@ -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 ()

View File

@ -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

View File

@ -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

View File

@ -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}}

View File

@ -33,7 +33,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef DEBUG
#ifdef GHCDEBUG
True
#else
False

View File

@ -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

View File

@ -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.

View File

@ -43,7 +43,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef DEBUG
#ifdef GHCDEBUG
True
#else
False

View File

@ -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

View File

@ -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

View File

@ -134,7 +134,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef DEBUG
#ifdef GHCDEBUG
True
#else
False

View File

@ -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

View File

@ -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"