使用效果
准备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)"

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

被折叠的 条评论
为什么被折叠?



