[v2] build: try to get kernel version from kernel source

Message ID 20220303131543.31246-1-rpm@fthiessen.de (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2] build: try to get kernel version from kernel source |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Ferdinand Thiessen March 3, 2022, 1:15 p.m. UTC
  When building the kernel modules, try to get the kernel
version from the kernel sources first. This fixes the
kernel modules installation directory if the target kernel
version differs from the host kernel version, like for
CI build or when packaging for linux distributions.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
---
 kernel/linux/meson.build | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
  

Comments

Ferruh Yigit March 8, 2022, 3:54 p.m. UTC | #1
On 3/3/2022 1:15 PM, Ferdinand Thiessen wrote:
> When building the kernel modules, try to get the kernel
> version from the kernel sources first. This fixes the
> kernel modules installation directory if the target kernel
> version differs from the host kernel version, like for
> CI build or when packaging for linux distributions.
> 
> Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>

lgtm

Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
David Marchand June 8, 2022, 3:39 p.m. UTC | #2
On Tue, Mar 8, 2022 at 4:55 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 3/3/2022 1:15 PM, Ferdinand Thiessen wrote:
> > When building the kernel modules, try to get the kernel
> > version from the kernel sources first. This fixes the
> > kernel modules installation directory if the target kernel
> > version differs from the host kernel version, like for
> > CI build or when packaging for linux distributions.
> >
> > Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks.
  

Patch

diff --git a/kernel/linux/meson.build b/kernel/linux/meson.build
index d8fb20c1c3..16a0948994 100644
--- a/kernel/linux/meson.build
+++ b/kernel/linux/meson.build
@@ -12,15 +12,21 @@  cross_args = []
 if not meson.is_cross_build()
     # native build
     kernel_version = run_command('uname', '-r', check: true).stdout().strip()
+    if kernel_source_dir != ''
+        # Try kernel release from sources first
+        r = run_command('make', '-s', '-C', kernel_source_dir, 'kernelrelease', check: false)
+        if r.returncode() == 0
+            kernel_version = r.stdout().strip()
+        endif
+    else
+        # use default path for native builds
+        kernel_source_dir = '/lib/modules/' + kernel_version + '/source'
+    endif
     kernel_install_dir = '/lib/modules/' + kernel_version + '/extra/dpdk'
     if kernel_build_dir == ''
         # use default path for native builds
         kernel_build_dir = '/lib/modules/' + kernel_version + '/build'
     endif
-    if kernel_source_dir == ''
-        # use default path for native builds
-        kernel_source_dir = '/lib/modules/' + kernel_version + '/source'
-    endif
 
     # test running make in kernel directory, using "make kernelversion"
     make_returncode = run_command('make', '-sC', kernel_build_dir,