我的Haskell程序或库如何找到它的版本号? [英] How can my Haskell program or library find its version number?
问题描述
我希望我的cabalised程序有一个 - 版本
开关。
我希望它报告与.cabal文件中存在的版本相同的版本。
如果必须在Haskell源代码以及.cabal文件中分别更新版本号,我最终会让它们不同步。
那么,我的程序在cabal下编译时,如何从.cabal文件中获取其版本号?
这得到了Cabal的很好的支持。如下所示(从xmonad):
导入 Paths_ $ myprogram
- Cabal使用大量元数据创建文件.cabal文件以及处理版本号的模块:
import Paths_xmonad(版本)
导入数据。版本(showVersion)
添加打印语句以打印由<$ c $提供的'版本' c> Paths_ $ myprogram :
[--version ] - > putStrLn(xmonad++ showVersion版本)
通常,Cabal生成的路径文件包含以下值,在 dist / build / autogen /
版本,
getBinDir,getLibDir,getDataDir,getLibexecDir,
getDataFileName
I would like my cabalised program to have a --version
switch.
I would like it to report the same version as is present in the .cabal file.
If I have to update the version number separately in my Haskell source code as well as in the .cabal file, I will eventually get them out of sync.
So, how can my program, while being compiled under cabal, get its version number from the .cabal file?
This is well supported with Cabal. As follows (from xmonad):
Import Paths_$myprogram
- a file Cabal creates with lots of metadata from the .cabal file, along with a the module for handling version numbers:
import Paths_xmonad (version)
import Data.Version (showVersion)
Add a print statement to print the 'version' field provided by Paths_$myprogram
:
case args of
["--version"] -> putStrLn ("xmonad " ++ showVersion version)
In general, Cabal's generated Paths file contains the following values, in dist/build/autogen/
version,
getBinDir, getLibDir, getDataDir, getLibexecDir,
getDataFileName
这篇关于我的Haskell程序或库如何找到它的版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!