在使用Subversion管理的项目中使用Autoconf时,我会将此代码放入configure.ac :
AC_REVISION($Revision: 1234 $)使用svn:keywords Revision , AC_REVISION会将configure.ac的修订版号插入生成的configure脚本中。
我如何在Git管理的项目中做类似的事情?
Git没有像$Revision$这样的关键字,并且没有像这样的版本号。 但它确实具有提交的SHA1,并用git describe 。 我只是不知道如何将它纳入configure.ac 。
When using Autoconf in a project managed with Subversion, I would put this code in configure.ac:
AC_REVISION($Revision: 1234 $)With svn:keywords Revision, AC_REVISION would insert the revision number of configure.ac into the generated configure script.
How can I do something similar in a project managed with Git?
Git doesn't have keywords like $Revision$, and doesn't have revision numbers as such. But it does have SHA1s for commits, and git describe. I'm just not sure how to incorporate that into configure.ac.
最满意答案
Autoconf运行时,您可以使用M4实际执行任何命令。 因此,也许你想要的东西如:
AC_REVISION([m4_esyscmd_s([git describe --always])])请注意,与$Revision$字符串不同,每次更新树时configure.ac都不会更改。 因此,每次更新后configure都不会重新生成,并且修改放入configure将只是生成configure的最后一个版本。
adl's answer wasn't quite what I wanted, but it pointed me in the right direction. Here's what I came up with:
Put this in configure.ac:
AC_REVISION([m4_esyscmd([./tools/configure.commit])])Save this as tools/configure.commit (and make it executable):
#! /bin/sh # Display the SHA1 of the commit in which configure.ac was last modified. # If it's not checked in yet, use the SHA1 of HEAD plus -dirty. if [ ! -d .git ] ; then # if no .git directory, assume they're not using Git printf 'unknown commit' elif git diff --quiet HEAD -- configure.ac ; then # configure.ac is not modified printf 'commit %s' `git rev-list --max-count=1 HEAD -- configure.ac` else # configure.ac is modified printf 'commit %s-dirty' `git rev-parse HEAD` fiThat combination will put the SHA-1 of the commit in which configure.ac was last modified into configure, which is what I was looking for. But there's a problem. Git doesn't touch the modification time of files when it commits them. This means that configure will continue to contain the OLDSHA-dirty value instead of being updated, because autoconf won't realize that it's out of date.
You can solve that with a post-commit hook. Save this as .git/hooks/post-commit (and make sure you chmod it as executable, or it won't run):
#!/bin/sh # # Copy this to .git/hooks/post-commit # If configure.ac was just checked in, touch it, # so that configure will be regenerated and # AC_REVISION will reflect the new commit. # # For some reason, --quiet isn't actually quiet, # so redirect output to /dev/null git diff-tree --quiet HEAD -- configure.ac >/dev/null \ || touch -c configure.ac更多推荐
发布评论