如何将Subversion版本号包含到Delphi项目中 [英] How to include Subversion revision number into Delphi project

查看:116
本文介绍了如何将Subversion版本号包含到Delphi项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要修改Delphi源代码和exe版本的源代码。自动执行此操作的最佳方式是什么?



我想在关于屏幕和项目的版本信息中显示修订号。 p>

我正在使用Delphi IDE(2006/2007)和Tortoise SVN。

解决方案>

我同意关于 $ Revision $ 的评论不是正确的工作工具。使用工具从 svn info 的输出中提取版本号确实是正确的事情。



还有两件事要注意:


  1. svn 信息只有在具有签出来源的目录上运行 svn 更新之后,系统才会返回正确的信息。如果您使用自定义构建步骤,您应该也可以为其添加命令。


  2. svn 信息还提供有关存储库路径的信息。这是区分 trunk 和其他地方的源的唯一方式,如标签。如果您希望关于框包含字符串以正确识别用于构建应用程序的源,请确保存储库路径也可用。


编辑:



这是一个应该被复制到项目顶级目录的命令脚本。它将从存储库更新源,从 svn info 调用获取SVN修订号,并将其与文件 src \SvnRev.inc 中的常量SVN_REVISION进行比较。如果文件丢失,它将创建它,如果修订版本不同,它将覆盖它。如果 svn 不可用,则会将修订号0写入该文件。



生成的文件 src\SvnRev.inc 可以简单地包含在源文件中。可以创建类似的文件以包含在版本资源中。

  @echo off 

setlocal
rem从命令文件名确定项目顶级目录
set PRJDIR =%〜dp0
cd%PRJDIR%

set SVNREVFILE = src\SvnRev.inc

rem执行svn info,提取修订:1234行,并从中获取SVN rev
svn update
for / Fusebackq tokens = 1,2 delims = :%% i in(`svn info`)do set key = %% i& set value = %% j& call:read-svn-rev
@echo SVN revision%SVNREV%

rem extractconst SVN_REVISION = 1234;行,并从头上获取标题SVN rev $ / $ F $$(%SVNREVFILE%)中设置name = %% i& set value = %% j& call: read-file-rev
@echo包含文件版本%FILEREV%

rem检查有效的SVN rev
如果%SVNREV%EQUgoto:no- svn-ref
rem如果SVN ref相等,则不写入文件
如果%FILEREV%EQU%SVNREV%goto:EOF

@echo编写svn revision% SVNREV%到%SVNREVFILE%
@echo const SVN_REVISION =%SVNREV%; > %SVNREVFILE%
goto:EOF

:no-svn-ref
如果不存在%SVNREVFILE%goto:no-header-file
rem不写文件如果SVN参考已经取消设置
如果%FILEREV%EQU0goto:EOF
@echo将svn修订版0写入%SVNREVFILE%
goto:write-no-version

:no-header-file
@echo使用svn revision创建%SVNREVFILE%0
:write-no-version
@echo const SVN_REVISION = 0; > %SVNREVFILE%
goto:EOF

endlocal
goto:EOF

:read-svn-rev
如果%key% EQURevision设置SVNREV =%value%&
goto:EOF

:read-file-rev
如果%name%EQUSVN_REVISION设置FILEREV =%value%&
goto:EOF


I'd like to have revision number of source code to Delphi's source code and exe version. What is the best way to do this automatically?

I'd like to display the revision number in "About" screen and in the version info of the project.

I'm using currently Delphi IDE (2006/2007) and Tortoise SVN.

解决方案

I agree with the comments about $Revision$ not being the right tool for the job. Using a tool to extract the revision number from the output of svn info is indeed the correct thing to do.

There are however two more things to note:

  1. svn info will only return the correct information if svn update has been run on the directory with the checked out sources. If you use custom build steps you should probably add a command for it too.

  2. svn info gives you also information about the repository path. This is the only way to differentiate between sources in trunk and somewhere else, like in tags. If you want your About box to contain a string to correctly identify the sources used to build the application, make sure that the repository path is available too.

Edit:

This is a command script that should be copied to the project top level directory. It will update the sources from the repository, get the SVN revision number from the svn info call and compare it with the constant SVN_REVISION from the file src\SvnRev.inc. If the file is missing it will create it, if the revision is different it will overwrite it. If svn is not available it will write the revision number 0 to the file.

The resulting file src\SvnRev.inc can simply be included in a source file. A similar file could be created to be included in the version resource.

@echo off

setlocal
rem determine project top level directory from command file name
set PRJDIR=%~dp0
cd %PRJDIR%

set SVNREVFILE=src\SvnRev.inc

rem execute "svn info", extract "Revision: 1234" line, and take SVN rev from there
svn update
for /F " usebackq tokens=1,2 delims=: " %%i in (`svn info`) do set key=%%i&set value=%%j&call :read-svn-rev
@echo SVN revision "%SVNREV%"

rem extract "const SVN_REVISION = 1234;" line, and take header SVN rev from there
for /F " usebackq tokens=2,4 " %%i in (%SVNREVFILE%) do set name=%%i&set value=%%j&call :read-file-rev
@echo Include file revision "%FILEREV%"

rem check for valid SVN rev
if "%SVNREV%" EQU "" goto :no-svn-ref
rem do not write file if SVN ref is equal
if "%FILEREV%" EQU "%SVNREV%" goto :EOF

@echo Writing svn revision %SVNREV% to %SVNREVFILE%
@echo const SVN_REVISION = %SVNREV% ; > %SVNREVFILE%
goto :EOF

:no-svn-ref
if not exist %SVNREVFILE% goto :no-header-file
rem do not write file if SVN ref is already unset
if "%FILEREV%" EQU "0" goto :EOF
@echo Writing svn revision 0 to %SVNREVFILE%
goto :write-no-version

:no-header-file
@echo Creating %SVNREVFILE% with svn revision 0
:write-no-version
@echo const SVN_REVISION = 0 ; > %SVNREVFILE%
goto :EOF

endlocal
goto :EOF

:read-svn-rev
if "%key%" EQU "Revision" set SVNREV=%value%&
goto :EOF

:read-file-rev
if "%name%" EQU "SVN_REVISION" set FILEREV=%value%&
goto :EOF

这篇关于如何将Subversion版本号包含到Delphi项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆