利用SVN实现自动版本号生成
来源:互联网 发布:linux copy文件夹命令 编辑:程序博客网 时间:2024/05/17 23:56
以 vc6 为例, 文件的版本信息保存在 rc 文件. 编译成 res 文件, 然后和其他 obj 一起 link. 现在的思路就是. 编辑 rc 文件, 将版本号比如 2.2.4.0 改成 2.2.4.$WCREV$, 在每次 link 之前, 先用 subwcrev.exe 处理 rc 文件, 进行宏替换. 然后调用
rc.exe 编译替换后的新文件. 生成 res 之后一起 link.……
/* * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <fstream>#include <sstream>#pragma warning(disable:4996)int main(int argc, char **argv){ std::string path; if(argc >= 1 && argv[1] ) { path = argv[1]; if(path.size() > 0 && (path[path.size()-1]!='/' || path[path.size()-1]!='//')) path += '/'; } FILE* EntriesFile = fopen((path+".svn/entries").c_str(), "r"); if(!EntriesFile) EntriesFile = fopen((path+"_svn/entries").c_str(), "r"); std::ostringstream newData; if(!EntriesFile) { newData << "#ifndef __SVN_REVISION_H__" << std::endl; newData << "#define __SVN_REVISION_H__" << std::endl; newData << " #define SVN_REVISION /"Unknown/"" << std::endl; newData << " #define SVN_DATE /"Unknown/"" << std::endl; newData << " #define SVN_TIME /"Unknown/""<< std::endl; newData << "#endif // __SVN_REVISION_H__" << std::endl; } else { char buf[200]; int revision; char date_str[200]; char time_str[200]; fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fscanf(EntriesFile,"%i",&revision); fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fgets(buf,200,EntriesFile); fscanf(EntriesFile,"%10sT%8s",date_str,time_str); newData << "#ifndef __SVN_REVISION_H__" << std::endl; newData << "#define __SVN_REVISION_H__" << std::endl; newData << " #define SVN_REVISION /"" << revision << "/"" << std::endl; newData << " #define SVN_REVISIONSTR /"" << revision/1000 << "." << revision%1000/100 << "." << revision%100/10 << "." << revision%10 << "/"" << std::endl; newData << " #define SVN_FILESTR " << revision/1000 << "," << revision%1000/100 << "," << revision%100/10 << "," << revision%10 << std::endl; newData << " #define SVN_DATE /"" << date_str << "/"" << std::endl; newData << " #define SVN_TIME /"" << time_str << "/""<< std::endl; newData << "#endif // __SVN_REVISION_H__" << std::endl; fclose(EntriesFile); } std::string oldData; if(FILE* HeaderFile = fopen((path+"svn_revision.h").c_str(),"rb")) { while(!feof(HeaderFile)) { int c = fgetc(HeaderFile); if(c < 0) break; oldData += (char)c; } fclose(HeaderFile); } if(newData.str() != oldData) { if(FILE* OutputFile = fopen((path+"svn_revision.h").c_str(),"wb")) { fprintf(OutputFile,"%s",newData.str().c_str()); fclose(OutputFile); } } return 0;}
在vc的precompile步骤里面调用gensvnrevision,生成svn_revision.h, 如:
#ifndef __SVN_REVISION_H__#define __SVN_REVISION_H__ #define SVN_REVISION "1707" #define SVN_REVISIONSTR "1.7.0.7" #define SVN_FILESTR 1,7,0,7 #define SVN_DATE "2010-02-02" #define SVN_TIME "01:36:29"#endif // __SVN_REVISION_H__
在 project.rc2里面添加include "svn_revision.h", 在版本里面用SVN_REVISIONSTR和SVN_FILESTR替换ProductVersion、FileVersion和 FILEVERSION 、PRODUCTVERSION 。
搞定!使用tsvn的童鞋们可以用第一种方法,要方便很 多!;-)
- 利用SVN实现自动版本号生成
- 利用SVN实现自动版本号生成
- 利用SVN实现自动修订版本号生成
- 利用SVN实现自动版本号生成
- 利用SVN实现版本号的自动增加
- SVN自动生成版本号
- [脚本]利用svn版本号动态生成version.h
- [脚本]利用svn版本号动态生成version.h
- eclipse中的Java文件自动根据svn版本号生成注释
- C# VS2008, VS2010 .NET 使用 SVN 的自动生成版本号
- eclipse中的Java文件自动根据svn版本号生成注释
- 工具——基于SVN自动生成版本号的方法
- SVN、GIT生成版本号
- [python]自动生成版本号
- c# 自动生成版本号
- 自动增加svn库版本号
- VS之版本-编译时自动生成版本-自动获取svn版本号
- 让IAR生成SVN版本号
- android 自定义view所需要的一些东西
- 闲聊linux中的input设备(9) 代代相传,何处是尽头
- 今天 是个好天气
- Windows 7下Grub4DOS引导安装Fedora14
- linq 如何查询 hashtable
- 利用SVN实现自动版本号生成
- w3school javascript教程
- DrawDib函数组的使用
- C++ String 详解
- Debug Tool-02-JVMTI 和 Agent 实现
- CSDN第一篇文章
- C++string类常用函数
- 华为三层以太网交换机基本原理及转发流程
- ASP.NET 动态转静态页面的两种方法总结