Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get version of Cabal package in source code of the package?

Tags:

haskell

cabal

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?

like image 504
Mark Karpov Avatar asked Oct 16 '15 18:10

Mark Karpov


1 Answers

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.

like image 79
Mark Karpov Avatar answered Sep 28 '22 00:09

Mark Karpov