SVN、GIT生成版本号

时间 : 14-12-12 栏目 : Android, CI, iOS, 移动开发, 集成测试 作者 : meiw@z3a105.com 评论 : 0 点击 : 427 次

李迟按:代码管理较多的是使用svn、git这类的版本管理工具,版本号是一个重要的东西,自然地,如何让我们显式地看到版本号是十分重要的。一般地,会通过某种手段让当前代码的版本号声明为宏定义字符串,或打印在串口上,或传输到上位机显示。这里介绍了svn和git的版本号生成方式。

SVN生成编译版本号脚本:

# file name: svn_local_ver_build.sh
#!/bin/bash
VER_FILE=version.h
LOCALVER=`svn info | cat -n | awk ‘{if($1==5)print $3}’`
echo “LOCALVER:” $LOCALVER
VER=r$LOCALVER
echo “Generated” $VER_FILE
echo “#ifndef PROJECT_VERSION_H” > $VER_FILE
echo “#define PROJECT_VERSION_H” >> $VER_FILE
echo “” >> $VER_FILE
echo “#define VERSION_NUMBER \”$VER\“” >> $VER_FILE
echo “” >> $VER_FILE
echo “#endif” >> $VER_FILE
echo “Job done!!”

方法:
先在SVN工作目录中查看SVN信息,再从这些信息中截取版本号,上面脚本中的命令语句执行得到下列结果:

atelee@latelee:mylib$ ls
branches  tags  trunk
latelee@latelee:mylib$ svn info | cat -n
1  路径: .
2  URL: https://latelee.org/svn/mylib3  版本库根: https://latelee.org/svn/mylib4  版本库 UUID: 1f5fb548-7608-e145-84f5-f0a17695809a
5  版本: 4
6  节点种类: 目录
7  调度: 正常
8  最后修改的作者: latelee
9  最后修改的版本: 4
10  最后修改的时间: 2012-03-02 11:31:59 +0800 (五, 2012-03-02)
11

awk ‘{if($1==5)print $3}’的意思是将第5行号的第3列打印出来。这个就是我们想要的版本号了。

GIT生成编译版本号脚本:

# file name: git_local_ver_build.sh
#!/bin/bash
VER_FILE=version.h
LOCALVER=`git rev-list HEAD | wc -l | awk ‘{print $1}’`
echo “LOCALVER:” $LOCALVER
VER=r$LOCALVER
VER=“$VER $(git rev-list HEAD -n 1 | cut -c 1-7)”
GIT_VERSION=$VER
echo “Generated” $VER_FILE
echo “#ifndef PROJECT_VERSION_H” > $VER_FILE
echo “#define PROJECT_VERSION_H” >> $VER_FILE
echo “” >> $VER_FILE
echo “#define VERSION_NUMBER \”$GIT_VERSION\“” >> $VER_FILE
echo “” >> $VER_FILE
echo “#endif” >> $VER_FILE
echo “Job done!!”

方法:
GIT的版本号是一个 40 位的 SHA-1 的哈希值,但我们不使用这个值作为版本号,r16比d51f6f0b5eb202bbe6204246187d35df43aa6ef8更容易看一些。我们先使用git rev-list HEAD命令打印所有GIT版本,再通过wc计数,得到的数字就是我们想要的版本号(万一版本号有10000个,不知道这样做好不好)。另外,我们在数字的版本号后面加上哈希值的前7位,这使得数字的版本号和哈希值的版本号对应起来。
生成的文件示例:

#ifndef PROJECT_VERSION_H
#define PROJECT_VERSION_H
#define VERSION_NUMBER “r16 d51f6f0″
#endif

补记:可以在版本号添加分支名称,语句如下:

BRANCH=`git branch | awk ‘{if ($1==”*”) print $2}’`
GIT_VERSION=”$VER $BRANCH”

另一个较复杂的GIT生成编译版本号脚本:

# file name: git_build_version.sh
#!/bin/bash
VER_FILE=version.h
git rev-list HEAD | sort > config.git-hash
LOCALVER=`wc -l config.git-hash | awk ‘{print $1}’`
echo “LOCALVER:” $LOCALVER
if [ $LOCALVER \> 1 ]  ; then
VER=`git rev-list origin/master | sort | join config.git-hash – | wc -l | awk ‘{print $1}’`
if [ $VER != $LOCALVER ]  ; then
VER=“$VER+$(($LOCALVER-$VER))”
fi
if git status | grep -q “modified:”  ; then
VER=“${VER}M”
fi
VER=“$VER $(git rev-list HEAD -n 1 | cut -c 1-7)”
GIT_VERSION=r$VER
else
GIT_VERSION=
VER=“x”
fi
rm -f config.git-hash
echo “VER: “ $VER
echo “GIT_VERSION: “ $GIT_VERSION
echo “Generated” $VER_FILE
echo “#ifndef PROJECT_VERSION_H” > $VER_FILE
echo “#define PROJECT_VERSION_H” >> $VER_FILE
echo “” >> $VER_FILE
echo “#define VERSION_NUMBER \”$GIT_VERSION\“” >> $VER_FILE
echo “” >> $VER_FILE
echo “#endif” >> $VER_FILE
echo “Job done!!”

这个脚本需要join命令的支持,在windows上join.exe命令需要msys-iconv-2.dll、msys-intl-8.dll动态库的支持。如果安装了MinGW,可以从安装目录中直接获取。

 

本文标签 , , ,

除非注明,文章均为( meiw@z3a105.com )原创,转载请保留链接: http://blog.z3a105.com/?p=357

SVN、GIT生成版本号:等您坐沙发呢!

发表评论





       ==QQ:122320466==

 微信    QQ群

推广

  • 104726drf320ff09r7i62f.jpg
  • 103217vn3333zbk3snwz2u.jpg

0

Aujourd’hui, une partie avec le développement du e-commerce, achats en ligne est devenu une partie de la vie pour beaucoup de gens. La mariage a commencé achats en ligne. Si vous choisissez achats les mariages en ligne, il peut être beaucoup moins cher que le salon de la Robe de mariée pas chermariée local, réduisant le budget de mariage. vous pouvez avoir beaucoup de choix si acheter de mariage en ligne. vous pouvez ramasser une robe de mariée bon marché sur Internet.
Piercing fascinerande figur, och nu tittar vi på 2016 senast brudklänning, kan du vara den vackraste bruden det!2016 senaste Bra brudklänning, söt temperament Bra design, romantiska spetsar blomma kjol, som du lägger till en elegant och charmig temperament.Kvinnan tillbaka mjuka linjer, människor brudklänningofta få en känsla av oändlig frestelse. Fall 2016 mässan, lämnar uppgifter om ditt bröllop charmig.
Yesterday afternoon, the Chinese team was training in the Guangzhou Gymnasium, when the reporter asked Zhao Yunlei the feeling of wearing the new cheap jersey , cheap jerseys online shopshe readily took a shirt from the bag crumpled ball to reporters, and she said with a smile: ” This shirt is light. ”Zhao Yunlei said: “Our material is very light like with the clothes of the tennis King Nadal, Federer, after the sweat, sweat does not drip down to the ground, when we do move, it is easy pace slipping if the sweat drip on the floor.”Tennis players Zhang Yawen, told reporters: “You might think the clothes attached to the body, fearing we swing will be affected, in fact, we do not feel anything, because the clothes are very light, very soft, put on quite comfortable. And it’s particularly good clothes to dry, washing and will dry in 15 minutes. ”
China’s sports enthusiasts NFL sweatshirt with mad love and the pursuit of, and therefore, NFL jerseys have a good market in China and development. China is a populous country, is the consumer, the economic momentum is so good, the sales prospects sportswear is immeasurable. With hot sales sweatshirt, but also to promote the importance of sports fans, on health, on the other hand is a matter of concern for the World Cup, fans wearing NFL jerseys and also can express themselves more fully love and obsession Therefore, NFL jerseys Wholesale jerseys online shopwholesale has good prospects and development in China.
ANTA-ANTA Sports Products Limited, referred to as ANTA Sports, Anta, is China’s leading sporting goods companies, mainly engaged in the design, development, manufacture and marketing of ANTA brand sporting goods, including sports footwear, apparel and accessories. Anta sweatshirt design advantages, warm stretch knit fabric, using Slim version of model, more personal fit, bid farewell to bloated, so wearing more stylish.GUIRENNIAO-This logo is a spiritual totem, smooth graphics implication unstoppable force; flexible deliver an elegant arc Wholesale jerseys china shop movement, strength and speed of the United States, a symbol of passion and rationality publicity “Heart” and “meaning”, “concept” unity; pass the fearless and enterprising mind, showing beyond the realm of self, to unstoppable force to create the future.XTEP-Xtep (China) Co., Ltd. is a comprehensive development wholesale jerseys china shop, production and marketing of Xtep brand (XTEP) sports shoes, clothing, bags, caps, balls, socks mainly large sporting goods industry enterprises.
There are a lot of fans in identifying the authenticity of the above cheap jerseys have great distress, so here to i will show you some methods to definitely affordable inexpensive cheap jerseys : Firstly, we should look at if it is working fine. China has been called the world’s factory, a lot cheap jerseys factories in China have foundries, but our cheap jerseys are all from here! Secondly, should to see whether it is the , we all know that it is difficult to get out of print once a genuine cheap cheap jerseys free shipping jersey was print. and we have all kind of stocka on the whole website, in other words, we have all you want ! Finally, look at the price, our price is not necessarily the lowest in the whole website but it must be most fair on the whole website, we certainly you will not regret later when you buy it. Of course, except that cheap jerseys, we also have the other products, such as socks, leggings and some other related products, everyone can enjoy the best services of here!