[v3,4/5] dpkg: Retrieve Debian source name from variable

Message ID efd5b9ea04d7164dc333ba1d72620e20509ed2d3.1715963742.git.jan.kiszka@siemens.com
State Accepted, archived
Headers show
Series More kbuild improvements, single-build source packages, cross profile fix | expand

Commit Message

Jan Kiszka May 17, 2024, 4:35 p.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

Rather than reading this multiple times back from the changelog, define
DEBIAN_SOURCE, by default BPN, and use that consistently. This will
allow to fetch sources built by the base recipe in native and compat
recipes later on without generating the changelog first.

It also permits to clean up related code. Specifically do_deploy_source
was expecting more than one source file (which was incorrect) and looked
in the wrong folder.

The equivalence between DEBIAN_SOURCE and the actual source field is
checked in do_dpkg_source and enforced by failing the build otherwise.

At this chance, also move global -maxdepth before -name in find
statements.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 meta/classes/dpkg-source.bbclass | 16 +++++++++++-----
 meta/classes/dpkg.bbclass        |  3 +--
 2 files changed, 12 insertions(+), 7 deletions(-)

Patch

diff --git a/meta/classes/dpkg-source.bbclass b/meta/classes/dpkg-source.bbclass
index 7fd5d2ed..560f536b 100644
--- a/meta/classes/dpkg-source.bbclass
+++ b/meta/classes/dpkg-source.bbclass
@@ -7,10 +7,15 @@  inherit dpkg-base
 
 DPKG_SOURCE_EXTRA_ARGS ?= "-I"
 
+DEBIAN_SOURCE ?= "${BPN}"
+
 do_dpkg_source() {
     # Create a .dsc file from source directory to use it with sbuild
     DEB_SOURCE_NAME=$(dpkg-parsechangelog --show-field Source --file ${WORKDIR}/${PPS}/debian/changelog)
-    find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -maxdepth 1 -delete
+    if [ "${DEB_SOURCE_NAME}" != "${DEBIAN_SOURCE}" ]; then
+        bbfatal "DEBIAN_SOURCE (${DEBIAN_SOURCE}) not aligned with source name used in control files (${DEB_SOURCE_NAME})"
+    fi
+    find ${WORKDIR} -maxdepth 1 -name "${DEBIAN_SOURCE}_*.dsc" -delete
     sh -c "cd ${WORKDIR}; dpkg-source ${DPKG_SOURCE_EXTRA_ARGS} -b ${PPS}"
 }
 addtask dpkg_source after do_prepare_build before do_dpkg_build
@@ -20,12 +25,13 @@  do_deploy_source[lockfiles] = "${REPO_ISAR_DIR}/isar.lock"
 do_deploy_source[dirs] = "${S}"
 do_deploy_source() {
     repo_del_srcpackage "${REPO_ISAR_DIR}"/"${DISTRO}" \
-        "${REPO_ISAR_DB_DIR}"/"${DISTRO}" "${DEBDISTRONAME}" "${BPN}"
-    find "${S}/../" -name '*\.dsc' -maxdepth 1 | while read package; do
+        "${REPO_ISAR_DB_DIR}"/"${DISTRO}" "${DEBDISTRONAME}" "${DEBIAN_SOURCE}"
+    DSC_FILE=$(find ${WORKDIR} -maxdepth 1 -name "${DEBIAN_SOURCE}_*.dsc")
+    if [ -n "${DSC_FILE}" ]; then
         repo_add_srcpackage "${REPO_ISAR_DIR}"/"${DISTRO}" \
             "${REPO_ISAR_DB_DIR}"/"${DISTRO}" \
             "${DEBDISTRONAME}" \
-            "${package}"
-    done
+            "${DSC_FILE}"
+    fi
 }
 addtask deploy_source after do_dpkg_source before do_dpkg_build
diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
index 0e25eb76..804fe5a6 100644
--- a/meta/classes/dpkg.bbclass
+++ b/meta/classes/dpkg.bbclass
@@ -109,8 +109,7 @@  dpkg_runbuild() {
     echo '$apt_keep_downloaded_packages = 1;' >> ${SBUILD_CONFIG}
     echo '$stalled_pkg_timeout = ${DPKG_BUILD_TIMEOUT};' >> ${SBUILD_CONFIG}
 
-    DEB_SOURCE_NAME=$(dpkg-parsechangelog --show-field Source --file ${WORKDIR}/${PPS}/debian/changelog)
-    DSC_FILE=$(find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -maxdepth 1 -print)
+    DSC_FILE=$(find ${WORKDIR} -maxdepth 1 -name "${DEBIAN_SOURCE}_*.dsc" -print)
 
     sbuild -A -n -c ${SBUILD_CHROOT} \
         --host=${PACKAGE_ARCH} --build=${BUILD_ARCH} ${profiles} \