[Rpm-maint] [PATCH 2/2] Add debugsource recommends to debuginfo packages.

Mark Wielaard mark at klomp.org
Thu Sep 21 15:01:50 UTC 2017


Debuginfo packages are useful without debugsource files. But it is often
useful to also have the debugsource files. So make debuginfo packages that
don't contain sources recommend the debugsource package (or the main
debuginfo one if the sources are not in a separate debugsource package).

Add Package dbgsrc as argument to filterDebuginfoPackage so it can be
added as recommendation. Add a new function findDebugsourcePackage.
Use it to add a requires to the main debuginfo file and/or the debuginfo
subpackages.

Extend the various rpmbuild.at tests that create debugsource and/or
debuginfo subpackages to check the debugsource (or main debuginfo)
package is recommended.

Signed-off-by: Mark Wielaard <mark at klomp.org>
---
 build/files.c     | 33 +++++++++++++++++++++++++++++++--
 tests/rpmbuild.at | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/build/files.c b/build/files.c
index aad9c5e..92f982e 100644
--- a/build/files.c
+++ b/build/files.c
@@ -2773,6 +2773,9 @@ static void patchDebugPackageString(Package dbg, rpmTag tag, Package pkg, Packag
     _free(newsubst);
 }
 
+/* Early prototype for use in filterDebuginfoPackage. */
+static void addPackageDeps(Package from, Package to, enum rpmTag_e tag);
+
 /* create a new debuginfo subpackage for package pkg from the
  * main debuginfo package */
 static Package cloneDebuginfoPackage(rpmSpec spec, Package pkg, Package maindbg)
@@ -2805,7 +2808,8 @@ static Package cloneDebuginfoPackage(rpmSpec spec, Package pkg, Package maindbg)
 /* collect the debug files for package pkg and put them into
  * a (possibly new) debuginfo subpackage */
 static void filterDebuginfoPackage(rpmSpec spec, Package pkg,
-		Package maindbg, char *buildroot, char *uniquearch)
+				   Package maindbg, Package dbgsrc,
+				   char *buildroot, char *uniquearch)
 {
     rpmfi fi;
     ARGV_t files = NULL;
@@ -2914,6 +2918,9 @@ static void filterDebuginfoPackage(rpmSpec spec, Package pkg,
 	else {
 	    Package dbg = cloneDebuginfoPackage(spec, pkg, maindbg);
 	    dbg->fileList = files;
+	    /* Recommend the debugsource package (or the main debuginfo).  */
+	    addPackageDeps(dbg, dbgsrc ? dbgsrc : maindbg,
+			   RPMTAG_RECOMMENDNAME);
 	}
     }
 }
@@ -2976,6 +2983,16 @@ static int addDebugSrc(Package pkg, char *buildroot)
     return ret;
 }
 
+/* find the debugsource package, if it has been created.
+ * We do this simply by searching for a package with the right name. */
+static Package findDebugsourcePackage(rpmSpec spec)
+{
+    Package pkg = NULL;
+    if (lookupPackage(spec, "debugsource", PART_SUBNAME|PART_QUIET, &pkg))
+	return NULL;
+    return pkg && pkg->fileList ? pkg : NULL;
+}
+
 /* find the main debuginfo package. We do this simply by
  * searching for a package with the right name. */
 static Package findDebuginfoPackage(rpmSpec spec)
@@ -3009,6 +3026,9 @@ rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
     char *uniquearch = NULL;
     Package maindbg = NULL;		/* the (existing) main debuginfo package */
     Package deplink = NULL;		/* create requires to this package */
+    /* The debugsource package, if it exists, that the debuginfo package(s)
+       should Recommend.  */
+    Package dbgsrcpkg = findDebugsourcePackage(spec);
     
 #if HAVE_LIBDW
     elf_version (EV_CURRENT);
@@ -3039,6 +3059,12 @@ rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
 	    if (rpmExpandNumeric("%{?_unique_debug_names}"))
 		uniquearch = rpmExpand("-%{VERSION}-%{RELEASE}.%{_arch}", NULL);
 	}
+    } else if (dbgsrcpkg != NULL) {
+	/* We have a debugsource package, but no debuginfo subpackages.
+	   The main debuginfo package should recommend the debugsource one. */
+	Package dbgpkg = findDebuginfoPackage(spec);
+	if (dbgpkg)
+	    addPackageDeps(dbgpkg, dbgsrcpkg, RPMTAG_RECOMMENDNAME);
     }
 
     for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
@@ -3056,6 +3082,8 @@ rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
 		deplink = extradbg;
 	    if (addDebugSrc(extradbg, buildroot))
 		deplink = extradbg;
+	    if (dbgsrcpkg != NULL)
+		addPackageDeps(extradbg, dbgsrcpkg, RPMTAG_RECOMMENDNAME);
 	    maindbg = NULL;	/* all normal packages processed */
 	}
 
@@ -3072,7 +3100,8 @@ rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
 	    goto exit;
 
 	if (maindbg)
-	    filterDebuginfoPackage(spec, pkg, maindbg, buildroot, uniquearch);
+	    filterDebuginfoPackage(spec, pkg, maindbg, dbgsrcpkg,
+				   buildroot, uniquearch);
 	else if (deplink && pkg != deplink)
 	    addPackageDeps(pkg, deplink, RPMTAG_REQUIRENAME);
 
diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at
index 25d9167..fe49b2b 100644
--- a/tests/rpmbuild.at
+++ b/tests/rpmbuild.at
@@ -856,15 +856,20 @@ run rpmbuild --quiet \
   --define "_debugsource_packages 1" \
   -ba "${abs_srcdir}"/data/SPECS/hello2.spec
 
-# Unpack the debuginfo rpms so we can check the sources are there.
+# Unpack the debugsource rpm so we can check the sources are there.
 rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello2-debugsource-1.0-1.*.rpm \
   | cpio -diu --quiet
 
 # Check that hello.c is there.
 ls ./usr/src/debug/hello2-1.0*/
+
+# The debuginfo package should recommend the debugsource package (ignore arch).
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/hello2-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
 ],
 [0],
 [hello.c
+Recommends: hello2-debugsource(ignore-arch) = 1.0-1
 ],
 [ignore])
 AT_CLEANUP
@@ -996,6 +1001,11 @@ else
   echo "No hello2: $debug_name"
 fi
 
+# No debugsource package, so sources are in the main debuginfo package.
+# Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test2-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
+
 # Third contains hello3.debug
 rpm2cpio ${abs_builddir}/testing/build/RPMS/*/test-test3-1.0-1.*.rpm \
   | cpio -diu --quiet
@@ -1009,12 +1019,19 @@ if test -f ./usr/lib/debug/bin/$debug_name; then
 else
   echo "No hello3: $debug_name"
 fi
+
+# No debugsource package, so sources are in the main debuginfo package.
+# Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test3-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
 ],
 [0],
 [3
 hello debug exists
 hello2 debug exists
+Recommends: test-debuginfo(ignore-arch) = 1.0-1
 hello3 debug exists
+Recommends: test-debuginfo(ignore-arch) = 1.0-1
 ],
 [ignore])
 AT_CLEANUP
@@ -1070,6 +1087,11 @@ else
   echo "No hello2: $debug_name"
 fi
 
+# No debugsource package, so sources are in the main debuginfo package.
+# Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test2-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
+
 # Third contains hello3.debug
 rpm2cpio ${abs_builddir}/testing/build/RPMS/*/test-test3-1.0-1.*.rpm \
   | cpio -diu --quiet
@@ -1083,12 +1105,19 @@ if test -f ./usr/lib/debug/bin/$debug_name; then
 else
   echo "No hello3: $debug_name"
 fi
+
+# No debugsource package, so sources are in the main debuginfo package.
+# Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test3-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
 ],
 [0],
 [3
 hello debug exists
 hello2 debug exists
+Recommends: test-debuginfo(ignore-arch) = 1.0-1
 hello3 debug exists
+Recommends: test-debuginfo(ignore-arch) = 1.0-1
 ],
 [ignore])
 AT_CLEANUP
@@ -1130,6 +1159,10 @@ else
   echo "No hello: $debug_name"
 fi
 
+# Sources are in debugsource package. Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
+
 # Second contains hello2.debug
 rpm2cpio ${abs_builddir}/testing/build/RPMS/*/test-test2-1.0-1.*.rpm \
   | cpio -diu --quiet
@@ -1144,6 +1177,10 @@ else
   echo "No hello2: $debug_name"
 fi
 
+# Sources are in debugsource package. Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test2-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
+
 # Third contains hello3.debug
 rpm2cpio ${abs_builddir}/testing/build/RPMS/*/test-test3-1.0-1.*.rpm \
   | cpio -diu --quiet
@@ -1157,12 +1194,19 @@ if test -f ./usr/lib/debug/bin/$debug_name; then
 else
   echo "No hello3: $debug_name"
 fi
+
+# Sources are in debugsource package. Make sure it is recommended.
+echo -n "Recommends: "
+rpm -qp --recommends ${abs_builddir}/testing/build/RPMS/*/test-test3-debuginfo-1.0-1.*.rpm | sed -E 's/([[-.a-z0-9]]+)\(.*\) = ([[-.0-9]]+)/\1\(ignore-arch\) = \2/'
 ],
 [0],
 [3
 hello debug exists
+Recommends: test-debugsource(ignore-arch) = 1.0-1
 hello2 debug exists
+Recommends: test-debugsource(ignore-arch) = 1.0-1
 hello3 debug exists
+Recommends: test-debugsource(ignore-arch) = 1.0-1
 ],
 [ignore])
 AT_CLEANUP
-- 
1.8.3.1



More information about the Rpm-maint mailing list