debianize: add support for DEBIAN_BUILD_CONFLICTS

Message ID 20261120123351.16764-1-badrikesh.prusty@siemens.com
State New
Headers show
Series debianize: add support for DEBIAN_BUILD_CONFLICTS | expand

Commit Message

Badrikesh Prusty Nov. 20, 2026, 12:33 p.m. UTC
Allow recipes inheriting debianize (such as dpkg-raw) to specify
packages that must not be installed in the build environment by
introducing DEBIAN_BUILD_CONFLICTS.

This is useful in scenarios such as:
 - Conflicting or alternative toolchains in the build chroot causing
   compilation failures (e.g. both 'rustc' and 'rustc-web' getting
   pulled in, leading to toolchain version mismatches):
       DEBIAN_BUILD_CONFLICTS = "rustc-web"

 - Build systems (such as CMake, Meson, or Autotools) auto-detecting
   unwanted optional packages present in the chroot, altering the build
   output, or breaking build reproducibility.

When defined, this emits the 'Build-Conflicts' field into the Source
stanza of the generated debian/control file. If unset or empty, the
field is omitted to prevent empty-field.

Signed-off-by: Badrikesh Prusty <badrikesh.prusty@siemens.com>
---
 doc/user_manual.md                    | 1 +
 meta/classes-recipe/debianize.bbclass | 7 +++++++
 2 files changed, 8 insertions(+)

Patch

diff --git a/doc/user_manual.md b/doc/user_manual.md
index 199eb931..baf984bf 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -1065,6 +1065,7 @@  Other (optional) customization variables include:
  - `DEBIAN_PROVIDES` - declare a virtual package to satisfy dependencies
  - `DEBIAN_REPLACES` - to replace a package with another
  - `DEBIAN_BREAKS` - Packages which break other packages
+ - `DEBIAN_BUILD_CONFLICTS` - Packages that must not be installed during the build (added to `Build-Conflicts`)
  - `DEBIAN_BUILT_USING` - Used when a binary package includes parts of other source packages, f.e: by statically linking their libraries or embedding their
     code or data during the build.
     E.x: Built-Using: <name> (= <version>)
diff --git a/meta/classes-recipe/debianize.bbclass b/meta/classes-recipe/debianize.bbclass
index e483a52d..101e79c5 100644
--- a/meta/classes-recipe/debianize.bbclass
+++ b/meta/classes-recipe/debianize.bbclass
@@ -8,6 +8,7 @@ 
 CHANGELOG_V ??= "${PV}"
 DPKG_ARCH ??= "any"
 DEBIAN_BUILD_DEPENDS ??= ""
+DEBIAN_BUILD_CONFLICTS ??= ""
 DEBIAN_SECTION ??= "misc"
 DEBIAN_DEPENDS ??= ""
 DEBIAN_PROVIDES ??= ""
@@ -83,6 +84,7 @@  EOF
 
 
 deb_create_control[vardeps] += "DEBIANIZE_BUILD_DEPENDS \
+                                DEBIAN_BUILD_CONFLICTS \
                                 DEBIAN_SECTION \
                                 DEBIAN_DEPENDS \
                                 DEBIAN_PROVIDES \
@@ -103,6 +105,11 @@  Standards-Version: ${DEBIAN_STANDARDS_VERSION}
 Maintainer: ${MAINTAINER}
 Build-Depends: ${@ deb_list_beautify(d, 'DEBIANIZE_BUILD_DEPENDS')}
 EOF
+	# If a value has been set, add Build-Conflicts to the control file
+	if [ -n "${DEBIAN_BUILD_CONFLICTS}" ]; then
+		echo "Build-Conflicts: ${@ deb_list_beautify(d, 'DEBIAN_BUILD_CONFLICTS')}" >> \
+			${S}/debian/control
+	fi
 
 	# If a value has been set, add the value of DEBIAN_RULES_REQUIRES_ROOT to
 	# the control file.