[Haskell-cafe] get cabal info for self?
Gwern Branwen
gwern0 at gmail.com
Sat Jul 11 00:10:55 EDT 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On Fri, Jul 10, 2009 at 11:46 PM, Keith Sheppard wrote:
> Is there a way for a cabalized program to get its own info. I'm
> specifically interested in version info.
>
> Thanks
> Keith
>
Sure, via the Paths_* mechanism. For your reference, here's what it
looks like for xmonad:
module Paths_xmonad (
version,
getBinDir, getLibDir, getDataDir, getLibexecDir,
getDataFileName
) where
import Data.Version (Version(..))
import System.Environment (getEnv)
version :: Version
version = Version {versionBranch = [0,8,1], versionTags = []}
bindir, libdir, datadir, libexecdir :: FilePath
bindir = "/home/gwern/bin/bin"
libdir = "/home/gwern/bin/lib/xmonad-0.8.1/ghc-6.10.2"
datadir = "/home/gwern/bin/share/xmonad-0.8.1"
libexecdir = "/home/gwern/bin/libexec"
getBinDir, getLibDir, getDataDir, getLibexecDir :: IO FilePath
getBinDir = catch (getEnv "xmonad_bindir") (\_ -> return bindir)
getLibDir = catch (getEnv "xmonad_libdir") (\_ -> return libdir)
getDataDir = catch (getEnv "xmonad_datadir") (\_ -> return datadir)
getLibexecDir = catch (getEnv "xmonad_libexecdir") (\_ -> return libexecdir)
getDataFileName :: FilePath -> IO FilePath
getDataFileName name = do
dir <- getDataDir
return (dir ++ "/" ++ name)
So if you wanted the version number "081", you could do something like
'concatMap show $ versionBranch $ version'
- --
gwern
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEAREKAAYFAkpYD98ACgkQvpDo5Pfl1oI6gACZATzqwtJgBFhAl/qo0ZPauqhg
zBcAnRdHtv5nFzNAo2Z9ulHdW1DxiJBE
=XyEM
-----END PGP SIGNATURE-----
More information about the Haskell-Cafe
mailing list