我的 Haskell 程序或库如何找到其版本号?

发布于 2024-09-02 19:45:54 字数 200 浏览 0 评论 0原文

我希望我的 cabalized 程序有一个 --version 开关。

我希望它报告与 .cabal 文件中存在的版本相同的版本。

如果我必须在 Haskell 源代码和 .cabal 文件中分别更新版本号,我最终会让它们不同步。

那么,我的程序在 cabal 下编译时如何从 .cabal 文件中获取其版本号?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2024-09-09 19:45:54

Cabal 对此提供了很好的支持。如下(来自 xmonad):

导入 Paths_$myprogram - Cabal 使用 .cabal 文件中的大量元数据创建的文件,以及用于处理版本号的模块:

import Paths_xmonad (version)
import Data.Version (showVersion)

添加打印语句以打印Paths_$myprogram 提供的 'version' 字段:

case args of
     ["--version"] -> putStrLn ("xmonad " ++ showVersion version)

一般来说,Cabal 生成的 Paths 文件包含以下值,位于 dist/build/autogen/

version,
getBinDir, getLibDir, getDataDir, getLibexecDir,
getDataFileName

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文