diff mbox series

[1/1,SRU,Lunar] UBUNTU: [Packaging] support modaliases for standalone dkms packages

Message ID 20231013043630.1667443-2-vicamo.yang@canonical.com
State New
Headers show
Series Add XB-Modaliases field for standalone linux-modules-foo-* packages | expand

Commit Message

You-Sheng Yang Oct. 13, 2023, 4:36 a.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2021740

Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
---
 debian.master/control.stub.in        |  1 +
 debian/control.d/flavour-module.stub |  1 +
 debian/rules                         |  1 +
 debian/rules.d/2-binary-arch.mk      | 10 +++++++++-
 debian/scripts/dkms-build            |  9 +++++++++
 5 files changed, 21 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/debian.master/control.stub.in b/debian.master/control.stub.in
index cf8164ebba26..7c8660ad433a 100644
--- a/debian.master/control.stub.in
+++ b/debian.master/control.stub.in
@@ -35,6 +35,7 @@  Build-Depends:
  uuid-dev <!stage1>,
  libnuma-dev [amd64 arm64 ppc64el s390x] <!stage1>,
  dkms <!stage1>,
+ dh-modaliases <!stage1>,
  curl <!stage1>,
  zstd [amd64 s390x] <!stage1>,
  pahole [amd64 arm64 armhf ppc64el s390x riscv64] | dwarves (>= 1.21) [amd64 arm64 armhf ppc64el s390x riscv64] <!stage1>,
diff --git a/debian/control.d/flavour-module.stub b/debian/control.d/flavour-module.stub
index 2810f83bb361..d3a7b2ca1030 100644
--- a/debian/control.d/flavour-module.stub
+++ b/debian/control.d/flavour-module.stub
@@ -7,6 +7,7 @@  Priority: optional
 Depends:
  ${misc:Depends},
  linux-image-PKGVER-ABINUM-FLAVOUR | linux-image-unsigned-PKGVER-ABINUM-FLAVOUR,
+XB-Modaliases: ${modaliases}
 Built-Using: ${linux:BuiltUsing}
 Description: Linux kernel MODULE modules for version PKGVER-ABINUM
  This package provides the Linux kernel MODULE modules for version
diff --git a/debian/rules b/debian/rules
index 034aa2b789a6..a5ca75ac998d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -152,6 +152,7 @@  clean: debian/control debian/canonical-certs.pem debian/canonical-revoked-certs.
 	# Remove generated intermediate files
 	rm -f $(DROOT)/control.stub $(DEBIAN)/control.stub
 	rm -f $(DROOT)/scripts/fix-filenames
+	rm -f $(DROOT)/*.modaliases
 
 .PHONY: distclean
 distclean: clean
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index aa790f98f000..af43aa0455f1 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -451,6 +451,9 @@  endif
 	$(foreach _m,$(all_dkms_modules), \
 	  $(if $(enable_$(_m)), \
 	    $(call build_dkms,$(dkms_$(_m)_pkg_name)-$*,$(dkms_$(_m)_pkgdir)/lib/modules/$(abi_release)-$*/$(dkms_$(_m)_subdir),$(dbgpkgdir_dkms),$(_m),$(dkms_$(_m)_debpath)); \
+	    $(if $(filter $(_m),$(all_standalone_dkms_modules)), \
+	      if [ -f "$(dkms_dir)/$(_m).modaliases" ]; then cp "$(dkms_dir)/$(_m).modaliases" "$(CURDIR)/debian/$(dkms_$(_m)_pkg_name)-$*.modaliases"; fi; \
+	    ) \
 	  ) \
 	)
 
@@ -672,7 +675,12 @@  ifeq ($(do_extras_package),true)
 endif
 
 	$(foreach _m,$(all_standalone_dkms_modules), \
-	  $(if $(enable_$(_m)),$(call dh_all,$(dkms_$(_m)_pkg_name)-$*);)\
+	  $(if $(enable_$(_m)), \
+	    if [ -f "$(CURDIR)/debian/$(dkms_$(_m)_pkg_name)-$*.modaliases" ]; then \
+	      dh_modaliases -p$(dkms_$(_m)_pkg_name)-$*; \
+	    fi; \
+	    $(call dh_all,$(dkms_$(_m)_pkg_name)-$*); \
+	  )\
 	)
 
 	$(call dh_all,$(pkgbldinfo))
diff --git a/debian/scripts/dkms-build b/debian/scripts/dkms-build
index f85a6557a8e0..0b9c3df3fde3 100755
--- a/debian/scripts/dkms-build
+++ b/debian/scripts/dkms-build
@@ -91,6 +91,15 @@  do
 	fi
 
 	dpkg -x "$lpackage"_*.deb "$package"
+	if [ -n "$(dpkg-deb -f "$lpackage"_*.deb Modaliases)" ]; then
+		echo "II: dkms-build $package modaliases:"
+		dpkg-deb -f "$lpackage"_*.deb Modaliases | \
+			sed -e 's/\([^(]\+\)(\([^)]\+\))\(, \)\?/\1 \2\n/g' | \
+			sed -e '/,/bx' -e 's/\([^ ]\+\) \([^ ]\+\)/alias \2 \1/' \
+			    -e 'bend' -e ':x' -e 's/\([^ ]\+\) \([^ ]\+\), \(.*\)/alias \2 \1\n\1 \3/' -e 'P;D' -e ':end' | \
+			grep -v '^$' | \
+			sort | tee "$package".modaliases
+	fi
 
 	lversion=$( echo "$lpackage_path" | sed -e 's@.*/@@' -e 's@_[^_]*$@@' -e 's@.*_@@')
 	#built_using_record "$srcdir/debian/$pkgname.substvars" "$built_using$lpackage (= $lversion)"