Injecting mercurial changeset as version information in a C executable

♀尐吖头ヾ 提交于 2019-11-29 08:23:13

问题


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?

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

Thanks!

Setjmp


回答1:


Add this to configure.ac:

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

Add the following lines to 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.




回答2:


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:

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).

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




回答3:


See wiki page on versioning with make



来源:https://stackoverflow.com/questions/3593003/injecting-mercurial-changeset-as-version-information-in-a-c-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!