将mercurial changeset注入C可执行文件中的版本信息

时间:2022-05-16 17:05:26

I would like the executables for a project I am working on to have the latest mercurial changeset recorded so that when a user complains about buggy behavior, I can track which version they are using. Some of my executables are Python and others are compiled C. Is there a way to automate this, or can you point me to projects that exhibit solutions that I can look at?

我希望我正在处理的项目的可执行文件记录了最新的mercurial变更集,以便当用户抱怨错误行为时,我可以跟踪他们正在使用的版本。我的一些可执行文件是Python,其他的是C编译。有没有办法自动化这个,或者你能指出我展示可以看到的解决方案的项目吗?

I am using autoconf in my project... in case that makes the solution easier.

我在我的项目中使用autoconf ...以防止解决方案更容易。

Thanks!

Setjmp

3 个解决方案

#1


5  

Add this to configure.ac:

将其添加到configure.ac:

AM_CONDITIONAL([IS_HG_REPO], [test -d "$srcdir/.hg"])

Add the following lines to Makefile.am:

将以下行添加到Makefile.am:

if IS_HG_REPO
AM_CPPFLAGS = -DHGVERSION="\"$(PACKAGE) `hg parents --template 'hgid: {node|short}'`\""
else
AM_CPPFLAGS = -DHGVERSION=PACKAGE_STRING
endif

This will define HGVERSION as a string of the form APPNAME hgid: 24d0921ee4bd or APPNAME VERSION, if building from a release tarball.

如果从发布tarball构建,这将HGVERSION定义为APPNAME hgid:24d0921ee4bd或APPNAME VERSION形式的字符串。

#2


6  

A common way to do this is with m4_esyscmd. For example, autoconf distributes a script in build-aux which generates a version number from the git repo and invokes AC_INIT as:

执行此操作的常用方法是使用m4_esyscmd。例如,autoconf在build-aux中分发一个脚本,它从git repo生成一个版本号,并调用AC_INIT:

AC_INIT([GNU Autoconf], m4_esyscmd([build-aux/git-version-gen .tarball-version]), 
  [bug-autoconf@gnu.org])

You can often get away without distributing the script and do something simple like:

您可以经常离开而不分发脚本并执行以下操作:

AC_INIT([Package name], m4_esyscmd([git describe --dirty | tr -d '\012']), 
  [bug-report-address])

Instead of git-describe, use whatever command you want to generate the version number. One important detail is that it should not have a trailing newline (hence the tr following git-describe).

而不是git-describe,使用您想要生成版本号的任何命令。一个重要的细节是它不应该有一个尾随换行符(因此跟随git-describe的tr)。

A major drawback with this technique is that the version number is only generated when you run autoconf.

此技术的一个主要缺点是版本号仅在运行autoconf时生成。

#3


1  

See wiki page on versioning with make

有关make的版本控制,请参阅wiki页面

#1


5  

Add this to configure.ac:

将其添加到configure.ac:

AM_CONDITIONAL([IS_HG_REPO], [test -d "$srcdir/.hg"])

Add the following lines to Makefile.am:

将以下行添加到Makefile.am:

if IS_HG_REPO
AM_CPPFLAGS = -DHGVERSION="\"$(PACKAGE) `hg parents --template 'hgid: {node|short}'`\""
else
AM_CPPFLAGS = -DHGVERSION=PACKAGE_STRING
endif

This will define HGVERSION as a string of the form APPNAME hgid: 24d0921ee4bd or APPNAME VERSION, if building from a release tarball.

如果从发布tarball构建,这将HGVERSION定义为APPNAME hgid:24d0921ee4bd或APPNAME VERSION形式的字符串。

#2


6  

A common way to do this is with m4_esyscmd. For example, autoconf distributes a script in build-aux which generates a version number from the git repo and invokes AC_INIT as:

执行此操作的常用方法是使用m4_esyscmd。例如,autoconf在build-aux中分发一个脚本,它从git repo生成一个版本号,并调用AC_INIT:

AC_INIT([GNU Autoconf], m4_esyscmd([build-aux/git-version-gen .tarball-version]), 
  [bug-autoconf@gnu.org])

You can often get away without distributing the script and do something simple like:

您可以经常离开而不分发脚本并执行以下操作:

AC_INIT([Package name], m4_esyscmd([git describe --dirty | tr -d '\012']), 
  [bug-report-address])

Instead of git-describe, use whatever command you want to generate the version number. One important detail is that it should not have a trailing newline (hence the tr following git-describe).

而不是git-describe,使用您想要生成版本号的任何命令。一个重要的细节是它不应该有一个尾随换行符(因此跟随git-describe的tr)。

A major drawback with this technique is that the version number is only generated when you run autoconf.

此技术的一个主要缺点是版本号仅在运行autoconf时生成。

#3


1  

See wiki page on versioning with make

有关make的版本控制,请参阅wiki页面