diff mbox series

[1/2] package/pkg-generic.mk: add '<pkg>-dirclean-rdepends' command

Message ID 20240827-package-dirclean-rdep-v1-1-d5e4f79a4241@collins.com
State New
Headers show
Series package/pkg-generic.mk: add '<pkg>-dirclean-rdepends' command | expand

Commit Message

Brandon Maier Aug. 27, 2024, 1:04 p.m. UTC
Add a build target similar to '<pkg>-dirclean' that cleans a package and
all of its reverse dependencies (rdepends).

This is useful for resyncing the target/ and host/ directories of a
package when using per-package directory. And to force a rebuild of any
packages depending on a package.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 package/pkg-generic.mk | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 171163dcb4..3c17c5418d 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -407,6 +407,13 @@  $(BUILD_DIR)/%/.stamp_dircleaned:
 	$(if $(BR2_PER_PACKAGE_DIRECTORIES),rm -Rf $(PER_PACKAGE_DIR)/$(NAME))
 	rm -Rf $(@D)
 
+# Remove package and reverse-dependencies sources
+$(BUILD_DIR)/%/.stamp_rdepends_dircleaned:
+	$(foreach rdep,$(NAME) $($(PKG)_FINAL_RECURSIVE_RDEPENDENCIES), \
+		$(if $(BR2_PER_PACKAGE_DIRECTORIES), \
+			rm -Rf $(PER_PACKAGE_DIR)/$(rdep)$(sep)) \
+		rm -Rf $($(call UPPERCASE,$(rdep))_BUILDDIR)$(sep))
+
 ################################################################################
 # virt-provides-single -- check that provider-pkg is the declared provider for
 # the virtual package virt-pkg
@@ -858,6 +865,7 @@  $(2)_TARGET_EXTRACT =		$$($(2)_DIR)/.stamp_extracted
 $(2)_TARGET_SOURCE =		$$($(2)_DIR)/.stamp_downloaded
 $(2)_TARGET_ACTUAL_SOURCE =	$$($(2)_DIR)/.stamp_actual_downloaded
 $(2)_TARGET_DIRCLEAN =		$$($(2)_DIR)/.stamp_dircleaned
+$(2)_TARGET_DIRCLEAN_RDEPENDS =	$$($(2)_DIR)/.stamp_rdepends_dircleaned
 
 # default extract command
 $(2)_EXTRACT_CMDS ?= \
@@ -1055,6 +1063,7 @@  $(1)-all-legal-info:	$(1)-legal-info
 $(1)-all-legal-info:	$$(foreach p,$$($(2)_FINAL_ALL_DEPENDENCIES),$$(p)-all-legal-info)
 
 $(1)-dirclean:		$$($(2)_TARGET_DIRCLEAN)
+$(1)-dirclean-rdepends:	$$($(2)_TARGET_DIRCLEAN_RDEPENDS)
 
 $(1)-clean-for-reinstall:
 ifneq ($$($(2)_OVERRIDE_SRCDIR),)
@@ -1100,6 +1109,8 @@  $$($(2)_TARGET_ACTUAL_SOURCE):		PKG=$(2)
 $$($(2)_TARGET_ACTUAL_SOURCE):		PKGDIR=$(pkgdir)
 $$($(2)_TARGET_DIRCLEAN):		PKG=$(2)
 $$($(2)_TARGET_DIRCLEAN):		NAME=$(1)
+$$($(2)_TARGET_DIRCLEAN_RDEPENDS):	PKG=$(2)
+$$($(2)_TARGET_DIRCLEAN_RDEPENDS):	NAME=$(1)
 
 # Compute the name of the Kconfig option that correspond to the
 # package being enabled.
@@ -1293,6 +1304,7 @@  DL_TOOLS_DEPENDENCIES += $$(call extractor-system-dependency,$$($(2)_SOURCE))
 	$(1)-configure \
 	$(1)-depends \
 	$(1)-dirclean \
+	$(1)-dirclean-rdepends \
 	$(1)-external-deps \
 	$(1)-extract \
 	$(1)-graph-depends \