From: Jan Stancek <[email protected]>

kernel.spec: gcov: make gcov subpackages per variant

There is currently only one gcov subpackage, but builds can contain multiple
kernel variants, which creates confusion which one is "gcov enabled".
Modify spec file so that gcov subpackage is created for each kernel variant.

During build, gcc creates gcno files (gcov notes), which we package
into -gcov subpackage. kernel exposes gcda (count data) via sysfs.
To make it easy to pair gcno and gcda, kernel also creates symlinks in sysfs
for gcno files. These symlinks use absolute paths based on builddir.
This creates a problem when we build multiple variants in same directory,
because gcno from all variants are mixed together (or overwritten).
Make build directory name unique so that we can package and install gcov
for more than one variant.

Signed-off-by: Jan Stancek <[email protected]>

diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index blahblah..blahblah 100644
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -1164,12 +1164,12 @@ Kernel sample programs and selftests.
 # with_selftests
 %endif
 
-%if %{with_gcov}
-%package gcov
-Summary: gcov graph and source files for coverage data collection.
-%description gcov
-kernel-gcov includes the gcov graph and source files for gcov coverage 
collection.
-%endif
+%define kernel_gcov_package() \
+%package %{?1:%{1}-}gcov\
+Summary: gcov graph and source files for coverage data collection.\
+%description %{?1:%{1}-}gcov\
+%{?1:%{1}-}gcov includes the gcov graph and source files for gcov coverage 
collection.\
+%{nil}
 
 %package -n %{package_name}-abi-stablelists
 Summary: The Red Hat Enterprise Linux kernel ABI symbol stablelists
@@ -1409,6 +1409,9 @@ Provides: installonlypkg(kernel)\
 Provides: kernel-%{?1:%{1}-}uname-r = %{KVERREL}%{?1:+%{1}}\
 Requires: kernel%{?1:-%{1}}-modules-core-uname-r = %{KVERREL}%{?1:+%{1}}\
 %endif\
+%if %{with_gcov}\
+%{expand:%%kernel_gcov_package %{?1:%{1}}}\
+%endif\
 %{nil}
 
 #
@@ -1775,6 +1778,17 @@ BuildKernel() {
       CopyKernel=cp
     fi
 
+%if %{with_gcov}
+    # Make build directory unique for each variant, so that gcno symlinks
+    # are also unique for each variant.
+    if [ -n "$Variant" ]; then
+        ln -s $(pwd) ../linux-%{KVERREL}-${Variant}
+    fi
+    echo "GCOV - continuing build in: $(pwd)"
+    pushd ../linux-%{KVERREL}${Variant:+-${Variant}}
+    pwd > ../kernel${Variant:+-${Variant}}-gcov.list
+%endif
+
     InitBuildVars $Variant
 
     echo BUILDING A KERNEL FOR ${Variant} %{_target_cpu}...
@@ -2403,6 +2417,9 @@ BuildKernel() {
     fi
 %endif
 
+%if %{with_gcov}
+    popd
+%endif
 }
 
 ###
@@ -3268,13 +3285,6 @@ fi
 %files
 %endif
 
-%if %{with_gcov}
-%ifnarch %nobuildarches noarch
-%files gcov
-%{_builddir}
-%endif
-%endif
-
 # This is %%{image_install_path} on an arch where that includes ELF files,
 # or empty otherwise.
 %define elf_image_install_path %{?kernel_image_elf:%{image_install_path}}
@@ -3349,6 +3359,11 @@ fi
 %if %{?3:1} %{!?3:0}\
 %{expand:%%files %{3}}\
 %endif\
+%if %{with_gcov}\
+%ifnarch %nobuildarches noarch\
+%{expand:%%files -f kernel-%{?3:%{3}-}gcov.list %{?3:%{3}-}gcov}\
+%endif\
+%endif\
 %endif\
 %{nil}
 

--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2398
_______________________________________________
kernel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to