haskell, hledger
June 6, 2013

GHCI fix



Next item on the 0.22 backlog: fix make ghci and make ghciweb.

The goal of these make rules is to bring up a GHCI prompt with as much as possible of the guts of hledger (or hledger-web) loaded, in scope, and visible. This can be really valuable for debugging, sanity-checking, and exploratory development, but it’s quite hard to set up by hand, as the necessary flags tend to proliferate. Hence these rules.

The latest breakage was due to my using cabal’s MIN_version_* macros (to make Hledger.Cli.Utils compatible with both the versions of directory currently found on user machines). It’s hard to ensure these macros are available in all circumstances (sp/ghc builds, haddock, ghci..) So I’ve made it work with or without them, with this not-very-pretty kludge:

#ifdef MIN_VERSION_directory
#if MIN_VERSION_directory(1,2,0)
        utc <- getModificationTime f
        let nom = utcTimeToPOSIXSeconds utc
        let clo = TOD (read $ takeWhile (`elem` "0123456789") $ show nom) 0 -- XXX read
        clo <- getModificationTime f
-- cabal macros aren't available, assume the new directory
        utc <- getModificationTime f
        let nom = utcTimeToPOSIXSeconds utc
        let clo = TOD (read $ takeWhile (`elem` "0123456789") $ show nom) 0 -- XXX read

And now I’ve got ghci prompts again. It looks like they could do some more importing though:

~/src/hledger$ make ghciweb
ghci -rtsopts -W -fwarn-tabs -fno-warn-unused-do-bind -fno-warn-name-shadowing  -ihledger-lib -ihledger -ihledger-web -ihledger-web/app -L/usr/lib  -optP-include -optPhledger/dist/build/autogen/cabal_macros.h -DPATCHLEVEL=0 -DDEVELOPMENT -DVERSION='"0.21.2dev"' -XCPP -XMultiParamTypeClasses -XOverloadedStrings -XQuasiQuotes -XRecordWildCards -XTemplateHaskell  hledger-web/app/main.hs
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[ 1 of 52] Compiling Settings.Development ( hledger-web/Settings/Development.hs, interpreted ) [flags changed]
[ 2 of 52] Compiling Settings         ( hledger-web/Settings.hs, interpreted ) [flags changed]
Loading package array- ... linking ... done.
[52 of 52] Compiling Main             ( hledger-web/app/main.hs, interpreted )
Ok, modules loaded: Hledger, Hledger.Data, Hledger.Data.Account, Hledger.Data.AccountName, Hledger.Data.Amount, Hledger.Data.Commodity, Hledger.Data.Dates, Hledger.Data.FormatStrings, Hledger.Data.Journal, Hledger.Data.Ledger, Hledger.Data.Posting, Hledger.Data.TimeLog, Hledger.Data.Transaction, Hledger.Data.Types, Hledger.Query, Hledger.Read, Hledger.Read.CsvReader, Hledger.Read.JournalReader, Hledger.Read.TimelogReader, Hledger.Reports, Hledger.Utils, Hledger.Utils.UTF8IOCompat, Hledger.Cli, Hledger.Cli.Options, Hledger.Cli.Utils, Hledger.Cli.Version, Hledger.Cli.Add, Hledger.Cli.Balance, Hledger.Cli.Balancesheet, Hledger.Cli.Cashflow, Hledger.Cli.Histogram, Hledger.Cli.Incomestatement, Hledger.Cli.Print, Hledger.Cli.Register, Hledger.Cli.Stats, Application, Foundation, Import, Settings, Settings.StaticFiles, Settings.Development, Handler.Common, Handler.JournalEditR, Handler.JournalEntriesR, Handler.JournalR, Handler.Post, Handler.RegisterR, Handler.RootR, Handler.Utils, Hledger.Web.Main, Hledger.Web.Options, Main.
>>> :t defbaseurl

<interactive>:1:1: Not in scope: `defbaseurl'
>>> import Settings
>>> :t defbaseurl
defbaseurl :: GHC.Types.Int -> GHC.Base.String