Ticket #823 (closed enhancement: worksforme)

Opened 2 years ago

Last modified 2 years ago

Accessing the package version from within the package

Reported by: basvandijk Owned by:
Priority: normal Milestone:
Component: Cabal library Version: 1.8.0.6
Severity: normal Keywords:
Cc: Difficulty: unknown
GHC Version: Platform:

Description

Just like you can access data files from a package, it would be useful to retrieve the current version of your package from within your program.

This is useful when you want to print the current version of your program when the user issues a --version flag for example.

More specifically I would like the following module to be generated automatically:

module Version_pkgname where

import Distribution.Version (Version)

version :: Version
version = <the current package version>

where Version is from the Cabal library.

Having just a String for the version type is also OK and maybe even preferable because otherwise a dependency on the Cabal library is required.

Change History

follow-up: ↓ 2   Changed 2 years ago by AntoineLatter

Maybe I'm miss-understanding, but this feature already exists exactly as you've described.

Paths_$pkgname.version :: Version

is exported by default.

I'm not sure in which version it was introduced, and the user guide makes no mention of the feature.

Here's the code in 1.10:

 http://www.haskell.org/ghc/docs/7.0.2/html/libraries/Cabal-1.10.1.0/src/Distribution-Simple-Build-PathsModule.html

in reply to: ↑ 1   Changed 2 years ago by basvandijk

  • status changed from new to closed
  • resolution set to worksforme

Replying to AntoineLatter:

Maybe I'm miss-understanding, but this feature already exists exactly as you've described.

Indeed. I just discovered this myself when browsing through the autogen directory of one of my packages and reading the Paths_package module.

I'm closing the ticket as worksforme.

  Changed 2 years ago by basvandijk

I wrote some documentation.

Note: See TracTickets for help on using tickets.