将颠覆存储库编号放入代码中

发布于 2024-07-04 07:35:45 字数 211 浏览 9 评论 0原文

我想实现一种在代码中记录项目版本的方法,以便在测试时使用它并帮助跟踪错误。 看起来最好使用的版本号就是 Subversion 的当前修订版号。 有没有一种简单的方法可以将这个数字挂接到(在我的例子中是C++)头文件或其他文件中,然后我可以在代码中获取它? 我想这是一个提交后钩子什么的?

有谁有实现此功能的经验(请分享代码?),或者可以建议更好的替代方案吗? 谢谢。

I'd like to implement a way of recording the version of a project within code, so that it can be used when testing and to help track bugs.
It seems the best version number to use would just be the current revision number from Subversion. Is there an easy way to hook this number into a (C++ in my case) header file or something, which I can then get at in code? I guess this is a post commit hook or something?

Does anyone have any experience of implementing this (with code to share, please?), or can suggest a better alternative?
Thanks.

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

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

发布评论

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

评论(7

幻想少年梦 2024-07-11 07:35:46

虽然很漂亮,但修订版关键字技巧仅在该修订版中发生更改时更新文件 - 如果您不更改文件,那么它将继续反映旧修订版。

如果您希望软件始终反映总体修订号,那么您必须深入研究 相关 SVN 条目文件 并提取它,这并不太困难(它是一个 XML 文件)。

维基百科在其版本页面上执行此操作,以指示正在运行的软件的修订版本; 代码在这里 - 查找 <强>getSvnRevision()方法。

While nifty, the revision keyword trick only updates the file when it's changed in that revision - if you don't change the file, then it will continue to reflect the old revision.

If you want the software to always reflect the overall revision number, then you'll have to delve into the relevant SVN entries file and extract it, which isn't too difficult (it's an XML file).

Wikipedia does this on their version page to indicate the revision of the software that's running live; the code is here - look for the getSvnRevision() method.

养猫人 2024-07-11 07:35:46

您还可以使用 SubWCRev,它是 TortoiseSVN 的一部分。

SubWCRev 是 Windows 控制台程序,可用于读取 Subversion 工作副本的状态并可选择在模板文件中执行关键字替换。 这通常用作构建过程的一部分,作为将工作副本信息合并到正在构建的对象中的一种方法。 通常,它可用于在“关于”框中包含修订号。

http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html

You can also use SubWCRev which is part of TortoiseSVN.

SubWCRev is Windows console program which can be used to read the status of a Subversion working copy and optionally perform keyword substitution in a template file. This is often used as part of the build process as a means of incorporating working copy information into the object you are building. Typically it might be used to include the revision number in an “About” box.

http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html

风启觞 2024-07-11 07:35:46

将以下内容添加到文件顶部应该可以解决问题

[Subversion]
Revision = "$Revision: $"
Author   = "$Author:   $"
Date     = "$Date:     $"
HeadURL  = "$HeadURL:  $"

Adding the following to the top of the file should do the trick

[Subversion]
Revision = "$Revision: 
quot;
Author   = "$Author:   
quot;
Date     = "$Date:     
quot;
HeadURL  = "$HeadURL:  
quot;
小兔几 2024-07-11 07:35:46

在你的Makefile中添加:

SVNDEV := -D'SVN_REV="$(shell svnversion -n .)"'
CFLAGS := $(SVNDEV) ...

然后你可以在代码中的任何地方使用宏SVN_REV,例如:

printf ("Version: SVN %s\n", SVN_REV);

in your Makefile, add:

SVNDEV := -D'SVN_REV="$(shell svnversion -n .)"'
CFLAGS := $(SVNDEV) ...

then you can use macro SVN_REV anywhere in your code, eg:

printf ("Version: SVN %s\n", SVN_REV);
樱桃奶球 2024-07-11 07:35:46

您可以使用 svn:keywords 属性来启用 Rev 关键字。

然后,您可以在代码中使用 $Rev$ ,SVN 在更新到 $Rev: 256 $ 时会自动扩展它,然后可以解析...

有关 Subversion 手册的更多信息

You can use the svn:keywords property to enable the Rev keyword.

You can then use $Rev$ in your code and SVN will expand it automatically when updating to $Rev: 256 $ which can then parse...

More info on the Subversion manual

少女情怀诗 2024-07-11 07:35:46

一个很好的最新解决方案:

创建一个包含以下行的 Makefile(与 YourFile.dox 位于同一文件夹中):

sed "s~RevNumber~$(shell svnversion ../)~g" YourFile.dox > YourFileDummy.dox; doxygen YourFileDummy.dox

以及 YourFile.dox 应包含以下内容:

...
PROJECT_NUMBER         = "Revision RevNumber"
...

现在:

  1. sed 将 .dox 中的 RevNumber 替换为 svnversion 的输出(在存储库的主文件夹中执行) )并将修改后的文件保存到 YourFileDummy.dox
  2. YourFileDummy.dox 上执行 doxygen 以生成文档
  3. 您的文档现在将包含修订号!

A good up-to-date solution:

Create a Makefile containing the following line (in the same folder as YourFile.dox):

sed "s~RevNumber~$(shell svnversion ../)~g" YourFile.dox > YourFileDummy.dox; doxygen YourFileDummy.dox

And YourFile.dox should contain this:

...
PROJECT_NUMBER         = "Revision RevNumber"
...

Now:

  1. sed replaces RevNumber in the .dox with the output of svnversion (executed in the main folder of your repository) and saves the modified file to YourFileDummy.dox
  2. doxygen is executed on YourFileDummy.dox to generate the documentation
  3. Your documentation will now contain the revision number!
我不会写诗 2024-07-11 07:35:45

两种方法:

在代码中嵌入 $Id$$Revision$。 然后设置文件的 svn:keywords="Id Revision" 属性。 这将为您提供该源文件的最后修改版本。 适合较小的项目和脚本。

或者,使用 Makefile 驱动的进程和命令行工具 svnversion。 (特定于语言 - 这应该适用于 C/C++)

echo -n "#define VERSION 1.0.1-" > version.h
svnversion -n . >> version.h

或一些带有 sed 和 version.h.in 的更复杂的构建脚本。 然后只需 #include version.h

这将为您提供存储库版本号,该版本号将随着每次提交/更新而变化,并且对于大多数项目来说可能是更合适的版本号。

注意:我还使用了手动更新的人类可读版本字符串。 该示例将给出: 版本:1.0.1-r13445

~J

Two ways:

Embed $Id$ or $Revision$ within the code. Then set svn:keywords="Id Revision" property on the file. This will give you the last modified revision of that source file. Good for smaller projects and scripts.

Alternatively, use a Makefile driven process and the command line tool svnversion. (Language specific - this should work for C/C++)

echo -n "#define VERSION 1.0.1-" > version.h
svnversion -n . >> version.h

Or some more complex build script with sed and version.h.in. Then just #include version.h

That will give you the repository version number, which will change with every commit / update, and is probably a more appropriate version number for most projects.

Note: I also used a human readable version string that I manually update. The example would give: Version: 1.0.1-r13445

~J

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