Say I have a console program that has an option to display its
version. Currently whenever I update version in .cabal
file I need to go
to source code and update constant — string representation of current
version number as well. This feels against DRY principle and now I'm
wondering, is it possible to get version of my project as defined in
.cabal
file from source code? Maybe Cabal defines some CPP macro or
something else?
Indeed Cabal allows to access information from .cabal
file in your
program. According to Cabal documentation,
you can import special module that exists during building of your package,
like this:
import Paths_packagename (version)
import Data.Version (showVersion)
myVersion :: String
myVersion = showVersion version
The module Paths_packagename
provides version
of type
Version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With