我如何在Git中使用AC

编程入门 行业动态 更新时间:2024-10-24 02:36:49
如何在Git中使用AC_REVISION?(How can I use AC_REVISION with Git?)

在使用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` fi

That 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

更多推荐

本文发布于:2023-07-28 18:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Git   AC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!