gpt4 book ai didi

mercurial - 我使用 Mercurial Hook 将版本号嵌入到我的应用程序中的方法有多好?

转载 作者:行者123 更新时间:2023-12-04 11:45:14 25 4
gpt4 key购买 nike

这不是一个非常具体的问题,我更喜欢批评我目前的方法。

我想在我正在开发的程序中包含程序版本号。这不是商业产品,而是研究应用程序,因此了解哪个版本生成结果非常重要。

我的方法如下:

  • 我的 .hg/hgrc 文件链接中有一个“预提交” Hook ,指向 version_gen.sh
  • version_gen.sh 仅包含:hg parent --template "r{rev}_{date|shortdate}" > version.num
  • 在 makefile 中,行 version="%__VERSION__%主脚本中的内容替换为 version.num 文件的内容。

  • 有没有更好的方法来做到这一点?我能看到的唯一真正的缺点是,如果你只提交一个特定的文件,version.num 将被更新,但它不会被提交,如果我尝试添加总是提交该文件,那将导致无限循环(除非我创建了一些临时文件来表明我已经在提交中,但这看起来很难看......)。

    最佳答案

    问题

    如您所见,您确实创建了 Catch-22这里的情况。

    您不能在 version.num 中真正放入有意义的信息。文件,直到提交更改并且因为您正在存储 version.num在存储库中,在填充 version.num 之前,您不能将更改提交到存储库。文件。

    我的解决方案

    我的建议是:

  • 摆脱“预提交”钩子(Hook)和hg forget version.num文件。
  • 添加 version.num给您的.hgignore文件。
  • 调整version_gen.sh包括:
    hg parent --template "r{node|short}_{date|shortdate}" > version.num
  • 在 makefile 中,确保 version_gen.shversion.num 之前运行用于设置版本参数。

  • 我的理由

    @Ry4an suggests ,让构建系统在构建时将修订信息插入到软件中,使用来自版本控制系统的信息是一个更好的选择。唯一的问题是如果您尝试从 hg archive 编译代码。存储库的,其中构建系统无法提取相关信息。

    但是,我倾向于不鼓励这样做 - 在我自己的构建系统中,如果无法提取修订信息,则构建失败。

    此外,如 @Kai Inkinen suggests ,使用修订号是不可移植的。一台机器上的 Rev 21 可能是另一台机器上的 rev 22。虽然现在这可能不是问题,但如果您开始与其他人合作,它可能会在 future 出现。

    最后,我解释了我不喜欢 question 中的关键字扩展的原因。我的,它涉及与您自己的问题类似的问题:

    I looked at Mercurials Keyword extension, since it seemed like the obvious solution. However the more I looked at it and read peoples opinions, the more that I came to the conclusion that it wasn't the right thing to do.

    I also remember the problems that keyword substitution has caused me in projects at previous companies. ...

    Also, I don't particularly want to have to enable Mercurial extensions to get the build to complete. I want the solution to be self contained, so that it isn't easy for the application to be accidentally compiled without the embedded version information just because an extension isn't enabled or the right helper software hasn't been installed.



    然后在对建议使用 keyword 的答案的评论中无论如何扩展:

    ... I rejected using the keyword extension as it would be too easy to end up with the string "$Id$" being compiled into the executable. If keyword expansion was built into mercurial rather than an extension, and on by default, I might consider it, but as it stands it just wouldn't be reliable. – Mark Booth

    A don't think that there can be a more reliable solution. What if someone accidentally damages .hg or builds not from a clone but from an archive? – Mr.Cat

    @Mr.Cat - I don't think there can be a less reliable solution than the keywords extension. Anywhere you haven't explicitly enabled the extension (or someone has disabled it) then you get the literal string "$ID$" compiled into the object file without complaint. If mercurial or the repo is damaged (not sure which you meant) you need to fix that first anyway. As for hg archive, my original solution fails to compile if you try to build it from an archive! That is precisely what I want. I don't want any source to be compiled into our apps without it source being under revision control! – Mark Booth

    关于mercurial - 我使用 Mercurial Hook 将版本号嵌入到我的应用程序中的方法有多好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2558531/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com