哈斯克尔:正确的做法来指定源代码版本? [英] Haskell: Correct practice to specify version in source?

查看:66
本文介绍了哈斯克尔:正确的做法来指定源代码版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在您的源代码树中指定版本的最佳/正确做法是什么?
例如,我想要的是将VERSION文件放在源代码树的顶层,并获取版本函数来读取它。

cabal文件中有一个版本部分。是否可以通过帮助或版本功能从我的源文件中读取它?
在一个地方指定版本并使其可用于全球范围内的正确做法是什么?

Cabal库中是否有任何函数允许您从cabal文件中提取任何部分并将其显示在源代码中?然后我可以简单地从cabal文件中提取版本部分。



- UPDATE -



感谢Thomas对Pathes_x模块的了解。
只是想补充一点,显然,我不需要把任何东西放到我的cabal文件中。没有它,一切都是有效的。我所需要的只是导入Pathes_X。
另外,我需要导入Data.Version来获取showVersion函数以正确格式化/打印版本数据类型。所以最后我得到了这样的结果:

  import Paths_kvman 
import Data.Version

runVersion _ = putStrLn(Version:++(showVersion version))

现在,所有我需要的是改变cabal文件中的版本号,以便将其传播到我的源代码中。正是我需要的。感谢。

解决方案Cabal为每个包名为 Paths_packagename 自动生成一个模块, 。只需导入这个包,看看它导出的版本值。



编辑:例如:

  module Data.Blah where 

import Paths_t

func :: IO()
func =打印版本

并运行一个示例:

 > func 
版本{versionBranch = [0,1],versionTags = []}

确保在cabal文件的其他模块部分放置 Paths_packagename


What is the best/correct practice to specify version within your source code tree? What I want is, for instance, to put VERSION file in the top level of the source tree and get the "version" function to read it.

There is a version section in the cabal file. Is it possible to read it from my source by "help" or "version" functions? What is the correct practice of specifying the version in one place and making it available globaly?

P.S. Are there any functions in the Cabal library that allow you to pull any section from the cabal file and present it in your source? Then I could simply pull the version section from the cabal file.

-- UPDATE --

Thank you Thomas for an nice piece of knowledge about the Pathes_x module. Just wanted to add that, apparently, I don't need to put anything into my cabal file. Everything just works without it. All I needed was to import the Pathes_X as you sugested. Also, I needed to import Data.Version to get the showVersion function to properly format/print the Version data type. So at the end I get something like this:

import Paths_kvman
import Data.Version

runVersion _ = putStrLn ("Version: " ++ (showVersion version))

Now, all I need is to change the version number in the cabal file to propagade it all over my source. Exactly what I needed. Thanks.

解决方案

Cabal automatically generates a module for each package named Paths_packagename. Just import this package and look at the version value it exports.

Edit: For example:

module Data.Blah where

import Paths_t

func :: IO ()
func = print version

And an example run:

> func
Version {versionBranch = [0,1], versionTags = []}

Be sure to put Paths_packagename in your Other-Modules section of the cabal file.

这篇关于哈斯克尔:正确的做法来指定源代码版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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