使用linux内核版本生成脚本setlocalversion

本文介绍了一种在Git仓库中自动化生成版本标识的方法,通过使用setlocalversion脚本结合localversion文件,能够根据仓库状态生成包含具体版本号、提交次数及最新提交哈希的版本标识,对于脏仓库还会附加-dirty标记。

使用效果

准备localversion文件,里面写上当前的版本

>>> echo "1.0.1" > localversion

运行版本生成脚本(需要在git仓库中运行)

>>> ./setlocalversion $(pwd)
1.0.1-00081-g3511b91

当仓库中的文件进行了修改(新增文件不算),会加-dirty,如下

>>> ./setlocalversion $(pwd)
1.0.1-00081-g3511b91-dirty

说明:

1.0.1:localversion中的内容
00081-g3511b91:这个字段来源于setlocalversion脚本中的git describe 2>/dev/null,这个命令的完整打印为V1.0.21-81-g3511b91脚本中进行了截取,去掉了git tag (V1.0.21) ,00081的意思是从标签(V1.0.21)到HEAD的提交次数,g3511b91是最近一次提交的hash

脚本修改

setlocalversion使用linux kernal代码中的scripts/setlocalversion,版本随意,这个脚本改动不大,这里使用的是4.1.15版本的内核;

要将setlocalversionyin应用在自己的项目中,修改脚本如下

diff --git a/scripts/setlocalversion b/setlocalversion
--- a/scripts/setlocalversion
+++ b/setlocalversion
@@ -140,12 +140,12 @@ if $scm_only; then
 	exit
 fi
 
-if test -e include/config/auto.conf; then
-	. include/config/auto.conf
-else
-	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
-	exit 1
-fi
+#if test -e include/config/auto.conf; then
+#	. include/config/auto.conf
+#else
+#	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
+#	exit 1
+#fi
 
 # localversion* files in the build and source directory
 res="$(collect_files localversion*)"
@@ -157,6 +157,9 @@ fi
 res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
 
 # scm version string if not at a tagged commit
+
+CONFIG_LOCALVERSION_AUTO="y"
+
 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
 	# full scm version string
 	res="$res$(scm_version)"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值