kmodtool, macros.kmp: support "+" for the kernel variant in uname

A patch[1] to the kernel spec file changed the separator that is used
for kernel flavor designation from "." to "+", which broke kmodtool and
%kernel_module_package in multiple places.  Try to accomodate it by
accepting both "+" and "." during parsing, and guessing which one should
be used for kernel osurce path generation.

PS. It looks like the analogous breakage was before, when it was changed
from "-" to ".". May be we should start support it back again as well.

[1] https://lists.fedoraproject.org/pipermail/kernel/2013-June/004262.html

* kmodtool (get_verrel, get_variant): Accept both "." and "+" as separators.
(get_variant_char, print_variant_char, print_kernel_source): New functions.
(get_filelist): Convert "+%1" in file list to $dotvariant, in addition
to ".%1" and "-%1".
(get_rpmtemplate): Determine a char that is used as a variant separator.
Use it in $dotvariant.
(usage): Mention "veriant_char" and "kernel_source" commands.
* macros.kmp (%kernel_module_package): Use "kernel_source" command in
"%kernel_source" definition when non-default variant is used; fall back
to ls-based heuristics when it is not available (for example, when a
version of kmodtool that doesn't support this command is used).

Resolves: #2002887
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
This commit is contained in:
Eugene Syromiatnikov 2019-01-25 14:34:52 +01:00
parent b4645cd8aa
commit 6a73d7992a
2 changed files with 61 additions and 4 deletions

View File

@ -52,7 +52,7 @@ variant=
get_verrel () get_verrel ()
{ {
verrel=${1:-$(uname -r)} verrel=${1:-$(uname -r)}
verrel=${verrel/%.$knownvariants/} verrel=${verrel/%[.+]$knownvariants/}
} }
print_verrel () print_verrel ()
@ -65,7 +65,7 @@ get_variant ()
{ {
get_verrel "$@" get_verrel "$@"
variant=${1:-$(uname -r)} variant=${1:-$(uname -r)}
variant=${variant/#$verrel?(.)/} variant=${variant/#$verrel?(.+)/}
variant=${variant:-'""'} variant=${variant:-'""'}
} }
@ -75,6 +75,45 @@ print_variant ()
echo "${variant}" echo "${variant}"
} }
# Detect flavor separator character. We have to do that due to
# a systemd-tailored patch for kernel spec[1][2] introduced in Fedora and then
# imported in RHEL 8 that broke all OOT kmod infrastructure for the flavored
# kernels.
#
# [1] https://lists.fedoraproject.org/pipermail/kernel/2013-June/004262.html
# [2] https://src.fedoraproject.org/rpms/kernel/c/faf25207dc86666a611c45ae3ffaf385c170bd2a
#
# $1 - kver
# $2 - variant
get_variant_char ()
{
variant="$2"
[ "$variant" != "default" ] || variant=""
get_verrel "$1"
variant_char=""
[ -n "$variant" ] || return 0
# We expect that the flavored kernel is already installed in the buildroot
variant_char="+"
[ -e "/usr/src/kernels/${verrel}+${variant}" ] && return 0
variant_char="."
}
print_variant_char ()
{
get_variant_char "$@"
echo "${variant_char}"
}
print_kernel_source ()
{
get_variant_char "$@"
echo "/usr/src/kernels/${verrel}${variant_char}${variant}"
}
get_filelist() { get_filelist() {
local IFS=$'\n' local IFS=$'\n'
filelist=($(cat)) filelist=($(cat))
@ -89,6 +128,7 @@ get_filelist() {
| sed -e "s/%variant/$variant/g" \ | sed -e "s/%variant/$variant/g" \
| sed -e "s/%dashvariant/$dashvariant/g" \ | sed -e "s/%dashvariant/$dashvariant/g" \
| sed -e "s/%dotvariant/$dotvariant/g" \ | sed -e "s/%dotvariant/$dotvariant/g" \
| sed -e "s/\+%1/$dotvariant/g" \
| sed -e "s/\.%1/$dotvariant/g" \ | sed -e "s/\.%1/$dotvariant/g" \
| sed -e "s/\-%1/$dotvariant/g" \ | sed -e "s/\-%1/$dotvariant/g" \
| sed -e "s/%2/$verrel/g") | sed -e "s/%2/$verrel/g")
@ -104,8 +144,11 @@ get_filelist() {
get_rpmtemplate () get_rpmtemplate ()
{ {
local variant="${1}" local variant="${1}"
get_variant_char "${verrel}" "${variant}"
local dashvariant="${variant:+-${variant}}" local dashvariant="${variant:+-${variant}}"
local dotvariant="${variant:+.${variant}}" local dotvariant="${variant:+${variant_char}${variant}}"
echo "%package -n kmod-${kmod_name}${dashvariant}" echo "%package -n kmod-${kmod_name}${dashvariant}"
@ -246,6 +289,10 @@ Usage: ${myprog} <command> <option>+
- Get "base" version-release. - Get "base" version-release.
variant <uname> variant <uname>
- Get variant from uname. - Get variant from uname.
variant_char <uname> <variant>
- Get kernel variant separator character.
kernel_source <uname> <variant>
- Get path to kernel source directory.
rpmtemplate <mainpgkname> <uname> <variants> rpmtemplate <mainpgkname> <uname> <variants>
- Return a template for use in a source RPM - Return a template for use in a source RPM
version version
@ -266,6 +313,16 @@ while [ "${1}" ] ; do
print_variant "$@" print_variant "$@"
exit $? exit $?
;; ;;
variant_char)
shift
print_variant_char "$@"
exit $?
;;
kernel_source)
shift
print_kernel_source "$@"
exit $?
;;
rpmtemplate) rpmtemplate)
shift shift
print_rpmtemplate "$@" print_rpmtemplate "$@"

View File

@ -31,7 +31,7 @@ kernel_module_package_release 1
done \ done \
fi \ fi \
echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \ echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \
echo "%%global kernel_source() /usr/src/kernels/%kverrel\\\$([ %%%%{1} = default ] || echo ".%%%%{1}")" \ echo "%%global kernel_source() \\\$([ default = \"%%%%{1}\" ] && echo \"/usr/src/kernels//%%%%kverrel\" || %{kmodtool} kernel_source \"%%%%{kverrel}\" \"%%%%{1}\" 2>/dev/null || { ls -Ud \"/usr/src/kernels///%%%%{kverrel}\"[.+]\"%%%%{1}\" | sort -V | tail -n 1; } || echo \"/usr/src/kernels////%%%%kverrel.%%%%1\")" \
echo "%%global kernel_module_package_moddir() extra" \ echo "%%global kernel_module_package_moddir() extra" \
if [ ! -z "%{-f*}" ] \ if [ ! -z "%{-f*}" ] \
then \ then \