40

I'd like to implement a way of recording the version of a project within code, so that it can be used when testing and to help track bugs. It seems the best version number to use would just be the current revision number from Subversion. Is there an easy way to hook this number into a (C++ in my case) header file or something, which I can then get at in code? I guess this is a post commit hook or something?

Does anyone have any experience of implementing this (with code to share, please?), or can suggest a better alternative? Thanks.

4

6 に答える 6

27

Two ways:

Embed $Id$ or $Revision$ within the code. Then set svn:keywords="Id Revision" property on the file. This will give you the last modified revision of that source file. Good for smaller projects and scripts.

Alternatively, use a Makefile driven process and the command line tool svnversion. (Language specific - this should work for C/C++)

echo -n "#define VERSION 1.0.1-" > version.h
svnversion -n . >> version.h

Or some more complex build script with sed and version.h.in. Then just #include version.h

That will give you the repository version number, which will change with every commit / update, and is probably a more appropriate version number for most projects.

Note: I also used a human readable version string that I manually update. The example would give: Version: 1.0.1-r13445

~J

于 2008-08-19T14:30:18.310 に答える
14

リビジョン キーワード トリックは気の利いたものですが、そのリビジョンで変更された場合にのみファイルを更新します。ファイルを変更しない場合は、古いリビジョンが引き続き反映されます。

ソフトウェアに常に全体的なリビジョン番号を反映させたい場合は、関連する SVN エントリ ファイルを掘り下げて抽出する必要がありますが、これはそれほど難しくありません (これは XML ファイルです)。

ウィキペディアは、ライブで実行されているソフトウェアのリビジョンを示すために、バージョン ページでこれを行います。コードはここにあります- getSvnRevision()メソッドを探してください。

于 2008-08-30T04:23:00.737 に答える
14

TortoiseSVN の一部である SubWCRev を使用することもできます。

SubWCRev は、Subversion 作業コピーのステータスを読み取り、オプションでテンプレート ファイル内のキーワード置換を実行するために使用できる Windows コンソール プログラムです。これは、構築中のオブジェクトに作業コピー情報を組み込む手段として、構築プロセスの一部としてよく使用されます。通常、「バージョン情報」ボックスにリビジョン番号を含めるために使用されます。

http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html

于 2008-10-09T10:16:43.867 に答える
6

Makefile に以下を追加します。

SVNDEV := -D'SVN_REV="$(shell svnversion -n .)"'
CFLAGS := $(SVNDEV) ...

SVN_REV次に、コード内の任意の場所でマクロを使用できます。たとえば、次のようになります。

printf ("Version: SVN %s\n", SVN_REV);
于 2013-05-11T00:51:21.383 に答える
5

You can use the svn:keywords property to enable the Rev keyword.

You can then use $Rev$ in your code and SVN will expand it automatically when updating to $Rev: 256 $ which can then parse...

More info on the Subversion manual

于 2008-08-19T14:26:10.737 に答える
0

適切な最新のソリューション:

次の行を含む を作成しますMakefile( と同じフォルダ内YourFile.dox)。

sed "s~RevNumber~$(shell svnversion ../)~g" YourFile.dox > YourFileDummy.dox; doxygen YourFileDummy.dox

そしてYourFile.dox、これを含める必要があります:

...
PROJECT_NUMBER         = "Revision RevNumber"
...

今:

  1. sed.doxRevNumbersvnversion(リポジトリのメイン フォルダーで実行された) の出力に置き換え、変更されたファイルを次の場所に保存します。YourFileDummy.dox
  2. doxygenYourFileDummy.doxドキュメントを生成するために実行されます
  3. ドキュメントにリビジョン番号が含まれるようになりました。
于 2017-04-18T09:26:41.893 に答える