我的Haskell程序或库如何找到它的版本号? [英] How can my Haskell program or library find its version number?

查看:206
本文介绍了我的Haskell程序或库如何找到它的版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆