ANDROID: setlocalversion: Add a flag to keep tag info

When the kernel head is at a tagged commit, the generated kernel
version will have neither the tag nor the commit hash.

So, unless we manually set EXTRAVERSION in the Makefile when releasing
a new kernel, it is hard to pinpoint the exact kernel release version.

Alternatively, let's add an option to keep the tag info when the kernel
head is at a tagged commit.

This fix only helps when building kernel with build.sh.
Since Android 14 has switched to Bazel, and Bazel uses a different
mechanism (workspace_status_stamp.py) to set up kernel version, the fix
doesn't need to go to Android 14 or newer kernel branches.

Bug: 266829022
Test: build kernel and verify the tag is embedded in the kernel version

Signed-off-by: Philip Chen <philipchen@google.com>
Change-Id: I40bbc414d103567bcc92985f6d63ae27aac8c9b1
This commit is contained in:
Philip Chen
2023-04-07 10:37:25 -07:00
committed by Treehugger Robot
parent 5e6e9c596b
commit 67510f5083
2 changed files with 14 additions and 7 deletions

View File

@@ -1291,7 +1291,7 @@ $(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
filechk_kernel.release = \
echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \
$(srctree) $(BRANCH) $(KMI_GENERATION))"
--save-tag $(srctree) $(BRANCH) $(KMI_GENERATION))"
# Store (new) KERNELRELEASE string in include/config/kernel.release
include/config/kernel.release: FORCE

View File

@@ -11,11 +11,12 @@
#
usage() {
echo "Usage: $0 [--save-scmversion] [srctree] [branch] [kmi-generation]" >&2
echo "Usage: $0 [--save-scmversion] [--save-tag] [srctree] [branch] [kmi-generation]" >&2
exit 1
}
scm_only=false
save_tag=false
srctree=.
android_release=
kmi_generation=
@@ -23,6 +24,10 @@ if test "$1" = "--save-scmversion"; then
scm_only=true
shift
fi
if test "$1" = "--save-tag"; then
save_tag=true
shift
fi
if test $# -gt 0; then
srctree=$1
shift
@@ -69,11 +74,11 @@ scm_version()
elif [ -n "$android_release" ]; then
printf '%s' "-$android_release"
fi
# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
# it, because this version is defined in the top level Makefile.
if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
# If we are at a tagged commit (like "v2.6.30-rc6"), by default
# we ignore it and manually define VERSION in the top level
# Makefile. Alternatively, set --save-tag to keep the tag.
tag="$(git describe --exact-match 2>/dev/null)"
if [ -z "$tag" ]; then
# If only the short version is requested, don't bother
# running further git commands
if $short; then
@@ -88,6 +93,8 @@ scm_version()
# Add -g and exactly 12 hex chars.
printf '%s%s' -g "$(echo $head | cut -c1-12)"
elif $save_tag; then
printf '%s' - "$(echo $tag)"
fi
# Check for uncommitted changes.