自动版本编号

发布于 2024-10-06 03:29:30 字数 512 浏览 2 评论 0原文

我正在向我的可执行文件添加一个功能,以使用 --version 参数运行它。该项目非常大并且使用了多个类。我想打印出所有课程的版本。

现在我的每个类都有一个函数 static void print_info() { cout << “信息在这里”<<结束; } 并且带有 main() 的文件调用每个类的 print_info

问题:有没有办法在更改时自动维护版本号?

附加信息: 我和我的团队使用 NetBeans 进行开发。我们还使用 Subversion (svn),我知道它保留修订版本号。问题仅与修订号相关。我希望能够分发一个可执行文件,无需访问 subversion 服务器即可打印版本号。

如果这有点模糊,我很乐意提供更多信息。 谢谢!

聚苯乙烯 我不在乎版本值是多少。 Weather 是 NetBeans 生成的任意数字,或者相应的 subversion 修订版本号,或者只是最后一次修改的日期。

I'm adding a functionality to my executable to run it with --version argument. The project is very big and uses multiple classes. I'd like to print out the versions of all of the classes.

Right now each of my classes has a function static void print_info() { cout << "information here" << endl; } and the file with a main() calls print_info of each class.

Question: Is there a way to upkeep the version number automatically with changes?

Additional information:
I and my team use NetBeans for development. We also use Subversion (svn) and I know that it keeps revision numbers. Problem is only tangently related to the revision number. I want to be able to distribute an executable that will print the version number without accessing subversion server.

I'll be glad to provide more information if this is somewhat vague.
Thanks!

P.S.
I don't care what the version value is. Weather is an arbitrary number generated by NetBeans, or the corresponding subversion revision number, or just the date when the last modification was made.

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

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

发布评论

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

评论(3

醉生梦死 2024-10-13 03:29:30

您可以在源文件上使用 subversion Revision 属性,该属性会激活文件中的 $Revision$ 关键字替换。

string version = "$Revision:$";

http://svnbook.red-bean.com /en/1.4/svn.advanced.props.special.keywords.html

You could use a subversion Revision property on the source file which activates the $Revision$ keyword substitution within the file.

string version = "$Revision:$";

http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html

夜访吸血鬼 2024-10-13 03:29:30

首先,我建议您执行 print_info() 方法之外的其他方法,因为它不是很灵活 - 如果您想实际使用该版本而不是简单地将其打印到 STDOUT,或者如果您想实际使用该版本怎么办?希望将错误消息中的版本报告给 STDERR?返回 const char 字符串的 static 方法会更加通用。

关于版本号的选择,当然可以使用SVN关键字,可以是 替换 到代码正文中。例如(遵循所提供的链接中给出的示例),如果您有该行

char[] versionString = "commit revision $Rev$";

并启用了相应的关键字替换 svn propset svn:keywords "Rev" file.cpp,则下次执行时更新你的 SVN 客户端会将文本更新为类似的内容

char[] versionString = "commit revision $Rev: 12 $";

,下次提交时,该字符串将被覆盖为新的正确字符串,例如

char[] versionString = "commit revision $Rev: 13 $";

如果你使用 SVN 很好,你应该进行分支和标记,在这种情况下分支和标签信息(构成 $URL$ 关键字的一部分)是包含在版本字符串中的有用信息。 $Revision$ 对于为您提供在更新之间变化的值也很有用。但请记住,关键字仅在执行更新(签出、提交等)时更新。如果您对代码进行更改然后编译它,则报告的 $Revision$ 将与您最初签出代码时的相同。据我所知,避免陷入困境的唯一方法是在编译软件的新版本之前采用执行代码提交的过程 - 如果将其与标记版本的过程结合起来,那么效果很好SVN 内。

First off, I recommend you do something other than your print_info() approach, since it's not very flexible - what if you want to actually use the version rather than simple print it to STDOUT, or what if you wish to report the version in an error message to STDERR? A static method returning a const char string would be more versatile.

Regarding the choice of version number, you can certainly use SVN keywords, which can be substituted into the body of your code. For instance (following one the examples given in the link provided), if you have the line

char[] versionString = "commit revision $Rev$";

and have enable the corresponding keyword substitution svn propset svn:keywords "Rev" file.cpp, the next time you perform an update your SVN client will update the text to something like

char[] versionString = "commit revision $Rev: 12 $";

and the next time you commit it the string will be overwritten to the new correct string, such as

char[] versionString = "commit revision $Rev: 13 $";

If you use SVN well you should be branching and tagging, in which case the branch and tag info (which form part of $URL$ keyword) are useful things to include in your version string. $Revision$ is also useful for giving you a value that changes between updates. Remember, though, that keywords are only updated when you perform an update (checkout, commit, etc.). If you make changes to your code and then compile it, the reported $Revision$ will be the same as when you originally checked out the code. As far as I know, the only way to avoid being caught out by this is to adopt a procedure of performing a commit of your code before compiling a new release of you software - this works well if you combine it with a process of tagging releases within SVN.

留一抹残留的笑 2024-10-13 03:29:30

如果你想这样做,我会在每个源文件的开头使用 #define 并用文件的最后修改日期更新它(使用 $Date:$ 或更新这与您自己的脚本)。然后您可以非常轻松地使用 print_info() 中定义的常量。

If you want to do that like that I would go for a #define at the begging of each source file and update it with a last-modification date of a file (either using $Date:$ or updating this with your own script). You can then use the defined constant in print_info() very easily.

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