Automatically display the SVN version and the svn version of the automation program in the program

Source: Internet
Author: User
Tags svn client tortoisesvn

Automatically display the SVN version and the svn version of the automation program in the program
Sometimes there is such a situation where a bug is proposed with the app, but we are not sure which code version the app is installed on the mobile phone.

To solve this problem, we hope to display the code version of the current application, that is, the svn version.

After thinking about it, I hope the final results will be:

Automation. You do not need to perform this step every time you compile a version. For example, you can manually modify a value or click a script when you compile a version.
Cross-platform, win32, iOS, and Android versions released externally can be correctly displayed.
Comprehensive: the current code version can be displayed no matter if you use XCode or Eclipse for Windows vs development or Mac OS development, or when debugging or various platform packages are released.

The idea is as follows:

1. Automatic acquisition and storage of svn versions:

Run svn info in the Code directory managed by svn. You can see a series of information related to version information: Revision and Last Changed Rev.
Revision is the local version number, and Last Changed Rev is the version number specified in the selected directory. Select Last Changed Rev as needed.
You can use a script to obtain version data and save it to a directory that the program can use.

2. Automation:

You can use various IDE build events or some functions of the svn client, such as Hook scripts [1] of TortoiseSVN:

1) if the Hook scripts of TortoiseSVN is updated in the top-level directory, the update Hook of the internal source code directory is not triggered.
2). No similar features are found in Mac Versions.

I do not want this version data file to be managed by svn. Therefore, we decided to use various IDE compilation events.

A. VS setting method VS_Setting.png



PreBuildScript. bat


@echo offset src_dir=%~dp0..echo %src_dir%set keyword="Last Changed Rev"for /f "delims=" %%i in ('svn info %src_dir% ^| findstr /C:%keyword%') do set rev=%%iecho %rev%set rev=%rev:~18%@echo onecho %rev% > %src_dir%/CMWar_2dx/Resources/gen/Rev.gen




B. in XCode settings, you can use Build> Pre-actions [2]. However, if you set it in Build, you will not execute it when directly clicking Run for debugging, it is not elegant to set multiple places, and it is decided to set it in Build Phases.

For the setting method, refer to the "add Script" section in [3]. Pay special attention to "Run Script bar, move it to the second position in the list ", this determines whether the script execution time is before or after compilation.

XCodePreBuildScript. sh

#XCodePreBuildScript.sh#Ruoqian, Chen<piao.polar@gmail.com> #2014/7/25path=$(dirname $0)#gen revsrc_dir=$path/../CMWar_2dxecho src_dir $src_dirrev=`svn info $src_dir | awk -F ':' '{ if($1 ~ /^Last Changed Rev$/) {print $2} }' | tr -d " "`res_dir=$src_dir/CMWar_2dx/Resources/echo rev $revecho $rev > $res_dir/gen/Rev.gen#for xcode update bug#find $res_dir -type d -exec touch -cm {} \;touch -cm $res_dir/ini $res_dir/gen $res_dir/script

C. Eclipse version. Because the project is a 2dx game, Builder calls build_native.sh to execute the compilation. Just add the following code in a proper place.

GEN_PATH="$APP_ANDROID_ROOT"/assets/genif [ ! -d "$GEN_PATH" ]; then    mkdir "$GEN_PATH"fiversion=`svn info ../../CMWar_2dx | awk -F ':' '{ if($1 ~ /^Last Changed Rev$/) {print $2} }' | tr -d " "`echo $version > "$GEN_PATH"/Rev.gen



3. Because each IDE writes version information to Rev. gen before compilation, the program only needs to read Rev. gen data and display it. In this way, the current code version is automatically displayed. However, when SVN is updated, the Last Changed Rev of the Code directory changes accordingly.

After translation, Rev. gen will naturally change accordingly, achieving the goal of automated changes.


Other details:

A) The main reason why you need to add a level-1 directory gen is to pack files or folders that are not managed in the project in XCode, And Rev. gen we do not want to enter the version library, so we have to add a referenced folder gen to the XCode project and add the folder itself to version management.

B) Packaging optimization policy [2] [3] After XCode5, so that we need to touch it to package the latest Rev. gen into the version.

C. The co-developers may mistakenly upload Rev. gen. Submitting the ignore settings of Rev. gen to SVN can avoid this problem.

D) the Rev of the corresponding code version will be generated locally after compilation. gen information. You can use the information here to compare the SVN version to determine whether the current code version has been compiled. This can be used to check the Release script automatically.

set /p build_ver= < ..\..\CMWar_2dx\CMWar_2dx\Resources\gen\Rev.genif not "%rev%"=="%build_ver%" (    echo "Build Ver != rev"    pause    exit)



The txt version and the script files involved in this article have been packaged and uploaded to the http://download.csdn.net/detail/piao_polar/7678339

Parameters:
[1] http://www.cnblogs.com/loongwong/archive/2012/07/13/2590927.html
[2] http://blog.mutoo.im/2013/12/xcode-5-does-not-copy-bundle-resources-in-folder.html
[3] http://quick.cocos.org /? P = 22



How to obtain the SVN version number in the program

The content of svnversion. sh is as follows :#! /Bin/shVERFILE =. /include/Limit = 'svnversion-C' svn _ last_rev =$ {svn_last_rev_str ###:} echo "# define SVN_SERIAL $ svn_last_rev" $ VERFILE Step 2: In version. the SVN version within SVN_Serial.h is obtained for processing, so that the program can use the version. h: # ifndef _ VERSION_H _ # define _ VERSION_H _ # include "kernel" # define VERSION_HEAD "Ver" # define VERSION_PATCH SVN_SERIAL # define VERSION_COMP_DATE _ DATE __# define VERSION_COMP_TIME _ TI ME __# define _ VERSION_STRINGIZE (str) # str # define _ VERSION_STRING (num) _ VERSION_STRINGIZE (num) # define VERSION_STRING VERSION_HEAD \ _ VERSION_STRING (VERSION_PATCH) "" # define VERSION_COMP_DATA_TIME VERSION_COMP_DATE "-" \ VERSION_COMP_TIME # endifPS: Command: svn info can also obtain SVN-related information, but it cannot obtain the status after the current version is modified, that is: xxM.

Where is the svn Automatic startup configuration?

1. download the software * download the Subversion server program. Go to the official website to download the binary Installation File, go to the Binary Package download section, find Windows NT, 2000, XP and 2003, and then select "the same directory". In this example, we can see more content. Currently, we can download svn-1.4.6-setup.exe. * Download the Subversion Windows client TortoiseSVN. TortoiseSVN is a tool that extends Windows Shell and can be seen as a plug-in for Windows resource manager. After installation, Windows can identify the working directory of Subversion. The Official website is TortoiseSVN. The Download method is similar to that of the svn server. On the Download page, select Official version for Win2k/XP or higher, then on the sourceforge download page, select the current highest stable version of the Installation File TortoiseSVN-1.4.8.12137-win32-svn-1.4.6.msi, You can also download the Simplified Chinese Language Pack from the sourceforge language download page. 2. Install the * server on the server and client, run svn-1.4.6-setup.exe directly, and install it as prompted. In this way, we have an environment where the server can run. * Install TortoiseSVN, also directly run the TortoiseSVN-1.4.8.12137-win32-svn-1.4.6.msi according to the prompts to install, but after the completion of the last will prompt whether to restart, in fact, restart is just to make svn work copy in windows special style effective, it has nothing to do with all the actual functions. In order to immediately see the good results, restart the machine. 3. To create a version Library (Repository) to run the Subversion server, you must first create a version Library (Repository), which can be seen as a database for storing data on the server. After the Subversion server is installed, you can run it directly, for example, svnadmin create E: \ svndemo \ repository (you need to create a directory svndemo before that). A version library is created under directory E: \ svndemo \ repository. We can also use TortoiseSVN to graphically complete this step: in the directory E: \ svndemo \ repository (of course this directory needs to be empty) right-click and choose TortoiseSVN> Create Repository here... ", then you can select the version library mode. Here you can use the default mode, and then create a series of directories and files. 4. Configure users and permissions to go to the E: \ svndemo \ repository \ conf directory and modify svnserve. conf: # [general] # Change password-db = passwd to [general] password-db = passwd, modify the passwd file in the same directory, and remove the comments of the following three lines: # [users] # harry = harryssecret # sally = sallyssecret: [users] admin = admin (write the user name and password here for later access) 5, run the independent server in any directory: SC create svnserve binpath = "D: \ Program Files \ Subversion \ bin \ svnserve.exe -- service -- ro ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.