HBeat Lives

Reorganising my projects home, I copied in the old documentation for my hbeat program. The docs needed some updating, so I decided to check it all still works ok. Fearing bitrot, I was pleased and a little suprised to see that on my recently rebuilt ubuntu machine, all I needed was

sudo apt-get install libsdl1.2-dev
sudo apt-get install libsdl-mixer1.2-dev
cabal-dev install hbeat

Or at least that’s what I first thought. The program fired up ok, but failed to respond to mouse clicks as expected. It turns out that this was a pre-existing bug – if the screen redraws don’t happen fast enough, hbeat gets further and further behind in it’s event processing eventually ignoring everything. A small code fix (now published to hackage) causes out-of-date redraw requests to be dropped.

But why was I seeing this problem now? It seems that since I wrote the software, openGL via SDL seems to have got alot slower. The compositing window manager (compiz) seems to be the culprit – it’s consuming significant cpu time whilst hbeat is running. Some references to this can be found here.

I guess there’s a downside to all those fancy compositing effects.

It’s a shame hbeat is now a fair bit glitchier than it was before. Maybe sometime I’ll look at this, but for now at least it still works.

Accessing the cabal version number from an application

I wanted the –version flag in an application to return the version from the cabal file. Unable to find solution for this on the net, I ventured into the darcs source code to for a solution. It’s actually pretty easy:

Step 1

Change the Build-Type field in the cabal file to be “Custom”. This means cabal will look for a Setup.hs file to control the build.

Step 2

Create a Setup.hs that autogenerates a haskell module containing the version number. Here’s mine:

import Distribution.Simple(defaultMainWithHooks, UserHooks(..), simpleUserHooks )
import Distribution.Simple.Utils(rewriteFile)
import Distribution.Package(packageVersion)
import Distribution.Simple.BuildPaths(autogenModulesDir)
import System.FilePath((</>))
import Data.Version(showVersion)
generateVersionModule pkg lbi = do
let dir = autogenModulesDir lbi
let version = packageVersion pkg

rewriteFile (dir </> "Version.hs") $ unlines
["module Version where"
,"version :: String"
,"version = \"" ++ showVersion version ++ "\""
]

myBuildHook pkg lbi hooks flags = do
generateVersionModule pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags

main = defaultMainWithHooks simpleUserHooks {
buildHook=myBuildHook
}

Step 3

Change your program to access the created Version module. It’s actually generated in the ./dist/build./autogen directory, but this seems to be correctly on the source path by default.