8

C/C++ コードに Mercurial タグを埋め込む方法があるかどうか知りたいです。

基本的には、最終的にリリース番号 (major.minor.rev) になるタグ文字列を、C コードの特定の場所に静的文字列として自動的に挿入したいと考えています。

全体的な目的は、たとえば「-v」コマンド ライン引数を使用してアプリケーションを実行したときに、アプリケーションのバージョン番号を照会できるようにすることです。Mercurial タグを埋め込まない代替アプローチも、回答として歓迎されます。

Linux 環境で Code::Blocks を使用しているため、ソリューションは Visual Studio の機能に依存できません。

4

2 に答える 2

6

キーワード エントリの拡張を許可するには、キーワード拡張が必要です。これは Mercurial にバンドルされています。

たとえば、サポートを受けるには、レポ ( )$Id$の hgrc を編集して次を追加します。.hg/hgrc

[extensions]
keyword =

[keyword]
# Enable expansion for the specific files
myfile.cpp =
# Enable for all .h files
**.h =

次に実行します

hg kwexpand

関連するファイルのキーワードを展開する、または

hg kwshrink

キーワードを縮小します。[keywordmaps]エントリを追加して、独自のキーワードを作成することもできます。

[keywordmaps]
User = {author|user}

:これにより、組み込みのキーワードが無効になります

拡張機能の詳細については、wikiを参照してください。

于 2010-02-12T18:41:36.400 に答える
0

We use a macro for this

#define CVS(a) static const volatile char *rcsid = a;

....
CVS("$Id$")

CVS automagically expands $Id$. I assume this is what mercurial tags work as well.

Then we can use the strings command to find the exact version of each file in the executable / library etc.

You could use something similar.

static const volatile char *rcsid = "$Id"; //or whatever mercurial tag you want

int main() {

    .....
    std::cout << "Version is " << rcsid << std::endl;
}
于 2010-02-12T18:15:10.513 に答える